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

Documentation generated on Mon, 08 Apr 2013 18:12:53 +0200 by phpDocumentor 1.4.1