Plugin API Method No. 1
SkyBlueCanvas has a very flexible yet simple plugin API. Actually, it has 2 plugin APIs for greater flexibility. The first API is almost identical to the API used by Wordpress and Joomla - both of which use the Observer design pattern.
Calling an Observer plugin in SkyBlueCanvas is simple. Create a file named 'myplugin.php' and save it in /skyblue/data/plugins/myplugin.php. In the file, include the following code:
global $Core;
$Core->RegisterEvent('OnBeforeShowPage', 'AllYourPlugins');
function AllYourPlugins($html) { $html .= "<p>All your plugins are belong to us</p>n"; return $html; }
That's it. Now when the $Core object gets to the 'BeforeShowPage' marker, it will call the AllYourPlugins function, passing the $html variable containing the page data to the function. The function can perform any operation it need to on the page code, then must return it to the $Core object.
SkyBlueCanvas currently has 3 events to which plugin execution can be attached:
- OnBeforeInitPage
is triggered before the page is built. - OnAfterLoadStory
is triggered when the article for the current page is loaded. - OnBeforeShowPage
is triggered after the entire page is built but before it is sent to the brower.
I am working on implementing more events but they will not be available until the next release.
Plugin Method No. 2
There are instances when you want to insert some code or execute some code at a certain point within the flow of a story. Well, SkyBlueCanvas allows you to do just that with the second Plugin API.
This API allows you to call specific functions, with arguments within the flow of the text using special tokens and function calls that look like this:
Before SkyBlueCanvas displays the page, it will parse all of the special plugin tokens, and call the function specified in the token. So, in this example, when the token is parsed, the SkyBlueCanvas PluginParser will call 'myfunction' passing it the argument 'Plugins'.
Now create a file in /skyblue/data/plugins/myplugin.php and create the myfunction function like so:
function myfunction($what)
{
echo "All your $what are belong to us";
}
Additionally, this method can be embedded in the HTML of your template as well like so:
<!--#plugin:myfunction(Plugins)-->