Dotclear

source: admin/post.php @ 1001:a6f660d85764

Revision 1001:a6f660d85764, 9.1 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

Better that way...

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

Sites map