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 | $post_id = ''; |
---|
18 | $post_dt = ''; |
---|
19 | $post_format = $core->auth->getOption('post_format'); |
---|
20 | $post_password = ''; |
---|
21 | $post_url = ''; |
---|
22 | $post_lang = $core->auth->getInfo('user_lang'); |
---|
23 | $post_title = ''; |
---|
24 | $post_excerpt = ''; |
---|
25 | $post_excerpt_xhtml = ''; |
---|
26 | $post_content = ''; |
---|
27 | $post_content_xhtml = ''; |
---|
28 | $post_notes = ''; |
---|
29 | $post_status = $core->auth->getInfo('user_post_status'); |
---|
30 | $post_selected = false; |
---|
31 | |
---|
32 | $page_title = __('New entry'); |
---|
33 | |
---|
34 | $can_view_page = true; |
---|
35 | $can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id); |
---|
36 | $can_publish = $core->auth->check('publish,contentadmin',$core->blog->id); |
---|
37 | $can_delete = false; |
---|
38 | |
---|
39 | $post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />'; |
---|
40 | $post_link = '<a href="post.php?id=%s" title="%s">%s</a>'; |
---|
41 | |
---|
42 | $next_link = $prev_link = $next_headlink = $prev_headlink = null; |
---|
43 | |
---|
44 | # If user can't publish |
---|
45 | if (!$can_publish) { |
---|
46 | $post_status = -2; |
---|
47 | } |
---|
48 | |
---|
49 | # Status combo |
---|
50 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
---|
51 | $status_combo[$v] = (string) $k; |
---|
52 | } |
---|
53 | |
---|
54 | # Formaters combo |
---|
55 | foreach ($core->getFormaters() as $v) { |
---|
56 | $formaters_combo[$v] = $v; |
---|
57 | } |
---|
58 | |
---|
59 | # Languages combo |
---|
60 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
61 | $all_langs = l10n::getISOcodes(0,1); |
---|
62 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
63 | while ($rs->fetch()) { |
---|
64 | if (isset($all_langs[$rs->post_lang])) { |
---|
65 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
66 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
67 | } else { |
---|
68 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
69 | } |
---|
70 | } |
---|
71 | unset($all_langs); |
---|
72 | unset($rs); |
---|
73 | |
---|
74 | |
---|
75 | # Get entry informations |
---|
76 | if (!empty($_REQUEST['id'])) |
---|
77 | { |
---|
78 | $params['post_id'] = $_REQUEST['id']; |
---|
79 | |
---|
80 | $post = $core->blog->getPosts($params); |
---|
81 | |
---|
82 | if ($post->isEmpty()) |
---|
83 | { |
---|
84 | $core->error->add(__('This entry does not exist.')); |
---|
85 | $can_view_page = false; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | $post_id = $post->post_id; |
---|
90 | $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); |
---|
91 | $post_format = $post->post_format; |
---|
92 | $post_password = $post->post_password; |
---|
93 | $post_url = $post->post_url; |
---|
94 | $post_lang = $post->post_lang; |
---|
95 | $post_title = $post->post_title; |
---|
96 | $post_excerpt = $post->post_excerpt; |
---|
97 | $post_excerpt_xhtml = $post->post_excerpt_xhtml; |
---|
98 | $post_content = $post->post_content; |
---|
99 | $post_content_xhtml = $post->post_content_xhtml; |
---|
100 | $post_notes = $post->post_notes; |
---|
101 | $post_status = $post->post_status; |
---|
102 | $post_selected = (boolean) $post->post_selected; |
---|
103 | |
---|
104 | $page_title = __('Edit entry'); |
---|
105 | |
---|
106 | $can_edit_post = $post->isEditable(); |
---|
107 | $can_delete= $post->isDeletable(); |
---|
108 | |
---|
109 | $next_rs = $core->blog->getNextPost($post,1); |
---|
110 | $prev_rs = $core->blog->getNextPost($post,-1); |
---|
111 | |
---|
112 | if ($next_rs !== null) { |
---|
113 | $next_link = sprintf($post_link,$next_rs->post_id, |
---|
114 | html::escapeHTML($next_rs->post_title),__('next entry').' »'); |
---|
115 | $next_headlink = sprintf($post_headlink,'next', |
---|
116 | html::escapeHTML($next_rs->post_title),$next_rs->post_id); |
---|
117 | } |
---|
118 | |
---|
119 | if ($prev_rs !== null) { |
---|
120 | $prev_link = sprintf($post_link,$prev_rs->post_id, |
---|
121 | html::escapeHTML($prev_rs->post_title),'« '.__('previous entry')); |
---|
122 | $prev_headlink = sprintf($post_headlink,'previous', |
---|
123 | html::escapeHTML($prev_rs->post_title),$prev_rs->post_id); |
---|
124 | } |
---|
125 | |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | # Format excerpt and content |
---|
130 | if (!empty($_POST) && $can_edit_post) |
---|
131 | { |
---|
132 | $post_format = $_POST['post_format']; |
---|
133 | $post_excerpt = $_POST['post_excerpt']; |
---|
134 | $post_content = $_POST['post_content']; |
---|
135 | |
---|
136 | $post_title = $_POST['post_title']; |
---|
137 | |
---|
138 | if (isset($_POST['post_status'])) { |
---|
139 | $post_status = (integer) $_POST['post_status']; |
---|
140 | } |
---|
141 | |
---|
142 | if (empty($_POST['post_dt'])) { |
---|
143 | $post_dt = ''; |
---|
144 | } else { |
---|
145 | $post_dt = strtotime($_POST['post_dt']); |
---|
146 | $post_dt = date('Y-m-d H:i',$post_dt); |
---|
147 | } |
---|
148 | |
---|
149 | $post_selected = !empty($_POST['post_selected']); |
---|
150 | $post_lang = $_POST['post_lang']; |
---|
151 | $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; |
---|
152 | |
---|
153 | $post_notes = $_POST['post_notes']; |
---|
154 | |
---|
155 | if (isset($_POST['post_url'])) { |
---|
156 | $post_url = $_POST['post_url']; |
---|
157 | } |
---|
158 | |
---|
159 | $core->blog->setPostContent( |
---|
160 | $post_id,$post_format,$post_lang, |
---|
161 | $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml |
---|
162 | ); |
---|
163 | } |
---|
164 | |
---|
165 | # Create or update post |
---|
166 | if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post) |
---|
167 | { |
---|
168 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
169 | |
---|
170 | $cur->post_title = $post_title; |
---|
171 | $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; |
---|
172 | $cur->post_format = $post_format; |
---|
173 | $cur->post_password = $post_password; |
---|
174 | $cur->post_lang = $post_lang; |
---|
175 | $cur->post_title = $post_title; |
---|
176 | $cur->post_excerpt = $post_excerpt; |
---|
177 | $cur->post_excerpt_xhtml = $post_excerpt_xhtml; |
---|
178 | $cur->post_content = $post_content; |
---|
179 | $cur->post_content_xhtml = $post_content_xhtml; |
---|
180 | $cur->post_notes = $post_notes; |
---|
181 | $cur->post_status = $post_status; |
---|
182 | $cur->post_selected = (integer) $post_selected; |
---|
183 | |
---|
184 | if (isset($_POST['post_url'])) { |
---|
185 | $cur->post_url = $post_url; |
---|
186 | } |
---|
187 | |
---|
188 | # Update post |
---|
189 | if ($post_id) |
---|
190 | { |
---|
191 | try |
---|
192 | { |
---|
193 | # --BEHAVIOR-- adminBeforePostUpdate |
---|
194 | $core->callBehavior('adminBeforePostUpdate',$cur,$post_id); |
---|
195 | |
---|
196 | $core->blog->updPost($post_id,$cur); |
---|
197 | |
---|
198 | # --BEHAVIOR-- adminAfterPostUpdate |
---|
199 | $core->callBehavior('adminAfterPostUpdate',$cur,$post_id); |
---|
200 | |
---|
201 | http::redirect('post.php?id='.$post_id.'&upd=1'); |
---|
202 | } |
---|
203 | catch (Exception $e) |
---|
204 | { |
---|
205 | $core->error->add($e->getMessage()); |
---|
206 | } |
---|
207 | } |
---|
208 | else |
---|
209 | { |
---|
210 | $cur->user_id = $core->auth->userID(); |
---|
211 | |
---|
212 | try |
---|
213 | { |
---|
214 | # --BEHAVIOR-- adminBeforePostCreate |
---|
215 | $core->callBehavior('adminBeforePostCreate',$cur); |
---|
216 | |
---|
217 | $return_id = $core->blog->addPost($cur); |
---|
218 | |
---|
219 | # --BEHAVIOR-- adminAfterPostCreate |
---|
220 | $core->callBehavior('adminAfterPostCreate',$cur,$return_id); |
---|
221 | |
---|
222 | http::redirect('post.php?id='.$return_id.'&crea=1'); |
---|
223 | } |
---|
224 | catch (Exception $e) |
---|
225 | { |
---|
226 | $core->error->add($e->getMessage()); |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | if (!empty($_POST['delete']) && $can_delete) |
---|
232 | { |
---|
233 | try { |
---|
234 | # --BEHAVIOR-- adminBeforePostDelete |
---|
235 | $core->callBehavior('adminBeforePostDelete',$post_id); |
---|
236 | $core->blog->delPost($post_id); |
---|
237 | http::redirect('posts.php'); |
---|
238 | } catch (Exception $e) { |
---|
239 | $core->error->add($e->getMessage()); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | /* DISPLAY |
---|
244 | -------------------------------------------------------- */ |
---|
245 | $default_tab = 'edit-entry'; |
---|
246 | if (!$can_edit_post) { |
---|
247 | $default_tab = ''; |
---|
248 | } |
---|
249 | |
---|
250 | dcPage::open($page_title.' - '.__('Entries'), |
---|
251 | dcPage::jsDatePicker(). |
---|
252 | dcPage::jsToolBar(). |
---|
253 | dcPage::jsModal(). |
---|
254 | dcPage::jsMetaEditor(). |
---|
255 | dcPage::jsLoad('js/_post.js'). |
---|
256 | dcPage::jsConfirmClose('entry-form'). |
---|
257 | # --BEHAVIOR-- adminPostHeaders |
---|
258 | $core->callBehavior('adminPostHeaders'). |
---|
259 | dcPage::jsPageTabs($default_tab). |
---|
260 | $next_headlink."\n".$prev_headlink |
---|
261 | ); |
---|
262 | |
---|
263 | if (!empty($_GET['upd'])) { |
---|
264 | echo '<p class="message">'.__('Entry has been successfully updated.').'</p>'; |
---|
265 | } |
---|
266 | elseif (!empty($_GET['crea'])) { |
---|
267 | echo '<p class="message">'.__('Entry has been successfully created.').'</p>'; |
---|
268 | } |
---|
269 | elseif (!empty($_GET['attached'])) { |
---|
270 | echo '<p class="message">'.__('File has been successfully attached.').'</p>'; |
---|
271 | } |
---|
272 | elseif (!empty($_GET['rmattach'])) { |
---|
273 | echo '<p class="message">'.__('Attachment has been successfully removed.').'</p>'; |
---|
274 | } |
---|
275 | |
---|
276 | |
---|
277 | # XHTML conversion |
---|
278 | if (!empty($_GET['xconv'])) |
---|
279 | { |
---|
280 | $post_excerpt = $post_excerpt_xhtml; |
---|
281 | $post_content = $post_content_xhtml; |
---|
282 | $post_title = $post_title_xhtml; |
---|
283 | $post_format = 'xhtml'; |
---|
284 | |
---|
285 | echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your post.').'</p>'; |
---|
286 | } |
---|
287 | |
---|
288 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.'<a href="posts.php">'.__('Entries').'</a> › <span class="page-title">'.$page_title; |
---|
289 | |
---|
290 | if ($post_id) { |
---|
291 | echo ' “'.$post_title.'”'; |
---|
292 | } |
---|
293 | echo '</span></h2>'; |
---|
294 | |
---|
295 | if ($post_id && $post->post_status == 1) { |
---|
296 | echo '<p><a href="'.$post->getURL().'" onclick="window.open(this.href);return false;" title="'.$post_title.' ('.__('new window').')'.'">'.__('Go to this entry on the site').' <img src="images/outgoing-blue.png" alt="" /></a></p>'; |
---|
297 | } |
---|
298 | if ($post_id) |
---|
299 | { |
---|
300 | echo '<p>'; |
---|
301 | if ($prev_link) { echo $prev_link; } |
---|
302 | if ($next_link && $prev_link) { echo ' - '; } |
---|
303 | if ($next_link) { echo $next_link; } |
---|
304 | |
---|
305 | # --BEHAVIOR-- adminPostNavLinks |
---|
306 | $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null); |
---|
307 | |
---|
308 | echo '</p>'; |
---|
309 | } |
---|
310 | |
---|
311 | # Exit if we cannot view page |
---|
312 | if (!$can_view_page) { |
---|
313 | dcPage::helpBlock('core_post'); |
---|
314 | dcPage::close(); |
---|
315 | exit; |
---|
316 | } |
---|
317 | |
---|
318 | /* Post form if we can edit post |
---|
319 | -------------------------------------------------------- */ |
---|
320 | if ($can_edit_post) |
---|
321 | { |
---|
322 | echo '<div class="multi-part" title="'.__('Edit entry').'" id="edit-entry">'; |
---|
323 | echo '<form action="post.php" method="post" id="entry-form">'; |
---|
324 | echo '<div id="entry-wrapper">'; |
---|
325 | echo '<div id="entry-content"><div class="constrained">'; |
---|
326 | |
---|
327 | echo |
---|
328 | '<p class="col"><label class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:'). |
---|
329 | form::field('post_title',20,255,html::escapeHTML($post_title),'maximal'). |
---|
330 | '</label></p>'. |
---|
331 | |
---|
332 | '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '. |
---|
333 | form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)). |
---|
334 | '</p>'. |
---|
335 | |
---|
336 | '<p class="area"><label class="required" '. |
---|
337 | 'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. |
---|
338 | form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)). |
---|
339 | '</p>'. |
---|
340 | |
---|
341 | '<p class="area" id="notes-area"><label for="post_notes">'.__('Notes:').'</label>'. |
---|
342 | form::textarea('post_notes',50,5,html::escapeHTML($post_notes)). |
---|
343 | '</p>'; |
---|
344 | |
---|
345 | # --BEHAVIOR-- adminPostForm |
---|
346 | $core->callBehavior('adminPostForm',isset($post) ? $post : null); |
---|
347 | |
---|
348 | echo |
---|
349 | '<p>'. |
---|
350 | ($post_id ? form::hidden('id',$post_id) : ''). |
---|
351 | '<input type="submit" value="'.__('Save').' (s)" '. |
---|
352 | 'accesskey="s" name="save" /> '; |
---|
353 | if ($post_id) { |
---|
354 | $preview_url = |
---|
355 | $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. |
---|
356 | http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). |
---|
357 | '/'.$post->post_url); |
---|
358 | echo '<a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview').'</a> '; |
---|
359 | } |
---|
360 | echo |
---|
361 | ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : ''). |
---|
362 | $core->formNonce(). |
---|
363 | '</p>'; |
---|
364 | |
---|
365 | echo '</div></div>'; // End #entry-content |
---|
366 | echo '</div>'; // End #entry-wrapper |
---|
367 | |
---|
368 | echo '<div id="entry-sidebar">'; |
---|
369 | |
---|
370 | echo |
---|
371 | '<p><label for="post_status">'.__('Entry status:'). |
---|
372 | form::combo('post_status',$status_combo,$post_status,'','',!$can_publish). |
---|
373 | '</label></p>'. |
---|
374 | |
---|
375 | '<p><label for="post_dt">'.__('Published on:'). |
---|
376 | form::field('post_dt',16,16,$post_dt). |
---|
377 | '</label></p>'. |
---|
378 | |
---|
379 | '<p><label for="post_format">'.__('Text formating:'). |
---|
380 | form::combo('post_format',$formaters_combo,$post_format). |
---|
381 | '</label>'. |
---|
382 | '</p>'. |
---|
383 | '<p>'.($post_id && $post_format != 'xhtml' ? '<a id="convert-xhtml" class="button" href="post.php?id='.$post_id.'&xconv=1">'.__('Convert to XHTML').'</a>' : '').'</p>'. |
---|
384 | |
---|
385 | '<p><label for="post_selected" class="classic">'.form::checkbox('post_selected',1,$post_selected).' '. |
---|
386 | __('Selected entry').'</label></p>'. |
---|
387 | |
---|
388 | '<p><label for="post_lang">'.__('Entry lang:'). |
---|
389 | form::combo('post_lang',$lang_combo,$post_lang). |
---|
390 | '</label></p>'. |
---|
391 | |
---|
392 | '<p><label for="post_password">'.__('Entry password:'). |
---|
393 | form::field('post_password',10,32,html::escapeHTML($post_password),'maximal'). |
---|
394 | '</label></p>'. |
---|
395 | |
---|
396 | '<div class="lockable">'. |
---|
397 | '<p><label for="post_url">'.__('Basename:'). |
---|
398 | form::field('post_url',10,255,html::escapeHTML($post_url),'maximal'). |
---|
399 | '</label></p>'. |
---|
400 | '<p class="form-note warn">'. |
---|
401 | __('Warning: If you set the URL manually, it may conflict with another entry.'). |
---|
402 | '</p>'. |
---|
403 | '</div>'; |
---|
404 | |
---|
405 | # --BEHAVIOR-- adminPostFormSidebar |
---|
406 | $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); |
---|
407 | |
---|
408 | echo '</div>'; // End #entry-sidebar |
---|
409 | |
---|
410 | echo '</form>'; |
---|
411 | |
---|
412 | # --BEHAVIOR-- adminPostForm |
---|
413 | $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null); |
---|
414 | |
---|
415 | echo '</div>'; |
---|
416 | |
---|
417 | } |
---|
418 | |
---|
419 | dcPage::helpBlock('core_post','core_wiki'); |
---|
420 | dcPage::close(); |
---|
421 | ?> |
---|