Dotclear

source: plugins/pages/page.php @ 3:cf375f1e7b0f

Revision 3:cf375f1e7b0f, 18.3 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

Ported Franck & Kozlika updates for user prefs, dedicated branch

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

Sites map