1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | |
---|
13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('admin'); |
---|
16 | |
---|
17 | # -------------------------------------------------- |
---|
18 | # @todo Add settings to Dotclear update features |
---|
19 | if ($core->blog->settings->system->plugins_allow_multi_install === null) { |
---|
20 | $core->blog->settings->system->put( |
---|
21 | 'plugins_allow_multi_install', false, 'boolean', 'Allow multi-installation for plugins', true, true |
---|
22 | ); |
---|
23 | } |
---|
24 | if ($core->blog->settings->system->repository_plugin_url === null) { |
---|
25 | $core->blog->settings->system->put( |
---|
26 | 'repository_plugin_url', 'http://update.dotaddict.org/dc2/plugins.xml', 'string', 'Plugins XML feed location', true, true |
---|
27 | ); |
---|
28 | } |
---|
29 | # -------------------------------------------------- |
---|
30 | |
---|
31 | # -- Repository helper -- |
---|
32 | $repository = new dcRepository( |
---|
33 | $core->plugins, |
---|
34 | $core->blog->settings->system->repository_plugin_url |
---|
35 | ); |
---|
36 | $repository->check(); |
---|
37 | |
---|
38 | # -- Page helper -- |
---|
39 | $list = new adminModulesList( |
---|
40 | $core, |
---|
41 | DC_PLUGINS_ROOT, |
---|
42 | $core->blog->settings->system->plugins_allow_multi_install |
---|
43 | ); |
---|
44 | |
---|
45 | $list::setDistributedModules(array( |
---|
46 | 'aboutConfig', |
---|
47 | 'akismet', |
---|
48 | 'antispam', |
---|
49 | 'attachments', |
---|
50 | 'blogroll', |
---|
51 | 'blowupConfig', |
---|
52 | 'daInstaller', |
---|
53 | 'fairTrackbacks', |
---|
54 | 'importExport', |
---|
55 | 'maintenance', |
---|
56 | 'pages', |
---|
57 | 'pings', |
---|
58 | 'simpleMenu', |
---|
59 | 'tags', |
---|
60 | 'themeEditor', |
---|
61 | 'userPref', |
---|
62 | 'widgets' |
---|
63 | )); |
---|
64 | |
---|
65 | # -- Check for module configuration -- |
---|
66 | $conf_file = false; |
---|
67 | if (!empty($_REQUEST['conf']) && !empty($_REQUEST['module'])) { |
---|
68 | if (!$core->plugins->moduleExists($_REQUEST['module'])) { |
---|
69 | $core->error->add(__('Unknow module ID')); |
---|
70 | } |
---|
71 | else { |
---|
72 | $module = $core->plugins->getModules($_REQUEST['module']); |
---|
73 | $module = adminModulesList::setModuleInfo($_REQUEST['module'], $module); |
---|
74 | |
---|
75 | if (!file_exists(path::real($module['root'].'/_config.php'))) { |
---|
76 | $core->error->add(__('This module has no configuration file.')); |
---|
77 | } |
---|
78 | else { |
---|
79 | $conf_file = path::real($module['root'].'/_config.php'); |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | # -- Display module configuration page -- |
---|
85 | if ($conf_file) { |
---|
86 | dcPage::open(__('Plugins management'), |
---|
87 | |
---|
88 | # --BEHAVIOR-- pluginsToolsHeaders |
---|
89 | $core->callBehavior('pluginsToolsHeaders', $core, $module['id']), |
---|
90 | |
---|
91 | dcPage::breadcrumb( |
---|
92 | array( |
---|
93 | html::escapeHTML($core->blog->name) => '', |
---|
94 | '<a href="'.$list->getPageURL().'">'.__('Plugins management').'</a>' => '', |
---|
95 | '<span class="page-title">'.__('Plugin configuration').'</span>' => '' |
---|
96 | )) |
---|
97 | ); |
---|
98 | |
---|
99 | if (!empty($_GET['done'])){ |
---|
100 | dcPage::success(__('Plugin successfully configured.')); |
---|
101 | } |
---|
102 | |
---|
103 | try { |
---|
104 | if (!$module['standalone_config']) { |
---|
105 | echo |
---|
106 | '<form id="module_config" action="'.$list->getPageURL('conf=1').'" method="post" enctype="multipart/form-data">'. |
---|
107 | '<h3>'.sprintf(__('Configure plugin "%s"'), html::escapeHTML($module['name'])).'</h3>'. |
---|
108 | '<p><a class="back" href="'.$list->getPageURL().'#plugins">'.__('Back').'</a></p>'; |
---|
109 | } |
---|
110 | define('DC_CONTEXT_PLUGIN', true); |
---|
111 | |
---|
112 | include $conf_file; |
---|
113 | |
---|
114 | if (!$module['standalone_config']) { |
---|
115 | echo |
---|
116 | '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. |
---|
117 | form::hidden('module', $module['id']). |
---|
118 | $core->formNonce().'</p>'. |
---|
119 | '</form>'; |
---|
120 | } |
---|
121 | } |
---|
122 | catch (Exception $e) { |
---|
123 | echo '<div class="error"><p>'.$e->getMessage().'</p></div>'; |
---|
124 | } |
---|
125 | |
---|
126 | dcPage::close(); |
---|
127 | |
---|
128 | # Stop reading code here |
---|
129 | return; |
---|
130 | } |
---|
131 | |
---|
132 | # -- Execute actions -- |
---|
133 | if (!empty($_POST) && empty($_REQUEST['conf']) && $core->auth->isSuperAdmin() && $list->isPathWritable()) { |
---|
134 | try { |
---|
135 | $list->executeAction('plugins', $core->plugins, $repository); |
---|
136 | } |
---|
137 | catch (Exception $e) { |
---|
138 | $core->error->add($e->getMessage()); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | # -- Plugin install -- |
---|
143 | $plugins_install = null; |
---|
144 | if (!$core->error->flag()) { |
---|
145 | $plugins_install = $core->plugins->installModules(); |
---|
146 | } |
---|
147 | |
---|
148 | # -- Page header -- |
---|
149 | dcPage::open(__('Plugins management'), |
---|
150 | dcPage::jsLoad('js/_plugins.js'). |
---|
151 | dcPage::jsPageTabs(). |
---|
152 | |
---|
153 | # --BEHAVIOR-- pluginsToolsHeaders |
---|
154 | $core->callBehavior('pluginsToolsHeaders', $core, false), |
---|
155 | |
---|
156 | dcPage::breadcrumb( |
---|
157 | array( |
---|
158 | __('System') => '', |
---|
159 | '<span class="page-title">'.__('Plugins management').'</span>' => '' |
---|
160 | )) |
---|
161 | ); |
---|
162 | |
---|
163 | # -- Succes messages -- |
---|
164 | if (!empty($_GET['msg'])) { |
---|
165 | $list->displayMessage($_GET['msg']); |
---|
166 | } |
---|
167 | |
---|
168 | # -- Plugins install messages -- |
---|
169 | if (!empty($plugins_install['success'])) { |
---|
170 | echo |
---|
171 | '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; |
---|
172 | foreach ($plugins_install['success'] as $k => $v) { |
---|
173 | echo |
---|
174 | '<li>'.$k.'</li>'; |
---|
175 | } |
---|
176 | echo |
---|
177 | '</ul></div>'; |
---|
178 | } |
---|
179 | if (!empty($plugins_install['failure'])) { |
---|
180 | echo |
---|
181 | '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; |
---|
182 | foreach ($plugins_install['failure'] as $k => $v) { |
---|
183 | echo |
---|
184 | '<li>'.$k.' ('.$v.')</li>'; |
---|
185 | } |
---|
186 | echo |
---|
187 | '</ul></div>'; |
---|
188 | } |
---|
189 | |
---|
190 | # -- Display modules lists -- |
---|
191 | if ($core->auth->isSuperAdmin() && $list->isPathWritable()) { |
---|
192 | |
---|
193 | # Updated modules from repo |
---|
194 | $modules = $repository->get(true); |
---|
195 | if (!empty($modules)) { |
---|
196 | echo |
---|
197 | '<div class="multi-part" id="update" title="'.html::escapeHTML(__('Update plugins')).'">'. |
---|
198 | '<h3>'.html::escapeHTML(__('Update plugins')).'</h3>'. |
---|
199 | '<p>'.sprintf( |
---|
200 | __('There is one plugin to update available from %2$s.', 'There are %s plugins to update available from %s.', count($modules)), |
---|
201 | count($modules), |
---|
202 | '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>' |
---|
203 | ).'</p>'; |
---|
204 | |
---|
205 | $list |
---|
206 | ->newList('plugin-update') |
---|
207 | ->setModules($modules) |
---|
208 | ->setPageTab('update') |
---|
209 | ->displayModulesList( |
---|
210 | /*cols */ array('icon', 'name', 'version', 'current_version', 'desc'), |
---|
211 | /* actions */ array('update') |
---|
212 | ); |
---|
213 | |
---|
214 | echo |
---|
215 | '</div>'; |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | # List all active plugins |
---|
220 | echo |
---|
221 | '<div class="multi-part" id="plugins" title="'.__('Installed plugins').'">'; |
---|
222 | |
---|
223 | $modules = $core->plugins->getModules(); |
---|
224 | if (!empty($modules)) { |
---|
225 | |
---|
226 | echo |
---|
227 | '<h3>'.__('Activated plugins').'</h3>'. |
---|
228 | '<p>'.__('Manage installed plugins from this list.').'</p>'; |
---|
229 | |
---|
230 | $list |
---|
231 | ->newList('plugin-activate') |
---|
232 | ->setModules($modules) |
---|
233 | ->setPageTab('plugins') |
---|
234 | ->displayModulesList( |
---|
235 | /* cols */ array('expander', 'icon', 'name', 'config', 'version', 'desc', 'distrib'), |
---|
236 | /* actions */ array('deactivate', 'delete') |
---|
237 | ); |
---|
238 | } |
---|
239 | |
---|
240 | # Deactivated modules |
---|
241 | $modules = $core->plugins->getDisabledModules(); |
---|
242 | if (!empty($modules)) { |
---|
243 | |
---|
244 | echo |
---|
245 | '<h3>'.__('Deactivated plugins').'</h3>'. |
---|
246 | '<p>'.__('Deactivated plugins are installed but not usable. You can activate them from here.').'</p>'; |
---|
247 | |
---|
248 | $list |
---|
249 | ->newList('plugin-deactivate') |
---|
250 | ->setModules($modules) |
---|
251 | ->setPageTab('plugins') |
---|
252 | ->displayModulesList( |
---|
253 | /* cols */ array('icon', 'name', 'distrib'), |
---|
254 | /* actions */ array('activate', 'delete') |
---|
255 | ); |
---|
256 | } |
---|
257 | |
---|
258 | echo |
---|
259 | '</div>'; |
---|
260 | |
---|
261 | if ($core->auth->isSuperAdmin() && $list->isPathWritable()) { |
---|
262 | |
---|
263 | # New modules from repo |
---|
264 | $search = $list->getSearchQuery(); |
---|
265 | $modules = $search ? $repository->search($search) : $repository->get(); |
---|
266 | |
---|
267 | echo |
---|
268 | '<div class="multi-part" id="new" title="'.__('Add plugins from Dotaddict').'">'. |
---|
269 | '<h3>'.__('Add plugins from Dotaddict repository').'</h3>'; |
---|
270 | |
---|
271 | $list |
---|
272 | ->newList('plugin-new') |
---|
273 | ->setModules($modules) |
---|
274 | ->setPageTab('new') |
---|
275 | ->displaySearchForm() |
---|
276 | ->displayNavMenu() |
---|
277 | ->displayModulesList( |
---|
278 | /* cols */ array('expander', 'name', 'version', 'desc'), |
---|
279 | /* actions */ array('install'), |
---|
280 | /* nav limit */ true |
---|
281 | ); |
---|
282 | |
---|
283 | echo |
---|
284 | '<p class="info vertical-separator">'.sprintf( |
---|
285 | __("Visit %s repository, the resources center for Dotclear."), |
---|
286 | '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>' |
---|
287 | ). |
---|
288 | '</p>'. |
---|
289 | |
---|
290 | '</div>'; |
---|
291 | |
---|
292 | # Add a new plugin |
---|
293 | echo |
---|
294 | '<div class="multi-part" id="addplugin" title="'.__('Install or upgrade manually').'">'; |
---|
295 | |
---|
296 | echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>'; |
---|
297 | |
---|
298 | $list->displayManualForm(); |
---|
299 | |
---|
300 | echo |
---|
301 | '</div>'; |
---|
302 | } |
---|
303 | |
---|
304 | # --BEHAVIOR-- pluginsToolsTabs |
---|
305 | $core->callBehavior('pluginsToolsTabs', $core); |
---|
306 | |
---|
307 | # -- Notice for super admin -- |
---|
308 | if ($core->auth->isSuperAdmin() && !$list->isPathWritable()) { |
---|
309 | echo |
---|
310 | '<p class="warning">'.__('Some functions are disabled, please give write access to your plugins directory to enable them.').'</p>'; |
---|
311 | } |
---|
312 | |
---|
313 | dcPage::close(); |
---|
314 | ?> |
---|