linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file class.plugin.php

Documentation is available at class.plugin.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage plugin
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Plugin Management
  10.  */
  11.  
  12. class plugin {
  13.  
  14.   private $info array();
  15.  
  16.   public function __construct($name{
  17.  
  18.     $a array();
  19.  
  20.     try{
  21.       if(!@$flow=simplexml_load_file(SITE_PATH.'plugins/'.$name.'/plugin.xml')){
  22.         throw new Exception($name.' plugin : xml file was not found');
  23.       }
  24.       $this->info['name'$name;
  25.       $this->info['shortname'str_replace('l21_'''$name);
  26.       $this->info['description'$flow->description;
  27.       $this->info['version'$flow->version;
  28.       $this->info['date'$flow->date;
  29.       $this->info['compatibility'$flow->compatibility;
  30.       $this->info['author'$flow->author;
  31.       $this->info['homepage'$flow->homepage;
  32.       $this->info['settings'= (integer) $flow->settings;
  33.       $this->info['default_language'$flow->default_language;
  34.       $this->info['image'$flow->image;
  35.       $this->info['active_path'SITE_PATH.'plugins/'.$this->info['name'].'/.active';
  36.  
  37.       /** TODO - Définir la portée du plugin sur les applications 'admin' | 'public'
  38.        * afin d'optimiser le chargement des fichiers depuis __init__.php
  39.        * **/
  40.       foreach($flow->apps->app as $el{
  41.         $this->info['apps'][]=(string) $el;
  42.       }
  43.     }
  44.     catch(Exception $e){
  45.       return $e->getMessage();
  46.     }
  47.  
  48.   }
  49.  
  50.   public function __toString({
  51.     return $this->getVar('name');
  52.   }
  53.  
  54.   public function hasImage({
  55.  
  56.     if(!empty($this->info['image'])) return true;
  57.     else return false;
  58.  
  59.   }
  60.  
  61.   public function hasAdvancedSettings({
  62.  
  63.     if($this->info['settings'== truereturn true;
  64.     else return false;
  65.  
  66.   }
  67.  
  68.   public function imagePath({
  69.  
  70.     return '../plugins/'.$this->info['name'].'/'.$this->info['image'];
  71.  
  72.   }
  73.  
  74.   public function getPluginInfo({
  75.  
  76.     return $this->info;
  77.  
  78.   }
  79.  
  80.   public function getVar($varname{
  81.  
  82.     return $this->info[$varname];
  83.   }
  84.  
  85.   public function getAvailablePlugins({
  86.  
  87.     return availablePlugins();
  88.  
  89.   }
  90.  
  91.   public function loadPlugin({
  92.     // we check if the current app is concerned by the module
  93.     if(!in_array(CURRENT_APP$this->getVar('apps'))) return false;
  94.     if(file_exists(SITE_PATH.'plugins/'.$this->info['name'].'/__init__.php')) {
  95.       include_once(SITE_PATH.'plugins/'.$this->info['name'].'/__init__.php');
  96.     }
  97.     return true;
  98.   }
  99.  
  100.   public function enable({
  101.  
  102.     $fp fopen($this->getVar('active_path')"x");
  103.     fclose($fp);
  104.  
  105.     if(file_exists(SITE_PATH.'plugins/'.$this->info['name'].'/__install__.php')) {
  106.       include_once(SITE_PATH.'plugins/'.$this->info['name'].'/__install__.php');
  107.     }
  108.  
  109.   }
  110.  
  111.   public function disable({
  112.  
  113.     return unlink($this->getVar('active_path'));
  114.  
  115.   }
  116.  
  117.   public function is_active({
  118.  
  119.     return file_exists($this->getVar('active_path'));
  120.  
  121.   }
  122.  
  123.  
  124. }
  125.  
  126. ?>

Documentation generated on Fri, 01 Apr 2011 09:29:07 +0200 by phpDocumentor 1.4.1