Dotclear

source: admin/media_item.php @ 1605:14d1360a6f7b

Revision 1605:14d1360a6f7b, 18.8 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

Typos. Thanks to Brol.

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

Sites map