[2235] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3049] | 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[2235] | 23 | |
---|
| 24 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 25 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
[2291] | 26 | include_once(LOCALEDIT_PATH.'functions.inc.php'); |
---|
[2235] | 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('tpl', |
---|
| 43 | l10n('locfiledit_onglet_tpl'), |
---|
| 44 | $my_base_url.'&tab=tpl'); |
---|
| 45 | $tabsheet->add('lang', |
---|
| 46 | l10n('locfiledit_onglet_lang'), |
---|
| 47 | $my_base_url.'&tab=lang'); |
---|
| 48 | $tabsheet->add('plug', |
---|
| 49 | l10n('locfiledit_onglet_plug'), |
---|
| 50 | $my_base_url.'&tab=plug'); |
---|
| 51 | $tabsheet->select($page['tab']); |
---|
| 52 | $tabsheet->assign(); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | // +-----------------------------------------------------------------------+ |
---|
| 56 | // | Variables init |
---|
| 57 | // +-----------------------------------------------------------------------+ |
---|
[2588] | 58 | $edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : ''; |
---|
[2235] | 59 | $content_file = ''; |
---|
[2588] | 60 | $new_file['localconf'] = "<?php\n\n/* ".l10n('locfiledit_newfile')." */\n\n\n\n\n?>"; |
---|
| 61 | $new_file['css'] = "/* " . l10n('locfiledit_newfile') . " */\n\n"; |
---|
| 62 | $new_file['tpl'] = "{* " . l10n('locfiledit_newfile') . " *}\n\n"; |
---|
| 63 | $new_file['lang'] = $new_file['localconf']; |
---|
[2235] | 64 | $new_file['plug'] = "<?php\n/* |
---|
| 65 | Plugin Name: " . l10n('locfiledit_onglet_plug') . " |
---|
| 66 | Version: 1.0 |
---|
| 67 | Description: " . l10n('locfiledit_onglet_plug') . " |
---|
[3133] | 68 | Plugin URI: http://piwigo.org |
---|
[2235] | 69 | Author: |
---|
| 70 | Author URI: |
---|
| 71 | */\n\n\n\n\n?>"; |
---|
[2588] | 72 | $newfile_page = isset($_GET['newfile']) ? true : false; |
---|
[2235] | 73 | |
---|
[2291] | 74 | // Editarea options |
---|
[2588] | 75 | $editarea_options = array( |
---|
| 76 | 'language' => substr($user['language'], 0, 2), |
---|
[2291] | 77 | 'start_highlight' => true, |
---|
[2588] | 78 | 'allow_toggle' => false, |
---|
[2291] | 79 | 'toolbar' => 'search,fullscreen, |,select_font, |, undo, redo, change_smooth_selection, highlight, reset_highlight, |, help'); |
---|
| 80 | |
---|
[2235] | 81 | // Edit selected file for CSS, template and language |
---|
| 82 | if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit'])) |
---|
| 83 | { |
---|
| 84 | $edited_file = $_POST['file_to_edit']; |
---|
| 85 | $content_file = file_exists($edited_file) ? |
---|
| 86 | file_get_contents($edited_file) : $new_file[$page['tab']]; |
---|
| 87 | } |
---|
| 88 | |
---|
[2588] | 89 | // Edit new tpl file |
---|
| 90 | if (isset($_POST['create_tpl'])) |
---|
| 91 | { |
---|
| 92 | $filename = $_POST['tpl_name']; |
---|
[2906] | 93 | if (empty($filename)) |
---|
| 94 | { |
---|
| 95 | array_push($page['errors'], l10n('locfiledit_empty_filename')); |
---|
| 96 | } |
---|
[2588] | 97 | if (get_extension($filename) != 'tpl') |
---|
| 98 | { |
---|
| 99 | $filename .= '.tpl'; |
---|
| 100 | } |
---|
| 101 | if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) |
---|
| 102 | { |
---|
| 103 | array_push($page['errors'], l10n('locfiledit_filename_error')); |
---|
| 104 | } |
---|
| 105 | if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0') |
---|
| 106 | { |
---|
| 107 | array_push($page['errors'], l10n('locfiledit_model_error')); |
---|
| 108 | } |
---|
| 109 | if (file_exists($_POST['tpl_parent'] . '/' . $filename)) |
---|
| 110 | { |
---|
| 111 | array_push($page['errors'], l10n('locfiledit_file_already_exists')); |
---|
[2906] | 112 | } |
---|
| 113 | if (!empty($page['errors'])) |
---|
| 114 | { |
---|
[2588] | 115 | $newfile_page = true; |
---|
| 116 | } |
---|
[2906] | 117 | else |
---|
[2588] | 118 | { |
---|
| 119 | $edited_file = $_POST['tpl_parent'] . '/' . $filename; |
---|
| 120 | $content_file = ($_POST['tpl_model'] == '0') ? $new_file['tpl'] : file_get_contents($_POST['tpl_model']); |
---|
| 121 | } |
---|
| 122 | } |
---|
[2235] | 123 | |
---|
| 124 | // +-----------------------------------------------------------------------+ |
---|
| 125 | // | Process tabsheet |
---|
| 126 | // +-----------------------------------------------------------------------+ |
---|
| 127 | switch ($page['tab']) |
---|
| 128 | { |
---|
| 129 | case 'localconf': |
---|
| 130 | $edited_file = PHPWG_ROOT_PATH . "include/config_local.inc.php"; |
---|
| 131 | $content_file = file_exists($edited_file) ? |
---|
| 132 | file_get_contents($edited_file) : $new_file['localconf']; |
---|
| 133 | |
---|
| 134 | $template->assign('show_default' , array( |
---|
| 135 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
| 136 | . 'show_default.php?file=include/config_default.inc.php', |
---|
| 137 | 'FILE' => 'config_default.inc.php'))); |
---|
[2588] | 138 | $editarea_options['syntax'] = 'php'; |
---|
[2235] | 139 | break; |
---|
| 140 | |
---|
| 141 | case 'tpl': |
---|
[2588] | 142 | // New file form creation |
---|
| 143 | if ($newfile_page and !is_adviser()) |
---|
[2235] | 144 | { |
---|
[2588] | 145 | $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : ''; |
---|
| 146 | $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0'; |
---|
| 147 | $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension'; |
---|
| 148 | |
---|
| 149 | // Parent directories list |
---|
| 150 | $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension'); |
---|
| 151 | $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension')); |
---|
| 152 | |
---|
| 153 | // Model list |
---|
| 154 | $eligible_templates = array( |
---|
| 155 | 'about.tpl', |
---|
[3182] | 156 | 'footer.tpl', |
---|
| 157 | 'header.tpl', |
---|
[2588] | 158 | 'identification.tpl', |
---|
[3182] | 159 | 'index.tpl', |
---|
[2588] | 160 | 'mainpage_categories.tpl', |
---|
[2712] | 161 | 'menubar.tpl', |
---|
| 162 | 'menubar_categories.tpl', |
---|
| 163 | 'menubar_identification.tpl', |
---|
| 164 | 'menubar_links.tpl', |
---|
| 165 | 'menubar_menu.tpl', |
---|
| 166 | 'menubar_specials.tpl', |
---|
| 167 | 'menubar_tags.tpl', |
---|
[3182] | 168 | 'navigation_bar.tpl', |
---|
[2588] | 169 | 'nbm.tpl', |
---|
| 170 | 'notification.tpl', |
---|
[3182] | 171 | 'picture.tpl', |
---|
[2588] | 172 | 'picture_content.tpl', |
---|
[3665] | 173 | 'picture_nav_buttons.tpl', |
---|
[2588] | 174 | 'popuphelp.tpl', |
---|
| 175 | 'profile.tpl', |
---|
| 176 | 'profile_content.tpl', |
---|
[3182] | 177 | 'redirect.tpl', |
---|
[2588] | 178 | 'register.tpl', |
---|
| 179 | 'search.tpl', |
---|
| 180 | 'search_rules.tpl', |
---|
| 181 | 'slideshow.tpl', |
---|
| 182 | 'tags.tpl', |
---|
[3182] | 183 | 'thumbnails.tpl', |
---|
[2588] | 184 | 'upload.tpl'); |
---|
| 185 | |
---|
| 186 | $options['model'][] = l10n('locfiledit_empty_page'); |
---|
| 187 | $options['model'][] = '----------------------'; |
---|
| 188 | foreach (get_extents() as $pwg_template) |
---|
[2235] | 189 | { |
---|
[2588] | 190 | $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template; |
---|
| 191 | $options['model'][$value] = 'template-extension / ' . str_replace('/', ' / ', $pwg_template); |
---|
| 192 | } |
---|
| 193 | $template_dir = PHPWG_ROOT_PATH . 'template'; |
---|
| 194 | foreach (get_dirs($template_dir) as $pwg_template) |
---|
| 195 | { |
---|
| 196 | if (count($options['model']) > 2) |
---|
[2235] | 197 | { |
---|
[2588] | 198 | $options['model'][] = '----------------------'; |
---|
| 199 | } |
---|
| 200 | $dir = $template_dir . '/' . $pwg_template . '/'; |
---|
| 201 | if (is_dir($dir) and $content = opendir($dir)) |
---|
| 202 | { |
---|
| 203 | while ($node = readdir($content)) |
---|
[2235] | 204 | { |
---|
[2588] | 205 | if (is_file($dir . $node) and in_array($node, $eligible_templates)) |
---|
| 206 | { |
---|
| 207 | $value = $dir . $node; |
---|
| 208 | $options['model'][$value] = $pwg_template . ' / ' . $node; |
---|
| 209 | } |
---|
[2235] | 210 | } |
---|
| 211 | } |
---|
| 212 | } |
---|
[2588] | 213 | // Assign variables to template |
---|
| 214 | $template->assign('create_tpl', array( |
---|
| 215 | 'NEW_FILE_NAME' => $filename, |
---|
| 216 | 'MODEL_OPTIONS' => $options['model'], |
---|
| 217 | 'MODEL_SELECTED' => $selected['model'], |
---|
| 218 | 'PARENT_OPTIONS' => $options['parent'], |
---|
| 219 | 'PARENT_SELECTED' => $selected['parent'])); |
---|
| 220 | break; |
---|
[2235] | 221 | } |
---|
[2588] | 222 | // List existing template extensions |
---|
| 223 | $template_dir = PHPWG_ROOT_PATH . 'template-extension'; |
---|
| 224 | $selected = 0; |
---|
| 225 | $options[] = l10n('locfiledit_choose_file'); |
---|
| 226 | $options[] = '----------------------'; |
---|
| 227 | foreach (get_extents() as $pwg_template) |
---|
| 228 | { |
---|
| 229 | $value = './template-extension/' . $pwg_template; |
---|
| 230 | $options[$value] = str_replace('/', ' / ', $pwg_template); |
---|
| 231 | if ($edited_file == $value) $selected = $value; |
---|
| 232 | } |
---|
| 233 | if ($selected == 0 and !empty($edited_file)) |
---|
| 234 | { |
---|
| 235 | $options[$edited_file] = str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file); |
---|
| 236 | $selected = $edited_file; |
---|
| 237 | } |
---|
[2235] | 238 | $template->assign('css_lang_tpl', array( |
---|
[2588] | 239 | 'OPTIONS' => $options, |
---|
| 240 | 'SELECTED' => $selected, |
---|
| 241 | 'NEW_FILE_URL' => $my_base_url.'&tab=tpl&newfile', |
---|
| 242 | 'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right')); |
---|
| 243 | |
---|
| 244 | $editarea_options['syntax'] = 'html'; |
---|
[2235] | 245 | break; |
---|
| 246 | |
---|
| 247 | case 'lang': |
---|
[2588] | 248 | $selected = 0; |
---|
| 249 | $options[] = l10n('locfiledit_choose_file'); |
---|
[2235] | 250 | $options[] = '----------------------'; |
---|
| 251 | foreach (get_languages() as $language_code => $language_name) |
---|
| 252 | { |
---|
| 253 | $value = PHPWG_ROOT_PATH.'language/'.$language_code.'/local.lang.php'; |
---|
| 254 | if ($edited_file == $value) |
---|
| 255 | { |
---|
| 256 | $selected = $value; |
---|
| 257 | $template->assign('show_default', array( |
---|
| 258 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
| 259 | . 'show_default.php?file=' |
---|
| 260 | . 'language/'.$language_code.'/common.lang.php', |
---|
| 261 | 'FILE' => 'common.lang.php'), |
---|
| 262 | array('SHOW_DEFAULT' => LOCALEDIT_PATH |
---|
| 263 | . 'show_default.php?file=' |
---|
| 264 | . 'language/'.$language_code.'/admin.lang.php', |
---|
| 265 | 'FILE' => 'admin.lang.php'))); |
---|
| 266 | } |
---|
| 267 | $options[$value] = $language_name; |
---|
| 268 | } |
---|
| 269 | $template->assign('css_lang_tpl', array( |
---|
| 270 | 'OPTIONS' => $options, |
---|
| 271 | 'SELECTED' => $selected)); |
---|
[2588] | 272 | $editarea_options['syntax'] = 'php'; |
---|
[2235] | 273 | break; |
---|
| 274 | |
---|
| 275 | case 'plug': |
---|
| 276 | $edited_file = PHPWG_PLUGINS_PATH . "PersonalPlugin/main.inc.php"; |
---|
| 277 | $content_file = file_exists($edited_file) ? |
---|
| 278 | file_get_contents($edited_file) : $new_file['plug']; |
---|
[2588] | 279 | $editarea_options['syntax'] = 'php'; |
---|
[2235] | 280 | break; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | // +-----------------------------------------------------------------------+ |
---|
| 284 | // | Load backup file |
---|
| 285 | // +-----------------------------------------------------------------------+ |
---|
| 286 | if (isset($_POST['restore']) and !is_adviser()) |
---|
| 287 | { |
---|
| 288 | $edited_file = $_POST['edited_file']; |
---|
[2588] | 289 | $content_file = file_get_contents(get_bak_file($edited_file)); |
---|
[2235] | 290 | array_push($page['infos'], |
---|
[2588] | 291 | l10n('locfiledit_bak_loaded1'), |
---|
| 292 | l10n('locfiledit_bak_loaded2')); |
---|
[2235] | 293 | } |
---|
| 294 | |
---|
| 295 | // +-----------------------------------------------------------------------+ |
---|
| 296 | // | Save file |
---|
| 297 | // +-----------------------------------------------------------------------+ |
---|
| 298 | if (isset($_POST['submit']) and !is_adviser()) |
---|
| 299 | { |
---|
| 300 | $edited_file = $_POST['edited_file']; |
---|
| 301 | $content_file = stripslashes($_POST['text']); |
---|
| 302 | if (get_extension($edited_file) == 'php') |
---|
| 303 | { |
---|
| 304 | $content_file = eval_syntax($content_file); |
---|
| 305 | } |
---|
| 306 | if ($content_file === false) |
---|
| 307 | { |
---|
| 308 | array_push($page['errors'], l10n('locfiledit_syntax_error')); |
---|
| 309 | } |
---|
| 310 | else |
---|
| 311 | { |
---|
[2588] | 312 | if ($page['tab'] == 'plug' and !is_dir(PHPWG_PLUGINS_PATH . 'PersonalPlugin')) |
---|
[2235] | 313 | { |
---|
| 314 | @mkdir(PHPWG_PLUGINS_PATH . "PersonalPlugin"); |
---|
| 315 | } |
---|
| 316 | if (file_exists($edited_file)) |
---|
| 317 | { |
---|
[2588] | 318 | @copy($edited_file, get_bak_file($edited_file)); |
---|
| 319 | array_push($page['infos'], sprintf(l10n('locfiledit_saved_bak'), substr(get_bak_file($edited_file), 2))); |
---|
[2235] | 320 | } |
---|
| 321 | |
---|
| 322 | if ($file = @fopen($edited_file , "w")) |
---|
| 323 | { |
---|
| 324 | @fwrite($file , $content_file); |
---|
| 325 | @fclose($file); |
---|
[2588] | 326 | array_unshift($page['infos'], l10n('locfiledit_save_config')); |
---|
[2235] | 327 | } |
---|
| 328 | else |
---|
| 329 | { |
---|
| 330 | array_push($page['errors'], l10n('locfiledit_cant_save')); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | // +-----------------------------------------------------------------------+ |
---|
| 336 | // | template initialization |
---|
| 337 | // +-----------------------------------------------------------------------+ |
---|
| 338 | $template->set_filenames(array( |
---|
| 339 | 'plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
| 340 | |
---|
| 341 | if (!empty($edited_file)) |
---|
| 342 | { |
---|
| 343 | if (!empty($page['errors'])) |
---|
| 344 | { |
---|
| 345 | $content_file = stripslashes($_POST['text']); |
---|
| 346 | } |
---|
| 347 | $template->assign('zone_edit', |
---|
| 348 | array('EDITED_FILE' => $edited_file, |
---|
| 349 | 'CONTENT_FILE' => htmlspecialchars($content_file), |
---|
| 350 | 'FILE_NAME' => trim($edited_file, './\\'))); |
---|
[2588] | 351 | if (file_exists(get_bak_file($edited_file))) |
---|
[2235] | 352 | { |
---|
| 353 | $template->assign('restore', true); |
---|
| 354 | } |
---|
[2588] | 355 | if (file_exists($edited_file)) |
---|
| 356 | { |
---|
| 357 | $template->assign('restore_infos', true); |
---|
| 358 | } |
---|
| 359 | |
---|
[2235] | 360 | } |
---|
| 361 | |
---|
[2588] | 362 | $template->assign(array( |
---|
| 363 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=plugin&section=LocalFilesEditor%2Fadmin.php&tab=' . $page['tab'], |
---|
| 364 | 'LOCALEDIT_PATH' => LOCALEDIT_PATH, |
---|
| 365 | 'LOAD_EDITAREA' => isset($conf['LocalFilesEditor']) ? $conf['LocalFilesEditor'] : 'off', |
---|
| 366 | 'EDITAREA_OPTIONS' => $editarea_options)); |
---|
[2291] | 367 | |
---|
[2235] | 368 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 369 | |
---|
| 370 | ?> |
---|