Dotclear

source: admin/post.php @ 747:46a1263c6991

Revision 747:46a1263c6991, 18.5 KB checked in by xave, 12 years ago (diff)

Locales building was broken

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;
323
324     if ($post_id) {
325          echo ' &ldquo;'.$post_title.'&rdquo;';
326     }
327echo '</span></h2>';
328
329if ($post_id && $post->post_status == 1) {
330     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>';
331}
332if ($post_id)
333{
334     echo '<p>';
335     if ($prev_link) { echo $prev_link; }
336     if ($next_link && $prev_link) { echo ' - '; }
337     if ($next_link) { echo $next_link; }
338     
339     # --BEHAVIOR-- adminPostNavLinks
340     $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null);
341     
342     echo '</p>';
343}
344
345# Exit if we cannot view page
346if (!$can_view_page) {
347     dcPage::helpBlock('core_post');
348     dcPage::close();
349     exit;
350}
351
352/* Post form if we can edit post
353-------------------------------------------------------- */
354if ($can_edit_post)
355{
356     echo '<div class="multi-part" title="'.__('Edit entry').'" id="edit-entry">';
357     echo '<form action="post.php" method="post" id="entry-form">';
358     echo '<div id="entry-wrapper">';
359     echo '<div id="entry-content"><div class="constrained">';
360     
361     echo
362     '<p class="col"><label class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').
363     form::field('post_title',20,255,html::escapeHTML($post_title),'maximal').
364     '</label></p>'.
365     
366     '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '.
367     form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)).
368     '</p>'.
369     
370     '<p class="area"><label class="required" '.
371     'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
372     form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)).
373     '</p>'.
374     
375     '<p class="area" id="notes-area"><label for="post_notes">'.__('Notes:').'</label>'.
376     form::textarea('post_notes',50,5,html::escapeHTML($post_notes)).
377     '</p>';
378     
379     # --BEHAVIOR-- adminPostForm
380     $core->callBehavior('adminPostForm',isset($post) ? $post : null);
381     
382     echo
383     '<p>'.
384     ($post_id ? form::hidden('id',$post_id) : '').
385     '<input type="submit" value="'.__('Save').' (s)" '.
386     'accesskey="s" name="save" /> ';
387     if ($post_id) {
388          $preview_url =
389          $core->blog->url.$core->url->getBase('preview').'/'.
390          $core->auth->userID().'/'.
391          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
392          '/'.$post->post_url;
393          echo '<a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview').'</a> ';
394     }
395     echo
396     ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : '').
397     $core->formNonce().
398     '</p>';
399     
400     echo '</div></div>';          // End #entry-content
401     echo '</div>';      // End #entry-wrapper
402
403     echo '<div id="entry-sidebar">';
404     
405     echo
406     '<p><label for="cat_id">'.__('Category:').
407     form::combo('cat_id',$categories_combo,$cat_id,'maximal').
408     '</label></p>'.
409     
410     '<p><label for="post_status">'.__('Entry status:').
411     form::combo('post_status',$status_combo,$post_status,'','',!$can_publish).
412     '</label></p>'.
413     
414     '<p><label for="post_dt">'.__('Published on:').
415     form::field('post_dt',16,16,$post_dt).
416     '</label></p>'.
417     
418     '<p><label for="post_format">'.__('Text formating:').
419     form::combo('post_format',$formaters_combo,$post_format).
420     '</label>'.
421     '</p>'.
422     '<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>'.
423     
424     '<p><label for="post_open_comment" class="classic">'.form::checkbox('post_open_comment',1,$post_open_comment).' '.
425     __('Accept comments').'</label></p>'.
426     '<p><label for="post_open_tb" class="classic">'.form::checkbox('post_open_tb',1,$post_open_tb).' '.
427     __('Accept trackbacks').'</label></p>'.
428     '<p><label for="post_selected" class="classic">'.form::checkbox('post_selected',1,$post_selected).' '.
429     __('Selected entry').'</label></p>'.
430     
431     '<p><label for="post_lang">'.__('Entry lang:').
432     form::combo('post_lang',$lang_combo,$post_lang).
433     '</label></p>'.
434     
435     '<p><label for="post_password">'.__('Entry password:').
436     form::field('post_password',10,32,html::escapeHTML($post_password),'maximal').
437     '</label></p>'.
438     
439     '<div class="lockable">'.
440     '<p><label for="post_url">'.__('Basename:').
441     form::field('post_url',10,255,html::escapeHTML($post_url),'maximal').
442     '</label></p>'.
443     '<p class="form-note warn">'.
444     __('Warning: If you set the URL manually, it may conflict with another entry.').
445     '</p>'.
446     '</div>';
447     
448     # --BEHAVIOR-- adminPostFormSidebar
449     $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null);
450     
451     echo '</div>';      // End #entry-sidebar
452
453     echo '</form>';
454     
455     # --BEHAVIOR-- adminPostForm
456     $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null);
457     
458     echo '</div>';
459     
460     if ($post_id && $post->post_status == 1) {
461          echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'.
462          __('Ping blogs').'</a></p>';
463     }
464     
465}
466
467
468/* Comments and trackbacks
469-------------------------------------------------------- */
470if ($post_id)
471{
472     $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC');
473     
474     $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0)));
475     $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1)));
476     
477     # Actions combo box
478     $combo_action = array();
479     if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id))
480     {
481          $combo_action[__('publish')] = 'publish';
482          $combo_action[__('unpublish')] = 'unpublish';
483          $combo_action[__('mark as pending')] = 'pending';
484          $combo_action[__('mark as junk')] = 'junk';
485     }
486     
487     if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id))
488     {
489          $combo_action[__('Delete')] = 'delete';
490     }
491     
492     # --BEHAVIOR-- adminCommentsActionsCombo
493     $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action));
494     
495     $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty());
496     
497     echo
498     '<div id="comments" class="multi-part" title="'.__('Comments').'">';
499     
500     if ($has_action) {
501          echo '<form action="comments_actions.php" id="form-comments" method="post">';
502     }
503     
504     echo '<h3>'.__('Trackbacks').'</h3>';
505     
506     if (!$trackbacks->isEmpty()) {
507          showComments($trackbacks,$has_action,true);
508     } else {
509          echo '<p>'.__('No trackback').'</p>';
510     }
511     
512     echo '<h3>'.__('Comments').'</h3>';
513     if (!$comments->isEmpty()) {
514          showComments($comments,$has_action);
515     } else {
516          echo '<p>'.__('No comment').'</p>';
517     }
518     
519     if ($has_action) {
520          echo
521          '<div class="two-cols">'.
522          '<p class="col checkboxes-helpers"></p>'.
523         
524          '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
525          form::combo('action',$combo_action).
526          form::hidden('redir','post.php?id='.$post_id.'&amp;co=1').
527          $core->formNonce().
528          '<input type="submit" value="'.__('ok').'" /></p>'.
529          '</div>'.
530          '</form>';
531     }
532     
533     echo '</div>';
534}
535
536/* Add a comment
537-------------------------------------------------------- */
538if ($post_id)
539{
540     echo
541     '<div class="multi-part" id="add-comment" title="'.__('Add a comment').'">'.
542     '<h3>'.__('Add a comment').'</h3>'.
543     
544     '<form action="comment.php" method="post" id="comment-form">'.
545     '<div class="constrained">'.
546     '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:').
547     form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))).
548     '</label></p>'.
549     
550     '<p><label for="comment_email">'.__('Email:').
551     form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))).
552     '</label></p>'.
553     
554     '<p><label for="comment_site">'.__('Web site:').
555     form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))).
556     '</label></p>'.
557     
558     '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '.
559     __('Comment:').'</label> '.
560     form::textarea('comment_content',50,8,html::escapeHTML('')).
561     '</p>'.
562     
563     '<p>'.form::hidden('post_id',$post_id).
564     $core->formNonce().
565     '<input type="submit" name="add" value="'.__('Save').'" /></p>'.
566     '</div>'.
567     '</form>'.
568     '</div>';
569}
570
571
572# Show comments or trackbacks
573function showComments($rs,$has_action,$tb=false)
574{
575     echo
576     '<table class="comments-list"><tr>'.
577     '<th colspan="2">'.__('Author').'</th>'.
578     '<th>'.__('Date').'</th>'.
579     '<th class="nowrap">'.__('IP address').'</th>'.
580     '<th>'.__('Status').'</th>'.
581     '<th>&nbsp;</th>'.
582     '</tr>';
583     
584     while($rs->fetch())
585     {
586          $comment_url = 'comment.php?id='.$rs->comment_id;
587         
588          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
589          switch ($rs->comment_status) {
590               case 1:
591                    $img_status = sprintf($img,__('published'),'check-on.png');
592                    break;
593               case 0:
594                    $img_status = sprintf($img,__('unpublished'),'check-off.png');
595                    break;
596               case -1:
597                    $img_status = sprintf($img,__('pending'),'check-wrn.png');
598                    break;
599               case -2:
600                    $img_status = sprintf($img,__('junk'),'junk.png');
601                    break;
602          }
603         
604          echo
605          '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'.
606          ' id="c'.$rs->comment_id.'">'.
607         
608          '<td class="nowrap">'.
609          ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,'','','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'.
610          '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'.
611          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'.
612          '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'.
613          '<td class="nowrap status">'.$img_status.'</td>'.
614          '<td class="nowrap status"><a href="'.$comment_url.'">'.
615          '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'.
616         
617          '</tr>';
618     }
619     
620     echo '</table>';
621}
622
623dcPage::helpBlock('core_post','core_wiki');
624dcPage::close();
625?>
Note: See TracBrowser for help on using the repository browser.

Sites map