1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
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 | |
---|
13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('usage,contentadmin'); |
---|
16 | |
---|
17 | $post_id = ''; |
---|
18 | $post_dt = ''; |
---|
19 | $post_format = $core->auth->getOption('post_format'); |
---|
20 | $post_password = ''; |
---|
21 | $post_url = ''; |
---|
22 | $post_lang = $core->auth->getInfo('user_lang'); |
---|
23 | $post_title = ''; |
---|
24 | $post_excerpt = ''; |
---|
25 | $post_excerpt_xhtml = ''; |
---|
26 | $post_content = ''; |
---|
27 | $post_content_xhtml = ''; |
---|
28 | $post_notes = ''; |
---|
29 | $post_status = $core->auth->getInfo('user_post_status'); |
---|
30 | $post_selected = false; |
---|
31 | |
---|
32 | $page_title = __('New entry'); |
---|
33 | |
---|
34 | $can_view_page = true; |
---|
35 | $can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id); |
---|
36 | $can_publish = $core->auth->check('publish,contentadmin',$core->blog->id); |
---|
37 | $can_delete = false; |
---|
38 | |
---|
39 | $post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />'; |
---|
40 | $post_link = '<a href="post.php?id=%s" title="%s">%s</a>'; |
---|
41 | |
---|
42 | $next_link = $prev_link = $next_headlink = $prev_headlink = null; |
---|
43 | |
---|
44 | # If user can't publish |
---|
45 | if (!$can_publish) { |
---|
46 | $post_status = -2; |
---|
47 | } |
---|
48 | |
---|
49 | # Status combo |
---|
50 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
---|
51 | $status_combo[$v] = (string) $k; |
---|
52 | } |
---|
53 | |
---|
54 | # Formaters combo |
---|
55 | foreach ($core->getFormaters() as $v) { |
---|
56 | $formaters_combo[$v] = $v; |
---|
57 | } |
---|
58 | |
---|
59 | # Languages combo |
---|
60 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
61 | $all_langs = l10n::getISOcodes(0,1); |
---|
62 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
63 | while ($rs->fetch()) { |
---|
64 | if (isset($all_langs[$rs->post_lang])) { |
---|
65 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
66 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
67 | } else { |
---|
68 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
69 | } |
---|
70 | } |
---|
71 | unset($all_langs); |
---|
72 | unset($rs); |
---|
73 | |
---|
74 | |
---|
75 | # Get entry informations |
---|
76 | if (!empty($_REQUEST['id'])) |
---|
77 | { |
---|
78 | $params['post_id'] = $_REQUEST['id']; |
---|
79 | |
---|
80 | $post = $core->blog->getPosts($params); |
---|
81 | |
---|
82 | if ($post->isEmpty()) |
---|
83 | { |
---|
84 | $core->error->add(__('This entry does not exist.')); |
---|
85 | $can_view_page = false; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | $post_id = $post->post_id; |
---|
90 | $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); |
---|
91 | $post_format = $post->post_format; |
---|
92 | $post_password = $post->post_password; |
---|
93 | $post_url = $post->post_url; |
---|
94 | $post_lang = $post->post_lang; |
---|
95 | $post_title = $post->post_title; |
---|
96 | $post_excerpt = $post->post_excerpt; |
---|
97 | $post_excerpt_xhtml = $post->post_excerpt_xhtml; |
---|
98 | $post_content = $post->post_content; |
---|
99 | $post_content_xhtml = $post->post_content_xhtml; |
---|
100 | $post_notes = $post->post_notes; |
---|
101 | $post_status = $post->post_status; |
---|
102 | $post_selected = (boolean) $post->post_selected; |
---|
103 | |
---|
104 | $page_title = __('Edit entry'); |
---|
105 | |
---|
106 | $can_edit_post = $post->isEditable(); |
---|
107 | $can_delete= $post->isDeletable(); |
---|
108 | |
---|
109 | $next_rs = $core->blog->getNextPost($post,1); |
---|
110 | $prev_rs = $core->blog->getNextPost($post,-1); |
---|
111 | |
---|
112 | if ($next_rs !== null) { |
---|
113 | $next_link = sprintf($post_link,$next_rs->post_id, |
---|
114 | html::escapeHTML($next_rs->post_title),__('next entry').' »'); |
---|
115 | $next_headlink = sprintf($post_headlink,'next', |
---|
116 | html::escapeHTML($next_rs->post_title),$next_rs->post_id); |
---|
117 | } |
---|
118 | |
---|
119 | if ($prev_rs !== null) { |
---|
120 | $prev_link = sprintf($post_link,$prev_rs->post_id, |
---|
121 | html::escapeHTML($prev_rs->post_title),'« '.__('previous entry')); |
---|
122 | $prev_headlink = sprintf($post_headlink,'previous', |
---|
123 | html::escapeHTML($prev_rs->post_title),$prev_rs->post_id); |
---|
124 | } |
---|
125 | |
---|
126 | try { |
---|
127 | $core->media = new dcMedia($core); |
---|
128 | } catch (Exception $e) {} |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | # Format excerpt and content |
---|
133 | if (!empty($_POST) && $can_edit_post) |
---|
134 | { |
---|
135 | $post_format = $_POST['post_format']; |
---|
136 | $post_excerpt = $_POST['post_excerpt']; |
---|
137 | $post_content = $_POST['post_content']; |
---|
138 | |
---|
139 | $post_title = $_POST['post_title']; |
---|
140 | |
---|
141 | if (isset($_POST['post_status'])) { |
---|
142 | $post_status = (integer) $_POST['post_status']; |
---|
143 | } |
---|
144 | |
---|
145 | if (empty($_POST['post_dt'])) { |
---|
146 | $post_dt = ''; |
---|
147 | } else { |
---|
148 | $post_dt = strtotime($_POST['post_dt']); |
---|
149 | $post_dt = date('Y-m-d H:i',$post_dt); |
---|
150 | } |
---|
151 | |
---|
152 | $post_selected = !empty($_POST['post_selected']); |
---|
153 | $post_lang = $_POST['post_lang']; |
---|
154 | $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; |
---|
155 | |
---|
156 | $post_notes = $_POST['post_notes']; |
---|
157 | |
---|
158 | if (isset($_POST['post_url'])) { |
---|
159 | $post_url = $_POST['post_url']; |
---|
160 | } |
---|
161 | |
---|
162 | $core->blog->setPostContent( |
---|
163 | $post_id,$post_format,$post_lang, |
---|
164 | $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml |
---|
165 | ); |
---|
166 | } |
---|
167 | |
---|
168 | # Create or update post |
---|
169 | if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post) |
---|
170 | { |
---|
171 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
172 | |
---|
173 | $cur->post_title = $post_title; |
---|
174 | $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; |
---|
175 | $cur->post_format = $post_format; |
---|
176 | $cur->post_password = $post_password; |
---|
177 | $cur->post_lang = $post_lang; |
---|
178 | $cur->post_title = $post_title; |
---|
179 | $cur->post_excerpt = $post_excerpt; |
---|
180 | $cur->post_excerpt_xhtml = $post_excerpt_xhtml; |
---|
181 | $cur->post_content = $post_content; |
---|
182 | $cur->post_content_xhtml = $post_content_xhtml; |
---|
183 | $cur->post_notes = $post_notes; |
---|
184 | $cur->post_status = $post_status; |
---|
185 | $cur->post_selected = (integer) $post_selected; |
---|
186 | |
---|
187 | if (isset($_POST['post_url'])) { |
---|
188 | $cur->post_url = $post_url; |
---|
189 | } |
---|
190 | |
---|
191 | # Update post |
---|
192 | if ($post_id) |
---|
193 | { |
---|
194 | try |
---|
195 | { |
---|
196 | # --BEHAVIOR-- adminBeforePostUpdate |
---|
197 | $core->callBehavior('adminBeforePostUpdate',$cur,$post_id); |
---|
198 | |
---|
199 | $core->blog->updPost($post_id,$cur); |
---|
200 | |
---|
201 | # --BEHAVIOR-- adminAfterPostUpdate |
---|
202 | $core->callBehavior('adminAfterPostUpdate',$cur,$post_id); |
---|
203 | |
---|
204 | http::redirect('post.php?id='.$post_id.'&upd=1'); |
---|
205 | } |
---|
206 | catch (Exception $e) |
---|
207 | { |
---|
208 | $core->error->add($e->getMessage()); |
---|
209 | } |
---|
210 | } |
---|
211 | else |
---|
212 | { |
---|
213 | $cur->user_id = $core->auth->userID(); |
---|
214 | |
---|
215 | try |
---|
216 | { |
---|
217 | # --BEHAVIOR-- adminBeforePostCreate |
---|
218 | $core->callBehavior('adminBeforePostCreate',$cur); |
---|
219 | |
---|
220 | $return_id = $core->blog->addPost($cur); |
---|
221 | |
---|
222 | # --BEHAVIOR-- adminAfterPostCreate |
---|
223 | $core->callBehavior('adminAfterPostCreate',$cur,$return_id); |
---|
224 | |
---|
225 | http::redirect('post.php?id='.$return_id.'&crea=1'); |
---|
226 | } |
---|
227 | catch (Exception $e) |
---|
228 | { |
---|
229 | $core->error->add($e->getMessage()); |
---|
230 | } |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | if (!empty($_POST['delete']) && $can_delete) |
---|
235 | { |
---|
236 | try { |
---|
237 | # --BEHAVIOR-- adminBeforePostDelete |
---|
238 | $core->callBehavior('adminBeforePostDelete',$post_id); |
---|
239 | $core->blog->delPost($post_id); |
---|
240 | http::redirect('posts.php'); |
---|
241 | } catch (Exception $e) { |
---|
242 | $core->error->add($e->getMessage()); |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | /* DISPLAY |
---|
247 | -------------------------------------------------------- */ |
---|
248 | $default_tab = 'edit-entry'; |
---|
249 | if (!$can_edit_post) { |
---|
250 | $default_tab = ''; |
---|
251 | } |
---|
252 | |
---|
253 | dcPage::open($page_title.' - '.__('Entries'), |
---|
254 | dcPage::jsDatePicker(). |
---|
255 | dcPage::jsToolBar(). |
---|
256 | dcPage::jsModal(). |
---|
257 | dcPage::jsMetaEditor(). |
---|
258 | dcPage::jsLoad('js/_post.js'). |
---|
259 | dcPage::jsConfirmClose('entry-form'). |
---|
260 | # --BEHAVIOR-- adminPostHeaders |
---|
261 | $core->callBehavior('adminPostHeaders'). |
---|
262 | dcPage::jsPageTabs($default_tab). |
---|
263 | $next_headlink."\n".$prev_headlink |
---|
264 | ); |
---|
265 | |
---|
266 | if (!empty($_GET['upd'])) { |
---|
267 | echo '<p class="message">'.__('Entry has been successfully updated.').'</p>'; |
---|
268 | } |
---|
269 | elseif (!empty($_GET['crea'])) { |
---|
270 | echo '<p class="message">'.__('Entry has been successfully created.').'</p>'; |
---|
271 | } |
---|
272 | elseif (!empty($_GET['attached'])) { |
---|
273 | echo '<p class="message">'.__('File has been successfully attached.').'</p>'; |
---|
274 | } |
---|
275 | elseif (!empty($_GET['rmattach'])) { |
---|
276 | echo '<p class="message">'.__('Attachment has been successfully removed.').'</p>'; |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | # XHTML conversion |
---|
281 | if (!empty($_GET['xconv'])) |
---|
282 | { |
---|
283 | $post_excerpt = $post_excerpt_xhtml; |
---|
284 | $post_content = $post_content_xhtml; |
---|
285 | $post_title = $post_title_xhtml; |
---|
286 | $post_format = 'xhtml'; |
---|
287 | |
---|
288 | echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your post.').'</p>'; |
---|
289 | } |
---|
290 | |
---|
291 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.'<a href="posts.php">'.__('Entries').'</a> › <span class="page-title">'.$page_title; |
---|
292 | |
---|
293 | if ($post_id) { |
---|
294 | echo ' “'.$post_title.'”'; |
---|
295 | } |
---|
296 | echo '</span></h2>'; |
---|
297 | |
---|
298 | if ($post_id && $post->post_status == 1) { |
---|
299 | echo '<p><a href="'.$post->getURL().'" onclick="window.open(this.href);return false;" title="'.$post_title.' ('.__('new window').')'.'">'.__('Go to this entry on the site').' <img src="images/outgoing-blue.png" alt="" /></a></p>'; |
---|
300 | } |
---|
301 | if ($post_id) |
---|
302 | { |
---|
303 | echo '<p>'; |
---|
304 | if ($prev_link) { echo $prev_link; } |
---|
305 | if ($next_link && $prev_link) { echo ' - '; } |
---|
306 | if ($next_link) { echo $next_link; } |
---|
307 | |
---|
308 | # --BEHAVIOR-- adminPostNavLinks |
---|
309 | $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null); |
---|
310 | |
---|
311 | echo '</p>'; |
---|
312 | } |
---|
313 | |
---|
314 | # Exit if we cannot view page |
---|
315 | if (!$can_view_page) { |
---|
316 | dcPage::helpBlock('core_post'); |
---|
317 | dcPage::close(); |
---|
318 | exit; |
---|
319 | } |
---|
320 | |
---|
321 | /* Post form if we can edit post |
---|
322 | -------------------------------------------------------- */ |
---|
323 | if ($can_edit_post) |
---|
324 | { |
---|
325 | echo '<div class="multi-part" title="'.__('Edit entry').'" id="edit-entry">'; |
---|
326 | echo '<form action="post.php" method="post" id="entry-form">'; |
---|
327 | echo '<div id="entry-wrapper">'; |
---|
328 | echo '<div id="entry-content"><div class="constrained">'; |
---|
329 | |
---|
330 | echo |
---|
331 | '<p class="col"><label class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:'). |
---|
332 | form::field('post_title',20,255,html::escapeHTML($post_title),'maximal'). |
---|
333 | '</label></p>'. |
---|
334 | |
---|
335 | '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '. |
---|
336 | form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)). |
---|
337 | '</p>'. |
---|
338 | |
---|
339 | '<p class="area"><label class="required" '. |
---|
340 | 'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. |
---|
341 | form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)). |
---|
342 | '</p>'. |
---|
343 | |
---|
344 | '<p class="area" id="notes-area"><label for="post_notes">'.__('Notes:').'</label>'. |
---|
345 | form::textarea('post_notes',50,5,html::escapeHTML($post_notes)). |
---|
346 | '</p>'; |
---|
347 | |
---|
348 | # --BEHAVIOR-- adminPostForm |
---|
349 | $core->callBehavior('adminPostForm',isset($post) ? $post : null); |
---|
350 | |
---|
351 | echo |
---|
352 | '<p>'. |
---|
353 | ($post_id ? form::hidden('id',$post_id) : ''). |
---|
354 | '<input type="submit" value="'.__('Save').' (s)" '. |
---|
355 | 'accesskey="s" name="save" /> '; |
---|
356 | if ($post_id) { |
---|
357 | $preview_url = |
---|
358 | $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. |
---|
359 | http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). |
---|
360 | '/'.$post->post_url); |
---|
361 | echo '<a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview').'</a> '; |
---|
362 | } |
---|
363 | echo |
---|
364 | ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : ''). |
---|
365 | $core->formNonce(). |
---|
366 | '</p>'; |
---|
367 | |
---|
368 | echo '</div></div>'; // End #entry-content |
---|
369 | echo '</div>'; // End #entry-wrapper |
---|
370 | |
---|
371 | echo '<div id="entry-sidebar">'; |
---|
372 | |
---|
373 | echo |
---|
374 | '<p><label for="post_status">'.__('Entry status:'). |
---|
375 | form::combo('post_status',$status_combo,$post_status,'','',!$can_publish). |
---|
376 | '</label></p>'. |
---|
377 | |
---|
378 | '<p><label for="post_dt">'.__('Published on:'). |
---|
379 | form::field('post_dt',16,16,$post_dt). |
---|
380 | '</label></p>'. |
---|
381 | |
---|
382 | '<p><label for="post_format">'.__('Text formating:'). |
---|
383 | form::combo('post_format',$formaters_combo,$post_format). |
---|
384 | '</label>'. |
---|
385 | '</p>'. |
---|
386 | '<p>'.($post_id && $post_format != 'xhtml' ? '<a id="convert-xhtml" class="button" href="post.php?id='.$post_id.'&xconv=1">'.__('Convert to XHTML').'</a>' : '').'</p>'. |
---|
387 | |
---|
388 | '<p><label for="post_selected" class="classic">'.form::checkbox('post_selected',1,$post_selected).' '. |
---|
389 | __('Selected entry').'</label></p>'. |
---|
390 | |
---|
391 | '<p><label for="post_lang">'.__('Entry lang:'). |
---|
392 | form::combo('post_lang',$lang_combo,$post_lang). |
---|
393 | '</label></p>'. |
---|
394 | |
---|
395 | '<p><label for="post_password">'.__('Entry password:'). |
---|
396 | form::field('post_password',10,32,html::escapeHTML($post_password),'maximal'). |
---|
397 | '</label></p>'. |
---|
398 | |
---|
399 | '<div class="lockable">'. |
---|
400 | '<p><label for="post_url">'.__('Basename:'). |
---|
401 | form::field('post_url',10,255,html::escapeHTML($post_url),'maximal'). |
---|
402 | '</label></p>'. |
---|
403 | '<p class="form-note warn">'. |
---|
404 | __('Warning: If you set the URL manually, it may conflict with another entry.'). |
---|
405 | '</p>'. |
---|
406 | '</div>'; |
---|
407 | |
---|
408 | # --BEHAVIOR-- adminPostFormSidebar |
---|
409 | $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); |
---|
410 | |
---|
411 | echo '</div>'; // End #entry-sidebar |
---|
412 | |
---|
413 | echo '</form>'; |
---|
414 | |
---|
415 | # --BEHAVIOR-- adminPostForm |
---|
416 | $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null); |
---|
417 | |
---|
418 | echo '</div>'; |
---|
419 | |
---|
420 | } |
---|
421 | |
---|
422 | dcPage::helpBlock('core_post','core_wiki'); |
---|
423 | dcPage::close(); |
---|
424 | ?> |
---|