Introducing Pixelpost's Admin-Addons

Developed and documented by Ramin Mehran, last modified: april 2006

In version 1.5 of Pixelpost, team Pixelpost has introduced a new feature, called Admin-Addon, that extends the flexibility and functionality of the Pixelpost software. With this new feature people can simply use addons and plugins to add new new function inside the Admin-Panel of Pixelpost. Read this article to get a better understanding of this new useful feature.

  1. What are Admin-Addons?
  2. Which version of Pixelpost supports Admin-Addons?
  3. What are the new features?
  4. How does Admin-Addons work?
  5. How to write Admin-Addons?
  6. Can I add new menu items and tabs to Pixelpost Admin-Panel with Admin-Addons? How?
  7. Should Admin-Addons have special filename style?
  8. Do Admin-Addons work exclusively on the Admin-Panel or can they add new functions to the browsing side of a Pixelpost photoblog?
  9. What does the term workspace mean in the Admin-Addons?
  10. What are the available workspaces?
  11. How could I add new workspaces?
  12. Does Admin-Addons eliminate the need for hacks in Admin-Panel?
  13. Are there any available Admin-Addons for download?
  14. How could I add a new page to Admin-Panel with multiple submenus?
  15. I have other questions about Admin-Addons. What should I do?

  1. What are Admin-Addons?

    Basically, Pixelpost accepts addons for adding custom functionality to its simple behavior. Before the release of Pixelpost 1.5, addons were only able to add new feature to the visitors side of a photoblog. However, since version 1.5, addons can be used to add new functionalities to the Admin-Panel side, where admin user manages the photoblog. This realizes the dreams that the simple Pixelpost software could perform complex behaviors with some customizations. People now can use addons in the Admin-Panel to have more options in posting an image, editing previously posted photos, having more options, and even adding new pages to the Admin-Panel. This new type of addons is called Admin-Addon.

  2. Which version of Pixelpost supports Admin-Addons?

    Only Pixelpost 1.5 or above supports the Admin-Addons feature.

  3. What are the new features?

    With Admin-Addons you can

  4. How does Admin-Addon work?
    The logic behind the Admin-Addons are simple and once you get knowing it, you can write Admin-Addons even with one hand tied behind your back! Once admin user visits the admin pages and logs in, the script looks into the addons folder for the admin-addons and updates the list of available addons in the addons' table. Thereafter it will gather a list of functions from addons and their corresponding workspaces in an array. Consequently, at every workspace/anchor in run-time it will call the related functions from admin-addons.
    By considering the usage, the related functions can be categories in 5 different groups.

    1. Functions for extending the HTML code between <head> and </head> tags in admin pages.

    2. Simple functions that don't need menu and submenus.

    3. Function that act in menus or submenus.

    4. Functions that add new menu items to admin area.

    5. Functions that add new page content to admin area.

    All of the above different types of functions will be assigned through a single interface. The interface is the function named add_admin_functions().
    Below, the syntax for using the interface function is decribed:

    add_admin_functions ($function_name as string ,$workspace as string ,$menu as string ,$admin_submenu as string );

      Syntax Description
    1 add_admin_functions ($function_name,'admin_html_head','',''); This can be used to echo some additional HTML codes into the place between <head> and </head> inside all page of admin area. For instance, the function with name as string in variable $function_name, could have simple code like: echo '<script language="javascript" type="text/javascript">somescript code... </script>';
    2 add_admin_functions ($function_name,$workspace,'',''); This can be used to assign a function (with name as string in variable $function_name) to a predefined workspace ($workspace as string) in the admin code without setting a specific menu or submenu for it. The second and third arguments are set to empty strings.
    3 add_admin_functions ($function_name,$workspace,$menu,$submenu); This will can be used to assign a function to the place in the code that user has selected a menu and/or submenu in the admin area. If you pass only menu string and leave submenu variable string as an empty string the function will be called just when menu is selected. If both menu and submenu strings are set the function will directly called when the submenu of the selected menu is visited. If the submenu you mention in this function does not exist in the package it will create that submenu automatically. The list of available menu and submenus is provided below this table.
    4 add_admin_functions ('','admin_main_menu',$menu,''); This function call will create a new menu item with a link to a newpage. The $menu variable will indicate the title of the page in the menu as well as the link to that new page in the admin area. For instance if $menu is newitem, the link to the new page will end with index.php?x=newitem.
    5 add_admin_functions ($function_name,'admin_main_menu_contents',$menu,''); This function call will assign a function to print the content of a new page with name specified in $menu variable as string. The function with the name as string inside $function_name variable should will be called when the menu item as $menu is selected.


    Here is the list of available Menu/Submenus of Pixelpost 1.5 that can be used for Admin-Addons

    menu name menu variable string submenu name submenu variable strings link
    New Image - - - index.php
    Options options General general index.php?x=options&optionsview=general
    Options options Template template index.php?x=options&optionsview=template
    Options options Thumbnails thumb

    index.php?x=options&optionsview=thumb

    Options options Spam Control antispam index.php?x=options&optionsview=antispam
    Options options <custom submenu> <customsubmenu> index.php?x=options&optionsview=customsubmenu
    Images images - - index.php?view=images
    Images images <custom submenu> <customsubmenu> index.php?view=images&imagesview=customsubmenu

    As it is presented in the above table with a distinct color, if you want to add new submenus to images or options page the link these pages will be automatically created as index.php?view=images&imagesview=customsubmenu and index.php?x=options&optionsview=customsubmenu respectively where you can replace the "customsubmenu" with the name of your choice.

  5. How to write Admin-Addons?

    There is a sample admin-addon named Admin_12CropImage that adds the cropping ability for creating thumbnails after uploading a new image or even when editing an old post.
    There are some detailed instructions for writing an admin addon (addons/admin_12CropImage.php).
    Key points are:

    1. To create such an addon you should fill $addon_* variables properly.
      All of the activity of each addon is encapsulated inside a custom function by the addon developer. The function should not have any arguments. It's recommended that the function name have a fixed variable name like $addon_function_name.
    2. The addon for Admin-Panel must have "admin_" at the beginnig of its name.
      This is the only way that these addons are distinguished and included inside
      admin/index.php.
    3. The needed variables of the admin/index.php OR new_image.php OR images_edit.php OR options.php are accessed as globals inside the function of the addons. This should be changed by some safer methods.
    4. When creating an addon, please always use the $addon_*variables. These values will be displayed in a users Admin-Panel under addons:
      $addon_name
      $addon_description
      $addon_version
      and the others are used for the functionality of the addon in the Admin-Panel.
       
    5. You can write separate functions for different places of the Admin-Panel. These function can be called in the proper place and the only thing you need to do is to assign each function to some predefined places in the code. These predefined places are called workspaces which anchors to some places inside Admin-Panel codes. With assigning new functions to each of these anchors you may get new functionalities in different parts of the code.
      Below is a part of the sample admin addon that assigns a custom function, cropimage12_admin_addon, to a predefined place, image_edit, which is actually the page that admin visits when it has to edit a post.
      This addon adds a submenu to the edit image page and thus, the menu name for this new submenu is specified as

      $addon_menu = "images";
      Also the title of the submenu is introduced as
      $addon_admin_submenu = "12cropimage";
      Finally, the function add_admin_functions, performs the assignment by adding the function named cropimage12_admin_addon to the workspace
      named image_edit.
      It also adds a new submenu to the images menu named 12cropimage.
      // The workspace. Where to activate the function inside index.php
      $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);
      Assigning multiple functions to multiple workspaces is as simple as repeating the above procedure for each new function.
    6. To add new pages to Admin-Panel and add new menu and submenus you should take following steps:
      First to add the name of the new page to the menu

      • set the workspace admin_main_menu:
        $addon_workspace = "admin_main_menu";
      • Choose a new admin menu name, for example:
        $addon_menu = "new-item";
      • Call the assinging function:
        add_admin_functions('',$addon_workspace,$addon_menu,'');
      • Now it's time to create the content of the new page. To do that choose admin_main_menu_contents workspace and write a function that works when user visits the new-item page.
         

        // add the function
        $addon_workspace = 'admin_main_menu_contents';
        $addon_function_name = 'new_item_show_page';
        $addon_admin_submenu = "";
        $$addon_menu = "NEWITEM";
        add_admin_functions($addon_function_name,$addon_workspace,$addon_menu,$addon_admin_submenu);

        // the function to act on the new page
        function
        new_item_show_page()
        {
        global $addon_admin_functions;
        global $pixelpost_db_prefix;
        if ($_GET['view']=='newitem'){
        echo "
        <div class='caption'>
        NEWITEM
        </div>
        <div class='jcaption'>
        Some Section Title...
        </div>
        "
        ;


      • echo "<p/> This is really a <b>new page</b>!!";
        }// end if

        }

      • This will produce a page like this

        newitem: a new page in the AdminPanel  
      • The whole admin_newitem.php code will be like this
         

        <?php

        // add the new page title to the main menu
        $addon_workspace = "admin_main_menu";
        $addon_menu = "NEWITEM";
        add_admin_functions('',$addon_workspace,$addon_menu,'');

        // assign a function name to make the content of the new page
        // add the function
        $addon_workspace = 'admin_main_menu_contents';
        $addon_function_name = 'new_item_show_page';
        $addon_admin_submenu = "";

        add_admin_functions($addon_function_name,$addon_workspace,$addon_menu,$addon_admin_submenu);

        // the function to write the content of the new page
        function new_item_show_page()
        {
        global $addon_admin_functions;
        global $pixelpost_db_prefix;
        if ($_GET['view']=='newitem'){
        echo "
        <div class='caption'>
        NEWITEM
        </div>
        <div class='jcaption'>
        Some Section Title...
        </div>
        ";
        echo "<p/> This is really a <b>new page</b>!!";
        }// end if

        }

        ?>

         

    7. To add content of the new page which includes the submenus:
  6. Can I add new menu items and tabs to Pixelpost Admin-Panel with Admin-Addons?
    yes, read "How to write Admin-Addons"

  7. .
    ^
  8. Should Admin-Addons have special filename style?
    yes, they should start with admin_
  9. for example admin_newitem.php is an admin addon named newitem and admin_ in the start of the file name identify it as and Admin-Addon.
    ^
  10. Do Admin-Addons work exclusively on the Admin-Panel or can they add new functions to the browsing side of a Pixelpost photoblog?
    They can add new functionalities to the browsing side of a Pixelpost photoblog as well! Every script that is written inside every type of addon will be executed when someone is browsing the photoblog and this is the same for admin addons. BUT the codes for admin new features are encapsulated into separated functions and these function are assigned to specific workspaces. Thus, in the admin addons the functions that are assigned to workspaces will run on admin page but you can always put some code there to add some new tags to the visiting side of photoblog too.

    For example: you can add these lines to an Admin-Addon called admin_newitem.php to replace the current date with tag <NEWITEM_DATE>
    $newitem_time = date();
    $tpl = ereg_replace("<NEWITEM_DATE>",$newitem_time,$tpl);

    ^
  11. What does the term workspace mean in the Admin-Addons?
    Workspaces are the anchors in the admin code that you can assign functions to them. When the code executes and reaches the anchors all functions that are assigned to that anchor will be called. This way you can add new functionalities to any place inside the admin codes. There are some pre-defined workspaces in the code.
    ^
  12. What are the available workspaces?
    Here is the list of available workspaces
     

    Workspace Name

    Menu Name file/ near line Description

    image_edit

    images images_edit.php/267 Place that executes the code when admin tries to edit an image. Useful when you want to add new submenus to the image edit page. Admin_12CropImage sample addon uses this workspace.

    image_edit_form

    images images_edit.php/274 To add any new input to the form for the editing of an individual image.

    image_update

    images images_edit.php/73 Place that executes the code when admin updates an image via the editing page. Useful when adding new functions to editing images.
    image_deleted images images_edit.php/120 Place that executes the code when admin deleted an image. Useful when you want to add new submenus to the image edit page.
    admin_html_head - index.php/187 Executes when code is producing HTML to be placed between <head> and </head> tags and will work for every page of Admin-Panel.
    admin_main_menu - index.php/244 Place that executes the code to automatically produce the menu items.
    admin_main_menu_contents - index.php/271 Place that executes the code to show the contents of every new page in the Admin-Panel.
    new_image_form - new_image.php/127 To add any new element to the HTML form in the New Image page you can use this workspace.
    image_uploaded -

    new_image.php/228

    A part of code that will execute JUST after the successful uploading of an image.
    thumb_created - new_image.php/255 A part of code that will execute right after uploading a new file and the creation of the thumbnail image. This is useful when you want to add new tools or information after file upload. For example, Admin_FlashCrop addon uses this to let you crop the image for creation of a thumbnail in a Flash screen below the uploaded page.
    options options options.php/186 A part of code which executes when admin browses to the options page. You may use this to create new option pages with submenus to the option page.
    info info view_info.php/16 A part of code which executes when admin browses to the general info page. You may use this to create new general info pages with submenus to the general info page.

    image_list

    images images_edit.php/330 Place that executes the code for each image in the image overview of "images". Useful if you want to add new information for each image in the image list.

    image_upload_start

    images new_image.php/279 Place that executes the code before the image is actually moved to the images folder when uploading an image.

    image_upload_succesful

    images new_image.php/279 Place that executes the code when the uploading of an image was succesful.(Note: this is similar to "image_uploaded" workspace but for sake of compatibility both workspaces remain active.)

    image_upload_failed

    images new_image.php/279 Place that executes the code when the uploading of an image failed.

    image_reupload_start

    images images_edit.php/206 Place that executes the code before the image is actually moved to the images folder when reuploading an image.

    image_reupload_succesful

    images images_edit.php/219 Place that executes the code when the reuploading of an image was succesful.

    image_reupload_failed

    images new_image.php/424 Place that executes the code when the uploading of an image AND the creation of a thumbnail have finished.

    upload_finished

    images images_edit.php/237 Place that executes the code when the reuploading of an image failed.

    new_image_form_def_lang

    images new_images.php/237 Show more options when uploading a file (default language).

    new_image_form_alt_lang

    images new_image.php/189 Show more options when uploading a file (alternative language).

    ^
     

  13. How can I add new workspaces?
    To add/define a new workspace just append the name of the admin code where you want to place the anchor with call of function eval_addon_admin_workspace_menu:
    eval_addon_admin_workspace_menu('new_workspace','menu_name');
    where new_workspace is the name of new workspace and 'menu_name' is the name of the menu that this workspace is working under. If you don't need to have submenu in that workspace/anchor you can only pass the first argument to the above function (e.g. eval_addon_admin_workspace_menu('new_workspace'); ).
    ^
  14. Does Admin-Addons eliminate the need for hacks in Admin-Panel?
    Almost no hack is necessary in Admin-Panel unless there is no workspace available for the required functionality. Only in that case, a very simple hack can be done by adding a new workspace to that part of the code and assigning addons to that workspace. This way it will increase the modularity of the hacks/addons and also it will enormously simplify the procedure for users.
    ^
  15. Are there any Admin-Addons available for download?
    Yes! Always check Pixelpost.org >> addons for new admin addons!
    ^
  16. How could I add a new page to Admin-Panel with multiple submenus?
    Adding submenus to a new page in the Admin-Panel is described here where the creation of new pages is discussed.
    ^
  17. I have other questions about Admin-Addons. What should I do?
    Check out Pixelpost support forum and ask your questions there.

Top of page