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: $page = new cGuiPage('pim_overview', 'pim');
20:
21: $setup = new PimPluginSetup();
22:
23:
24: if (!$perm->isSysadmin($currentuser)) {
25: $page->displayCriticalError(i18n("Permission denied"));
26: $page->render();
27: exit();
28: }
29:
30:
31: if ($cfg['debug']['disable_plugins'] === true) {
32: $page->displayWarning(i18n('Currently the plugin system is disabled via configuration', 'pim'));
33: }
34:
35: $viewAction = isset($_REQUEST['pim_view'])? $_REQUEST['pim_view'] : 'overview';
36:
37: switch ($viewAction) {
38: case 'activestatus':
39: $setup->changeActiveStatus($_GET['pluginId'], $page);
40: break;
41: case 'update':
42: $setup->checkZip();
43: $setup->checkSamePlugin($_POST['pluginId']);
44: $setup->setIsUpdate(1);
45: $setup->uninstall($_POST['pluginId']);
46: installationRoutine($page, true, $_POST['foldername'], true);
47: break;
48: case 'uninstall':
49: $setup->uninstall($_GET['pluginId']);
50: break;
51: case 'uninstall-extracted':
52: $setup->uninstallDir($_GET['pluginFoldername'], $page);
53: break;
54: case 'install':
55: $setup->checkZip();
56: $setup->checkSamePlugin();
57: installationRoutine($page);
58: break;
59: case 'install-extracted':
60: installationRoutine($page, true, $_GET['pluginFoldername']);
61: break;
62: }
63:
64:
65: 66: 67: 68: 69: 70: 71: 72: 73: 74:
75: function installationRoutine($page, $isExtracted = false, $extractedPath = '', $update = false) {
76: global $setup;
77: $cfg = cRegistry::getConfig();
78: $sess = cRegistry::getSession();
79:
80: if ($isExtracted === false) {
81:
82:
83: $tempFileName = cSecurity::escapeString($_FILES['package']['name']);
84:
85:
86: $tempFileNewPath = $cfg['path']['frontend'] . '/' . $cfg['path']['temp'];
87:
88:
89: move_uploaded_file($_FILES['package']['tmp_name'], $tempFileNewPath . $tempFileName);
90:
91:
92: try {
93: $extractor = new PimPluginArchiveExtractor($tempFileNewPath, $tempFileName);
94: $setup->addArchiveObject($extractor);
95: } catch (cException $e) {
96: $extractor->destroyTempFiles();
97: }
98:
99: $tempPluginXmlContent = $extractor->extractArchiveFileToVariable('plugin.xml');
100: $setup->setTempXml($tempPluginXmlContent);
101: } else {
102: $tempPluginXmlContent = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . $extractedPath . '/plugin.xml');
103: $setup->setTempXml($tempPluginXmlContent);
104: $setup->setIsExtracted($isExtracted);
105: $setup->setExtractedPath($extractedPath);
106: }
107:
108:
109: $setup->checkValidXml();
110:
111:
112: $tempXml = simplexml_load_string($setup->getTempXml());
113:
114:
115: $setup->checkRequirements();
116:
117:
118: $tempPluginDir = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $tempXml->general->plugin_foldername . DIRECTORY_SEPARATOR;
119:
120:
121: if ($setup->getValid() === true && $isExtracted === false) {
122: try {
123: $extractor->setDestinationPath($tempPluginDir);
124: } catch (cException $e) {
125: $extractor->destroyTempFiles();
126: }
127:
128: try {
129: $extractor->extractArchive();
130: } catch (cException $e) {
131: $extractor->destroyTempFiles();
132: }
133: }
134:
135: if ($isExtracted === true) {
136:
137:
138: $setup->install($tempXml);
139:
140:
141: if ($update == false) {
142: $page->displayInfo(i18n('The plugin has been successfully installed. To apply the changes please login into backend again.', 'pim'));
143: } else {
144: $page->displayInfo(i18n('The plugin has been successfully updated. To apply the changes please login into backend again.', 'pim'));
145: }
146: } else {
147:
148:
149: $page->displayInfo(i18n('The plugin has been successfully uploaded. Now you can install it.', 'pim'));
150:
151:
152: $extractor->closeArchive();
153: }
154: }
155:
156:
157: $tempTplPath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . 'pim/templates';
158:
159:
160: $installedPluginFoldernames = array();
161:
162:
163: $oItem = new PimPluginCollection();
164: $oItem->select(null, null, 'name');
165:
166: while (($plugin = $oItem->next()) !== false) {
167:
168:
169: $pagePlugins = new cTemplate();
170:
171:
172: $date = date_format(date_create($plugin->get('installed')), i18n('Y-m-d', 'pim'));
173:
174: $pagePlugins->set('s', 'IDPLUGIN', $plugin->get('idplugin'));
175: $pagePlugins->set('s', 'FOLDERNAME', $plugin->get('folder'));
176: $pagePlugins->set('s', 'NAME', $plugin->get('name'));
177: $pagePlugins->set('s', 'VERSION', $plugin->get('version'));
178: $pagePlugins->set('s', 'DESCRIPTION', $plugin->get('description'));
179: $pagePlugins->set('s', 'AUTHOR', $plugin->get('author'));
180: $pagePlugins->set('s', 'MAIL', $plugin->get('mail'));
181: $pagePlugins->set('s', 'WEBSITE', $plugin->get('website'));
182: $pagePlugins->set('s', 'COPYRIGHT', $plugin->get('copyright'));
183: $pagePlugins->set('s', 'INSTALLED', $date);
184:
185: $pagePlugins->set('s', 'LANG_INSTALLED', i18n('Installed since', 'pim'));
186: $pagePlugins->set('s', 'LANG_AUTHOR', i18n('Author', 'pim'));
187: $pagePlugins->set('s', 'LANG_CONTACT', i18n('Contact', 'pim'));
188:
189: $pagePlugins->set('s', 'LANG_UPDATE', i18n('Update', 'pim'));
190: $pagePlugins->set('s', 'LANG_UPDATE_CHOOSE', i18n('Please choose your new file', 'pim'));
191: $pagePlugins->set('s', 'LANG_UPDATE_UPLOAD', i18n('Update', 'pim'));
192:
193:
194: $activeStatus = $plugin->get('active');
195: $tempActiveStatusLink = $sess->url('main.php?area=pim&frame=4&pim_view=activestatus&pluginId=' . $plugin->get('idplugin'));
196: if ($activeStatus == 1) {
197: $pagePlugins->set('s', 'LANG_ACTIVESTATUS', '<img src="images/online.gif" class="vAlignMiddle" /> <a href="' . $tempActiveStatusLink . '">' . i18n('Disable plugin', 'pim') . '</a>');
198: } else {
199: $pagePlugins->set('s', 'LANG_ACTIVESTATUS', '<img src="images/offline.gif" class="vAlignMiddle" /> <a href="' . $tempActiveStatusLink . '">' . i18n('Enable plugin', 'pim') . '</a>');
200: }
201:
202:
203: $tempUninstallLink = $sess->url('main.php?area=pim&frame=4&pim_view=uninstall&pluginId=' . $plugin->get('idplugin'));
204: $pagePlugins->set('s', 'UNINSTALL_LINK', '<a href="javascript:void(0)" onclick="javascript:showConfirmation(\'' . i18n('Are you sure to delete this plugin? Files are not deleted in filesystem.', 'pim') . '\', function() { window.location.href=\'' . $tempUninstallLink . '\';})">' . i18n('Uninstall', 'pim') . '</a>');
205:
206:
207: $installedPluginFoldernames[] = $plugin->get('folder');
208:
209: $pluginsInstalled .= $pagePlugins->generate($tempTplPath . '/template.pim_plugins_installed.html', true, false);
210: }
211:
212:
213: if(is_dir($cfg['path']['plugins'])){
214: if ($handle = opendir($cfg['path']['plugins'])) {
215: while ($pluginFoldername = readdir($handle)) {
216:
217: $tempPath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $pluginFoldername . '/plugin.xml';
218:
219: if (cFileHandler::exists($tempPath) && !in_array($pluginFoldername, $installedPluginFoldernames)) {
220:
221:
222: $pagePlugins = new cTemplate();
223:
224: $pagePlugins->set('s', 'LANG_FOLDERNAME', i18n('Foldername', 'pim'));
225: $pagePlugins->set('s', 'LANG_TOOLTIP_INSTALL', i18n('Install extracted plugin', 'pim'));
226: $pagePlugins->set('s', 'LANG_TOOLTIP_UNINSTALL', i18n('Uninstall extracted plugin (deleted plugin files from filesystem)', 'pim'));
227: $pagePlugins->set('s', 'FOLDERNAME', $pluginFoldername);
228: $pagePlugins->set('s', 'INSTALL_LINK', $sess->url('main.php?area=pim&frame=4&pim_view=install-extracted&pluginFoldername=' . $pluginFoldername));
229:
230:
231: if (is_writable($cfg['path']['contenido'] . $cfg['path']['plugins'] . $pluginFoldername)) {
232: $pagePlugins->set('s', 'UNINSTALL_LINK', $sess->url('main.php?area=pim&frame=4&pim_view=uninstall-extracted&pluginFoldername=' . $pluginFoldername));
233: $pagePlugins->set('s', 'LANG_WRITABLE', '');
234: } else {
235: $pagePlugins->set('s', 'UNINSTALL_LINK', 'javascript://');
236: $pagePlugins->set('s', 'LANG_WRITABLE', '(<span class="settingWrong">' . i18n('This plugin is not writeable, please set the rights manually', 'pim') . '</span>)');
237: }
238:
239: $pluginsExtracted .= $pagePlugins->generate($tempTplPath . '/template.pim_plugins_extracted.html', true, false);
240: }
241: }
242: closedir($handle);
243: }
244: }
245:
246:
247: if (empty($pluginsExtracted)) {
248: $pluginsExtracted = i18n('No entries', 'pim');
249: }
250:
251:
252: $page->set('s', 'LANG_UPLOAD', i18n('Upload a new plugin', 'pim'));
253: $page->set('s', 'LANG_UPLOAD_CHOOSE', i18n('Please choose a plugin package', 'pim'));
254: $page->set('s', 'LANG_UPLOAD_BUTTON', i18n('Upload plugin package', 'pim'));
255: $page->set('s', 'LANG_INSTALLED', i18n('Installed Plugins', 'pim'));
256: $page->set('s', 'LANG_EXTRACTED', i18n('Not installed Plugins', 'pim'));
257:
258:
259: $page->set('s', 'INSTALLED_PLUGINS', $oItem->count());
260: $page->set('s', 'PLUGINS_INSTALLED', $pluginsInstalled);
261: $page->set('s', 'PLUGINS_EXTRACTED', $pluginsExtracted);
262:
263: $page->render();