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

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 abstract class for installation new plugins
  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:  * Install class for new plugins, extends PimPluginSetup
 18:  *
 19:  * @package Plugin
 20:  * @subpackage PluginManager
 21:  * @author frederic.schneider
 22:  */
 23: class PimPluginSetupInstall extends PimPluginSetup {
 24: 
 25:     // Initializing variables
 26:     // Plugin specific data
 27:     // Foldername of installed plugin
 28:     private $PluginFoldername;
 29: 
 30:     // All area entries from database in an array
 31:     private $PluginInstalledAreas = array();
 32: 
 33:     // Classes
 34:     // Class variable for PimPluginCollection
 35:     protected $_PimPluginCollection;
 36: 
 37:     // Class variable for PimPluginRelationsCollection
 38:     protected $_PimPluginRelationsCollection;
 39: 
 40:     // Class variable for cApiAreaCollection;
 41:     protected $_ApiAreaCollection;
 42: 
 43:     // Class variable for cApiActionCollection
 44:     protected $_ApiActionCollection;
 45: 
 46:     // Class variable for cApiFileCollection
 47:     protected $_ApiFileCollection;
 48: 
 49:     // Class variable for cApiFrameFileCollection
 50:     protected $_ApiFrameFileCollection;
 51: 
 52:     // Class variable for cApiNavMainCollection
 53:     protected $_ApiNavMainCollection;
 54: 
 55:     // Class variable for cApiNavSubCollection
 56:     protected $_ApiNavSubCollection;
 57: 
 58:     // Class variable for cApiTypeCollection
 59:     protected $_ApiTypeCollection;
 60: 
 61:     // GET and SET methods for installation routine
 62:     /**
 63:      * Set variable for plugin foldername
 64:      *
 65:      * @param string $foldername
 66:      * @return string
 67:      */
 68:     private function _setPluginFoldername($foldername) {
 69:         return $this->PluginFoldername = cSecurity::escapeString($foldername);
 70:     }
 71: 
 72:     /**
 73:      * Initializing and set variable for PimPluginCollection class
 74:      *
 75:      * @return PimPluginCollection
 76:      */
 77:     private function _setPimPluginCollection() {
 78:         return $this->_PimPluginCollection = new PimPluginCollection();
 79:     }
 80: 
 81:     /**
 82:      * Initializing and set variable for PimPluginRelationsCollection class
 83:      *
 84:      * @return PimPluginRelationsCollection
 85:      */
 86:     private function _setPimPluginRelationsCollection() {
 87:         return $this->_PimPluginRelationsCollection = new PimPluginRelationsCollection();
 88:     }
 89: 
 90:     /**
 91:      * Initializing and set variable for cApiAreaCollection
 92:      *
 93:      * @return cApiAreaCollection
 94:      */
 95:     private function _setApiAreaCollection() {
 96:         return $this->_ApiAreaCollection = new cApiAreaCollection();
 97:     }
 98: 
 99:     /**
100:      * Initializing and set variable for cApiActionCollection
101:      *
102:      * @return cApiActionCollection
103:      */
104:     private function _setApiActionCollection() {
105:         return $this->_ApiActionCollection = new cApiActionCollection();
106:     }
107: 
108:     /**
109:      * Initializing and set variable for cApiAFileCollection
110:      *
111:      * @return cApiFileCollection
112:      */
113:     private function _setApiFileCollection() {
114:         return $this->_ApiFileCollection = new cApiFileCollection();
115:     }
116: 
117:     /**
118:      * Initializing and set variable for cApiFrameFileCollection
119:      *
120:      * @return cApiFrameFileCollection
121:      */
122:     private function _setApiFrameFileCollection() {
123:         return $this->_ApiFrameFileCollection = new cApiFrameFileCollection();
124:     }
125: 
126:     /**
127:      * Initializing and set variable for cApiNavMainFileCollection
128:      *
129:      * @return cApiNavMainCollection
130:      */
131:     private function _setApiNavMainCollection() {
132:         return $this->_ApiNavMainCollection = new cApiNavMainCollection();
133:     }
134: 
135:     /**
136:      * Initializing and set variable for cApiNavSubCollection
137:      *
138:      * @return cApiNavSubCollection
139:      */
140:     private function _setApiNavSubCollection() {
141:         return $this->_ApiNavSubCollection = new cApiNavSubCollection();
142:     }
143: 
144:     /**
145:      * Initializing and set variable for cApiTypeCollection
146:      *
147:      * @return cApiNavSubCollection
148:      */
149:     private function _setApiTypeCollection() {
150:         return $this->_ApiTypeCollection = new cApiTypeCollection();
151:     }
152: 
153:     /**
154:      * Get method for foldername of installed plugin
155:      *
156:      * @return string
157:      */
158:     protected function _getPluginFoldername() {
159:         return $this->PluginFoldername;
160:     }
161: 
162:     /**
163:      * Get method for installed areas
164:      *
165:      * @return array
166:      */
167:     protected function _getInstalledAreas() {
168:         return $this->PluginInstalledAreas;
169:     }
170: 
171:     /**
172:      * Get id of nav_main entry
173:      * @param string $navm
174:      * @return boolean|integer
175:      */
176:     protected function _getNavMainId($navm = '') {
177: 
178:         if (!$navm) {
179:             return false;
180:         }
181: 
182:         $this->_ApiNavMainCollection->setWhere('name', cSecurity::escapeString($navm));
183:         $this->_ApiNavMainCollection->query();
184: 
185:         if ($this->_ApiNavMainCollection->count() == 0) {
186:             return false;
187:         } else {
188:             $entry = $this->_ApiNavMainCollection->next();
189:             return $entry->get('idnavm');
190:         }
191:     }
192: 
193:     // Begin of installation routine
194:     /**
195:      * Construct function
196:      */
197:     public function __construct() {
198: 
199:         // Initializing and set classes
200:         // PluginManager classes
201:         $this->_setPimPluginCollection();
202:         $this->_setPimPluginRelationsCollection();
203: 
204:         // cApiClasses
205:         $this->_setApiAreaCollection();
206:         $this->_setApiActionCollection();
207:         $this->_setApiFileCollection();
208:         $this->_setApiFrameFileCollection();
209:         $this->_setApiNavMainCollection();
210:         $this->_setApiNavSubCollection();
211:         $this->_setApiTypeCollection();
212:     }
213: 
214:     /**
215:      * Installation method
216:      */
217:     public function install() {
218: 
219:         // Does this plugin already exist?
220:         $this->_installCheckUuid();
221: 
222:         // Requirement checks
223:         $this->_installCheckRequirements();
224: 
225:         // Dependencies checks
226:         $this->_installCheckDependencies();
227: 
228:         // Add new plugin: *_plugins
229:         $this->_installAddPlugin();
230: 
231:         // Get all area names from database
232:         $this->_installFillAreas();
233: 
234:         // Add new CONTENIDO areas: *_area
235:         $this->_installAddAreas();
236: 
237:         // Add new CONTENIDO actions: *_actions
238:         $this->_installAddActions();
239: 
240:         // Add new CONTENIDO frames: *_frame_files and *_files
241:         $this->_installAddFrames();
242: 
243:         // Add new CONTENIDO main navigations: *_nav_main
244:         $this->_installAddNavMain();
245: 
246:         // Add new CONTENIDO sub navigations: *_nav_sub
247:         $this->_installAddNavSub();
248: 
249:         // Add specific sql queries, run only if we have no update sql file
250:         if (PimPluginSetup::_getUpdateSqlFileExist() === false) {
251:             $this->_installAddSpecificSql();
252:         }
253: 
254:         // Add new CONTENIDO content types: *_type
255:         $this->_installAddContentTypes();
256: 
257:         // Add new modules
258:         $this->_installAddModules();
259: 
260:         // Add plugin dir for uploaded plugins
261:         if (parent::getMode() == 2) {
262:             $this->_installAddDir();
263:         }
264: 
265:         // Success message for new plugins
266:         // Get only for extracted (1) and installed mode (2)
267:         if (parent::getMode() <= 2) {
268:             parent::info(i18n('The plugin has been successfully installed. To apply the changes please login into backend again.', 'pim'));
269:         }
270:     }
271: 
272:     /**
273:      * Check uuId: You can install a plugin only for one time
274:      */
275:     private function _installCheckUuid() {
276:         $this->_PimPluginCollection->setWhere('uuid', parent::$XmlGeneral->uuid);
277:         $this->_PimPluginCollection->query();
278:         if ($this->_PimPluginCollection->count() > 0) {
279:             parent::error(i18n('You can install this plugin only for one time.', 'pim'));
280:         }
281:     }
282: 
283:     /**
284:      * This function checks requirements for one plugin
285:      */
286:     private function _installCheckRequirements() {
287: 
288:         // Check min CONTENIDO version
289:         if (version_compare(CON_VERSION, parent::$XmlRequirements->contenido->attributes()->minversion, '<')) {
290:             parent::error(sprintf(i18n('You have to install CONTENIDO <strong>%s</strong> or higher to install this plugin!', 'pim'), parent::$XmlRequirements->contenido->attributes()->minversion));
291:         }
292: 
293:         // Check max CONTENIDO version
294:         if (parent::$XmlRequirements->contenido->attributes()->maxversion) {
295: 
296:             if (version_compare(CON_VERSION, parent::$XmlRequirements->contenido->attributes()->maxversion, '>')) {
297:                 parent::error(sprintf(i18n('Your current CONTENIDO version is to new - max CONTENIDO version: %s', 'pim'), parent::$XmlRequirements->contenido->attributes()->maxversion));
298:             }
299:         }
300: 
301:         // Check PHP version
302:         if (version_compare(phpversion(), parent::$XmlRequirements->attributes()->php, '<')) {
303:             parent::error(sprintf(i18n('You have to install PHP <strong>%s</strong> or higher to install this plugin!', 'pim'), parent::$XmlRequirements->attributes()->php));
304:         }
305: 
306:         // Check extensions
307:         if (count(parent::$XmlRequirements->extension) != 0) {
308: 
309:             for ($i = 0; $i < count(parent::$XmlRequirements->extension); $i++) {
310: 
311:                 if (!extension_loaded(parent::$XmlRequirements->extension[$i]->attributes()->name)) {
312:                     parent::error(sprintf(i18n('The plugin could not find the PHP extension <strong>%s</strong>. Because this is required by the plugin, it can not be installed.', 'pim'), parent::$XmlRequirements->extension[$i]->attributes()->name));
313:                 }
314:             }
315:         }
316: 
317:         // Check classes
318:         if (count(parent::$XmlRequirements->class) != 0) {
319: 
320:             for ($i = 0; $i < count(parent::$XmlRequirements->class); $i++) {
321: 
322:                 if (!class_exists(parent::$XmlRequirements->class[$i]->attributes()->name)) {
323:                     parent::error(sprintf(i18n('The plugin could not find the class <strong>%s</strong>. Because this is required by the plugin, it can not be installed.', 'pim'), parent::$XmlRequirements->class[$i]->attributes()->name));
324:                 }
325:             }
326:         }
327: 
328:         // Check functions
329:         if (count(parent::$XmlRequirements->function) != 0) {
330: 
331:             for ($i = 0; $i < count(parent::$XmlRequirements->function); $i++) {
332: 
333:                 if (!function_exists(parent::$XmlRequirements->function[$i]->attributes()->name)) {
334:                     parent::error(sprintf(i18n('The plugin could not find the function <strong>%s</strong>. Because this is required by the plugin, it can not be installed.', 'pim'), parent::$XmlRequirements->function[$i]->attributes()->name));
335:                 }
336:             }
337:         }
338:     }
339: 
340:     /**
341:      * Check dependencies to other plugins (dependencies-Tag at plugin.xml)
342:      */
343:     private function _installCheckDependencies() {
344: 
345:         $dependenciesCount = count(parent::$XmlDependencies);
346:         for ($i = 0; $i < $dependenciesCount; $i++) {
347: 
348:             $attributes = array();
349: 
350:             // Build attributes
351:             foreach (parent::$XmlDependencies->depend[$i]->attributes() as $key => $value) {
352:                 $attributes[$key] = $value;
353:             }
354: 
355:             // Security check
356:             $depend = cSecurity::escapeString(parent::$XmlDependencies->depend[$i]);
357: 
358:             if ($depend == "") {
359:                 return true;
360:             }
361: 
362:             // Add attributes "min_version" and "max_version" to an array
363:             $attributes = array(
364:                     'uuid' => cSecurity::escapeString($attributes['uuid']),
365:                     'minversion' => cSecurity::escapeString($attributes['min_version']),
366:                     'maxversion' => cSecurity::escapeString($attributes['max_version'])
367:             );
368: 
369: 
370:             $this->_PimPluginCollection->setWhere('uuid', $attributes['uuid']);
371:             $this->_PimPluginCollection->setWhere('active', '1');
372:             $this->_PimPluginCollection->query();
373:             if ($this->_PimPluginCollection->count() == 0) {
374:                 parent::error(sprintf(i18n('This plugin required the plugin <strong>%s</strong>.', 'pim'), $depend));
375:             }
376: 
377:             $plugin = $this->_PimPluginCollection->next();
378: 
379:             // Check min plugin version
380:             if (parent::$XmlDependencies->depend[$i]->attributes()->minversion) {
381: 
382:                 if (version_compare($plugin->get("version"), parent::$XmlDependencies->depend[$i]->attributes()->minversion, '<')) {
383:                     parent::error(sprintf(i18n('You have to install<strong>%s %</strong> or higher to install this plugin!', 'pim'), $depend, parent::$XmlDependencies->depend[$i]->attributes()->minversion));
384:                 }
385:             }
386: 
387:             // Check max plugin version
388:             if (parent::$XmlDependencies->depend[$i]->attributes()->maxversion) {
389: 
390:                 if (version_compare($plugin->get("version"),  parent::$XmlDependencies->depend[$i]->attributes()->maxversion, '>')) {
391:                     parent::error(sprintf(i18n('You have to install <strong>%s %s</strong> or lower to install this plugin!', 'pim'), $depend, parent::$XmlDependencies->depend[$i]->attributes()->maxversion));
392:                 }
393:             }
394: 
395:         }
396: 
397:     }
398: 
399:     /**
400:      * Add entries at *_plugins
401:      */
402:     private function _installAddPlugin() {
403:         // Add entry at *_plugins
404:         $pimPlugin = $this->_PimPluginCollection->create(parent::$XmlGeneral->plugin_name, parent::$XmlGeneral->description, parent::$XmlGeneral->author, parent::$XmlGeneral->copyright, parent::$XmlGeneral->mail, parent::$XmlGeneral->website, parent::$XmlGeneral->version, parent::$XmlGeneral->plugin_foldername, parent::$XmlGeneral->uuid, parent::$XmlGeneral->attributes()->active);
405: 
406:         // Get Id of new plugin
407:         $pluginId = $pimPlugin->get('idplugin');
408: 
409:         // Set pluginId
410:         parent::setPluginId($pluginId);
411: 
412:         // Set foldername of new plugin
413:         $this->_setPluginFoldername(parent::$XmlGeneral->plugin_foldername);
414:     }
415: 
416:     /**
417:      * Get all area names from database
418:      */
419:     private function _installFillAreas() {
420:         $this->_ApiAreaCollection->select(NULL, NULL, 'name');
421:         while (($areas = $this->_ApiAreaCollection->next()) !== false) {
422:             $this->PluginInstalledAreas[] = $areas->get('name');
423:         }
424:     }
425: 
426:     /**
427:      * Add entries at *_area
428:      */
429:     private function _installAddAreas() {
430: 
431:         // Initializing attribute array
432:         $attributes = array();
433: 
434:         // Get Id of plugin
435:         $pluginId = parent::_getPluginId();
436: 
437:         $areaCount = count(parent::$XmlArea->area);
438:         for ($i = 0; $i < $areaCount; $i++) {
439: 
440:             $attributes = array();
441: 
442:             // Build attributes
443:             foreach (parent::$XmlArea->area[$i]->attributes() as $key => $value) {
444:                 $attributes[$key] = $value;
445:             }
446: 
447:             // Security check
448:             $area = cSecurity::escapeString(parent::$XmlArea->area[$i]);
449: 
450:             // Add attributes "parent", "relevant" and "menuless" to an array
451:             $attributes = array(
452:                 'parent' => cSecurity::escapeString($attributes['parent']),
453:                 'relevant' => cSecurity::toInteger($attributes['relevant']),
454:                 'menuless' => cSecurity::toInteger($attributes['menuless'])
455:             );
456: 
457:             // Fix for parent and relevant attributes
458:             if (empty($attributes['parent'])) {
459:                 $attributes['parent'] = 0;
460:             }
461: 
462:             if (empty($attributes['relevant'])) {
463:                 $attributes['relevant'] = 1;
464:             }
465: 
466:             // Create a new entry
467:             $item = $this->_ApiAreaCollection->create($area, $attributes['parent'], $attributes['relevant'], 1, $attributes['menuless']);
468: 
469:             // Set a relation
470:             $this->_PimPluginRelationsCollection->create($item->get('idarea'), $pluginId, 'area');
471: 
472:             // Add new area to all area array
473:             $this->PluginInstalledAreas[] = $area;
474:         }
475:     }
476: 
477:     /**
478:      * Add entries at *_actions
479:      */
480:     private function _installAddActions() {
481: 
482:         // Initializing attribute array
483:         $attributes = array();
484: 
485:         // Get Id of plugin
486:         $pluginId = parent::_getPluginId();
487: 
488:         $actionCount = count(parent::$XmlActions->action);
489:         for ($i = 0; $i < $actionCount; $i++) {
490: 
491:             // Build attributes
492:             foreach (parent::$XmlActions->action[$i]->attributes() as $key => $value) {
493:                 $attributes[$key] = $value;
494:             }
495: 
496:             // Set relevant value if it is empty
497:             if (empty($attributes['relevant'])) {
498:                 $attributes['relevant'] = 1;
499:             }
500: 
501:             // Add attributes "area" and "relevant" to an safe array
502:             $attributes = array(
503:                 'area' => cSecurity::escapeString($attributes['area']),
504:                 'relevant' => cSecurity::toInteger($attributes['relevant'])
505:             );
506: 
507:             // Security check for action name
508:             $action = cSecurity::escapeString(parent::$XmlActions->action[$i]);
509: 
510:             // Check for valid area
511:             if (!in_array($attributes['area'], $this->_getInstalledAreas())) {
512:                 parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your CONTENIDO installation. Please contact your plugin author.', 'pim'), $attributes['area']));
513:             }
514: 
515:             // Create a new entry
516:             $item = $this->_ApiActionCollection->create($attributes['area'], $action, '', '', '', $attributes['relevant']);
517: 
518:             // Set a relation
519:             $this->_PimPluginRelationsCollection->create($item->get('idaction'), $pluginId, 'action');
520:         }
521:     }
522: 
523:     /**
524:      * Add entries at *_frame_files and *_files
525:      */
526:     private function _installAddFrames() {
527: 
528:         // Initializing attribute array
529:         $attributes = array();
530: 
531:         // Get Id of plugin
532:         $pluginId = parent::_getPluginId();
533: 
534:         $frameCount = count(parent::$XmlFrames->frame);
535:         for ($i = 0; $i < $frameCount; $i++) {
536: 
537:             // Build attributes with security checks
538:             foreach (parent::$XmlFrames->frame[$i]->attributes() as $sKey => $sValue) {
539:                 $attributes[$sKey] = cSecurity::escapeString($sValue);
540:             }
541: 
542:             // Check for valid area
543:             if (!in_array($attributes['area'], $this->_getInstalledAreas())) {
544:                 parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your CONTENIDO installation. Please contact your plugin author.', 'pim'), $attributes['area']));
545:             }
546: 
547:             // Create a new entry at *_files
548:             $file = $this->_ApiFileCollection->create($attributes['area'], $attributes['name'], $attributes['filetype']);
549: 
550:             // Create a new entry at *_frame_files
551:             if (!empty($attributes['frameId'])) {
552:                 $item = $this->_ApiFrameFileCollection->create($attributes['area'], $attributes['frameId'], $file->get('idfile'));
553: 
554:                 // Set a relation
555:                 $this->_PimPluginRelationsCollection->create($item->get('idframefile'), $pluginId, 'framefl');
556:             }
557:         }
558:     }
559: 
560:     /**
561:      * Add entries at *_nav_main
562:      */
563:     private function _installAddNavMain() {
564:         $cfg = cRegistry::getConfig();
565:         $db = cRegistry::getDb();
566: 
567:         // Initializing attribute array
568:         $attributes = array();
569: 
570:         // Get Id of plugin
571:         $pluginId = parent::_getPluginId();
572: 
573:         // Get idnavm informations to build an new id
574:         $sql = 'SELECT MAX(idnavm) AS id FROM ' . $cfg['tab']['nav_main'];
575:         $db->query($sql);
576: 
577:         if ($db->nextRecord()) {
578:             $idnavm = $db->f('id');
579: 
580:             // id must be over 10.000
581:             if ($idnavm < 10000) {
582:                 $idnavm = 10000;
583:             }
584:         }
585: 
586:         $navCount = count(parent::$XmlNavMain->nav);
587:         for ($i = 0; $i < $navCount; $i++) {
588: 
589:             // Security check for location
590:             $location = cSecurity::escapeString(parent::$XmlNavMain->nav[$i]);
591: 
592:             // Build attributes with security checks
593:             foreach (parent::$XmlNavMain->nav[$i]->attributes() as $sKey => $sValue) {
594:                 $attributes[$sKey] = cSecurity::escapeString($sValue);
595:             }
596: 
597:             // Fallback for older plugins
598:             if (!$attributes['name']) {
599:                 $attributes['name'] = strtolower($location);
600:                 $attributes['name'] = str_replace('/', '', $attributes['name']);
601:             }
602: 
603:             // Create new idnavm
604:             $idnavm = $idnavm + 10;
605: 
606:             // Removed the last number at idnavm
607:             $idnavm = substr($idnavm, 0, strlen($idnavm) - 1);
608: 
609:             // Last number is always a zero
610:             $idnavm = cSecurity::toInteger($idnavm . 0);
611: 
612:             // Create a new entry at *_nav_main
613:             $this->_ApiNavMainCollection->create($attributes['name'], $location, $idnavm);
614: 
615:             // Set a relation
616:             $this->_PimPluginRelationsCollection->create($idnavm, $pluginId, 'navm');
617:         }
618:     }
619: 
620:     /**
621:      * Add entries at *_nav_sub
622:      */
623:     private function _installAddNavSub() {
624: 
625:         // Initializing attribute array
626:         $attributes = array();
627: 
628:         // Get Id of plugin
629:         $pluginId = parent::_getPluginId();
630: 
631:         $navCount = count(parent::$XmlNavSub->nav);
632:         for ($i = 0; $i < $navCount; $i++) {
633: 
634:             // Build attributes
635:             foreach (parent::$XmlNavSub->nav[$i]->attributes() as $key => $value) {
636:                 $attributes[$key] = $value;
637:             }
638: 
639:             // Convert area to string
640:             $attributes['area'] = cSecurity::toString($attributes['area']);
641: 
642:             // Check for valid area
643:             if (!in_array($attributes['area'], $this->_getInstalledAreas())) {
644:                 parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your CONTENIDO installation. Please contact your plugin author.', 'pim'), $attributes['area']));
645:             }
646: 
647:             // If navm attribute is an string get it's id
648:             if (!preg_match('/[^a-zA-Z]/u', $attributes['navm'])) {
649: 
650:                 $navm = $this->_getNavMainId($attributes['navm']);;
651:                 if ($navm === false) {
652:                     parent::error(sprintf(i18n('Can not find <strong>%s</strong> entry at nav_main table on your CONTENIDO installation. Please contact your plugin author.', 'pim'), $attributes['navm']));
653:                 } else {
654:                     $attributes['navm'] = $navm;
655:                 }
656:             }
657: 
658:             // Create a new entry at *_nav_sub
659:             $item = $this->_ApiNavSubCollection->create($attributes['navm'], $attributes['area'], $attributes['level'], parent::$XmlNavSub->nav[$i], 1);
660: 
661:             // Set a relation
662:             $this->_PimPluginRelationsCollection->create($item->get('idnavs'), $pluginId, 'navs');
663:         }
664:     }
665: 
666:     /**
667:      * Add specific sql queries
668:      */
669:     private function _installAddSpecificSql() {
670:         $cfg = cRegistry::getConfig();
671:         $db = cRegistry::getDb();
672:         if (parent::getMode() == 1) { // Plugin is already extracted
673:             $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . 'plugin_install.sql';
674:         } elseif (parent::getMode() == 2 || parent::getMode() == 4) { // Plugin
675:                                                                       // is
676:                                                                       // uploaded
677:                                                                       // or /
678:                                                                       // and
679:                                                                       // update
680:                                                                       // mode
681:             $tempSqlFilename = parent::$_PimPluginArchiveExtractor->extractArchiveFileToVariable('plugin_install.sql', 0);
682:         }
683: 
684:         // skip using plugin_install.sql if it does not exist
685:         if (!cFileHandler::exists($tempSqlFilename)) {
686:             return;
687:         }
688: 
689:         $tempSqlContent = cFileHandler::read($tempSqlFilename);
690:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
691:         $tempSqlContent = explode("\n", $tempSqlContent);
692:         $tempSqlLines = count($tempSqlContent);
693: 
694:         $pattern = '/^(CREATE TABLE IF NOT EXISTS|INSERT INTO|UPDATE|ALTER TABLE) `?' . parent::SQL_PREFIX . '`?\b/';
695: 
696:         for ($i = 0; $i < $tempSqlLines; $i++) {
697:             if (preg_match($pattern, $tempSqlContent[$i])) {
698:                 $tempSqlContent[$i] = str_replace(parent::SQL_PREFIX, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
699:                 $db->query($tempSqlContent[$i]);
700:             }
701:         }
702:     }
703: 
704:     /**
705:      * Add content types (*_type)
706:      */
707:     private function _installAddContentTypes() {
708: 
709:         // Get Id of plugin
710:         $pluginId = parent::_getPluginId();
711: 
712:         $pattern = '/^CMS_.+/';
713: 
714:         $typeCount = count(parent::$XmlContentType->type);
715:         for ($i = 0; $i < $typeCount; $i++) {
716: 
717:             $type = cSecurity::toString(parent::$XmlContentType->type[$i]);
718: 
719:             if (preg_match($pattern, $type)) {
720: 
721:                 // Create new content type
722:                 $item = $this->_ApiTypeCollection->create($type, '');
723: 
724:                 // Set a relation
725:                 $this->_PimPluginRelationsCollection->create($item->get('idtype'), $pluginId, 'ctype');
726:             }
727:         }
728:     }
729: 
730:     /**
731:      * Add modules
732:      */
733:     private function _installAddModules() {
734:         $cfg = cRegistry::getConfig();
735:         $module = new cApiModule();
736: 
737:         // Set path to modules path
738:         $modulesPath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR;
739: 
740:         if (!is_dir($modulesPath)) {
741:             return false;
742:         }
743: 
744:         foreach (new DirectoryIterator($modulesPath) as $modulesFiles) {
745: 
746:             if (substr($modulesFiles->getBasename(), -4) == ".zip") {
747: 
748:                 // Import founded module
749:                 $module->import($modulesFiles->getBasename(), $modulesFiles->getBasename(), false);
750:             }
751:         }
752: 
753:         cDirHandler::recursiveRmdir($modulesPath);
754:     }
755: 
756:     /**
757:      * Add plugin dir
758:      */
759:     private function _installAddDir() {
760:         $cfg = cRegistry::getConfig();
761: 
762:         // Build the new plugin dir
763:         $tempPluginDir = $cfg['path']['contenido'] . $cfg['path']['plugins'] . parent::$XmlGeneral->plugin_foldername . DIRECTORY_SEPARATOR;
764: 
765:         // Set destination path
766:         try {
767:             parent::$_PimPluginArchiveExtractor->setDestinationPath($tempPluginDir);
768:         } catch (cException $e) {
769:             parent::$_PimPluginArchiveExtractor->destroyTempFiles();
770:         }
771: 
772:         // Extract Zip archive files into the new plugin dir
773:         try {
774:             parent::$_PimPluginArchiveExtractor->extractArchive();
775:         } catch (cException $e) {
776:             parent::$_PimPluginArchiveExtractor->destroyTempFiles();
777:         }
778:     }
779: 
780: }
781: ?>
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0