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 $XmlArea;
62:
63:
64: public static $XmlActions;
65:
66:
67: public static $XmlFrames;
68:
69:
70: public static $XmlNavMain;
71:
72:
73: public static $XmlNavSub;
74:
75:
76: public static $XmlContentType;
77:
78:
79: protected static $_pluginId = 0;
80:
81:
82: 83: 84: 85: 86: 87: 88:
89: public static function setMode($mode) {
90: switch ($mode) {
91: case 'extracted':
92: self::$mode = 1;
93: break;
94: case 'uploaded':
95: self::$mode = 2;
96: break;
97: case 'uninstall':
98: self::$mode = 3;
99: break;
100: case 'update':
101: self::$mode = 4;
102: break;
103: }
104: }
105:
106: 107: 108: 109: 110:
111: public function setPageClass($page) {
112: return self::$_GuiPage = $page;
113: }
114:
115: 116: 117: 118: 119:
120: protected function _setUpdateSqlFileExist($value) {
121: self::$_updateSqlFileExist = cSecurity::toBoolean($value);
122: }
123:
124: 125: 126: 127: 128: 129: 130:
131: protected static function ($tempArchiveNewPath, $tempArchiveName) {
132: return self::$_PimPluginArchiveExtractor = new PimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
133: }
134:
135: 136: 137: 138: 139:
140: private function _setXml($xml) {
141:
142:
143: self::$XmlGeneral = $xml->general;
144:
145:
146: self::$XmlRequirements = $xml->requirements;
147:
148:
149: self::$XmlArea = $xml->contenido->areas;
150:
151:
152: self::$XmlActions = $xml->contenido->actions;
153:
154:
155: self::$XmlFrames = $xml->contenido->frames;
156:
157:
158: self::$XmlNavMain = $xml->contenido->nav_main;
159:
160:
161: self::$XmlNavSub = $xml->contenido->nav_sub;
162:
163:
164: self::$XmlContentType = $xml->content_types;
165: }
166:
167: 168: 169: 170: 171: 172:
173: public function setPluginId($pluginId = 0) {
174: return self::$_pluginId = $pluginId;
175: }
176:
177: 178: 179: 180: 181:
182: public static function getMode() {
183: return self::$mode;
184: }
185:
186: 187: 188: 189: 190:
191: protected static function _getPluginId() {
192: return self::$_pluginId;
193: }
194:
195: 196: 197: 198: 199:
200: protected function _getUpdateSqlFileExist() {
201: return self::$_updateSqlFileExist;
202: }
203:
204:
205: 206: 207: 208:
209: public function checkXml() {
210: $cfg = cRegistry::getConfig();
211:
212: if (self::getMode() == 1) {
213: $XmlData = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . cSecurity::escapeString($_GET['pluginFoldername']) . DIRECTORY_SEPARATOR . self::PLUGIN_XML_FILENAME);
214: } elseif (self::getMode() == 2 || self::getMode() == 4) {
215:
216:
217:
218:
219: $tempArchiveNewPath = $cfg['path']['frontend'] . DIRECTORY_SEPARATOR . $cfg['path']['temp'];
220:
221:
222: $tempArchiveName = cSecurity::escapeString($_FILES['package']['name']);
223:
224:
225: try {
226: self::_setPimPluginArchiveExtractor($tempArchiveNewPath, $tempArchiveName);
227: } catch (cException $e) {
228: self::$_PimPluginArchiveExtractor->destroyTempFiles();
229: }
230:
231:
232: $this->checkZip();
233:
234:
235: move_uploaded_file($_FILES['package']['tmp_name'], $tempArchiveNewPath . $tempArchiveName);
236:
237:
238: $XmlData = self::$_PimPluginArchiveExtractor->extractArchiveFileToVariable(self::PLUGIN_XML_FILENAME);
239: }
240:
241:
242: if ($this->validXml($XmlData) === true) {
243: $this->_setXml(simplexml_load_string($XmlData));
244: } else {
245: return self::error(i18n('Invalid Xml document. Please contact the plugin author.', 'pim'));
246: }
247: }
248:
249: 250: 251:
252: private function checkZip() {
253: if (substr($_FILES['package']['name'], -4) != ".zip") {
254: self::error(i18n('Plugin Manager accepts only Zip archives', 'pim'));
255: }
256: }
257:
258: 259: 260: 261: 262:
263: private function validXml($xml) {
264:
265: $dom = new DomDocument();
266: $dom->loadXML($xml);
267:
268:
269: if ($dom->schemaValidate('plugins' . DIRECTORY_SEPARATOR . 'pim' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'plugin_info.xsd')) {
270: return true;
271: } else {
272: return false;
273: }
274: }
275:
276: 277: 278: 279:
280: protected static function error($message = '') {
281:
282:
283: $session = cRegistry::getSession();
284:
285:
286: if (self::getMode() == 2) {
287: self::$_PimPluginArchiveExtractor->destroyTempFiles();
288: }
289:
290:
291: $pimError = new cGuiPage('pim_error', 'pim');
292: $pimError->set('s', 'BACKLINK', $session->url('main.php?area=pim&frame=4'));
293: $pimError->set('s', 'LANG_BACKLINK', i18n('Back to Plugin Manager', 'pim'));
294: $pimError->displayError($message);
295: $pimError->render();
296: exit();
297: }
298:
299: 300: 301: 302:
303: protected static function info($message = '') {
304: return self::$_GuiPage->displayInfo($message);
305: }
306:
307: }
308:
309: ?>