1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2009 Olivier Meunier and contributors |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
13 | dcPage::check('pages,contentadmin'); |
---|
14 | |
---|
15 | $default_page = $core->getPostAdminURL('page',$_REQUEST['id']); |
---|
16 | |
---|
17 | $redir_url = $p_url.'&type=page'; |
---|
18 | |
---|
19 | $post_id = ''; |
---|
20 | $post_dt = ''; |
---|
21 | $post_format = $core->auth->getOption('post_format'); |
---|
22 | $post_password = ''; |
---|
23 | $post_url = ''; |
---|
24 | $post_lang = $core->auth->getInfo('user_lang'); |
---|
25 | $post_title = ''; |
---|
26 | $post_excerpt = ''; |
---|
27 | $post_excerpt_xhtml = ''; |
---|
28 | $post_content = ''; |
---|
29 | $post_content_xhtml = ''; |
---|
30 | $post_status = $core->auth->getInfo('user_post_status'); |
---|
31 | $post_position = 0; |
---|
32 | $post_open_comment = false; |
---|
33 | $post_open_tb = false; |
---|
34 | |
---|
35 | $post_media = array(); |
---|
36 | |
---|
37 | $page_title = __('New page'); |
---|
38 | |
---|
39 | $can_view_page = true; |
---|
40 | $can_edit_page = $core->auth->check('page,usage',$core->blog->id); |
---|
41 | $can_publish = $core->auth->check('page,publish,contentadmin',$core->blog->id); |
---|
42 | $can_delete = false; |
---|
43 | |
---|
44 | // link |
---|
45 | $tmp = $redir_url; |
---|
46 | |
---|
47 | $redir_url = 'plugin.php?p=page&p=pages'; |
---|
48 | |
---|
49 | $post_headlink = '<link rel="%s" title="%s" href="'.html::escapeURL($redir_url).'&id=%s" />'; |
---|
50 | $post_link = '<a href="'.html::escapeURL($redir_url).'&id=%s" title="%s">%s</a>'; |
---|
51 | |
---|
52 | $redir_url = $tmp; |
---|
53 | unset($tmp); |
---|
54 | |
---|
55 | $next_link = $prev_link = $next_headlink = $prev_headlink = null; |
---|
56 | |
---|
57 | # If user can't publish |
---|
58 | if (!$can_publish) { |
---|
59 | $post_status = -2; |
---|
60 | } |
---|
61 | |
---|
62 | # Get page informations |
---|
63 | if (!empty($_REQUEST['id'])) |
---|
64 | { |
---|
65 | $params['post_type'] = 'page'; |
---|
66 | $params['post_id'] = $_REQUEST['id']; |
---|
67 | |
---|
68 | $post = $core->blog->getPosts($params); |
---|
69 | |
---|
70 | if ($post->isEmpty()) |
---|
71 | { |
---|
72 | $core->error->add(__('This page does not exist.')); |
---|
73 | $can_view_page = false; |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | $post_id = $post->post_id; |
---|
78 | $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); |
---|
79 | $post_format = $post->post_format; |
---|
80 | |
---|
81 | # check post format |
---|
82 | if (($post_format != 'xhtml') && (empty($_GET['xconv']))) |
---|
83 | { |
---|
84 | $core->error->add(__('This entry format is not XHTML.').' '. |
---|
85 | __('You have to convert this entry to XHTML format to use TinyMCE, this operation cannot be undone.').' '. |
---|
86 | '<a href="'.$p_url.'&type=page&id='.$post_id.'&xconv=1" '. |
---|
87 | 'id="tinyMce-convert" class="button">'. |
---|
88 | __('Convert this post to XHTML format').'</a> '. |
---|
89 | '<a href="'.$default_page.'" class="button">'. |
---|
90 | __('Return to the default page').'</a> '); |
---|
91 | $can_view_page = false; |
---|
92 | } |
---|
93 | |
---|
94 | $post_password = $post->post_password; |
---|
95 | $post_url = $post->post_url; |
---|
96 | $post_lang = $post->post_lang; |
---|
97 | $post_title = $post->post_title; |
---|
98 | $post_excerpt = $post->post_excerpt; |
---|
99 | $post_excerpt_xhtml = $post->post_excerpt_xhtml; |
---|
100 | $post_content = $post->post_content; |
---|
101 | $post_content_xhtml = $post->post_content_xhtml; |
---|
102 | $post_status = $post->post_status; |
---|
103 | $post_position = (integer) $post->post_position; |
---|
104 | $post_open_comment = (boolean) $post->post_open_comment; |
---|
105 | $post_open_tb = (boolean) $post->post_open_tb; |
---|
106 | |
---|
107 | $page_title = __('Edit page'); |
---|
108 | |
---|
109 | $can_edit_page = $post->isEditable(); |
---|
110 | $can_delete= $post->isDeletable(); |
---|
111 | |
---|
112 | $next_rs = $core->blog->getNextPost($post,1); |
---|
113 | $prev_rs = $core->blog->getNextPost($post,-1); |
---|
114 | |
---|
115 | if ($next_rs !== null) { |
---|
116 | $next_link = sprintf($post_link,$next_rs->post_id, |
---|
117 | html::escapeHTML($next_rs->post_title),__('next page').' »'); |
---|
118 | $next_headlink = sprintf($post_headlink,'next', |
---|
119 | html::escapeHTML($next_rs->post_title),$next_rs->post_id); |
---|
120 | } |
---|
121 | |
---|
122 | if ($prev_rs !== null) { |
---|
123 | $prev_link = sprintf($post_link,$prev_rs->post_id, |
---|
124 | html::escapeHTML($prev_rs->post_title),'« '.__('previous page')); |
---|
125 | $prev_headlink = sprintf($post_headlink,'previous', |
---|
126 | html::escapeHTML($prev_rs->post_title),$prev_rs->post_id); |
---|
127 | } |
---|
128 | |
---|
129 | try { |
---|
130 | $core->media = new dcMedia($core); |
---|
131 | $post_media = $core->media->getPostMedia($post_id); |
---|
132 | } catch (Exception $e) {} |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | # Format content |
---|
137 | if (!empty($_POST) && $can_edit_page) |
---|
138 | { |
---|
139 | $post_format = $_POST['post_format']; |
---|
140 | $post_excerpt = $_POST['post_excerpt']; |
---|
141 | $post_content = $_POST['post_content']; |
---|
142 | |
---|
143 | $post_title = $_POST['post_title']; |
---|
144 | |
---|
145 | if (isset($_POST['post_status'])) { |
---|
146 | $post_status = (integer) $_POST['post_status']; |
---|
147 | } |
---|
148 | |
---|
149 | if (empty($_POST['post_dt'])) { |
---|
150 | $post_dt = ''; |
---|
151 | } else { |
---|
152 | $post_dt = strtotime($_POST['post_dt']); |
---|
153 | $post_dt = date('Y-m-d H:i',$post_dt); |
---|
154 | } |
---|
155 | |
---|
156 | $post_open_comment = !empty($_POST['post_open_comment']); |
---|
157 | $post_open_tb = !empty($_POST['post_open_tb']); |
---|
158 | $post_lang = $_POST['post_lang']; |
---|
159 | $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; |
---|
160 | $post_position = (integer) $_POST['post_position']; |
---|
161 | |
---|
162 | if (isset($_POST['post_url'])) { |
---|
163 | $post_url = $_POST['post_url']; |
---|
164 | } |
---|
165 | |
---|
166 | $core->blog->setPostContent( |
---|
167 | $post_id,$post_format,$post_lang, |
---|
168 | $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml |
---|
169 | ); |
---|
170 | } |
---|
171 | |
---|
172 | # Create or update post |
---|
173 | if (!empty($_POST) && !empty($_POST['save']) && $can_edit_page) |
---|
174 | { |
---|
175 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
176 | |
---|
177 | # Magic tweak :) |
---|
178 | $core->blog->settings->post_url_format = $page_url_format; |
---|
179 | |
---|
180 | $cur->post_type = 'page'; |
---|
181 | $cur->post_title = $post_title; |
---|
182 | $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; |
---|
183 | $cur->post_format = $post_format; |
---|
184 | $cur->post_password = $post_password; |
---|
185 | $cur->post_lang = $post_lang; |
---|
186 | $cur->post_title = $post_title; |
---|
187 | $cur->post_excerpt = $post_excerpt; |
---|
188 | $cur->post_excerpt_xhtml = $post_excerpt_xhtml; |
---|
189 | $cur->post_content = $post_content; |
---|
190 | $cur->post_content_xhtml = $post_content_xhtml; |
---|
191 | $cur->post_status = $post_status; |
---|
192 | $cur->post_position = $post_position; |
---|
193 | $cur->post_open_comment = (integer) $post_open_comment; |
---|
194 | $cur->post_open_tb = (integer) $post_open_tb; |
---|
195 | |
---|
196 | if (isset($_POST['post_url'])) { |
---|
197 | $cur->post_url = $post_url; |
---|
198 | } |
---|
199 | |
---|
200 | # Update post |
---|
201 | if ($post_id) |
---|
202 | { |
---|
203 | try |
---|
204 | { |
---|
205 | # --BEHAVIOR-- adminBeforePageUpdate |
---|
206 | //$core->callBehavior('adminBeforePageUpdate',$cur,$post_id); |
---|
207 | |
---|
208 | $core->blog->updPost($post_id,$cur); |
---|
209 | |
---|
210 | # --BEHAVIOR-- adminAfterPageUpdate |
---|
211 | //$core->callBehavior('adminAfterPageUpdate',$cur,$post_id); |
---|
212 | |
---|
213 | http::redirect($redir_url.'&id='.$post_id.'&upd=1'); |
---|
214 | } |
---|
215 | catch (Exception $e) |
---|
216 | { |
---|
217 | $core->error->add($e->getMessage()); |
---|
218 | } |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | dcPage::open($page_title.' - '.__('Pages'), |
---|
223 | dcPage::jsModal(). |
---|
224 | dcPage::jsConfirmClose('entry-form'). |
---|
225 | # --BEHAVIOR-- adminPostHeaders |
---|
226 | //$core->callBehavior('adminPostHeaders'). |
---|
227 | $next_headlink."\n".$prev_headlink. |
---|
228 | # TinyMCE Javascript |
---|
229 | '<script type="text/javascript" src="index.php?pf='. |
---|
230 | 'tinyMce/js/tiny_mce_jquery/jquery.tinymce.js">'. |
---|
231 | '</script>'. |
---|
232 | '<script type="text/javascript" src="index.php?pf='. |
---|
233 | 'tinyMce/js/init_jquery.js">'. |
---|
234 | '</script>' |
---|
235 | ); |
---|
236 | |
---|
237 | if (!empty($_GET['upd'])) { |
---|
238 | echo '<p class="message">'.__('Page has been successfully updated.').'</p>'; |
---|
239 | } |
---|
240 | |
---|
241 | # XHTML conversion |
---|
242 | if (!empty($_GET['xconv'])) |
---|
243 | { |
---|
244 | $post_excerpt = $post_excerpt_xhtml; |
---|
245 | $post_content = $post_content_xhtml; |
---|
246 | $post_format = 'xhtml'; |
---|
247 | |
---|
248 | echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your post.').'</p>'; |
---|
249 | } |
---|
250 | |
---|
251 | echo '<h2>'.html::escapeHTML($core->blog->name). |
---|
252 | ' › <a href="'.$p_url.'">'.__('Pages').'</a> › '.$page_title; |
---|
253 | |
---|
254 | if ($post_id && $post->post_status == 1) { |
---|
255 | echo ' - <a id="post-preview" href="'.$post->getURL().'" class="button">'.__('View page').'</a>'; |
---|
256 | } elseif ($post_id) { |
---|
257 | $preview_url = |
---|
258 | $core->blog->url.$core->url->getBase('pagespreview').'/'. |
---|
259 | $core->auth->userID().'/'. |
---|
260 | http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). |
---|
261 | '/'.$post->post_url; |
---|
262 | echo ' - <a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview page').'</a>'; |
---|
263 | } |
---|
264 | |
---|
265 | echo '</h2>'; |
---|
266 | |
---|
267 | if ($post_id) |
---|
268 | { |
---|
269 | echo '<p>'; |
---|
270 | if ($prev_link) { echo $prev_link; } |
---|
271 | if ($next_link && $prev_link) { echo ' - '; } |
---|
272 | if ($next_link) { echo $next_link; } |
---|
273 | |
---|
274 | # --BEHAVIOR-- adminPageNavLinks |
---|
275 | //$core->callBehavior('adminPageNavLinks',isset($post) ? $post : null); |
---|
276 | |
---|
277 | # link to default page |
---|
278 | echo('<p><a href="'.$default_page.'" class="button">'. |
---|
279 | __('Return to the default page').'</a></p>'); |
---|
280 | |
---|
281 | echo '</p>'; |
---|
282 | } |
---|
283 | |
---|
284 | # Exit if we cannot view page |
---|
285 | if (!$can_view_page) { |
---|
286 | echo '</body></html>'; |
---|
287 | return; |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | /* Post form if we can edit post |
---|
292 | -------------------------------------------------------- */ |
---|
293 | if ($can_edit_page) |
---|
294 | { |
---|
295 | echo '<div class="multi-part" title="'.__('Edit page').'" id="edit-entry">'; |
---|
296 | echo '<form action="'.html::escapeURL($redir_url).'" method="post" id="entry-form">'; |
---|
297 | echo form::hidden('p','tinyMce'); |
---|
298 | echo form::hidden('type','page'); |
---|
299 | |
---|
300 | echo( |
---|
301 | form::hidden('post_status',$post_status). |
---|
302 | form::hidden('post_dt',$post_dt). |
---|
303 | form::hidden('post_format',$post_format). |
---|
304 | |
---|
305 | form::hidden('post_open_comment',(integer) $post_open_comment). |
---|
306 | form::hidden('post_open_tb',(integer) $post_open_tb). |
---|
307 | form::hidden('post_lang',$post_lang). |
---|
308 | form::hidden('post_password',html::escapeHTML($post_password)). |
---|
309 | form::hidden('post_url',html::escapeHTML($post_url)). |
---|
310 | |
---|
311 | form::hidden('post_position',(string) $post_position) |
---|
312 | ); |
---|
313 | |
---|
314 | # --BEHAVIOR-- adminPageFormSidebar |
---|
315 | //$core->callBehavior('adminPageFormSidebar',isset($post) ? $post : null); |
---|
316 | |
---|
317 | echo '<div><fieldset class="constrained">'; |
---|
318 | |
---|
319 | echo |
---|
320 | '<p class="col"><label class="required" title="'.__('Required field').'">'.__('Title:'). |
---|
321 | form::field('post_title',20,255,html::escapeHTML($post_title),'maximal',2). |
---|
322 | '</label></p>'. |
---|
323 | |
---|
324 | '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '. |
---|
325 | form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt),'tinymce',2). |
---|
326 | '</p>'. |
---|
327 | |
---|
328 | '<p class="area"><label class="required" title="'.__('Required field').'" '. |
---|
329 | 'for="post_content">'.__('Content:').'</label> '. |
---|
330 | form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content),'tinymce',2). |
---|
331 | '</p>'; |
---|
332 | |
---|
333 | # --BEHAVIOR-- adminPageForm |
---|
334 | //$core->callBehavior('adminPageForm',isset($post) ? $post : null); |
---|
335 | |
---|
336 | echo |
---|
337 | '<p>'. |
---|
338 | ($post_id ? form::hidden('id',$post_id) : ''). |
---|
339 | '<input type="submit" value="'.__('save').' (s)" tabindex="4" '. |
---|
340 | 'accesskey="s" name="save" /> '. |
---|
341 | $core->formNonce(). |
---|
342 | '</p>'; |
---|
343 | |
---|
344 | echo '</fieldset></div>'; // End #entry-content |
---|
345 | echo '</form>'; |
---|
346 | echo '</div>'; |
---|
347 | } |
---|
348 | |
---|
349 | dcPage::close(); |
---|
350 | |
---|
351 | ?> |
---|