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
    • 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 uuid", "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:         $elements = parent::$XmlArea->area;
432:         if (empty($elements)) {
433:             return;
434:         }
435: 
436:         // Get Id of plugin
437:         $pluginId = parent::_getPluginId();
438: 
439:         foreach ($elements as $element) {
440: 
441:             // Initializing attributes array
442:             $attributes = array();
443: 
444:             // Build attributes
445:             foreach ($element->attributes() as $key => $value) {
446:                 $attributes[$key] = $value;
447:             }
448: 
449:             // Security check
450:             $area = cSecurity::escapeString($element);
451: 
452:             // Add attributes "parent", "relevant" and "menuless" to an array
453:             $attributes = array(
454:                 'parent' => cSecurity::escapeString($attributes['parent']),
455:                 'relevant' => cSecurity::toInteger($attributes['relevant']),
456:                 'menuless' => cSecurity::toInteger($attributes['menuless'])
457:             );
458: 
459:             // Fix for parent and relevant attributes
460:             if (empty($attributes['parent'])) {
461:                 $attributes['parent'] = 0;
462:             }
463: 
464:             if (empty($attributes['relevant'])) {
465:                 $attributes['relevant'] = 1;
466:             }
467: 
468:             // Create a new entry
469:             $item = $this->_ApiAreaCollection->create($area, $attributes['parent'], $attributes['relevant'], 1, $attributes['menuless']);
470: 
471:             // Set a relation
472:             $this->_PimPluginRelationsCollection->create($item->get('idarea'), $pluginId, 'area');
473: 
474:             // Add new area to all area array
475:             $this->PluginInstalledAreas[] = $area;
476:         }
477:     }
478: 
479:     /**
480:      * Add entries at *_actions
481:      */
482:     private function _installAddActions() {
483: 
484:         $elements = parent::$XmlActions->action;
485:         if (empty($elements)) {
486:             return;
487:         }
488: 
489:         // Initializing attributes array
490:         $attributes = array();
491: 
492:         // Get Id of plugin
493:         $pluginId = parent::_getPluginId();
494: 
495:         foreach ($elements as $element) {
496: 
497:             // Build attributes
498:             foreach ($element->attributes() as $key => $value) {
499:                 $attributes[$key] = $value;
500:             }
501: 
502:             // Set relevant value if it is empty
503:             if (empty($attributes['relevant'])) {
504:                 $attributes['relevant'] = 1;
505:             }
506: 
507:             // Add attributes "area" and "relevant" to an safe array
508:             $attributes = array(
509:                 'area' => cSecurity::escapeString($attributes['area']),
510:                 'relevant' => cSecurity::toInteger($attributes['relevant'])
511:             );
512: 
513:             // Security check for action name
514:             $action = cSecurity::escapeString($element);
515: 
516:             // Check for valid area
517:             if (!in_array($attributes['area'], $this->_getInstalledAreas())) {
518:                 parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your CONTENIDO installation. Please contact your plugin author.', 'pim'), $attributes['area']));
519:             }
520: 
521:             // Create a new entry
522:             $item = $this->_ApiActionCollection->create($attributes['area'], $action, '', '', '', $attributes['relevant']);
523: 
524:             // Set a relation
525:             $this->_PimPluginRelationsCollection->create($item->get('idaction'), $pluginId, 'action');
526:         }
527:     }
528: 
529:     /**
530:      * Add entries at *_frame_files and *_files
531:      */
532:     private function _installAddFrames() {
533: 
534:         $elements = parent::$XmlFrames->frame;
535:         if (empty($elements)) {
536:             return;
537:         }
538: 
539:         // Initializing attributes array
540:         $attributes = array();
541: 
542:         // Get Id of plugin
543:         $pluginId = parent::_getPluginId();
544: 
545:         foreach ($elements as $element) {
546: 
547:             // Build attributes with security checks
548:             foreach ($element->attributes() as $sKey => $sValue) {
549:                 $attributes[$sKey] = cSecurity::escapeString($sValue);
550:             }
551: 
552:             // Check for valid area
553:             if (!in_array($attributes['area'], $this->_getInstalledAreas())) {
554:                 parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your CONTENIDO installation. Please contact your plugin author.', 'pim'), $attributes['area']));
555:             }
556: 
557:             // Create a new entry at *_files
558:             $file = $this->_ApiFileCollection->create($attributes['area'], $attributes['name'], $attributes['filetype']);
559: 
560:             // Create a new entry at *_frame_files
561:             if (!empty($attributes['frameId'])) {
562:                 $item = $this->_ApiFrameFileCollection->create($attributes['area'], $attributes['frameId'], $file->get('idfile'));
563: 
564:                 // Set a relation
565:                 $this->_PimPluginRelationsCollection->create($item->get('idframefile'), $pluginId, 'framefl');
566:             }
567:         }
568:     }
569: 
570:     /**
571:      * Add entries at *_nav_main
572:      */
573:     private function _installAddNavMain() {
574: 
575:         $elements = parent::$XmlNavMain->nav;
576:         if (empty($elements)) {
577:             return;
578:         }
579: 
580:         $cfg = cRegistry::getConfig();
581:         $db = cRegistry::getDb();
582: 
583:         // Initializing attributes array
584:         $attributes = array();
585: 
586:         // Get Id of plugin
587:         $pluginId = parent::_getPluginId();
588: 
589:         // Get idnavm informations to build an new id
590:         $sql = 'SELECT MAX(idnavm) AS id FROM ' . $cfg['tab']['nav_main'];
591:         $db->query($sql);
592: 
593:         if ($db->nextRecord()) {
594:             $idnavm = $db->f('id');
595: 
596:             // id must be over 10.000
597:             if ($idnavm < 10000) {
598:                 $idnavm = 10000;
599:             }
600:         }
601: 
602:         foreach ($elements as $element) {
603: 
604:             // Security check for location
605:             $location = cSecurity::escapeString($element);
606: 
607:             // Build attributes with security checks
608:             foreach ($element->attributes() as $sKey => $sValue) {
609:                 $attributes[$sKey] = cSecurity::escapeString($sValue);
610:             }
611: 
612:             // Fallback for older plugins
613:             if (!$attributes['name']) {
614:                 $attributes['name'] = cString::toLowerCase($location);
615:                 $attributes['name'] = str_replace('/', '', $attributes['name']);
616:             }
617: 
618:             // Create new idnavm
619:             $idnavm = $idnavm + 10;
620: 
621:             // Removed the last number at idnavm
622:             $idnavm = cString::getPartOfString($idnavm, 0, cString::getStringLength($idnavm) - 1);
623: 
624:             // Last number is always a zero
625:             $idnavm = cSecurity::toInteger($idnavm . 0);
626: 
627:             // Create a new entry at *_nav_main
628:             $this->_ApiNavMainCollection->create($attributes['name'], $location, $idnavm);
629: 
630:             // Set a relation
631:             $this->_PimPluginRelationsCollection->create($idnavm, $pluginId, 'navm');
632:         }
633:     }
634: 
635:     /**
636:      * Add entries at *_nav_sub
637:      */
638:     private function _installAddNavSub() {
639: 
640:         $elements = parent::$XmlNavSub->nav;
641:         if (empty($elements)) {
642:             return;
643:         }
644: 
645:         // Initializing attributes array
646:         $attributes = array();
647: 
648:         // Get Id of plugin
649:         $pluginId = parent::_getPluginId();
650: 
651:         foreach ($elements as $element) {
652: 
653:             // Build attributes
654:             foreach ($element->attributes() as $key => $value) {
655:                 $attributes[$key] = $value;
656:             }
657: 
658:             // Convert area to string
659:             $attributes['area'] = cSecurity::toString($attributes['area']);
660: 
661:             // Check for valid area
662:             if (!in_array($attributes['area'], $this->_getInstalledAreas())) {
663:                 parent::error(sprintf(i18n('Defined area <strong>%s</strong> are not found on your CONTENIDO installation. Please contact your plugin author.', 'pim'), $attributes['area']));
664:             }
665: 
666:             // If navm attribute is an string get it's id
667:             if (!preg_match('/[^a-zA-Z]/u', $attributes['navm'])) {
668: 
669:                 $navm = $this->_getNavMainId($attributes['navm']);;
670:                 if ($navm === false) {
671:                     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']));
672:                 } else {
673:                     $attributes['navm'] = $navm;
674:                 }
675:             }
676: 
677:             // Create a new entry at *_nav_sub
678:             $item = $this->_ApiNavSubCollection->create($attributes['navm'], $attributes['area'], $attributes['level'], $element, 1);
679: 
680:             // Set a relation
681:             $this->_PimPluginRelationsCollection->create($item->get('idnavs'), $pluginId, 'navs');
682:         }
683:     }
684: 
685:     /**
686:      * Add specific sql queries
687:      */
688:     private function _installAddSpecificSql() {
689: 
690:         $cfg = cRegistry::getConfig();
691:         $db = cRegistry::getDb();
692: 
693:         if (parent::getMode() == 1) { // Plugin is already extracted
694:             $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . 'plugin_install.sql';
695:         } elseif (parent::getMode() == 2 || parent::getMode() == 4) {
696:             // Plugin is uploaded or / and update mode
697:             $tempSqlFilename = parent::$_PimPluginArchiveExtractor->extractArchiveFileToVariable('plugin_install.sql', 0);
698:         }
699: 
700:         // skip using plugin_install.sql if it does not exist
701:         if (!cFileHandler::exists($tempSqlFilename)) {
702:             return;
703:         }
704: 
705:         $tempSqlContent = cFileHandler::read($tempSqlFilename);
706:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
707:         $tempSqlContent = explode("\n", $tempSqlContent);
708:         $tempSqlLines = count($tempSqlContent);
709: 
710:         $pattern = '/^(CREATE TABLE IF NOT EXISTS|INSERT INTO|UPDATE|ALTER TABLE) `?' . parent::SQL_PREFIX . '`?\b/';
711: 
712:         for ($i = 0; $i < $tempSqlLines; $i++) {
713:             if (preg_match($pattern, $tempSqlContent[$i])) {
714:                 $tempSqlContent[$i] = str_replace(parent::SQL_PREFIX, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
715:                 $db->query($tempSqlContent[$i]);
716:             }
717:         }
718:     }
719: 
720:     /**
721:      * Add content types (*_type)
722:      */
723:     private function _installAddContentTypes() {
724: 
725:         $elements = parent::$XmlContentType->type;
726:         if (empty($elements)) {
727:             return;
728:         }
729: 
730:         // Get Id of plugin
731:         $pluginId = parent::_getPluginId();
732: 
733:         $pattern = '/^CMS_.+/';
734: 
735:         foreach ($elements as $element) {
736: 
737:             $type = cSecurity::toString($element);
738: 
739:             if (preg_match($pattern, $type)) {
740: 
741:                 // Create new content type
742:                 $item = $this->_ApiTypeCollection->create($type, '');
743: 
744:                 // Set a relation
745:                 $this->_PimPluginRelationsCollection->create($item->get('idtype'), $pluginId, 'ctype');
746:             }
747:         }
748:     }
749: 
750:     /**
751:      * Add modules
752:      */
753:     private function _installAddModules() {
754: 
755:         $cfg = cRegistry::getConfig();
756:         $module = new cApiModule();
757: 
758:         // Set path to modules path
759:         $modulesPath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR;
760: 
761:         if (!is_dir($modulesPath)) {
762:             return;
763:         }
764: 
765:         foreach (new DirectoryIterator($modulesPath) as $modulesFiles) {
766: 
767:             if (cString::getPartOfString($modulesFiles->getBasename(), -4) == ".zip") {
768: 
769:                 // Import founded module
770:                 $module->import($modulesFiles->getBasename(), $modulesFiles->getBasename(), false);
771:             }
772:         }
773: 
774:         cDirHandler::recursiveRmdir($modulesPath);
775:     }
776: 
777:     /**
778:      * Add plugin dir
779:      */
780:     private function _installAddDir() {
781: 
782:         $cfg = cRegistry::getConfig();
783: 
784:         // Build the new plugin dir
785:         $tempPluginDir = $cfg['path']['contenido'] . $cfg['path']['plugins'] . parent::$XmlGeneral->plugin_foldername . DIRECTORY_SEPARATOR;
786: 
787:         // Set destination path
788:         try {
789:             parent::$_PimPluginArchiveExtractor->setDestinationPath($tempPluginDir);
790:         } catch (cException $e) {
791:             parent::$_PimPluginArchiveExtractor->destroyTempFiles();
792:         }
793: 
794:         // Extract Zip archive files into the new plugin dir
795:         try {
796:             parent::$_PimPluginArchiveExtractor->extractArchive();
797:         } catch (cException $e) {
798:             parent::$_PimPluginArchiveExtractor->destroyTempFiles();
799:         }
800:     }
801: 
802: }
803: ?>
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0