Admun's NUDN


  • San Francisco, CA





Notify Me


subscribers to this blog

htmlspecialchars & htmlspecialchars_decode

To properly handle inputs, i.e. all those ", `, and '. Be sure to use htmlspecialchars to convert them before writing to the table. Then use htmlspecialchars_decode to decode it before display. This also work with UTF-8, but not some of the encoding. So, special handling is need to detected them and handle.

How simple an idea... and how come I never pay attention? sad

14:30:49 on 04/14/07 by Admun - Developer Notes - tags: - #

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);


15:59:19 on 03/08/07 by Admun - Developer Notes - tags: - #

To Make createItemLink() Work....

Just saw some code from NP_Trackback that need to make createItemLink() to work... I ran into some problem in the past that have to resolve into manually construct the item link. In fact, what need to do is to set $CONF['ItemURL'] using the following code:
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);

16:58:13 on 02/21/07 by Admun - Developer Notes - tags: - #

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';

$b->readLogAmount($tempalte, 1, $extraQuery, 0, 1, 0);
$outbuf = ob_get_contents();
The contents of the post is in the $outbuf for your consumption.

10:48:46 on 11/22/05 by Admun - Developer Notes - tags: none - #

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:
  1. Create function to insert XMLHttpRequest javascript
  2. Setup doSkinvar() with function to insert javascript and <div> block
  3. Add action to receive remote HTTP request


16:04:07 on 11/17/05 by Admun - Developer Notes - tags: none - #

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().

17:56:29 on 09/15/05 by Admun - Developer Notes - tags: none - #

Depending on plugin

I should have written this little post a while back. cool

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.

19:15:27 on 04/10/05 by Admun - Developer Notes - tags: none - #

Softer plugin dependancy

Currently in CVS, there is a plugin dependancy support to allow a plugin to specify what other plugins must be installed for it to function properly.


11:28:46 on 02/07/05 by Admun - Developer Notes - tags: none - #

The Way to Show the Item

I saw some code from NP_Print the other day about how it parses and display an item. I thought I will distill it and document a snippet of code hope other plugin developer found useful.


17:53:45 on 11/04/04 by Admun - Developer Notes - tags: none - #

More Benchmarking Nucleus

Building on top of existing benchmarking infrastructure, here I show how to count number of SQL queries a page generated.


20:09:33 on 10/13/04 by Admun - Developer Notes - tags: none - #
| 1 | 2 | Next»