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