Dotclear

source: admin/post.php @ 1491:2b9253624dbe

Revision 1491:2b9253624dbe, 10.3 KB checked in by Dsls, 12 years ago (diff)

Implemented last merges from default, post.php is now more flexible.
added twig function : form_field_attr

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1139]6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
[0]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
[1414]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               }
[1053]103
[1414]104     } catch (Exception $e) {
105          $ctx->setError($e->getMessage());
106     }
[1053]107}
[1414]108     function deletePost($form) {
109          echo $form->id->getValue(); exit;
110     }
[1053]111}
[0]112
[195]113$page_title = __('New entry');
[1414]114$post_id='';
[0]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) {
[992]127     $form->post_status = -2;
[0]128}
129
130# Getting categories
131$categories_combo = array('&nbsp;' => '');
132try {
133     $categories = $core->blog->getCategories(array('post_type'=>'post'));
134     while ($categories->fetch()) {
[1053]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);
[0]139     }
140} catch (Exception $e) { }
141
142# Status combo
143foreach ($core->blog->getAllPostStatus() as $k => $v) {
[992]144     $status_combo[$k] = $v;
[0]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);
[1414]155$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1));
[0]156while ($rs->fetch()) {
157     if (isset($all_langs[$rs->post_lang])) {
[1414]158          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang];
159          unset($lang_combo[__('Available')][$rs->post_lang]);
[0]160     } else {
[1414]161          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang];
[0]162     }
163}
164unset($all_langs);
165unset($rs);
166
[992]167$form = new dcForm($core,'post','post.php');
168$form
169     ->addField(
170          new dcFieldText('post_title','', array(
[1414]171               'maxlength'         => 255,
[992]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(
[1053]187          new dcFieldSubmit('save',__('Save'),array(
[1414]188               'action' => array('PostActions','savePost'))))
[992]189     ->addField(
[1053]190          new dcFieldSubmit('delete',__('Delete'),array(
191               'action' => 'deletePost')))
[1001]192     ->addField(
[992]193          new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array(
194               'disabled' => !$can_publish,
[1491]195               'label' => __('Entry status'))))
[992]196     ->addField(
197          new dcFieldCombo('cat_id','',$categories_combo,array(
[1491]198               "label" => __('Category'))))
199     ->addField(
200          new dcFieldCombo('new_cat_parent','',$categories_combo,array(
201               "label" => __('Parent:'))))
202     ->addField(
203          new dcFieldText('new_cat_title','', array(
204               'maxlength'         => 255,
205               'label'        => __('Title'))))
206         
[992]207     ->addField(
208          new dcFieldText('post_dt','',array(
[1491]209               "label" => __('Publication date and hour'))))
[992]210     ->addField(
211          new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array(
[1491]212               "label" => __('Text formating'))))
[992]213     ->addField(
214          new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array(
215               "label" => __('Accept comments'))))
216     ->addField(
217          new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array(
218               "label" => __('Accept trackbacks'))))
219     ->addField(
[1414]220          new dcFieldCheckbox ('post_selected',array(1=>false),array(
[992]221               "label" => __('Selected entry'))))
222     ->addField(
223          new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array(
224               "label" => __('Entry lang:'))))
[1053]225     ->addField(
[1319]226          new dcFieldText('post_password','',array(
227               "maxlength" => 32,
228               "label" => __('Entry password:'))))
229     ->addField(
230          new dcFieldText('post_url','',array(
231               "maxlength" => 255,
232               "label" => __('Basename:'))))
233     ->addField(
[1053]234          new dcFieldHidden ('id',''))
[992]235;
[0]236# Get entry informations
237if (!empty($_REQUEST['id']))
238{
239     $params['post_id'] = $_REQUEST['id'];
240     
241     $post = $core->blog->getPosts($params);
242     
243     if ($post->isEmpty())
244     {
245          $core->error->add(__('This entry does not exist.'));
246          $can_view_page = false;
247     }
248     else
249     {
[1319]250          $form->id = $post_id = $post->post_id;
[992]251          $form->cat_id = $post->cat_id;
252          $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
253          $form->post_format = $post->post_format;
254          $form->post_password = $post->post_password;
255          $form->post_url = $post->post_url;
256          $form->post_lang = $post->post_lang;
257          $form->post_title = $post->post_title;
258          $form->post_excerpt = $post->post_excerpt;
[1053]259          $form->post_excerpt_xhtml = $post->post_excerpt_xhtml;
[992]260          $form->post_content = $post->post_content;
[1053]261          $form->post_content_xhtml = $post->post_content_xhtml;
[992]262          $form->post_notes = $post->post_notes;
263          $form->post_status = $post->post_status;
264          $form->post_selected = (boolean) $post->post_selected;
265          $form->post_open_comment = (boolean) $post->post_open_comment;
266          $form->post_open_tb = (boolean) $post->post_open_tb;
[1053]267          $form->can_edit_post = $post->isEditable();
268          $form->can_delete= $post->isDeletable();
[1333]269          $page_title = __('Edit entry');
[1319]270
[0]271     }
272}
[1319]273if ($post_id) {
274     $_ctx->post_id = $post->post_id;
[0]275
[1319]276     $_ctx->preview_url =
277          $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'.
278          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
279          '/'.$post->post_url);
[1312]280         
[0]281     
[1319]282     $form_comment = new dcForm($core,'add-comment','post.php');
283     $form_comment
284          ->addField(
285               new dcFieldText('comment_author','', array(
286                    'maxlength'         => 255,
287                    'required'     => true,
288                    'label'        => __('Name:'))))
289          ->addField(
290               new dcFieldText('comment_email','', array(
291                    'maxlength'         => 255,
292                    'required'     => true,
293                    'label'        => __('Email:'))))
294          ->addField(
295               new dcFieldText('comment_site','', array(
296                    'maxlength'         => 255,
297                    'label'        => __('Web site:'))))
298          ->addField(
299               new dcFieldTextArea('comment_content','', array(
300                    'required'     => true,
301                    'label'        => __('Comment:'))))
302          ->addField(
303               new dcFieldSubmit('add',__('Save'),array(
304                    'action' => 'addComment')))
305          ;
306
[0]307     
308}
309
[1053]310$form->setup();
[0]311
[1491]312$sidebar_blocks = new ArrayObject(array(
313     'status-box' => array(
314          'title' => __('Status'),
315          'items' => array('post_status','post_dt','post_lang','post_format')),
316     'metas-box' => array(
317          'title' => __('Ordering'),
318          'items' => array('post_selected','cat_id')),
319     'options-box' => array(
320          'title' => __('Options'),
321          'items' => array('post_open_comment','post_open_tb','post_password','post_url'))
322));
323
324$main_blocks = new ArrayObject(array(
325     "post_title","post_excerpt","post_content","post_notes"
326));
327
328
329$_ctx->sidebar_blocks = $sidebar_blocks;
330$_ctx->main_blocks = $main_blocks;
331
[0]332/* DISPLAY
333-------------------------------------------------------- */
334$default_tab = 'edit-entry';
335if (!$can_edit_post) {
336     $default_tab = '';
337}
338if (!empty($_GET['co'])) {
339     $default_tab = 'comments';
340}
[1414]341$page_title_edit = __('Edit entry');
[1089]342$_ctx
[1414]343     ->setBreadCrumb(
[1358]344          array(
345               html::escapeHTML($core->blog->name) => '',
346               __('Entries') => 'posts.php',
[1414]347               ($post_id ? $page_title_edit : $page_title) => ''
348     ))
[1089]349     ->default_tab = $default_tab;
[0]350
[1491]351     
352     
[1056]353$core->tpl->display('post.html.twig');
[1312]354?>
Note: See TracBrowser for help on using the repository browser.

Sites map