Changeset 10348 for trunk/plugins/LocalFilesEditor/admin.php
- Timestamp:
- Apr 13, 2011, 12:36:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/LocalFilesEditor/admin.php
r10309 r10348 24 24 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 25 25 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); 26 include_once(LOCALEDIT_PATH.' functions.inc.php');26 include_once(LOCALEDIT_PATH.'include/functions.inc.php'); 27 27 load_language('plugin.lang', LOCALEDIT_PATH); 28 28 $my_base_url = get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)); … … 55 55 $tabsheet->assign(); 56 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 // Edit selected file for CSS, template and language 78 if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit'])) 79 { 80 $edited_file = $_POST['file_to_edit']; 81 $content_file = file_exists($edited_file) ? 82 file_get_contents($edited_file) : $new_file[$page['tab']]; 83 } 84 85 // Edit new tpl file 86 if (isset($_POST['create_tpl'])) 87 { 88 $filename = $_POST['tpl_name']; 89 if (empty($filename)) 90 { 91 array_push($page['errors'], l10n('locfiledit_empty_filename')); 92 } 93 if (get_extension($filename) != 'tpl') 94 { 95 $filename .= '.tpl'; 96 } 97 if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) 98 { 99 array_push($page['errors'], l10n('locfiledit_filename_error')); 100 } 101 if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0') 102 { 103 array_push($page['errors'], l10n('locfiledit_model_error')); 104 } 105 if (file_exists($_POST['tpl_parent'] . '/' . $filename)) 106 { 107 array_push($page['errors'], l10n('locfiledit_file_already_exists')); 108 } 109 if (!empty($page['errors'])) 110 { 111 $newfile_page = true; 112 } 113 else 114 { 115 $edited_file = $_POST['tpl_parent'] . '/' . $filename; 116 $content_file = ($_POST['tpl_model'] == '0') ? $new_file['tpl'] : file_get_contents($_POST['tpl_model']); 117 } 118 } 119 120 // +-----------------------------------------------------------------------+ 121 // | Process tabsheet 122 // +-----------------------------------------------------------------------+ 123 switch ($page['tab']) 124 { 125 case 'localconf': 126 $edited_file = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . "config/config.inc.php"; 127 $content_file = file_exists($edited_file) ? 128 file_get_contents($edited_file) : $new_file['localconf']; 129 130 $template->assign('show_default' , array( 131 array('SHOW_DEFAULT' => LOCALEDIT_PATH 132 . 'show_default.php?file=include/config_default.inc.php', 133 'FILE' => 'config_default.inc.php'))); 134 $codemirror_mode = 'application/x-httpd-php'; 135 break; 136 137 case 'css': 138 $selected = 0; 139 $options[] = l10n('locfiledit_choose_file'); 140 $options[] = '----------------------'; 141 $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . "css/rules.css"; 142 $options[$value] = 'local / css / rules.css'; 143 if ($edited_file == $value) $selected = $value; 144 $options[] = '----------------------'; 145 146 foreach (get_dirs($conf['themes_dir']) as $theme_id) 147 { 148 $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . 'css/'.$theme_id.'-rules.css'; 149 $options[$value] = 'local / css / '.$theme_id.'-rules.css'; 150 if ($edited_file == $value) $selected = $value; 151 } 152 $template->assign('css_lang_tpl', array( 153 'OPTIONS' => $options, 154 'SELECTED' => $selected)); 155 $codemirror_mode = 'text/css'; 156 break; 157 158 case 'tpl': 159 // New file form creation 160 if ($newfile_page) 161 { 162 $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : ''; 163 $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0'; 164 $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension'; 165 166 // Parent directories list 167 $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension'); 168 $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension')); 169 170 $options['model'][] = l10n('locfiledit_empty_page'); 171 $options['model'][] = '----------------------'; 172 $i = 0; 173 foreach (get_extents() as $pwg_template) 174 { 175 $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template; 176 $options['model'][$value] = 'template-extension / ' . str_replace('/', ' / ', $pwg_template); 177 $i++; 178 } 179 foreach (get_dirs($conf['themes_dir']) as $theme_id) 180 { 181 if ($i) 182 { 183 $options['model'][] = '----------------------'; 184 $i = 0; 185 } 186 $dir = $conf['themes_dir'] . '/' . $theme_id . '/template/'; 187 if (is_dir($dir) and $content = opendir($dir)) 188 { 189 while ($node = readdir($content)) 190 { 191 if (is_file($dir.$node) and get_extension($node) == 'tpl') 192 { 193 $value = $dir . $node; 194 $options['model'][$value] = $theme_id . ' / ' . $node; 195 $i++; 196 } 197 } 198 } 199 } 200 if (end($options['model']) == '----------------------') 201 { 202 array_pop($options['model']); 203 } 204 // Assign variables to template 205 $template->assign('create_tpl', array( 206 'NEW_FILE_NAME' => $filename, 207 'MODEL_OPTIONS' => $options['model'], 208 'MODEL_SELECTED' => $selected['model'], 209 'PARENT_OPTIONS' => $options['parent'], 210 'PARENT_SELECTED' => $selected['parent'])); 211 break; 212 } 213 // List existing template extensions 214 $selected = 0; 215 $options[] = l10n('locfiledit_choose_file'); 216 $options[] = '----------------------'; 217 foreach (get_extents() as $pwg_template) 218 { 219 $value = './template-extension/' . $pwg_template; 220 $options[$value] = str_replace('/', ' / ', $pwg_template); 221 if ($edited_file == $value) $selected = $value; 222 } 223 if ($selected == 0 and !empty($edited_file)) 224 { 225 $options[$edited_file] = str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file); 226 $selected = $edited_file; 227 } 228 $template->assign('css_lang_tpl', array( 229 'OPTIONS' => $options, 230 'SELECTED' => $selected, 231 'NEW_FILE_URL' => $my_base_url.'-tpl&newfile', 232 'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right')); 233 234 $codemirror_mode = 'text/html'; 235 break; 236 237 case 'lang': 238 $selected = 0; 239 $options[] = l10n('locfiledit_choose_file'); 240 $options[] = '----------------------'; 241 foreach (get_languages() as $language_code => $language_name) 242 { 243 $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'language/'.$language_code.'.lang.php'; 244 if ($edited_file == $value) 245 { 246 $selected = $value; 247 $template->assign('show_default', array( 248 array('SHOW_DEFAULT' => LOCALEDIT_PATH 249 . 'show_default.php?file=' 250 . 'language/'.$language_code.'/common.lang.php', 251 'FILE' => 'common.lang.php'), 252 array('SHOW_DEFAULT' => LOCALEDIT_PATH 253 . 'show_default.php?file=' 254 . 'language/'.$language_code.'/admin.lang.php', 255 'FILE' => 'admin.lang.php'))); 256 } 257 $options[$value] = $language_name; 258 } 259 $template->assign('css_lang_tpl', array( 260 'OPTIONS' => $options, 261 'SELECTED' => $selected)); 262 $codemirror_mode = 'application/x-httpd-php'; 263 break; 264 265 case 'plug': 266 $edited_file = PHPWG_PLUGINS_PATH . "PersonalPlugin/main.inc.php"; 267 $content_file = file_exists($edited_file) ? 268 file_get_contents($edited_file) : $new_file['plug']; 269 $codemirror_mode = 'application/x-httpd-php'; 270 break; 271 } 57 include_once(LOCALEDIT_PATH.'include/'.$page['tab'].'.inc.php'); 272 58 273 59 // +-----------------------------------------------------------------------+ … … 335 121 // +-----------------------------------------------------------------------+ 336 122 $template->set_filenames(array( 337 'plugin_admin_content' => dirname(__FILE__) . '/ admin.tpl'));123 'plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl')); 338 124 339 125 if (!empty($edited_file)) … … 344 130 } 345 131 $template->assign('zone_edit', 346 array('EDITED_FILE' => $edited_file, 347 'CONTENT_FILE' => htmlspecialchars($content_file), 348 'FILE_NAME' => trim($edited_file, './\\'))); 132 array( 133 'EDITED_FILE' => $edited_file, 134 'CONTENT_FILE' => htmlspecialchars($content_file), 135 'FILE_NAME' => trim($edited_file, './\\') 136 ) 137 ); 349 138 if (file_exists(get_bak_file($edited_file))) 350 139 { … … 355 144 $template->assign('restore_infos', true); 356 145 } 357 358 146 } 359 147
Note: See TracChangeset
for help on using the changeset viewer.