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