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