Fork me on GitHub
Reply New Topic
2010/2/14 7:25:03
#1
Offline
Home away from home

icmsOnDemandPreload - what is it and how does it work?

I was troubleshooting a blank page in imBlogging admin and ImpressCMS 1.2 and found a class being redeclared because of this in imblogging/admin/post.php

PC9wPg0KDQo8cD4kaWNtc09uRGVtYW5kUHJlbG9hZFtdID0gYXJyYXkoICYjMzk7bW9kdWxlJiMzOTs9Jmd0OyYjMzk7aW10YWdnaW5nJiMzOTssICYjMzk7ZmlsZW5hbWUmIzM5Oz0mZ3Q7JiMzOTtqcXVlcnkucGhwJiMzOTsgKTsgJGljbXNPbkRlbWFuZFByZWxvYWRbXSA9IGFycmF5KCAmIzM5O21vZHVsZSYjMzk7PSZndDsmIzM5O2ltdGFnZ2luZyYjMzk7LCAmIzM5O2ZpbGVuYW1lJiMzOTs9Jmd0OyYjMzk7aW10YWdnaW5nYWRtaW5jc3MucGhwJiMzOTsgKTsg By commenting out that section, the blank page went away and everything seems to be working just fine. Just below the above section of code is the following IC8qKiBJY21zT25kZW1hbmRQcmVsb2FkIGlzIG5vdCBzdXBwb3J0ZWQgcHJpb3IgdG8gMS4yIEFscGhhLiBUaGlzIGlzIGEgd29ya2Fyb3VuZCAqLyBpZiAoSUNNU19WRVJTSU9OX0JVSUxEICZsdDsgMjUpIHsgJGljbXNBZG1pblRwbC0mZ3Q7YXNzaWduKCYjMzk7aW1ibG9nZ2luZ19qcXVlcnlfaW5jJiMzOTssICYjMzk7PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiIHNyYz0iJyAuIElDTVNfTElCUkFSSUVTX1VSTCAuICcvanF1ZXJ5L2pxdWVyeS5qcyI+PC9zY3JpcHQ+PC9wPg0KDQo8cD4mIzM5Oyk7IH08L3A+DQoNCjxwPg==

I think 2 different approaches were made for preloads and they now conflict with each other. Who can explain and improve this?



Edited by skenow on 2019/11/16 8:44:59
_________________

Steve Twitter: @skenow Facebook: Steve Kenow


2010/2/17 4:29:45
#2
Offline
Home away from home

Re: icmsOnDemandPreload - what is it and how does it work?

The icmsOnDemandPreload concept is to be able to load preload code on demand, when we want it.

As we know, adding a file in htdocs/plugins/preloads will add code somewhere in the bootstrap process. But this code will be executed all the time. Sometimes, we don't want this. We only want to add code somewhere in the bootstrap, but on some specific occasion.

In the case you are referring too, imBlogging, we need to "link" to imTagging module as it's the module taking care of the categories of imBlogging. The admin create/edit post page in imBlogging is displaying a category control powered by imTagging, and this needs jQuery and CSS, both already defined in imTagging.

(Today, there would be a better way to include this code, but at the time, it was teh best way, and a good demonstration of IcmsOnDemandPreload).

So how does IcmsOnDemandPreload works ? Simply by defining an array before mainfile.php is included. This is what we do in imblogging/admin/post.php:

JGljbXNPbkRlbWFuZFByZWxvYWRbXSA9IGFycmF5KA0KCSdtb2R1bGUnPT4naW10YWdnaW5nJywNCgknZmlsZW5hbWUnPT4nanF1ZXJ5LnBocCcNCik7DQokaWNtc09uRGVtYW5kUHJlbG9hZFtdID0gYXJyYXkoDQoJJ21vZHVsZSc9PidpbXRhZ2dpbmcnLA0KCSdmaWxlbmFtZSc9PidpbXRhZ2dpbmdhZG1pbmNzcy5waHAnDQopOw0KDQppbmNsdWRlX29uY2UoImFkbWluX2hlYWRlci5waHAiKTs=
The array need to be named $icmsOnDemandPreload and each item of this array is another array with 2 info:

1- In what module shall we find the preload item
2- what is the preload filename

In this case, we are defining 2 preload item to be loaded:

1- modules/imtagging/preload/jquery.php
2- modules/imtagging/preload/imtaggingadmincss.php

So that's it for ccmsOnDemandPreload.

Quote:

I think 2 different approaches were made for preloads and they now conflict with each other. Who can explain and improve this?


No, it's the same approach. We can see it in kernel/icmspreloadhandler.php, in the constructor, we are checking for an array named icmsOnDemandPreload:
CWZ1bmN0aW9uIEljbXNQcmVsb2FkSGFuZGxlcigpIHsNCgkJJHByZWxvYWRGaWxlc0FycmF5ID0gWG9vcHNMaXN0czo6Z2V0RmlsZUxpc3RBc0FycmF5KElDTVNfUFJFTE9BRF9QQVRIKTsNCgkJZm9yZWFjaCAoJHByZWxvYWRGaWxlc0FycmF5IGFzICRmaWxlbmFtZSkgew0KCQkJLy8gZXhjbHVkZSBpbmRleC5odG1sDQoJCQlpZiAoJGZpbGVuYW1lICE9ICdpbmRleC5odG1sJykgew0KCQkJCSR0aGlzLT5fcHJlbG9hZEZpbGVzQXJyYXlbXSA9ICRmaWxlbmFtZTsNCgkJCQkkdGhpcy0+YWRkUHJlbG9hZEV2ZW50cygkZmlsZW5hbWUpOw0KCQkJfQ0KCQl9DQoNCgkJLy8gYWRkIG9uZGVtYW5kIHByZWxvYWQNCgkJZ2xvYmFsICRpY21zT25EZW1hbmRQcmVsb2FkOw0KCQlpZiAoaXNzZXQoJGljbXNPbkRlbWFuZFByZWxvYWQpICYmIGNvdW50KCRpY21zT25EZW1hbmRQcmVsb2FkKSA+IDApIHsNCgkJCWZvcmVhY2ggKCRpY21zT25EZW1hbmRQcmVsb2FkIGFzICRvbkRlbWFuZFByZWxvYWQpIHsNCgkJCQkkdGhpcy0+X3ByZWxvYWRGaWxlc0FycmF5W10gPSAkb25EZW1hbmRQcmVsb2FkWydmaWxlbmFtZSddOw0KCQkJCSR0aGlzLT5hZGRQcmVsb2FkRXZlbnRzKCRvbkRlbWFuZFByZWxvYWRbJ2ZpbGVuYW1lJ10sICRvbkRlbWFuZFByZWxvYWRbJ21vZHVsZSddKTsNCgkJCX0NCgkJfQ0KCX0=
Now, why would this create a blank page, this is another question. Perhaps another thread should be opened to discuss this bug ?

Any question, please ask!

_________________
Marc-André Lanciault
Founder and CEO INBOX International inc.
Co-Founder ImpressCMS

2010/2/17 20:32:02
#3
Offline
Home away from home

Re: icmsOnDemandPreload - what is it and how does it work?

Thanks, Marc.

What happens if a preload is added to the icmsOnDemandPreload more than once? I think this it the problem in imBlogging/imTagging - the jquery class is already loaded and when the class is redeclared, the error and blank page occurs.

_________________

Steve Twitter: @skenow Facebook: Steve Kenow


2012/2/11 15:31:56
#4
Offline
Home away from home

Re: icmsOnDemandPreload - what is it and how does it work?

Any thoughts on how we can best use this function?


2012/2/11 15:42:01
#5
Offline
Home away from home

Re: icmsOnDemandPreload - what is it and how does it work?

possibly use array_unique to remove duplicate keys in the array.

_________________
Live as if you were to die tomorrow, Learn as if you were to live forever

The beauty of a living thing is not the atoms that go into it, but the way those atoms are put together!

2012/2/11 15:52:35
#6
Offline
Home away from home

Re: icmsOnDemandPreload - what is it and how does it work?

That sounds like a good idea Vaughan


2012/2/12 14:44:39
#7
Offline
Home away from home

Re: icmsOnDemandPreload - what is it and how does it work?

Quote:


Vaughan wrote:
possibly use array_unique to remove duplicate keys in the array.



Agreed - and possibly an array_diff(), too, since there are 2 arrays for preloads.

_________________

Steve Twitter: @skenow Facebook: Steve Kenow


2019/11/15 9:08:06
#8
Offline
Webmaster

Re: icmsOnDemandPreload - what is it and how does it work?

I tested this in ImpressCMS 1.4.0 (the module-specific code by marcan) and it works, but the filename doesn't need to have the '.php' extension at the end.


_________________

Me on Ohloh


Reply New Topic extras
 Previous Topic   Next Topic
You can view topic.
You can start a new topic.
You can reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You can post without approval.