1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | if (!isset($edited_page)) |
---|
6 | { |
---|
7 | $edited_page = array(); |
---|
8 | $edited_page['id'] = 0; |
---|
9 | $edited_page['homepage'] = false; |
---|
10 | $page_title = l10n('ap_create'); |
---|
11 | } |
---|
12 | |
---|
13 | // Enregistrement |
---|
14 | if (isset($_POST['save'])) |
---|
15 | { |
---|
16 | if (empty($_POST['title'])) |
---|
17 | { |
---|
18 | array_push($page['errors'], l10n('ap_no_name')); |
---|
19 | } |
---|
20 | if (!empty($_POST['permalink'])) |
---|
21 | { |
---|
22 | $permalink = $_POST['permalink']; |
---|
23 | $sanitized_permalink = preg_replace( '#[^a-zA-Z0-9_/-]#', '' ,$permalink); |
---|
24 | $sanitized_permalink = trim($sanitized_permalink, '/'); |
---|
25 | $sanitized_permalink = str_replace('//', '/', $sanitized_permalink); |
---|
26 | if ( $sanitized_permalink != $permalink or preg_match( '#^(\d)+(-.*)?$#', $permalink) ) |
---|
27 | { |
---|
28 | array_push($page['errors'], l10n('The permalink name must be composed of a-z, A-Z, 0-9, "-", "_" or "/". It must not be numeric or start with number followed by "-"')); |
---|
29 | } |
---|
30 | $query =' |
---|
31 | SELECT id FROM '.ADD_PAGES_TABLE.' |
---|
32 | WHERE permalink = "'.$permalink.'" |
---|
33 | AND id <> '.$edited_page['id'].' |
---|
34 | ;'; |
---|
35 | $ids = array_from_query($query, 'id'); |
---|
36 | if (!empty($ids)) |
---|
37 | { |
---|
38 | array_push($page['errors'], sprintf(l10n('ap_permalink_already_used'), $permalink, $ids[0])); |
---|
39 | } |
---|
40 | $permalink = '"'.$permalink.'"'; |
---|
41 | } |
---|
42 | else |
---|
43 | { |
---|
44 | $permalink = 'NULL'; |
---|
45 | } |
---|
46 | |
---|
47 | $language = $_POST['lang'] != 'ALL' ? '"'.$_POST['lang'].'"' : 'NULL'; |
---|
48 | $group_access = !empty($_POST['groups']) ? '"'.implode(',', $_POST['groups']).'"' : 'NULL'; |
---|
49 | $user_access = !empty($_POST['users']) ? '"'.implode(',', $_POST['users']).'"' : 'NULL'; |
---|
50 | $standalone = isset($_POST['standalone']) ? '"true"' : '"false"'; |
---|
51 | |
---|
52 | if (empty($page['errors'])) |
---|
53 | { |
---|
54 | if ($page['tab'] == 'edit_page') |
---|
55 | { |
---|
56 | $query = ' |
---|
57 | UPDATE '.ADD_PAGES_TABLE.' |
---|
58 | SET lang = '.$language.', |
---|
59 | title = "'.$_POST['title'].'", |
---|
60 | content = "'.$_POST['ap_content'].'", |
---|
61 | users = '.$user_access.', |
---|
62 | groups = '.$group_access.', |
---|
63 | permalink = '.$permalink.', |
---|
64 | standalone = '.$standalone.' |
---|
65 | WHERE id = '.$edited_page['id'] .' |
---|
66 | ;'; |
---|
67 | pwg_query($query); |
---|
68 | } |
---|
69 | else |
---|
70 | { |
---|
71 | $query = 'SELECT MAX(ABS(pos)) AS pos FROM ' . ADD_PAGES_TABLE . ';'; |
---|
72 | list($position) = array_from_query($query, 'pos'); |
---|
73 | |
---|
74 | $query = ' |
---|
75 | INSERT INTO ' . ADD_PAGES_TABLE . ' ( pos , lang , title , content , users , groups , permalink, standalone) |
---|
76 | VALUES ('.($position+1).' , '.$language.' , "'.$_POST['title'].'" , "'.$_POST['ap_content'].'" , '.$user_access.' , '.$group_access.' , '.$permalink.' , '.$standalone.');'; |
---|
77 | pwg_query($query); |
---|
78 | $edited_page['id'] = mysql_insert_id(); |
---|
79 | } |
---|
80 | |
---|
81 | // Homepage |
---|
82 | if (isset($_POST['homepage']) xor $conf['additional_pages']['homepage'] == $edited_page['id']) |
---|
83 | { |
---|
84 | $conf['additional_pages']['homepage'] = isset($_POST['homepage']) ? $edited_page['id'] : null; |
---|
85 | conf_update_param('additional_pages', pwg_db_real_escape_string(serialize($conf['additional_pages']))); |
---|
86 | } |
---|
87 | |
---|
88 | // Enregistrement du fichier de sauvegarde |
---|
89 | mkgetdir($conf['local_data_dir'], MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); |
---|
90 | mkgetdir($conf['local_data_dir'].'/additional_pages_backup', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); |
---|
91 | $sav_file = @fopen($conf['local_data_dir'].'/additional_pages_backup/' . $edited_page['id'] . '.txt', "w"); |
---|
92 | @fwrite($sav_file, "Title: ".$_POST['title']." |
---|
93 | Permalink: ".$_POST['permalink']." |
---|
94 | Language: ".$_POST['lang']." |
---|
95 | |
---|
96 | " . $_POST['ap_content']); |
---|
97 | @fclose($sav_file); |
---|
98 | |
---|
99 | if (isset($_GET['redirect'])) |
---|
100 | { |
---|
101 | redirect(make_index_url() . '/page/' . $edited_page['id']); |
---|
102 | } |
---|
103 | redirect($my_base_url.'&page_saved='); |
---|
104 | } |
---|
105 | |
---|
106 | $edited_page['title'] = stripslashes($_POST['title']); |
---|
107 | $edited_page['permalink'] = $_POST['permalink']; |
---|
108 | $edited_page['content'] = stripslashes($_POST['ap_content']); |
---|
109 | $edited_page['groups'] = !empty($_POST['groups']) ? trim($group_access, '"') : ''; |
---|
110 | $edited_page['users'] = !empty($_POST['users']) ? trim($user_access, '"') : ''; |
---|
111 | $edited_page['homepage'] = isset($_POST['homepage']); |
---|
112 | $edited_page['standalone'] = isset($_POST['standalone']); |
---|
113 | } |
---|
114 | |
---|
115 | // Selection des langues |
---|
116 | $options['ALL'] = l10n('ap_all_lang'); |
---|
117 | $selected = 'ALL'; |
---|
118 | foreach (get_languages() as $language_code => $language_name) |
---|
119 | { |
---|
120 | $options[$language_code] = $language_name; |
---|
121 | if (isset($edited_page['lang']) and $edited_page['lang'] == $language_code) |
---|
122 | { |
---|
123 | $selected = $language_code; |
---|
124 | } |
---|
125 | } |
---|
126 | $template->assign('lang', array( |
---|
127 | 'OPTIONS' => $options, |
---|
128 | 'SELECTED' => $selected)); |
---|
129 | |
---|
130 | // Selection des groupes |
---|
131 | if ($conf['additional_pages']['group_perm']) |
---|
132 | { |
---|
133 | include_once(AP_PATH . 'admin/functions_groups.php'); |
---|
134 | $groups = !empty($edited_page['groups']) ? explode(',', $edited_page['groups']) : array(); |
---|
135 | $template->assign('GROUPSELECTION', get_html_groups_selection(get_all_groups(), 'groups', $groups)); |
---|
136 | } |
---|
137 | |
---|
138 | // Selection des utilisateurs |
---|
139 | if ($conf['additional_pages']['user_perm']) |
---|
140 | { |
---|
141 | if (isset($_GET['edit'])) |
---|
142 | $selected_users = isset($edited_page['users']) ? explode(',', $edited_page['users']) : array(); |
---|
143 | else |
---|
144 | $selected_users = array('guest', 'generic', 'normal'); |
---|
145 | |
---|
146 | $template->assign('user_perm', array( |
---|
147 | 'GUEST' => (in_array('guest', $selected_users) ? 'checked="checked"' : ''), |
---|
148 | 'GENERIC' => (in_array('generic', $selected_users) ? 'checked="checked"' : ''), |
---|
149 | 'NORMAL' => (in_array('normal', $selected_users) ? 'checked="checked"' : ''))); |
---|
150 | } |
---|
151 | |
---|
152 | // Chargement des données pour l'édition |
---|
153 | if ($page['tab'] == 'edit_page') |
---|
154 | { |
---|
155 | $template->assign(array( |
---|
156 | 'NAME' => $edited_page['title'], |
---|
157 | 'PERMALINK' => $edited_page['permalink'], |
---|
158 | 'HOMEPAGE' => $edited_page['homepage'], |
---|
159 | 'STANDALONE' => $edited_page['standalone'], |
---|
160 | 'CONTENT' => $edited_page['content'])); |
---|
161 | } |
---|
162 | |
---|
163 | // Parametrage du template |
---|
164 | $template->assign('AP_TITLE', $page_title); |
---|
165 | |
---|
166 | $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/add_page.tpl'); |
---|
167 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
168 | |
---|
169 | ?> |
---|