1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
25 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
26 | include_once(LOCALEDIT_PATH.'functions.inc.php'); |
---|
27 | load_language('plugin.lang', LOCALEDIT_PATH); |
---|
28 | $my_base_url = get_admin_plugin_menu_link(__FILE__); |
---|
29 | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | // | Tabssheet |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | if (!isset($_GET['tab'])) |
---|
34 | $page['tab'] = 'localconf'; |
---|
35 | else |
---|
36 | $page['tab'] = $_GET['tab']; |
---|
37 | |
---|
38 | $tabsheet = new tabsheet(); |
---|
39 | $tabsheet->add('localconf', |
---|
40 | l10n('locfiledit_onglet_localconf'), |
---|
41 | $my_base_url.'&tab=localconf'); |
---|
42 | $tabsheet->add('css', |
---|
43 | l10n('locfiledit_onglet_css'), |
---|
44 | $my_base_url.'&tab=css'); |
---|
45 | $tabsheet->add('tpl', |
---|
46 | l10n('locfiledit_onglet_tpl'), |
---|
47 | $my_base_url.'&tab=tpl'); |
---|
48 | $tabsheet->add('lang', |
---|
49 | l10n('locfiledit_onglet_lang'), |
---|
50 | $my_base_url.'&tab=lang'); |
---|
51 | $tabsheet->add('plug', |
---|
52 | l10n('locfiledit_onglet_plug'), |
---|
53 | $my_base_url.'&tab=plug'); |
---|
54 | $tabsheet->select($page['tab']); |
---|
55 | $tabsheet->assign(); |
---|
56 | |
---|
57 | |
---|
58 | // +-----------------------------------------------------------------------+ |
---|
59 | // | Variables init |
---|
60 | // +-----------------------------------------------------------------------+ |
---|
61 | $edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : ''; |
---|
62 | $content_file = ''; |
---|
63 | $new_file['localconf'] = "<?php\n\n/* ".l10n('locfiledit_newfile')." */\n\n\n\n\n?>"; |
---|
64 | $new_file['css'] = "/* " . l10n('locfiledit_newfile') . " */\n\n"; |
---|
65 | $new_file['tpl'] = "{* " . l10n('locfiledit_newfile') . " *}\n\n"; |
---|
66 | $new_file['lang'] = $new_file['localconf']; |
---|
67 | $new_file['plug'] = "<?php\n/* |
---|
68 | Plugin Name: " . l10n('locfiledit_onglet_plug') . " |
---|
69 | Version: 1.0 |
---|
70 | Description: " . l10n('locfiledit_onglet_plug') . " |
---|
71 | Plugin URI: http://piwigo.org |
---|
72 | Author: |
---|
73 | Author URI: |
---|
74 | */\n\n\n\n\n?>"; |
---|
75 | $newfile_page = isset($_GET['newfile']) ? true : false; |
---|
76 | |
---|
77 | // Editarea options |
---|
78 | $editarea_options = array( |
---|
79 | 'language' => substr($user['language'], 0, 2), |
---|
80 | 'start_highlight' => true, |
---|
81 | 'allow_toggle' => false, |
---|
82 | 'toolbar' => 'search,fullscreen, |,select_font, |, undo, redo, change_smooth_selection, highlight, reset_highlight, |, help'); |
---|
83 | |
---|
84 | // Edit selected file for CSS, template and language |
---|
85 | if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit'])) |
---|
86 | { |
---|
87 | $edited_file = $_POST['file_to_edit']; |
---|
88 | $content_file = file_exists($edited_file) ? |
---|
89 | file_get_contents($edited_file) : $new_file[$page['tab']]; |
---|
90 | } |
---|
91 | |
---|
92 | // Edit new tpl file |
---|
93 | if (isset($_POST['create_tpl'])) |
---|
94 | { |
---|
95 | $filename = $_POST['tpl_name']; |
---|
96 | if (empty($filename)) |
---|
97 | { |
---|
98 | array_push($page['errors'], l10n('locfiledit_empty_filename')); |
---|
99 | } |
---|
100 | if (get_extension($filename) != 'tpl') |
---|
101 | { |
---|
102 | $filename .= '.tpl'; |
---|
103 | } |
---|
104 | if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) |
---|
105 | { |
---|
106 | array_push($page['errors'], l10n('locfiledit_filename_error')); |
---|
107 | } |
---|
108 | if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0') |
---|
109 | { |
---|
110 | array_push($page['errors'], l10n('locfiledit_model_error')); |
---|
111 | } |
---|
112 | if (file_exists($_POST['tpl_parent'] . '/' . $filename)) |
---|
113 | { |
---|
114 | array_push($page['errors'], l10n('locfiledit_file_already_exists')); |
---|
115 | } |
---|
116 | if (!empty($page['errors'])) |
---|
117 | { |
---|
118 | $newfile_page = true; |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | $edited_file = $_POST['tpl_parent'] . '/' . $filename; |
---|
123 | $content_file = ($_POST['tpl_model'] == '0') ? $new_file['tpl'] : file_get_contents($_POST['tpl_model']); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | // +-----------------------------------------------------------------------+ |
---|
128 | // | Process tabsheet |
---|
129 | // +-----------------------------------------------------------------------+ |
---|
130 | switch ($page['tab']) |
---|
131 | { |
---|
132 | case 'localconf': |
---|
133 | $edited_file = PHPWG_ROOT_PATH . "include/config_local.inc.php"; |
---|
134 | $content_file = file_exists($edited_file) ? |
---|
135 | file_get_contents($edited_file) : $new_file['localconf']; |
---|
136 | |
---|
137 | $template->assign('show_default' , array( |
---|
138 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
139 | . 'show_default.php?file=include/config_default.inc.php', |
---|
140 | 'FILE' => 'config_default.inc.php'))); |
---|
141 | $editarea_options['syntax'] = 'php'; |
---|
142 | break; |
---|
143 | |
---|
144 | case 'css': |
---|
145 | $template_dir = PHPWG_ROOT_PATH . 'template'; |
---|
146 | $selected = 0; |
---|
147 | $options[] = l10n('locfiledit_choose_file'); |
---|
148 | $options[] = '----------------------'; |
---|
149 | $value = PHPWG_ROOT_PATH . "template-common/local-layout.css"; |
---|
150 | $options[$value] = 'template-common / local-layout.css'; |
---|
151 | if ($edited_file == $value) $selected = $value; |
---|
152 | |
---|
153 | foreach (get_dirs($template_dir) as $pwg_template) |
---|
154 | { |
---|
155 | $options[] = '----------------------'; |
---|
156 | $value = $template_dir . '/' . $pwg_template . '/local-layout.css'; |
---|
157 | $options[$value] = $pwg_template . ' / local-layout.css'; |
---|
158 | if ($edited_file == $value) $selected = $value; |
---|
159 | $options[] = '----------------------'; |
---|
160 | foreach (get_dirs($template_dir.'/'.$pwg_template.'/theme') as $theme) |
---|
161 | { |
---|
162 | $value = $template_dir.'/'.$pwg_template.'/theme/'.$theme.'/theme.css'; |
---|
163 | $options[$value] = $pwg_template . ' / ' . $theme . ' / theme.css'; |
---|
164 | if ($edited_file == $value) $selected = $value; |
---|
165 | } |
---|
166 | } |
---|
167 | $template->assign('css_lang_tpl', array( |
---|
168 | 'OPTIONS' => $options, |
---|
169 | 'SELECTED' => $selected)); |
---|
170 | $editarea_options['syntax'] = 'css'; |
---|
171 | break; |
---|
172 | |
---|
173 | case 'tpl': |
---|
174 | // New file form creation |
---|
175 | if ($newfile_page and !is_adviser()) |
---|
176 | { |
---|
177 | $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : ''; |
---|
178 | $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0'; |
---|
179 | $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension'; |
---|
180 | |
---|
181 | // Parent directories list |
---|
182 | $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension'); |
---|
183 | $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension')); |
---|
184 | |
---|
185 | // Model list |
---|
186 | $eligible_templates = array( |
---|
187 | 'about.tpl', |
---|
188 | 'footer.tpl', |
---|
189 | 'header.tpl', |
---|
190 | 'identification.tpl', |
---|
191 | 'index.tpl', |
---|
192 | 'mainpage_categories.tpl', |
---|
193 | 'menubar.tpl', |
---|
194 | 'menubar_categories.tpl', |
---|
195 | 'menubar_identification.tpl', |
---|
196 | 'menubar_links.tpl', |
---|
197 | 'menubar_menu.tpl', |
---|
198 | 'menubar_specials.tpl', |
---|
199 | 'menubar_tags.tpl', |
---|
200 | 'nbm.tpl', |
---|
201 | 'notification.tpl', |
---|
202 | 'picture.tpl', |
---|
203 | 'picture_content.tpl', |
---|
204 | 'picture_nav_buttons.tpl', |
---|
205 | 'popuphelp.tpl', |
---|
206 | 'profile.tpl', |
---|
207 | 'profile_content.tpl', |
---|
208 | 'redirect.tpl', |
---|
209 | 'register.tpl', |
---|
210 | 'search.tpl', |
---|
211 | 'search_rules.tpl', |
---|
212 | 'slideshow.tpl', |
---|
213 | 'tags.tpl', |
---|
214 | 'thumbnails.tpl', |
---|
215 | 'upload.tpl'); |
---|
216 | |
---|
217 | $options['model'][] = l10n('locfiledit_empty_page'); |
---|
218 | $options['model'][] = '----------------------'; |
---|
219 | foreach (get_extents() as $pwg_template) |
---|
220 | { |
---|
221 | $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template; |
---|
222 | $options['model'][$value] = 'template-extension / ' . str_replace('/', ' / ', $pwg_template); |
---|
223 | } |
---|
224 | $template_dir = PHPWG_ROOT_PATH . 'template'; |
---|
225 | foreach (get_dirs($template_dir) as $pwg_template) |
---|
226 | { |
---|
227 | if (count($options['model']) > 2) |
---|
228 | { |
---|
229 | $options['model'][] = '----------------------'; |
---|
230 | } |
---|
231 | $dir = $template_dir . '/' . $pwg_template . '/'; |
---|
232 | if (is_dir($dir) and $content = opendir($dir)) |
---|
233 | { |
---|
234 | while ($node = readdir($content)) |
---|
235 | { |
---|
236 | if (is_file($dir . $node) and in_array($node, $eligible_templates)) |
---|
237 | { |
---|
238 | $value = $dir . $node; |
---|
239 | $options['model'][$value] = $pwg_template . ' / ' . $node; |
---|
240 | } |
---|
241 | } |
---|
242 | } |
---|
243 | } |
---|
244 | // Assign variables to template |
---|
245 | $template->assign('create_tpl', array( |
---|
246 | 'NEW_FILE_NAME' => $filename, |
---|
247 | 'MODEL_OPTIONS' => $options['model'], |
---|
248 | 'MODEL_SELECTED' => $selected['model'], |
---|
249 | 'PARENT_OPTIONS' => $options['parent'], |
---|
250 | 'PARENT_SELECTED' => $selected['parent'])); |
---|
251 | break; |
---|
252 | } |
---|
253 | // List existing template extensions |
---|
254 | $template_dir = PHPWG_ROOT_PATH . 'template-extension'; |
---|
255 | $selected = 0; |
---|
256 | $options[] = l10n('locfiledit_choose_file'); |
---|
257 | $options[] = '----------------------'; |
---|
258 | foreach (get_extents() as $pwg_template) |
---|
259 | { |
---|
260 | $value = './template-extension/' . $pwg_template; |
---|
261 | $options[$value] = str_replace('/', ' / ', $pwg_template); |
---|
262 | if ($edited_file == $value) $selected = $value; |
---|
263 | } |
---|
264 | if ($selected == 0 and !empty($edited_file)) |
---|
265 | { |
---|
266 | $options[$edited_file] = str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file); |
---|
267 | $selected = $edited_file; |
---|
268 | } |
---|
269 | $template->assign('css_lang_tpl', array( |
---|
270 | 'OPTIONS' => $options, |
---|
271 | 'SELECTED' => $selected, |
---|
272 | 'NEW_FILE_URL' => $my_base_url.'&tab=tpl&newfile', |
---|
273 | 'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right')); |
---|
274 | |
---|
275 | $editarea_options['syntax'] = 'html'; |
---|
276 | break; |
---|
277 | |
---|
278 | case 'lang': |
---|
279 | $selected = 0; |
---|
280 | $options[] = l10n('locfiledit_choose_file'); |
---|
281 | $options[] = '----------------------'; |
---|
282 | foreach (get_languages() as $language_code => $language_name) |
---|
283 | { |
---|
284 | $value = PHPWG_ROOT_PATH.'language/'.$language_code.'/local.lang.php'; |
---|
285 | if ($edited_file == $value) |
---|
286 | { |
---|
287 | $selected = $value; |
---|
288 | $template->assign('show_default', array( |
---|
289 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
290 | . 'show_default.php?file=' |
---|
291 | . 'language/'.$language_code.'/common.lang.php', |
---|
292 | 'FILE' => 'common.lang.php'), |
---|
293 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
294 | . 'show_default.php?file=' |
---|
295 | . 'language/'.$language_code.'/admin.lang.php', |
---|
296 | 'FILE' => 'admin.lang.php'))); |
---|
297 | } |
---|
298 | $options[$value] = $language_name; |
---|
299 | } |
---|
300 | $template->assign('css_lang_tpl', array( |
---|
301 | 'OPTIONS' => $options, |
---|
302 | 'SELECTED' => $selected)); |
---|
303 | $editarea_options['syntax'] = 'php'; |
---|
304 | break; |
---|
305 | |
---|
306 | case 'plug': |
---|
307 | $edited_file = PHPWG_PLUGINS_PATH . "PersonalPlugin/main.inc.php"; |
---|
308 | $content_file = file_exists($edited_file) ? |
---|
309 | file_get_contents($edited_file) : $new_file['plug']; |
---|
310 | $editarea_options['syntax'] = 'php'; |
---|
311 | break; |
---|
312 | } |
---|
313 | |
---|
314 | // +-----------------------------------------------------------------------+ |
---|
315 | // | Load backup file |
---|
316 | // +-----------------------------------------------------------------------+ |
---|
317 | if (isset($_POST['restore']) and !is_adviser()) |
---|
318 | { |
---|
319 | $edited_file = $_POST['edited_file']; |
---|
320 | $content_file = file_get_contents(get_bak_file($edited_file)); |
---|
321 | array_push($page['infos'], |
---|
322 | l10n('locfiledit_bak_loaded1'), |
---|
323 | l10n('locfiledit_bak_loaded2')); |
---|
324 | } |
---|
325 | |
---|
326 | // +-----------------------------------------------------------------------+ |
---|
327 | // | Save file |
---|
328 | // +-----------------------------------------------------------------------+ |
---|
329 | if (isset($_POST['submit']) and !is_adviser()) |
---|
330 | { |
---|
331 | $edited_file = $_POST['edited_file']; |
---|
332 | $content_file = stripslashes($_POST['text']); |
---|
333 | if (get_extension($edited_file) == 'php') |
---|
334 | { |
---|
335 | $content_file = eval_syntax($content_file); |
---|
336 | } |
---|
337 | if ($content_file === false) |
---|
338 | { |
---|
339 | array_push($page['errors'], l10n('locfiledit_syntax_error')); |
---|
340 | } |
---|
341 | else |
---|
342 | { |
---|
343 | if ($page['tab'] == 'plug' and !is_dir(PHPWG_PLUGINS_PATH . 'PersonalPlugin')) |
---|
344 | { |
---|
345 | @mkdir(PHPWG_PLUGINS_PATH . "PersonalPlugin"); |
---|
346 | } |
---|
347 | if (file_exists($edited_file)) |
---|
348 | { |
---|
349 | @copy($edited_file, get_bak_file($edited_file)); |
---|
350 | array_push($page['infos'], sprintf(l10n('locfiledit_saved_bak'), substr(get_bak_file($edited_file), 2))); |
---|
351 | } |
---|
352 | |
---|
353 | if ($file = @fopen($edited_file , "w")) |
---|
354 | { |
---|
355 | @fwrite($file , $content_file); |
---|
356 | @fclose($file); |
---|
357 | array_unshift($page['infos'], l10n('locfiledit_save_config')); |
---|
358 | } |
---|
359 | else |
---|
360 | { |
---|
361 | array_push($page['errors'], l10n('locfiledit_cant_save')); |
---|
362 | } |
---|
363 | } |
---|
364 | } |
---|
365 | |
---|
366 | // +-----------------------------------------------------------------------+ |
---|
367 | // | template initialization |
---|
368 | // +-----------------------------------------------------------------------+ |
---|
369 | $template->set_filenames(array( |
---|
370 | 'plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
371 | |
---|
372 | if (!empty($edited_file)) |
---|
373 | { |
---|
374 | if (!empty($page['errors'])) |
---|
375 | { |
---|
376 | $content_file = stripslashes($_POST['text']); |
---|
377 | } |
---|
378 | $template->assign('zone_edit', |
---|
379 | array('EDITED_FILE' => $edited_file, |
---|
380 | 'CONTENT_FILE' => htmlspecialchars($content_file), |
---|
381 | 'FILE_NAME' => trim($edited_file, './\\'))); |
---|
382 | if (file_exists(get_bak_file($edited_file))) |
---|
383 | { |
---|
384 | $template->assign('restore', true); |
---|
385 | } |
---|
386 | if (file_exists($edited_file)) |
---|
387 | { |
---|
388 | $template->assign('restore_infos', true); |
---|
389 | } |
---|
390 | |
---|
391 | } |
---|
392 | |
---|
393 | $template->assign(array( |
---|
394 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=plugin&section=LocalFilesEditor%2Fadmin.php&tab=' . $page['tab'], |
---|
395 | 'LOCALEDIT_PATH' => LOCALEDIT_PATH, |
---|
396 | 'LOAD_EDITAREA' => isset($conf['LocalFilesEditor']) ? $conf['LocalFilesEditor'] : 'off', |
---|
397 | 'EDITAREA_OPTIONS' => $editarea_options)); |
---|
398 | |
---|
399 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
400 | |
---|
401 | ?> |
---|