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 | |
---|
13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('usage,contentadmin'); |
---|
16 | |
---|
17 | class 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 |
---|
126 | if (!$can_publish) { |
---|
127 | $form->post_status = -2; |
---|
128 | } |
---|
129 | |
---|
130 | # Getting categories |
---|
131 | $categories_combo = array(' ' => ''); |
---|
132 | try { |
---|
133 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
134 | while ($categories->fetch()) { |
---|
135 | $categories_combo[$categories->cat_id] = |
---|
136 | str_repeat(' ',$categories->level-1). |
---|
137 | ($categories->level-1 == 0 ? '' : '• '). |
---|
138 | html::escapeHTML($categories->cat_title); |
---|
139 | } |
---|
140 | } catch (Exception $e) { } |
---|
141 | |
---|
142 | # Status combo |
---|
143 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
---|
144 | $status_combo[$k] = $v; |
---|
145 | } |
---|
146 | |
---|
147 | # Formaters combo |
---|
148 | foreach ($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)); |
---|
156 | while ($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 | } |
---|
164 | unset($all_langs); |
---|
165 | unset($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 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 | |
---|
207 | ->addField( |
---|
208 | new dcFieldText('post_dt','',array( |
---|
209 | "label" => __('Publication date and hour')))) |
---|
210 | ->addField( |
---|
211 | new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array( |
---|
212 | "label" => __('Text formating')))) |
---|
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( |
---|
220 | new dcFieldCheckbox ('post_selected',array(1=>false),array( |
---|
221 | "label" => __('Selected entry')))) |
---|
222 | ->addField( |
---|
223 | new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array( |
---|
224 | "label" => __('Entry lang:')))) |
---|
225 | ->addField( |
---|
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( |
---|
234 | new dcFieldHidden ('id','')) |
---|
235 | ; |
---|
236 | # Get entry informations |
---|
237 | if (!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 | { |
---|
250 | $form->id = $post_id = $post->post_id; |
---|
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; |
---|
259 | $form->post_excerpt_xhtml = $post->post_excerpt_xhtml; |
---|
260 | $form->post_content = $post->post_content; |
---|
261 | $form->post_content_xhtml = $post->post_content_xhtml; |
---|
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; |
---|
267 | $form->can_edit_post = $post->isEditable(); |
---|
268 | $form->can_delete= $post->isDeletable(); |
---|
269 | $page_title = __('Edit entry'); |
---|
270 | |
---|
271 | } |
---|
272 | } |
---|
273 | if ($post_id) { |
---|
274 | $_ctx->post_id = $post->post_id; |
---|
275 | |
---|
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); |
---|
280 | |
---|
281 | |
---|
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 | |
---|
307 | |
---|
308 | } |
---|
309 | |
---|
310 | $form->setup(); |
---|
311 | |
---|
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 | |
---|
332 | /* DISPLAY |
---|
333 | -------------------------------------------------------- */ |
---|
334 | $default_tab = 'edit-entry'; |
---|
335 | if (!$can_edit_post) { |
---|
336 | $default_tab = ''; |
---|
337 | } |
---|
338 | if (!empty($_GET['co'])) { |
---|
339 | $default_tab = 'comments'; |
---|
340 | } |
---|
341 | $page_title_edit = __('Edit entry'); |
---|
342 | $_ctx |
---|
343 | ->setBreadCrumb( |
---|
344 | array( |
---|
345 | html::escapeHTML($core->blog->name) => '', |
---|
346 | __('Entries') => 'posts.php', |
---|
347 | ($post_id ? $page_title_edit : $page_title) => '' |
---|
348 | )) |
---|
349 | ->default_tab = $default_tab; |
---|
350 | |
---|
351 | |
---|
352 | |
---|
353 | $core->tpl->display('post.html.twig'); |
---|
354 | ?> |
---|