Plugins block

Creating a block listing all plugins on your site

Sometimes having all the plugins in the menu bar along the top of your page can create a cramped look, particularly if you also have lots of static pages there too. Here is a simple function (add it to your lib-custom.php file) that creates a block that lists all your plugins - at least the ones that would have appeared in the menu bar. That way you can remove the links in the menu bar and have a less cluttered site. The code is modified from lib-common.php.

Firstly, copy the following code and add it to your lib-custom.php at the bottom of the file (or anywhere, just as long as it is inside the <?php ?> tags and not in the middle of another function):


/*
* phpblockPlugins: creates html listing all plugins for inclusion in a block
*/
function phpblock_Plugins() {

    
$retval = '';
    
$plugin_menu = PLG_getMenuItems();
    
ksort($plugin_menu);                    // sort the plugins alphabetically; delete if wanted
    
if( count( $plugin_menu ) == 0 ) {
        
$retval = "No plugins";             // edit this to suit, or set from a language file
    
} else {
        for(
$i = 1; $i <= count( $plugin_menu ); $i++ ) {
            if (
strpos(current( $plugin_menu ),"staticpages")) {
                
next( $plugin_menu );       // exclude staticpages from the list
            
} else {
                
$retval .= '<a href="'.current( $plugin_menu ).'">'.key( $plugin_menu ).'</a><br>';
                
next( $plugin_menu );
            }
        }
    }
    return
$retval
}

Next, you need to create the block. From the block manager on your administration control panel, create a new block. Set the title to "Plugins" or something like that, the name to anything unique you like, and set the topic and position options as you like. Make it a PHP block, and set the name of the function to "phpblock_Plugins". Finally set access permissions at the bottom of the page and save.

You can also download the code from the downloads section or get the file directly from here.

Another version here below, also checks the static pages database for a page with the same id as the plugin name with spaces removed, and then adds a link to that page in the block if the page exists. Ideal for developers who want to add a page explaining their plugin.

/*
* phpblockPlugins: creates html listing all plugins for inclusion in a block
*/
function phpblock_Plugins() {
    global
$_TABLES;
    
$retval = '';
    
$plugin_menu = PLG_getMenuItems();
    
ksort($plugin_menu);                    // sort the plugins alphabetically; delete if wanted
    
if( count( $plugin_menu ) == 0 ) {
        
$retval = "No plugins";             // edit this to suit, or set from a language file
    
} else {
        for(
$i = 1; $i <= count( $plugin_menu ); $i++ ) {
            if (
strpos(current( $plugin_menu ),"staticpages")) {
                
next( $plugin_menu );
            } else {
                
$page = strtolower(str_replace(" ","",key( $plugin_menu )));
                if (
DB_getItem($_TABLES['staticpage'],'sp_id',"sp_id=''") == "") {
                    
$retval .= '<a href="'.current( $plugin_menu ).'">'.key( $plugin_menu ).'</a>';
                } else {
                    
$retval .= '<span style="float:left;">
                                <a href="'
.current( $plugin_menu ).'">'.key( $plugin_menu ).'</a>
                                </span>
                                <span style="float:right;">
                                <a href="'
.$_CONF['site_url'].'/staticpages/index.php/'.
                                    
$page.'">
                                info</a></span>'
;
                }
                
$retval .= '<br>';
                
next( $plugin_menu );
            }
        }
    }
    return
$retval;
}

Finally, to remove the links from your menu bar, the quickest way to hack this is to remove the item "" from the file header.thtml in each theme directory. This is not the best solution as it does not prevent Geeklog from processing the menu links and taking up server time, but it is quick and easy. If you are confident, you could hack lib-common.php to remove the code - only for the brave.

|