Dotclear

source: admin/post.php @ 1414:ce67e9c592b7

Revision 1414:ce67e9c592b7, 9.5 KB checked in by Dsls, 12 years ago (diff)
  • reworked breadcrumb
  • tuned checkboxes (need to see if it works for multiple values)
  • magic methods for dcForm are more intuitive now, getField method added
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
17class PostActions 
18{
19     public static function savePost($form) {
20          global $_ctx, $core;
21          try {
22               $form->check($_ctx);
23               $_ctx->setAlert('save');
24               $form->cat_id = (integer) $form->cat_id;
25     
26               if (!empty($form->post_dt)) {
27                    try
28                    {
29                         $post_dt = strtotime($form->post_dt);
30                         if ($post_dt == false || $post_dt == -1) {
31                              $bad_dt = true;
32                              throw new Exception(__('Invalid publication date'));
33                         }
34                         $form->post_dt = date('Y-m-d H:i',$post_dt);
35                    }
36                    catch (Exception $e)
37                    {
38                         $core->error->add($e->getMessage());
39                    }
40               }
41               $post_excerpt = $form->post_excerpt;
42               $post_content = $form->post_content;
43               $post_excerpt_xhtml = '';
44               $post_content_xhtml = '';
45               $core->blog->setPostContent(
46                    $form->id,$form->post_format,$form->post_lang,
47                    $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
48               );
49               $form->post_excerpt = $post_excerpt;
50               $form->post_content = $post_content;
51               $form->post_excerpt_xhtml = $post_excerpt_xhtml;
52               $form->post_content_xhtml = $post_content_xhtml;
53               
54               $cur = $core->con->openCursor($core->prefix.'post');
55     
56               $cur->post_title = $form->post_title;
57               $cur->cat_id = $form->cat_id ? $form->cat_id : null;
58               $cur->post_dt = $form->post_dt ? date('Y-m-d H:i:00',strtotime($form->post_dt)) : '';
59               $cur->post_format = $form->post_format;
60               $cur->post_password = $form->post_password;
61               $cur->post_lang = $form->post_lang;
62               $cur->post_title = $form->post_title;
63               $cur->post_excerpt = $form->post_excerpt;
64               $cur->post_excerpt_xhtml = $form->post_excerpt_xhtml;
65               $cur->post_content = $form->post_content;
66               $cur->post_content_xhtml = $form->post_content_xhtml;
67               $cur->post_notes = $form->post_notes;
68               $cur->post_status = $form->post_status;
69               $cur->post_selected = (integer) $form->post_selected;
70               $cur->post_open_comment = (integer) $form->post_open_comment;
71               $cur->post_open_tb = (integer) $form->post_open_tb;
72     
73               if (!empty($form->post_url)) {
74                    $cur->post_url = $form->post_url;
75               }
76     
77               # Update post
78               if ($form->id)
79               {
80                    # --BEHAVIOR-- adminBeforePostUpdate
81                    $core->callBehavior('adminBeforePostUpdate',$cur,$form->id);
82                   
83                    $core->blog->updPost($form->id,$cur);
84                   
85                    # --BEHAVIOR-- adminAfterPostUpdate
86                    $core->callBehavior('adminAfterPostUpdate',$cur,$form->id);
87                   
88                    http::redirect('post.php?id='.$form->id.'&upd=1');
89               }
90               else
91               {
92                    $cur->user_id = $core->auth->userID();
93                                        # --BEHAVIOR-- adminBeforePostCreate
94                    $core->callBehavior('adminBeforePostCreate',$cur);
95                   
96                    $return_id = $core->blog->addPost($cur);
97                   
98                    # --BEHAVIOR-- adminAfterPostCreate
99                    $core->callBehavior('adminAfterPostCreate',$cur,$return_id);
100                   
101                    http::redirect('post.php?id='.$return_id.'&crea=1');
102               }
103
104     } catch (Exception $e) {
105          $ctx->setError($e->getMessage());
106     }
107}
108     function deletePost($form) {
109          echo $form->id->getValue(); exit;
110     }
111}
112
113$page_title = __('New entry');
114$post_id='';
115$can_view_page = true;
116$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
117$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
118$can_delete = false;
119
120$post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />';
121$post_link = '<a href="post.php?id=%s" title="%s">%s</a>';
122
123$next_link = $prev_link = $next_headlink = $prev_headlink = null;
124
125# If user can't publish
126if (!$can_publish) {
127     $form->post_status = -2;
128}
129
130# Getting categories
131$categories_combo = array('&nbsp;' => '');
132try {
133     $categories = $core->blog->getCategories(array('post_type'=>'post'));
134     while ($categories->fetch()) {
135          $categories_combo[$categories->cat_id] = 
136               str_repeat('&nbsp;&nbsp;',$categories->level-1).
137               ($categories->level-1 == 0 ? '' : '&bull; ').
138               html::escapeHTML($categories->cat_title);
139     }
140} catch (Exception $e) { }
141
142# Status combo
143foreach ($core->blog->getAllPostStatus() as $k => $v) {
144     $status_combo[$k] = $v;
145}
146
147# Formaters combo
148foreach ($core->getFormaters() as $v) {
149     $formaters_combo[$v] = $v;
150}
151
152# Languages combo
153$rs = $core->blog->getLangs(array('order'=>'asc'));
154$all_langs = l10n::getISOcodes(0,1);
155$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1));
156while ($rs->fetch()) {
157     if (isset($all_langs[$rs->post_lang])) {
158          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang];
159          unset($lang_combo[__('Available')][$rs->post_lang]);
160     } else {
161          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang];
162     }
163}
164unset($all_langs);
165unset($rs);
166
167$form = new dcForm($core,'post','post.php');
168$form
169     ->addField(
170          new dcFieldText('post_title','', array(
171               'maxlength'         => 255,
172               'required'     => true,
173               'label'        => __('Title'))))
174     ->addField(
175          new dcFieldTextArea('post_excerpt','', array(
176               'cols'         => 50,
177               'rows'         => 5,
178               'label'        => __("Excerpt:"))))
179     ->addField(
180          new dcFieldTextArea('post_content','', array(
181               'required'     => true,
182               'label'        => __("Content:"))))
183     ->addField(
184          new dcFieldTextArea('post_notes','', array(
185               'label'        => __("Notes"))))
186     ->addField(
187          new dcFieldSubmit('save',__('Save'),array(
188               'action' => array('PostActions','savePost'))))
189     ->addField(
190          new dcFieldSubmit('delete',__('Delete'),array(
191               'action' => 'deletePost')))
192     ->addField(
193          new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array(
194               'disabled' => !$can_publish,
195               'label' => __('Entry status:'))))
196     ->addField(
197          new dcFieldCombo('cat_id','',$categories_combo,array(
198               "label" => __('Category:'))))
199     ->addField(
200          new dcFieldText('post_dt','',array(
201               "label" => __('Published on:'))))
202     ->addField(
203          new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array(
204               "label" => __('Text formating:'))))
205     ->addField(
206          new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array(
207               "label" => __('Accept comments'))))
208     ->addField(
209          new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array(
210               "label" => __('Accept trackbacks'))))
211     ->addField(
212          new dcFieldCheckbox ('post_selected',array(1=>false),array(
213               "label" => __('Selected entry'))))
214     ->addField(
215          new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array(
216               "label" => __('Entry lang:'))))
217     ->addField(
218          new dcFieldText('post_password','',array(
219               "maxlength" => 32,
220               "label" => __('Entry password:'))))
221     ->addField(
222          new dcFieldText('post_url','',array(
223               "maxlength" => 255,
224               "label" => __('Basename:'))))
225     ->addField(
226          new dcFieldHidden ('id',''))
227;
228# Get entry informations
229if (!empty($_REQUEST['id']))
230{
231     $params['post_id'] = $_REQUEST['id'];
232     
233     $post = $core->blog->getPosts($params);
234     
235     if ($post->isEmpty())
236     {
237          $core->error->add(__('This entry does not exist.'));
238          $can_view_page = false;
239     }
240     else
241     {
242          $form->id = $post_id = $post->post_id;
243          $form->cat_id = $post->cat_id;
244          $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
245          $form->post_format = $post->post_format;
246          $form->post_password = $post->post_password;
247          $form->post_url = $post->post_url;
248          $form->post_lang = $post->post_lang;
249          $form->post_title = $post->post_title;
250          $form->post_excerpt = $post->post_excerpt;
251          $form->post_excerpt_xhtml = $post->post_excerpt_xhtml;
252          $form->post_content = $post->post_content;
253          $form->post_content_xhtml = $post->post_content_xhtml;
254          $form->post_notes = $post->post_notes;
255          $form->post_status = $post->post_status;
256          $form->post_selected = (boolean) $post->post_selected;
257          $form->post_open_comment = (boolean) $post->post_open_comment;
258          $form->post_open_tb = (boolean) $post->post_open_tb;
259          $form->can_edit_post = $post->isEditable();
260          $form->can_delete= $post->isDeletable();
261          $page_title = __('Edit entry');
262
263     }
264}
265if ($post_id) {
266     $_ctx->post_id = $post->post_id;
267
268     $_ctx->preview_url =
269          $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'.
270          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
271          '/'.$post->post_url);
272         
273     
274     $form_comment = new dcForm($core,'add-comment','post.php');
275     $form_comment
276          ->addField(
277               new dcFieldText('comment_author','', array(
278                    'maxlength'         => 255,
279                    'required'     => true,
280                    'label'        => __('Name:'))))
281          ->addField(
282               new dcFieldText('comment_email','', array(
283                    'maxlength'         => 255,
284                    'required'     => true,
285                    'label'        => __('Email:'))))
286          ->addField(
287               new dcFieldText('comment_site','', array(
288                    'maxlength'         => 255,
289                    'label'        => __('Web site:'))))
290          ->addField(
291               new dcFieldTextArea('comment_content','', array(
292                    'required'     => true,
293                    'label'        => __('Comment:'))))
294          ->addField(
295               new dcFieldSubmit('add',__('Save'),array(
296                    'action' => 'addComment')))
297          ;
298
299     
300}
301
302$form->setup();
303
304/* DISPLAY
305-------------------------------------------------------- */
306$default_tab = 'edit-entry';
307if (!$can_edit_post) {
308     $default_tab = '';
309}
310if (!empty($_GET['co'])) {
311     $default_tab = 'comments';
312}
313$page_title_edit = __('Edit entry');
314$_ctx
315     ->setBreadCrumb(
316          array(
317               html::escapeHTML($core->blog->name) => '',
318               __('Entries') => 'posts.php',
319               ($post_id ? $page_title_edit : $page_title) => ''
320     ))
321     ->default_tab = $default_tab;
322
323$core->tpl->display('post.html.twig');
324?>
Note: See TracBrowser for help on using the repository browser.

Sites map