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