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