<?  // PHPmyGallery - backend core - start page

/* File description:

This file displays the available plugins for the adminmenu.

### What this script does:
###
### Included from: adminmenu.index.php
### |
### | (Uses templates from plugins)
### +- Show PlugIns   (Load available PlugIns filenames, Display Links & Descriptions)
### +- Execute PlugIn (Includes selected PlugIn Script with require() )
###
*/

// Get vars for this script
$plugin2load = $_GET['plugin'];

if($plugin2load == '') {
    // Show PlugIns
    $arr  = filenames2arr($conf['pluginsDir'],PLUGINS);
    
    if(count($arr) > 0) {
        $rows = '';
        foreach($arr as $plugin) {
            // Get name of plugin (just filename -4 characters for '.php')
            $name = substr($plugin,0,strlen($plugin)-4);
            
            $helpFilename = $conf['pluginsDir'].$name.'.txt';
            if(is_file($helpFilename))
                $description = implode("<br>\n",file($helpFilename));
            else
                $description = $l['no_description'];
            
            $pktpl_vars['pluginName']        = $name;
            $pktpl_vars['pluginLink']        = urlencode($name);
            $pktpl_vars['pluginDescription'] = $description;
            $rows                           .= pktpl('adminmenu/plugins/pluginsTableRow.html');
            
        } // foreach
        $pktpl_vars['template_pluginHeader'] = pktpl('adminmenu/plugins/pluginsTableHeader.html');
    } // if
    else {
        $rows = pktpl('adminmenu/plugins/pluginsTableRowEmpty.html');
        
        $pktpl_vars['template_pluginHeader'] = '';
    } // else
    
    // Make templates
    $pktpl_vars['template_pluginRows']   = $rows;
    $pktpl_vars['template_admin_table']  = pktpl('adminmenu/plugins/pluginsTable.html');
    
} // if
else {
    // Include plugin
    $pktpl_vars['pluginLink'] = $plugin2load;
    $plugin2load = urldecode($plugin2load);
    require($conf['pluginsDir'].$plugin2load.'.php');
} // else

?>