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

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($_REQUEST['post_id']) ? (integer) $_REQUEST['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($_REQUEST['popup']);
31$select = !empty($_REQUEST['select']) ? (integer)$_REQUEST['select'] : 0;  // 0 : none, 1 : single media, >1 : multiple medias
32$plugin_id = isset($_REQUEST['plugin_id']) ? html::sanitizeURL($_REQUEST['plugin_id']) : '';
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);
35
36if ($plugin_id != '') {
37     $page_url_params['plugin_id'] = $plugin_id;
38     $media_page_url_params['plugin_id'] = $plugin_id;
39}
40
41$id = !empty($_REQUEST['id']) ? (integer) $_REQUEST['id'] : '';
42
43if ($id != '') {
44     $page_url_params ['id'] = $id;
45}
46
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);
59
60     if ($id) {
61          $file = $core->media->getFile($id);
62     }
63
64     if ($file === null) {
65          throw new Exception(__('Not a valid file'));
66     }
67
68     $core->media->chdir(dirname($file->relname));
69     $core_media_writable = $core->media->writable();
70
71     # Prepare directories combo box
72     $dirs_combo = array();
73     foreach ($core->media->getDBDirs() as $v) {
74          $dirs_combo['/'.$v] = $v;
75     }
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     }
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);
94
95          dcPage::addSuccessNotice(__('File has been successfully updated.'));
96          $core->adminurl->redirect('admin.media.item',$page_url_params);
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;
106
107     $newFile->basename = $_POST['media_file'];
108
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']);
120
121     try {
122          $core->media->updateFile($file,$newFile);
123
124          dcPage::addSuccessNotice(__('File has been successfully updated.'));
125          $page_url_params['tab'] = 'media-details-tab';
126          $core->adminurl->redirect('admin.media.item',$page_url_params);
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;
137          $core->media->mediaFireRecreateEvent($file);
138
139          dcPage::addSuccessNotice(__('Thumbnails have been successfully updated.'));
140          $page_url_params['tab'] = 'media-details-tab';
141          $core->adminurl->redirect('admin.media.item',$page_url_params);
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');
152
153          dcPage::addSuccessNotice(__('Zip file has been successfully extracted.'));
154          $media_page_url_params['d'] = $unzip_dir;
155          $core->adminurl->redirect('admin.media',$media_page_url_params);
156     } catch (Exception $e) {
157          $core->error->add($e->getMessage());
158     }
159}
160
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     }
178
179     dcPage::addSuccessNotice(__('Default media insertion settings have been successfully updated.'));
180     $core->adminurl->redirect('admin.media.item',$page_url_params);
181}
182
183# Function to get image title based on meta
184function dcGetImageTitle($file,$pattern,$dto_first=false,$no_date_alone=false)
185{
186     $res = array();
187     $pattern = preg_split('/\s*;;\s*/',$pattern);
188     $sep = ', ';
189     $dates = 0;
190     $items = 0;
191
192     foreach ($pattern as $v) {
193          if ($v == 'Title') {
194               if ($file->media_title != '') {
195                    $res[] = $file->media_title;
196               }
197               $items++;
198          } elseif ($file->media_meta->{$v}) {
199               if ((string) $file->media_meta->{$v} != '') {
200                    $res[] = (string) $file->media_meta->{$v};
201               }
202               $items++;
203          } elseif (preg_match('/^Date\((.+?)\)$/u',$v,$m)) {
204               if ($dto_first && ($file->media_meta->DateTimeOriginal != 0)) {
205                    $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal);
206               } else {
207                    $res[] = dt::str($m[1],$file->media_dt);
208               }
209               $items++;
210               $dates++;
211          } elseif (preg_match('/^DateTimeOriginal\((.+?)\)$/u',$v,$m) && $file->media_meta->DateTimeOriginal) {
212               $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal);
213               $items++;
214               $dates++;
215          } elseif (preg_match('/^separator\((.*?)\)$/u',$v,$m)) {
216               $sep = $m[1];
217          }
218     }
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     }
223     return implode($sep,$res);
224}
225
226/* DISPLAY Main page
227-------------------------------------------------------- */
228$starting_scripts =
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');
235if ($popup && !empty($plugin_id)) {
236     $starting_scripts .= $core->callBehavior('adminPopupMedia', $plugin_id);
237}
238$temp_params = $media_page_url_params;
239$temp_params['d']='%s';
240$bc_template = $core->adminurl->get('admin.media',$temp_params,'&amp;',true);
241$temp_params['d']='';
242$home_url=$core->adminurl->get('admin.media',$temp_params);
243call_user_func($open_f,__('Media manager'),
244     $starting_scripts.
245     dcPage::jsDatePicker().
246     ($popup ? dcPage::jsPageTabs($tab) : ''),
247     dcPage::breadcrumb(
248          array(
249               html::escapeHTML($core->blog->name) => '',
250               __('Media manager') => $home_url,
251               $core->media->breadCrumb($bc_template).'<span class="page-title">'.$file->basename.'</span>' => ''
252          ),
253          array(
254               'home_link' => !$popup,
255               'hl' => false
256          )
257     )
258);
259
260if ($popup) {
261     // Display notices
262     echo dcPage::notices();
263}
264
265if ($file === null) {
266     call_user_func($close_f);
267     exit;
268}
269
270if (!empty($_GET['fupd']) || !empty($_GET['fupl'])) {
271     dcPage::success(__('File has been successfully updated.'));
272}
273if (!empty($_GET['thumbupd'])) {
274     dcPage::success(__('Thumbnails have been successfully updated.'));
275}
276if (!empty($_GET['blogprefupd'])) {
277     dcPage::success(__('Default media insertion settings have been successfully updated.'));
278}
279
280# Get major file type (first part of mime type)
281$file_type = explode('/',$file->type);
282
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
352# Insertion popup
353if ($popup && !$select)
354{
355     $media_desc = $file->media_title;
356
357     echo
358     '<div id="media-insert" class="multi-part" title="'.__('Insert media item').'">'.
359     '<h3>'.__('Insert media item').'</h3>'.
360     '<form id="media-insert-form" action="" method="get">';
361
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
372     if ($file->media_type == 'image')
373     {
374          $media_type = 'image';
375          $media_desc = dcGetImageTitle($file,
376               $core->blog->settings->system->media_img_title_pattern,
377               $core->blog->settings->system->media_img_use_dto_first,
378               $core->blog->settings->system->media_img_no_date_alone);
379          if ($media_desc == $file->basename) {
380               $media_desc = '';
381          }
382
383          echo
384          '<h3>'.__('Image size:').'</h3> ';
385
386          $s_checked = false;
387          echo '<p>';
388          foreach (array_reverse($file->media_thumb) as $s => $v) {
389               $s_checked = ($s == $media_img_default_size);
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          }
394          $s_checked = (!isset($file->media_thumb[$media_img_default_size]));
395          echo '<label class="classic">'.
396          form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> ';
397          echo '</p>';
398
399          echo
400          '<div class="two-boxes">'.
401          '<h3>'.__('Image alignment').'</h3>';
402          $i_align = array(
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))
407          );
408
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>';
415          echo '</div>';
416
417          echo
418          '<div class="two-boxes">'.
419          '<h3>'.__('Image insertion').'</h3>'.
420          '<p>'.
421          '<label for="insert1" class="classic">'.form::radio(array('insertion','insert1'),'simple',!$media_img_default_link).
422          __('As a single image').'</label><br />'.
423          '<label for="insert2" class="classic">'.form::radio(array('insertion','insert2'),'link',$media_img_default_link).
424          __('As a link to the original image').'</label>'.
425          '</p>'.
426          '</div>';
427     }
428     elseif ($file_type[0] == 'audio')
429     {
430          $media_type = 'mp3';
431
432          echo
433          '<div class="two-boxes">'.
434          '<h3>'.__('MP3 disposition').'</h3>';
435          dcPage::message(__("Please note that you cannot insert mp3 files with visual editor."),false);
436
437          $i_align = array(
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))
442          );
443
444          echo '<p>';
445          foreach ($i_align as $k => $v) {
446               echo '<label class="classic">'.
447               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
448          }
449
450          $public_player_style = unserialize($core->blog->settings->themes->mp3player_style);
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);
452          echo form::hidden('public_player',html::escapeHTML($public_player));
453          echo '</p>';
454          echo '</div>';
455     }
456     elseif ($file_type[0] == 'video')
457     {
458          $media_type = 'flv';
459
460          dcPage::message(__("Please note that you cannot insert video files with visual editor."),false);
461
462          echo
463          '<div class="two-boxes">'.
464          '<h3>'.__('Video size').'</h3>'.
465          '<p><label for="video_w" class="classic">'.__('Width:').'</label> '.
466          form::field('video_w',3,4,$core->blog->settings->system->media_video_width).'  '.
467          '<label for="video_h" class="classic">'.__('Height:').'</label> '.
468          form::field('video_h',3,4,$core->blog->settings->system->media_video_height).
469          '</p>'.
470          '</div>';
471
472
473          echo
474          '<div class="two-boxes">'.
475          '<h3>'.__('Video disposition').'</h3>';
476
477          $i_align = array(
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))
482          );
483
484          echo '<p>';
485          foreach ($i_align as $k => $v) {
486               echo '<label class="classic">'.
487               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
488          }
489
490          $public_player_style = unserialize($core->blog->settings->themes->flvplayer_style);
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);
492          echo form::hidden('public_player',html::escapeHTML($public_player));
493          echo '</p>';
494          echo '</div>';
495     }
496     else
497     {
498          $media_type = 'default';
499          echo '<p>'.__('Media item will be inserted as a link.').'</p>';
500     }
501
502     echo
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>'.
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>';
511
512     echo '</form>';
513
514     if ($media_type != 'default') {
515          echo
516          '<div class="border-top">'.
517          '<form id="save_settings" action="'.$core->adminurl->getBase('admin.media.item').'" method="post">'.
518          '<p>'.__('Make current settings as default').' '.
519          '<input class="reset" type="submit" name="save_blog_prefs" value="'.__('OK').'" />'.
520          form::hidden(array('pref_src'),'').
521          form::hidden(array('pref_alignment'),'').
522          form::hidden(array('pref_insertion'),'').
523          $core->adminurl->getHiddenFormFields('admin.media.item',$page_url_params).
524          $core->formNonce().'</p>'.
525          '</form>'.'</div>';
526     }
527
528     echo '</div>';
529}
530
531if ($popup || $select) {
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}
537echo
538'<p id="media-icon"><img src="'.$file->media_icon.'?'.time()*rand().'" alt="" /></p>';
539
540echo
541'<div id="media-details">'.
542'<div class="near-icon">';
543
544if ($file->media_image)
545{
546     $thumb_size = !empty($_GET['size']) ? $_GET['size'] : 's';
547
548     if (!isset($core->media->thumb_sizes[$thumb_size]) && $thumb_size != 'o') {
549          $thumb_size = 's';
550     }
551
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     }
560
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';
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> | ');
567     }
568     echo '<a href="'.$core->adminurl->get('admin.media.item',array_merge($page_url_params,array("size" => "o","tab"=>"media-details-tab"))).'">'.__('original').'</a>';
569     echo '</p>';
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     }
588}
589
590// Show player if relevant
591if ($file_type[0] == 'audio')
592{
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);
595}
596if ($file_type[0] == 'video')
597{
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);
600}
601
602echo
603'<h3>'.__('Media details').'</h3>'.
604'<ul>'.
605     '<li><strong>'.__('File owner:').'</strong> '.$file->media_user.'</li>'.
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
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
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"))).'">'.
624     __('Show entries containing this media').'</a></p>';
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     );
637
638     if ($file->media_image)
639     { # We look for thumbnails too
640          if (preg_match('#^http(s)?://#',$core->blog->settings->system->public_url)) {
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          }
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     }
651
652     $params['sql'] .= ') ';
653
654     $rs = $core->blog->getPosts($params);
655
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()) {
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>';
683          }
684          echo '</ul>';
685     }
686}
687
688if ($file->type == 'image/jpeg')
689{
690     echo '<h3>'.__('Image details').'</h3>';
691
692     $details = '';
693     if (count($file->media_meta) > 0)
694     {
695          foreach ($file->media_meta as $k => $v)
696          {
697               if ((string) $v) {
698                    $details .= '<li><strong>'.$k.':</strong> '.html::escapeHTML($v).'</li>';
699               }
700          }
701     }
702     if ($details) {
703          echo '<ul>'.$details.'</ul>';
704     } else {
705          echo '<p>'.__('No detail').'</p>';
706     }
707}
708
709echo '</div>';
710
711echo '<h3>'.__('Updates and modifications').'</h3>';
712
713if ($file->editable && $core_media_writable)
714{
715     if ($file->media_type == 'image')
716     {
717          echo
718          '<form class="clear fieldset" action="'.$core->adminurl->get("admin.media.item").'" method="post">'.
719          '<h4>'.__('Update thumbnails').'</h4>'.
720          '<p>'.__('This will create or update thumbnails for this image.').'</p>'.
721          '<p><input type="submit" name="thumbs" value="'.__('Update thumbnails').'" />'.
722          $core->adminurl->getHiddenFormFields('admin.media',$page_url_params).
723          $core->formNonce().'</p>'.
724          '</form>';
725     }
726
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          );
733
734          echo
735          '<form class="clear fieldset" id="file-unzip" action="'.$core->adminurl->get("admin.media.item").'" method="post">'.
736          '<h4>'.__('Extract archive').'</h4>'.
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>'.
743          '<p><label for="inflate_mode" class="classic">'.__('Extract mode:').'</label> '.
744          form::combo('inflate_mode',$inflate_combo,'new').
745          '<input type="submit" name="unzip" value="'.__('Extract').'" />'.
746          $core->adminurl->getHiddenFormFields('admin.media',$page_url_params).
747          $core->formNonce().'</p>'.
748          '</form>';
749     }
750
751     echo
752     '<form class="clear fieldset" action="'.$core->adminurl->get("admin.media.item").'" method="post">'.
753     '<h4>'.__('Change media properties').'</h4>'.
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>'.
760     '<p><label for="media_private" class="classic">'.form::checkbox('media_private',1,$file->media_priv).' '.
761     __('Private').'</label></p>'.
762     '<p><label for="media_path">'.__('New directory:').'</label>'.
763     form::combo('media_path',$dirs_combo,dirname($file->relname)).'</p>'.
764     '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'.
765     $core->adminurl->getHiddenFormFields('admin.media.item',$page_url_params).
766     $core->formNonce().'</p>'.
767     '</form>';
768
769     echo
770     '<form class="clear fieldset" action="'.$core->adminurl->get("admin.media.item").'" method="post" enctype="multipart/form-data">'.
771     '<h4>'.__('Change file').'</h4>'.
772     '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'.
773     '<p><label for="upfile">'.__('Choose a file:').
774     ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).') '.
775     '<input type="file" id="upfile" name="upfile" size="35" />'.
776     '</label></p>'.
777     '<p><input type="submit" value="'.__('Send').'" />'.
778     $core->adminurl->getHiddenFormFields('admin.media',$page_url_params).
779     $core->formNonce().'</p>'.
780     '</form>';
781
782     if ($file->del) {
783          echo
784          '<form id="delete-form" method="post" action="'.$core->adminurl->getBase("admin.media").'">'.
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).
788          $core->adminurl->getHiddenFormFields('admin.media',$media_page_url_params).
789          $core->formNonce().'</p>'.
790          '</form>';
791     }
792
793
794     # --BEHAVIOR-- adminMediaItemForm
795     $core->callBehavior('adminMediaItemForm',$file);
796}
797
798echo
799'</div>';
800if ($popup || $select) {
801     echo
802     '</div>';
803}
804
805call_user_func($close_f);
Note: See TracBrowser for help on using the repository browser.

Sites map