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
    • 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 = cString::getPartOfString($result, 0, cString::getStringLength($result) - 1);
110: 
111:             // last number is always zero
112:             return cSecurity::toInteger($result . 0);
113:         }
114:     }
115: }
116: 
117: /**
118:  * Single Plugin Manager Item
119:  */
120: class PimPlugin extends Item {
121: 
122:     /**
123:      * @var string Error storage
124:      */
125:     protected $_error;
126: 
127:     /**
128:      * Constructor Function
129:      *
130:      * @param  mixed  $id  Specifies the id of item to load
131:      */
132:     public function __construct($id = false) {
133:         $cfg = cRegistry::getConfig();
134:         parent::__construct($cfg['tab']['plugins'], 'idplugin');
135:         $this->_error = '';
136:         if ($id !== false) {
137:             $this->loadByPrimaryKey($id);
138:         }
139:     }
140: 
141:     /**
142:      * Userdefined setter for pim fields.
143:      *
144:      * @param string $name
145:      * @param mixed $value
146:      * @param bool $bSafe Flag to run defined inFilter on passed value
147:      */
148:     public function setField($name, $value, $bSafe = true) {
149:         switch ($name) {
150:             case 'idclient':
151:                 $value = (int) $value;
152:                 break;
153:             case 'active':
154:                 $value = (int) $value;
155:                 break;
156:         }
157: 
158:         return parent::setField($name, $value, $bSafe);
159:     }
160: 
161:     /**
162:      * Check dependencies
163:      * Adapted from PimPLuginSetup class
164:      *
165:      * @param integer $newOrder New executionorder value
166:      * @return boolean
167:      */
168:     public function checkDependedFromOtherPlugins($newOrder) {
169:         $cfg = cRegistry::getConfig();
170:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
171: 
172:         // Get uuid from selected plugin
173:         $pimPluginColl = new PimPluginCollection();
174:         $pimPluginColl->setWhere('idplugin', $this->get("idplugin"));
175:         $pimPluginColl->query();
176:         $pimPluginSql = $pimPluginColl->next();
177:         $uuidBase = $pimPluginSql->get('uuid');
178: 
179:         // Reset query so we can use PimPluginCollection later again...
180:         $pimPluginColl->resetQuery();
181: 
182:         // Read all dirs
183:         $dirs = cDirHandler::read($pluginsDir);
184:         foreach ($dirs as $dirname) {
185: 
186:             // Skip plugin if it has no plugin.xml file
187:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml")) {
188:                 continue;
189:             }
190: 
191:             // Read plugin.xml files from existing plugins at contenido/plugins dir
192:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml");
193: 
194:             // Write plugin.xml content into temporary variable
195:             $tempXml = simplexml_load_string($tempXmlContent);
196: 
197:             $dependenciesCount = count($tempXml->dependencies);
198:             for ($i = 0; $i < $dependenciesCount; $i++) {
199: 
200:                 // Security check
201:                 $depend = cSecurity::escapeString($tempXml->dependencies->depend[$i]);
202: 
203:                 // If is no dependencie name defined please go to next dependencie
204:                 if ($depend == "") {
205:                     continue;
206:                 }
207: 
208:                 // Build uuid variable from attributes
209:                 foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
210: 
211:                     // We use only uuid attribute and can ignore other attributes
212:                     if ($key == "uuid") {
213: 
214:                         $uuidTemp = cSecurity::escapeString($value);
215: 
216:                         if ($uuidBase === $uuidTemp) {
217: 
218:                             // Prüfe, ob das Kindplugin aktiv ist
219:                             $pimPluginColl->setWhere('uuid', $tempXml->general->uuid);
220:                             $pimPluginColl->setWhere('active', '1');
221:                             $pimPluginColl->query();
222: 
223:                             if ($pimPluginColl->count() == 0) {
224:                                 continue;
225:                             }
226: 
227:                             $result = $pimPluginColl->next();
228: 
229:                             if ($newOrder == $result->get('executionorder')) {
230:                                 return false;
231:                             }
232:                         }
233:                     }
234:                 }
235:             }
236:         }
237: 
238:         return true;
239:     }
240: 
241:     /**
242:      * Check dependencies
243:      * Adapted from PimPLuginSetup class
244:      *
245:      * @param integer $newOrder New executionorder value
246:      * @return boolean
247:      */
248:     public function checkDependenciesToOtherPlugins($newOrder) {
249:         $cfg = cRegistry::getConfig();
250:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
251: 
252:         // Get uuid from selected plugin
253:         $pimPluginColl = new PimPluginCollection();
254:         $pimPluginColl->setWhere('idplugin', $this->get("idplugin"));
255:         $pimPluginColl->query();
256:         $pimPluginSql = $pimPluginColl->next();
257:         $folderBase = $pimPluginSql->get('folder');
258:         $uuidBase = $pimPluginSql->get('uuid');
259: 
260:         // Reset query so we can use PimPluginCollection later again...
261:         $pimPluginColl->resetQuery();
262: 
263:         // Skip plugin if it has no plugin.xml file
264:         if (!cFileHandler::exists($pluginsDir . $folderBase . DIRECTORY_SEPARATOR . "plugin.xml")) {
265:             return true;
266:         }
267: 
268:         // Read plugin.xml files from existing plugins at contenido/plugins dir
269:         $tempXmlContent = cFileHandler::read($pluginsDir . $folderBase . DIRECTORY_SEPARATOR . "plugin.xml");
270: 
271:         // Write plugin.xml content into temporary variable
272:         $tempXml = simplexml_load_string($tempXmlContent);
273: 
274:         // Initializing dependencies array
275:         $dependenciesBase = array();
276: 
277:         $dependenciesCount = count($tempXml->dependencies);
278:         for ($i = 0; $i < $dependenciesCount; $i++) {
279: 
280:             foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
281:                 $dependenciesBase[] = cSecurity::escapeString($value);
282:             }
283: 
284:         }
285: 
286:         // Read all dirs
287:         $dirs = cDirHandler::read($pluginsDir);
288:         foreach ($dirs as $dirname) {
289: 
290:             // Skip plugin if it has no plugin.xml file
291:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml")) {
292:                 continue;
293:             }
294: 
295:             // Read plugin.xml files from existing plugins at contenido/plugins dir
296:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml");
297: 
298:             // Write plugin.xml content into temporary variable
299:             $tempXml = simplexml_load_string($tempXmlContent);
300: 
301:             if (in_array($tempXml->general->uuid, $dependenciesBase) === true) {
302: 
303:                 $pimPluginColl->setWhere('uuid', $tempXml->general->uuid);
304:                 $pimPluginColl->query();
305:                 $result = $pimPluginColl->next();
306: 
307:                 if ($newOrder == $result->get('executionorder')) {
308:                     return false;
309:                 }
310:             }
311:         }
312: 
313:         return true;
314:     }
315: 
316:     /**
317:      * Change the execution order of this plugin and update the order for every other plugin
318:      *
319:      * @param int $newOrder New execution order for this plugin
320:      * @return boolean
321:      */
322:     public function updateExecOrder($newOrder) {
323: 
324:         $dependendFromOtherPlugins = $this->checkDependedFromOtherPlugins($newOrder);
325:         $dependenciesToOtherPlugins = $this->checkDependenciesToOtherPlugins($newOrder);
326: 
327:         if ($dependendFromOtherPlugins === false || $dependenciesToOtherPlugins === false) {
328:             return false;
329:         }
330: 
331:         $oldOrder = $this->get('executionorder'); // get the old value
332:         $idplugin = $this->get("idplugin");
333: 
334:         $this->set('executionorder', $newOrder); // update this plugin to the new value
335:         $this->store();
336: 
337:         // move the other plugins up or down
338:         $pluginColl = new PimPluginCollection();
339:         $pluginColl->select('executionorder >= "' . min($newOrder, $oldOrder) . '" AND executionorder <= "' . max($newOrder, $oldOrder) . '" AND idplugin != "' . $idplugin . '"', NULL, 'executionorder'); // select every plugin that needs to be updated
340: 
341:         while ($plugin = $pluginColl->next()) {
342:             if ($newOrder < $oldOrder) {
343:                 $plugin->set("executionorder", $plugin->get("executionorder") + 1); // increment the execution order after we moved the plugin up
344:                 $plugin->store();
345:             } else if ($oldOrder < $newOrder) {
346:                 $plugin->set("executionorder", $plugin->get("executionorder") - 1); // decrement the execution value after we moved the plugin down
347:                 $plugin->store();
348:             }
349:         }
350: 
351:         return true;
352:     }
353: 
354:     /**
355:      * Check if plugin exists and is active
356:      *
357:      * @param string $pluginname
358:      * @return bool true iv available, false if it is not available
359:      */
360:     public function isPluginAvailable($pluginname) {
361:         return $this->loadByMany(array(
362:             'idclient' => cRegistry::getClientId(),
363:             'name' => $pluginname,
364:             'active' => 1
365:         ));
366:     }
367: }
368: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0