[3609] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[9261] | 4 | |
---|
[9264] | 5 | if (!isset($edited_page)) |
---|
| 6 | { |
---|
| 7 | $page_title = l10n('ap_create'); |
---|
[9314] | 8 | |
---|
[9310] | 9 | $edited_page = array( |
---|
| 10 | 'id' => 0, |
---|
| 11 | 'title' => '', |
---|
| 12 | 'permalink' => '', |
---|
[9350] | 13 | 'lang' => 'ALL', |
---|
[9310] | 14 | 'homepage' => false, |
---|
| 15 | 'standalone' => false, |
---|
[9546] | 16 | 'level' => 0, |
---|
[9310] | 17 | 'users' => array('guest', 'generic', 'normal', 'admin', 'webmaster'), |
---|
| 18 | 'groups' => array(), |
---|
| 19 | 'content' => '', |
---|
| 20 | ); |
---|
[9264] | 21 | } |
---|
[3609] | 22 | |
---|
[16118] | 23 | // load template |
---|
| 24 | if (isset($_GET['load_template'])) |
---|
| 25 | { |
---|
| 26 | if (file_exists(AP_DISTRIBUED . $_GET['load_template'])) |
---|
| 27 | { |
---|
| 28 | $distribued = load_ap_template($_GET['load_template'], true); |
---|
| 29 | } |
---|
| 30 | else |
---|
| 31 | { |
---|
| 32 | $distribued = trigger_event('load_ap_template', array(), $_GET['load_template']); |
---|
| 33 | } |
---|
| 34 | $edited_page = array_merge($edited_page, $distribued); |
---|
| 35 | $template->assign('template_selected', $_GET['load_template']); |
---|
| 36 | } |
---|
| 37 | |
---|
[9312] | 38 | // Submit form |
---|
[9264] | 39 | if (isset($_POST['save'])) |
---|
| 40 | { |
---|
| 41 | if (empty($_POST['title'])) |
---|
| 42 | { |
---|
| 43 | array_push($page['errors'], l10n('ap_no_name')); |
---|
| 44 | } |
---|
| 45 | if (!empty($_POST['permalink'])) |
---|
| 46 | { |
---|
[9275] | 47 | $permalink = trim($_POST['permalink'], ' /'); |
---|
| 48 | $permalink = str_replace(array(' ', '/'), '_',$permalink); |
---|
| 49 | |
---|
[9264] | 50 | $query =' |
---|
| 51 | SELECT id FROM '.ADD_PAGES_TABLE.' |
---|
| 52 | WHERE permalink = "'.$permalink.'" |
---|
| 53 | AND id <> '.$edited_page['id'].' |
---|
| 54 | ;'; |
---|
| 55 | $ids = array_from_query($query, 'id'); |
---|
| 56 | if (!empty($ids)) |
---|
| 57 | { |
---|
[9273] | 58 | array_push($page['errors'], sprintf(l10n('ap_permalink_already_used'), $permalink, $ids[0])); |
---|
[9264] | 59 | } |
---|
| 60 | $permalink = '"'.$permalink.'"'; |
---|
| 61 | } |
---|
| 62 | else |
---|
| 63 | { |
---|
| 64 | $permalink = 'NULL'; |
---|
| 65 | } |
---|
[3609] | 66 | |
---|
[9350] | 67 | $language = (empty($_POST['lang']) or $_POST['lang'] == 'ALL') ? 'NULL' : '"'.$_POST['lang'].'"'; |
---|
[9264] | 68 | $group_access = !empty($_POST['groups']) ? '"'.implode(',', $_POST['groups']).'"' : 'NULL'; |
---|
[9270] | 69 | $standalone = isset($_POST['standalone']) ? '"true"' : '"false"'; |
---|
[9264] | 70 | |
---|
[9275] | 71 | $user_access = 'NULL'; |
---|
[9323] | 72 | if ($conf['AP']['user_perm']) |
---|
[9275] | 73 | { |
---|
[9310] | 74 | $user_access = !empty($_POST['users']) ? '"'.implode(',', $_POST['users']).'"' : '""'; |
---|
[9275] | 75 | } |
---|
| 76 | |
---|
[9546] | 77 | $level_access = !empty($_POST['level']) ? $_POST['level'] : 0; |
---|
[9313] | 78 | |
---|
[9264] | 79 | if (empty($page['errors'])) |
---|
| 80 | { |
---|
| 81 | if ($page['tab'] == 'edit_page') |
---|
| 82 | { |
---|
| 83 | $query = ' |
---|
| 84 | UPDATE '.ADD_PAGES_TABLE.' |
---|
| 85 | SET lang = '.$language.', |
---|
| 86 | title = "'.$_POST['title'].'", |
---|
| 87 | content = "'.$_POST['ap_content'].'", |
---|
| 88 | users = '.$user_access.', |
---|
| 89 | groups = '.$group_access.', |
---|
[9313] | 90 | level = '.$level_access.', |
---|
[9270] | 91 | permalink = '.$permalink.', |
---|
| 92 | standalone = '.$standalone.' |
---|
[9264] | 93 | WHERE id = '.$edited_page['id'] .' |
---|
| 94 | ;'; |
---|
| 95 | pwg_query($query); |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | $query = 'SELECT MAX(ABS(pos)) AS pos FROM ' . ADD_PAGES_TABLE . ';'; |
---|
| 100 | list($position) = array_from_query($query, 'pos'); |
---|
[9310] | 101 | |
---|
[9264] | 102 | $query = ' |
---|
[9310] | 103 | INSERT INTO '.ADD_PAGES_TABLE.' ( pos , lang , title , content , users , groups , level , permalink, standalone) |
---|
| 104 | VALUES ( |
---|
| 105 | '.($position+1).', |
---|
| 106 | '.$language.', |
---|
| 107 | "'.$_POST['title'].'", |
---|
| 108 | "'.$_POST['ap_content'].'", |
---|
| 109 | '.$user_access.', |
---|
| 110 | '.$group_access.', |
---|
[9313] | 111 | '.$level_access.', |
---|
[9310] | 112 | '.$permalink.', |
---|
| 113 | '.$standalone.' |
---|
| 114 | );'; |
---|
[9264] | 115 | pwg_query($query); |
---|
[9314] | 116 | $edited_page['id'] = pwg_db_insert_id(ADD_PAGES_TABLE, 'id'); |
---|
[9264] | 117 | } |
---|
| 118 | |
---|
| 119 | // Homepage |
---|
[9323] | 120 | if (isset($_POST['homepage']) xor $conf['AP']['homepage'] == $edited_page['id']) |
---|
[9264] | 121 | { |
---|
[9323] | 122 | $conf['AP']['homepage'] = isset($_POST['homepage']) ? $edited_page['id'] : null; |
---|
| 123 | conf_update_param('additional_pages', pwg_db_real_escape_string(serialize($conf['AP']))); |
---|
[9264] | 124 | } |
---|
| 125 | |
---|
[9312] | 126 | // Backup file |
---|
[19429] | 127 | mkgetdir($conf['data_location'], MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); |
---|
| 128 | mkgetdir($conf['data_location'].'/additional_pages_backup', MKGETDIR_PROTECT_HTACCESS&~MKGETDIR_DIE_ON_ERROR); |
---|
| 129 | $sav_file = @fopen($conf['data_location'].'/additional_pages_backup/' . $edited_page['id'] . '.txt', "w"); |
---|
[9350] | 130 | @fwrite($sav_file, "Title: ".stripslashes($_POST['title'])."\nPermalink: ".stripslashes($_POST['permalink'])."\n\n".stripslashes($_POST['ap_content'])); |
---|
[9264] | 131 | @fclose($sav_file); |
---|
| 132 | |
---|
[9312] | 133 | // Redirect to admin pannel or additional page |
---|
[9264] | 134 | if (isset($_GET['redirect'])) |
---|
| 135 | { |
---|
[9660] | 136 | redirect(make_index_url(array('section'=>'page')).'/'.$edited_page['id']); |
---|
[9264] | 137 | } |
---|
| 138 | redirect($my_base_url.'&page_saved='); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | $edited_page['title'] = stripslashes($_POST['title']); |
---|
[9310] | 142 | $edited_page['permalink'] = stripslashes($_POST['permalink']); |
---|
[9264] | 143 | $edited_page['content'] = stripslashes($_POST['ap_content']); |
---|
[9350] | 144 | $edited_page['lang'] = !empty($_POST['lang']) ? $_POST['lang'] : 'ALL'; |
---|
[9310] | 145 | $edited_page['groups'] = !empty($_POST['groups']) ? $_POST['groups'] : array(); |
---|
| 146 | $edited_page['users'] = !empty($_POST['users']) ? $_POST['users'] : array(); |
---|
[9546] | 147 | $edited_page['level'] = !empty($_POST['level']) ? $_POST['level'] : 0; |
---|
[9264] | 148 | $edited_page['homepage'] = isset($_POST['homepage']); |
---|
[9270] | 149 | $edited_page['standalone'] = isset($_POST['standalone']); |
---|
[9264] | 150 | } |
---|
| 151 | |
---|
[9312] | 152 | // Language options |
---|
[9350] | 153 | if ($conf['AP']['language_perm']) |
---|
[9264] | 154 | { |
---|
[9350] | 155 | $languages = get_languages(); |
---|
| 156 | $options = array('ALL' => l10n('ap_all_lang')); |
---|
| 157 | foreach ($languages as $language_code => $language_name) |
---|
[9264] | 158 | { |
---|
[9350] | 159 | $options[$language_code] = $language_name; |
---|
[9264] | 160 | } |
---|
[9350] | 161 | $template->assign(array( |
---|
| 162 | 'lang' => $options, |
---|
| 163 | 'selected_lang' => $edited_page['lang'], |
---|
| 164 | ) |
---|
| 165 | ); |
---|
[9264] | 166 | } |
---|
| 167 | |
---|
[9310] | 168 | // Groups options |
---|
[9323] | 169 | if ($conf['AP']['group_perm']) |
---|
[9264] | 170 | { |
---|
[9310] | 171 | $query = 'SELECT id, name FROM '.GROUPS_TABLE.' ORDER BY name ASC;'; |
---|
| 172 | $result = pwg_query($query); |
---|
| 173 | $groups = array(); |
---|
| 174 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 175 | { |
---|
| 176 | $groups[$row['id']] = $row['name']; |
---|
| 177 | } |
---|
| 178 | $template->assign(array( |
---|
| 179 | 'groups' => $groups, |
---|
| 180 | 'selected_groups' => $edited_page['groups'], |
---|
| 181 | ) |
---|
| 182 | ); |
---|
[9264] | 183 | } |
---|
| 184 | |
---|
[9310] | 185 | // Users options |
---|
[9323] | 186 | if ($conf['AP']['user_perm']) |
---|
[9264] | 187 | { |
---|
[9310] | 188 | $users_id = array('guest', 'generic', 'normal', 'admin', 'webmaster'); |
---|
| 189 | $users = array(); |
---|
| 190 | foreach ($users_id as $id) |
---|
[9275] | 191 | { |
---|
[9310] | 192 | $users[$id] = l10n('user_status_'.$id); |
---|
[9275] | 193 | } |
---|
[9310] | 194 | $template->assign(array( |
---|
| 195 | 'users' => $users, |
---|
| 196 | 'selected_users' => $edited_page['users'], |
---|
[9275] | 197 | ) |
---|
| 198 | ); |
---|
[9264] | 199 | } |
---|
| 200 | |
---|
[9310] | 201 | // User level options |
---|
[9323] | 202 | if ($conf['AP']['level_perm']) |
---|
[9264] | 203 | { |
---|
[9310] | 204 | foreach ($conf['available_permission_levels'] as $level) |
---|
| 205 | { |
---|
| 206 | $level_options[$level] = l10n(sprintf('Level %d', $level)); |
---|
| 207 | } |
---|
[9264] | 208 | $template->assign(array( |
---|
[9310] | 209 | 'level_perm' => $level_options, |
---|
| 210 | 'level_selected' => $edited_page['level'] |
---|
| 211 | ) |
---|
| 212 | ); |
---|
[9264] | 213 | } |
---|
| 214 | |
---|
[16118] | 215 | // Available templates |
---|
| 216 | if (!isset($_GET['edit'])) |
---|
| 217 | { |
---|
| 218 | $distribued = array(); |
---|
| 219 | $dh = opendir(AP_DISTRIBUED); |
---|
| 220 | if ($dh) |
---|
| 221 | { |
---|
| 222 | while (($dir = readdir($dh)) !== false) |
---|
| 223 | { |
---|
[16122] | 224 | if ( is_dir(AP_DISTRIBUED.$dir) and $dir!='.' and $dir!='..' and $dir!='.svn' ) |
---|
[16118] | 225 | { |
---|
| 226 | array_push($distribued, load_ap_template($dir, false)); |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | closedir($dh); |
---|
| 230 | } |
---|
| 231 | $distribued = trigger_event('load_ap_templates_list', $distribued); // external plugins can add templates |
---|
| 232 | $template->assign('TEMPLATES', $distribued); |
---|
| 233 | } |
---|
| 234 | |
---|
[9310] | 235 | // template output |
---|
| 236 | $template->assign(array( |
---|
| 237 | 'AP_TITLE' => $page_title, |
---|
[9323] | 238 | 'NAME' => htmlspecialchars($edited_page['title']), |
---|
| 239 | 'PERMALINK' => htmlspecialchars($edited_page['permalink']), |
---|
[9310] | 240 | 'HOMEPAGE' => $edited_page['homepage'], |
---|
| 241 | 'STANDALONE' => $edited_page['standalone'], |
---|
[9323] | 242 | 'CONTENT' => htmlspecialchars($edited_page['content']) |
---|
| 243 | ) |
---|
| 244 | ); |
---|
[9264] | 245 | |
---|
| 246 | $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/add_page.tpl'); |
---|
| 247 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 248 | |
---|
[16118] | 249 | |
---|
| 250 | function load_ap_template($dir, $with_content=true) |
---|
| 251 | { |
---|
| 252 | $path = AP_DISTRIBUED . $dir . '/'; |
---|
| 253 | |
---|
| 254 | // default template |
---|
| 255 | $template_conf = array( |
---|
| 256 | 'name' => $dir, |
---|
| 257 | 'title' => '', |
---|
| 258 | 'permalink' => '', |
---|
| 259 | 'lang' => 'ALL', |
---|
| 260 | 'homepage' => false, |
---|
| 261 | 'standalone' => false, |
---|
| 262 | 'level' => 0, |
---|
| 263 | 'users' => array('guest', 'generic', 'normal', 'admin', 'webmaster'), |
---|
| 264 | 'groups' => array(), |
---|
| 265 | 'content' => '', |
---|
| 266 | ); |
---|
| 267 | |
---|
| 268 | // load config |
---|
| 269 | if (file_exists($path.'config.php')) |
---|
| 270 | { |
---|
| 271 | include($path.'config.php'); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | // load content |
---|
| 275 | if ( $with_content and file_exists($path.'content.tpl') ) |
---|
| 276 | { |
---|
| 277 | $template_conf['content'] = file_get_contents($path.'content.tpl'); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | $template_conf['tpl_id'] = $dir; |
---|
| 281 | return $template_conf; |
---|
| 282 | } |
---|
| 283 | |
---|
[3292] | 284 | ?> |
---|