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: class PimPluginSetup {
26:
27:
28:
29:
30: public static $mode = 0;
31:
32:
33: const PLUGIN_XML_FILENAME = "plugin.xml";
34:
35:
36: const SQL_PREFIX = "!PREFIX!";
37:
38:
39: protected static $_GuiPage;
40:
41:
42: protected static ;
43:
44: 45: 46: 47: 48: 49: 50:
51: private static $_updateSqlFileExist = false;
52:
53:
54:
55: public static $XmlGeneral;
56:
57:
58: public static $XmlRequirements;
59:
60:
61: public static $XmlDependencies;
62:
63:
64: public static $XmlArea;
65:
66:
67: public static $XmlActions;
68:
69:
70: public static $XmlFrames;
71:
72:
73: public static $XmlNavMain;
74:
75:
76: public static $XmlNavSub;
77:
78:
79: public static $XmlContentType;
80:
81:
82: protected static $_pluginId = 0;
83:
84:
85: protected static $_pluginName;
86:
87:
88: 89: 90: 91: 92: 93: 94:
95: public static function setMode($mode) {
96: switch ($mode) {
97: case 'extracted':
98: self::$mode = 1;
99: break;
100: case 'uploaded':
101: self::$mode = 2;
102: break;
103: case 'uninstall':
104: self::$mode = 3;
105: break;
106: case 'update':
107: self::$mode = 4;
108: break;
109: }
110: }
111:
112: 113: 114: 115: 116:
117: public function setPageClass($page) {
118: return self::$_GuiPage = $page;
119: }
120:
121: 122: 123: 124: 125:
126: protected function _setUpdateSqlFileExist($value) {
127: self::$_updateSqlFileExist = cSecurity::toBoolean($value);
128: }
129:
130: 131: 132: 133: 134: 135: 136:
137: protected static function ($tempArchiveNewPath, $tempArchiveName) {
138: return self::$_PimPluginArchiveExtractor = new PimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
139: }
140:
141: 142: 143: 144: 145:
146: private function _setXml($xml) {
147:
148:
149: self::$XmlGeneral = $xml->general;
150:
151:
152: self::$XmlRequirements = $xml->requirements;
153:
154:
155: self::$XmlDependencies = $xml->dependencies;
156:
157:
158: self::$XmlArea = $xml->contenido->areas;
159:
160:
161: self::$XmlActions = $xml->contenido->actions;
162:
163:
164: self::$XmlFrames = $xml->contenido->frames;
165:
166:
167: self::$XmlNavMain = $xml->contenido->nav_main;
168:
169:
170: self::$XmlNavSub = $xml->contenido->nav_sub;
171:
172:
173: self::$XmlContentType = $xml->content_types;
174: }
175:
176: 177: 178: 179: 180: 181:
182: public function setPluginId($pluginId = 0) {
183: return self::$_pluginId = $pluginId;
184: }
185:
186: 187: 188: 189: 190: 191:
192: public function setPluginName($pluginName = '') {
193: return self::$_pluginName = $pluginName;
194: }
195:
196: 197: 198: 199: 200:
201: public static function getMode() {
202: return self::$mode;
203: }
204:
205: 206: 207: 208: 209:
210: protected static function _getPluginId() {
211: return self::$_pluginId;
212: }
213:
214: 215: 216: 217: 218:
219: protected static function _getPluginName() {
220: return self::$_pluginName;
221: }
222:
223: 224: 225: 226: 227:
228: protected function _getUpdateSqlFileExist() {
229: return self::$_updateSqlFileExist;
230: }
231:
232:
233: 234: 235: 236:
237: public function checkXml() {
238: $cfg = cRegistry::getConfig();
239:
240: if (self::getMode() == 1) {
241: $XmlData = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . cSecurity::escapeString($_GET['pluginFoldername']) . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME);
242: } elseif (self::getMode() == 2 || self::getMode() == 4) {
243:
244:
245:
246:
247: $tempArchiveNewPath = $cfg['path']['frontend'] . DIRECTORY_SEPARATOR . $cfg['path']['temp'];
248:
249:
250: $tempArchiveName = cSecurity::escapeString($_FILES['package']['name']);
251:
252:
253: move_uploaded_file($_FILES['package']['tmp_name'], $tempArchiveNewPath . $tempArchiveName);
254:
255:
256: try {
257: self::_setPimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
258: } catch (cException $e) {
259: self::$_PimPluginArchiveExtractor->destroyTempFiles();
260: }
261:
262:
263: $this->checkZip();
264:
265:
266: $XmlData = self::$_PimPluginArchiveExtractor->extractArchiveFileToVariable(self::PLUGIN_XML_FILENAME);
267: }
268:
269:
270: if ($this->validXml($XmlData) === true) {
271: $this->_setXml(simplexml_load_string($XmlData));
272: } else {
273: return self::error(i18n('Invalid Xml document. Please contact the plugin author.', 'pim'));
274: }
275: }
276:
277: 278: 279: 280: 281: 282: 283:
284: public function checkDependencies() {
285:
286:
287: $cfg = cRegistry::getConfig();
288: $pluginsDir = $cfg['path']['contenido'] . $cfg['path']['plugins'];
289:
290:
291: $this->_PimPluginCollection->setWhere('idplugin', self::_getPluginId());
292: $this->_PimPluginCollection->query();
293: $pimPluginSql = $this->_PimPluginCollection->next();
294: $uuidUninstall = $pimPluginSql->get('uuid');
295:
296:
297: $this->_PimPluginCollection->resetQuery();
298:
299:
300: $dirs = cDirHandler::read($pluginsDir);
301: foreach ($dirs as $dirname) {
302:
303:
304: if (!cFileHandler::exists($pluginsDir . $dirname . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME)) {
305: continue;
306: }
307:
308:
309: $tempXmlContent = cFileHandler::read($pluginsDir . $dirname . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME);
310:
311:
312: $tempXml = simplexml_load_string($tempXmlContent);
313:
314: $dependenciesCount = count($tempXml->dependencies);
315: for ($i = 0; $i < $dependenciesCount; $i++) {
316:
317:
318: $depend = cSecurity::escapeString($tempXml->dependencies->depend[$i]);
319:
320:
321: if ($depend == "") {
322: continue;
323: }
324:
325:
326: foreach ($tempXml->dependencies->depend[$i]->attributes() as $key => $value) {
327:
328:
329: if ($key == "uuid") {
330: $uuidTemp = cSecurity::escapeString($value);
331: }
332: }
333:
334:
335:
336: if ($uuidTemp === $uuidUninstall) {
337:
338: $this->_PimPluginCollection->setWhere('uuid', $tempXml->general->uuid);
339: $this->_PimPluginCollection->setWhere('active', '1');
340: $this->_PimPluginCollection->query();
341: if ($this->_PimPluginCollection->count() != 0) {
342: self::setPluginName($tempXml->general->plugin_name);
343: return false;
344: }
345: }
346: }
347: }
348:
349: return true;
350: }
351:
352:
353: 354: 355:
356: private function checkZip() {
357: if (substr($_FILES['package']['name'], -4) != ".zip") {
358: self::error(i18n('Plugin Manager accepts only Zip archives', 'pim'));
359: }
360: }
361:
362: 363: 364: 365: 366:
367: private function validXml($xml) {
368:
369: $dom = new DomDocument();
370: $dom->loadXML($xml);
371:
372:
373: if ($dom->schemaValidate('plugins' . DIRECTORY_SEPARATOR . 'pim' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'plugin_info.xsd')) {
374: return true;
375: } else {
376: return false;
377: }
378: }
379:
380: 381: 382: 383:
384: protected static function error($message = '') {
385:
386:
387: $session = cRegistry::getSession();
388:
389:
390: if (self::getMode() == 2) {
391: self::$_PimPluginArchiveExtractor->destroyTempFiles();
392: }
393:
394:
395: $pimError = new cGuiPage('pim_error', 'pim');
396: $pimError->set('s', 'BACKLINK', $session->url('main.php?area=pim&frame=4'));
397: $pimError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
398: $pimError->displayError($message);
399: $pimError->render();
400: exit();
401: }
402:
403: 404: 405: 406:
407: protected static function info($message = '') {
408: return self::$_GuiPage->displayInfo($message);
409: }
410:
411: }
412:
413: ?>