Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

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