Archived : Techno Babble

This is the archived version of my b2evolution code blog.
If you require any help regarding b2evolution then
visit it's support forums

You can find my current blogs here
Code : {@link : WafflesOn}
Personal : {@link : InnerVisions}

Custom Admin Pages

Posted on 13th Jul 2009 in : Techno Babble

Add your tabs today!

Unlike most of our other plugins this one does bugger all by itself, it's only reason for existence is to be used by other plugins and at the moment the only plugin that uses it is one that we're currently developing. So, what does it do? What this plugin does is allow your own plugins to easily add their own custom tabs to the admin area. Now, before any of yah point out that plugins already have the ability to easily add their own tab to the tools tab, I know, but this plugin allows you to add tabs to any of the evo tab pages ;)

How it works

There's a couple of rules that your plugin has to play by to make all this work. The first and most obvious one is that it needs to declare this plugin as a dependency to ensure that it's always installed when you need it. You tell evo about dependencies by adding the following code snippet to your plugin.

PHP ( _your_plugin.plugin.php ) :

/**
     * This plugin requires the AM Admin Pages plugin
     *
     * @return array dependencies
     */
    function GetDependencies()
    {
        return array'requires' => array(
            'plugins' => arrayarray'am_adminpages_plugin') ), // requires at least version 1 of the plugin
            ));
    }

Next you need to create a shiny new method in your plugin called GetAdminTabs() which should return an array of all tabs that you wish to add your tabs to, and the tabs that you wish to add ... it's probably simpler to just show you some code ;)

PHP ( _your_plugin.plugin.php ) :

/**
     * Add our tabs to the admin tabs
     *
     * @param array $params
     *    string 'main_tab' : This is the main b2evo tab that is currently being displayed
     * @return array : our tabs
     */
    function GetAdminTabs($params)
    {
        global $admin_url$blog$current_User$user_ID;
        global $AdminUI;
 
        $admin_tabs false;
 
        switch( $params['main_tab'] )
        {
            case 'dashboard' :
            case 'blog_settings' :
                global $blog;
                $bCache get_Cache'BlogCache' );
                if( $blog && $sBlog $bCache->get_by_ID($blog ) )
                {
                    $shop_ID $sBlog->owner_user_ID;
                }
                break;
 
            case 'users' :
                $shop_ID param'user_ID''integer' );
                break;
        }
 
        if( empty$shop_ID ) )
        {
            $shop_ID 0;
        }
 
        switch( $params['main_tab'] )
        {
/* start snippet */
            case 'blog_settings' :
                if( $this->ShopSettings->get('enabled'$shop_ID ) || $current_User->check_perm('blog_properties''edit'false$blog ) )
                {
                    $admin_tabs array(
                        'blogs' => array(
                            'amsc_settings' => array(
                                'text' => $this->T_('Shop Settings' ),
                                'href' => url_add_param$admin_url'ctrl=coll_settings&blog='.$blog.'&amat_tab=amsc_settings' ),
                            ),
                        ),
                    );
                }
                break;
/* end snippet */
        }
        return $admin_tabs;
    }

The important thing to note in that code is the bit of the href which reads 'amat_tab=amsc_settings', this is the parameter that's used to tell our plugin which one of your custom pages you want to display, and it must have a corresponding function with the following naming convention function AdminTabPayload_your_unique_tab_value(). In the above example the corresponding function would be called AdminTabPayload_amsc_settings(), the following is our code for that function :

PHP ( Our Plugin ) :

/**
     * Display our settings
     *
     * @param array $params
     *    string 'main_tab' : This is the main b2evo tab that is currently being displayed
     */
    function AdminTabPayload_amsc_settings($params)
    {
        global $AdminUI;
 
        switch( $ctrl param('ctrl''string' ) )
        {
            case 'dashboard' :
            case 'coll_settings' :
                global $blog;
                $bCache get_Cache'BlogCache' );
                if( $blog && $sBlog $bCache->get_by_ID($blog ) )
                {
                    $shop_ID $sBlog->owner_user_ID;
                }
                break;
 
            case 'users' :
                $shop_ID param'user_ID''integer' );
                break;
        }
 
        if( empty$shop_ID ) )
        {
            $shop_ID 0;
        }
 
        $edited_settings $this->ShopSettings;
        $edited_settings->ID $shop_ID;
        global $Blog;
        amsc_load_disp'shopsettings' );
    }

The final thing you need to do is to inform evo of your shiny new abilities :

PHP ( your_plugin.plugin.php ) :

/**
   * List of events that we handle
   *
   * @return array : events
   */
    function GetExtraEvents()
    {
        return array(
            'GetAdminTabs' => 'Adds all our required tabs',
            'AdminTabPayload_amsc_settings' => 'Displays our settings',
            'AdminTabPayload_amsc_info' => 'Displays our info',
            'AdminTabPayload_amsc_customers' => 'Displays our customers',
            'AdminTabPayload_amsc_invoices' => 'Displays our invoices',
        );
    }

To make life a tad easier I've also coded a demo plugin that uses this plugin so you can (hopefully) see how it all works.

Anyway, enough blather from me, you can download the plugin here am_adminpages_plugin.zip and the demo plugin from here am_adminpagesdemo_plugin.zip
¥

Tidying the Admin screen

Posted on 12th May 2008 in : Plugins & Widgets

Does your admin look bloated?

NOTE : The chances are that none of this works in IE, so if you use IE you may as well skip the rest of this post ..... or read it and then go get a better browser ... whichever rocks your boat

So, I was playing around with the admin area to see what could be done using js, as it's required for the admin area to function anyway, and css. The main idea was to hide all of the clutter that's not used for the majority of posts, or only used briefly during the whole posting process, whilst also leaving it accessible for the moments that you do need it. When I say "clutter" I pretty much mean everything except the textarea that you type in and the post title. Toolbars - gone, advanced properties - gone, categories - gone, post status - gone, you get the picture ;)

All of this is done from a plugin which hooks into a couple of the admin events and then unleashes a bit of javascript to play around with classnames and id's and onclick events and stuff. The rest is handled by a simple bit of css ...... so simple in fact that IE can't understand it ...... nothing new there then huh? ..... anyway, the end result is that pretty much everything in admin is collapsed or hidden until you hover over or click stuff. The toolbars will show on hover, or you can click the text to pin them open if you're going to be using them a lot for a particular post.

The whole of the right column is reduced to a lil tab handily marked "OPTIONS". Hovering over the tab brings the right column back so you can play with your categories, visibility and renderers and things. This allows the post textarea et el to be expanded to fill the width of the screen which, for me, makes posting far far easier ...... combine that with Afwas's plugin ( [2.4] Resize Admin Textarea plugin ) and you can pretty much fill your screen with just the post area ...... cool huh?

Finally a thanks to John for his constructive criticism and suggestions about the plugin ..... and for allowing me to scare the shit out of him when most of his admin area disappeared ..... I suppose I should have warned him first :roll:

Anyway, if you fancy having a play with this plugin, and you're using a decent browser, then you can download it here ( am_tidyadmin.zip ). If you find any bugs or flaws or stuff ( apart from "it doesn't work in IE", and variations of the same tune ) then just let me know.

¥

Page archived : 11th Nov 2009
 

X