Dotclear

source: admin/post.php @ 537:334ae2e6917d

Revision 537:334ae2e6917d, 18.4 KB checked in by kozlika, 14 years ago (diff)

Accessibility/Ergonomy?: admin post page "breadcrumb" show entry title. Close #605.

Line 
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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::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$post_open_comment = $core->blog->settings->system->allow_comments;
33$post_open_tb = $core->blog->settings->system->allow_trackbacks;
34
35$page_title = __('New entry');
36
37$can_view_page = true;
38$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
39$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
40$can_delete = false;
41
42$post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />';
43$post_link = '<a href="post.php?id=%s" title="%s">%s</a>';
44
45$next_link = $prev_link = $next_headlink = $prev_headlink = null;
46
47# If user can't publish
48if (!$can_publish) {
49     $post_status = -2;
50}
51
52# Getting categories
53$categories_combo = array('&nbsp;' => '');
54try {
55     $categories = $core->blog->getCategories(array('post_type'=>'post'));
56     while ($categories->fetch()) {
57          $categories_combo[] = new formSelectOption(
58               str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title),
59               $categories->cat_id
60          );
61     }
62} catch (Exception $e) { }
63
64# Status combo
65foreach ($core->blog->getAllPostStatus() as $k => $v) {
66     $status_combo[$v] = (string) $k;
67}
68
69# Formaters combo
70foreach ($core->getFormaters() as $v) {
71     $formaters_combo[$v] = $v;
72}
73
74# Languages combo
75$rs = $core->blog->getLangs(array('order'=>'asc'));
76$all_langs = l10n::getISOcodes(0,1);
77$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
78while ($rs->fetch()) {
79     if (isset($all_langs[$rs->post_lang])) {
80          $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang;
81          unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]);
82     } else {
83          $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang;
84     }
85}
86unset($all_langs);
87unset($rs);
88
89
90# Get entry informations
91if (!empty($_REQUEST['id']))
92{
93     $params['post_id'] = $_REQUEST['id'];
94     
95     $post = $core->blog->getPosts($params);
96     
97     if ($post->isEmpty())
98     {
99          $core->error->add(__('This entry does not exist.'));
100          $can_view_page = false;
101     }
102     else
103     {
104          $post_id = $post->post_id;
105          $cat_id = $post->cat_id;
106          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
107          $post_format = $post->post_format;
108          $post_password = $post->post_password;
109          $post_url = $post->post_url;
110          $post_lang = $post->post_lang;
111          $post_title = $post->post_title;
112          $post_excerpt = $post->post_excerpt;
113          $post_excerpt_xhtml = $post->post_excerpt_xhtml;
114          $post_content = $post->post_content;
115          $post_content_xhtml = $post->post_content_xhtml;
116          $post_notes = $post->post_notes;
117          $post_status = $post->post_status;
118          $post_selected = (boolean) $post->post_selected;
119          $post_open_comment = (boolean) $post->post_open_comment;
120          $post_open_tb = (boolean) $post->post_open_tb;
121         
122          $page_title = __('Edit entry');
123         
124          $can_edit_post = $post->isEditable();
125          $can_delete= $post->isDeletable();
126         
127          $next_rs = $core->blog->getNextPost($post,1);
128          $prev_rs = $core->blog->getNextPost($post,-1);
129         
130          if ($next_rs !== null) {
131               $next_link = sprintf($post_link,$next_rs->post_id,
132                    html::escapeHTML($next_rs->post_title),__('next entry').'&nbsp;&#187;');
133               $next_headlink = sprintf($post_headlink,'next',
134                    html::escapeHTML($next_rs->post_title),$next_rs->post_id);
135          }
136         
137          if ($prev_rs !== null) {
138               $prev_link = sprintf($post_link,$prev_rs->post_id,
139                    html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('previous entry'));
140               $prev_headlink = sprintf($post_headlink,'previous',
141                    html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);
142          }
143         
144          try {
145               $core->media = new dcMedia($core);
146          } catch (Exception $e) {}
147     }
148}
149
150# Format excerpt and content
151if (!empty($_POST) && $can_edit_post)
152{
153     $post_format = $_POST['post_format'];
154     $post_excerpt = $_POST['post_excerpt'];
155     $post_content = $_POST['post_content'];
156     
157     $post_title = $_POST['post_title'];
158     
159     $cat_id = (integer) $_POST['cat_id'];
160     
161     if (isset($_POST['post_status'])) {
162          $post_status = (integer) $_POST['post_status'];
163     }
164     
165     if (empty($_POST['post_dt'])) {
166          $post_dt = '';
167     } else {
168          $post_dt = strtotime($_POST['post_dt']);
169          $post_dt = date('Y-m-d H:i',$post_dt);
170     }
171     
172     $post_open_comment = !empty($_POST['post_open_comment']);
173     $post_open_tb = !empty($_POST['post_open_tb']);
174     $post_selected = !empty($_POST['post_selected']);
175     $post_lang = $_POST['post_lang'];
176     $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null;
177     
178     $post_notes = $_POST['post_notes'];
179     
180     if (isset($_POST['post_url'])) {
181          $post_url = $_POST['post_url'];
182     }
183     
184     $core->blog->setPostContent(
185          $post_id,$post_format,$post_lang,
186          $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
187     );
188}
189
190# Create or update post
191if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post)
192{
193     $cur = $core->con->openCursor($core->prefix.'post');
194     
195     $cur->post_title = $post_title;
196     $cur->cat_id = ($cat_id ? $cat_id : null);
197     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : '';
198     $cur->post_format = $post_format;
199     $cur->post_password = $post_password;
200     $cur->post_lang = $post_lang;
201     $cur->post_title = $post_title;
202     $cur->post_excerpt = $post_excerpt;
203     $cur->post_excerpt_xhtml = $post_excerpt_xhtml;
204     $cur->post_content = $post_content;
205     $cur->post_content_xhtml = $post_content_xhtml;
206     $cur->post_notes = $post_notes;
207     $cur->post_status = $post_status;
208     $cur->post_selected = (integer) $post_selected;
209     $cur->post_open_comment = (integer) $post_open_comment;
210     $cur->post_open_tb = (integer) $post_open_tb;
211     
212     if (isset($_POST['post_url'])) {
213          $cur->post_url = $post_url;
214     }
215     
216     # Update post
217     if ($post_id)
218     {
219          try
220          {
221               # --BEHAVIOR-- adminBeforePostUpdate
222               $core->callBehavior('adminBeforePostUpdate',$cur,$post_id);
223               
224               $core->blog->updPost($post_id,$cur);
225               
226               # --BEHAVIOR-- adminAfterPostUpdate
227               $core->callBehavior('adminAfterPostUpdate',$cur,$post_id);
228               
229               http::redirect('post.php?id='.$post_id.'&upd=1');
230          }
231          catch (Exception $e)
232          {
233               $core->error->add($e->getMessage());
234          }
235     }
236     else
237     {
238          $cur->user_id = $core->auth->userID();
239         
240          try
241          {
242               # --BEHAVIOR-- adminBeforePostCreate
243               $core->callBehavior('adminBeforePostCreate',$cur);
244               
245               $return_id = $core->blog->addPost($cur);
246               
247               # --BEHAVIOR-- adminAfterPostCreate
248               $core->callBehavior('adminAfterPostCreate',$cur,$return_id);
249               
250               http::redirect('post.php?id='.$return_id.'&crea=1');
251          }
252          catch (Exception $e)
253          {
254               $core->error->add($e->getMessage());
255          }
256     }
257}
258
259if (!empty($_POST['delete']) && $can_delete)
260{
261     try {
262          # --BEHAVIOR-- adminBeforePostDelete
263          $core->callBehavior('adminBeforePostDelete',$post_id);
264          $core->blog->delPost($post_id);
265          http::redirect('posts.php');
266     } catch (Exception $e) {
267          $core->error->add($e->getMessage());
268     }
269}
270
271/* DISPLAY
272-------------------------------------------------------- */
273$default_tab = 'edit-entry';
274if (!$can_edit_post) {
275     $default_tab = '';
276}
277if (!empty($_GET['co'])) {
278     $default_tab = 'comments';
279}
280
281dcPage::open($page_title.' - '.__('Entries'),
282     dcPage::jsDatePicker().
283     dcPage::jsToolBar().
284     dcPage::jsModal().
285     dcPage::jsMetaEditor().
286     dcPage::jsLoad('js/_post.js').
287     dcPage::jsConfirmClose('entry-form','comment-form').
288     # --BEHAVIOR-- adminPostHeaders
289     $core->callBehavior('adminPostHeaders').
290     dcPage::jsPageTabs($default_tab).
291     $next_headlink."\n".$prev_headlink
292);
293
294if (!empty($_GET['upd'])) {
295          echo '<p class="message">'.__('Entry has been successfully updated.').'</p>';
296}
297elseif (!empty($_GET['crea'])) {
298          echo '<p class="message">'.__('Entry has been successfully created.').'</p>';
299}
300elseif (!empty($_GET['attached'])) {
301     echo '<p class="message">'.__('File has been successfully attached.').'</p>';
302}
303elseif (!empty($_GET['rmattach'])) {
304     echo '<p class="message">'.__('Attachment has been successfully removed.').'</p>';
305}
306
307if (!empty($_GET['creaco'])) {
308          echo '<p class="message">'.__('Comment has been successfully created.').'</p>';
309     }
310
311# XHTML conversion
312if (!empty($_GET['xconv']))
313{
314     $post_excerpt = $post_excerpt_xhtml;
315     $post_content = $post_content_xhtml;
316     $post_title = $post_title_xhtml;
317     $post_format = 'xhtml';
318     
319     echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your post.').'</p>';
320}
321
322echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.'<a href="posts.php">'.__('Entries').'</a> &rsaquo; <span class="page-title">'.$page_title.'  &ldquo;'.$post_title.'&rdquo;</span></h2>';
323
324if ($post_id && $post->post_status == 1) {
325     echo '<p><a id="post-preview" href="'.$post->getURL().'" class="button">'.__('View entry').'</a>';
326} elseif ($post_id) {
327     $preview_url =
328     $core->blog->url.$core->url->getBase('preview').'/'.
329     $core->auth->userID().'/'.
330     http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
331     '/'.$post->post_url;
332     echo '<p><a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview entry').'</a>';
333}
334
335echo '</p>';
336
337if ($post_id)
338{
339     echo '<p>';
340     if ($prev_link) { echo $prev_link; }
341     if ($next_link && $prev_link) { echo ' - '; }
342     if ($next_link) { echo $next_link; }
343     
344     # --BEHAVIOR-- adminPostNavLinks
345     $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null);
346     
347     echo '</p>';
348}
349
350# Exit if we cannot view page
351if (!$can_view_page) {
352     dcPage::helpBlock('core_post');
353     dcPage::close();
354     exit;
355}
356
357/* Post form if we can edit post
358-------------------------------------------------------- */
359if ($can_edit_post)
360{
361     echo '<div class="multi-part" title="'.__('Edit entry').'" id="edit-entry">';
362     echo '<form action="post.php" method="post" id="entry-form">';
363     echo '<div id="entry-wrapper">';
364     echo '<div id="entry-content"><div class="constrained">';
365     
366     echo
367     '<p class="col"><label class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').
368     form::field('post_title',20,255,html::escapeHTML($post_title),'maximal').
369     '</label></p>'.
370     
371     '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '.
372     form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)).
373     '</p>'.
374     
375     '<p class="area"><label class="required" '.
376     'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
377     form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)).
378     '</p>'.
379     
380     '<p class="area" id="notes-area"><label for="post_notes">'.__('Notes:').'</label>'.
381     form::textarea('post_notes',50,5,html::escapeHTML($post_notes)).
382     '</p>';
383     
384     # --BEHAVIOR-- adminPostForm
385     $core->callBehavior('adminPostForm',isset($post) ? $post : null);
386     
387     echo
388     '<p>'.
389     ($post_id ? form::hidden('id',$post_id) : '').
390     '<input type="submit" value="'.__('Save').' (s)" '.
391     'accesskey="s" name="save" /> '.
392     ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : '').
393     $core->formNonce().
394     '</p>';
395     
396     echo '</div></div>';          // End #entry-content
397     echo '</div>';      // End #entry-wrapper
398
399     echo '<div id="entry-sidebar">';
400     
401     echo
402     '<p><label for="cat_id">'.__('Category:').
403     form::combo('cat_id',$categories_combo,$cat_id,'maximal').
404     '</label></p>'.
405     
406     '<p><label for="post_status">'.__('Entry status:').
407     form::combo('post_status',$status_combo,$post_status,'','',!$can_publish).
408     '</label></p>'.
409     
410     '<p><label for="post_dt">'.__('Published on:').
411     form::field('post_dt',16,16,$post_dt).
412     '</label></p>'.
413     
414     '<p><label for="post_format">'.__('Text formating:').
415     form::combo('post_format',$formaters_combo,$post_format).
416     '</label>'.
417     '</p>'.
418     '<p>'.($post_id && $post_format != 'xhtml' ? '<a id="convert-xhtml" class="button" href="post.php?id='.$post_id.'&amp;xconv=1">'.__('Convert to XHTML').'</a>' : '').'</p>'.
419     
420     '<p><label for="post_open_comment" class="classic">'.form::checkbox('post_open_comment',1,$post_open_comment).' '.
421     __('Accept comments').'</label></p>'.
422     '<p><label for="post_open_tb" class="classic">'.form::checkbox('post_open_tb',1,$post_open_tb).' '.
423     __('Accept trackbacks').'</label></p>'.
424     '<p><label for="post_selected" class="classic">'.form::checkbox('post_selected',1,$post_selected).' '.
425     __('Selected entry').'</label></p>'.
426     
427     '<p><label for="post_lang">'.__('Entry lang:').
428     form::combo('post_lang',$lang_combo,$post_lang).
429     '</label></p>'.
430     
431     '<p><label for="post_password">'.__('Entry password:').
432     form::field('post_password',10,32,html::escapeHTML($post_password),'maximal').
433     '</label></p>'.
434     
435     '<div class="lockable">'.
436     '<p><label for="post_url">'.__('Basename:').
437     form::field('post_url',10,255,html::escapeHTML($post_url),'maximal').
438     '</label></p>'.
439     '<p class="form-note warn">'.
440     __('Warning: If you set the URL manually, it may conflict with another entry.').
441     '</p>'.
442     '</div>';
443     
444     # --BEHAVIOR-- adminPostFormSidebar
445     $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null);
446     
447     echo '</div>';      // End #entry-sidebar
448
449     echo '</form>';
450     
451     # --BEHAVIOR-- adminPostForm
452     $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null);
453     
454     echo '</div>';
455     
456     if ($post_id && $post->post_status == 1) {
457          echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'.
458          __('Ping blogs').'</a></p>';
459     }
460     
461}
462
463
464/* Comments and trackbacks
465-------------------------------------------------------- */
466if ($post_id)
467{
468     $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC');
469     
470     $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0)));
471     $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1)));
472     
473     # Actions combo box
474     $combo_action = array();
475     if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id))
476     {
477          $combo_action[__('publish')] = 'publish';
478          $combo_action[__('unpublish')] = 'unpublish';
479          $combo_action[__('mark as pending')] = 'pending';
480          $combo_action[__('mark as junk')] = 'junk';
481     }
482     
483     if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id))
484     {
485          $combo_action[__('delete')] = 'delete';
486     }
487     
488     # --BEHAVIOR-- adminCommentsActionsCombo
489     $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action));
490     
491     $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty());
492     
493     echo
494     '<div id="comments" class="multi-part" title="'.__('Comments').'">';
495     
496     if ($has_action) {
497          echo '<form action="comments_actions.php" id="form-comments" method="post">';
498     }
499     
500     echo '<h3>'.__('Trackbacks').'</h3>';
501     
502     if (!$trackbacks->isEmpty()) {
503          showComments($trackbacks,$has_action,true);
504     } else {
505          echo '<p>'.__('No trackback').'</p>';
506     }
507     
508     echo '<h3>'.__('Comments').'</h3>';
509     if (!$comments->isEmpty()) {
510          showComments($comments,$has_action);
511     } else {
512          echo '<p>'.__('No comment').'</p>';
513     }
514     
515     if ($has_action) {
516          echo
517          '<div class="two-cols">'.
518          '<p class="col checkboxes-helpers"></p>'.
519         
520          '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
521          form::combo('action',$combo_action).
522          form::hidden('redir','post.php?id='.$post_id.'&amp;co=1').
523          $core->formNonce().
524          '<input type="submit" value="'.__('ok').'" /></p>'.
525          '</div>'.
526          '</form>';
527     }
528     
529     echo '</div>';
530}
531
532/* Add a comment
533-------------------------------------------------------- */
534if ($post_id)
535{
536     echo
537     '<div class="multi-part" id="add-comment" title="'.__('Add a comment').'">'.
538     '<h3>'.__('Add a comment').'</h3>'.
539     
540     '<form action="comment.php" method="post" id="comment-form">'.
541     '<div class="constrained">'.
542     '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:').
543     form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))).
544     '</label></p>'.
545     
546     '<p><label for="comment_email">'.__('Email:').
547     form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))).
548     '</label></p>'.
549     
550     '<p><label for="comment_site">'.__('Web site:').
551     form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))).
552     '</label></p>'.
553     
554     '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '.
555     __('Comment:').'</label> '.
556     form::textarea('comment_content',50,8,html::escapeHTML('')).
557     '</p>'.
558     
559     '<p>'.form::hidden('post_id',$post_id).
560     $core->formNonce().
561     '<input type="submit" name="add" value="'.__('Save').'" /></p>'.
562     '</div>'.
563     '</form>'.
564     '</div>';
565}
566
567
568# Show comments or trackbacks
569function showComments($rs,$has_action,$tb=false)
570{
571     echo
572     '<table class="comments-list"><tr>'.
573     '<th colspan="2">'.__('Author').'</th>'.
574     '<th>'.__('Date').'</th>'.
575     '<th class="nowrap">'.__('IP address').'</th>'.
576     '<th>'.__('Status').'</th>'.
577     '<th>&nbsp;</th>'.
578     '</tr>';
579     
580     while($rs->fetch())
581     {
582          $comment_url = 'comment.php?id='.$rs->comment_id;
583         
584          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
585          switch ($rs->comment_status) {
586               case 1:
587                    $img_status = sprintf($img,__('published'),'check-on.png');
588                    break;
589               case 0:
590                    $img_status = sprintf($img,__('unpublished'),'check-off.png');
591                    break;
592               case -1:
593                    $img_status = sprintf($img,__('pending'),'check-wrn.png');
594                    break;
595               case -2:
596                    $img_status = sprintf($img,__('junk'),'junk.png');
597                    break;
598          }
599         
600          echo
601          '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'.
602          ' id="c'.$rs->comment_id.'">'.
603         
604          '<td class="nowrap">'.
605          ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,'','','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'.
606          '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'.
607          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'.
608          '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'.
609          '<td class="nowrap status">'.$img_status.'</td>'.
610          '<td class="nowrap status"><a href="'.$comment_url.'">'.
611          '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'.
612         
613          '</tr>';
614     }
615     
616     echo '</table>';
617}
618
619dcPage::helpBlock('core_post','core_wiki');
620dcPage::close();
621?>
Note: See TracBrowser for help on using the repository browser.

Sites map