Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • 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
  • PimPluginViewNavSub
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  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:             // Name of uploaded Zip archive
250:             $tempArchiveName = cSecurity::escapeString($_FILES['package']['name']);
251: 
252:             // Move temporary archive files into CONTENIDO temp dir
253:             move_uploaded_file($_FILES['package']['tmp_name'], $tempArchiveNewPath . $tempArchiveName);
254: 
255:             // Initializing plugin archive extractor
256:             try {
257:                 self::_setPimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
258:             } catch (cException $e) {
259:                 self::$_PimPluginArchiveExtractor->destroyTempFiles();
260:             }
261: 
262:             // Check valid Zip archive
263:             $this->checkZip();
264: 
265:             // Get plugin.xml informations
266:             $XmlData = self::$_PimPluginArchiveExtractor->extractArchiveFileToVariable(self::PLUGIN_XML_FILENAME);
267:         }
268: 
269:         // Check and set plugin.xml
270:         if ($this->validXml($XmlData) === true) {
271:             $this->_setXml(simplexml_load_string($XmlData));
272:         } else {
273:             return self::error(i18n('Invalid Xml document. Please contact the plugin author.', 'pim'));
274:         }
275:     }
276: 
277:     /**
278:      * Check dependencies to other plugins (dependencies-Tag at plugin.xml)
279:      * Global function for uninstall and status mode
280:      * Install mode uses an own dependencies function
281:      *
282:      * @return boolean
283:      */
284:     public function checkDependencies() {
285: 
286:         // Initializings
287:         $cfg = cRegistry::getConfig();
288:         $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
289: 
290:         // Get uuid from plugin to uninstall
291:         $this->_PimPluginCollection->setWhere('idplugin', self::_getPluginId());
292:         $this->_PimPluginCollection->query();
293:         $pimPluginSql = $this->_PimPluginCollection->next();
294:         $uuidUninstall = $pimPluginSql->get('uuid');
295: 
296:         // Reset query so we can use PimPluginCollection later again...
297:         $this->_PimPluginCollection->resetQuery();
298: 
299:         // Read all dirs
300:         $dirs = cDirHandler::read($pluginsDir);
301:         foreach ($dirs as $dirname) {
302: 
303:             // Skip plugin if it has no plugin.xml file
304:             if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME)) {
305:                 continue;
306:             }
307: 
308:             // Read plugin.xml files from existing plugins at contenido/plugins dir
309:             $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME);
310: 
311:             // Write plugin.xnl content into temporary variable
312:             $tempXml = simplexml_load_string($tempXmlContent);
313: 
314:             $dependenciesCount = count($tempXml->dependencies);
315:             for ($i = 0; $i < $dependenciesCount; $i++) {
316: 
317:                 // Security check
318:                 $depend = cSecurity::escapeString($tempXml->dependencies->depend[$i]);
319: 
320:                 // If is no dependencie name defined please go to next dependencie
321:                 if ($depend == "") {
322:                     continue;
323:                 }
324: 
325:                 // Build uuid variable from attributes
326:                 foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
327: 
328:                     // We use only uuid attribute and can ignore other attributes
329:                     if ($key  == "uuid") {
330:                         $uuidTemp = cSecurity::escapeString($value);
331:                     }
332:                 }
333: 
334:                 // Return false if uuid from plugin to uninstall and depended plugin is the same
335:                 // AND depended plugin is active
336:                 if ($uuidTemp === $uuidUninstall) {
337: 
338:                     $this->_PimPluginCollection->setWhere('uuid', $tempXml->general->uuid);
339:                     $this->_PimPluginCollection->setWhere('active', '1');
340:                     $this->_PimPluginCollection->query();
341:                     if ($this->_PimPluginCollection->count() != 0) {
342:                         self::setPluginName($tempXml->general->plugin_name);
343:                         return false;
344:                     }
345:                 }
346:             }
347:         }
348: 
349:         return true;
350:     }
351: 
352: 
353:     /**
354:      * Check file type, Plugin Manager accepts only Zip archives
355:      */
356:     private function checkZip() {
357:         if (substr($_FILES['package']['name'], -4) != ".zip") {
358:             self::error(i18n('Plugin Manager accepts only Zip archives', 'pim'));
359:         }
360:     }
361: 
362:     /**
363:      * Validate Xml source
364:      * @param string $xml
365:      * @return bool
366:      */
367:     private function validXml($xml) {
368:         // Initializing PHP DomDocument class
369:         $dom = new DomDocument();
370:         $dom->loadXML($xml);
371: 
372:         // Validate
373:         if ($dom->schemaValidate('plugins' . DIRECTORY_SEPARATOR . 'pim' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'plugin_info.xsd')) {
374:             return true;
375:         } else {
376:             return false;
377:         }
378:     }
379: 
380:     /**
381:      * Error function with pim_error-Template
382:      * @param string $message
383:      */
384:     protected static function error($message = '') {
385: 
386:         // Get session variable
387:         $session = cRegistry::getSession();
388: 
389:         // Destroy temporary files if plugin is uploaded
390:         if (self::getMode() == 2) {
391:             self::$_PimPluginArchiveExtractor->destroyTempFiles();
392:         }
393: 
394:         // Error template
395:         $pimError = new cGuiPage('pim_error', 'pim');
396:         $pimError->set('s', 'BACKLINK', $session->url('main.php?area=pim&frame=4'));
397:         $pimError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
398:         $pimError->displayError($message);
399:         $pimError->render();
400:         exit();
401:     }
402: 
403:     /**
404:      * Info function
405:      * @param string $message
406:      */
407:     protected static function info($message = '') {
408:         return self::$_GuiPage->displayInfo($message);
409:     }
410: 
411: }
412: 
413: ?>
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0