Dotclear

source: admin/post.php @ 2468:d7fda5a0bd39

Revision 2468:d7fda5a0bd39, 11.7 KB checked in by Dsls, 12 years ago (diff)

Merge with 2.6

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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
17class PostActions 
18{
19     public static function savePost($form) {
20          global $_ctx, $core;
21          if (!$form->can_edit_post) {
22               return;
23          }
24          try {
25               $form->check($_ctx);
26               $form->cat_id = (integer) $form->cat_id;
27     
28               if (!empty($form->post_dt)) {
29                    try
30                    {
31                         $post_dt = strtotime($form->post_dt);
32                         if ($post_dt == false || $post_dt == -1) {
33                              $bad_dt = true;
34                              throw new Exception(__('Invalid publication date'));
35                         }
36                         $form->post_dt = date('Y-m-d H:i',$post_dt);
37                    }
38                    catch (Exception $e)
39                    {
40                         $core->error->add($e->getMessage());
41                    }
42               }
43               $post_excerpt = $form->post_excerpt;
44               $post_content = $form->post_content;
45               $post_excerpt_xhtml = '';
46               $post_content_xhtml = '';
47               $core->blog->setPostContent(
48                    $form->id,$form->post_format,$form->post_lang,
49                    $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
50               );
51               $form->post_excerpt = $post_excerpt;
52               $form->post_content = $post_content;
53               $form->post_excerpt_xhtml = $post_excerpt_xhtml;
54               $form->post_content_xhtml = $post_content_xhtml;
55               
56               $cur = $core->con->openCursor($core->prefix.'post');
57     
58               $cur->post_title = $form->post_title;
59               $cur->cat_id = $form->cat_id ? $form->cat_id : null;
60               $cur->post_dt = $form->post_dt ? date('Y-m-d H:i:00',strtotime($form->post_dt)) : '';
61               $cur->post_format = $form->post_format;
62               $cur->post_password = $form->post_password;
63               $cur->post_lang = $form->post_lang;
64               $cur->post_title = $form->post_title;
65               $cur->post_excerpt = $form->post_excerpt;
66               $cur->post_excerpt_xhtml = $form->post_excerpt_xhtml;
67               $cur->post_content = $form->post_content;
68               $cur->post_content_xhtml = $form->post_content_xhtml;
69               $cur->post_notes = $form->post_notes;
70               $cur->post_status = $form->post_status;
71               $cur->post_selected = (integer) $form->post_selected;
72               $cur->post_open_comment = (integer) $form->post_open_comment;
73               $cur->post_open_tb = (integer) $form->post_open_tb;
74     
75               if (!empty($form->post_url)) {
76                    $cur->post_url = $form->post_url;
77               }
78     
79               # Update post
80               if ($form->id)
81               {
82                    # --BEHAVIOR-- adminBeforePostUpdate
83                    $core->callBehavior('adminBeforePostUpdate',$cur,$form->id);
84                   
85                    $core->blog->updPost($form->id,$cur);
86                   
87                    # --BEHAVIOR-- adminAfterPostUpdate
88                    $core->callBehavior('adminAfterPostUpdate',$cur,$form->id);
89                    http::redirect('post.php?id='.$form->id.'&upd=1');
90               }
91               else
92               {
93                    $cur->user_id = $core->auth->userID();
94                                        # --BEHAVIOR-- adminBeforePostCreate
95                    $core->callBehavior('adminBeforePostCreate',$cur);
96                   
97                    $return_id = $core->blog->addPost($cur);
98                   
99                    # --BEHAVIOR-- adminAfterPostCreate
100                    $core->callBehavior('adminAfterPostCreate',$cur,$return_id);
101                   
102                    http::redirect('post.php?id='.$return_id.'&crea=1');
103               }
104
105          } catch (Exception $e) {
106               $_ctx->addError($e->getMessage());
107          }
108     }
109     public static function deletePost($form) {
110          global $core,$_ctx;
111          if ($form->can_delete) {
112               try {
113                    $post_id = $form->id;
114                    $core->callBehavior('adminBeforePostDelete',$post_id);
115                    $core->blog->delPost($post_id);
116                    http::redirect('posts.php');
117                    exit;
118               } catch (Exception $e) {
119                    $_ctx->addError($e->getMessage());
120               }
121          }
122     }
123}
124
125$page_title = __('New entry');
126$post_id='';
127$can_view_page = true;
128$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
129$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
130$can_delete = false;
131
132$post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />';
133$post_link = '<a href="post.php?id=%s" title="%s">%s</a>';
134
135$next_link = $prev_link = $next_headlink = $prev_headlink = null;
136
137# If user can't publish
138if (!$can_publish) {
139     $form->post_status = -2;
140}
141
142# Getting categories
143$categories_combo = array('&nbsp;' => '');
144try {
145     $categories = $core->blog->getCategories(array('post_type'=>'post'));
146     while ($categories->fetch()) {
147          $categories_combo[$categories->cat_id] = 
148               str_repeat('&nbsp;&nbsp;',$categories->level-1).
149               ($categories->level-1 == 0 ? '' : '&bull; ').
150               html::escapeHTML($categories->cat_title);
151     }
152} catch (Exception $e) { }
153
154# Status combo
155foreach ($core->blog->getAllPostStatus() as $k => $v) {
156     $status_combo[$k] = $v;
157}
158
159# Formaters combo
160foreach ($core->getFormaters() as $v) {
161     $formaters_combo[$v] = $v;
162}
163
164# Languages combo
165$rs = $core->blog->getLangs(array('order'=>'asc'));
166$all_langs = l10n::getISOcodes(0,1);
167$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1));
168while ($rs->fetch()) {
169     if (isset($all_langs[$rs->post_lang])) {
170          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang];
171          unset($lang_combo[__('Available')][$rs->post_lang]);
172     } else {
173          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang];
174     }
175}
176unset($all_langs);
177unset($rs);
178
179$form = new dcForm($core,'post','post.php');
180$form
181     ->addField(
182          new dcFieldText('post_title','', array(
183               'maxlength'         => 255,
184               'required'     => true,
185               'label'        => __('Title:'))))
186     ->addField(
187          new dcFieldTextArea('post_excerpt','', array(
188               'cols'         => 50,
189               'rows'         => 5,
190               'label'        => __("Excerpt:").'<span class="form-note">'.
191               __('Add an introduction to the post.').'</span>')))
192     ->addField(
193          new dcFieldTextArea('post_content','', array(
194               'required'     => true,
195               'label'        => __("Content:"))))
196     ->addField(
197          new dcFieldTextArea('post_notes','', array(
198               'label'        => __("Notes"))))
199     ->addField(
200          new dcFieldSubmit('save',__('Save'),array(
201               'action' => array('PostActions','savePost'))))
202     ->addField(
203          new dcFieldSubmit('delete',__('Delete'),array(
204               'action' => array('PostActions','deletePost'))))
205     ->addField(
206          new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array(
207               'disabled' => !$can_publish,
208               'label' => __('Entry status'))))
209     ->addField(
210          new dcFieldCombo('cat_id','',$categories_combo,array(
211               "label" => __('Category'))))
212     ->addField(
213          new dcFieldCombo('new_cat_parent','',$categories_combo,array(
214               "label" => __('Parent:'))))
215     ->addField(
216          new dcFieldText('new_cat_title','', array(
217               'maxlength'         => 255,
218               'label'        => __('Title'))))
219         
220     ->addField(
221          new dcFieldText('post_dt','',array(
222               "label" => __('Publication date and hour'))))
223     ->addField(
224          new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array(
225               "label" => __('Text formating'))))
226     ->addField(
227          new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array(
228               "label" => __('Accept comments'))))
229     ->addField(
230          new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array(
231               "label" => __('Accept trackbacks'))))
232     ->addField(
233          new dcFieldCheckbox ('post_selected',array(1=>false),array(
234               "label" => __('Selected entry'))))
235     ->addField(
236          new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array(
237               "label" => __('Entry lang:'))))
238     ->addField(
239          new dcFieldText('post_password','',array(
240               "maxlength" => 32,
241               "label" => __('Entry password:'))))
242     ->addField(
243          new dcFieldText('post_url','',array(
244               "maxlength" => 255,
245               "label" => __('Basename:'))))
246     ->addField(
247          new dcFieldHidden ('id',''))
248;
249# Get entry informations
250if (!empty($_REQUEST['id']))
251{
252     $params['post_id'] = $_REQUEST['id'];
253     
254     $post = $core->blog->getPosts($params);
255     
256     if ($post->isEmpty())
257     {
258          $core->error->add(__('This entry does not exist.'));
259          $can_view_page = false;
260     }
261     else
262     {
263          $form->id = $post_id = $post->post_id;
264          $form->cat_id = $post->cat_id;
265          $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
266          $form->post_format = $post->post_format;
267          $form->post_password = $post->post_password;
268          $form->post_url = $post->post_url;
269          $form->post_lang = $post->post_lang;
270          $form->post_title = $post->post_title;
271          $form->post_excerpt = $post->post_excerpt;
272          $form->post_excerpt_xhtml = $post->post_excerpt_xhtml;
273          $form->post_content = $post->post_content;
274          $form->post_content_xhtml = $post->post_content_xhtml;
275          $form->post_notes = $post->post_notes;
276          $form->post_status = $post->post_status;
277          $form->post_selected = (boolean) $post->post_selected;
278          $form->post_open_comment = (boolean) $post->post_open_comment;
279          $form->post_open_tb = (boolean) $post->post_open_tb;
280          $form->can_edit_post = $post->isEditable();
281          $form->can_delete= $post->isDeletable();
282          $next_rs = $core->blog->getNextPost($post,1);
283          $prev_rs = $core->blog->getNextPost($post,-1);
284         
285          if ($next_rs !== null) {
286               $_ctx->next_post = array('id' => $next_rs->post_id,'title' => $next_rs->post_title);
287          }
288          if ($prev_rs !== null) {
289               $_ctx->prev_post = array('id' => $prev_rs->post_id,'title' => $prev_rs->post_title);
290          }
291          $page_title = __('Edit entry');
292
293     }
294}
295if ($post_id) {
296     $_ctx->post_id = $post->post_id;
297
298     $_ctx->preview_url =
299          $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'.
300          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
301          '/'.$post->post_url);
302         
303     
304     $form_comment = new dcForm($core,'add-comment','comment.php');
305     $form_comment
306          ->addField(
307               new dcFieldText('comment_author','', array(
308                    'maxlength'         => 255,
309                    'required'     => true,
310                    'label'        => __('Name:'))))
311          ->addField(
312               new dcFieldText('comment_email','', array(
313                    'maxlength'         => 255,
314                    'required'     => true,
315                    'label'        => __('Email:'))))
316          ->addField(
317               new dcFieldText('comment_site','', array(
318                    'maxlength'         => 255,
319                    'label'        => __('Web site:'))))
320          ->addField(
321               new dcFieldTextArea('comment_content','', array(
322                    'required'     => true,
323                    'label'        => __('Comment:'))))
324          ->addField(
325               new dcFieldHidden('post_id',$post_id))
326          ->addField(
327               new dcFieldSubmit('add',__('Save'),array(
328                    'action' => 'addComment')))
329          ;
330
331     
332}
333
334$form->setup();
335
336$sidebar_blocks = new ArrayObject(array(
337     'status-box' => array(
338          'title' => __('Status'),
339          'items' => array('post_status','post_dt','post_lang','post_format')),
340     'metas-box' => array(
341          'title' => __('Ordering'),
342          'items' => array('post_selected','cat_id')),
343     'options-box' => array(
344          'title' => __('Options'),
345          'items' => array('post_open_comment','post_open_tb','post_password','post_url'))
346));
347
348$main_blocks = new ArrayObject(array(
349     "post_title","post_excerpt","post_content","post_notes"
350));
351
352
353$_ctx->sidebar_blocks = $sidebar_blocks;
354$_ctx->main_blocks = $main_blocks;
355
356/* DISPLAY
357-------------------------------------------------------- */
358$default_tab = 'edit-entry';
359if (!$can_edit_post) {
360     $default_tab = '';
361}
362if (!empty($_GET['co'])) {
363     $default_tab = 'comments';
364}
365$page_title_edit = __('Edit entry');
366$_ctx
367     ->setBreadCrumb(
368          array(
369               html::escapeHTML($core->blog->name) => '',
370               __('Entries') => 'posts.php',
371               ($post_id ? $page_title_edit : $page_title) => ''
372     ))
373     ->default_tab = $default_tab;
374$_ctx->post_status = $form->post_status;
375$_ctx->post_title = $form->post_title;
376if ($form->post_status == 1) {
377     $_ctx->post_url = $post->getURL();
378}
379
380if (!empty($_GET['upd'])) {
381     $_ctx->setAlert(__('Entry has been successfully updated.'));
382}
383elseif (!empty($_GET['crea'])) {
384     $_ctx->setAlert(__('Entry has been successfully created.'));
385}
386elseif (!empty($_GET['attached'])) {
387     $_ctx->setAlert(__('File has been successfully attached.'));
388}
389elseif (!empty($_GET['rmattach'])) {
390     $_ctx->setAlert(__('Attachment has been successfully removed.'));
391}
392if (!empty($_GET['creaco'])) {
393     $_ctx->setAlert(__('Comment has been successfully created.'));
394}   
395     
396$core->tpl->display('post.html.twig');
397?>
Note: See TracBrowser for help on using the repository browser.

Sites map