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 abstract class for CONTENIDO plugins
  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:  * Standard class for Plugin Manager (PIM)
 20:  *
 21:  * @package Plugin
 22:  * @subpackage PluginManager
 23:  * @author frederic.schneider
 24:  */
 25: class PimPluginSetup {
 26: 
 27:     // Initializing variables
 28:     // Variable for installation / update mode:
 29:     // Extracted or uploaded file?
 30:     public static $mode = 0;
 31: 
 32:     // File name of Xml configuration file for plugins
 33:     const PLUGIN_XML_FILENAME = "plugin.xml";
 34: 
 35:     // Specific sql prefix
 36:     const SQL_PREFIX = "!PREFIX!";
 37: 
 38:     // Class variable for cGuiPage
 39:     protected static $_GuiPage;
 40: 
 41:     // Class variable for PimPluginArchiveExtractor
 42:     protected static $_PimPluginArchiveExtractor;
 43: 
 44:     /**
 45:      * Help variable.
 46:      * If this variable is true PIM does not run uninstall and install
 47:      * sql file. Standard value: false (update sql file does not exist)
 48:      *
 49:      * @var boolean
 50:      */
 51:     private static $_updateSqlFileExist = false;
 52: 
 53:     // Xml variables
 54:     // General informations of plugin
 55:     public static $XmlGeneral;
 56: 
 57:     // Plugin requirements
 58:     public static $XmlRequirements;
 59: 
 60:     // Plugin dependencies
 61:     public static $XmlDependencies;
 62: 
 63:     // CONTENIDO areas: *_area
 64:     public static $XmlArea;
 65: 
 66:     // CONTENIDO actions: *_actions
 67:     public static $XmlActions;
 68: 
 69:     // CONTENIDO frames: *_frame_files and *_files
 70:     public static $XmlFrames;
 71: 
 72:     // CONTENIDO main navigations: *_nav_main
 73:     public static $XmlNavMain;
 74: 
 75:     // CONTENIDO sub navigations: *_nav_sub
 76:     public static $XmlNavSub;
 77: 
 78:     // CONTENIDO content types: *_type
 79:     public static $XmlContentType;
 80: 
 81:     // Id of selected/new plugin
 82:     protected static $_pluginId = 0;
 83: 
 84:     // Name of selected plugin
 85:     protected static $_pluginName;
 86: 
 87:     // GET and SET methods for installation routine
 88:     /**
 89:      * Set method for installation / update mode
 90:      * Mode 1: Plugin is already extracted
 91:      * Mode 2: Plugin is uploaded
 92:      *
 93:      * @param string $mode
 94:      */
 95:     public static function setMode($mode) {
 96:         switch ($mode) {
 97:             case 'extracted':
 98:                 self::$mode = 1;
 99:                 break;
100:             case 'uploaded':
101:                 self::$mode = 2;
102:                 break;
103:             case 'uninstall':
104:                 self::$mode = 3;
105:                 break;
106:             case 'update':
107:                 self::$mode = 4;
108:                 break;
109:         }
110:     }
111: 
112:     /**
113:      * Set method for cGuiPage class
114:      *
115:      * @param cGuiPage $page
116:      */
117:     public function setPageClass($page) {
118:         return self::$_GuiPage = $page;
119:     }
120: 
121:     /**
122:      * Set method to change updateSqlFileExist variable
123:      *
124:      * @param bool $value
125:      */
126:     protected function _setUpdateSqlFileExist($value) {
127:         self::$_updateSqlFileExist = cSecurity::toBoolean($value);
128:     }
129: 
130:     /**
131:      * Initialzing and set variable for PimPluginArchiveExtractor class
132:      *
133:      * @param string $tempArchiveNewPath Path to Zip archive
134:      * @param string $tempArchiveName Name of Zip archive
135:      * @return PimPluginArchiveExtractor
136:      */
137:     protected static function _setPimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName) {
138:         return self::$_PimPluginArchiveExtractor = new PimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
139:     }
140: 
141:     /**
142:      * Set temporary xml content to static variables
143:      *
144:      * @param string $xml
145:      */
146:     private function _setXml($xml) {
147: 
148:         // General plugin informations
149:         self::$XmlGeneral = $xml->general;
150: 
151:         // Plugin requirements
152:         self::$XmlRequirements = $xml->requirements;
153: 
154:         // Plugin dependencies
155:         self::$XmlDependencies = $xml->dependencies;
156: 
157:         // CONTENIDO areas: *_area
158:         self::$XmlArea = $xml->contenido->areas;
159: 
160:         // CONTENIDO actions: *_actions
161:         self::$XmlActions = $xml->contenido->actions;
162: 
163:         // CONTENIDO frames: *_frame_files and *_files
164:         self::$XmlFrames = $xml->contenido->frames;
165: 
166:         // CONTENIDO main navigations: *_nav_main
167:         self::$XmlNavMain = $xml->contenido->nav_main;
168: 
169:         // CONTENIDO sub navigations: *_nav_sub
170:         self::$XmlNavSub = $xml->contenido->nav_sub;
171: 
172:         // CONTENIDO Content Types: *_type
173:         self::$XmlContentType = $xml->content_types;
174:     }
175: 
176:     /**
177:      * Set method for PluginId
178:      *
179:      * @param int $pluginId
180:      * @return int
181:      */
182:     public function setPluginId($pluginId = 0) {
183:         return self::$_pluginId = $pluginId;
184:     }
185: 
186:     /**
187:      * Set method for PluginName
188:      *
189:      * @param string $pluginName
190:      * @return string
191:      */
192:     public function setPluginName($pluginName = '') {
193:         return self::$_pluginName = $pluginName;
194:     }
195: 
196:     /**
197:      * Get method for installation / update mode
198:      *
199:      * @return int
200:      */
201:     public static function getMode() {
202:         return self::$mode;
203:     }
204: 
205:     /**
206:      * Get method for PluginId
207:      *
208:      * @return int
209:      */
210:     protected static function _getPluginId() {
211:         return self::$_pluginId;
212:     }
213: 
214:     /**
215:      * Get methos for PluginName
216:      *
217:      * @return string
218:      */
219:     protected static function _getPluginName() {
220:         return self::$_pluginName;
221:     }
222: 
223:     /**
224:      * Set method for updateSqlFileExist variable
225:      *
226:      * @return bool
227:      */
228:     protected function _getUpdateSqlFileExist() {
229:         return self::$_updateSqlFileExist;
230:     }
231: 
232:     // Help methods
233:     /**
234:      * checkXml
235:      * Load plugin datas and run Xml checks
236:      */
237:     public function checkXml() {
238:         $cfg = cRegistry::getConfig();
239: 
240:         if (self::getMode() == 1) { // Plugin is already extracted
241:             $XmlData = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . cSecurity::escapeString($_GET['pluginFoldername']) . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME);
242:         } elseif (self::getMode() == 2 || self::getMode() == 4) { // Plugin is
243:                                                                   // uploaded /
244:                                                                   // Update mode
245: 
246:             // Path to CONTENIDO temp dir
247:             $tempArchiveNewPath = $cfg['path']['frontend'] . DIRECTORY_SEPARATOR . $cfg['path']['temp'];
248: 
249:             // Check if temp directory exists, otherwise try to create it
250:             if (!cDirHandler::exists($tempArchiveNewPath)) {
251:                 $success = cDirHandler::create($tempArchiveNewPath);
252: 
253:                 // If PIM can not create a temporary directory (if it does not exists), throw an error message
254:                 if (!$success) {
255:                     return self::error(sprintf(i18n('Plugin Manager can not found a temporary CONTENIDO directory. Also it is not possible to create a temporary directory at <em>%s</em>. You have to create it manualy.', 'pim'), $tempArchiveNewPath));              }
256:             }
257: 
258:             // Name of uploaded Zip archive
259:             $tempArchiveName = cSecurity::escapeString($_FILES['package']['name']);
260: 
261:             // Move temporary archive files into CONTENIDO temp dir
262:             move_uploaded_file($_FILES['package']['tmp_name'], $tempArchiveNewPath . $tempArchiveName);
263: 
264:             // Initializing plugin archive extractor
265:             try {
266:                 self::_setPimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
267:             } catch (cException $e) {
268:                 self::$_PimPluginArchiveExtractor->destroyTempFiles();
269:             }
270: 
271:             // Check valid Zip archive
272:             $this->checkZip();
273: 
274:             // Get plugin.xml informations
275:             $XmlData = self::$_PimPluginArchiveExtractor->extractArchiveFileToVariable(self::PLUGIN_XML_FILENAME);
276:         }
277: 
278:         // Check and set plugin.xml
279:         if ($this->validXml($XmlData) === true) {
280:             $this->_setXml(simplexml_load_string($XmlData));
281:         } else {
282:             return self::error(i18n('Invalid Xml document. Please contact the plugin author.', 'pim'));
283:         }
284:     }
285: 
286:     /**
287:      * Check dependencies to other plugins (dependencies-Tag at plugin.xml)
288:      * Global function for uninstall and status mode
289:      * Install mode uses an own dependencies function
290:      *
291:      * @return boolean
292:      */
293:     public function checkDependencies() {
294: 
295:         // Initializings
296:         $cfg = cRegistry::getConfig();
297:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
298: 
299:         // Get uuid from plugin to uninstall
300:         $this->_PimPluginCollection->setWhere('idplugin', self::_getPluginId());
301:         $this->_PimPluginCollection->query();
302:         $pimPluginSql = $this->_PimPluginCollection->next();
303:         $uuidUninstall = $pimPluginSql->get('uuid');
304: 
305:         // Reset query so we can use PimPluginCollection later again...
306:         $this->_PimPluginCollection->resetQuery();
307: 
308:         // Read all dirs
309:         $dirs = cDirHandler::read($pluginsDir);
310:         foreach ($dirs as $dirname) {
311: 
312:             // Skip plugin if it has no plugin.xml file
313:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME)) {
314:                 continue;
315:             }
316: 
317:             // Read plugin.xml files from existing plugins at contenido/plugins dir
318:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME);
319: 
320:             // Write plugin.xml content into temporary variable
321:             $tempXml = simplexml_load_string($tempXmlContent);
322: 
323:             $dependenciesCount = count($tempXml->dependencies);
324:             for ($i = 0; $i < $dependenciesCount; $i++) {
325: 
326:                 // Security check
327:                 $depend = cSecurity::escapeString($tempXml->dependencies->depend[$i]);
328: 
329:                 // If is no dependencie name defined please go to next dependencie
330:                 if ($depend == "") {
331:                     continue;
332:                 }
333: 
334:                 // Build uuid variable from attributes
335:                 foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
336: 
337:                     // We use only uuid attribute and can ignore other attributes
338:                     if ($key  == "uuid") {
339:                         $uuidTemp = cSecurity::escapeString($value);
340:                     }
341:                 }
342: 
343:                 // Return false if uuid from plugin to uninstall and depended plugin is the same
344:                 // AND depended plugin is active
345:                 if ($uuidTemp === $uuidUninstall) {
346: 
347:                     $this->_PimPluginCollection->setWhere('uuid', $tempXml->general->uuid);
348:                     $this->_PimPluginCollection->setWhere('active', '1');
349:                     $this->_PimPluginCollection->query();
350:                     if ($this->_PimPluginCollection->count() != 0) {
351:                         self::setPluginName($tempXml->general->plugin_name);
352:                         return false;
353:                     }
354:                 }
355:             }
356:         }
357: 
358:         return true;
359:     }
360: 
361: 
362:     /**
363:      * Check file type, Plugin Manager accepts only Zip archives
364:      */
365:     private function checkZip() {
366:         if (substr($_FILES['package']['name'], -4) != ".zip") {
367:             self::error(i18n('Plugin Manager accepts only Zip archives', 'pim'));
368:         }
369:     }
370: 
371:     /**
372:      * Validate Xml source
373:      * @param string $xml
374:      * @return bool
375:      */
376:     private function validXml($xml) {
377:         // Initializing PHP DomDocument class
378:         $dom = new DomDocument();
379:         $dom->loadXML($xml);
380: 
381:         // Validate
382:         if ($dom->schemaValidate('plugins' . DIRECTORY_SEPARATOR . 'pim' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'plugin_info.xsd')) {
383:             return true;
384:         } else {
385:             return false;
386:         }
387:     }
388: 
389:     /**
390:      * Error function with pim_error-Template
391:      * @param string $message
392:      */
393:     protected static function error($message = '') {
394: 
395:         // Get session variable
396:         $session = cRegistry::getSession();
397: 
398:         // Destroy temporary files if plugin is uploaded
399:         if (self::getMode() == 2) {
400:             self::$_PimPluginArchiveExtractor->destroyTempFiles();
401:         }
402: 
403:         // Error template
404:         $pimError = new cGuiPage('pim_error', 'pim');
405:         $pimError->set('s', 'BACKLINK', $session->url('main.php?area=pim&frame=4'));
406:         $pimError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
407:         $pimError->displayError($message);
408:         $pimError->render();
409:         exit();
410:     }
411: 
412:     /**
413:      * Info function
414:      * @param string $message
415:      */
416:     protected static function info($message = '') {
417:         return self::$_GuiPage->displayInfo($message);
418:     }
419: 
420: }
421: 
422: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen