Dotclear

source: admin/media_item.php @ 861:3e2e678fef61

Revision 861:3e2e678fef61, 16.3 KB checked in by JcDenis, 13 years ago (diff)

Fixes tabs links in media item popup, fixes #1283

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     echo '<p class="message">'.__('File has been successfully updated.').'</p>';
179}
180if (!empty($_GET['thumbupd'])) {
181     echo '<p class="message">'.__('Thumbnails have been successfully updated.').'</p>';
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          echo
206          '<h3>'.__('Image size:').'</h3> ';
207         
208          $s_checked = false;
209          echo '<p>';
210          foreach (array_reverse($file->media_thumb) as $s => $v) {
211               $s_checked = ($s == 'm');
212               echo '<label class="classic">'.
213               form::radio(array('src'),html::escapeHTML($v),$s_checked).' '.
214               $core->media->thumb_sizes[$s][2].'</label><br /> ';
215          }
216          $s_checked = (!isset($file->media_thumb['m']));
217          echo '<label class="classic">'.
218          form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> ';
219          echo '</p>';
220         
221         
222          echo '<h3>'.__('Image alignment').'</h3>';
223          $i_align = array(
224               'none' => array(__('None'),1),
225               'left' => array(__('Left'),0),
226               'right' => array(__('Right'),0),
227               'center' => array(__('Center'),0)
228          );
229         
230          echo '<p>';
231          foreach ($i_align as $k => $v) {
232               echo '<label class="classic">'.
233               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
234          }
235          echo '</p>';
236         
237          echo
238          '<h3>'.__('Image insertion').'</h3>'.
239          '<p>'.
240          '<label for="insert1" class="classic">'.form::radio(array('insertion','insert1'),'simple',true).
241          __('As a single image').'</label><br />'.
242          '<label for="insert2" class="classic">'.form::radio(array('insertion','insert2'),'link',false).
243          __('As a link to original image').'</label>'.
244          '</p>';
245     }
246     elseif ($file->type == 'audio/mpeg3')
247     {
248          $media_type = 'mp3';
249         
250          echo '<h3>'.__('MP3 disposition').'</h3>'.
251          '<p class="message">'.__("Please note that you cannot insert mp3 files with visual editor.").'</p>';
252         
253          $i_align = array(
254               'none' => array(__('None'),0),
255               'left' => array(__('Left'),0),
256               'right' => array(__('Right'),0),
257               'center' => array(__('Center'),1)
258          );
259         
260          echo '<p>';
261          foreach ($i_align as $k => $v) {
262               echo '<label for="alignment" class="classic">'.
263               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
264          }
265         
266          $public_player_style = unserialize($core->blog->settings->themes->mp3player_style);
267          $public_player = dcMedia::mp3player($file->file_url,$core->blog->getQmarkURL().'pf=player_mp3.swf',$public_player_style);
268          echo form::hidden('public_player',html::escapeHTML($public_player));
269          echo '</p>';
270     }
271     elseif ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v')
272     {
273          $media_type = 'flv';
274         
275          echo
276          '<p class="message">'.__("Please note that you cannot insert video files with visual editor.").'</p>';
277         
278          echo
279          '<h3>'.__('Video size').'</h3>'.
280          '<p><label for="video_w" class="classic">'.__('Width:').' '.
281          form::field('video_w',3,4,400).'  '.
282          '<label for="video_h" class="classic">'.__('Height:').' '.
283          form::field('video_h',3,4,300).
284          '</p>';
285         
286          echo '<h3>'.__('Video disposition').'</h3>';
287         
288          $i_align = array(
289               'none' => array(__('None'),0),
290               'left' => array(__('Left'),0),
291               'right' => array(__('Right'),0),
292               'center' => array(__('Center'),1)
293          );
294         
295          echo '<p>';
296          foreach ($i_align as $k => $v) {
297               echo '<label for="alignment" class="classic">'.
298               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
299          }
300         
301          $public_player_style = unserialize($core->blog->settings->themes->flvplayer_style);
302          $public_player = dcMedia::flvplayer($file->file_url,$core->blog->getQmarkURL().'pf=player_flv.swf',$public_player_style);
303          echo form::hidden('public_player',html::escapeHTML($public_player));
304          echo '</p>';
305     }
306     else
307     {
308          $media_type = 'default';
309          echo '<p>'.__('Media item will be inserted as a link.').'</p>';
310     }
311     
312     echo
313     '<p><a id="media-insert-cancel" class="button" href="#">'.__('Cancel').'</a> - '.
314     '<strong><a id="media-insert-ok" class="button" href="#">'.__('Insert').'</a></strong>'.
315     form::hidden(array('type'),html::escapeHTML($media_type)).
316     form::hidden(array('title'),html::escapeHTML($file->media_title)).
317     form::hidden(array('description'),html::escapeHTML($media_desc)).
318     form::hidden(array('url'),$file->file_url).
319     '</p>';
320     
321     echo '</form></div>';
322}
323
324echo
325'<div class="multi-part" title="'.__('Media details').'" id="media-details-tab">'.
326'<p id="media-icon"><img src="'.$file->media_icon.'" alt="" /></p>';
327
328echo
329'<div id="media-details">';
330
331if ($file->media_image)
332{
333     $thumb_size = !empty($_GET['size']) ? $_GET['size'] : 's';
334     
335     if (!isset($core->media->thumb_sizes[$thumb_size]) && $thumb_size != 'o') {
336          $thumb_size = 's';
337     }
338     
339     echo '<p>'.__('Available sizes:').' ';
340     foreach (array_reverse($file->media_thumb) as $s => $v)
341     {
342          $strong_link = ($s == $thumb_size) ? '<strong>%s</strong>' : '%s';
343          printf($strong_link,'<a href="'.html::escapeURL($page_url).
344          '&amp;id='.$id.'&amp;size='.$s.'&amp;tab=media-details-tab">'.$core->media->thumb_sizes[$s][2].'</a> | ');
345     }
346     echo '<a href="'.html::escapeURL($page_url).'&amp;id='.$id.'&amp;size=o&amp;tab=media-details-tab">'.__('original').'</a>';
347     echo '</p>';
348     
349     if (isset($file->media_thumb[$thumb_size])) {
350          echo '<p><img src="'.$file->media_thumb[$thumb_size].'" alt="" /></p>';
351     } elseif ($thumb_size == 'o') {
352          $S = getimagesize($file->file);
353          $class = ($S[1] > 500) ? ' class="overheight"' : '';
354          unset($S);
355          echo '<p id="media-original-image"'.$class.'><img src="'.$file->file_url.'" alt="" /></p>';
356     }
357}
358
359if ($file->type == 'audio/mpeg3')
360{
361     echo dcMedia::mp3player($file->file_url,'index.php?pf=player_mp3.swf');
362}
363
364if ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v')
365{
366     echo dcMedia::flvplayer($file->file_url,'index.php?pf=player_flv.swf');
367}
368
369echo
370'<h3>'.__('Media details').'</h3>'.
371'<ul>'.
372     '<li><strong>'.__('File owner:').'</strong> '.$file->media_user.'</li>'.
373     '<li><strong>'.__('File type:').'</strong> '.$file->type.'</li>'.
374     '<li><strong>'.__('File size:').'</strong> '.files::size($file->size).'</li>'.
375     '<li><strong>'.__('File URL:').'</strong> <a href="'.$file->file_url.'">'.$file->file_url.'</a></li>'.
376'</ul>';
377
378if (empty($_GET['find_posts']))
379{
380     echo
381     '<p><strong><a href="'.html::escapeHTML($page_url).'&amp;id='.$id.'&amp;find_posts=1&amp;tab=media-details-tab">'.
382     __('Show entries containing this media').'</a></strong></p>';
383}
384else
385{
386     echo '<h3>'.__('Entries containing this media').'</h3>';
387     $params = array(
388          'post_type' => '',
389          'from' => 'LEFT OUTER JOIN '.$core->prefix.'post_media PM ON P.post_id = PM.post_id ',
390          'sql' => 'AND ('.
391               'PM.media_id = '.(integer) $id.' '.
392               "OR post_content_xhtml LIKE '%".$core->con->escape($file->relname)."%' ".
393               "OR post_excerpt_xhtml LIKE '%".$core->con->escape($file->relname)."%' "
394     );
395     
396     if ($file->media_image)
397     { # We look for thumbnails too
398          if (preg_match('#^http(s)?://#',$core->blog->settings->system->public_url)) {
399               $media_root = $core->blog->settings->system->public_url;
400          } else {
401               $media_root = $core->blog->host.path::clean($core->blog->settings->system->public_url).'/';
402          }
403          foreach ($file->media_thumb as $v) {
404               $v = preg_replace('/^'.preg_quote($media_root,'/').'/','',$v);
405               $params['sql'] .= "OR post_content_xhtml LIKE '%".$core->con->escape($v)."%' ";
406               $params['sql'] .= "OR post_excerpt_xhtml LIKE '%".$core->con->escape($v)."%' ";
407          }
408     }
409     
410     $params['sql'] .= ') ';
411     
412     $rs = $core->blog->getPosts($params);
413     
414     if ($rs->isEmpty())
415     {
416          echo '<p>'.__('No entry seems contain this media.').'</p>';
417     }
418     else
419     {
420          echo '<ul>';
421          while ($rs->fetch()) {
422               echo '<li><a href="'.$core->getPostAdminURL($rs->post_type,$rs->post_id).'">'.
423               $rs->post_title.'</a>'.
424               ($rs->post_type != 'post' ? ' ('.html::escapeHTML($rs->post_type).')' : '').
425               ' - '.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->post_dt).'</li>';
426          }
427          echo '</ul>';
428     }
429}
430
431if ($file->type == 'image/jpeg')
432{
433     echo '<h3>'.__('Image details').'</h3>';
434     
435     if (count($file->media_meta) == 0)
436     {
437          echo '<p>'.__('No detail').'</p>';
438     }
439     else
440     {
441          echo '<ul>';
442          foreach ($file->media_meta as $k => $v)
443          {
444               if ((string) $v) {
445                    echo '<li><strong>'.$k.':</strong> '.html::escapeHTML($v).'</li>';
446               }
447          }
448          echo '</ul>';
449     }
450}
451
452if ($file->editable && $core_media_writable)
453{
454     if ($file->media_type == 'image')
455     {
456          echo
457          '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'.
458          '<fieldset><legend>'.__('Update thumbnails').'</legend>'.
459          '<p>'.__('This will create or update thumbnails for this image.').'</p>'.
460          '<p><input type="submit" name="thumbs" value="'.__('Update thumbnails').'" />'.
461          form::hidden(array('id'),$id).
462          $core->formNonce().'</p>'.
463          '</fieldset></form>';
464     }
465     
466     if ($file->type == 'application/zip')
467     {
468          $inflate_combo = array(
469               __('Extract in a new directory') => 'new',
470               __('Extract in current directory') => 'current'
471          );
472         
473          echo
474          '<form class="clear" id="file-unzip" action="'.html::escapeURL($page_url).'" method="post">'.
475          '<fieldset><legend>'.__('Extract archive').'</legend>'.
476          '<ul>'.
477          '<li><strong>'.__('Extract in a new directory').'</strong> : '.
478          __('This will extract archive in a new directory that should not exist yet.').'</li>'.
479          '<li><strong>'.__('Extract in current directory').'</strong> : '.
480          __('This will extract archive in current directory and will overwrite existing files or directory.').'</li>'.
481          '</ul>'.
482          '<p><label for="inflate_mode" class="classic">'.__('Extract mode:').' '.
483          form::combo('inflate_mode',$inflate_combo,'new').'</label> '.
484          '<input type="submit" name="unzip" value="'.__('Extract').'" />'.
485          form::hidden(array('id'),$id).
486          $core->formNonce().'</p>'.
487          '</fieldset></form>';
488     }
489     
490     echo
491     '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'.
492     '<fieldset><legend>'.__('Change media properties').'</legend>'.
493     '<p><label for="media_file">'.__('File name:').
494     form::field('media_file',30,255,html::escapeHTML($file->basename)).'</label></p>'.
495     '<p><label for="media_title">'.__('File title:').
496     form::field('media_title',30,255,html::escapeHTML($file->media_title)).'</label></p>'.
497     '<p><label for="media_dt">'.__('File date:').
498     form::field('media_dt',16,16,html::escapeHTML($file->media_dtstr)).'</label></p>'.
499     '<p><label for="media_private" class="classic">'.form::checkbox('media_private',1,$file->media_priv).' '.
500     __('Private').'</label></p>'.
501     '<p><label for="media_path">'.__('New directory:').
502     form::combo('media_path',$dirs_combo,dirname($file->relname)).'</label></p>'.
503     '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'.
504     form::hidden(array('id'),$id).
505     $core->formNonce().'</p>'.
506     '</fieldset></form>';
507     
508     echo
509     '<form class="clear" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data">'.
510     '<fieldset><legend>'.__('Change file').'</legend>'.
511     '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'.
512     '<p><label for="upfile">'.__('Choose a file:').
513     ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).') '.
514     '<input type="file" id="upfile" name="upfile" size="35" />'.
515     '</label></p>'.
516     '<p><input type="submit" value="'.__('Send').'" />'.
517     form::hidden(array('id'),$id).
518     $core->formNonce().'</p>'.
519     '</fieldset></form>';
520
521     # --BEHAVIOR-- adminMediaItemForm
522     $core->callBehavior('adminMediaItemForm',$file);
523}
524
525echo
526'</div>'.
527'</div>';
528
529call_user_func($close_f);
530?>
Note: See TracBrowser for help on using the repository browser.

Sites map