1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 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 | // | PhpWebGallery - a PHP based picture gallery | |
---|
25 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
26 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | // | file : $Id: admin.php 2297 2008-04-04 22:57:23Z plg $ |
---|
29 | // | last update : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $ |
---|
30 | // | last modifier : $Author: plg $ |
---|
31 | // | revision : $Revision: 2297 $ |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | // | This program is free software; you can redistribute it and/or modify | |
---|
34 | // | it under the terms of the GNU General Public License as published by | |
---|
35 | // | the Free Software Foundation | |
---|
36 | // | | |
---|
37 | // | This program is distributed in the hope that it will be useful, but | |
---|
38 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
39 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
40 | // | General Public License for more details. | |
---|
41 | // | | |
---|
42 | // | You should have received a copy of the GNU General Public License | |
---|
43 | // | along with this program; if not, write to the Free Software | |
---|
44 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
45 | // | USA. | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | |
---|
48 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
49 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
50 | include_once(LOCALEDIT_PATH.'functions.inc.php'); |
---|
51 | load_language('plugin.lang', LOCALEDIT_PATH); |
---|
52 | $my_base_url = get_admin_plugin_menu_link(__FILE__); |
---|
53 | |
---|
54 | // +-----------------------------------------------------------------------+ |
---|
55 | // | Tabssheet |
---|
56 | // +-----------------------------------------------------------------------+ |
---|
57 | if (!isset($_GET['tab'])) |
---|
58 | $page['tab'] = 'localconf'; |
---|
59 | else |
---|
60 | $page['tab'] = $_GET['tab']; |
---|
61 | |
---|
62 | $tabsheet = new tabsheet(); |
---|
63 | $tabsheet->add('localconf', |
---|
64 | l10n('locfiledit_onglet_localconf'), |
---|
65 | $my_base_url.'&tab=localconf'); |
---|
66 | $tabsheet->add('css', |
---|
67 | l10n('locfiledit_onglet_css'), |
---|
68 | $my_base_url.'&tab=css'); |
---|
69 | $tabsheet->add('tpl', |
---|
70 | l10n('locfiledit_onglet_tpl'), |
---|
71 | $my_base_url.'&tab=tpl'); |
---|
72 | $tabsheet->add('lang', |
---|
73 | l10n('locfiledit_onglet_lang'), |
---|
74 | $my_base_url.'&tab=lang'); |
---|
75 | $tabsheet->add('plug', |
---|
76 | l10n('locfiledit_onglet_plug'), |
---|
77 | $my_base_url.'&tab=plug'); |
---|
78 | $tabsheet->select($page['tab']); |
---|
79 | $tabsheet->assign(); |
---|
80 | |
---|
81 | |
---|
82 | // +-----------------------------------------------------------------------+ |
---|
83 | // | Variables init |
---|
84 | // +-----------------------------------------------------------------------+ |
---|
85 | $edited_file = ''; |
---|
86 | $content_file = ''; |
---|
87 | $new_file['localconf'] = "<?php\n\n".l10n('locfiledit_newfile')."\n\n\n\n\n?>"; |
---|
88 | $new_file['css'] = l10n('locfiledit_newfile') . "\n\n"; |
---|
89 | $new_file['lang'] = "<?php\n\n" . l10n('locfiledit_newfile') . "\n\n\n\n\n?>"; |
---|
90 | $new_file['plug'] = "<?php\n/* |
---|
91 | Plugin Name: " . l10n('locfiledit_onglet_plug') . " |
---|
92 | Version: 1.0 |
---|
93 | Description: " . l10n('locfiledit_onglet_plug') . " |
---|
94 | Plugin URI: http://www.phpwebgallery.net |
---|
95 | Author: |
---|
96 | Author URI: |
---|
97 | */\n\n\n\n\n?>"; |
---|
98 | |
---|
99 | // Editarea options |
---|
100 | $editarea = array( |
---|
101 | 'start_highlight' => true, |
---|
102 | 'language' => substr($user['language'], 0, 2), |
---|
103 | 'toolbar' => 'search,fullscreen, |,select_font, |, undo, redo, change_smooth_selection, highlight, reset_highlight, |, help'); |
---|
104 | if (isset($conf['editarea_options']) and is_array($conf['editarea_options'])) |
---|
105 | { |
---|
106 | $editarea = array_merge($editarea, $conf['editarea_options']); |
---|
107 | } |
---|
108 | |
---|
109 | // Edit selected file for CSS, template and language |
---|
110 | if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit'])) |
---|
111 | { |
---|
112 | $edited_file = $_POST['file_to_edit']; |
---|
113 | $content_file = file_exists($edited_file) ? |
---|
114 | file_get_contents($edited_file) : $new_file[$page['tab']]; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | // +-----------------------------------------------------------------------+ |
---|
119 | // | Process tabsheet |
---|
120 | // +-----------------------------------------------------------------------+ |
---|
121 | $options[] = l10n('locfiledit_choose_file'); |
---|
122 | $selected = 0; |
---|
123 | |
---|
124 | switch ($page['tab']) |
---|
125 | { |
---|
126 | case 'localconf': |
---|
127 | $edited_file = PHPWG_ROOT_PATH . "include/config_local.inc.php"; |
---|
128 | $content_file = file_exists($edited_file) ? |
---|
129 | file_get_contents($edited_file) : $new_file['localconf']; |
---|
130 | |
---|
131 | $template->assign('show_default' , array( |
---|
132 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
133 | . 'show_default.php?file=include/config_default.inc.php', |
---|
134 | 'FILE' => 'config_default.inc.php'))); |
---|
135 | $editarea['syntax'] = 'php'; |
---|
136 | break; |
---|
137 | |
---|
138 | case 'css': |
---|
139 | $template_dir = PHPWG_ROOT_PATH . 'template'; |
---|
140 | $options[] = '----------------------'; |
---|
141 | $value = PHPWG_ROOT_PATH . "template-common/local-layout.css"; |
---|
142 | $options[$value] = 'template-common / local-layout.css'; |
---|
143 | if ($edited_file == $value) $selected = $value; |
---|
144 | |
---|
145 | foreach (get_dirs($template_dir) as $pwg_template) |
---|
146 | { |
---|
147 | $options[] = '----------------------'; |
---|
148 | $value = $template_dir . '/' . $pwg_template . '/local-layout.css'; |
---|
149 | $options[$value] = $pwg_template . ' / local-layout.css'; |
---|
150 | if ($edited_file == $value) $selected = $value; |
---|
151 | $options[] = '----------------------'; |
---|
152 | foreach (get_dirs($template_dir.'/'.$pwg_template.'/theme') as $theme) |
---|
153 | { |
---|
154 | $value = $template_dir.'/'.$pwg_template.'/theme/'.$theme.'/theme.css'; |
---|
155 | $options[$value] = $pwg_template . ' / ' . $theme . ' / theme.css'; |
---|
156 | if ($edited_file == $value) $selected = $value; |
---|
157 | } |
---|
158 | } |
---|
159 | $template->assign('css_lang_tpl', array( |
---|
160 | 'OPTIONS' => $options, |
---|
161 | 'SELECTED' => $selected)); |
---|
162 | $editarea['syntax'] = 'css'; |
---|
163 | break; |
---|
164 | |
---|
165 | case 'tpl': |
---|
166 | $template_dir = PHPWG_ROOT_PATH . 'template'; |
---|
167 | foreach (get_dirs($template_dir) as $pwg_template) |
---|
168 | { |
---|
169 | $dir = $template_dir . '/' . $pwg_template . '/'; |
---|
170 | $options[] = '----------------------'; |
---|
171 | if (is_dir($dir) and $content = opendir($dir)) |
---|
172 | { |
---|
173 | while ($node = readdir($content)) |
---|
174 | { |
---|
175 | if (is_file($dir . $node) |
---|
176 | and strtolower(get_extension($node)) == 'tpl' |
---|
177 | and !strpos($node , '.bak.tpl')) |
---|
178 | { |
---|
179 | $value = $dir . $node; |
---|
180 | $options[$value] = $pwg_template . ' / ' . $node; |
---|
181 | if ($edited_file == $value) $selected = $value; |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | $template->assign('css_lang_tpl', array( |
---|
187 | 'OPTIONS' => $options, |
---|
188 | 'SELECTED' => $selected)); |
---|
189 | $editarea['syntax'] = 'html'; |
---|
190 | break; |
---|
191 | |
---|
192 | case 'lang': |
---|
193 | $options[] = '----------------------'; |
---|
194 | foreach (get_languages() as $language_code => $language_name) |
---|
195 | { |
---|
196 | $value = PHPWG_ROOT_PATH.'language/'.$language_code.'/local.lang.php'; |
---|
197 | if ($edited_file == $value) |
---|
198 | { |
---|
199 | $selected = $value; |
---|
200 | $template->assign('show_default', array( |
---|
201 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
202 | . 'show_default.php?file=' |
---|
203 | . 'language/'.$language_code.'/common.lang.php', |
---|
204 | 'FILE' => 'common.lang.php'), |
---|
205 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
206 | . 'show_default.php?file=' |
---|
207 | . 'language/'.$language_code.'/admin.lang.php', |
---|
208 | 'FILE' => 'admin.lang.php'))); |
---|
209 | } |
---|
210 | $options[$value] = $language_name; |
---|
211 | } |
---|
212 | $template->assign('css_lang_tpl', array( |
---|
213 | 'OPTIONS' => $options, |
---|
214 | 'SELECTED' => $selected)); |
---|
215 | $editarea['syntax'] = 'php'; |
---|
216 | break; |
---|
217 | |
---|
218 | case 'plug': |
---|
219 | $edited_file = PHPWG_PLUGINS_PATH . "PersonalPlugin/main.inc.php"; |
---|
220 | $content_file = file_exists($edited_file) ? |
---|
221 | file_get_contents($edited_file) : $new_file['plug']; |
---|
222 | $editarea['syntax'] = 'php'; |
---|
223 | break; |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | // +-----------------------------------------------------------------------+ |
---|
228 | // | Load backup file |
---|
229 | // +-----------------------------------------------------------------------+ |
---|
230 | if (isset($_POST['restore']) and !is_adviser()) |
---|
231 | { |
---|
232 | $edited_file = $_POST['edited_file']; |
---|
233 | $content_file = file_get_contents( |
---|
234 | substr_replace($edited_file , '.bak' , strrpos($edited_file ,'.') , 0)); |
---|
235 | |
---|
236 | array_push($page['infos'], |
---|
237 | l10n('locfiledit_bak_loaded1'), |
---|
238 | l10n('locfiledit_bak_loaded2')); |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | // +-----------------------------------------------------------------------+ |
---|
243 | // | Save file |
---|
244 | // +-----------------------------------------------------------------------+ |
---|
245 | if (isset($_POST['submit']) and !is_adviser()) |
---|
246 | { |
---|
247 | $edited_file = $_POST['edited_file']; |
---|
248 | $content_file = stripslashes($_POST['text']); |
---|
249 | if (get_extension($edited_file) == 'php') |
---|
250 | { |
---|
251 | $content_file = eval_syntax($content_file); |
---|
252 | } |
---|
253 | if ($content_file === false) |
---|
254 | { |
---|
255 | array_push($page['errors'], l10n('locfiledit_syntax_error')); |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | if ($page['tab'] == 'plug' |
---|
260 | and !is_dir(PHPWG_PLUGINS_PATH . 'PersonalPlugin')) |
---|
261 | { |
---|
262 | @mkdir(PHPWG_PLUGINS_PATH . "PersonalPlugin"); |
---|
263 | } |
---|
264 | if (file_exists($edited_file)) |
---|
265 | { |
---|
266 | @copy($edited_file, |
---|
267 | substr_replace($edited_file, |
---|
268 | '.bak', |
---|
269 | strrpos($edited_file , '.'), |
---|
270 | 0) |
---|
271 | ); |
---|
272 | } |
---|
273 | |
---|
274 | if ($file = @fopen($edited_file , "w")) |
---|
275 | { |
---|
276 | @fwrite($file , $content_file); |
---|
277 | @fclose($file); |
---|
278 | array_push($page['infos'], |
---|
279 | l10n('locfiledit_save_config'), |
---|
280 | sprintf(l10n('locfiledit_saved_bak'), |
---|
281 | substr(substr_replace($edited_file, |
---|
282 | '.bak', |
---|
283 | strrpos($edited_file , '.'), |
---|
284 | 0), |
---|
285 | 2))); |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | array_push($page['errors'], l10n('locfiledit_cant_save')); |
---|
290 | } |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | |
---|
295 | // +-----------------------------------------------------------------------+ |
---|
296 | // | template initialization |
---|
297 | // +-----------------------------------------------------------------------+ |
---|
298 | $template->set_filenames(array( |
---|
299 | 'plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
300 | |
---|
301 | if (!empty($edited_file)) |
---|
302 | { |
---|
303 | if (!empty($page['errors'])) |
---|
304 | { |
---|
305 | $content_file = stripslashes($_POST['text']); |
---|
306 | } |
---|
307 | $template->assign('zone_edit', |
---|
308 | array('EDITED_FILE' => $edited_file, |
---|
309 | 'CONTENT_FILE' => htmlspecialchars($content_file), |
---|
310 | 'FILE_NAME' => trim($edited_file, './\\'))); |
---|
311 | if (file_exists( |
---|
312 | substr_replace($edited_file ,'.bak',strrpos($edited_file , '.'),0))) |
---|
313 | { |
---|
314 | $template->assign('restore', true); |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | // Editarea |
---|
319 | if (!isset($conf['editarea_options']) or $conf['editarea_options'] !== false) |
---|
320 | { |
---|
321 | $template->assign('editarea', array( |
---|
322 | 'URL' => LOCALEDIT_PATH . 'editarea/edit_area_full.js', |
---|
323 | 'OPTIONS' => $editarea)); |
---|
324 | } |
---|
325 | |
---|
326 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
327 | |
---|
328 | ?> |
---|