1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24: 25:
26: class PimPluginSetup {
27:
28: protected $sqlPrefix = "!PREFIX!";
29:
30: protected $valid = false;
31:
32: protected $tempXml;
33:
34: protected = false;
35:
36: protected ;
37:
38: protected $pluginId = 0;
39:
40: protected $allAreas = array();
41:
42: protected $isUpdate = 0;
43:
44: protected ;
45: public function addArchiveObject($extractor) {
46: $this->_extractor = $extractor;
47: }
48:
49: 50: 51: 52: 53: 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: 81: 82: 83: 84:
85: public function checkRequirements() {
86:
87:
88: $cfg = cRegistry::getConfig();
89:
90:
91: $xml = simplexml_load_string($this->getTempXml());
92:
93:
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:
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:
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:
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:
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:
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: 147: 148: 149: 150: 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: 165: 166: 167: 168:
169: public function getTempXml() {
170: return $this->tempXml;
171: }
172:
173: 174: 175: 176: 177: 178:
179: public function getValid() {
180: return $this->valid;
181: }
182:
183: 184: 185: 186: 187: 188:
189: public function getPluginId() {
190: return $this->pluginId;
191: }
192:
193: 194: 195: 196: 197: 198: 199: 200: 201: 202:
203: public function getIsUpdate() {
204: return $this->isUpdate;
205: }
206:
207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217:
218: public function setIsUpdate($value) {
219: $this->isUpdate = $value;
220: }
221:
222: 223: 224: 225: 226: 227: 228:
229: public function setTempXml($value) {
230: $this->tempXml = $value;
231: }
232:
233: 234: 235: 236: 237: 238: 239:
240: public function ($value) {
241: $this->isExtracted = $value;
242: }
243:
244: 245: 246: 247: 248: 249: 250:
251: public function ($value) {
252: $this->extractedPath = $value;
253: }
254:
255: 256: 257: 258: 259: 260: 261:
262: public function setPluginId($value) {
263: $this->pluginId = $value;
264: }
265:
266: 267: 268: 269: 270: 271: 272:
273: public function install($tempXml) {
274: $pimPluginColl = new PimPluginCollection();
275:
276:
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:
281: $this->setPluginId($pluginId);
282:
283:
284: $this->_installAddArea($tempXml->contenido->areas);
285:
286:
287: $this->_installAddActions($tempXml->contenido->actions);
288:
289:
290: $this->_installAddFrames($tempXml->contenido->frames);
291:
292:
293: $this->_installAddNavMain($tempXml->contenido->nav_main);
294:
295:
296: $this->_installAddNavSub($tempXml->contenido->nav_sub);
297:
298:
299: if ($this->getIsUpdate() == 0) {
300: $this->_installAddSpecificSql();
301: }
302:
303:
304: $this->_installAddContentTypes($tempXml->content_types);
305:
306:
307: $this->_installAddModules($tempXml->general);
308: }
309:
310: 311: 312: 313: 314: 315: 316:
317: protected function _installAddArea($tempXml) {
318: $areaColl = new cApiAreaCollection();
319: $pimPluginRelColl = new PimPluginRelationsCollection();
320: $pluginId = $this->getPluginId();
321:
322:
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:
334: foreach ($tempXml->area[$i]->attributes() as $key => $value) {
335: $attributes[$key] = $value;
336: }
337:
338:
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:
346: if (empty($attributes['parent'])) {
347: $attributes['parent'] = 0;
348: }
349:
350:
351: $item = $areaColl->create($area, $attributes['parent'], 1, 1, $attributes['menuless']);
352:
353:
354: $pimPluginRelColl->create($item->get('idarea'), $pluginId, 'area');
355:
356:
357: $this->allAreas[] = $area;
358: }
359: }
360:
361: 362: 363: 364: 365: 366: 367:
368: protected function _installAddActions($tempXml) {
369: $actionColl = new cApiActionCollection();
370:
371: $actionCount = count($tempXml->action);
372: for ($i = 0; $i < $actionCount; $i++) {
373:
374: $area = $tempXml->action[$i]->attributes();
375:
376:
377: $area = cSecurity::escapeString($area);
378: $action = cSecurity::escapeString($tempXml->action[$i]);
379:
380:
381: if (!in_array($area, $this->allAreas)) {
382: $this->errorArea($area);
383: }
384:
385:
386: $actionColl->create($area, $action, '', '', '', 1);
387: }
388: }
389:
390: 391: 392: 393: 394: 395: 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:
407: foreach ($tempXml->frame[$i]->attributes() as $sKey => $sValue) {
408: $attributes[$sKey] = cSecurity::escapeString($sValue);
409: }
410:
411:
412: if (!in_array($attributes['area'], $this->allAreas)) {
413: $this->errorArea($attributes['area']);
414: }
415:
416:
417: $file = $fileColl->create($attributes['area'], $attributes['name'], $attributes['filetype']);
418:
419:
420: if (!empty($attributes['frameId'])) {
421: $frameFileColl->create($attributes['area'], $attributes['frameId'], $file->get('idfile'));
422: }
423: }
424: }
425:
426: 427: 428: 429: 430: 431: 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:
441: $location = cSecurity::escapeString($tempXml->nav[$i]);
442:
443:
444: $navMain = $navMainColl->create($location);
445:
446:
447: $pimPluginRelColl->create($navMain->get('idnavm'), $pluginId, 'navm');
448: }
449: }
450:
451: 452: 453: 454: 455: 456: 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:
469: foreach ($tempXml->nav[$i]->attributes() as $key => $value) {
470: $attributes[$key] = $value;
471: }
472:
473:
474: $attributes['area'] = cSecurity::toString($attributes['area']);
475:
476:
477: if (!in_array($attributes['area'], $this->allAreas)) {
478: $this->errorArea($attributes['area']);
479: }
480:
481:
482: $item = $navSubColl->create($attributes['navm'], $attributes['area'], $attributes['level'], $tempXml->nav[$i], 1);
483:
484:
485: $pimPluginRelColl->create($item->get('idnavs'), $pluginId, 'navs');
486: }
487: }
488:
489: 490: 491: 492: 493: 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: 526: 527: 528: 529: 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:
546: $item = $typeColl->create($type, '');
547:
548:
549: $pimPluginRelColl->create($item->get('idtype'), $pluginId, 'ctype');
550: }
551: }
552: }
553:
554: 555: 556: 557: 558: 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: 582: 583: 584: 585: 586: 587: 588: 589: 590:
591: public function uninstall($pluginId, $page = null, $sql = true) {
592: $cfg = cRegistry::getConfig();
593:
594:
595: $pluginId = cSecurity::toInteger($pluginId);
596:
597:
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:
608: $pimPluginRelColl = new PimPluginRelationsCollection();
609: $pimPluginRelColl->setWhere('idplugin', $pluginId);
610: $pimPluginRelColl->query();
611:
612: $relations = array();
613:
614: while (($relation = $pimPluginRelColl->next()) !== false) {
615:
616: $index = $relation->get('type');
617:
618:
619: $value = $relation->get('iditem');
620: $relations[$index][] = $value;
621: }
622:
623:
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:
633: if (!empty($relations['navm'])) {
634: $navMainColl->deleteByWhereClause("idnavm IN('" . join("', '", $relations['navm']) . "')");
635: }
636:
637:
638: if (!empty($relations['ctype'])) {
639: $typeColl->deleteByWhereClause("idtype IN('" . join("', '", $relations['ctype']) . "')");
640: }
641:
642:
643: $pimPluginColl->setWhere('idplugin', $pluginId);
644: $pimPluginColl->query();
645: $pimPluginSql = $pimPluginColl->next();
646:
647: $foldername = $pimPluginSql->get('folder');
648:
649:
650: if ($sql == true) {
651:
652: if ($this->getIsUpdate() == 0) {
653: $this->_uninstallFullDeleteSpecificSql($foldername);
654: } else {
655: $this->_uninstallUpdateDeleteSpecificSql($foldername);
656: }
657: }
658:
659:
660: $pluginname = $pimPluginSql->get('name');
661:
662:
663: $pimPluginRelColl->deleteByWhereClause('idplugin = ' . $pluginId);
664: $pimPluginColl->deleteByWhereClause('idplugin = ' . $pluginId);
665:
666:
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: 674: 675: 676: 677: 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: 706: 707: 708: 709: 710: 711: 712:
713: protected function _uninstallUpdateDeleteSpecificSql($foldername) {
714: $cfg = cRegistry::getConfig();
715: $db = cRegistry::getDb();
716:
717:
718: $tempFileName = cSecurity::escapeString($_FILES['package']['name']);
719:
720:
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: 746: 747: 748: 749: 750: 751:
752: public function uninstallDir($foldername, $page = null) {
753: $cfg = cRegistry::getConfig();
754:
755:
756: $folderpath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . cSecurity::escapeString($foldername);
757: cFileHandler::recursiveRmdir($folderpath);
758:
759: if ($page instanceof cGuiPage) {
760:
761:
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: 772: 773: 774: 775: 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:
786: $pimPluginRelColl = new PimPluginRelationsCollection();
787: $pimPluginRelColl->setWhere('idplugin', cSecurity::toInteger($pluginId));
788: $pimPluginRelColl->setWhere('type', 'navs');
789: $pimPluginRelColl->query();
790:
791: if ($activeStatus == 1) {
792: $plugin->set('active', 0);
793: $plugin->store();
794:
795: while (($relation = $pimPluginRelColl->next()) !== false) {
796:
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 {
803: $plugin->set('active', 1);
804: $plugin->store();
805:
806: while (($relation = $pimPluginRelColl->next()) !== false) {
807:
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: 818: 819: 820: 821: 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: 837: 838: 839: 840: 841:
842: public function checkSamePlugin($pluginId = '0') {
843: $cfg = cRegistry::getConfig();
844: $db = cRegistry::getDb();
845: $sess = cRegistry::getSession();
846:
847:
848: $tempFileName = cSecurity::escapeString($_FILES['package']['name']);
849:
850:
851: $tempFileNewPath = $cfg['path']['frontend'] . '/' . $cfg['path']['temp'];
852:
853:
854: move_uploaded_file($_FILES['package']['tmp_name'], $tempFileNewPath . $tempFileName);
855:
856:
857: try {
858: $extractor = new PimPluginArchiveExtractor($tempFileNewPath, $tempFileName);
859: $this->addArchiveObject($extractor);
860: } catch (cException $e) {
861: $extractor->destroyTempFiles();
862: }
863:
864:
865: $tempPluginXmlContent = $extractor->extractArchiveFileToVariable('plugin.xml');
866: $this->setTempXml($tempPluginXmlContent);
867:
868:
869: $tempXml = simplexml_load_string($this->getTempXml());
870:
871:
872: $newId = $tempXml->general->uuid;
873:
874:
875: $pimPluginColl = new PimPluginCollection();
876:
877:
878:
879: if ($pluginId != '0') {
880: $pimPluginColl->setWhere('idplugin', $pluginId);
881: }
882:
883: $pimPluginColl->query();
884: while ($result = $pimPluginColl->next()) {
885:
886:
887: $oldId = $result->get('uuid');
888:
889: if ($pluginId == 0 && $newId == $oldId) {
890:
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) {
898:
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: 911: 912: 913: 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: 930: 931: 932: 933:
934: protected function errorArea($area) {
935: $sess = cRegistry::getSession();
936:
937:
938: $this->uninstall($this->pluginId, null, false);
939:
940:
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: