Location: PHPKode > projects > Bee-rain > www/include/plugins.class.php
<?php
/*
    Bee-rain-ui
    Copyright (C) 2008-2009 Mathieu Lory <hide@address.com>
    This file is part of Bee-rain-ui.

    Bee-rain-ui 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, either version 3 of the License, or
    (at your option) any later version.

    Bee-rain-ui 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 Bee-rain-ui. If not, see <http://www.gnu.org/licenses/>.
    
    Project started on 2008-11-22 with help from Serg Podtynnyi
    <hide@address.com>
 */

/**
 * @package    Bee-rain-ui
 * @subpackage Plugins
 * @author     Mathieu Lory <hide@address.com>
 */

if (basename($_SERVER["SCRIPT_NAME"])==basename(__FILE__))die();

class Plugins
{
	public static $activatedPlugins = array();
	public static $loadedPlugins = array();
	
	public function __construct()
	{
	}
	
	public static function isActive($pluginName)
	{
		$f = new file(Settings::getVar('plug_dir') . strtolower($pluginName) . '/ACTIF');
		if ( $f->Exists() )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public static function listPlugins()
	{
		return file::GetDirs(Settings::getVar('plug_dir'));
	}
	
	public static function LoadPlugin($pluginName)
	{
		array_push(self::$loadedPlugins, $pluginName);
		$f = new File(Settings::getVar('plug_dir') . strtolower($pluginName) . '/_plugin.php');
		if ( $f->Exists() )
		{
			require(Settings::getVar('plug_dir') . strtolower($pluginName) . '/_plugin.php');
			if( DEBUG )
			{
				Debug::Log('Plugin "' . strtolower($pluginName) . '" is activated', NOTICE);
			}
		}
		else
		{
			if( DEBUG )
			{
				Debug::Log(Settings::getVar('plug_dir') . strtolower($pluginName) . '/_plugin.php' . " doesn't exists", NOTICE);
			}
			return false;
		}
		
		if ( $p = new $pluginName )
		{
			/* register subdirs from plugin */
			$subdirs = $p->getSubDirs();
			if ( is_array($subdirs) )
			{
				foreach ( $subdirs as $dir )
				{
					if ( $registred = Settings::registerSubdir($dir, $pluginName) )
					{
						//print_r($registred);
						Debug::Log('Folder "' . $dir . '" is registered by "' . $pluginName . '"' , NOTICE);
					}
				}
			}
			return $p;
		}
	}
	
	public function listPages($pluginName)
	{
		$liste = array();
		foreach ( scandir(Settings::getVar('plug_dir') . '/' . strtolower($pluginName) . '/') as $node )
		{
			if ( ereg('.*\.php$', $node) && $node != strtolower($pluginName).'.php' )
			{
				//$liste .= '<li><a href="'.$node.'">'.$node.'</a></li>';
				array_push($liste, $node);
			}
		}
		return $liste;
	}
	
	public static function deActivatePlugin($pluginName)
	{
		Debug::Log($pluginName . " is de-activated", NOTICE);
		# TODO
		//self::$activatedPlugins
	}
	
	public static function pluginGetInfos($pluginName)
	{
		if ( in_array($pluginName, self::$activatedPlugins) )
		{
			$p = new $pluginName;
			return array( $p->getName(), $p->getVersion(), $p->getAuthor(), $p->getDescription() );
		}
		else
		{
			return 'plugin "' . $pluginName . '" not activated !';
		}
	}
}

?>
Return current item: Bee-rain