Dotclear

source: plugins/tinyMce/admin/post.php @ 3023

Revision 3023, 10.4 KB checked in by Moe, 13 years ago (diff)

TinyMCE 0.2.4: Dotclear 2.2 compatibility

  • Property svn:executable set to *
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 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
15dcPage::check('usage,contentadmin');
16
17# added
18if ((!isset($_REQUEST['id'])) OR (!is_numeric($_REQUEST['id'])))
19{
20     throw new Exception(__('Invalid post ID.'));
21     exit;
22}
23
24$default_page = $core->getPostAdminURL('post',$_REQUEST['id']);
25# /added
26
27$post_id = '';
28$cat_id = '';
29$post_dt = '';
30$post_format = $core->auth->getOption('post_format');
31$post_password = '';
32$post_url = '';
33$post_lang = $core->auth->getInfo('user_lang');
34$post_title = '';
35$post_excerpt = '';
36$post_excerpt_xhtml = '';
37$post_content = '';
38$post_content_xhtml = '';
39$post_notes = '';
40$post_status = $core->auth->getInfo('user_post_status');
41$post_selected = false;
42$post_open_comment = $core->blog->settings->system->allow_comments;
43$post_open_tb = $core->blog->settings->system->allow_trackbacks;
44
45$post_media = array();
46
47$page_title = __('New entry');
48
49$can_view_page = true;
50$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
51$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
52$can_delete = false;
53
54$post_headlink = '<link rel="%s" title="%s" href="plugin.php?p=tinyMce&amp;id=%s" />';
55$post_link = '<a href="plugin.php?p=tinyMce&amp;id=%s" title="%s">%s</a>';
56
57$next_link = $prev_link = $next_headlink = $prev_headlink = null;
58
59# If user can't publish
60if (!$can_publish) {
61     $post_status = -2;
62}
63
64# Get entry informations
65if (!empty($_REQUEST['id']))
66{
67     $params['post_id'] = $_REQUEST['id'];
68     
69     $post = $core->blog->getPosts($params);
70     
71     if ($post->isEmpty())
72     {
73          $core->error->add(__('This entry does not exist.'));
74          $can_view_page = false;
75     }
76     else
77     {
78          $post_id = $post->post_id;
79          $cat_id = $post->cat_id;
80          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
81          $post_format = $post->post_format;
82         
83          # check post format
84          if (($post_format != 'xhtml') && (empty($_GET['xconv'])))
85          {
86               $core->error->add(__('This entry format is not XHTML.').' '.
87                    __('You have to convert this entry to XHTML format to use TinyMCE, this operation cannot be undone.').' '.
88                    '<a href="'.$p_url.'&amp;id='.$post_id.'&amp;xconv=1" '.
89                    'id="tinyMce-convert" class="button">'.
90                         __('Convert this post to XHTML format').'</a> '.
91                    '<a href="'.$default_page.'" class="button">'.
92                         __('Return to the default page').'</a> ');
93               $can_view_page = false;
94          }
95         
96          $post_password = $post->post_password;
97          $post_url = $post->post_url;
98          $post_lang = $post->post_lang;
99          $post_title = $post->post_title;
100          $post_excerpt = $post->post_excerpt;
101          $post_excerpt_xhtml = $post->post_excerpt_xhtml;
102          $post_content = $post->post_content;
103          $post_content_xhtml = $post->post_content_xhtml;
104          $post_notes = $post->post_notes;
105          $post_status = $post->post_status;
106          $post_selected = (boolean) $post->post_selected;
107          $post_open_comment = (boolean) $post->post_open_comment;
108          $post_open_tb = (boolean) $post->post_open_tb;
109         
110          $page_title = __('Edit entry');
111         
112          $can_edit_post = $post->isEditable();
113          $can_delete= $post->isDeletable();
114         
115          $next_rs = $core->blog->getNextPost($post,1);
116          $prev_rs = $core->blog->getNextPost($post,-1);
117         
118          if ($next_rs !== null) {
119               $next_link = sprintf($post_link,$next_rs->post_id,
120                    html::escapeHTML($next_rs->post_title),__('next entry').'&nbsp;&#187;');
121               $next_headlink = sprintf($post_headlink,'next',
122                    html::escapeHTML($next_rs->post_title),$next_rs->post_id);
123          }
124         
125          if ($prev_rs !== null) {
126               $prev_link = sprintf($post_link,$prev_rs->post_id,
127                    html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('previous entry'));
128               $prev_headlink = sprintf($post_headlink,'previous',
129                    html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);
130          }
131     }
132}
133
134# Format excerpt and content
135if (!empty($_POST) && $can_edit_post)
136{
137     $post_format = $_POST['post_format'];
138     $post_excerpt = $_POST['post_excerpt'];
139     $post_content = $_POST['post_content'];
140     
141     $post_title = $_POST['post_title'];
142     
143     $cat_id = (integer) $_POST['cat_id'];
144     
145     if (isset($_POST['post_status'])) {
146          $post_status = (integer) $_POST['post_status'];
147     }
148     
149     if (empty($_POST['post_dt'])) {
150          $post_dt = '';
151     } else {
152          $post_dt = strtotime($_POST['post_dt']);
153          $post_dt = date('Y-m-d H:i',$post_dt);
154     }
155     
156     $post_open_comment = !empty($_POST['post_open_comment']);
157     $post_open_tb = !empty($_POST['post_open_tb']);
158     $post_selected = !empty($_POST['post_selected']);
159     $post_lang = $_POST['post_lang'];
160     $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null;
161     
162     $post_notes = $_POST['post_notes'];
163     
164     if (isset($_POST['post_url'])) {
165          $post_url = $_POST['post_url'];
166     }
167     
168     $core->blog->setPostContent(
169          $post_id,$post_format,$post_lang,
170          $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
171     );
172}
173
174# Create or update post
175if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post)
176{
177     $cur = $core->con->openCursor($core->prefix.'post');
178     
179     $cur->post_title = $post_title;
180     $cur->cat_id = ($cat_id ? $cat_id : null);
181     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : '';
182     $cur->post_format = $post_format;
183     $cur->post_password = $post_password;
184     $cur->post_lang = $post_lang;
185     $cur->post_title = $post_title;
186     $cur->post_excerpt = $post_excerpt;
187     $cur->post_excerpt_xhtml = $post_excerpt_xhtml;
188     $cur->post_content = $post_content;
189     $cur->post_content_xhtml = $post_content_xhtml;
190     $cur->post_notes = $post_notes;
191     $cur->post_status = $post_status;
192     $cur->post_selected = (integer) $post_selected;
193     $cur->post_open_comment = (integer) $post_open_comment;
194     $cur->post_open_tb = (integer) $post_open_tb;
195     
196     if (isset($_POST['post_url'])) {
197          $cur->post_url = $post_url;
198     }
199     
200     # Update post
201     if ($post_id)
202     {
203          try
204          {
205               # --BEHAVIOR-- adminBeforePostUpdate
206               $core->callBehavior('adminBeforePostUpdate',$cur,$post_id);
207               
208               $core->blog->updPost($post_id,$cur);
209               
210               # --BEHAVIOR-- adminAfterPostUpdate
211               $core->callBehavior('adminAfterPostUpdate',$cur,$post_id);
212               
213               http::redirect('plugin.php?p=tinyMce&id='.$post_id.'&upd=1');
214          }
215          catch (Exception $e)
216          {
217               $core->error->add($e->getMessage());
218          }
219     }
220}
221
222dcPage::open($page_title,
223     dcPage::jsModal().
224     dcPage::jsConfirmClose('entry-form').
225     # --BEHAVIOR-- adminPostHeaders
226     //$core->callBehavior('adminPostHeaders').
227     $next_headlink."\n".$prev_headlink.
228     # TinyMCE Javascript
229     '<script type="text/javascript" src="index.php?pf='.
230          'tinyMce/js/tiny_mce_jquery/jquery.tinymce.js">'.
231     '</script>'.
232     '<script type="text/javascript" src="index.php?pf='.
233          'tinyMce/js/init_jquery.js">'.
234     '</script>'
235);
236
237if (!empty($_GET['upd'])) {
238          echo '<p class="message">'.__('Entry has been successfully updated.').'</p>';
239}
240
241# XHTML conversion
242if (!empty($_GET['xconv']))
243{
244     $post_excerpt = $post_excerpt_xhtml;
245     $post_content = $post_content_xhtml;
246     $post_format = 'xhtml';
247     
248     echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your post.').'</p>';
249}
250
251echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.$page_title;
252
253if ($post_id && $post->post_status == 1) {
254     echo ' - <a id="post-preview" href="'.$post->getURL().'" class="button">'.__('View entry').'</a>';
255} elseif ($post_id) {
256     $preview_url =
257     $core->blog->url.$core->url->getBase('preview').'/'.
258     $core->auth->userID().'/'.
259     http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
260     '/'.$post->post_url;
261     echo ' - <a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview entry').'</a>';
262}
263
264echo '</h2>';
265
266if ($post_id)
267{
268     echo '<p>';
269     if ($prev_link) { echo $prev_link; }
270     if ($next_link && $prev_link) { echo ' - '; }
271     if ($next_link) { echo $next_link; }
272     
273     # --BEHAVIOR-- adminPostNavLinks
274     //$core->callBehavior('adminPostNavLinks',isset($post) ? $post : null);
275     
276     # link to default page
277     echo('<p><a href="'.$default_page.'" class="button">'.
278          __('Return to the default page').'</a></p>');
279                         
280     echo '</p>';
281}
282
283# Exit if we cannot view page
284if (!$can_view_page) {
285     dcPage::close();
286     exit;
287}
288
289/* Post form if we can edit post
290-------------------------------------------------------- */
291if ($can_edit_post)
292{
293     echo '<form action="plugin.php" method="post" id="entry-form">';
294     echo form::hidden('p','tinyMce');
295     
296     echo(
297          form::hidden('cat_id',$cat_id).
298          form::hidden('post_status',$post_status).
299          form::hidden('post_dt',$post_dt).
300          form::hidden('post_format',$post_format).
301         
302          form::hidden('post_open_comment',(integer) $post_open_comment).
303          form::hidden('post_open_tb',(integer) $post_open_tb).
304          form::hidden('post_selected',(integer) $post_selected).
305          form::hidden('post_lang',$post_lang).
306          form::hidden('post_password',html::escapeHTML($post_password)).
307          form::hidden('post_url',html::escapeHTML($post_url))
308     );
309     
310     //echo '<div id="entry-content"><fieldset class="constrained">';
311     echo '<div><fieldset class="constrained">';
312     
313     echo
314     '<p class="col"><label class="required" title="'.__('Required field').'">'.__('Title:').
315     form::field('post_title',20,255,html::escapeHTML($post_title),'maximal',2).
316     '</label></p>'.
317     
318     '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '.
319     form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt),'tinymce',2).
320     '</p>'.
321     
322     '<p class="area"><label class="required" title="'.__('Required field').'" '.
323     'for="post_content">'.__('Content:').'</label> '.
324     form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content),'tinymce',2).
325     '</p>'.
326     
327     form::hidden('post_notes',html::escapeHTML($post_notes));
328     
329     # --BEHAVIOR-- adminPostForm
330     //$core->callBehavior('adminPostForm',isset($post) ? $post : null);
331     
332     echo
333     '<p>'.
334     ($post_id ? form::hidden('id',$post_id) : '').
335     '<input type="submit" value="'.__('save').' (s)" tabindex="4" '.
336     'accesskey="s" name="save" /> '.
337     //($can_delete ? '<input type="submit" value="'.__('delete').'" name="delete" />' : '').
338     $core->formNonce().
339     '</p>';
340     
341     echo '</fieldset></div>';          // End #entry-content
342     echo '</form>';
343     //echo '</div>';
344     
345     if ($post_id && !empty($post_media))
346     {
347          echo
348          '<form action="post_media.php" id="attachment-remove-hide" method="post">'.
349          '<div>'.form::hidden(array('post_id'),$post_id).
350          form::hidden(array('media_id'),'').
351          form::hidden(array('remove'),1).
352          $core->formNonce().'</div></form>';
353     }
354}
355
356dcPage::close();
357?>
Note: See TracBrowser for help on using the repository browser.

Sites map