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:     // CONTENIDO areas: *_area
 61:     public static $XmlArea;
 62: 
 63:     // CONTENIDO actions: *_actions
 64:     public static $XmlActions;
 65: 
 66:     // CONTENIDO frames: *_frame_files and *_files
 67:     public static $XmlFrames;
 68: 
 69:     // CONTENIDO main navigations: *_nav_main
 70:     public static $XmlNavMain;
 71: 
 72:     // CONTENIDO sub navigations: *_nav_sub
 73:     public static $XmlNavSub;
 74: 
 75:     // CONTENIDO content types: *_type
 76:     public static $XmlContentType;
 77: 
 78:     // Id of selected / new plugin
 79:     protected static $_pluginId = 0;
 80: 
 81:     // GET and SET methods for installation routine
 82:     /**
 83:      * Set method for installation / update mode
 84:      * Mode 1: Plugin is already extracted
 85:      * Mode 2: Plugin is uploaded
 86:      *
 87:      * @param string $mode
 88:      */
 89:     public static function setMode($mode) {
 90:         switch ($mode) {
 91:             case 'extracted':
 92:                 self::$mode = 1;
 93:                 break;
 94:             case 'uploaded':
 95:                 self::$mode = 2;
 96:                 break;
 97:             case 'uninstall':
 98:                 self::$mode = 3;
 99:                 break;
100:             case 'update':
101:                 self::$mode = 4;
102:                 break;
103:         }
104:     }
105: 
106:     /**
107:      * Set method for cGuiPage class
108:      *
109:      * @param cGuiPage $page
110:      */
111:     public function setPageClass($page) {
112:         return self::$_GuiPage = $page;
113:     }
114: 
115:     /**
116:      * Set method to change updateSqlFileExist variable
117:      *
118:      * @param bool $value
119:      */
120:     protected function _setUpdateSqlFileExist($value) {
121:         self::$_updateSqlFileExist = cSecurity::toBoolean($value);
122:     }
123: 
124:     /**
125:      * Initialzing and set variable for PimPluginArchiveExtractor class
126:      *
127:      * @param string $tempArchiveNewPath Path to Zip archive
128:      * @param string $tempArchiveName Name of Zip archive
129:      * @return PimPluginArchiveExtractor
130:      */
131:     protected static function _setPimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName) {
132:         return self::$_PimPluginArchiveExtractor = new PimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
133:     }
134: 
135:     /**
136:      * Set temporary xml content to static variables
137:      *
138:      * @param string $xml
139:      */
140:     private function _setXml($xml) {
141: 
142:         // General plugin informations
143:         self::$XmlGeneral = $xml->general;
144: 
145:         // Plugin requirements
146:         self::$XmlRequirements = $xml->requirements;
147: 
148:         // CONTENIDO areas: *_area
149:         self::$XmlArea = $xml->contenido->areas;
150: 
151:         // CONTENIDO actions: *_actions
152:         self::$XmlActions = $xml->contenido->actions;
153: 
154:         // CONTENIDO frames: *_frame_files and *_files
155:         self::$XmlFrames = $xml->contenido->frames;
156: 
157:         // CONTENIDO main navigations: *_nav_main
158:         self::$XmlNavMain = $xml->contenido->nav_main;
159: 
160:         // CONTENIDO sub navigations: *_nav_sub
161:         self::$XmlNavSub = $xml->contenido->nav_sub;
162: 
163:         // CONTENIDO Content Types: *_type
164:         self::$XmlContentType = $xml->content_types;
165:     }
166: 
167:     /**
168:      * Set method for PluginId
169:      *
170:      * @param int $pluginId
171:      * @return int
172:      */
173:     public function setPluginId($pluginId = 0) {
174:         return self::$_pluginId = $pluginId;
175:     }
176: 
177:     /**
178:      * Get method for installation / update mode
179:      *
180:      * @return int
181:      */
182:     public static function getMode() {
183:         return self::$mode;
184:     }
185: 
186:     /**
187:      * Get method for PluginId
188:      *
189:      * @return int
190:      */
191:     protected static function _getPluginId() {
192:         return self::$_pluginId;
193:     }
194: 
195:     /**
196:      * Set method for updateSqlFileExist variable
197:      *
198:      * @return bool
199:      */
200:     protected function _getUpdateSqlFileExist() {
201:         return self::$_updateSqlFileExist;
202:     }
203: 
204:     // Help methods
205:     /**
206:      * checkXml
207:      * Load plugin datas and run Xml checks
208:      */
209:     public function checkXml() {
210:         $cfg = cRegistry::getConfig();
211: 
212:         if (self::getMode() == 1) { // Plugin is already extracted
213:             $XmlData = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . cSecurity::escapeString($_GET['pluginFoldername']) . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME);
214:         } elseif (self::getMode() == 2 || self::getMode() == 4) { // Plugin is
215:                                                                   // uploaded /
216:                                                                   // Update mode
217: 
218:             // Path to CONTENIDO temp dir
219:             $tempArchiveNewPath = $cfg['path']['frontend'] . DIRECTORY_SEPARATOR . $cfg['path']['temp'];
220: 
221:             // Name of uploaded Zip archive
222:             $tempArchiveName = cSecurity::escapeString($_FILES['package']['name']);
223: 
224:             // Initializing plugin archive extractor
225:             try {
226:                 self::_setPimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
227:             } catch (cException $e) {
228:                 self::$_PimPluginArchiveExtractor->destroyTempFiles();
229:             }
230: 
231:             // Check valid Zip archive
232:             $this->checkZip();
233: 
234:             // Move temporary archive files into CONTENIDO temp dir
235:             move_uploaded_file($_FILES['package']['tmp_name'], $tempArchiveNewPath . $tempArchiveName);
236: 
237:             // Get plugin.xml informations
238:             $XmlData = self::$_PimPluginArchiveExtractor->extractArchiveFileToVariable(self::PLUGIN_XML_FILENAME);
239:         }
240: 
241:         // Check and set plugin.xml
242:         if ($this->validXml($XmlData) === true) {
243:             $this->_setXml(simplexml_load_string($XmlData));
244:         } else {
245:             return self::error(i18n('Invalid Xml document. Please contact the plugin author.', 'pim'));
246:         }
247:     }
248: 
249:     /**
250:      * Check file type, Plugin Manager accepts only Zip archives
251:      */
252:     private function checkZip() {
253:         if (substr($_FILES['package']['name'], -4) != ".zip") {
254:             self::error(i18n('Plugin Manager accepts only Zip archives', 'pim'));
255:         }
256:     }
257: 
258:     /**
259:      * Validate Xml source
260:      * @param string $xml
261:      * @return bool
262:      */
263:     private function validXml($xml) {
264:         // Initializing PHP DomDocument class
265:         $dom = new DomDocument();
266:         $dom->loadXML($xml);
267: 
268:         // Validate
269:         if ($dom->schemaValidate('plugins' . DIRECTORY_SEPARATOR . 'pim' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'plugin_info.xsd')) {
270:             return true;
271:         } else {
272:             return false;
273:         }
274:     }
275: 
276:     /**
277:      * Error function with pim_error-Template
278:      * @param string $message
279:      */
280:     protected static function error($message = '') {
281: 
282:         // Get session variable
283:         $session = cRegistry::getSession();
284: 
285:         // Destroy temporary files if plugin is uploaded
286:         if (self::getMode() == 2) {
287:             self::$_PimPluginArchiveExtractor->destroyTempFiles();
288:         }
289: 
290:         // Error template
291:         $pimError = new cGuiPage('pim_error', 'pim');
292:         $pimError->set('s', 'BACKLINK', $session->url('main.php?area=pim&frame=4'));
293:         $pimError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
294:         $pimError->displayError($message);
295:         $pimError->render();
296:         exit();
297:     }
298: 
299:     /**
300:      * Info function
301:      * @param string $message
302:      */
303:     protected static function info($message = '') {
304:         return self::$_GuiPage->displayInfo($message);
305:     }
306: 
307: }
308: 
309: ?>
CMS CONTENIDO 4.9.3 API documentation generated by ApiGen 2.8.0