Dotclear

source: plugins/pacKman/index.php @ 3246

Revision 3246, 8.3 KB checked in by JcDenis, 10 years ago (diff)

Fix notice (unremoved old var), Fix install version comparison

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of pacKman, a plugin for Dotclear 2.
5#
6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
7# contact@jcdenis.fr
8#
9# Licensed under the GPL version 2.0 license.
10# A copy of this license is available in LICENSE file or at
11# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12#
13# -- END LICENSE BLOCK ------------------------------------
14
15if (!defined('DC_CONTEXT_ADMIN')) {
16     return null;
17}
18
19dcPage::checkSuper();
20
21# Queries
22$p_url = 'plugin.php?p=pacKman';
23$action = isset($_POST['action']) ? $_POST['action'] : '';
24$type = isset($_POST['type']) && in_array($_POST['type'],
25     array('plugins','themes','repository')) ? $_POST['type'] : '';
26
27# Settings
28$core->blog->settings->addNamespace('pacKman');
29$s = $core->blog->settings->pacKman;
30
31# Modules
32if (!isset($core->themes)) {
33     $core->themes = new dcThemes($core);
34     $core->themes->loadModules($core->blog->themes_path,null);
35}
36$themes = $core->themes;
37$plugins = $core->plugins;
38
39# Paths
40$ppexp = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT);
41$pppop = array_pop($ppexp);
42$plugins_path = path::real($pppop);
43$themes_path = $core->blog->themes_path;
44$repo_path = $s->packman_pack_repository;
45
46# Rights
47$is_writable = libPackman::is_writable(
48     $s->packman_pack_repository,
49     $s->packman_pack_filename
50);
51$is_editable =
52     !empty($type)
53     && !empty($_POST['modules']) 
54     && is_array($_POST['modules']);
55
56$is_configured = libPackman::is_configured(
57     $core,
58     $s->packman_pack_repository,
59     $s->packman_pack_filename,
60     $s->packman_secondpack_filename
61);
62
63# Actions
64try
65{
66     # Download
67     if (isset($_REQUEST['package']) && empty($type)) {
68
69          $modules = array();
70          if ($type == 'plugins') {
71               $modules = dcPackman::getPackages($core, $plugins_path);
72          }
73          elseif ($type == 'themes') {
74               $modules = dcPackman::getPackages($core, $themes_path);
75          }
76          else {
77               $modules = array_merge(
78                    dcPackman::getPackages($core, dirname($repo_path.'/'.$s->packman_pack_filename)),
79                    dcPackman::getPackages($core, dirname($repo_path.'/'.$s->packman_secondpack_filename))
80               );
81          }
82
83          foreach($modules as $f) {
84
85               if (preg_match('/'.preg_quote($_REQUEST['package']).'$/', $f['root'])
86                && is_file($f['root']) && is_readable($f['root'])
87               ) {
88
89                    # --BEHAVIOR-- packmanBeforeDownloadPackage
90                    $core->callBehavior('packmanBeforeDownloadPackage', $f, $type);
91
92                    header('Content-Type: application/zip');
93                    header('Content-Length: '.filesize($f['root']));
94                    header('Content-Disposition: attachment; filename="'.basename($f['root']).'"');
95                    readfile($f['root']);
96
97                    # --BEHAVIOR-- packmanAfterDownloadPackage
98                    $core->callBehavior('packmanAfterDownloadPackage', $f, $type);
99
100                    exit;
101               }
102          }
103
104          # Not found
105          header('Content-Type: text/plain');
106          http::head(404,'Not Found');
107          exit;
108     }
109     elseif (!empty($action) && !$is_editable) {
110          throw new Exception('No selected modules');
111     }
112
113     # Pack
114     elseif ($action == 'packup') {
115
116          $modules = array_keys($_POST['modules']);
117
118          foreach ($modules as $id) {
119
120               if (!${$type}->moduleExists($id)) {
121                    throw new Exception('No such module');
122               }
123
124               $module = ${$type}->getModules($id);
125               $module['id'] = $id;
126               $module['type'] = $type == 'themes' ? 'theme' : 'plugin';
127
128               $root = $s->packman_pack_repository;
129               $files = array(
130                    $s->packman_pack_filename,
131                    $s->packman_secondpack_filename
132               );
133               $nocomment = $s->packman_pack_nocomment;
134               $overwrite = $s->packman_pack_overwrite;
135               $exclude = explode(',', $s->packman_pack_excludefiles);
136
137               # --BEHAVIOR-- packmanBeforeCreatePackage
138               $core->callBehavior('packmanBeforeCreatePackage', $core, $module);
139
140               dcPackman::pack($module, $root, $files, $overwrite, $exclude, $nocomment);
141
142               # --BEHAVIOR-- packmanAfterCreatePackage
143               $core->callBehavior('packmanAfterCreatePackage', $core, $module);
144
145          }
146
147          dcPage::addSuccessNotice(
148               __('Package successfully created.')
149          );
150          http::redirect(empty($_POST['redir']) ? 
151               $p_url.'#packman-'.$type : $_POST['redir']
152          );
153     }
154
155     # Delete
156     elseif ($action == 'delete') {
157
158          foreach ($_POST['modules'] as $id => $root) {
159               if (!file_exists($root) || !files::isDeletable($root)) {
160                    throw new Exception('Undeletable file: '.$root);
161               }
162
163               unlink($root);
164          }
165
166          dcPage::addSuccessNotice(
167               __('Package successfully deleted.')
168          );
169          http::redirect(
170               $p_url.'#packman-repository-'.$type
171          );
172     }
173
174     # Install
175     elseif ($action == 'install') {
176
177          foreach ($_POST['modules'] as $id => $root) {
178
179               # --BEHAVIOR-- packmanBeforeInstallPackage
180               $core->callBehavior('packmanBeforeInstallPackage', $type, $id, $root);
181
182               if ($type == 'plugins') {
183                    $plugins->installPackage($root, $plugins);
184               }
185               if ($type == 'themes') {
186                    $themes->installPackage($root, $themes);
187               }
188
189               # --BEHAVIOR-- packmanAfterInstallPackage
190               $core->callBehavior('packmanAfterInstallPackage', $type, $id, $root);
191
192          }
193
194          dcPage::addSuccessNotice(
195               __('Package successfully installed.')
196          );
197          http::redirect(
198               $p_url.'#packman-repository-'.$type
199          );
200     }
201
202     # Copy
203     elseif (strpos($action, 'copy_to_') !== false) {
204
205          if ($action == 'copy_to_plugins') {
206               $dest = $plugins_path;
207          }
208          elseif ($action == 'copy_to_themes') {
209               $dest = $themes_path;
210          }
211          elseif ($action == 'copy_to_repository') {
212               $dest = $repo_path;
213          }
214
215          foreach ($_POST['modules'] as $id => $root) {
216               file_put_contents(
217                    $dest.'/'.basename($root),
218                    file_get_contents($root)
219               );
220          }
221
222          dcPage::addSuccessNotice(
223               __('Package successfully copied.')
224          );
225          http::redirect(
226               $p_url.'#packman-repository-'.$type
227          );
228     }
229
230     # Move
231     elseif (strpos($action, 'move_to_') !== false) {
232
233          if ($action == 'move_to_plugins') {
234               $dest = $plugins_path;
235          }
236          elseif ($action == 'move_to_themes') {
237               $dest = $themes_path;
238          }
239          elseif ($action == 'move_to_repository') {
240               $dest = $repo_path;
241          }
242
243          foreach ($_POST['modules'] as $id => $root) {
244               file_put_contents(
245                    $dest.'/'.basename($root),
246                    file_get_contents($root)
247               );
248               unlink($root);
249          }
250
251          dcPage::addSuccessNotice(
252               __('Package successfully moved.')
253          );
254          http::redirect(
255               $p_url.'#packman-repository-'.$type
256          );
257     }
258}
259catch(Exception $e) {
260     $core->error->add($e->getMessage());
261}
262
263# Display
264echo 
265'<html><head><title>'.__('pacKman').'</title>'.
266dcPage::jsPageTabs().
267dcPage::jsLoad('index.php?pf=pacKman/js/packman.js');
268
269# --BEHAVIOR-- packmanAdminHeader
270$core->callBehavior('packmanAdminHeader', $core);
271
272echo 
273'</head><body>'.
274
275dcPage::breadcrumb(
276     array(
277          __('Plugins') => '',
278          __('pacKman') => ''
279     )
280).
281dcPage::notices();
282
283if ($core->error->flag()) {
284     echo
285     '<p class="warning">'.__('pacKman is not well configured.').' '.
286     '<a href="plugins.php?module=pacKman&amp;conf=1&amp;redir='.
287     urlencode('plugin.php?p=pacKman').'">'.__('Configuration').'</a>'.
288     '</p>';
289}
290else {
291
292     $repo_path_modules = array_merge(
293          dcPackman::getPackages(
294               $core,
295               dirname($repo_path.'/'.$s->packman_pack_filename)
296          ),
297          dcPackman::getPackages(
298               $core,
299               dirname($repo_path.'/'.$s->packman_secondpack_filename)
300          )
301     );
302     $plugins_path_modules = dcPackman::getPackages(
303          $core,
304          $plugins_path
305     );
306     $themes_path_modules = dcPackman::getPackages(
307          $core,
308          $themes_path
309     );
310
311     libPackman::modules(
312          $core,
313          $plugins->getModules(),
314          'plugins',
315          __('Installed plugins')
316     );
317
318     libPackman::modules(
319          $core,
320          $themes->getModules(),
321          'themes',
322          __('Installed themes')
323     );
324
325     libPackman::repository(
326          $core,
327          $plugins_path_modules,
328          'plugins',
329          __('Plugins root')
330     );
331
332     libPackman::repository(
333          $core,
334          $themes_path_modules,
335          'themes',
336          __('Themes root')
337     );
338
339     libPackman::repository(
340          $core,
341          $repo_path_modules,
342          'repository',
343          __('Packages repository')
344     );
345}
346
347# --BEHAVIOR-- packmanAdminTabs
348$core->callBehavior('packmanAdminTabs', $core);
349
350dcPage::helpBlock('pacKman');
351
352echo 
353'<hr class="clear"/><p class="right modules">
354<a class="module-config" '.
355'href="plugins.php?module=pacKman&amp;conf=1&amp;redir='.
356urlencode('plugin.php?p=pacKman').'">'.__('Configuration').'</a> -
357pacKman - '.$core->plugins->moduleInfo('pacKman', 'version').'&nbsp;
358<img alt="'.__('pacKman').'" src="index.php?pf=pacKman/icon.png" />
359</p>
360</body></html>';
Note: See TracBrowser for help on using the repository browser.

Sites map