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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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:         $cfg = cRegistry::getConfig();
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:      * Check dependencies
154:      * Adapted from PimPLuginSetup class
155:      *
156:      * @param integer $newOrder New executionorder value
157:      * @return boolean
158:      */
159:     public function checkDependedFromOtherPlugins($newOrder) {
160:         $cfg = cRegistry::getConfig();
161:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
162: 
163:         // Get uuid from selected plugin
164:         $pimPluginColl = new PimPluginCollection();
165:         $pimPluginColl->setWhere('idplugin', $this->get("idplugin"));
166:         $pimPluginColl->query();
167:         $pimPluginSql = $pimPluginColl->next();
168:         $uuidBase = $pimPluginSql->get('uuid');
169: 
170:         // Reset query so we can use PimPluginCollection later again...
171:         $pimPluginColl->resetQuery();
172: 
173:         // Read all dirs
174:         $dirs = cDirHandler::read($pluginsDir);
175:         foreach ($dirs as $dirname) {
176: 
177:             // Skip plugin if it has no plugin.xml file
178:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml")) {
179:                 continue;
180:             }
181: 
182:             // Read plugin.xml files from existing plugins at contenido/plugins dir
183:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml");
184: 
185:             // Write plugin.xml content into temporary variable
186:             $tempXml = simplexml_load_string($tempXmlContent);
187: 
188:             $dependenciesCount = count($tempXml->dependencies);
189:             for ($i = 0; $i < $dependenciesCount; $i++) {
190: 
191:                 // Security check
192:                 $depend = cSecurity::escapeString($tempXml->dependencies->depend[$i]);
193: 
194:                 // If is no dependencie name defined please go to next dependencie
195:                 if ($depend == "") {
196:                     continue;
197:                 }
198: 
199:                 // Build uuid variable from attributes
200:                 foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
201: 
202:                     // We use only uuid attribute and can ignore other attributes
203:                     if ($key == "uuid") {
204: 
205:                         $uuidTemp = cSecurity::escapeString($value);
206: 
207:                         if ($uuidBase === $uuidTemp) {
208: 
209:                             // Prüfe, ob das Kindplugin aktiv ist
210:                             $pimPluginColl->setWhere('uuid', $tempXml->general->uuid);
211:                             $pimPluginColl->setWhere('active', '1');
212:                             $pimPluginColl->query();
213: 
214:                             if ($pimPluginColl->count() == 0) {
215:                                 continue;
216:                             }
217: 
218:                             $result = $pimPluginColl->next();
219: 
220:                             if ($newOrder == $result->get('executionorder')) {
221:                                 return false;
222:                             }
223:                         }
224:                     }
225:                 }
226:             }
227:         }
228: 
229:         return true;
230:     }
231: 
232:     /**
233:      * Check dependencies
234:      * Adapted from PimPLuginSetup class
235:      *
236:      * @param integer $newOrder New executionorder value
237:      * @return boolean
238:      */
239:     public function checkDependenciesToOtherPlugins($newOrder) {
240:         $cfg = cRegistry::getConfig();
241:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
242: 
243:         // Get uuid from selected plugin
244:         $pimPluginColl = new PimPluginCollection();
245:         $pimPluginColl->setWhere('idplugin', $this->get("idplugin"));
246:         $pimPluginColl->query();
247:         $pimPluginSql = $pimPluginColl->next();
248:         $folderBase = $pimPluginSql->get('folder');
249:         $uuidBase = $pimPluginSql->get('uuid');
250: 
251:         // Reset query so we can use PimPluginCollection later again...
252:         $pimPluginColl->resetQuery();
253: 
254:         // Skip plugin if it has no plugin.xml file
255:         if (!cFileHandler::exists($pluginsDir . $folderBase . DIRECTORY_SEPARATOR . "plugin.xml")) {
256:             return true;
257:         }
258: 
259:         // Read plugin.xml files from existing plugins at contenido/plugins dir
260:         $tempXmlContent = cFileHandler::read($pluginsDir . $folderBase . DIRECTORY_SEPARATOR . "plugin.xml");
261: 
262:         // Write plugin.xml content into temporary variable
263:         $tempXml = simplexml_load_string($tempXmlContent);
264: 
265:         // Initializing dependencies array
266:         $dependenciesBase = array();
267: 
268:         $dependenciesCount = count($tempXml->dependencies);
269:         for ($i = 0; $i < $dependenciesCount; $i++) {
270: 
271:             foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
272:                 $dependenciesBase[] = cSecurity::escapeString($value);
273:             }
274: 
275:         }
276: 
277:         // Read all dirs
278:         $dirs = cDirHandler::read($pluginsDir);
279:         foreach ($dirs as $dirname) {
280: 
281:             // Skip plugin if it has no plugin.xml file
282:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml")) {
283:                 continue;
284:             }
285: 
286:             // Read plugin.xml files from existing plugins at contenido/plugins dir
287:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . "plugin.xml");
288: 
289:             // Write plugin.xml content into temporary variable
290:             $tempXml = simplexml_load_string($tempXmlContent);
291: 
292:             if (in_array($tempXml->general->uuid, $dependenciesBase) === true) {
293: 
294:                 $pimPluginColl->setWhere('uuid', $tempXml->general->uuid);
295:                 $pimPluginColl->query();
296:                 $result = $pimPluginColl->next();
297: 
298:                 if ($newOrder == $result->get('executionorder')) {
299:                     return false;
300:                 }
301:             }
302:         }
303: 
304:         return true;
305:     }
306: 
307:     /**
308:      * Change the execution order of this plugin and update the order for every other plugin
309:      *
310:      * @param int $newOrder New execution order for this plugin
311:      * @return boolean
312:      */
313:     public function updateExecOrder($newOrder) {
314: 
315:         $dependendFromOtherPlugins = $this->checkDependedFromOtherPlugins($newOrder);
316:         $dependenciesToOtherPlugins = $this->checkDependenciesToOtherPlugins($newOrder);
317: 
318:         if ($dependendFromOtherPlugins === false || $dependenciesToOtherPlugins === false) {
319:             return false;
320:         }
321: 
322:         $oldOrder = $this->get('executionorder'); // get the old value
323:         $idplugin = $this->get("idplugin");
324: 
325:         $this->set('executionorder', $newOrder); // update this plugin to the new value
326:         $this->store();
327: 
328:         // move the other plugins up or down
329:         $pluginColl = new PimPluginCollection();
330:         $pluginColl->select('executionorder >= "' . min($newOrder, $oldOrder) . '" AND executionorder <= "' . max($newOrder, $oldOrder) . '" AND idplugin != "' . $idplugin . '"', NULL, 'executionorder'); // select every plugin that needs to be updated
331: 
332:         while ($plugin = $pluginColl->next()) {
333:             if ($newOrder < $oldOrder) {
334:                 $plugin->set("executionorder", $plugin->get("executionorder") + 1); // increment the execution order after we moved the plugin up
335:                 $plugin->store();
336:             } else if ($oldOrder < $newOrder) {
337:                 $plugin->set("executionorder", $plugin->get("executionorder") - 1); // decrement the execution value after we moved the plugin down
338:                 $plugin->store();
339:             }
340:         }
341: 
342:         return true;
343:     }
344: }
345: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen