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
    • NavigationMain
    • 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

Functions

  • installationRoutine
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains abstract class for contenido setup.
  4:  *
  5:  * @package CONTENIDO Plugins
  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:  * Abstract class for contenido setup operations When creating install,
 20:  * uninstall, update you must extend this class.
 21:  *
 22:  * @package Plugin
 23:  * @subpackage PluginManager
 24:  *
 25:  */
 26: class PimPluginSetup {
 27: 
 28:     protected $sqlPrefix = "!PREFIX!";
 29: 
 30:     protected $valid = false;
 31: 
 32:     protected $tempXml;
 33: 
 34:     protected $isExtracted = false;
 35: 
 36:     protected $extractedPath;
 37: 
 38:     protected $pluginId = 0;
 39: 
 40:     protected $allAreas = array();
 41: 
 42:     protected $isUpdate = 0; // 0 = No (Standard),
 43:                              // 1 = Yes
 44:     protected $_extractor; // TODO
 45:     public function addArchiveObject($extractor) {
 46:         $this->_extractor = $extractor;
 47:     }
 48: 
 49:     /**
 50:      * Checks xml file to valid
 51:      *
 52:      * @throws cException
 53:      * @return boolean
 54:      */
 55:     public function checkValidXml() {
 56:         $sess = cRegistry::getSession();
 57: 
 58:         $dom = new DomDocument();
 59:         $dom->loadXML($this->tempXml);
 60: 
 61:         if ($dom->schemaValidate('plugins/pim/xml/plugin_info.xsd')) {
 62:             $this->valid = true;
 63:             return true;
 64:         } else {
 65: 
 66:             if ($this->isExtracted === false) {
 67:                 $this->_extractor->destroyTempFiles();
 68:             }
 69: 
 70:             $pageError = new cGuiPage('pim_error', 'pim');
 71:             $pageError->set('s', 'BACKLINK', $sess->url('main.php?area=pim&frame=4'));
 72:             $pageError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
 73:             $pageError->displayError(i18n('Invalid Xml document. Please contact the plugin author.', 'pim'));
 74:             $pageError->render();
 75:             exit();
 76:         }
 77:     }
 78: 
 79:     /**
 80:      * Checks plugin specific requirements
 81:      *
 82:      * @access public
 83:      * @return void
 84:      */
 85:     public function checkRequirements() {
 86: 
 87:         // get config
 88:         $cfg = cRegistry::getConfig();
 89: 
 90:         // get requirements xml
 91:         $xml = simplexml_load_string($this->getTempXml());
 92: 
 93:         // check CONTENIDO min version
 94:         if (version_compare($cfg['version'], $xml->requirements->contenido->attributes()->minversion, '<')) {
 95:             $this->getRequirementsError(i18n('You have to install CONTENIDO <strong>', 'pim') . $xml->requirements->contenido->attributes()->minversion . i18n('</strong> or higher to install this plugin!', 'pim'));
 96:         }
 97: 
 98:         // check CONTENIDO max version
 99:         if ($xml->requirements->contenido->attributes()->maxversion) {
100: 
101:             if (version_compare($cfg['version'], $xml->requirements->contenido->attributes()->maxversion, '>')) {
102:                 $this->getRequirementsError(i18n('This plugin is only valid for CONTENIDO <strong>', 'pim') . $xml->requirements->contenido->attributes()->maxversion . i18n('</strong> or lower!', 'pim'));
103:             }
104:         }
105: 
106:         // check PHP version
107:         if (version_compare(phpversion(), $xml->requirements->attributes()->php, '<')) {
108:             $this->getRequirementsError(i18n('You have to install PHP <strong>', 'pim') . $xml->requirements->attributes()->php . i18n('</strong> or higher to install this plugin!', 'pim'));
109:         }
110: 
111:         // check extensions
112:         if (count($xml->requirements->extension) != 0) {
113: 
114:             for ($i = 0; $i < count($xml->requirements->extension); $i++) {
115: 
116:                 if (!extension_loaded($xml->requirements->extension[$i]->attributes()->name)) {
117:                     $this->getRequirementsError(i18n('The plugin could not find the PHP extension <strong>', 'pim') . $xml->requirements->extension[$i]->attributes()->name . i18n('</strong>. Because this is required by the plugin, it can not be installed.', 'pim'));
118:                 }
119:             }
120:         }
121: 
122:         // check classes
123:         if (count($xml->requirements->class) != 0) {
124: 
125:             for ($i = 0; $i < count($xml->requirements->class); $i++) {
126: 
127:                 if (!class_exists($xml->requirements->class[$i]->attributes()->name)) {
128:                     $this->getRequirementsError(i18n('The plugin could not find the class <strong>', 'pim') . $xml->requirements->class[$i]->attributes()->name . i18n('</strong>. Because this is required by the plugin, it can not be installed.', 'pim'));
129:                 }
130:             }
131:         }
132: 
133:         // check functions
134:         if (count($xml->requirements->function) != 0) {
135: 
136:             for ($i = 0; $i < count($xml->requirements->function); $i++) {
137: 
138:                 if (!function_exists($xml->requirements->function[$i]->attributes()->name)) {
139:                     $this->getRequirementsError(i18n('The plugin could not find the function <strong>', 'pim') . $xml->requirements->function[$i]->attributes()->name . i18n('</strong>. Because this is required by the plugin, it can not be installed.', 'pim'));
140:                 }
141:             }
142:         }
143:     }
144: 
145:     /**
146:      * Get error template for requirements (checkRequirements())
147:      *
148:      * @access private
149:      * @param errorMessage Specific error message string
150:      * @return void
151:      */
152:     private function getRequirementsError($errorMessage) {
153:         $sess = cRegistry::getSession();
154: 
155:         $pageError = new cGuiPage('pim_error', 'pim');
156:         $pageError->set('s', 'BACKLINK', $sess->url('main.php?area=pim&frame=4'));
157:         $pageError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
158:         $pageError->displayError($errorMessage);
159:         $pageError->render();
160:         exit();
161:     }
162: 
163:     /**
164:      * Get method for $tempXml
165:      *
166:      * @access public
167:      * @return content of $tempXml
168:      */
169:     public function getTempXml() {
170:         return $this->tempXml;
171:     }
172: 
173:     /**
174:      * Get method for $valid
175:      *
176:      * @access public
177:      * @return true or fales value of $valid
178:      */
179:     public function getValid() {
180:         return $this->valid;
181:     }
182: 
183:     /**
184:      * Get method for $pluginId
185:      *
186:      * @access public
187:      * @return id of selected plugin
188:      */
189:     public function getPluginId() {
190:         return $this->pluginId;
191:     }
192: 
193:     /**
194:      * Get method for "is update?" ($isUpdate)
195:      *
196:      * 0 = No (Standard)
197:      * 1 = Yes
198:      *
199:      * TODO: Optimize this function (CON-1358)
200:      *
201:      * @access public
202:      */
203:     public function getIsUpdate() {
204:         return $this->isUpdate;
205:     }
206: 
207:     /**
208:      * Set method for "is update?" ($isUpdate)
209:      *
210:      * 0 = No (Standard)
211:      * 1 = Yes
212:      *
213:      * TODO: Optimize this function (CON-1358)
214:      *
215:      * @access public
216:      * @param integer $value
217:      */
218:     public function setIsUpdate($value) {
219:         $this->isUpdate = $value;
220:     }
221: 
222:     /**
223:      * Set method for $tempXml
224:      *
225:      * @access public
226:      * @param $value xml content
227:      * @return void
228:      */
229:     public function setTempXml($value) {
230:         $this->tempXml = $value;
231:     }
232: 
233:     /**
234:      * Set method for $isExtracted
235:      *
236:      * @access public
237:      * @param $value true or false value
238:      * @return void
239:      */
240:     public function setIsExtracted($value) {
241:         $this->isExtracted = $value;
242:     }
243: 
244:     /**
245:      * Set method for $extractedPath
246:      *
247:      * @access public
248:      * @param $value path to extracted files
249:      * @return void
250:      */
251:     public function setExtractedPath($value) {
252:         $this->extractedPath = $value;
253:     }
254: 
255:     /**
256:      * Set method for $pluginId
257:      *
258:      * @access public
259:      * @param $value id of selected plugin
260:      * @return void
261:      */
262:     public function setPluginId($value) {
263:         $this->pluginId = $value;
264:     }
265: 
266:     /**
267:      * Install a new plugin
268:      *
269:      * @access protected
270:      * @param $tempXml temporary plugin definitions
271:      * @return void
272:      */
273:     public function install($tempXml) {
274:         $pimPluginColl = new PimPluginCollection();
275: 
276:         // add entry at *_plugins
277:         $pimPlugin = $pimPluginColl->create($tempXml->general->plugin_name, $tempXml->general->description, $tempXml->general->author, $tempXml->general->copyright, $tempXml->general->mail, $tempXml->general->website, $tempXml->general->version, $tempXml->general->plugin_foldername, $tempXml->general->uuid, $tempXml->general->attributes()->active);
278:         $pluginId = $pimPlugin->get('idplugin');
279: 
280:         // set pluginId
281:         $this->setPluginId($pluginId);
282: 
283:         // add entries at *_area
284:         $this->_installAddArea($tempXml->contenido->areas);
285: 
286:         // add entries at *_actions
287:         $this->_installAddActions($tempXml->contenido->actions);
288: 
289:         // add entries at *_files and *_frame_files
290:         $this->_installAddFrames($tempXml->contenido->frames);
291: 
292:         // add entries at *_nav_main
293:         $this->_installAddNavMain($tempXml->contenido->nav_main);
294: 
295:         // add entries at *_nav_sub
296:         $this->_installAddNavSub($tempXml->contenido->nav_sub);
297: 
298:         // add specific sql queries
299:         if ($this->getIsUpdate() == 0) {
300:             $this->_installAddSpecificSql();
301:         }
302: 
303:         // add content types
304:         $this->_installAddContentTypes($tempXml->content_types);
305: 
306:         // add modules
307:         $this->_installAddModules($tempXml->general);
308:     }
309: 
310:     /**
311:      * Add entries at *_area
312:      *
313:      * @access protected
314:      * @param $tempXml temporary plugin definitions
315:      * @return void
316:      */
317:     protected function _installAddArea($tempXml) {
318:         $areaColl = new cApiAreaCollection();
319:         $pimPluginRelColl = new PimPluginRelationsCollection();
320:         $pluginId = $this->getPluginId();
321: 
322:         // get all area names from database
323:         $oItem = new cApiAreaCollection();
324:         $oItem->select(null, null, 'name');
325:         while (($areas = $oItem->next()) !== false) {
326:             $this->allAreas[] = $areas->get('name');
327:         }
328: 
329:         $areaCount = count($tempXml->area);
330:         for ($i = 0; $i < $areaCount; $i++) {
331:             $attributes = array();
332: 
333:             // build attributes
334:             foreach ($tempXml->area[$i]->attributes() as $key => $value) {
335:                 $attributes[$key] = $value;
336:             }
337: 
338:             // security check
339:             $area = cSecurity::escapeString($tempXml->area[$i]);
340:             $attributes = array(
341:                 'parent' => cSecurity::escapeString($attributes['parent']),
342:                 'menuless' => cSecurity::toInteger($attributes['menuless'])
343:             );
344: 
345:             // parent fix
346:             if (empty($attributes['parent'])) {
347:                 $attributes['parent'] = 0;
348:             }
349: 
350:             // create a new entry
351:             $item = $areaColl->create($area, $attributes['parent'], 1, 1, $attributes['menuless']);
352: 
353:             // set a relation
354:             $pimPluginRelColl->create($item->get('idarea'), $pluginId, 'area');
355: 
356:             // add new area to all area array
357:             $this->allAreas[] = $area;
358:         }
359:     }
360: 
361:     /**
362:      * Add entries at *_actions
363:      *
364:      * @access protected
365:      * @param $tempXml temporary plugin definitions
366:      * @return void
367:      */
368:     protected function _installAddActions($tempXml) {
369:         $actionColl = new cApiActionCollection();
370: 
371:         $actionCount = count($tempXml->action);
372:         for ($i = 0; $i < $actionCount; $i++) {
373:             // build attribut
374:             $area = $tempXml->action[$i]->attributes();
375: 
376:             // security check
377:             $area = cSecurity::escapeString($area);
378:             $action = cSecurity::escapeString($tempXml->action[$i]);
379: 
380:             // check for valid area
381:             if (!in_array($area, $this->allAreas)) {
382:                 $this->errorArea($area);
383:             }
384: 
385:             // create a new entry
386:             $actionColl->create($area, $action, '', '', '', 1);
387:         }
388:     }
389: 
390:     /**
391:      * Add entries at *_files and *_frame_files
392:      *
393:      * @access protected
394:      * @param $tempXml temporary plugin definitions
395:      * @return void
396:      */
397:     protected function _installAddFrames($tempXml) {
398:         $fileColl = new cApiFileCollection();
399:         $frameFileColl = new cApiFrameFileCollection();
400: 
401:         $frameCount = count($tempXml->frame);
402:         for ($i = 0; $i < $frameCount; $i++) {
403: 
404:             $attributes = array();
405: 
406:             // build attributes with security checks
407:             foreach ($tempXml->frame[$i]->attributes() as $sKey => $sValue) {
408:                 $attributes[$sKey] = cSecurity::escapeString($sValue);
409:             }
410: 
411:             // check for valid area
412:             if (!in_array($attributes['area'], $this->allAreas)) {
413:                 $this->errorArea($attributes['area']);
414:             }
415: 
416:             // create a new entry at *_files
417:             $file = $fileColl->create($attributes['area'], $attributes['name'], $attributes['filetype']);
418: 
419:             // create a new entry at *_frame_files
420:             if (!empty($attributes['frameId'])) {
421:                 $frameFileColl->create($attributes['area'], $attributes['frameId'], $file->get('idfile'));
422:             }
423:         }
424:     }
425: 
426:     /**
427:      * Add entries at *_nav_main
428:      *
429:      * @access protected
430:      * @param $tempXml temporary plugin definitions
431:      * @return void
432:      */
433:     protected function _installAddNavMain($tempXml) {
434:         $navMainColl = new cApiNavMainCollection();
435:         $pimPluginRelColl = new PimPluginRelationsCollection();
436:         $pluginId = $this->getPluginId();
437: 
438:         $navCount = count($tempXml->nav);
439:         for ($i = 0; $i < $navCount; $i++) {
440:             // security check
441:             $location = cSecurity::escapeString($tempXml->nav[$i]);
442: 
443:             // create a new entry at *_nav_main
444:             $navMain = $navMainColl->create($location);
445: 
446:             // set a relation
447:             $pimPluginRelColl->create($navMain->get('idnavm'), $pluginId, 'navm');
448:         }
449:     }
450: 
451:     /**
452:      * Add entries at *_nav_sub
453:      *
454:      * @access protected
455:      * @param $tempXml temporary plugin definitions
456:      * @return void
457:      */
458:     protected function _installAddNavSub($tempXml) {
459:         $navSubColl = new cApiNavSubCollection();
460:         $pimPluginRelColl = new PimPluginRelationsCollection();
461:         $pluginId = $this->getPluginId();
462: 
463:         $navCount = count($tempXml->nav);
464:         for ($i = 0; $i < $navCount; $i++) {
465: 
466:             $attributes = array();
467: 
468:             // build attributes
469:             foreach ($tempXml->nav[$i]->attributes() as $key => $value) {
470:                 $attributes[$key] = $value;
471:             }
472: 
473:             // convert area to string
474:             $attributes['area'] = cSecurity::toString($attributes['area']);
475: 
476:             // check for valid area
477:             if (!in_array($attributes['area'], $this->allAreas)) {
478:                 $this->errorArea($attributes['area']);
479:             }
480: 
481:             // create a new entry at *_nav_sub
482:             $item = $navSubColl->create($attributes['navm'], $attributes['area'], $attributes['level'], $tempXml->nav[$i], 1);
483: 
484:             // set a relation
485:             $pimPluginRelColl->create($item->get('idnavs'), $pluginId, 'navs');
486:         }
487:     }
488: 
489:     /**
490:      * Add specific sql queries
491:      *
492:      * @access protected
493:      * @return void
494:      */
495:     protected function _installAddSpecificSql() {
496:         $cfg = cRegistry::getConfig();
497:         $db = cRegistry::getDb();
498: 
499:         if ($this->isExtracted === false) {
500:             $tempSqlFilename = $this->_extractor->extractArchiveFileToVariable('plugin_install.sql', 0);
501:         } else {
502:             $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->extractedPath . '/plugin_install.sql';
503:         }
504: 
505:         if (!cFileHandler::exists($tempSqlFilename)) {
506:             return;
507:         }
508: 
509:         $tempSqlContent = cFileHandler::read($tempSqlFilename);
510:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
511:         $tempSqlContent = explode("\n", $tempSqlContent);
512:         $tempSqlLines = count($tempSqlContent);
513: 
514:         $pattern = '/(CREATE TABLE IF NOT EXISTS|INSERT INTO|UPDATE|ALTER TABLE) ' . $this->sqlPrefix . '\b/';
515: 
516:         for ($i = 0; $i < $tempSqlLines; $i++) {
517:             if (preg_match($pattern, $tempSqlContent[$i])) {
518:                 $tempSqlContent[$i] = str_replace($this->sqlPrefix, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
519:                 $db->query($tempSqlContent[$i]);
520:             }
521:         }
522:     }
523: 
524:     /**
525:      * Add content types (*_type)
526:      *
527:      * @access protected
528:      * @param $tempXml temporary plugin definitions
529:      * @return void
530:      */
531:     protected function _installAddContentTypes($tempXml) {
532:         $typeColl = new cApiTypeCollection();
533:         $pimPluginRelColl = new PimPluginRelationsCollection();
534:         $pluginId = $this->getPluginId();
535: 
536:         $pattern = '/^CMS_.+/';
537: 
538:         $typeCount = count($tempXml->type);
539:         for ($i = 0; $i < $typeCount; $i++) {
540: 
541:             $type = cSecurity::toString($tempXml->type[$i]);
542: 
543:             if (preg_match($pattern, $type)) {
544: 
545:                 // create new content type
546:                 $item = $typeColl->create($type, '');
547: 
548:                 // set a relation
549:                 $pimPluginRelColl->create($item->get('idtype'), $pluginId, 'ctype');
550:             }
551:         }
552:     }
553: 
554:     /**
555:      * Add modules
556:      *
557:      * @access protected
558:      * @return void
559:      */
560:     protected function _installAddModules($tempXml) {
561:         $cfg = cRegistry::getConfig();
562:         $module = new cApiModule();
563: 
564:         $modulesPath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $tempXml->plugin_foldername . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR;
565: 
566:         if (!is_dir($modulesPath)) {
567:             return false;
568:         }
569: 
570:         foreach (new DirectoryIterator($modulesPath) as $modulesFiles) {
571: 
572:             if (substr($modulesFiles->getBasename(), -4) == ".zip") {
573:                 $module->import($modulesFiles->getBasename(), $modulesFiles->getBasename(), false);
574:             }
575:         }
576: 
577:         $this->uninstallDir($tempXml->plugin_foldername . DIRECTORY_SEPARATOR . "modules");
578:     }
579: 
580:     /**
581:      * Uninstall a plugin
582:      *
583:      * TODO: Optimize sql method for update plugins (CON-1358)
584:      *
585:      * @access public
586:      * @param $pluginId id of uninstall plugid
587:      * @param $page page class for success message
588:      * @param $sql true or false
589:      * @return void
590:      */
591:     public function uninstall($pluginId, $page = null, $sql = true) {
592:         $cfg = cRegistry::getConfig();
593: 
594:         // security check
595:         $pluginId = cSecurity::toInteger($pluginId);
596: 
597:         // initializing collection classes
598:         $areaColl = new cApiAreaCollection();
599:         $actionColl = new cApiActionCollection();
600:         $fileColl = new cApiFileCollection();
601:         $frameFileColl = new cApiFrameFileCollection();
602:         $navMainColl = new cApiNavMainCollection();
603:         $navSubColl = new cApiNavSubCollection();
604:         $typeColl = new cApiTypeCollection();
605:         $pimPluginColl = new PimPluginCollection();
606: 
607:         // get relations
608:         $pimPluginRelColl = new PimPluginRelationsCollection();
609:         $pimPluginRelColl->setWhere('idplugin', $pluginId);
610:         $pimPluginRelColl->query();
611: 
612:         $relations = array();
613: 
614:         while (($relation = $pimPluginRelColl->next()) !== false) {
615:             // relation to tables *_area, *_nav_main and *_type
616:             $index = $relation->get('type');
617: 
618:             // is equivalent to idarea, idnavm or idtype column
619:             $value = $relation->get('iditem');
620:             $relations[$index][] = $value;
621:         }
622: 
623:         // delete entries with relations to *_area
624:         if (!empty($relations['area'])) {
625:             $actionColl->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
626:             $fileColl->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
627:             $frameFileColl->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
628:             $navSubColl->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
629:             $areaColl->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
630:         }
631: 
632:         // delete entries from *_nav_main
633:         if (!empty($relations['navm'])) {
634:             $navMainColl->deleteByWhereClause("idnavm IN('" . join("', '", $relations['navm']) . "')");
635:         }
636: 
637:         // delete content types
638:         if (!empty($relations['ctype'])) {
639:             $typeColl->deleteByWhereClause("idtype IN('" . join("', '", $relations['ctype']) . "')");
640:         }
641: 
642:         // get plugininformations
643:         $pimPluginColl->setWhere('idplugin', $pluginId);
644:         $pimPluginColl->query();
645:         $pimPluginSql = $pimPluginColl->next();
646: 
647:         $foldername = $pimPluginSql->get('folder');
648: 
649:         // delete specific sql entries or tables
650:         if ($sql == true) {
651: 
652:             if ($this->getIsUpdate() == 0) {
653:                 $this->_uninstallFullDeleteSpecificSql($foldername);
654:             } else {
655:                 $this->_uninstallUpdateDeleteSpecificSql($foldername);
656:             }
657:         }
658: 
659:         // pluginname
660:         $pluginname = $pimPluginSql->get('name');
661: 
662:         // delete entries at *_plugins_rel and *_plugins
663:         $pimPluginRelColl->deleteByWhereClause('idplugin = ' . $pluginId);
664:         $pimPluginColl->deleteByWhereClause('idplugin = ' . $pluginId);
665: 
666:         // success message
667:         if ($page instanceof cGuiPage) {
668:             $page->displayInfo(i18n('The plugin', 'pim') . ' <strong>' . $pluginname . '</strong> ' . i18n('has been successfully uninstalled. To apply the changes please login into backend again.', 'pim'));
669:         }
670:     }
671: 
672:     /**
673:      * Delete specific sql entries or tables, full uninstall mode
674:      *
675:      * @access protected
676:      * @param $foldername foldername of installed plugin
677:      * @return void
678:      */
679:     protected function _uninstallFullDeleteSpecificSql($foldername) {
680:         $cfg = cRegistry::getConfig();
681:         $db = cRegistry::getDb();
682: 
683:         $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $foldername . '/plugin_uninstall.sql';
684: 
685:         if (!cFileHandler::exists($tempSqlFilename)) {
686:             return;
687:         }
688: 
689:         $tempSqlContent = cFileHandler::read($tempSqlFilename);
690:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
691:         $tempSqlContent = explode("\n", $tempSqlContent);
692:         $tempSqlLines = count($tempSqlContent);
693: 
694:         $pattern = '/(DELETE FROM|DROP TABLE) ' . $this->sqlPrefix . '\b/';
695: 
696:         for ($i = 0; $i < $tempSqlLines; $i++) {
697:             if (preg_match($pattern, $tempSqlContent[$i])) {
698:                 $tempSqlContent[$i] = str_replace($this->sqlPrefix, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
699:                 $db->query($tempSqlContent[$i]);
700:             }
701:         }
702:     }
703: 
704:     /**
705:      * Delete specific sql entries or tables, update uninstall mode
706:      *
707:      * TODO: Optimize this function (CON-1358)
708:      *
709:      * @access protected
710:      * @param $foldername foldername of installed plugin
711:      * @return void
712:      */
713:     protected function _uninstallUpdateDeleteSpecificSql($foldername) {
714:         $cfg = cRegistry::getConfig();
715:         $db = cRegistry::getDb();
716: 
717:         // name of uploaded file
718:         $tempFileName = cSecurity::escapeString($_FILES['package']['name']);
719: 
720:         // path to temporary dir
721:         $tempFileNewPath = $cfg['path']['frontend'] . '/' . $cfg['path']['temp'];
722: 
723:         $extractor = new PimPluginArchiveExtractor($tempFileNewPath, $tempFileName);
724:         $tempSqlContent = $extractor->extractArchiveFileToVariable('plugin_update.sql');
725: 
726:         if (empty($tempSqlContent)) {
727:             return;
728:         }
729: 
730:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
731:         $tempSqlContent = explode("\n", $tempSqlContent);
732:         $tempSqlLines = count($tempSqlContent);
733: 
734:         $pattern = '/(UPDATE|ALTER TABLE|DELETE FROM|DROP TABLE) ' . $this->sqlPrefix . '\b/';
735: 
736:         for ($i = 0; $i < $tempSqlLines; $i++) {
737:             if (preg_match($pattern, $tempSqlContent[$i])) {
738:                 $tempSqlContent[$i] = str_replace($this->sqlPrefix, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
739:                 $db->query($tempSqlContent[$i]);
740:             }
741:         }
742:     }
743: 
744:     /**
745:      * Delete a installed plugin directory
746:      *
747:      * @access public
748:      * @param $foldername name of extracted plugin
749:      * @param $page page class for success or error message
750:      * @return void
751:      */
752:     public function uninstallDir($foldername, $page = null) {
753:         $cfg = cRegistry::getConfig();
754: 
755:         // delete folders
756:         $folderpath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . cSecurity::escapeString($foldername);
757:         cFileHandler::recursiveRmdir($folderpath);
758: 
759:         if ($page instanceof cGuiPage) {
760: 
761:             // success message
762:             if (!cFileHandler::exists($folderpath)) {
763:                 $page->displayInfo(i18n('The pluginfolder', 'pim') . ' <strong>' . $foldername . '</strong> ' . i18n('has been successfully uninstalled.', 'pim'));
764:             } else if (cFileHandler::exists($folderpath)) {
765:                 $page->displayError(i18n('The pluginfolder', 'pim') . ' <strong>' . $foldername . '</strong> ' . i18n('could not be uninstalled.', 'pim'));
766:             }
767:         }
768:     }
769: 
770:     /**
771:      * Enable / disable plugins (active status)
772:      *
773:      * @param integer $pluginId
774:      * @param $page page class for success or error message
775:      * @return void
776:      */
777:     public function changeActiveStatus($pluginId, $page = null) {
778:         $pimPluginColl = new PimPluginCollection();
779:         $pimPluginColl->setWhere('idplugin', cSecurity::toInteger($pluginId));
780:         $pimPluginColl->query();
781:         $plugin = $pimPluginColl->next();
782:         $pluginname = $plugin->get('name');
783:         $activeStatus = $plugin->get('active');
784: 
785:         // get relations
786:         $pimPluginRelColl = new PimPluginRelationsCollection();
787:         $pimPluginRelColl->setWhere('idplugin', cSecurity::toInteger($pluginId));
788:         $pimPluginRelColl->setWhere('type', 'navs');
789:         $pimPluginRelColl->query();
790: 
791:         if ($activeStatus == 1) { // set offline
792:             $plugin->set('active', 0);
793:             $plugin->store();
794: 
795:             while (($relation = $pimPluginRelColl->next()) !== false) {
796:                 // is equivalent to idnavs column at *_nav_sub
797:                 $idnavs = $relation->get('iditem');
798:                 $this->_setNavSubOnlineStatus($idnavs, 0);
799:             }
800: 
801:             $page->displayInfo(i18n('The plugin', 'pim') . ' <strong>' . $pluginname . '</strong> ' . i18n('has been sucessfully disabled. To apply the changes please login into backend again.', 'pim'));
802:         } else { // set online
803:             $plugin->set('active', 1);
804:             $plugin->store();
805: 
806:             while (($relation = $pimPluginRelColl->next()) !== false) {
807:                 // is equivalent to idnavs column at *_nav_sub
808:                 $idnavs = $relation->get('iditem');
809:                 $this->_setNavSubOnlineStatus($idnavs, 1);
810:             }
811: 
812:             $page->displayInfo(i18n('The plugin', 'pim') . ' <strong>' . $pluginname . '</strong> ' . i18n('has been sucessfully enabled. To apply the changes please login into backend again.', 'pim'));
813:         }
814:     }
815: 
816:     /**
817:      * Set the online status of nav_sub
818:      *
819:      * @param integer $idnavs Id of nav_sub menu (is equivalent to idnavs
820:      * @param integer $online 0 = offline, 1 = online
821:      * @return true
822:      */
823:     protected function _setNavSubOnlineStatus($idnavs, $online) {
824:         $navSubColl = new cApiNavSubCollection();
825:         $navSubColl->setWhere('idnavs', cSecurity::toInteger($idnavs));
826:         $navSubColl->query();
827: 
828:         $navSub = $navSubColl->next();
829:         $navSub->set('online', cSecurity::toInteger($online));
830:         $navSub->store();
831: 
832:         return true;
833:     }
834: 
835:     /**
836:      * Check uuId for update routine
837:      *
838:      * @access protected
839:      * @param integer $pluginId id of installed plugid
840:      * @return void
841:      */
842:     public function checkSamePlugin($pluginId = '0') {
843:         $cfg = cRegistry::getConfig();
844:         $db = cRegistry::getDb();
845:         $sess = cRegistry::getSession();
846: 
847:         // name of uploaded file
848:         $tempFileName = cSecurity::escapeString($_FILES['package']['name']);
849: 
850:         // path to temporary dir
851:         $tempFileNewPath = $cfg['path']['frontend'] . '/' . $cfg['path']['temp'];
852: 
853:         // move temporary files into CONTENIDO temp dir
854:         move_uploaded_file($_FILES['package']['tmp_name'], $tempFileNewPath . $tempFileName);
855: 
856:         // initalizing plugin archive extractor
857:         try {
858:             $extractor = new PimPluginArchiveExtractor($tempFileNewPath, $tempFileName);
859:             $this->addArchiveObject($extractor);
860:         } catch (cException $e) {
861:             $extractor->destroyTempFiles();
862:         }
863: 
864:         // extract plugin.xml content to variable
865:         $tempPluginXmlContent = $extractor->extractArchiveFileToVariable('plugin.xml');
866:         $this->setTempXml($tempPluginXmlContent);
867: 
868:         // load plugin.xml to an xml-string
869:         $tempXml = simplexml_load_string($this->getTempXml());
870: 
871:         // save new uuId
872:         $newId = $tempXml->general->uuid;
873: 
874:         // initializing PimPluginCollection class
875:         $pimPluginColl = new PimPluginCollection();
876: 
877:         // if pluginId is not null, add idplugin for sql statement (case:
878:         // update)
879:         if ($pluginId != '0') {
880:             $pimPluginColl->setWhere('idplugin', $pluginId);
881:         }
882: 
883:         $pimPluginColl->query();
884:         while ($result = $pimPluginColl->next()) {
885: 
886:             // save old uuId
887:             $oldId = $result->get('uuid');
888: 
889:             if ($pluginId == 0 && $newId == $oldId) { // case: new installation
890:                                                       // failed
891:                 $pageError = new cGuiPage('pim_error', 'pim');
892:                 $pageError->set('s', 'BACKLINK', $sess->url('main.php?area=pim&frame=4'));
893:                 $pageError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
894:                 $pageError->displayError(i18n('This plugin is already installed', 'pim'));
895:                 $pageError->render();
896:                 exit();
897:             } elseif ($pluginId != 0 && $newId != $oldId) { // case: update
898:                                                             // failed
899:                 $pageError = new cGuiPage('pim_error', 'pim');
900:                 $pageError->set('s', 'BACKLINK', $sess->url('main.php?area=pim&frame=4'));
901:                 $pageError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
902:                 $pageError->displayError(i18n('You have to update the same plugin', 'pim'));
903:                 $pageError->render();
904:                 exit();
905:             }
906:         }
907:     }
908: 
909:     /**
910:      * Check file type, Plugin Manager accepts only Zip archives
911:      *
912:      * @access public
913:      * @return void
914:      */
915:     public function checkZip() {
916:         $sess = cRegistry::getSession();
917: 
918:         if (substr($_FILES['package']['name'], -4) != ".zip") {
919:             $pageError = new cGuiPage('pim_error', 'pim');
920:             $pageError->set('s', 'BACKLINK', $sess->url('main.php?area=pim&frame=4'));
921:             $pageError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
922:             $pageError->displayError(i18n('Plugin Manager accepts only Zip archives', 'pim'));
923:             $pageError->render();
924:             exit();
925:         }
926:     }
927: 
928:     /**
929:      * Error message function for not existing areas
930:      *
931:      * @access protected
932:      * @param string $area name of not existing area
933:      */
934:     protected function errorArea($area) {
935:         $sess = cRegistry::getSession();
936: 
937:         // uninstall plugin from database
938:         $this->uninstall($this->pluginId, null, false);
939: 
940:         // error template
941:         $pageError = new cGuiPage('pim_error', 'pim');
942:         $pageError->set('s', 'BACKLINK', $sess->url('main.php?area=pim&frame=4'));
943:         $pageError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
944:         $pageError->displayError(i18n('Defined area', 'pim') . ' <strong>' . $area . '</strong> ' . i18n('are not found on your CONTENIDO installation. Please contact your plugin author.', 'pim'));
945:         $pageError->render();
946:         exit();
947:     }
948: 
949: }
950: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0