[10348] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
[20714] | 4 | $edited_file = ''; |
---|
[10348] | 5 | |
---|
[20714] | 6 | if (isset($_POST['edit'])) |
---|
[10348] | 7 | { |
---|
[20714] | 8 | $_POST['template'] = $_POST['file_to_edit']; |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | if (!empty($_POST['template'])) |
---|
| 12 | { |
---|
| 13 | if (preg_match('#\.\./#', $_POST['template'])) |
---|
[10348] | 14 | { |
---|
[20714] | 15 | die('Hacking attempt! template extension must be in template-extension directory'); |
---|
[10348] | 16 | } |
---|
[20714] | 17 | |
---|
| 18 | if (!preg_match('#\.tpl$#', $_POST['template'])) |
---|
[10348] | 19 | { |
---|
[20714] | 20 | die('Hacking attempt! template extension must be a *.tpl file'); |
---|
[10348] | 21 | } |
---|
[20714] | 22 | |
---|
| 23 | $template->assign('template', $_POST['template']); |
---|
| 24 | |
---|
| 25 | $edited_file = './template-extension/'.$_POST['template']; |
---|
[10348] | 26 | } |
---|
| 27 | |
---|
[20714] | 28 | $content_file = ''; |
---|
| 29 | if (file_exists($edited_file)) |
---|
| 30 | { |
---|
| 31 | $content_file = file_get_contents($edited_file); |
---|
| 32 | } |
---|
| 33 | |
---|
[10348] | 34 | $newfile_page = isset($_GET['newfile']); |
---|
| 35 | |
---|
| 36 | // Edit new tpl file |
---|
| 37 | if (isset($_POST['create_tpl'])) |
---|
| 38 | { |
---|
| 39 | $filename = $_POST['tpl_name']; |
---|
| 40 | if (empty($filename)) |
---|
| 41 | { |
---|
| 42 | array_push($page['errors'], l10n('locfiledit_empty_filename')); |
---|
| 43 | } |
---|
| 44 | if (get_extension($filename) != 'tpl') |
---|
| 45 | { |
---|
| 46 | $filename .= '.tpl'; |
---|
| 47 | } |
---|
| 48 | if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) |
---|
| 49 | { |
---|
| 50 | array_push($page['errors'], l10n('locfiledit_filename_error')); |
---|
| 51 | } |
---|
| 52 | if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0') |
---|
| 53 | { |
---|
| 54 | array_push($page['errors'], l10n('locfiledit_model_error')); |
---|
| 55 | } |
---|
| 56 | if (file_exists($_POST['tpl_parent'] . '/' . $filename)) |
---|
| 57 | { |
---|
| 58 | array_push($page['errors'], l10n('locfiledit_file_already_exists')); |
---|
| 59 | } |
---|
| 60 | if (!empty($page['errors'])) |
---|
| 61 | { |
---|
| 62 | $newfile_page = true; |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
[20714] | 66 | $template->assign('template', $filename); |
---|
[10348] | 67 | $edited_file = $_POST['tpl_parent'] . '/' . $filename; |
---|
[11654] | 68 | $content_file = ($_POST['tpl_model'] == '0') ? '' : file_get_contents($_POST['tpl_model']); |
---|
[10348] | 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if ($newfile_page) |
---|
| 73 | { |
---|
| 74 | $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : ''; |
---|
| 75 | $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0'; |
---|
| 76 | $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension'; |
---|
| 77 | |
---|
| 78 | // Parent directories list |
---|
| 79 | $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension'); |
---|
| 80 | $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension')); |
---|
| 81 | |
---|
| 82 | $options['model'][] = l10n('locfiledit_empty_page'); |
---|
| 83 | $options['model'][] = '----------------------'; |
---|
| 84 | $i = 0; |
---|
| 85 | foreach (get_extents() as $pwg_template) |
---|
| 86 | { |
---|
| 87 | $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template; |
---|
| 88 | $options['model'][$value] = 'template-extension / ' . str_replace('/', ' / ', $pwg_template); |
---|
| 89 | $i++; |
---|
| 90 | } |
---|
| 91 | foreach (get_dirs($conf['themes_dir']) as $theme_id) |
---|
| 92 | { |
---|
| 93 | if ($i) |
---|
| 94 | { |
---|
| 95 | $options['model'][] = '----------------------'; |
---|
| 96 | $i = 0; |
---|
| 97 | } |
---|
| 98 | $dir = $conf['themes_dir'] . '/' . $theme_id . '/template/'; |
---|
| 99 | if (is_dir($dir) and $content = opendir($dir)) |
---|
| 100 | { |
---|
| 101 | while ($node = readdir($content)) |
---|
| 102 | { |
---|
| 103 | if (is_file($dir.$node) and get_extension($node) == 'tpl') |
---|
| 104 | { |
---|
| 105 | $value = $dir . $node; |
---|
| 106 | $options['model'][$value] = $theme_id . ' / ' . $node; |
---|
| 107 | $i++; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | if (end($options['model']) == '----------------------') |
---|
| 113 | { |
---|
| 114 | array_pop($options['model']); |
---|
| 115 | } |
---|
| 116 | // Assign variables to template |
---|
| 117 | $template->assign('create_tpl', array( |
---|
| 118 | 'NEW_FILE_NAME' => $filename, |
---|
| 119 | 'MODEL_OPTIONS' => $options['model'], |
---|
| 120 | 'MODEL_SELECTED' => $selected['model'], |
---|
| 121 | 'PARENT_OPTIONS' => $options['parent'], |
---|
| 122 | 'PARENT_SELECTED' => $selected['parent'] |
---|
| 123 | ) |
---|
| 124 | ); |
---|
| 125 | } |
---|
| 126 | else |
---|
| 127 | { |
---|
| 128 | // List existing template extensions |
---|
| 129 | $selected = 0; |
---|
| 130 | $options[] = l10n('locfiledit_choose_file'); |
---|
| 131 | $options[] = '----------------------'; |
---|
| 132 | foreach (get_extents() as $pwg_template) |
---|
| 133 | { |
---|
[20714] | 134 | $value = $pwg_template; |
---|
[10348] | 135 | $options[$value] = str_replace('/', ' / ', $pwg_template); |
---|
| 136 | if ($edited_file == $value) $selected = $value; |
---|
| 137 | } |
---|
| 138 | if ($selected == 0 and !empty($edited_file)) |
---|
| 139 | { |
---|
| 140 | $options[$edited_file] = str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file); |
---|
| 141 | $selected = $edited_file; |
---|
| 142 | } |
---|
[20714] | 143 | $template->assign( |
---|
| 144 | 'css_lang_tpl', |
---|
| 145 | array( |
---|
| 146 | 'SELECT_NAME' => 'file_to_edit', |
---|
| 147 | 'OPTIONS' => $options, |
---|
| 148 | 'SELECTED' => $selected, |
---|
| 149 | 'NEW_FILE_URL' => $my_base_url.'-tpl&newfile', |
---|
| 150 | 'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right' |
---|
| 151 | ) |
---|
| 152 | ); |
---|
[10348] | 153 | } |
---|
| 154 | |
---|
| 155 | $codemirror_mode = 'text/html'; |
---|
| 156 | |
---|
| 157 | ?> |
---|