From d2da26e467aec1347ae7c314c4c8279cb4618c34 Mon Sep 17 00:00:00 2001 From: patdenice Date: Wed, 13 Apr 2011 10:36:53 +0000 Subject: [PATCH] Clean code git-svn-id: http://piwigo.org/svn/trunk@10348 68402e56-0260-453c-a942-63ccdbb3a9ee --- plugins/LocalFilesEditor/admin.php | 230 +----------------- plugins/LocalFilesEditor/include/css.inc.php | 45 ++++ .../{ => include}/functions.inc.php | 0 plugins/LocalFilesEditor/include/lang.inc.php | 53 ++++ .../include/localconf.inc.php | 26 ++ plugins/LocalFilesEditor/include/plug.inc.php | 25 ++ plugins/LocalFilesEditor/include/tpl.inc.php | 140 +++++++++++ plugins/LocalFilesEditor/show_default.php | 6 +- .../LocalFilesEditor/{ => template}/admin.tpl | 21 +- .../{ => template}/locfiledit.css | 32 ++- .../{ => template}/show_default.tpl | 26 +- 11 files changed, 340 insertions(+), 264 deletions(-) create mode 100644 plugins/LocalFilesEditor/include/css.inc.php rename plugins/LocalFilesEditor/{ => include}/functions.inc.php (100%) create mode 100644 plugins/LocalFilesEditor/include/lang.inc.php create mode 100644 plugins/LocalFilesEditor/include/localconf.inc.php create mode 100644 plugins/LocalFilesEditor/include/plug.inc.php create mode 100644 plugins/LocalFilesEditor/include/tpl.inc.php rename plugins/LocalFilesEditor/{ => template}/admin.tpl (88%) rename plugins/LocalFilesEditor/{ => template}/locfiledit.css (50%) rename plugins/LocalFilesEditor/{ => template}/show_default.tpl (80%) diff --git a/plugins/LocalFilesEditor/admin.php b/plugins/LocalFilesEditor/admin.php index cd2c5b301..a0e679378 100644 --- a/plugins/LocalFilesEditor/admin.php +++ b/plugins/LocalFilesEditor/admin.php @@ -23,7 +23,7 @@ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); -include_once(LOCALEDIT_PATH.'functions.inc.php'); +include_once(LOCALEDIT_PATH.'include/functions.inc.php'); load_language('plugin.lang', LOCALEDIT_PATH); $my_base_url = get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)); @@ -54,221 +54,7 @@ $tabsheet->add('plug', $tabsheet->select($page['tab']); $tabsheet->assign(); - -// +-----------------------------------------------------------------------+ -// | Variables init -// +-----------------------------------------------------------------------+ -$edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : ''; -$content_file = ''; -$new_file['localconf'] = ""; -$new_file['css'] = "/* " . l10n('locfiledit_newfile') . " */\n\n"; -$new_file['tpl'] = "{* " . l10n('locfiledit_newfile') . " *}\n\n"; -$new_file['lang'] = $new_file['localconf']; -$new_file['plug'] = ""; -$newfile_page = isset($_GET['newfile']) ? true : false; - -// Edit selected file for CSS, template and language -if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit'])) -{ - $edited_file = $_POST['file_to_edit']; - $content_file = file_exists($edited_file) ? - file_get_contents($edited_file) : $new_file[$page['tab']]; -} - -// Edit new tpl file -if (isset($_POST['create_tpl'])) -{ - $filename = $_POST['tpl_name']; - if (empty($filename)) - { - array_push($page['errors'], l10n('locfiledit_empty_filename')); - } - if (get_extension($filename) != 'tpl') - { - $filename .= '.tpl'; - } - if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) - { - array_push($page['errors'], l10n('locfiledit_filename_error')); - } - if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0') - { - array_push($page['errors'], l10n('locfiledit_model_error')); - } - if (file_exists($_POST['tpl_parent'] . '/' . $filename)) - { - array_push($page['errors'], l10n('locfiledit_file_already_exists')); - } - if (!empty($page['errors'])) - { - $newfile_page = true; - } - else - { - $edited_file = $_POST['tpl_parent'] . '/' . $filename; - $content_file = ($_POST['tpl_model'] == '0') ? $new_file['tpl'] : file_get_contents($_POST['tpl_model']); - } -} - -// +-----------------------------------------------------------------------+ -// | Process tabsheet -// +-----------------------------------------------------------------------+ -switch ($page['tab']) -{ - case 'localconf': - $edited_file = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . "config/config.inc.php"; - $content_file = file_exists($edited_file) ? - file_get_contents($edited_file) : $new_file['localconf']; - - $template->assign('show_default' , array( - array('SHOW_DEFAULT' => LOCALEDIT_PATH - . 'show_default.php?file=include/config_default.inc.php', - 'FILE' => 'config_default.inc.php'))); - $codemirror_mode = 'application/x-httpd-php'; - break; - - case 'css': - $selected = 0; - $options[] = l10n('locfiledit_choose_file'); - $options[] = '----------------------'; - $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . "css/rules.css"; - $options[$value] = 'local / css / rules.css'; - if ($edited_file == $value) $selected = $value; - $options[] = '----------------------'; - - foreach (get_dirs($conf['themes_dir']) as $theme_id) - { - $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . 'css/'.$theme_id.'-rules.css'; - $options[$value] = 'local / css / '.$theme_id.'-rules.css'; - if ($edited_file == $value) $selected = $value; - } - $template->assign('css_lang_tpl', array( - 'OPTIONS' => $options, - 'SELECTED' => $selected)); - $codemirror_mode = 'text/css'; - break; - - case 'tpl': - // New file form creation - if ($newfile_page) - { - $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : ''; - $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0'; - $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension'; - - // Parent directories list - $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension'); - $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension')); - - $options['model'][] = l10n('locfiledit_empty_page'); - $options['model'][] = '----------------------'; - $i = 0; - foreach (get_extents() as $pwg_template) - { - $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template; - $options['model'][$value] = 'template-extension / ' . str_replace('/', ' / ', $pwg_template); - $i++; - } - foreach (get_dirs($conf['themes_dir']) as $theme_id) - { - if ($i) - { - $options['model'][] = '----------------------'; - $i = 0; - } - $dir = $conf['themes_dir'] . '/' . $theme_id . '/template/'; - if (is_dir($dir) and $content = opendir($dir)) - { - while ($node = readdir($content)) - { - if (is_file($dir.$node) and get_extension($node) == 'tpl') - { - $value = $dir . $node; - $options['model'][$value] = $theme_id . ' / ' . $node; - $i++; - } - } - } - } - if (end($options['model']) == '----------------------') - { - array_pop($options['model']); - } - // Assign variables to template - $template->assign('create_tpl', array( - 'NEW_FILE_NAME' => $filename, - 'MODEL_OPTIONS' => $options['model'], - 'MODEL_SELECTED' => $selected['model'], - 'PARENT_OPTIONS' => $options['parent'], - 'PARENT_SELECTED' => $selected['parent'])); - break; - } - // List existing template extensions - $selected = 0; - $options[] = l10n('locfiledit_choose_file'); - $options[] = '----------------------'; - foreach (get_extents() as $pwg_template) - { - $value = './template-extension/' . $pwg_template; - $options[$value] = str_replace('/', ' / ', $pwg_template); - if ($edited_file == $value) $selected = $value; - } - if ($selected == 0 and !empty($edited_file)) - { - $options[$edited_file] = str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file); - $selected = $edited_file; - } - $template->assign('css_lang_tpl', array( - 'OPTIONS' => $options, - 'SELECTED' => $selected, - 'NEW_FILE_URL' => $my_base_url.'-tpl&newfile', - 'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right')); - - $codemirror_mode = 'text/html'; - break; - - case 'lang': - $selected = 0; - $options[] = l10n('locfiledit_choose_file'); - $options[] = '----------------------'; - foreach (get_languages() as $language_code => $language_name) - { - $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'language/'.$language_code.'.lang.php'; - if ($edited_file == $value) - { - $selected = $value; - $template->assign('show_default', array( - array('SHOW_DEFAULT' => LOCALEDIT_PATH - . 'show_default.php?file=' - . 'language/'.$language_code.'/common.lang.php', - 'FILE' => 'common.lang.php'), - array('SHOW_DEFAULT' => LOCALEDIT_PATH - . 'show_default.php?file=' - . 'language/'.$language_code.'/admin.lang.php', - 'FILE' => 'admin.lang.php'))); - } - $options[$value] = $language_name; - } - $template->assign('css_lang_tpl', array( - 'OPTIONS' => $options, - 'SELECTED' => $selected)); - $codemirror_mode = 'application/x-httpd-php'; - break; - - case 'plug': - $edited_file = PHPWG_PLUGINS_PATH . "PersonalPlugin/main.inc.php"; - $content_file = file_exists($edited_file) ? - file_get_contents($edited_file) : $new_file['plug']; - $codemirror_mode = 'application/x-httpd-php'; - break; -} +include_once(LOCALEDIT_PATH.'include/'.$page['tab'].'.inc.php'); // +-----------------------------------------------------------------------+ // | Load backup file @@ -334,7 +120,7 @@ if (isset($_POST['submit'])) // | template initialization // +-----------------------------------------------------------------------+ $template->set_filenames(array( - 'plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); + 'plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl')); if (!empty($edited_file)) { @@ -343,9 +129,12 @@ if (!empty($edited_file)) $content_file = stripslashes($_POST['text']); } $template->assign('zone_edit', - array('EDITED_FILE' => $edited_file, - 'CONTENT_FILE' => htmlspecialchars($content_file), - 'FILE_NAME' => trim($edited_file, './\\'))); + array( + 'EDITED_FILE' => $edited_file, + 'CONTENT_FILE' => htmlspecialchars($content_file), + 'FILE_NAME' => trim($edited_file, './\\') + ) + ); if (file_exists(get_bak_file($edited_file))) { $template->assign('restore', true); @@ -354,7 +143,6 @@ if (!empty($edited_file)) { $template->assign('restore_infos', true); } - } $template->assign(array( diff --git a/plugins/LocalFilesEditor/include/css.inc.php b/plugins/LocalFilesEditor/include/css.inc.php new file mode 100644 index 000000000..42c6b6920 --- /dev/null +++ b/plugins/LocalFilesEditor/include/css.inc.php @@ -0,0 +1,45 @@ +assign('css_lang_tpl', array( + 'OPTIONS' => $options, + 'SELECTED' => $selected + ) +); + +$codemirror_mode = 'text/css'; + +?> \ No newline at end of file diff --git a/plugins/LocalFilesEditor/functions.inc.php b/plugins/LocalFilesEditor/include/functions.inc.php similarity index 100% rename from plugins/LocalFilesEditor/functions.inc.php rename to plugins/LocalFilesEditor/include/functions.inc.php diff --git a/plugins/LocalFilesEditor/include/lang.inc.php b/plugins/LocalFilesEditor/include/lang.inc.php new file mode 100644 index 000000000..fe5a4f85c --- /dev/null +++ b/plugins/LocalFilesEditor/include/lang.inc.php @@ -0,0 +1,53 @@ +"; + } +} + +$selected = 0; +$options[] = l10n('locfiledit_choose_file'); +$options[] = '----------------------'; +foreach (get_languages() as $language_code => $language_name) +{ + $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'language/'.$language_code.'.lang.php'; + if ($edited_file == $value) + { + $selected = $value; + $template->assign('show_default', array( + array( + 'URL' => LOCALEDIT_PATH.'show_default.php?file=language/'.$language_code.'/common.lang.php', + 'FILE' => 'common.lang.php' + ), + array( + 'URL' => LOCALEDIT_PATH.'show_default.php?file=language/'.$language_code.'/admin.lang.php', + 'FILE' => 'admin.lang.php' + ) + ) + ); + } + $options[$value] = $language_name; +} + +$template->assign('css_lang_tpl', array( + 'OPTIONS' => $options, + 'SELECTED' => $selected + ) + ); + +$codemirror_mode = 'application/x-httpd-php'; + +?> \ No newline at end of file diff --git a/plugins/LocalFilesEditor/include/localconf.inc.php b/plugins/LocalFilesEditor/include/localconf.inc.php new file mode 100644 index 000000000..b801db236 --- /dev/null +++ b/plugins/LocalFilesEditor/include/localconf.inc.php @@ -0,0 +1,26 @@ +"; +} + +$template->assign('show_default', array( + array( + 'URL' => LOCALEDIT_PATH.'show_default.php?file=include/config_default.inc.php', + 'FILE' => 'config_default.inc.php' + ) + ) +); + +$codemirror_mode = 'application/x-httpd-php'; + +?> \ No newline at end of file diff --git a/plugins/LocalFilesEditor/include/plug.inc.php b/plugins/LocalFilesEditor/include/plug.inc.php new file mode 100644 index 000000000..55c4b2dde --- /dev/null +++ b/plugins/LocalFilesEditor/include/plug.inc.php @@ -0,0 +1,25 @@ +"; +} + +$codemirror_mode = 'application/x-httpd-php'; + +?> \ No newline at end of file diff --git a/plugins/LocalFilesEditor/include/tpl.inc.php b/plugins/LocalFilesEditor/include/tpl.inc.php new file mode 100644 index 000000000..aea29ed9d --- /dev/null +++ b/plugins/LocalFilesEditor/include/tpl.inc.php @@ -0,0 +1,140 @@ + 'template-extension'); + $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension')); + + $options['model'][] = l10n('locfiledit_empty_page'); + $options['model'][] = '----------------------'; + $i = 0; + foreach (get_extents() as $pwg_template) + { + $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template; + $options['model'][$value] = 'template-extension / ' . str_replace('/', ' / ', $pwg_template); + $i++; + } + foreach (get_dirs($conf['themes_dir']) as $theme_id) + { + if ($i) + { + $options['model'][] = '----------------------'; + $i = 0; + } + $dir = $conf['themes_dir'] . '/' . $theme_id . '/template/'; + if (is_dir($dir) and $content = opendir($dir)) + { + while ($node = readdir($content)) + { + if (is_file($dir.$node) and get_extension($node) == 'tpl') + { + $value = $dir . $node; + $options['model'][$value] = $theme_id . ' / ' . $node; + $i++; + } + } + } + } + if (end($options['model']) == '----------------------') + { + array_pop($options['model']); + } + // Assign variables to template + $template->assign('create_tpl', array( + 'NEW_FILE_NAME' => $filename, + 'MODEL_OPTIONS' => $options['model'], + 'MODEL_SELECTED' => $selected['model'], + 'PARENT_OPTIONS' => $options['parent'], + 'PARENT_SELECTED' => $selected['parent'] + ) + ); +} +else +{ + // List existing template extensions + $selected = 0; + $options[] = l10n('locfiledit_choose_file'); + $options[] = '----------------------'; + foreach (get_extents() as $pwg_template) + { + $value = './template-extension/' . $pwg_template; + $options[$value] = str_replace('/', ' / ', $pwg_template); + if ($edited_file == $value) $selected = $value; + } + if ($selected == 0 and !empty($edited_file)) + { + $options[$edited_file] = str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file); + $selected = $edited_file; + } + $template->assign('css_lang_tpl', array( + 'OPTIONS' => $options, + 'SELECTED' => $selected, + 'NEW_FILE_URL' => $my_base_url.'-tpl&newfile', + 'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right' + ) + ); +} + +$codemirror_mode = 'text/html'; + +?> \ No newline at end of file diff --git a/plugins/LocalFilesEditor/show_default.php b/plugins/LocalFilesEditor/show_default.php index 14e2ad70d..c3ec7fa1a 100644 --- a/plugins/LocalFilesEditor/show_default.php +++ b/plugins/LocalFilesEditor/show_default.php @@ -24,7 +24,7 @@ define('PHPWG_ROOT_PATH', '../../'); define('IN_ADMIN', true); include_once(PHPWG_ROOT_PATH . 'include/common.inc.php'); -include_once(LOCALEDIT_PATH.'functions.inc.php'); +include_once(LOCALEDIT_PATH.'include/functions.inc.php'); load_language('plugin.lang', LOCALEDIT_PATH); check_status(ACCESS_ADMINISTRATOR); @@ -36,7 +36,7 @@ if (isset($_GET['file'])) die('Hacking attempt!'); } - $template->set_filename('show_default', dirname(__FILE__) . '/show_default.tpl'); + $template->set_filename('show_default', dirname(__FILE__) . '/template/show_default.tpl'); $file = file_get_contents(PHPWG_ROOT_PATH . $path); $title = str_replace('/', ' / ', $path); @@ -44,8 +44,6 @@ if (isset($_GET['file'])) $template->assign(array( 'TITLE' => $title, 'DEFAULT_CONTENT' => $file, - 'LOCALEDIT_PATH' => LOCALEDIT_PATH, - 'CODEMIRROR_MODE' => 'application/x-httpd-php' ) ); diff --git a/plugins/LocalFilesEditor/admin.tpl b/plugins/LocalFilesEditor/template/admin.tpl similarity index 88% rename from plugins/LocalFilesEditor/admin.tpl rename to plugins/LocalFilesEditor/template/admin.tpl index d59df2f27..1761951d2 100644 --- a/plugins/LocalFilesEditor/admin.tpl +++ b/plugins/LocalFilesEditor/template/admin.tpl @@ -11,7 +11,7 @@ {combine_css path="plugins/LocalFilesEditor/codemirror/mode/javascript/javascript.css"} {combine_css path="plugins/LocalFilesEditor/codemirror/mode/css/css.css"} {combine_css path="plugins/LocalFilesEditor/codemirror/mode/clike/clike.css"} -{combine_css path="plugins/LocalFilesEditor/locfiledit.css"} +{combine_css path="plugins/LocalFilesEditor/template/locfiledit.css"} {footer_script} if (document.getElementById("text") != null) @@ -62,26 +62,27 @@ if (document.getElementById("text") != null) {/if} {/if} -
{* top bar buttons *} +{if isset ($zone_edit)} +
+{/if} + {if !empty($show_default)} {foreach from=$show_default item=file name=default_loop} - -{'locfiledit_show_default'|@translate} "{$file.FILE}" + +{'locfiledit_show_default'|@translate} "{$file.FILE}" {if !($smarty.foreach.default_loop.last)}
{/if} {/foreach} {/if} {if isset ($zone_edit)} -{$zone_edit.FILE_NAME} - -
{* top bar buttons *} +{$zone_edit.FILE_NAME} +
{* title_bar *} -
- + {if isset ($restore)} {/if} @@ -91,6 +92,6 @@ if (document.getElementById("text") != null) {'locfiledit_save_bak'|@translate} {/if} -{/if} +{/if} {* zone_edit *} diff --git a/plugins/LocalFilesEditor/locfiledit.css b/plugins/LocalFilesEditor/template/locfiledit.css similarity index 50% rename from plugins/LocalFilesEditor/locfiledit.css rename to plugins/LocalFilesEditor/template/locfiledit.css index bb59ec40c..10589bcec 100644 --- a/plugins/LocalFilesEditor/locfiledit.css +++ b/plugins/LocalFilesEditor/template/locfiledit.css @@ -3,32 +3,30 @@ margin: 0 2em; } -#LocalFilesEditor .top_right { +#LocalFilesEditor #title_bar { + overflow: auto; +} + +#LocalFilesEditor .file_name { + font-weight: bold; + float: left; +} + +#LocalFilesEditor .default_file { float: right; - margin-right: 1%; -} - -#LocalFilesEditor B { - float: left; -} - -#LocalFilesEditor TEXTAREA { - margin: 0.5em 0; - width: 99%; - height: 500px; - float: left; } #LocalFilesEditor TD { padding: 0.5em; } -.CodeMirror { +#LocalFilesEditor TEXTAREA, .CodeMirror { background-color: #EEEEEE; - font-size: 1.3em; + font-family: monospace,Arial,sans-serif; + font-size: 1.2em; border: 1px solid #999999; margin: 0.5em 0; - width: 99%; + width: 100%; min-height: 500px; height: auto; -} +} \ No newline at end of file diff --git a/plugins/LocalFilesEditor/show_default.tpl b/plugins/LocalFilesEditor/template/show_default.tpl similarity index 80% rename from plugins/LocalFilesEditor/show_default.tpl rename to plugins/LocalFilesEditor/template/show_default.tpl index ef6970d41..cd6c3f318 100644 --- a/plugins/LocalFilesEditor/show_default.tpl +++ b/plugins/LocalFilesEditor/template/show_default.tpl @@ -1,8 +1,3 @@ -{html_head} - -{/html_head} -{combine_script id="jquery"} - {combine_script id="codemirror" path="plugins/LocalFilesEditor/codemirror/lib/codemirror.js"} {combine_script id="codemirror.xml" require="codemirror" path="plugins/LocalFilesEditor/codemirror/mode/xml/xml.js"} {combine_script id="codemirror.javascript" require="codemirror" path="plugins/LocalFilesEditor/codemirror/mode/javascript/javascript.js"} @@ -16,20 +11,27 @@ {combine_css path="plugins/LocalFilesEditor/codemirror/mode/javascript/javascript.css"} {combine_css path="plugins/LocalFilesEditor/codemirror/mode/css/css.css"} {combine_css path="plugins/LocalFilesEditor/codemirror/mode/clike/clike.css"} -{combine_css path="plugins/LocalFilesEditor/locfiledit.css"} +{combine_css path="plugins/LocalFilesEditor/template/locfiledit.css"} {footer_script} var editor = CodeMirror.fromTextArea(document.getElementById("text"), {ldelim} - matchBrackets: true, readOnly: true, - mode: "{$CODEMIRROR_MODE}", - tabMode: "shift" + mode: "application/x-httpd-php" }); {/footer_script} -
-
{$TITLE}
+{html_head} + +{/html_head} - +
+ +
+ {$TITLE} +
+ +