diff --git a/032-JCB-manual-custom-code-implementation.md b/032-JCB-manual-custom-code-implementation.md index d56309e..66ea611 100644 --- a/032-JCB-manual-custom-code-implementation.md +++ b/032-JCB-manual-custom-code-implementation.md @@ -2,11 +2,13 @@ ### Brief Explanation -Automatic import of custom code during compilation. This is one of our latest features that's been added to the JCB component. [00:00:16](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m16s) I'm happy to demonstrate it to you since all it's functionality is in place. I explain to you some of the limitations that currently still exist. Hope that it will become a very useful tool to all of you out there. First what does it do? Well it is actually a little mutated from what it's original intent was and it's become two things. The first thing is, (and this is obviously what was initially [00:00:52](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m52s) intended) is that you would be able to add code to your component, once it's been compiled and installed into that same Joomla website. That you be able to go into that code, and with a few placeholders add code, [00:01:21](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m21s) that once you compile the component again, JCB would dynamically grab that code extracted into its database, store it there. And from there on forward continue to add it back into the component every time. The way we've done that, we have not used the line numbers as the main [00:01:50](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m50s) way of determining where that code must be added. Because of the reality that line numbers always will change. You might have the custom code that you're adding, you said line 105 or something, and if you make it change at line 20, that means all the code moves down of course and now we don't know where to add your code [00:02:19](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m19s) without either writing over or placing it before, there's all kinds of complications. So the only way we could resolve that is to create what we initially called the fingerprint, but later became a hash reference of the code, a few lines of code above the custom script, and a few lines of code below the customs. [00:02:50](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m50s) It varies from how many lines it uses. There is a reason for it. +[00:00:00](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s) + +Automatic import of custom code during compilation. This is one of the latest features that has been added to the JCB component. Although all its functionality is in place there is currently some limitations which exist that need to be explained. First, what does it accomplish? It actually mutated from that which its original purpose had been and became two things.[00:00:52](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m52s) The first thing is, (and this is obviously what was initially intended) that it will be possible to add code to the component, once it's been compiled and installed into that same Joomla website. That you be able to go into that code, and with a few placeholders add code, [00:01:21](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m21s) that once you compile the component again, JCB would dynamically grab that code, extract it into its database, store it there. And from there on forward continue to add it back into the component every time. The way we've done that, we have not used the line numbers as the main [00:01:50](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m50s) way of determining where that code must be added. Because of the reality that line numbers always will change. You might have the custom code that you're adding, you said line 105 or something, and if you make it change at line 20, that means all the code moves down of course and now we don't know where to add your code [00:02:19](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m19s) without either writing over or placing it before, there's all kinds of complications. So the only way we could resolve that is to create what we initially called the fingerprint, but later became a hash reference of the code, a few lines of code above the custom script, and a few lines of code below the customs. [00:02:50](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m50s) It varies from how many lines it uses. There is a reason for it. ### Updating Code From JCB In The Editor -If you want to see how we do it, there is the code is open source, so you can go look at it. So there is a function in the aget file, which is part of the [00:03:22](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m22s) compiler a set of files. The functions name is searchfilecontent. It's in this function that it really goes through every line of the code that is already on the Joomla website. When it finds it, it adds it to an array which eventually gets save to the database. This is the lines that actually does the work. [00:03:53](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m53s) There's lots of things that works with this function, but this is the center of everything. I'm very sure there are better ways to do this. We will constantly improve this as others makes suggestions, and make sure that it remains stable. But to to explain why it sometimes [00:04:27](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m27s) uses more or less of the lines above, it should never use more than 8 lines. Because here it is packing the fingerprint, taking the line content putting it into an array. Every time it passes, it checks whether that array is greater than 10, we cut it down to 6. [00:04:54](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m54s) This continues to happen over and over and over because we don't want this fingerprint array to become bigger then 10 lines. At some point when we find a placeholder, we actually take that fingerprint array, we create a hash from it, then we store that hash into the database. [00:05:24](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m24s) That means that amount of lines are changing. Because we have just cleared the array and we are at 6 lines. Then we add a 7th and now we find a placeholder and everything happens. +If you want to see how we do it, there is the code is open source, so you can go look at it. So there is a function in the aget file, which is part of the [00:03:22](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m22s) compiler a set of files. The functions name is searchfilecontent. It's in this function that it really goes through every line of the code that is already on the Joomla website. When it finds it, it adds it to an array which eventually gets save to the database. This is the lines that actually does the work. [00:03:53](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m53s) There's lots of things that works with this function, but this is the center of everything. I'm very sure there are better ways to do this. We will constantly improve this as others makes suggestions, and make sure that it remains stable. But to to explain why it sometimes [00:04:27](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m27s) uses more or less of the lines above, it should never use more than 8 lines. Because here it is packing the fingerprint, taking the line content putting it into an array. Every time it passes, it checks whether that array if it is greater than 10, we cut it down to 6. [00:04:54](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m54s) This continues to happen over and over and over because we don't want this fingerprint array to become bigger then 10 lines. At some point when we find a placeholder, we actually take that fingerprint array, we create a hash from it, then we store that hash into the database. [00:05:24](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m24s) That means that amount of lines are changing. Because we have just cleared the array and we are at 6 lines. Then we add a 7th and now we find a placeholder and everything happens. ### Quick Explanation - Insert/Replace