/* Enjoy!!! Dino Ciuffetti - dam2k@users.sourceforge.net
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program (COPYING); if not, go to http://www.fsf.org/ or write
* to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
/* PLUGINS CLASS */
/**
* Here you can handle plugins mechanism. You can for example list all the installed plugins, include
* a plugin, ecc.
* Class instance: $cms->plugins
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
class cmsdam_plugins
{
/**
* You should not use this variable from your section.
*/
var $conf;
var $included; // Included plugins are instanciated here!
var $basedir; // Plugin base directory
var $logs; // Log class
var $plugin_genuine; // Plugin instance file
function cmsdam_plugins () {
$this->basedir = "plugins";
$this->plugin_genuine = "cmsdam_genuine.php";
return true;
}
/**
* This api method return an array containing the sorted list of the installed plugins
* @return array The sorted list of installed plugins
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function list_installed() {
// cmsdam related plugins directory
$basedir = $this->basedir;
$plugin_genuine = $this->plugin_genuine;
$dh = opendir($basedir);
if ($dh == false) {
return false;
}
while (false !== ($filename = @readdir($dh))) {
// Exclude some common plugin name from be considered a valid plugin, so prevent it from listing
if (($filename != ".") && ($filename != "..") && ($filename != "CVS") && ($filename != "_skel") &&
(is_dir($basedir . "/" . $filename))) {
// Check if this is really a plugin... invent something!!
if (is_readable($basedir . "/" . $filename . "/" . $plugin_genuine)) { // Plugin is a genuine cmsdAm plugin
$files[] = $filename;
}
}
}
@sort($files);
print_r($files);
closedir($dh);
return $files;
}
function plugin_include($plugin_name) { // Include a cmsdAm plugin
Global $cms;
$basedir = $this->basedir;
$plugin_genuine = $this->plugin_genuine;
if ($plugin_name === false) { // Plugin name not passed
return false;
}
// Get a common plugin method to see if the plugin is already loaded
$plugin_included = $this->included->$plugin_name->plugin_name;
if ($plugin_included != "") { // Plugin already loaded
// echo "DEBUG: Plugin already loaded.";
$this->logs->log_note(5, "Tried to include already loaded plugin: $plugin_name");
return false;
}
$this->logs->log_note(6, "Trying to include plugin: $plugin_name");
if (is_readable ($basedir . "/" . $plugin_name . "/" . $plugin_genuine)) { // Is a valid plugin
include_once ($basedir . "/" . $plugin_name . "/" . $plugin_genuine);
} else { // Is not a valid plugin or genuine file is not readable
$this->logs->log_note(4, "Genuine file for plugin $plugin_name is not readable");
return false;
}
$this->logs->log_note(6, "Plugin $plugin_name included");
return true;
}
}
?>