htmlspecialchars & htmlspecialchars_decode
How simple an idea... and how come I never pay attention?
Template Filling, NucluesCMS way
Here's a snippet of code taken from NP_Blogroll to show how someone can utilize Nucleus's build-in class to do template token replacement.
Say we have a few template var <%var1%>, <%var2%>, <%var3%>.
// The text with template vars to be processed $text = "I have <%var1%> to be <%var2%>, at <%var3%>"; // Setup value for each template var $Vars = array ( 'var1' => "a dog", 'var2' => " walked", 'var3' => "home" ); // processing the text and fill in the template var TEMPLATE::fill($text, $Vars);
Handy!
To Make createItemLink() Work....
global $manager, $CONF; // need to reset the ItemURL so createItemLink work properly $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL()); // then createItemLink() will work! $url = createItemLink($itemid);
Getting the post, the right way
In the other post, I come up with a trick to call PreItem event to allow other installed plugins to process any skinvar might be in the data. There is still one problem that internal skinvar like <%image%>, <%popup%>, and etc are not resolve.
Here's the trick to do that, in a one stone for 2 birds fashion. The trick used PHP output buffer control function redirect the output mean for the broswer and capture it into a variable for our use.
example: getting contents of a post:
... ... (get blogid) ... $b =& $manager->getBlog($blogid); ... ... $extraQuery = ' and inumber=' . intval($itemid); $template = 'default'; ob_start(); $b->readLogAmount($tempalte, 1, $extraQuery, 0, 1, 0); $outbuf = ob_get_contents(); ob_end_clean();The contents of the post is in the $outbuf for your consumption.
My private Ajaxized Nuclues Plugin
Here's my note on how to add Ajax function to a Nucleus plugin. Ajax provides interaction to your web application (in our case, a blog) without reloading the whole web page. I think it is a very good mechanism to refresh just a small portions of your blog without clicking the reload button. NP_MiniForum is a good example.
There are 3 area of changes in order to add Ajax function to a Nucleus plugin:- Create function to insert XMLHttpRequest javascript
- Setup doSkinvar() with function to insert javascript and <div> block
- Add action to receive remote HTTP request
PreItem my Item (also known as PreComment your comment)
I've been working on many plugins recently to add support to call other plugins to do pre-processing work. In many plugins that deal with items and comments, the output often not display properly with other plugin's skinvar display in raw code (ie <%Image(file.jpg|1024|768|320|240|test image)%> for NP_PopupImageNetPBM).
I think the best way to fix such a problem is to trigger PreItem (for item) and PreComment (for comment) events before proceeding with the output. The event calls all plugins registered to the event to process the data so all plugin skinvars are render properly.
For comment pre-processing, this can be done by:
$manager->notify('PreComment', array('comment' => &$comment));
For item pre-processing, calls:
$manager->notify('PreItem', array('blog' => &$blog, 'item' => &$item));
Assumption is "global $manager, $blog;" is done earlier in the code.
Note that plugin developer should format and make sure $comment and $item are in the same format as the core pass it to notify().
Depending on plugin
I should have written this little post a while back.
In Nucleus 3.2, a new plugin mechanism is added to allow a plugin to detect whether all plugin(s) it requires are present. There are some plugins that depends on another plugin to function. NP_MostViewed and NP_View is one.
For the same reason, Nuclues now failed the plugin uninstall operation if it is required by another plugin.
For developer, they can simply put in a function in their plugin to tell Nuclues that what plugin(s) the say plugin require:
GetDepPen function getPluginDep() { return array('NP_BlogWithOffset'); }
One note is this new plugin dependancy check mechanism does not break the compatibility for older version of Nucleus, the declared getPluginDep() in the plugin will becomes domrant if a plugin is installed in a older Nucleus.