Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • PimPluginViewDependencies
  • 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:  * @author Frederic Schneider
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Plugin Manager recipient class.
 18:  *
 19:  * @package     Plugin
 20:  * @subpackage  PluginManager
 21:  * @author Frederic Schneider
 22:  */
 23: class PimPluginCollection extends ItemCollection {
 24: 
 25:     /**
 26:      * Constructor Function
 27:      *
 28:      * @param none
 29:      */
 30:     public function __construct() {
 31:         global $cfg;
 32:         parent::__construct($cfg['tab']['plugins'], 'idplugin');
 33:         $this->_setItemClass('PimPlugin');
 34:     }
 35: 
 36:     /**
 37:      * Create a new plugin
 38:      * 
 39:      * @param     $name
 40:      * @param     $description
 41:      * @param     $author
 42:      * @param     $copyright
 43:      * @param     $mail
 44:      * @param     $website
 45:      * @param     $version
 46:      * @param     $foldername
 47:      * @param     $uuId
 48:      * @param     $active
 49:      * @param int $execOrder
 50:      *
 51:      * @return Item
 52:      */
 53:     public function create($name, $description, $author, $copyright, $mail, $website, $version, $foldername, $uuId, $active, $execOrder = 0) {
 54:         global $client;
 55: 
 56:         $nextId = $this->_getNextId();
 57: 
 58:         // create a new entry
 59:         $item = $this->createNewItem($nextId);
 60:         $item->set('idclient', $client);
 61:         $item->set('name', $name);
 62:         $item->set('description', $description);
 63:         $item->set('author', $author);
 64:         $item->set('copyright', $copyright);
 65:         $item->set('mail', $mail);
 66:         $item->set('website', $website);
 67:         $item->set('version', $version);
 68:         $item->set('folder', $foldername);
 69:         $item->set('uuid', $uuId);
 70:         $item->set('installed', date("Y-m-d H:i:s"), false);
 71:         $item->set('active', $active);
 72: 
 73:         // set execution order to the last of the list or to what was specified in create
 74:         if ($execOrder == 0) {
 75:             $this->select();
 76:             $execOrder = $this->count();
 77:         }
 78:         $item->set("executionorder", $execOrder);
 79: 
 80:         $item->store();
 81: 
 82:         return $item;
 83:     }
 84: 
 85:     /**
 86:      * Get the next id in table *_plugins
 87:      *
 88:      * @return int
 89:      */
 90:     protected function _getNextId() {
 91:         $cfg = cRegistry::getConfig();
 92: 
 93:         $sql = 'SELECT MAX(idplugin) AS id FROM ' . $cfg['tab']['plugins'];
 94:         $this->db->query($sql);
 95: 
 96:         if ($this->db->nextRecord()) {
 97: 
 98:             $result = $this->db->f('id');
 99: 
100:             // id must be over 10.000
101:             if ($result < 10000) {
102:                 $result = 10000;
103:             }
104: 
105:             // add ten
106:             $result = $result + 10;
107: 
108:             // removed the last number
109:             $result = substr($result, 0, strlen($result) - 1);
110: 
111:             // last number is always zero
112:             return cSecurity::toInteger($result . 0);
113:         }
114:     }
115: 
116: }
117: 
118: /**
119:  * Single Plugin Manager Item
120:  */
121: class PimPlugin extends Item {
122: 
123:     /**
124:      * @var string Error storage
125:      */
126:     protected $_error;
127: 
128:     /**
129:      * Constructor Function
130:      *
131:      * @param  mixed  $id  Specifies the id of item to load
132:      */
133:     public function __construct($id = false) {
134:         $cfg = cRegistry::getConfig();
135:         parent::__construct($cfg['tab']['plugins'], 'idplugin');
136:         $this->_error = '';
137:         if ($id !== false) {
138:             $this->loadByPrimaryKey($id);
139:         }
140:     }
141: 
142:     /**
143:      * Userdefined setter for pim fields.
144:      *
145:      * @param string $name
146:      * @param mixed $value
147:      * @param bool $bSafe Flag to run defined inFilter on passed value
148:      */
149:     public function setField($name, $value, $bSafe = true) {
150:         switch ($name) {
151:             case 'idclient':
152:                 $value = (int) $value;
153:                 break;
154:             case 'active':
155:                 $value = (int) $value;
156:                 break;
157:         }
158: 
159:         return parent::setField($name, $value, $bSafe);
160:     }
161: 
162:     /**
163:      * Check dependencies
164:      * Adapted from PimPLuginSetup class
165:      *
166:      * @param integer $newOrder New executionorder value
167:      * @return boolean
168:      */
169:     public function checkDependedFromOtherPlugins($newOrder) {
170:         $cfg = cRegistry::getConfig();
171:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
172: 
173:         // Get uuid from selected plugin
174:         $pimPluginColl = new PimPluginCollection();
175:         $pimPluginColl->setWhere('idplugin', $this->get("idplugin"));
176:         $pimPluginColl->query();
177:         $pimPluginSql = $pimPluginColl->next();
178:         $uuidBase = $pimPluginSql->get('uuid');
179: 
180:         // Reset query so we can use PimPluginCollection later again...
181:         $pimPluginColl->resetQuery();
182: 
183:         // Read all dirs
184:         $dirs = cDirHandler::read($pluginsDir);
185:         foreach ($dirs as $dirname) {
186: 
187:             // Skip plugin if it has no plugin.xml file
188:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml")) {
189:                 continue;
190:             }
191: 
192:             // Read plugin.xml files from existing plugins at contenido/plugins dir
193:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml");
194: 
195:             // Write plugin.xml content into temporary variable
196:             $tempXml = simplexml_load_string($tempXmlContent);
197: 
198:             $dependenciesCount = count($tempXml->dependencies);
199:             for ($i = 0; $i < $dependenciesCount; $i++) {
200: 
201:                 // Security check
202:                 $depend = cSecurity::escapeString($tempXml->dependencies->depend[$i]);
203: 
204:                 // If is no dependencie name defined please go to next dependencie
205:                 if ($depend == "") {
206:                     continue;
207:                 }
208: 
209:                 // Build uuid variable from attributes
210:                 foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
211: 
212:                     // We use only uuid attribute and can ignore other attributes
213:                     if ($key == "uuid") {
214: 
215:                         $uuidTemp = cSecurity::escapeString($value);
216: 
217:                         if ($uuidBase === $uuidTemp) {
218: 
219:                             // Prüfe, ob das Kindplugin aktiv ist
220:                             $pimPluginColl->setWhere('uuid', $tempXml->general->uuid);
221:                             $pimPluginColl->setWhere('active', '1');
222:                             $pimPluginColl->query();
223: 
224:                             if ($pimPluginColl->count() == 0) {
225:                                 continue;
226:                             }
227: 
228:                             $result = $pimPluginColl->next();
229: 
230:                             if ($newOrder == $result->get('executionorder')) {
231:                                 return false;
232:                             }
233:                         }
234:                     }
235:                 }
236:             }
237:         }
238: 
239:         return true;
240:     }
241: 
242:     /**
243:      * Check dependencies
244:      * Adapted from PimPLuginSetup class
245:      *
246:      * @param integer $newOrder New executionorder value
247:      * @return boolean
248:      */
249:     public function checkDependenciesToOtherPlugins($newOrder) {
250:         $cfg = cRegistry::getConfig();
251:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
252: 
253:         // Get uuid from selected plugin
254:         $pimPluginColl = new PimPluginCollection();
255:         $pimPluginColl->setWhere('idplugin', $this->get("idplugin"));
256:         $pimPluginColl->query();
257:         $pimPluginSql = $pimPluginColl->next();
258:         $folderBase = $pimPluginSql->get('folder');
259:         $uuidBase = $pimPluginSql->get('uuid');
260: 
261:         // Reset query so we can use PimPluginCollection later again...
262:         $pimPluginColl->resetQuery();
263: 
264:         // Skip plugin if it has no plugin.xml file
265:         if (!cFileHandler::exists($pluginsDir . $folderBase . DIRECTORY_SEPARATOR . "plugin.xml")) {
266:             return true;
267:         }
268: 
269:         // Read plugin.xml files from existing plugins at contenido/plugins dir
270:         $tempXmlContent = cFileHandler::read($pluginsDir . $folderBase . DIRECTORY_SEPARATOR . "plugin.xml");
271: 
272:         // Write plugin.xml content into temporary variable
273:         $tempXml = simplexml_load_string($tempXmlContent);
274: 
275:         // Initializing dependencies array
276:         $dependenciesBase = array();
277: 
278:         $dependenciesCount = count($tempXml->dependencies);
279:         for ($i = 0; $i < $dependenciesCount; $i++) {
280: 
281:             foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
282:                 $dependenciesBase[] = cSecurity::escapeString($value);
283:             }
284: 
285:         }
286: 
287:         // Read all dirs
288:         $dirs = cDirHandler::read($pluginsDir);
289:         foreach ($dirs as $dirname) {
290: 
291:             // Skip plugin if it has no plugin.xml file
292:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml")) {
293:                 continue;
294:             }
295: 
296:             // Read plugin.xml files from existing plugins at contenido/plugins dir
297:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml");
298: 
299:             // Write plugin.xml content into temporary variable
300:             $tempXml = simplexml_load_string($tempXmlContent);
301: 
302:             if (in_array($tempXml->general->uuid, $dependenciesBase) === true) {
303: 
304:                 $pimPluginColl->setWhere('uuid', $tempXml->general->uuid);
305:                 $pimPluginColl->query();
306:                 $result = $pimPluginColl->next();
307: 
308:                 if ($newOrder == $result->get('executionorder')) {
309:                     return false;
310:                 }
311:             }
312:         }
313: 
314:         return true;
315:     }
316: 
317:     /**
318:      * Change the execution order of this plugin and update the order for every other plugin
319:      *
320:      * @param int $newOrder New execution order for this plugin
321:      * @return boolean
322:      */
323:     public function updateExecOrder($newOrder) {
324: 
325:         $dependendFromOtherPlugins = $this->checkDependedFromOtherPlugins($newOrder);
326:         $dependenciesToOtherPlugins = $this->checkDependenciesToOtherPlugins($newOrder);
327: 
328:         if ($dependendFromOtherPlugins === false || $dependenciesToOtherPlugins === false) {
329:             return false;
330:         }
331: 
332:         $oldOrder = $this->get('executionorder'); // get the old value
333:         $idplugin = $this->get("idplugin");
334: 
335:         $this->set('executionorder', $newOrder); // update this plugin to the new value
336:         $this->store();
337: 
338:         // move the other plugins up or down
339:         $pluginColl = new PimPluginCollection();
340:         $pluginColl->select('executionorder >= "' . min($newOrder, $oldOrder) . '" AND executionorder <= "' . max($newOrder, $oldOrder) . '" AND idplugin != "' . $idplugin . '"', NULL, 'executionorder'); // select every plugin that needs to be updated
341: 
342:         while ($plugin = $pluginColl->next()) {
343:             if ($newOrder < $oldOrder) {
344:                 $plugin->set("executionorder", $plugin->get("executionorder") + 1); // increment the execution order after we moved the plugin up
345:                 $plugin->store();
346:             } else if ($oldOrder < $newOrder) {
347:                 $plugin->set("executionorder", $plugin->get("executionorder") - 1); // decrement the execution value after we moved the plugin down
348:                 $plugin->store();
349:             }
350:         }
351: 
352:         return true;
353:     }
354: }
355: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0