Dotclear

source: admin/media_item.php @ 918:7480ab529b0a

Revision 918:7480ab529b0a, 17.4 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Display status of entry in list of entries containing current media, fixes #1128

Line 
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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('media,media_admin');
16
17$tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab'];
18
19$post_id = !empty($_GET['post_id']) ? (integer) $_GET['post_id'] : null;
20if ($post_id) {
21     $post = $core->blog->getPosts(array('post_id'=>$post_id));
22     if ($post->isEmpty()) {
23          $post_id = null;
24     }
25     $post_title = $post->post_title;
26     unset($post);
27}
28
29$file = null;
30$popup = (integer) !empty($_GET['popup']);
31$page_url = 'media_item.php?popup='.$popup.'&post_id='.$post_id;
32$media_page_url = 'media.php?popup='.$popup.'&post_id='.$post_id;
33
34$id = !empty($_REQUEST['id']) ? (integer) $_REQUEST['id'] : '';
35
36if ($popup) {
37     $open_f = array('dcPage','openPopup');
38     $close_f = array('dcPage','closePopup');
39} else {
40     $open_f = array('dcPage','open');
41     $close_f = create_function('',"dcPage::helpBlock('core_media'); dcPage::close();");
42}
43
44$core_media_writable = false;
45try
46{
47     $core->media = new dcMedia($core);
48     
49     if ($id) {
50          $file = $core->media->getFile($id);
51     }
52     
53     if ($file === null) {
54          throw new Exception(__('Not a valid file'));
55     }
56     
57     $core->media->chdir(dirname($file->relname));
58     $core_media_writable = $core->media->writable();
59     
60     # Prepare directories combo box
61     $dirs_combo = array();
62     foreach ($core->media->getRootDirs() as $v) {
63          if ($v->w) {
64               $dirs_combo['/'.$v->relname] = $v->relname;
65          }
66     }
67     ksort($dirs_combo);
68}
69catch (Exception $e)
70{
71     $core->error->add($e->getMessage());
72}
73
74# Upload a new file
75if ($file && !empty($_FILES['upfile']) && $file->editable && $core_media_writable)
76{
77     try {
78          files::uploadStatus($_FILES['upfile']);
79          $core->media->uploadFile($_FILES['upfile']['tmp_name'],$file->basename,null,false,true);
80          http::redirect($page_url.'&id='.$id.'&fupl=1');
81     } catch (Exception $e) {
82          $core->error->add($e->getMessage());
83     }
84}
85
86# Update file
87if ($file && !empty($_POST['media_file']) && $file->editable && $core_media_writable)
88{
89     $newFile = clone $file;
90     
91     $newFile->basename = $_POST['media_file'];
92     
93     if ($_POST['media_path']) {
94          $newFile->dir = $_POST['media_path'];
95          $newFile->relname = $_POST['media_path'].'/'.$newFile->basename;
96     } else {
97          $newFile->dir = '';
98          $newFile->relname = $newFile->basename;
99     }
100     $newFile->media_title = $_POST['media_title'];
101     $newFile->media_dt = strtotime($_POST['media_dt']);
102     $newFile->media_dtstr = $_POST['media_dt'];
103     $newFile->media_priv = !empty($_POST['media_private']);
104     
105     try {
106          $core->media->updateFile($file,$newFile);
107          http::redirect($page_url.'&id='.$id.'&fupd=1&tab=media-details-tab');
108     } catch (Exception $e) {
109          $core->error->add($e->getMessage());
110     }
111}
112
113# Update thumbnails
114if (!empty($_POST['thumbs']) && $file->media_type == 'image' && $file->editable && $core_media_writable)
115{
116     try {
117          $foo = null;
118          $core->media->mediaFireRecreateEvent($file);
119          http::redirect($page_url.'&id='.$id.'&thumbupd=1&tab=media-details-tab');
120     } catch (Exception $e) {
121          $core->error->add($e->getMessage());
122     }
123}
124
125# Unzip file
126if (!empty($_POST['unzip']) && $file->type == 'application/zip' && $file->editable && $core_media_writable)
127{
128     try {
129          $unzip_dir = $core->media->inflateZipFile($file,$_POST['inflate_mode'] == 'new');
130          http::redirect($media_page_url.'&d='.$unzip_dir.'&unzipok=1');
131     } catch (Exception $e) {
132          $core->error->add($e->getMessage());
133     }
134}
135
136# Function to get image title based on meta
137function dcGetImageTitle($file,$pattern)
138{
139     $res = array();
140     $pattern = preg_split('/\s*;;\s*/',$pattern);
141     $sep = ', ';
142     
143     foreach ($pattern as $v) {
144          if ($v == 'Title') {
145               $res[] = $file->media_title;
146          } elseif ($file->media_meta->{$v}) {
147               $res[] = (string) $file->media_meta->{$v};
148          } elseif (preg_match('/^Date\((.+?)\)$/u',$v,$m)) {
149               $res[] = dt::str($m[1],$file->media_dt);
150          } elseif (preg_match('/^DateTimeOriginal\((.+?)\)$/u',$v,$m) && $file->media_meta->DateTimeOriginal) {
151               $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal);
152          } elseif (preg_match('/^separator\((.*?)\)$/u',$v,$m)) {
153               $sep = $m[1];
154          }
155     }
156     return implode($sep,$res);
157}
158
159/* DISPLAY Main page
160-------------------------------------------------------- */
161$starting_scripts = dcPage::jsLoad('js/_media_item.js');
162if ($popup) {
163     $starting_scripts .=
164     dcPage::jsLoad('js/jsToolBar/popup_media.js');
165}
166call_user_func($open_f,__('Media manager'),
167     $starting_scripts.
168     dcPage::jsDatePicker().
169     dcPage::jsPageTabs($tab)
170);
171
172if ($file === null) {
173     call_user_func($close_f);
174     exit;
175}
176
177if (!empty($_GET['fupd']) || !empty($_GET['fupl'])) {
178     dcPage::message(__('File has been successfully updated.'));
179}
180if (!empty($_GET['thumbupd'])) {
181     dcPage::message(__('Thumbnails have been successfully updated.'));
182}
183
184echo '<h2><a href="'.html::escapeURL($media_page_url).'">'.__('Media manager').'</a>'.
185' / '.$core->media->breadCrumb(html::escapeURL($media_page_url).'&amp;d=%s').
186'<span class="page-title">'.$file->basename.'</span></h2>';
187
188# Insertion popup
189if ($popup)
190{
191     $media_desc = $file->media_title;
192     
193     echo
194     '<div id="media-insert" class="multi-part" title="'.__('Insert media item').'">'.
195     '<form id="media-insert-form" action="" method="get">';
196     
197     if ($file->media_type == 'image')
198     {
199          $media_type = 'image';
200          $media_desc = dcGetImageTitle($file,$core->blog->settings->system->media_img_title_pattern);
201          if ($media_desc == $file->basename) {
202               $media_desc = '';
203          }
204
205          $media_img_default_size = $core->blog->settings->system->media_img_default_size;
206          if ($media_img_default_size == '') {
207               $media_img_default_size = 'm';
208          }
209          $media_img_default_alignment = $core->blog->settings->system->media_img_default_alignment;
210          if ($media_img_default_alignment == '') {
211               $media_img_default_alignment = 'none';
212          }
213          $media_img_default_link = (boolean)$core->blog->settings->system->media_img_default_link;
214
215          echo
216          '<h3>'.__('Image size:').'</h3> ';
217         
218          $s_checked = false;
219          echo '<p>';
220          foreach (array_reverse($file->media_thumb) as $s => $v) {
221               $s_checked = ($s == $media_img_default_size);
222               echo '<label class="classic">'.
223               form::radio(array('src'),html::escapeHTML($v),$s_checked).' '.
224               $core->media->thumb_sizes[$s][2].'</label><br /> ';
225          }
226          $s_checked = (!isset($file->media_thumb[$media_img_default_size]));
227          echo '<label class="classic">'.
228          form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> ';
229          echo '</p>';
230         
231         
232          echo '<h3>'.__('Image alignment').'</h3>';
233          $i_align = array(
234               'none' => array(__('None'),($media_img_default_alignment == 'none' ? 1 : 0)),
235               'left' => array(__('Left'),($media_img_default_alignment == 'left' ? 1 : 0)),
236               'right' => array(__('Right'),($media_img_default_alignment == 'right' ? 1 : 0)),
237               'center' => array(__('Center'),($media_img_default_alignment == 'center' ? 1 : 0))
238          );
239         
240          echo '<p>';
241          foreach ($i_align as $k => $v) {
242               echo '<label class="classic">'.
243               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
244          }
245          echo '</p>';
246         
247          echo
248          '<h3>'.__('Image insertion').'</h3>'.
249          '<p>'.
250          '<label for="insert1" class="classic">'.form::radio(array('insertion','insert1'),'simple',!$media_img_default_link).
251          __('As a single image').'</label><br />'.
252          '<label for="insert2" class="classic">'.form::radio(array('insertion','insert2'),'link',$media_img_default_link).
253          __('As a link to original image').'</label>'.
254          '</p>';
255     }
256     elseif ($file->type == 'audio/mpeg3')
257     {
258          $media_type = 'mp3';
259         
260          echo '<h3>'.__('MP3 disposition').'</h3>';
261          dcPage::message(__("Please note that you cannot insert mp3 files with visual editor."),false);
262         
263          $i_align = array(
264               'none' => array(__('None'),0),
265               'left' => array(__('Left'),0),
266               'right' => array(__('Right'),0),
267               'center' => array(__('Center'),1)
268          );
269         
270          echo '<p>';
271          foreach ($i_align as $k => $v) {
272               echo '<label for="alignment" class="classic">'.
273               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
274          }
275         
276          $public_player_style = unserialize($core->blog->settings->themes->mp3player_style);
277          $public_player = dcMedia::mp3player($file->file_url,$core->blog->getQmarkURL().'pf=player_mp3.swf',$public_player_style);
278          echo form::hidden('public_player',html::escapeHTML($public_player));
279          echo '</p>';
280     }
281     elseif ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v')
282     {
283          $media_type = 'flv';
284         
285          dcPage::message(__("Please note that you cannot insert video files with visual editor."),false);
286         
287          echo
288          '<h3>'.__('Video size').'</h3>'.
289          '<p><label for="video_w" class="classic">'.__('Width:').' '.
290          form::field('video_w',3,4,400).'  '.
291          '<label for="video_h" class="classic">'.__('Height:').' '.
292          form::field('video_h',3,4,300).
293          '</p>';
294         
295          echo '<h3>'.__('Video disposition').'</h3>';
296         
297          $i_align = array(
298               'none' => array(__('None'),0),
299               'left' => array(__('Left'),0),
300               'right' => array(__('Right'),0),
301               'center' => array(__('Center'),1)
302          );
303         
304          echo '<p>';
305          foreach ($i_align as $k => $v) {
306               echo '<label for="alignment" class="classic">'.
307               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
308          }
309         
310          $public_player_style = unserialize($core->blog->settings->themes->flvplayer_style);
311          $public_player = dcMedia::flvplayer($file->file_url,$core->blog->getQmarkURL().'pf=player_flv.swf',$public_player_style);
312          echo form::hidden('public_player',html::escapeHTML($public_player));
313          echo '</p>';
314     }
315     else
316     {
317          $media_type = 'default';
318          echo '<p>'.__('Media item will be inserted as a link.').'</p>';
319     }
320     
321     echo
322     '<p><a id="media-insert-cancel" class="button" href="#">'.__('Cancel').'</a> - '.
323     '<strong><a id="media-insert-ok" class="button" href="#">'.__('Insert').'</a></strong>'.
324     form::hidden(array('type'),html::escapeHTML($media_type)).
325     form::hidden(array('title'),html::escapeHTML($file->media_title)).
326     form::hidden(array('description'),html::escapeHTML($media_desc)).
327     form::hidden(array('url'),$file->file_url).
328     '</p>';
329     
330     echo '</form></div>';
331}
332
333echo
334'<div class="multi-part" title="'.__('Media details').'" id="media-details-tab">'.
335'<p id="media-icon"><img src="'.$file->media_icon.'" alt="" /></p>';
336
337echo
338'<div id="media-details">';
339
340if ($file->media_image)
341{
342     $thumb_size = !empty($_GET['size']) ? $_GET['size'] : 's';
343     
344     if (!isset($core->media->thumb_sizes[$thumb_size]) && $thumb_size != 'o') {
345          $thumb_size = 's';
346     }
347     
348     echo '<p>'.__('Available sizes:').' ';
349     foreach (array_reverse($file->media_thumb) as $s => $v)
350     {
351          $strong_link = ($s == $thumb_size) ? '<strong>%s</strong>' : '%s';
352          printf($strong_link,'<a href="'.html::escapeURL($page_url).
353          '&amp;id='.$id.'&amp;size='.$s.'&amp;tab=media-details-tab">'.$core->media->thumb_sizes[$s][2].'</a> | ');
354     }
355     echo '<a href="'.html::escapeURL($page_url).'&amp;id='.$id.'&amp;size=o&amp;tab=media-details-tab">'.__('original').'</a>';
356     echo '</p>';
357     
358     if (isset($file->media_thumb[$thumb_size])) {
359          echo '<p><img src="'.$file->media_thumb[$thumb_size].'" alt="" /></p>';
360     } elseif ($thumb_size == 'o') {
361          $S = getimagesize($file->file);
362          $class = ($S[1] > 500) ? ' class="overheight"' : '';
363          unset($S);
364          echo '<p id="media-original-image"'.$class.'><img src="'.$file->file_url.'" alt="" /></p>';
365     }
366}
367
368if ($file->type == 'audio/mpeg3')
369{
370     echo dcMedia::mp3player($file->file_url,'index.php?pf=player_mp3.swf');
371}
372
373if ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v')
374{
375     echo dcMedia::flvplayer($file->file_url,'index.php?pf=player_flv.swf');
376}
377
378echo
379'<h3>'.__('Media details').'</h3>'.
380'<ul>'.
381     '<li><strong>'.__('File owner:').'</strong> '.$file->media_user.'</li>'.
382     '<li><strong>'.__('File type:').'</strong> '.$file->type.'</li>'.
383     '<li><strong>'.__('File size:').'</strong> '.files::size($file->size).'</li>'.
384     '<li><strong>'.__('File URL:').'</strong> <a href="'.$file->file_url.'">'.$file->file_url.'</a></li>'.
385'</ul>';
386
387if (empty($_GET['find_posts']))
388{
389     echo
390     '<p><strong><a href="'.html::escapeHTML($page_url).'&amp;id='.$id.'&amp;find_posts=1&amp;tab=media-details-tab">'.
391     __('Show entries containing this media').'</a></strong></p>';
392}
393else
394{
395     echo '<h3>'.__('Entries containing this media').'</h3>';
396     $params = array(
397          'post_type' => '',
398          'from' => 'LEFT OUTER JOIN '.$core->prefix.'post_media PM ON P.post_id = PM.post_id ',
399          'sql' => 'AND ('.
400               'PM.media_id = '.(integer) $id.' '.
401               "OR post_content_xhtml LIKE '%".$core->con->escape($file->relname)."%' ".
402               "OR post_excerpt_xhtml LIKE '%".$core->con->escape($file->relname)."%' "
403     );
404     
405     if ($file->media_image)
406     { # We look for thumbnails too
407          if (preg_match('#^http(s)?://#',$core->blog->settings->system->public_url)) {
408               $media_root = $core->blog->settings->system->public_url;
409          } else {
410               $media_root = $core->blog->host.path::clean($core->blog->settings->system->public_url).'/';
411          }
412          foreach ($file->media_thumb as $v) {
413               $v = preg_replace('/^'.preg_quote($media_root,'/').'/','',$v);
414               $params['sql'] .= "OR post_content_xhtml LIKE '%".$core->con->escape($v)."%' ";
415               $params['sql'] .= "OR post_excerpt_xhtml LIKE '%".$core->con->escape($v)."%' ";
416          }
417     }
418     
419     $params['sql'] .= ') ';
420     
421     $rs = $core->blog->getPosts($params);
422     
423     if ($rs->isEmpty())
424     {
425          echo '<p>'.__('No entry seems contain this media.').'</p>';
426     }
427     else
428     {
429          echo '<ul>';
430          while ($rs->fetch()) {
431               $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
432               switch ($rs->post_status) {
433                    case 1:
434                         $img_status = sprintf($img,__('published'),'check-on.png');
435                         break;
436                    case 0:
437                         $img_status = sprintf($img,__('unpublished'),'check-off.png');
438                         break;
439                    case -1:
440                         $img_status = sprintf($img,__('scheduled'),'scheduled.png');
441                         break;
442                    case -2:
443                         $img_status = sprintf($img,__('pending'),'check-wrn.png');
444                         break;
445               }
446               echo '<li>'.$img_status.' '.'<a href="'.$core->getPostAdminURL($rs->post_type,$rs->post_id).'">'.
447                    $rs->post_title.'</a>'.
448                    ($rs->post_type != 'post' ? ' ('.html::escapeHTML($rs->post_type).')' : '').
449                    ' - '.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->post_dt).'</li>';
450          }
451          echo '</ul>';
452     }
453}
454
455if ($file->type == 'image/jpeg')
456{
457     echo '<h3>'.__('Image details').'</h3>';
458     
459     if (count($file->media_meta) == 0)
460     {
461          echo '<p>'.__('No detail').'</p>';
462     }
463     else
464     {
465          echo '<ul>';
466          foreach ($file->media_meta as $k => $v)
467          {
468               if ((string) $v) {
469                    echo '<li><strong>'.$k.':</strong> '.html::escapeHTML($v).'</li>';
470               }
471          }
472          echo '</ul>';
473     }
474}
475
476if ($file->editable && $core_media_writable)
477{
478     if ($file->media_type == 'image')
479     {
480          echo
481          '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'.
482          '<fieldset><legend>'.__('Update thumbnails').'</legend>'.
483          '<p>'.__('This will create or update thumbnails for this image.').'</p>'.
484          '<p><input type="submit" name="thumbs" value="'.__('Update thumbnails').'" />'.
485          form::hidden(array('id'),$id).
486          $core->formNonce().'</p>'.
487          '</fieldset></form>';
488     }
489     
490     if ($file->type == 'application/zip')
491     {
492          $inflate_combo = array(
493               __('Extract in a new directory') => 'new',
494               __('Extract in current directory') => 'current'
495          );
496         
497          echo
498          '<form class="clear" id="file-unzip" action="'.html::escapeURL($page_url).'" method="post">'.
499          '<fieldset><legend>'.__('Extract archive').'</legend>'.
500          '<ul>'.
501          '<li><strong>'.__('Extract in a new directory').'</strong> : '.
502          __('This will extract archive in a new directory that should not exist yet.').'</li>'.
503          '<li><strong>'.__('Extract in current directory').'</strong> : '.
504          __('This will extract archive in current directory and will overwrite existing files or directory.').'</li>'.
505          '</ul>'.
506          '<p><label for="inflate_mode" class="classic">'.__('Extract mode:').' '.
507          form::combo('inflate_mode',$inflate_combo,'new').'</label> '.
508          '<input type="submit" name="unzip" value="'.__('Extract').'" />'.
509          form::hidden(array('id'),$id).
510          $core->formNonce().'</p>'.
511          '</fieldset></form>';
512     }
513     
514     echo
515     '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'.
516     '<fieldset><legend>'.__('Change media properties').'</legend>'.
517     '<p><label for="media_file">'.__('File name:').
518     form::field('media_file',30,255,html::escapeHTML($file->basename)).'</label></p>'.
519     '<p><label for="media_title">'.__('File title:').
520     form::field('media_title',30,255,html::escapeHTML($file->media_title)).'</label></p>'.
521     '<p><label for="media_dt">'.__('File date:').
522     form::field('media_dt',16,16,html::escapeHTML($file->media_dtstr)).'</label></p>'.
523     '<p><label for="media_private" class="classic">'.form::checkbox('media_private',1,$file->media_priv).' '.
524     __('Private').'</label></p>'.
525     '<p><label for="media_path">'.__('New directory:').
526     form::combo('media_path',$dirs_combo,dirname($file->relname)).'</label></p>'.
527     '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'.
528     form::hidden(array('id'),$id).
529     $core->formNonce().'</p>'.
530     '</fieldset></form>';
531     
532     echo
533     '<form class="clear" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data">'.
534     '<fieldset><legend>'.__('Change file').'</legend>'.
535     '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'.
536     '<p><label for="upfile">'.__('Choose a file:').
537     ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).') '.
538     '<input type="file" id="upfile" name="upfile" size="35" />'.
539     '</label></p>'.
540     '<p><input type="submit" value="'.__('Send').'" />'.
541     form::hidden(array('id'),$id).
542     $core->formNonce().'</p>'.
543     '</fieldset></form>';
544
545     # --BEHAVIOR-- adminMediaItemForm
546     $core->callBehavior('adminMediaItemForm',$file);
547}
548
549echo
550'</div>'.
551'</div>';
552
553call_user_func($close_f);
554?>
Note: See TracBrowser for help on using the repository browser.

Sites map