Dotclear

source: plugins/gallery/trunk/item.php @ 2272

Revision 2272, 14.9 KB checked in by bruno, 14 years ago (diff)

Sanitized versions checking

  • Property svn:executable set to *
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Dotclear 2 Gallery plugin.
5#
6# Copyright (c) 2004-2008 Bruno Hondelatte, and contributors.
7# Many, many thanks to Olivier Meunier and the Dotclear Team.
8# Licensed under the GPL version 2.0 license.
9# See LICENSE file or
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13
14if (!defined('DC_CONTEXT_ADMIN')) { exit; }
15
16
17
18$post_id = '';
19$cat_id = '';
20$post_dt = '';
21$post_format = $core->auth->getOption('post_format');
22$post_password = '';
23$post_url = '';
24$post_lang = $core->auth->getInfo('user_lang');
25$post_title = '';
26$post_excerpt = '';
27$post_excerpt_xhtml = '';
28$post_content = '';
29$post_content_xhtml = '';
30$post_notes = '';
31$post_status = $core->auth->getInfo('user_post_status');
32$post_selected = false;
33if (version_compare(DC_VERSION,'2.2-alpha','>=')) {
34     $post_open_comment = $core->blog->settings->system->allow_comments;
35     $post_open_tb = $core->blog->settings->system->allow_trackbacks;
36} else {
37     $post_open_comment = $core->blog->settings->allow_comments;
38     $post_open_tb = $core->blog->settings->allow_trackbacks;
39}
40
41$post_media = array();
42
43$params['post_type']='galitem';
44$can_view_page = true;
45$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
46$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
47
48$core->media = new dcMedia($core);
49$core->meta = new dcMeta($core);
50
51
52/*
53$post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />';
54$post_link = '<a href="post.php?id=%s" title="%s">%s</a>';
55*/
56$next_link = $prev_link = $next_headlink = $prev_headlink = null;
57
58$item_headlink = '<link rel="%s" title="%s" href="plugin.php?p=gallery&amp;m=item&amp;id=%s" />';
59$item_link = '<a href="plugin.php?p=gallery&amp;m=item&amp;id=%s" title="%s">%s</a>';
60
61
62# If user can't publish
63if (!$can_publish) {
64     $post_status = -2;
65}
66
67# Getting categories
68$categories_combo = array('&nbsp;' => '');
69try {
70     $categories = $core->blog->getCategories();
71     while ($categories->fetch()) {
72          $categories_combo[html::escapeHTML($categories->cat_title)] = $categories->cat_id;
73     }
74} catch (Exception $e) { }
75
76# Status combo
77foreach ($core->blog->getAllPostStatus() as $k => $v) {
78     $status_combo[$v] = (string) $k;
79}
80
81# Formaters combo
82foreach ($core->getFormaters() as $v) {
83     $formaters_combo[$v] = $v;
84}
85
86
87if (empty($_REQUEST['id'])) {
88     $core->error->add(__('This entry does not exist.'));
89     $can_view_page = false;
90} else {
91     $params['post_id'] = $_REQUEST['id'];
92     
93     $post = $core->gallery->getGalImageMedia($params);
94     /*$post->extend(rsExtImage);*/
95     
96     if ($post->isEmpty())
97     {
98          $core->error->add(__('This entry does not exist.'));
99          $can_view_page = false;
100     }
101     else
102     {
103          $media=$core->media->getFile($post->media_id);
104          $post_id = $post->post_id;
105          $cat_id = $post->cat_id;
106          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
107          $post_format = $post->post_format;
108          $post_password = $post->post_password;
109          $post_url = $post->post_url;
110          $post_lang = $post->post_lang;
111          $post_title = $post->post_title;
112          $post_excerpt = $post->post_excerpt;
113          $post_excerpt_xhtml = $post->post_excerpt_xhtml;
114          $post_content = $post->post_content;
115          if (trim($post_content) === "///html\n<p></p>\n///" || trim($post_content) == '')
116               $post_content = '';
117          $post_content_xhtml = $post->post_content_xhtml;
118          if (trim($post_content_xhtml) === '<p></p>' || trim($post_content_xhtml) == '')
119               $post_content_xhtml = '';
120          $post_notes = $post->post_notes;
121          $post_status = $post->post_status;
122          $post_selected = (boolean) $post->post_selected;
123          $post_open_comment = (boolean) $post->post_open_comment;
124          $post_open_tb = (boolean) $post->post_open_tb;
125          $page_title = __('Edit image');
126         
127          $can_edit_post = $post->isEditable();
128          $img_gals = $core->gallery->getImageGalleries($post_id);
129         
130          $next_rs = $core->gallery->getNextGalleryItem($post,1);
131          $prev_rs = $core->gallery->getNextGalleryItem($post,-1);
132          if ($next_rs !== null) {
133               $next_link = sprintf($item_link,$next_rs->post_id,
134                    html::escapeHTML($next_rs->post_title),__('next item').'&nbsp;&#187;');
135               $next_headlink = sprintf($item_headlink,'next',
136                    html::escapeHTML($next_rs->post_title),$next_rs->post_id);
137          }
138         
139          if ($prev_rs !== null) {
140               $prev_link = sprintf($item_link,$prev_rs->post_id,
141                    html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('previous item'));
142               $prev_headlink = sprintf($item_headlink,'previous',
143                    html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);
144          }
145         
146     }
147}
148
149
150# Format excerpt and content
151if (!empty($_POST) && $can_edit_post)
152{
153     $post_format = $_POST['post_format'];
154     $post_excerpt = $_POST['post_excerpt'];
155     $post_content = $_POST['post_content'];
156
157     /* Enable null post content */
158     if (trim($post_content)==='')
159          $post_content="///html\n<p></p>\n///";
160     
161     if (trim($post_content_xhtml)==='')
162          $post_content_xhtml="<p></p>";
163     
164     $post_title = $_POST['post_title'];
165     
166     $cat_id = (integer) $_POST['cat_id'];
167     
168     if (isset($_POST['post_status'])) {
169          $post_status = (integer) $_POST['post_status'];
170     }
171     
172     if (empty($_POST['post_dt'])) {
173          $post_dt = '';
174     } else {
175          $post_dt = strtotime($_POST['post_dt']);
176          $post_dt = date('Y-m-d H:i',$post_dt);
177     }
178     
179     $post_open_comment = !empty($_POST['post_open_comment']);
180     $post_open_tb = !empty($_POST['post_open_tb']);
181     $post_selected = !empty($_POST['post_selected']);
182     $post_lang = $_POST['post_lang'];
183     $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null;
184     
185     $post_notes = $_POST['post_notes'];
186     if (isset($_POST['post_url'])) {
187          $post_url = $_POST['post_url'];
188     }
189     
190     $core->blog->setPostContent(
191          $post_id,$post_format,$post_lang,
192          $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
193     );
194     
195}
196
197# Create or update post
198if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post)
199{
200     $cur = $core->con->openCursor($core->prefix.'post');
201     
202     $cur->post_title = $post_title;
203     $cur->cat_id = ($cat_id ? $cat_id : null);
204     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : '';
205     $cur->post_format = $post_format;
206     $cur->post_password = $post_password;
207     $cur->post_lang = $post_lang;
208     $cur->post_title = $post_title;
209     $cur->post_excerpt = $post_excerpt;
210     $cur->post_excerpt_xhtml = $post_excerpt_xhtml;
211     $cur->post_content = $post_content;
212     $cur->post_content_xhtml = $post_content_xhtml;
213     $cur->post_notes = $post_notes;
214     $cur->post_status = $post_status;
215     $cur->post_selected = (integer) $post_selected;
216     $cur->post_open_comment = (integer) $post_open_comment;
217     $cur->post_open_tb = (integer) $post_open_tb;
218     $cur->post_type='galitem';   
219
220     if (isset($_POST['post_url'])) {
221          $cur->post_url = $post_url;
222     }
223     
224     # Update post
225     if ($post_id)
226     {
227          try
228          {
229               # --BEHAVIOR-- adminBeforeGalleryItemUpdate
230               $core->callBehavior('adminBeforeGalleryItemUpdate',$cur,$post_id);
231               
232               $core->blog->updPost($post_id,$cur);
233               
234               metaBehaviors::setTags($cur,$post_id);
235
236               # --BEHAVIOR-- adminBeforeGalleryItemUpdate
237               $core->callBehavior('adminAfterGalleryItemUpdate',$cur,$post_id);
238               
239               http::redirect('plugin.php?p=gallery&m=item&id='.$post_id.'&upd=1');
240          }
241          catch (Exception $e)
242          {
243               $core->error->add($e->getMessage());
244          }
245     }
246     else
247     {
248          $cur->user_id = $core->auth->userID();
249         
250          try
251          {
252         
253               # --BEHAVIOR-- adminBeforeGalleryItemCreate
254               $core->callBehavior('adminBeforeGalleryItemCreate',$cur);
255         
256               $return_id = $core->blog->addPost($cur);
257               
258               # --BEHAVIOR-- adminAfterGalleryItemCreate
259               $core->callBehavior('adminAfterGalleryItemCreate',$cur,$return_id);
260         
261               http::redirect('plugin.php?p=gallery&m=gal&id='.$return_id.'&crea=1');
262          }
263          catch (Exception $e)
264          {
265               $core->error->add($e->getMessage());
266          }
267     }
268}
269?>
270<html>
271<head>
272  <title>Gallery</title>
273<?php echo dcPage::jsDatePicker().
274     dcPage::jsToolBar().
275     dcPage::jsModal().
276     dcPage::jsLoad('index.php?pf=gallery/js/_item.js').
277     dcPage::jsLoad('index.php?pf=gallery/js/posttag.js').
278     dcPage::jsConfirmClose('entry-form').
279     dcPage::jsPageTabs('edit-entry').
280     metaBehaviors::postHeaders().
281     $core->callBehavior('adminGalleryItemHeaders'); ?>
282
283  <link rel="stylesheet" type="text/css" href="index.php?pf=gallery/admin_css/style.css" />
284
285 
286</script>
287</head>
288<body>
289<?php
290/* DISPLAY
291-------------------------------------------------------- */
292$default_tab = 'edit-entry';
293if (!$can_edit_post) {
294     $default_tab = '';
295}
296if (!empty($_GET['co'])) {
297     $default_tab = 'comments';
298}
299
300if (!empty($_GET['upd'])) {
301          echo '<p class="message">'.__('The image has been successfully updated.').'</p>';
302}
303elseif (!empty($_GET['crea'])) {
304          echo '<p class="message">'.__('The image has been successfully created.').'</p>';
305}
306elseif (!empty($_GET['attached'])) {
307     echo '<p class="message">'.__('File has been successfully attached.').'</p>';
308}
309elseif (!empty($_GET['rmattach'])) {
310     echo '<p class="message">'.__('Attachment has been successfully removed.').'</p>';
311}
312
313# XHTML conversion
314if (!empty($_GET['xconv']))
315{
316     $post_excerpt = $post_excerpt_xhtml;
317     $post_content = $post_content_xhtml;
318     $post_format = 'xhtml';
319     
320     echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your post.').'</p>';
321}
322
323
324if ($post_id)
325{
326     echo '<p>';
327     if ($prev_link) {
328          echo $prev_link.' - ';
329     }
330     if ($post->post_status == 1) {
331          echo '<a id="post-preview" href="'.$post->getURL().'" class="button">'.__('view item').'</a>';
332     } else {
333          $preview_url =
334          $core->blog->url.$core->url->getBase('imagepreview').'/'.
335          $core->auth->userID().'/'.
336          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
337          '/'.$post->post_url;
338          echo '<a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview image').'</a>';
339     }
340     
341     if ($next_link) {
342          echo ' - '.$next_link;
343     }
344
345     # --BEHAVIOR-- adminGalleryItemNavLinks
346     $core->callBehavior('adminGalleryItemNavLinks',isset($post) ? $post : null);
347     
348     echo '</p>';
349}
350
351
352if ($core->error->flag()) {
353     echo
354     '<div class="error"><strong>'.__('Errors:').'</strong>'.
355     $core->error->toHTML().
356     '</div>';
357}
358
359echo '<h2>'.html::escapeHTML($core->blog->name).' &gt; '.__('Galleries').' &gt; '.__('Entries').' &gt; '.$page_title.'</h2>';
360# Exit if we cannot view page
361if (!$can_view_page) {
362     exit;
363}
364echo '<p><a href="plugin.php?p=gallery" class="multi-part">'.__('Galleries').'</a></p>';
365echo '<p><a href="plugin.php?p=gallery&amp;m=items" class="multi-part">'.__('Images').'</a></p>';
366echo '<div id="edit-entry" class="multi-part" title="'. __('Image').'">';
367echo "<fieldset><legend>".__('Information')."</legend>";
368echo '<div class="three-cols">'.
369     '<div class="col">'.
370     '<img style="float:left;margin-right: 20px;" src="'.$media->media_thumb['t'].'" alt="'.$media->media_title.'" />'.
371     '</div>'.
372     '<div class="col">'.
373     '<h3>'.__('Media').'</h3>'.
374     '<p><a href="media_item.php?id='.$media->media_id.'&amp;popup=0">'.__('View associated media').'</a></p>';
375
376$img_gals_txt = ($img_gals->count() > 1)?__('This image belongs to %d galleries'):__('This image belongs to %d gallery');
377
378echo '</div>'.
379     '<div class="col">'.
380     '<h3>'.__('Galleries').'</h3>'.
381     '<p>'.sprintf($img_gals_txt,$img_gals->count()).' :</p>';
382if ($img_gals->count() != 0) {
383     echo '<ul>';
384     while ($img_gals->fetch()) {
385          echo '<li><a href="plugin.php?p=gallery&amp;m=gal&amp;id='.$img_gals->post_id.'" alt="'.$img_gals->post_title.'">'.$img_gals->post_title.'</a></li>';
386     }
387     echo '</ul>';
388}
389     
390echo '</div>'.
391     '</div>';
392echo "</fieldset></div>";
393
394/* Post form if we can edit post
395-------------------------------------------------------- */
396if ($can_edit_post)
397{
398?>
399<?php
400     echo '<form action="plugin.php?p=gallery&amp;m=item" method="post" id="entry-form">';
401     echo '<div id="entry-sidebar">'.
402     
403     '<p><label>'.__('Category:').
404     form::combo('cat_id',$categories_combo,$cat_id,'maximal',3).
405     '</label></p>'.
406     
407     '<p><label>'.__('Gallery status:').
408     form::combo('post_status',$status_combo,$post_status,'',3,!$can_publish).
409     '</label></p>'.
410     
411     '<p><label>'.__('Published on:').
412     form::field('post_dt',16,16,$post_dt,'',3).
413     '</label></p>'.
414     
415     '<p><label>'.__('Text formating:').
416     form::combo('post_format',$formaters_combo,$post_format,'',3).
417     ($post_id && $post_format != 'xhtml' ? '<a href="plugin.php?p=gallery&amp;m=item&amp;id='.$post_id.'&amp;xconv=1">'.__('Convert to XHTML').'</a>' : '').
418     '</label></p>'.
419     
420     '<p><label class="classic">'.form::checkbox('post_open_comment',1,$post_open_comment,'',3).' '.
421     __('Accept comments').'</label></p>'.
422     '<p><label class="classic">'.form::checkbox('post_open_tb',1,$post_open_tb,'',3).' '.
423     __('Accept trackbacks').'</label></p>'.
424     '<p><label class="classic">'.form::checkbox('post_selected',1,$post_selected,'',3).' '.
425     __('Selected image').'</label></p>'.
426     
427/*   '<p><label>'.__('Entry password:').
428     form::field('post_password',10,32,html::escapeHTML($post_password),'maximal',3).
429     '</label></p>'.*/
430     
431     '<div class="lockable">'.
432     '<p><label>'.__('Basename:').
433     form::field('post_url',10,255,html::escapeHTML($post_url),'maximal',3).
434     '</label></p>'.
435     '<p class="form-note warn">'.
436     __('Warning: If you set the URL manually, it may conflict with another entry.').
437     '</p>'.
438     '</div>'.
439     
440     '<p><label>'.__('Entry lang:').
441     form::field('post_lang',5,255,html::escapeHTML($post_lang),'',3).
442     '</label></p>';
443     if (isset($post))
444          metaBehaviors::tagsField($post);
445
446     # --BEHAVIOR-- adminGalleryFormSidebar
447     $core->callBehavior('adminGalleryItemFormSidebar',isset($post) ? $post : null);
448     
449     echo '</div>';      // End #entry-sidebar
450     
451     echo '<div id="entry-content"><fieldset class="constrained">';
452     
453     echo
454     '<p class="col"><label class="required" title="'.__('Required field').'">'.__('Title:').
455     form::field('post_title',20,255,html::escapeHTML($post_title),'maximal',2).
456     '</label></p>'.
457     
458     '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').
459     '</label> '.
460     form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt),'',2).
461     '</p>'.
462     
463     '<p class="area" id="content-area"><label '.
464     'for="post_content">'.__('Content:').
465     '</label> '.
466     form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content),'',2).
467     '</p>'.
468     
469     '<p class="area" id="notes-area"><label>'.__('Notes:').'</label>'.
470     form::textarea('post_notes',50,5,html::escapeHTML($post_notes),'',2).
471     '</p>';
472
473     # --BEHAVIOR-- adminGalleryItemForm
474     $core->callBehavior('adminGalleryItemForm',isset($post) ? $post : null);
475     
476     
477     echo
478     '<p>'.
479     $core->formNonce().
480     ($post_id ? form::hidden('id',$post_id) : '').
481     '<input type="submit" value="'.__('save').' (s)" tabindex="4" '.
482     'accesskey="s" name="save" /> '.
483     '</p>';
484     
485     echo '</fieldset></div>';          // End #entry-content
486     echo '</form>';
487     
488     /*if ($post_id && $post->post_status == 1) {
489          echo '<br /><p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'.
490          __('Ping blogs').'</a></p>';
491     }*/
492     
493} // if canedit post
494echo '<p><a href="plugin.php?p=gallery&amp;m=newitems" class="multi-part">'.__('Manage new items').'</a></p>';
495echo '<p><a href="plugin.php?p=gallery&amp;m=options" class="multi-part">'.__('Options').'</a></p>';
496if ($core->auth->isSuperAdmin())
497     echo '<p><a href="plugin.php?p=gallery&amp;m=maintenance" class="multi-part">'.__('Maintenance').'</a></p>';
498?>
499</body>
500</html>
Note: See TracBrowser for help on using the repository browser.

Sites map