Closed

The blogrums are now closed. If you wish to visit them on there new home then you can find it here ( InnerVisions Blogrums ).

AuthorAdd tabs in admin from a plugin

PHP:

<?php
/**
 * AstonishMe Gallery plugin.
 *
 * @package plugins
 *
 * @copyright (c)2008 by AstonishMe - {@link http://astonishme.co.uk/}.
 *
 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
 * @author Yabba    - {@link http://www.astonishme.co.uk/}
 * @author Stk        - {@link http://www.astonishme.co.uk/}
 *
 * @license GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
 *
 * @package plugins
 */
 
if( !defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
 
class am_gallery_plugin extends Plugin
{
    var $name 'Am Gallery';
    var $code 'am_gallery';
    var $priority 50;
    var $version '0.1';
    var $author 'AstonishMe';
    var $group 'AstonishMe';
    var $help_url '';
    var $apply_rendering 'stealth';
    var $number_of_installs 1;
 
 
    /**
     * Internal vars
     */
    var $adminPage ''// our admin page
    var $subtab '';    // our current sub tab
    var $url ''// our admin url
 
 
    /**
     * Initialises the plugin and adds to the <title> if relevant
     *
     */
    function PluginInit()
    {
        global $AdminUI$blog;
        $this->short_desc T_('AstonishMe - Add galleries to your blogs');
 
        // grab our params if available
        $this->adminPage param'amgAction''string' );
        $this->adminPage = ( in_array$this->adminPagearray'blog''users' ) ) ? $this->adminPage '' );
 
        $subtab param'subtab''string' );
        $this->subtab = ( in_array$subtabarray'manage''settings' ) ) ? $subtab 'manage' );
 
        if( is_admin_page() && $this->adminPage )
        {    // We're on an admin page and it's "us" lets add our shit to the title
            $AdminUI->set_path( ( $this->adminPage == 'blog' 'items' 'users' ), 'gallery'$this->subtab );
            $AdminUI->title = ( $this->adminPage == 'blog' $this->T_'Browse blog' ) : $this->T_'Profile' ) );
            $AdminUI->title .= $AdminUI->pathSeparator.$this->T_'AM Gallery' );
            $AdminUI->title .= $AdminUI->pathSeparator.( $this->subtab == 'manage' $this->T_'Manage Galleries' ) : $this->T_'Settings' ) );
            if( $this->adminPage == 'blog' && $blog == )
            {    // auto select first blog
                $blog autoselect_blog'blog_ismember''any' );
            }
        }
    }
 
 
    /**
     * Not used yet
     *
     * @param unknown_type $params
     * @return unknown
     */
    function GetDefaultSettings( & $params )
    {
        return array();
/*
        return array(
            'tag_separator' => array(
                'label' => T_('Tag separator'),
                'type' => 'text',
                'size' => 1,
                'note' => T_('This is whatever character seperates tags on your install'),
                'defaultvalue' => ',',
                ),
            );
*/
        }
 
 
    /**
     * Adds our subtabs to posts/comments && profile pages if required
     *
     */
    function AdminAfterMenuInit()
    {
        global $AdminUI$dispatcher,$blog$current_User;
 
        // setting the url to the tools tab gives us access to the AdminTabAction() && AdminTabPayload() events
        $this->url $dispatcher.'?ctrl=tools&amp;tab=plug_ID_'.$this->ID.'&amp;blog='.$blog.'&amp;amgAction=';
 
        // auto select blog if required
        $checkblog autoselect_blog'blog_ismember''any' );
 
        if( $current_User->check_perm'blog_properties''edit'false$checkblog ) )
        {    // user has permission to play with blog settings, add our sub tabs
            $AdminUI->add_menu_entries(
                    'items'// root
                    array(
                        'gallery' => array(    // add our own subtabs
                            'text' => $this->T_('AM Gallery'),
                            'href' => $this->url.'blog',
                            'entries' => array(
                                'manage' => array(
                                    'text' => $this->T_('Manage Galleries'),
                                    'href' => $this->url.'blog&amp;subtab=manage',
                                ),
                                'settings' => array(
                                    'text' => $this->T_('Settings'),
                                    'href' => $this->url.'blog&amp;subtab=settings',
                                    ),
                                ),
                            ),
                    ) );
        }
        elseif( $current_User->check_perm'blog_post_statuses''edit'false$checkblog ) )
        {    // user has permissions to create posts, add our sub tab to posts/comments tab
            $AdminUI->add_menu_entries(
                    'items'// root
                    array(
                        'gallery' => array(    // add our own subtabs
                            'text' => $this->T_('AM Gallery'),
                            'href' => $this->url.'blog',
                            ),
                    ) );
        }
 
 
        $foo param'user_ID''integer' );
        if(
                        ( $current_User->check_perm'users''edit' ) && $foo // user has edit perms and there is a selected user
                ||     ( !$current_User->check_perm'users''edit' ) && $foo == $current_User->ID  // user does not have edit perms and selected user is themselves
                ||    ( !$current_User->check_perm'users''edit' ) && !$foo // user does not have edit perms and no selected user
            )
        {    // add our sub tabs to profile tab
            $AdminUI->add_menu_entries(
                    'users'// root
                    array(
                        'profile' => array(
                            'text' => $this->T_('Profile'),    // we need to add a profile tab for main screen
                            'href' => $dispatcher.'?ctrl=users&amp;user_ID='.$foo,
                            ),
                        'gallery' => array(    // add our own subtabs
                            'text' => $this->T_('AM Gallery'),
                            'href' => $this->url.'users&amp;user_ID='.$foo,
                            'entries' => array(
                                'manage' => array(
                                    'text' => $this->T_('Manage Galleries'),
                                    'href' => $this->url.'users&amp;subtab=manage&amp;user_ID='.$foo,
                                ),
                                'settings' => array(
                                    'text' => $this->T_('Settings'),
                                    'href' => $this->url.'users&amp;subtab=settings&amp;user_ID='.$foo,
                                    ),
                                ),
                            ),
                    ) );
        }
        $foo =  param'ctrl''string' );
        switch( $foo )
        {
            case 'users' // set the default path for normal profile action
                $AdminUI->set_path'users''profile' );
                break;
 
            case 'items' // set the default path for normal profile action
                $AdminUI->set_path'items''full' );
        }
    }
 
 
    /**
     * Set paths if relevant
     *
     */
    function AdminEndHtmlHead()
    {
        global $AdminUI$blog$Blog;
        switch( $this->adminPage )
        {
            case 'blog' :
                // Generate available blogs list:
                $AdminUI->set_coll_list_params'blog_ismember''view'array'ctrl' => 'tools''tab' => 'plug_ID_'.$this->ID.'&amp;amgAction=blog''filter' => 'restore' ) );
 
                // auto select blog if required
                $BlogCache get_cache'BlogCache' );
                $Blog $BlogCache->get_by_ID$blog autoselect_blog'blog_ismember''any' ) );
 
                // Add posts/comments sub menu entries to AdminUI
                attach_browse_tabs();
                // set our path
                $AdminUI->set_path'items''gallery'$this->subtab );
                break;
 
            case 'users' :
                // set our path
                $AdminUI->set_path'users''gallery'$this->subtab );
                break;
        }
    }
 
 
 
    /**
     * Handle our tab action
     *
     */
    function AdminTabAction()
    {
        switch( $this->adminPage )
        {
            case 'blog' :
                $this->AdminTabActionBlog();
                break;
 
            case 'users' :
                $this->AdminTabActionUser();
                break;
        }
    }
 
 
    /**
     * Handle our tab payloads
     *
     */
    function AdminTabPayload()
    {
        global $AdminUI;
        // get the path for sub sub menu
        $long_path array$AdminUI->get_path(0), $AdminUI->get_path(1), $AdminUI->get_path(2)  );
        // get the path for sub menu
        $short_path array_slice$long_path0, -);
 
        // do we have a sub sub tab?
        $foo = ( sizeof$AdminUI->get_properties_for_path$long_patharray'text' ) ) ) == true false );
        if( $foo )
        { // display our sub  menu with relevant tab "open"
            echo $AdminUI->replace_vars$AdminUI->get_html_menu$short_path'sub' ) );
        }
 
        switch( $this->adminPage )
        {
            case 'blog' :    // we're managing blog galleries
                $this->AdminTabPayloadBlog();
                break;
 
            case 'users' :    // we're managing user galleries
                $this->AdminTabPayloadUser();
                break;
        }
 
        if( $foo )
        {    // close our sub sub tab
            $AdminUI->disp_payload_end'sub' );
        }
    }
 
 
    /**
     * Perfoms blog level gallery actions
     *
     */
    function AdminTabActionBlog()
    {
        global $blog$current_User$dispatcher;
 
        if( !$current_User->check_perm'blog_post_statuses''edit'false$blog ) )
        {    // user doesn't have permission to play on this blog, lets redirect them
            header_redirect$dispatcher.'?ctrl=items&tab=full&filter=restore&blog='.$blog );
            exit;
        }
    }
 
    /**
     * Displays blog level gallery payload
     */
    function AdminTabPayloadBlog()
    {
        global $blog;
        echo 'Blog payload ( '.$blog.' ) : '.( $this->subtab == 'settings' 'Gallery Settings' 'Manage Galleries' );
    }
 
    /**
     * Perfoms user level gallery actions
     *
     */
    function AdminTabActionUser()
    {
 
    }
 
    /**
     * Displays user level gallery payload
     */
    function AdminTabPayloadUser()
    {
        global $user_ID;
        echo 'User payload ( '.$user_ID.' ) : '.( $this->subtab == 'settings' 'Gallery Settings' 'Manage Galleries' );
&