2010/2/14 7:25:03
|
---|
|
icmsOnDemandPreload - what is it and how does it work?<p>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</p>
<p>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==</p>
<p>I think 2 different approaches were made for preloads and they now conflict with each other. Who can explain and improve this?</p>
Edited by skenow on 2019/11/16 8:44:59
|
2010/2/17 4:29:45
|
---|
|
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: $icmsOnDemandPreload[] = array(
'module'=>'imtagging',
'filename'=>'jquery.php'
);
$icmsOnDemandPreload[] = array(
'module'=>'imtagging',
'filename'=>'imtaggingadmincss.php'
);
include_once("admin_header.php"); 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:
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: function IcmsPreloadHandler() {
$preloadFilesArray = XoopsLists::getFileListAsArray(ICMS_PRELOAD_PATH);
foreach ($preloadFilesArray as $filename) {
// exclude index.html
if ($filename != 'index.html') {
$this->_preloadFilesArray[] = $filename;
$this->addPreloadEvents($filename);
}
}
// add ondemand preload
global $icmsOnDemandPreload;
if (isset($icmsOnDemandPreload) && count($icmsOnDemandPreload) > 0) {
foreach ($icmsOnDemandPreload as $onDemandPreload) {
$this->_preloadFilesArray[] = $onDemandPreload['filename'];
$this->addPreloadEvents($onDemandPreload['filename'], $onDemandPreload['module']);
}
}
} 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! |
2010/2/17 20:32:02
|
---|
|
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. |
2012/2/11 15:31:56
|
---|
|
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
|
---|
|
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
|
---|
|
Re: icmsOnDemandPreload - what is it and how does it work?That sounds like a good idea Vaughan
|
2012/2/12 14:44:39
|
---|
|
Re: icmsOnDemandPreload - what is it and how does it work?Quote:
Agreed - and possibly an array_diff(), too, since there are 2 arrays for preloads. |
2019/11/15 9:08:06
|
---|
|
Re: icmsOnDemandPreload - what is it and how does it work?<p>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.</p>
|
_________________
|