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 Simon Georget <simon@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.     protected $dispatcher = null;
  16.  
  17.     public function __construct($name{
  18.  
  19.         $a array();
  20.         $this->dispatcher = $GLOBALS['dispatcher'];
  21.  
  22.         try{
  23.  
  24.             if(!@$flow=simplexml_load_file(SITE_PATH.'plugins/'.$name.'/plugin.xml')){
  25.                 throw new Exception($name.' plugin : xml file was not found');
  26.             }
  27.  
  28.             $this->info['name'$name;
  29.             $this->info['shortname'str_replace('l21_'''$name);
  30.             $this->info['description'$flow->description;
  31.             $this->info['version'$flow->version;
  32.             $this->info['date'$flow->date;
  33.             $this->info['compatibility'$flow->compatibility;
  34.             $this->info['author'$flow->author;
  35.             $this->info['homepage'$flow->homepage;
  36.             $this->info['settings'= (integer) $flow->settings;
  37.             $this->info['default_language'$flow->default_language;
  38.             $this->info['status'$flow->status;
  39.             $this->info['image'$flow->image;
  40.             $this->info['active_path'SITE_PATH.'plugins/'.$this->info['name'].'/.active';
  41.             $this->info['active_url'SITE_ROOT_URL.'plugins/'.$this->info['name'].'/';
  42.             $this->info['relative_url''../plugins/'.$this->info['name'].'/';
  43.  
  44.             if($flow->apps->app != null{
  45.                 foreach($flow->apps->app as $el{
  46.                     $this->info['apps'][]=(string) $el;
  47.                 }
  48.             }
  49.         }
  50.         catch(Exception $e){
  51.             return $e->getMessage();
  52.         }
  53.  
  54.     }
  55.  
  56.     public function __toString({
  57.         return $this->getVar('name');
  58.     }
  59.  
  60.     public function hasImage({
  61.  
  62.         if(!empty($this->info['image'])) return true;
  63.         else return false;
  64.  
  65.     }
  66.  
  67.     public function hasAdvancedSettings({
  68.  
  69.         if($this->info['settings'== truereturn true;
  70.         else return false;
  71.  
  72.     }
  73.  
  74.     public function imagePath({
  75.  
  76.         return '../plugins/'.$this->info['name'].'/'.$this->info['image'];
  77.  
  78.     }
  79.  
  80.     public function getPluginInfo({
  81.  
  82.         return $this->info;
  83.  
  84.     }
  85.  
  86.     public function getVar($varname{
  87.  
  88.         if(isset($this->info[$varname])) {
  89.             return $this->info[$varname];
  90.         else {
  91.             return false;
  92.         }
  93.     }
  94.  
  95.     public function getAvailablePlugins({
  96.  
  97.         return availablePlugins();
  98.  
  99.     }
  100.  
  101.     public function loadPlugin({
  102.     
  103.         $test true;
  104.         
  105.         // Notify the beginning of the current method
  106.         $this->dispatcher->notify(new sfEvent($this'plugin.load'));
  107.         
  108.         // we check if the current app is concerned by the module or if we are in current plugin page (back-office)
  109.         if(($this->getVar('apps'&& in_array(CURRENT_APP$this->getVar('apps'))) || (isset($_REQUEST['current']&& isset($_REQUEST['rub']&& $_REQUEST['rub'== 'plugins' && $_REQUEST['current'== $this->info['name'])) {
  110.             IncludeLanguagesPluginfiles($this);
  111.             if(file_exists(SITE_PATH.'plugins/'.$this->info['name'].'/__init__.php')) {
  112.                 include_once(SITE_PATH.'plugins/'.$this->info['name'].'/__init__.php');
  113.             }
  114.             return true;
  115.         else {
  116.             return false;
  117.         }
  118.     }
  119.  
  120.     public function enable({
  121.  
  122.         // Notify the beginning of the current method
  123.         $this->dispatcher->notify(new sfEvent($this'plugin.enable'));
  124.  
  125.         $fp fopen($this->getVar('active_path')"x");
  126.         fclose($fp);
  127.  
  128.         if(file_exists(SITE_PATH.'plugins/'.$this->info['name'].'/__install__.php')) {
  129.             include_once(SITE_PATH.'plugins/'.$this->info['name'].'/__install__.php');
  130.         }
  131.  
  132.     }
  133.  
  134.     public function disable({
  135.         // Notify the beginning of the current method
  136.         $this->dispatcher->notify(new sfEvent($this'plugin.disable'));
  137.  
  138.         return unlink($this->getVar('active_path'));
  139.  
  140.     }
  141.  
  142.     public function is_active({
  143.  
  144.         return file_exists($this->getVar('active_path'));
  145.  
  146.     }
  147.  
  148.     public function retrieveValues($sqlo{
  149.  
  150.         // Notify the beginning of the current method
  151.         $this->dispatcher->notify(new sfEvent($this'plugin.retrieve_values'));
  152.         
  153.         $q 'SELECT plugin_values FROM '.T_PLUGIN' WHERE plugin_name = "'.$this->getVar('name').'"';
  154.         $r $sqlo->DBSelect($q);
  155.  
  156.         if(isset($r[0]['plugin_values'])){
  157.             return unserialize($r[0]['plugin_values']);
  158.         else {
  159.             return false;
  160.         }
  161.     }
  162.  
  163.     public function storeValues($array$sqlo{
  164.         
  165.         // Notify the beginning of the current method
  166.         $this->dispatcher->notify(new sfEvent($this'plugin.store_values'));
  167.  
  168.         // test if plugin is already registerd
  169.         if($this->isDatabaseRegistered($sqlo)) {
  170.  
  171.             $q 'UPDATE '.T_PLUGIN' SET plugin_values="'.$sqlo->DBescape(serialize($array)).'" WHERE plugin_name = "'.$this->getVar('name').'";';
  172.             $r $sqlo->DBQuery($q);
  173.  
  174.         else {
  175.  
  176.             $q 'INSERT INTO '.T_PLUGIN' (plugin_name, plugin_values, plugin_date_crea) VALUES("'.$this->getVar('name').'",  "'.$sqlo->DBescape(serialize($array)).'", NOW());';
  177.             $r $sqlo->DBInsert($q);
  178.         }
  179.  
  180.     return $r;
  181.  
  182.     }
  183.  
  184.     public function isDatabaseRegistered($sqlo{
  185.  
  186.         $q 'SELECT plugin_values FROM '.T_PLUGIN' WHERE plugin_name = "'.$this->getVar('name').'"';
  187.         $r $sqlo->DBSelect($q);
  188.  
  189.         if(isset($r[0]['plugin_values'])) return true;
  190.         else return false;
  191.  
  192.     }
  193.  
  194.  
  195. }
  196.  
  197. ?>

Documentation generated on Thu, 20 Mar 2014 16:46:38 +0100 by phpDocumentor 1.4.1