Dotclear

source: admin/media_item.php @ 3153:942a906c0986

Revision 3153:942a906c0986, 26.3 KB checked in by franck <carnet.franck.paul@…>, 10 years ago (diff)

Media selection mode (single or multiple), first step

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]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
[861]17$tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab'];
18
[2889]19$post_id = !empty($_REQUEST['post_id']) ? (integer) $_REQUEST['post_id'] : null;
[0]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;
[2884]30$popup = (integer) !empty($_REQUEST['popup']);
[3153]31$select = !empty($_REQUEST['select']) ? (integer)$_REQUEST['select'] : 0;  // 0 : none, 1 : single media, >1 : multiple medias
[2751]32$plugin_id = isset($_REQUEST['plugin_id']) ? html::sanitizeURL($_REQUEST['plugin_id']) : '';
[3153]33$page_url_params = array('popup' => $popup,'select' => $select,'post_id' => $post_id);
34$media_page_url_params = array('popup' => $popup,'select' => $select,'post_id' => $post_id);
[2852]35
36if ($plugin_id != '') {
[2872]37     $page_url_params['plugin_id'] = $plugin_id;
38     $media_page_url_params['plugin_id'] = $plugin_id;
[2852]39}
[0]40
41$id = !empty($_REQUEST['id']) ? (integer) $_REQUEST['id'] : '';
42
[2852]43if ($id != '') {
44     $page_url_params ['id'] = $id;
45}
46
[0]47if ($popup) {
48     $open_f = array('dcPage','openPopup');
49     $close_f = array('dcPage','closePopup');
50} else {
51     $open_f = array('dcPage','open');
52     $close_f = create_function('',"dcPage::helpBlock('core_media'); dcPage::close();");
53}
54
55$core_media_writable = false;
56try
57{
58     $core->media = new dcMedia($core);
[2529]59
[0]60     if ($id) {
61          $file = $core->media->getFile($id);
62     }
[2529]63
[0]64     if ($file === null) {
65          throw new Exception(__('Not a valid file'));
66     }
[2529]67
[0]68     $core->media->chdir(dirname($file->relname));
69     $core_media_writable = $core->media->writable();
[2529]70
[0]71     # Prepare directories combo box
72     $dirs_combo = array();
[1103]73     foreach ($core->media->getDBDirs() as $v) {
74          $dirs_combo['/'.$v] = $v;
[0]75     }
[2098]76     # Add parent and direct childs directories if any
77     $core->media->getFSDir();
78     foreach ($core->media->dir['dirs'] as $k => $v) {
79          $dirs_combo['/'.$v->relname] = $v->relname;
80     }
[0]81     ksort($dirs_combo);
82}
83catch (Exception $e)
84{
85     $core->error->add($e->getMessage());
86}
87
88# Upload a new file
89if ($file && !empty($_FILES['upfile']) && $file->editable && $core_media_writable)
90{
91     try {
92          files::uploadStatus($_FILES['upfile']);
93          $core->media->uploadFile($_FILES['upfile']['tmp_name'],$file->basename,null,false,true);
[2256]94
95          dcPage::addSuccessNotice(__('File has been successfully updated.'));
[2852]96          $core->adminurl->redirect('admin.media.item',$page_url_params);
[0]97     } catch (Exception $e) {
98          $core->error->add($e->getMessage());
99     }
100}
101
102# Update file
103if ($file && !empty($_POST['media_file']) && $file->editable && $core_media_writable)
104{
105     $newFile = clone $file;
[2529]106
[0]107     $newFile->basename = $_POST['media_file'];
[2529]108
[0]109     if ($_POST['media_path']) {
110          $newFile->dir = $_POST['media_path'];
111          $newFile->relname = $_POST['media_path'].'/'.$newFile->basename;
112     } else {
113          $newFile->dir = '';
114          $newFile->relname = $newFile->basename;
115     }
116     $newFile->media_title = $_POST['media_title'];
117     $newFile->media_dt = strtotime($_POST['media_dt']);
118     $newFile->media_dtstr = $_POST['media_dt'];
119     $newFile->media_priv = !empty($_POST['media_private']);
[2529]120
[0]121     try {
122          $core->media->updateFile($file,$newFile);
[2256]123
124          dcPage::addSuccessNotice(__('File has been successfully updated.'));
[2852]125          $page_url_params['tab'] = 'media-details-tab';
126          $core->adminurl->redirect('admin.media.item',$page_url_params);
[0]127     } catch (Exception $e) {
128          $core->error->add($e->getMessage());
129     }
130}
131
132# Update thumbnails
133if (!empty($_POST['thumbs']) && $file->media_type == 'image' && $file->editable && $core_media_writable)
134{
135     try {
136          $foo = null;
[2]137          $core->media->mediaFireRecreateEvent($file);
[2529]138
[2256]139          dcPage::addSuccessNotice(__('Thumbnails have been successfully updated.'));
[2852]140          $page_url_params['tab'] = 'media-details-tab';
141          $core->adminurl->redirect('admin.media.item',$page_url_params);
[0]142     } catch (Exception $e) {
143          $core->error->add($e->getMessage());
144     }
145}
146
147# Unzip file
148if (!empty($_POST['unzip']) && $file->type == 'application/zip' && $file->editable && $core_media_writable)
149{
150     try {
151          $unzip_dir = $core->media->inflateZipFile($file,$_POST['inflate_mode'] == 'new');
[2529]152
[2256]153          dcPage::addSuccessNotice(__('Zip file has been successfully extracted.'));
[2852]154          $media_page_url_params['d'] = $unzip_dir;
155          $core->adminurl->redirect('admin.media',$media_page_url_params);
[0]156     } catch (Exception $e) {
157          $core->error->add($e->getMessage());
158     }
159}
160
[2093]161# Save media insertion settings for the blog
162if (!empty($_POST['save_blog_prefs']))
163{
164     if (!empty($_POST['pref_src'])) {
165          foreach (array_reverse($file->media_thumb) as $s => $v) {
166               if ($v == $_POST['pref_src']) {
167                    $core->blog->settings->system->put('media_img_default_size',$s);
168                    break;
169               }
170          }
171     }
172     if (!empty($_POST['pref_alignment'])) {
173          $core->blog->settings->system->put('media_img_default_alignment',$_POST['pref_alignment']);
174     }
175     if (!empty($_POST['pref_insertion'])) {
176          $core->blog->settings->system->put('media_img_default_link',($_POST['pref_insertion'] == 'link'));
177     }
[2529]178
[2256]179     dcPage::addSuccessNotice(__('Default media insertion settings have been successfully updated.'));
[2852]180     $core->adminurl->redirect('admin.media.item',$page_url_params);
[2093]181}
182
[0]183# Function to get image title based on meta
[2799]184function dcGetImageTitle($file,$pattern,$dto_first=false,$no_date_alone=false)
[0]185{
186     $res = array();
187     $pattern = preg_split('/\s*;;\s*/',$pattern);
188     $sep = ', ';
[2799]189     $dates = 0;
190     $items = 0;
[2529]191
[0]192     foreach ($pattern as $v) {
193          if ($v == 'Title') {
[2209]194               if ($file->media_title != '') {
195                    $res[] = $file->media_title;
196               }
[2799]197               $items++;
[0]198          } elseif ($file->media_meta->{$v}) {
[2209]199               if ((string) $file->media_meta->{$v} != '') {
200                    $res[] = (string) $file->media_meta->{$v};
201               }
[2799]202               $items++;
[0]203          } elseif (preg_match('/^Date\((.+?)\)$/u',$v,$m)) {
[1121]204               if ($dto_first && ($file->media_meta->DateTimeOriginal != 0)) {
[1073]205                    $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal);
206               } else {
207                    $res[] = dt::str($m[1],$file->media_dt);
208               }
[2799]209               $items++;
210               $dates++;
[0]211          } elseif (preg_match('/^DateTimeOriginal\((.+?)\)$/u',$v,$m) && $file->media_meta->DateTimeOriginal) {
212               $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal);
[2799]213               $items++;
214               $dates++;
[0]215          } elseif (preg_match('/^separator\((.*?)\)$/u',$v,$m)) {
216               $sep = $m[1];
217          }
218     }
[2799]219     if ($no_date_alone && $dates == count($res) && $dates < $items) {
220          // On ne laisse pas les dates seules, sauf si ce sont les seuls items du pattern (hors séparateur)
221          return '';
222     }
[0]223     return implode($sep,$res);
224}
225
226/* DISPLAY Main page
227-------------------------------------------------------- */
[2529]228$starting_scripts =
[947]229     '<script type="text/javascript">'."\n".
230     "//<![CDATA["."\n".
231     dcPage::jsVar('dotclear.msg.confirm_delete_media',__('Are you sure to delete this media?'))."\n".
232     "//]]>".
233     "</script>".
234     dcPage::jsLoad('js/_media_item.js');
[2751]235if ($popup && !empty($plugin_id)) {
236     $starting_scripts .= $core->callBehavior('adminPopupMedia', $plugin_id);
[0]237}
[2852]238$temp_params = $media_page_url_params;
239$temp_params['d']='%s';
[2858]240$bc_template = $core->adminurl->get('admin.media',$temp_params,'&amp;',true);
[2852]241$temp_params['d']='';
242$home_url=$core->adminurl->get('admin.media',$temp_params);
[0]243call_user_func($open_f,__('Media manager'),
244     $starting_scripts.
245     dcPage::jsDatePicker().
[1996]246     ($popup ? dcPage::jsPageTabs($tab) : ''),
[1358]247     dcPage::breadcrumb(
248          array(
249               html::escapeHTML($core->blog->name) => '',
[2852]250               __('Media manager') => $home_url,
251               $core->media->breadCrumb($bc_template).'<span class="page-title">'.$file->basename.'</span>' => ''
[2166]252          ),
253          array(
254               'home_link' => !$popup,
[2167]255               'hl' => false
[2166]256          )
257     )
[0]258);
259
[2529]260if ($popup) {
261     // Display notices
262     echo dcPage::notices();
263}
264
[0]265if ($file === null) {
266     call_user_func($close_f);
267     exit;
268}
269
270if (!empty($_GET['fupd']) || !empty($_GET['fupl'])) {
[1553]271     dcPage::success(__('File has been successfully updated.'));
[0]272}
273if (!empty($_GET['thumbupd'])) {
[1553]274     dcPage::success(__('Thumbnails have been successfully updated.'));
[0]275}
[2093]276if (!empty($_GET['blogprefupd'])) {
277     dcPage::success(__('Default media insertion settings have been successfully updated.'));
278}
[0]279
[2767]280# Get major file type (first part of mime type)
281$file_type = explode('/',$file->type);
282
[3153]283# Selection mode
284if ($select) {
285     // Let user choose thumbnail size if image
286     $media_desc = $file->media_title;
287
288     echo
289     '<div id="media-select" class="multi-part" title="'.__('Select media item').'">'.
290     '<h3>'.__('Select media item').'</h3>'.
291     '<form id="media-select-form" action="" method="get">';
292
293     $media_img_default_size = $core->blog->settings->system->media_img_default_size;
294     if ($media_img_default_size == '') {
295          $media_img_default_size = 'm';
296     }
297     $media_img_default_alignment = $core->blog->settings->system->media_img_default_alignment;
298     if ($media_img_default_alignment == '') {
299          $media_img_default_alignment = 'none';
300     }
301     $media_img_default_link = (boolean)$core->blog->settings->system->media_img_default_link;
302
303     if ($file->media_type == 'image')
304     {
305          $media_type = 'image';
306          $media_desc = dcGetImageTitle($file,
307               $core->blog->settings->system->media_img_title_pattern,
308               $core->blog->settings->system->media_img_use_dto_first,
309               $core->blog->settings->system->media_img_no_date_alone);
310          if ($media_desc == $file->basename) {
311               $media_desc = '';
312          }
313
314          echo
315          '<h3>'.__('Image size:').'</h3> ';
316
317          $s_checked = false;
318          echo '<p>';
319          foreach (array_reverse($file->media_thumb) as $s => $v) {
320               $s_checked = ($s == $media_img_default_size);
321               echo '<label class="classic">'.
322               form::radio(array('src'),html::escapeHTML($v),$s_checked).' '.
323               $core->media->thumb_sizes[$s][2].'</label><br /> ';
324          }
325          $s_checked = (!isset($file->media_thumb[$media_img_default_size]));
326          echo '<label class="classic">'.
327          form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> ';
328          echo '</p>';
329
330     } elseif ($file_type[0] == 'audio') {
331          $media_type = 'mp3';
332     } elseif ($file_type[0] == 'video') {
333          $media_type = 'flv';
334     } else {
335          $media_type = 'default';
336     }
337
338     echo
339     '<p>'.
340     '<a id="media-select-ok" class="button submit" href="#">'.__('Select').'</a> '.
341     '<a id="media-select-cancel" class="button" href="#">'.__('Cancel').'</a>'.
342     form::hidden(array('type'),html::escapeHTML($media_type)).
343     form::hidden(array('title'),html::escapeHTML($file->media_title)).
344     form::hidden(array('description'),html::escapeHTML($media_desc)).
345     form::hidden(array('url'),$file->file_url).
346     '</p>';
347
348     echo '</form>';
349     echo '</div>';
350}
351
[0]352# Insertion popup
[3153]353if ($popup && !$select)
[0]354{
355     $media_desc = $file->media_title;
[2529]356
[0]357     echo
358     '<div id="media-insert" class="multi-part" title="'.__('Insert media item').'">'.
[2003]359     '<h3>'.__('Insert media item').'</h3>'.
[0]360     '<form id="media-insert-form" action="" method="get">';
[2529]361
[950]362     $media_img_default_size = $core->blog->settings->system->media_img_default_size;
363     if ($media_img_default_size == '') {
364          $media_img_default_size = 'm';
365     }
366     $media_img_default_alignment = $core->blog->settings->system->media_img_default_alignment;
367     if ($media_img_default_alignment == '') {
368          $media_img_default_alignment = 'none';
369     }
370     $media_img_default_link = (boolean)$core->blog->settings->system->media_img_default_link;
371
[0]372     if ($file->media_type == 'image')
373     {
374          $media_type = 'image';
[1073]375          $media_desc = dcGetImageTitle($file,
376               $core->blog->settings->system->media_img_title_pattern,
[2799]377               $core->blog->settings->system->media_img_use_dto_first,
378               $core->blog->settings->system->media_img_no_date_alone);
[0]379          if ($media_desc == $file->basename) {
380               $media_desc = '';
381          }
[887]382
[0]383          echo
384          '<h3>'.__('Image size:').'</h3> ';
[2529]385
[0]386          $s_checked = false;
387          echo '<p>';
388          foreach (array_reverse($file->media_thumb) as $s => $v) {
[887]389               $s_checked = ($s == $media_img_default_size);
[0]390               echo '<label class="classic">'.
391               form::radio(array('src'),html::escapeHTML($v),$s_checked).' '.
392               $core->media->thumb_sizes[$s][2].'</label><br /> ';
393          }
[887]394          $s_checked = (!isset($file->media_thumb[$media_img_default_size]));
[0]395          echo '<label class="classic">'.
396          form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> ';
397          echo '</p>';
[2529]398
[2510]399          echo
[2529]400          '<div class="two-boxes">'.
[2510]401          '<h3>'.__('Image alignment').'</h3>';
[0]402          $i_align = array(
[887]403               'none' => array(__('None'),($media_img_default_alignment == 'none' ? 1 : 0)),
404               'left' => array(__('Left'),($media_img_default_alignment == 'left' ? 1 : 0)),
405               'right' => array(__('Right'),($media_img_default_alignment == 'right' ? 1 : 0)),
406               'center' => array(__('Center'),($media_img_default_alignment == 'center' ? 1 : 0))
[0]407          );
[2529]408
[0]409          echo '<p>';
410          foreach ($i_align as $k => $v) {
411               echo '<label class="classic">'.
412               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
413          }
414          echo '</p>';
[2510]415          echo '</div>';
[2529]416
[0]417          echo
[2510]418          '<div class="two-boxes">'.
[0]419          '<h3>'.__('Image insertion').'</h3>'.
420          '<p>'.
[887]421          '<label for="insert1" class="classic">'.form::radio(array('insertion','insert1'),'simple',!$media_img_default_link).
[0]422          __('As a single image').'</label><br />'.
[887]423          '<label for="insert2" class="classic">'.form::radio(array('insertion','insert2'),'link',$media_img_default_link).
[1853]424          __('As a link to the original image').'</label>'.
[2510]425          '</p>'.
426          '</div>';
[0]427     }
[2768]428     elseif ($file_type[0] == 'audio')
[0]429     {
430          $media_type = 'mp3';
[2529]431
432          echo
[2510]433          '<div class="two-boxes">'.
434          '<h3>'.__('MP3 disposition').'</h3>';
[907]435          dcPage::message(__("Please note that you cannot insert mp3 files with visual editor."),false);
[2529]436
[0]437          $i_align = array(
[950]438               'none' => array(__('None'),($media_img_default_alignment == 'none' ? 1 : 0)),
439               'left' => array(__('Left'),($media_img_default_alignment == 'left' ? 1 : 0)),
440               'right' => array(__('Right'),($media_img_default_alignment == 'right' ? 1 : 0)),
441               'center' => array(__('Center'),($media_img_default_alignment == 'center' ? 1 : 0))
[0]442          );
[2529]443
[0]444          echo '<p>';
445          foreach ($i_align as $k => $v) {
[1853]446               echo '<label class="classic">'.
[0]447               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
448          }
[2529]449
[0]450          $public_player_style = unserialize($core->blog->settings->themes->mp3player_style);
[3138]451          $public_player = dcMedia::audioPlayer($file->type,$file->file_url,$core->blog->getQmarkURL().'pf=player_mp3.swf',$public_player_style,null,$core->blog->settings->system->media_flash_fallback);
[0]452          echo form::hidden('public_player',html::escapeHTML($public_player));
453          echo '</p>';
[2510]454          echo '</div>';
[0]455     }
[2768]456     elseif ($file_type[0] == 'video')
[0]457     {
458          $media_type = 'flv';
[2529]459
[907]460          dcPage::message(__("Please note that you cannot insert video files with visual editor."),false);
[2529]461
[0]462          echo
[2510]463          '<div class="two-boxes">'.
[0]464          '<h3>'.__('Video size').'</h3>'.
[1009]465          '<p><label for="video_w" class="classic">'.__('Width:').'</label> '.
[3112]466          form::field('video_w',3,4,$core->blog->settings->system->media_video_width).'  '.
[1009]467          '<label for="video_h" class="classic">'.__('Height:').'</label> '.
[3112]468          form::field('video_h',3,4,$core->blog->settings->system->media_video_height).
[2510]469          '</p>'.
470          '</div>';
471
[2529]472
473          echo
[2510]474          '<div class="two-boxes">'.
475          '<h3>'.__('Video disposition').'</h3>';
[2529]476
[0]477          $i_align = array(
[950]478               'none' => array(__('None'),($media_img_default_alignment == 'none' ? 1 : 0)),
479               'left' => array(__('Left'),($media_img_default_alignment == 'left' ? 1 : 0)),
480               'right' => array(__('Right'),($media_img_default_alignment == 'right' ? 1 : 0)),
481               'center' => array(__('Center'),($media_img_default_alignment == 'center' ? 1 : 0))
[0]482          );
[2529]483
[0]484          echo '<p>';
485          foreach ($i_align as $k => $v) {
[1853]486               echo '<label class="classic">'.
[0]487               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
488          }
[2529]489
[0]490          $public_player_style = unserialize($core->blog->settings->themes->flvplayer_style);
[3138]491          $public_player = dcMedia::videoPlayer($file->type,$file->file_url,$core->blog->getQmarkURL().'pf=player_flv.swf',$public_player_style,null,$core->blog->settings->system->media_flash_fallback);
[0]492          echo form::hidden('public_player',html::escapeHTML($public_player));
493          echo '</p>';
[2510]494          echo '</div>';
[0]495     }
496     else
497     {
498          $media_type = 'default';
499          echo '<p>'.__('Media item will be inserted as a link.').'</p>';
500     }
[2093]501
[0]502     echo
[2094]503     '<p>'.
504     '<a id="media-insert-ok" class="button submit" href="#">'.__('Insert').'</a> '.
505     '<a id="media-insert-cancel" class="button" href="#">'.__('Cancel').'</a>'.
[0]506     form::hidden(array('type'),html::escapeHTML($media_type)).
507     form::hidden(array('title'),html::escapeHTML($file->media_title)).
508     form::hidden(array('description'),html::escapeHTML($media_desc)).
509     form::hidden(array('url'),$file->file_url).
510     '</p>';
[2529]511
[2093]512     echo '</form>';
513
514     if ($media_type != 'default') {
515          echo
[2094]516          '<div class="border-top">'.
[2852]517          '<form id="save_settings" action="'.$core->adminurl->getBase('admin.media.item').'" method="post">'.
[2094]518          '<p>'.__('Make current settings as default').' '.
519          '<input class="reset" type="submit" name="save_blog_prefs" value="'.__('OK').'" />'.
[2093]520          form::hidden(array('pref_src'),'').
521          form::hidden(array('pref_alignment'),'').
522          form::hidden(array('pref_insertion'),'').
[2852]523          $core->adminurl->getHiddenFormFields('admin.media.item',$page_url_params).
[2093]524          $core->formNonce().'</p>'.
[2094]525          '</form>'.'</div>';
[2093]526     }
527
528     echo '</div>';
[0]529}
530
[3153]531if ($popup || $select) {
[1996]532     echo
533     '<div class="multi-part" title="'.__('Media details').'" id="media-details-tab">';
534} else {
535     echo '<h3 class="out-of-screen-if-js">'.__('Media details').'</h3>';
536}
[0]537echo
[1038]538'<p id="media-icon"><img src="'.$file->media_icon.'?'.time()*rand().'" alt="" /></p>';
[0]539
540echo
[1454]541'<div id="media-details">'.
542'<div class="near-icon">';
[0]543
544if ($file->media_image)
545{
546     $thumb_size = !empty($_GET['size']) ? $_GET['size'] : 's';
[2529]547
[0]548     if (!isset($core->media->thumb_sizes[$thumb_size]) && $thumb_size != 'o') {
549          $thumb_size = 's';
550     }
[2529]551
[1454]552     if (isset($file->media_thumb[$thumb_size])) {
553          echo '<p><img src="'.$file->media_thumb[$thumb_size].'?'.time()*rand().'" alt="" /></p>';
554     } elseif ($thumb_size == 'o') {
555          $S = getimagesize($file->file);
556          $class = ($S[1] > 500) ? ' class="overheight"' : '';
557          unset($S);
558          echo '<p id="media-original-image"'.$class.'><img src="'.$file->file_url.'?'.time()*rand().'" alt="" /></p>';
559     }
[2529]560
[0]561     echo '<p>'.__('Available sizes:').' ';
562     foreach (array_reverse($file->media_thumb) as $s => $v)
563     {
564          $strong_link = ($s == $thumb_size) ? '<strong>%s</strong>' : '%s';
[2852]565          printf($strong_link,'<a href="'.$core->adminurl->get('admin.media.item',array_merge($page_url_params,
566               array("size" => $s,'tab' => 'media-details-tab'))).'">'.$core->media->thumb_sizes[$s][2].'</a> | ');
[0]567     }
[2852]568     echo '<a href="'.$core->adminurl->get('admin.media.item',array_merge($page_url_params,array("size" => "o","tab"=>"media-details-tab"))).'">'.__('original').'</a>';
[0]569     echo '</p>';
[3093]570
571     if ($thumb_size != 'o' && isset($file->media_thumb[$thumb_size])) {
572          $p = path::info($file->file);
573          $alpha = ($p['extension'] == 'png') || ($p['extension'] == 'PNG');
574          $thumb = sprintf(($alpha ? $core->media->thumb_tp_alpha : $core->media->thumb_tp),$p['dirname'],$p['base'],'%s');
575          $thumb_file = sprintf($thumb,$thumb_size);
576          $T = getimagesize($thumb_file);
577          $stats = stat($thumb_file);
578          echo
579          '<h3>'.__('Thumbnail details').'</h3>'.
580          '<ul>'.
581          '<li><strong>'.__('Image width:').'</strong> '.$T[0].' px</li>'.
582          '<li><strong>'.__('Image height:').'</strong> '.$T[1].' px</li>'.
583          '<li><strong>'.__('File size:').'</strong> '.files::size($stats[7]).'</li>'.
584          '<li><strong>'.__('File URL:').'</strong> <a href="'.$file->media_thumb[$thumb_size].'">'.
585               $file->media_thumb[$thumb_size].'</a></li>'.
586          '</ul>';
587     }
[0]588}
589
[2767]590// Show player if relevant
591if ($file_type[0] == 'audio')
[0]592{
[3138]593     echo dcMedia::audioPlayer($file->type,$file->file_url,$core->adminurl->get("admin.home",array('pf' => 'player_mp3.swf')),
594          null,$core->blog->settings->system->media_flash_fallback);
[0]595}
[2767]596if ($file_type[0] == 'video')
[0]597{
[3138]598     echo dcMedia::videoPlayer($file->type,$file->file_url,$core->adminurl->get("admin.home",array('pf' => 'player_flv.swf')),
599          null,$core->blog->settings->system->media_flash_fallback);
[0]600}
601
602echo
603'<h3>'.__('Media details').'</h3>'.
604'<ul>'.
605     '<li><strong>'.__('File owner:').'</strong> '.$file->media_user.'</li>'.
[3093]606     '<li><strong>'.__('File type:').'</strong> '.$file->type.'</li>';
607if ($file->media_image)
608{
609     $S = getimagesize($file->file);
610     echo
611     '<li><strong>'.__('Image width:').'</strong> '.$S[0].' px</li>'.
612     '<li><strong>'.__('Image height:').'</strong> '.$S[1].' px</li>';
613     unset($S);
614}
615echo
[0]616     '<li><strong>'.__('File size:').'</strong> '.files::size($file->size).'</li>'.
617     '<li><strong>'.__('File URL:').'</strong> <a href="'.$file->file_url.'">'.$file->file_url.'</a></li>'.
618'</ul>';
619
620if (empty($_GET['find_posts']))
621{
622     echo
[2852]623     '<p><a class="button" href="'.$core->adminurl->get('admin.media.item',array_merge($page_url_params,array("find_posts"=>1,"tab"=>"media-details-tab"))).'">'.
[1605]624     __('Show entries containing this media').'</a></p>';
[0]625}
626else
627{
628     echo '<h3>'.__('Entries containing this media').'</h3>';
629     $params = array(
630          'post_type' => '',
631          'from' => 'LEFT OUTER JOIN '.$core->prefix.'post_media PM ON P.post_id = PM.post_id ',
632          'sql' => 'AND ('.
633               'PM.media_id = '.(integer) $id.' '.
634               "OR post_content_xhtml LIKE '%".$core->con->escape($file->relname)."%' ".
635               "OR post_excerpt_xhtml LIKE '%".$core->con->escape($file->relname)."%' "
636     );
[2529]637
[0]638     if ($file->media_image)
639     { # We look for thumbnails too
[663]640          if (preg_match('#^http(s)?://#',$core->blog->settings->system->public_url)) {
[375]641               $media_root = $core->blog->settings->system->public_url;
642          } else {
643               $media_root = $core->blog->host.path::clean($core->blog->settings->system->public_url).'/';
644          }
[0]645          foreach ($file->media_thumb as $v) {
646               $v = preg_replace('/^'.preg_quote($media_root,'/').'/','',$v);
647               $params['sql'] .= "OR post_content_xhtml LIKE '%".$core->con->escape($v)."%' ";
648               $params['sql'] .= "OR post_excerpt_xhtml LIKE '%".$core->con->escape($v)."%' ";
649          }
650     }
[2529]651
[0]652     $params['sql'] .= ') ';
[2529]653
[0]654     $rs = $core->blog->getPosts($params);
[2529]655
[0]656     if ($rs->isEmpty())
657     {
658          echo '<p>'.__('No entry seems contain this media.').'</p>';
659     }
660     else
661     {
662          echo '<ul>';
663          while ($rs->fetch()) {
[918]664               $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
665               switch ($rs->post_status) {
666                    case 1:
667                         $img_status = sprintf($img,__('published'),'check-on.png');
668                         break;
669                    case 0:
670                         $img_status = sprintf($img,__('unpublished'),'check-off.png');
671                         break;
672                    case -1:
673                         $img_status = sprintf($img,__('scheduled'),'scheduled.png');
674                         break;
675                    case -2:
676                         $img_status = sprintf($img,__('pending'),'check-wrn.png');
677                         break;
678               }
679               echo '<li>'.$img_status.' '.'<a href="'.$core->getPostAdminURL($rs->post_type,$rs->post_id).'">'.
680                    $rs->post_title.'</a>'.
681                    ($rs->post_type != 'post' ? ' ('.html::escapeHTML($rs->post_type).')' : '').
682                    ' - '.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->post_dt).'</li>';
[0]683          }
684          echo '</ul>';
685     }
686}
687
688if ($file->type == 'image/jpeg')
689{
690     echo '<h3>'.__('Image details').'</h3>';
[2529]691
[2106]692     $details = '';
693     if (count($file->media_meta) > 0)
[0]694     {
695          foreach ($file->media_meta as $k => $v)
696          {
697               if ((string) $v) {
[2106]698                    $details .= '<li><strong>'.$k.':</strong> '.html::escapeHTML($v).'</li>';
[0]699               }
700          }
[2106]701     }
702     if ($details) {
703          echo '<ul>'.$details.'</ul>';
704     } else {
705          echo '<p>'.__('No detail').'</p>';
[0]706     }
707}
708
[1454]709echo '</div>';
710
[1499]711echo '<h3>'.__('Updates and modifications').'</h3>';
712
[0]713if ($file->editable && $core_media_writable)
714{
715     if ($file->media_type == 'image')
716     {
717          echo
[2852]718          '<form class="clear fieldset" action="'.$core->adminurl->get("admin.media.item").'" method="post">'.
[1499]719          '<h4>'.__('Update thumbnails').'</h4>'.
[0]720          '<p>'.__('This will create or update thumbnails for this image.').'</p>'.
[557]721          '<p><input type="submit" name="thumbs" value="'.__('Update thumbnails').'" />'.
[2852]722          $core->adminurl->getHiddenFormFields('admin.media',$page_url_params).
[0]723          $core->formNonce().'</p>'.
[1499]724          '</form>';
[0]725     }
[2529]726
[0]727     if ($file->type == 'application/zip')
728     {
729          $inflate_combo = array(
730               __('Extract in a new directory') => 'new',
731               __('Extract in current directory') => 'current'
732          );
[2529]733
[0]734          echo
[2852]735          '<form class="clear fieldset" id="file-unzip" action="'.$core->adminurl->get("admin.media.item").'" method="post">'.
[1499]736          '<h4>'.__('Extract archive').'</h4>'.
[0]737          '<ul>'.
738          '<li><strong>'.__('Extract in a new directory').'</strong> : '.
739          __('This will extract archive in a new directory that should not exist yet.').'</li>'.
740          '<li><strong>'.__('Extract in current directory').'</strong> : '.
741          __('This will extract archive in current directory and will overwrite existing files or directory.').'</li>'.
742          '</ul>'.
[1399]743          '<p><label for="inflate_mode" class="classic">'.__('Extract mode:').'</label> '.
744          form::combo('inflate_mode',$inflate_combo,'new').
[557]745          '<input type="submit" name="unzip" value="'.__('Extract').'" />'.
[2852]746          $core->adminurl->getHiddenFormFields('admin.media',$page_url_params).
[0]747          $core->formNonce().'</p>'.
[1499]748          '</form>';
[0]749     }
[2529]750
[0]751     echo
[2852]752     '<form class="clear fieldset" action="'.$core->adminurl->get("admin.media.item").'" method="post">'.
[1499]753     '<h4>'.__('Change media properties').'</h4>'.
[1399]754     '<p><label for="media_file">'.__('File name:').'</label>'.
755     form::field('media_file',30,255,html::escapeHTML($file->basename)).'</p>'.
756     '<p><label for="media_title">'.__('File title:').'</label>'.
757     form::field('media_title',30,255,html::escapeHTML($file->media_title)).'</p>'.
758     '<p><label for="media_dt">'.__('File date:').'</label>'.
759     form::field('media_dt',16,16,html::escapeHTML($file->media_dtstr)).'</p>'.
[68]760     '<p><label for="media_private" class="classic">'.form::checkbox('media_private',1,$file->media_priv).' '.
[0]761     __('Private').'</label></p>'.
[1399]762     '<p><label for="media_path">'.__('New directory:').'</label>'.
763     form::combo('media_path',$dirs_combo,dirname($file->relname)).'</p>'.
[217]764     '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'.
[2852]765     $core->adminurl->getHiddenFormFields('admin.media.item',$page_url_params).
[0]766     $core->formNonce().'</p>'.
[1499]767     '</form>';
[2529]768
[0]769     echo
[2852]770     '<form class="clear fieldset" action="'.$core->adminurl->get("admin.media.item").'" method="post" enctype="multipart/form-data">'.
[1499]771     '<h4>'.__('Change file').'</h4>'.
[0]772     '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'.
[68]773     '<p><label for="upfile">'.__('Choose a file:').
[0]774     ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).') '.
[68]775     '<input type="file" id="upfile" name="upfile" size="35" />'.
[0]776     '</label></p>'.
[557]777     '<p><input type="submit" value="'.__('Send').'" />'.
[2852]778     $core->adminurl->getHiddenFormFields('admin.media',$page_url_params).
[0]779     $core->formNonce().'</p>'.
[1499]780     '</form>';
[0]781
[947]782     if ($file->del) {
783          echo
[2872]784          '<form id="delete-form" method="post" action="'.$core->adminurl->getBase("admin.media").'">'.
[947]785          '<p><input name="delete" type="submit" class="delete" value="'.__('Delete this media').'" />'.
786          form::hidden('remove',rawurlencode($file->basename)).
787          form::hidden('rmyes',1).
[2852]788          $core->adminurl->getHiddenFormFields('admin.media',$media_page_url_params).
[947]789          $core->formNonce().'</p>'.
790          '</form>';
791     }
792
793
[0]794     # --BEHAVIOR-- adminMediaItemForm
795     $core->callBehavior('adminMediaItemForm',$file);
796}
797
798echo
799'</div>';
[3153]800if ($popup || $select) {
[1996]801     echo
802     '</div>';
803}
[0]804
805call_user_func($close_f);
Note: See TracBrowser for help on using the repository browser.

Sites map