Pixelpost

Authentic Photoblog Flavour

ExtendingPixelpost /

Creating Addons

Creating Addons is not difficult at all but you should be familiar to PHP and the Pixelpost core code. Please bear in mind that if you use Pixelpost's own variables they can be overwritten by your Addon.
Tip: To show errors while testing your addon add "?errors" to the address string in the URL field of your browser or insert "error_reporting(E_ALL ^ E_NOTICE)" in the beginning of your Addon code (remove it when finished!).

Since version 1.7 there are three types of Addons and you must know the difference between them to make use of the whole Addons functionality.

"Normal" Addons

Normal Addons add new features to the visitor's side of the blog. They can create their own template tags which show new values on the pages. These Addons are called in the index.php in the pixelpost root directory, so their functions are available in all public pages.
Addons cannot make use of any existing template tags, but can call functions and variables. If you want to realize a different behaviour of Pixelpost, you usually have to rewrite the functions in your Addon.

Naming convention: addonname.php

Admin Addons

Admin Addons were invented in version 1.5.
With Admin Addons you can

  • add new content to the forms of the Admin panel in the New Image, Edit Image, Images List, Comments, Options and Info page.
  • add new pages to the Admin panel. This adds a new menu title link in the Admin menus automatically and creates optional submenu entries.
  • also place new tags for the public pages. It is recommended to split your Addon files to have one file per Addon type (see below).

The logic behind the Admin addons is simple: Whenever one of the Admin pages is called, a list of addon functions and their assigned location (=workspace) is stored in an array. At every workspace in the core code the related functions from Admin addons are performed in run-time.
See here a list of all available Admin workspaces.

Naming convention: admin_addonname.php

Front Addons

Front Addons are new in version 1.7. They behave similiar to the Admin Addons but their workspaces are defined within the front pages code. The code is again included when the workspace is parsed.
Front Addons can add extended functions within the Pixelpost code and can perform actions exactly in the moment they are called.

See here a list of all available Front workspaces.

Naming convention: front_addonname.php

For all these Addons you have to follow a few rules right in the beginning:

  • Strictly hold on the naming convention mentioned above
  • Always include the $addon_* variables in the beginning of the code. These are displayed in the Admin panel Addons page:
    • $addon_name: the compelling name of your Addon
    • $addon_version: the version number of your Addon
    • $addon_description: the Addon description to tell your users what it is for. The description can hold further information and a form for the settings.
      If you are inventing new template tags you should describe them here too.
  • Never change the core files of Pixelpost. Almost everything can be done with one of the Addon types: always try to keep the Pixelpost code clean.
  • To keep the files neat you should not mix the Addon types in one addon file. Create one Addon file for each addon type you are using.
    You can put them all together into a folder within the addons directory, using this naming convention: _addonfoldername
  • Always comment your Addon code so other users can understand what you were doing.
  • If you really need a new workspace you can add it but you should better tell it to the developer team so we can include it in the next version.

TOP

Writing a "Normal" Addon

Open the file current_datetime.php in your Addons directory and have a look at the code. This Addon is provided as a simple example how to write an addon:

current_datetime.php

It starts with the $addon_ variables which every Addon must have. Like mentioned above these are $addon_name, $addon_version and $addon_description.
Perform your PHP code, here it is the call of PHP function gmdate() making use of the $cfgrow array of Pixelpost core code. Pixelpost's core variables are always available in normal Addons. If you access them as globals they can be changed.
Replace your result with a template tag ($tmp variable is available too, it is always the one of the template that is in use right now).
Add your new template tag to the template where you want to show the new value.
That's all!

Now have a closer look to the other normal Addons like calendar.php and paged_archive.php which come with your Pixelpost installation. You will see that you can call the MySQL functions as well, read out the tables and create new ones.
As you can see in paged_archive.php the Addon has to repeat the "normal" pixelpost functions for showing the thumbnails in the archive page with page numbers.

See the code of a simple sample "Normal" Addon here: Hello World Addon Code TOP

Writing an Admin Addon

Always remember that when writing an Admin Addon:

  • Workspaces are predefined unique locations within the core code of the admin files.
  • Your Admin Addon code must be assigned to a workspace by using the Interface function.
  • You can create new menus and submenus by using the interface function and the correct workspace.
  • You can access the variables of the Admin files inside your addon's functions by defining them as globals.
  • You can overwrite them but make sure that the core code still works.
  • You have to name your Addon file like admin_addonname.php if you want to use admin workspaces.

Admin Interface function

To call your Admin Addon functions in the right place you have to make use of the admin interface function:
add_admin_functions($addon_function_name, $addon_workspace, $addon_menu, $addon_submenu);

You don't have to use all of those parameters when calling the interface, it depends on what kind of action you want to perform.
See the several ways to use this interface here:
Use of the Admin Interface Function

New Menus and Submenus

By using the interface function you can create your own menus and submenus with Your Admin Addon.
If you want to add a new submenu to one of the original pages the link to this submenu page is automatically created as
index.php?view=menu&menuview=new_submenu
where menu is the menu variable and new_submenu is the name of your new submenu.

See the list of available Menus / Submenus here: available Menus / Submenus

Admin Workspaces

Workspaces can be compared to anchors within the admin code. All addon functions must be "tied" to a workspace and are called in the moment the script passes the workspace. This way you can add new functionality into many locations of the admin files.
See the list of available Admin Workspaces here:
Admin Workspaces

admin_12CropImage.php

This Addon is provided as an example for an Admin addon. Open the file and see the code:
It starts again with the $addon_ variables which every Addon must have. Like mentioned above these are $addon_name, $addon_version and $addon_description.
It should perform its function in the New Image page and create a new submenu for that. So we call the interface function like this:

$addon_workspace = "image_edit";
// menu where the addon should appear in admin panel. in this case: images menu
$addon_menu = "images";
// What would be the title of submenu of this addon: 12cropimage
$addon_admin_submenu = "12cropimage";
// What is the function
$addon_function_name = "cropimage12_admin_addon";

// add the function
add_admin_functions($addon_function_name,$addon_workspace,$addon_menu,$addon_admin_submenu);

The function crop12_admin_addon() performs the action of this addon.

Please have a look into the code of admin_ping.php, admin_update_exif.php and admin_akismet_comment.php too! TOP

Coding Tips

  • You can use multiple functions in your Addon for different places of the Admin panel, just assign them to the workspaces where they should be called.
  • To add a new page with content to the Admin panel you should perform the following steps:
    1. create the new menu item
      add_admin_functions('', 'admin_main_menu', 'New_Page', '');
    2. assign the function for echoing the new content on New Page
      add_admin_functions('show_newpage', 'admin_main_menu_contents', 'New_Page', '');
    3. define the function:
      function show_newpage() {
         global $pixelpost_db_prefix;
         if ($_GET['view']=='new_page']) {
            echo '<div class="caption">NEW PAGE</div>
                  <div class="jcaption">Section Title</div>'
      ;
            echo '<p>This is a really new page!</p>';
         }
      }
    4. save it as admin_newpage.php in the Addons directory and try it!
  • To add content to the new page including submenus you should use the following function:
    • function show_newpage() {
         global $pixelpost_db_prefix;
         if ($_GET['view']=='new_page']) {
            echo '<div class="caption">NEW PAGE</div>
                  <div class="submenu">'
      ;
            $submenuclass = '';
            if (!isset($_GET['new_pageview']) || $_GET['new_pageview']=='overview') {
               $submenuclass = 'selectedsubmenu';
               echo "<a href='?view=new_page&amp;new_pageview=overview' class='".$submenucssclass."' >OVERVIEW</a>\n";
            }
            $submenuclass = '';
            if ($_GET['new_pageview'=='details') {
               $submenuclass = 'selectedsubmenu';
               echo "<a href='?view=new_page&amp;new_pageview=details' class='".$submenucssclass."' >DETAILS</a>\n";
            $submenuclass = '';
            if ($_GET['new_pageview'=='settings') {
               $submenuclass = 'selectedsubmenu';
               echo "<a href='?view=new_page&amp;new_pageview=settings' class='".$submenucssclass."' >SETTINGS</a>\n";
            echo '</div>';
            echo '<div class="jcaption">Section Title</div>';
            echo '<p>This is a really new page!</p>';
         }
      }

See the code of a simple sample Admin Addon here: Admin Hello World Addon Code

Writing a Front Addon

Front Addons work very similar to the Admin Addons. They use their own workspaces which we call Front Workspaces for differentiating.
You have to name your Addon file like front_addonname.php if you want to use front workspaces.

Front Interface function

To call your Front Addon functions in the right place you have to make use of the front interface function:
add_front_functions($addon_function_name, $addon_front_workspace)

Front Workspaces

The main reason for inventing the Front Workspaces in Pixelpost v1.7 was the demand for additional spam defeat methods. So you'll find the most front workspaces within the comments code where they can be used for spam statistics or for implementing new spam filters after or between the applying of Pixelpost's own spam control functions.

See the actual list of available Front Workspaces here: Front Workspaces

See the code of a simple sample Front Addon here: Front Hello World Addon Code TOP


Page last modified on December 07, 2007, at 04:14 AM