From d2da26e467aec1347ae7c314c4c8279cb4618c34 Mon Sep 17 00:00:00 2001 From: patdenice Date: Wed, 13 Apr 2011 10:36:53 +0000 Subject: Clean code git-svn-id: http://piwigo.org/svn/trunk@10348 68402e56-0260-453c-a942-63ccdbb3a9ee --- plugins/LocalFilesEditor/include/css.inc.php | 45 +++++++ plugins/LocalFilesEditor/include/functions.inc.php | 114 +++++++++++++++++ plugins/LocalFilesEditor/include/lang.inc.php | 53 ++++++++ plugins/LocalFilesEditor/include/localconf.inc.php | 26 ++++ plugins/LocalFilesEditor/include/plug.inc.php | 25 ++++ plugins/LocalFilesEditor/include/tpl.inc.php | 140 +++++++++++++++++++++ 6 files changed, 403 insertions(+) create mode 100644 plugins/LocalFilesEditor/include/css.inc.php create mode 100644 plugins/LocalFilesEditor/include/functions.inc.php 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 (limited to 'plugins/LocalFilesEditor/include') 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/include/functions.inc.php b/plugins/LocalFilesEditor/include/functions.inc.php new file mode 100644 index 000000000..b85887852 --- /dev/null +++ b/plugins/LocalFilesEditor/include/functions.inc.php @@ -0,0 +1,114 @@ +'), '', $code); + if (function_exists('token_get_all')) + { + $b = 0; + foreach (token_get_all($code) as $token) + { + if ('{' == $token) ++$b; + else if ('}' == $token) --$b; + } + if ($b) return false; + else + { + ob_start(); + $eval = eval('if(0){' . $code . '}'); + ob_end_clean(); + if ($eval === false) return false; + } + } + return ''; +} + +/** + * returns true or false if $str is bool + * returns $str if $str is integer + * else "$str" + * + * @param string + */ +function editarea_quote($value) +{ + switch (gettype($value)) + { + case "boolean": + return $value ? 'true' : 'false'; + case "integer": + return $value; + default: + return '"'.$value.'"'; + } +} + +/** + * returns bak file for restore + * @param string + */ +function get_bak_file($file) +{ + if (get_extension($file) == 'php') + { + return substr_replace($file, '.bak', strrpos($file , '.'), 0); + } + else + { + return $file . '.bak'; + } +} + +/** + * returns dirs and subdirs + * retun array + * @param string + */ +function get_rec_dirs($path='') +{ + $options = array(); + if (is_dir($path)) + { + $fh = opendir($path); + while ($file = readdir($fh)) + { + $pathfile = $path . '/' . $file; + if ($file != '.' and $file != '..' and $file != '.svn' and is_dir($pathfile)) + { + $options[$pathfile] = str_replace(array('./', '/'), array('', ' / '), $pathfile); + $options = array_merge($options, get_rec_dirs($pathfile)); + } + } + closedir($fh); + } + return $options; +} + +?> \ No newline at end of file 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 -- cgit v1.2.3