Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • PimPlugin
  • PimPluginArchiveExtractor
  • PimPluginCollection
  • PimPluginRelations
  • PimPluginRelationsCollection
  • PimPluginSetup
  • PimPluginSetupInstall
  • PimPluginSetupStatus
  • PimPluginSetupUninstall
  • PimPluginSetupUpdate
  • PimPluginViewNavSub
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains Plugin Manager class.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage PluginManager
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Frederic Schneider
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Plugin Manager recipient class.
 20:  *
 21:  * @package     Plugin
 22:  * @subpackage  PluginManager
 23:  * @author Frederic Schneider
 24:  */
 25: class PimPluginCollection extends ItemCollection {
 26: 
 27:     /**
 28:      * Constructor Function
 29:      *
 30:      * @param none
 31:      */
 32:     public function __construct() {
 33:         global $cfg;
 34:         parent::__construct($cfg['tab']['plugins'], 'idplugin');
 35:         $this->_setItemClass('PimPlugin');
 36:     }
 37: 
 38:     /**
 39:      * Create a new plugin
 40:      *
 41:      * @param none
 42:      */
 43:     public function create($name, $description, $author, $copyright, $mail, $website, $version, $foldername, $uuId, $active, $execOrder = 0) {
 44:         global $client;
 45: 
 46:         $nextId = $this->_getNextId();
 47: 
 48:         // create a new entry
 49:         $item = $this->createNewItem($nextId);
 50:         $item->set('idclient', $client);
 51:         $item->set('name', $name);
 52:         $item->set('description', $description);
 53:         $item->set('author', $author);
 54:         $item->set('copyright', $copyright);
 55:         $item->set('mail', $mail);
 56:         $item->set('website', $website);
 57:         $item->set('version', $version);
 58:         $item->set('folder', $foldername);
 59:         $item->set('uuid', $uuId);
 60:         $item->set('installed', date("Y-m-d H:i:s"), false);
 61:         $item->set('active', $active);
 62: 
 63:         // set execution order to the last of the list or to what was specified in create
 64:         if ($execOrder == 0) {
 65:             $this->select();
 66:             $execOrder = $this->count();
 67:         }
 68:         $item->set("executionorder", $execOrder);
 69: 
 70:         $item->store();
 71: 
 72:         return $item;
 73:     }
 74: 
 75:     /**
 76:      * Get the next id in table *_plugins
 77:      *
 78:      * @return int
 79:      */
 80:     protected function _getNextId() {
 81:         global $cfg;
 82: 
 83:         $sql = 'SELECT MAX(idplugin) AS id FROM ' . $cfg['tab']['plugins'];
 84:         $this->db->query($sql);
 85: 
 86:         if ($this->db->nextRecord()) {
 87: 
 88:             $result = $this->db->f('id');
 89: 
 90:             // id must be over 10.000
 91:             if ($result < 10000) {
 92:                 $result = 10000;
 93:             }
 94: 
 95:             // add ten
 96:             $result = $result + 10;
 97: 
 98:             // removed the last number
 99:             $result = substr($result, 0, strlen($result) - 1);
100: 
101:             // last number is always zero
102:             return cSecurity::toInteger($result . 0);
103:         }
104:     }
105: 
106: }
107: 
108: /**
109:  * Single Plugin Manager Item
110:  */
111: class PimPlugin extends Item {
112: 
113:     /**
114:      * @var string Error storage
115:      */
116:     protected $_error;
117: 
118:     /**
119:      * Constructor Function
120:      *
121:      * @param  mixed  $id  Specifies the id of item to load
122:      */
123:     public function __construct($id = false) {
124:         global $cfg;
125:         parent::__construct($cfg['tab']['plugins'], 'idplugin');
126:         $this->_error = '';
127:         if ($id !== false) {
128:             $this->loadByPrimaryKey($id);
129:         }
130:     }
131: 
132:     /**
133:      * Userdefined setter for pim fields.
134:      *
135:      * @param string $name
136:      * @param mixed $value
137:      * @param bool $bSafe Flag to run defined inFilter on passed value
138:      */
139:     public function setField($name, $value, $bSafe = true) {
140:         switch ($name) {
141:             case 'idclient':
142:                 $value = (int) $value;
143:                 break;
144:             case 'active':
145:                 $value = (int) $value;
146:                 break;
147:         }
148: 
149:         return parent::setField($name, $value, $bSafe);
150:     }
151: 
152:     /**
153:      * Change the execution order of this plugin and update the order for every other plugin
154:      *
155:      * @param int $newOrder New execution order for this plugin
156:      */
157:     public function updateExecOrder($newOrder) {
158:         $oldOrder = $this->get('executionorder'); // get the old value
159:         $idplugin = $this->get("idplugin");
160: 
161:         $this->set('executionorder', $newOrder); // update this plugin to the new value
162:         $this->store();
163: 
164:         // move the other plugins up or down
165:         $pluginColl = new PimPluginCollection();
166:         $pluginColl->select('executionorder >= "' . min($newOrder, $oldOrder) . '" AND executionorder <= "' . max($newOrder, $oldOrder) . '" AND idplugin != "' . $idplugin . '"', NULL, 'executionorder'); // select every plugin that needs to be updated
167: 
168:         while ($plugin = $pluginColl->next()) {
169:             if ($newOrder < $oldOrder) {
170:                 $plugin->set("executionorder", $plugin->get("executionorder") + 1); // increment the execution order after we moved the plugin up
171:                 $plugin->store();
172:             } else if ($oldOrder < $newOrder) {
173:                 $plugin->set("executionorder", $plugin->get("executionorder") - 1); // decrement the execution value after we moved the plugin down
174:                 $plugin->store();
175:             }
176:         }
177:     }
178: }
179: 
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0