Dotclear

source: admin/media_item.php @ 380:3befe1b6ed88

Revision 380:3befe1b6ed88, 15.8 KB checked in by Tomtom33 <tbouron@…>, 14 years ago (diff)

Finished integration for dotclear media popup

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 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$post_id = !empty($_GET['post_id']) ? (integer) $_GET['post_id'] : null;
18if ($post_id) {
19     $post = $core->blog->getPosts(array('post_id'=>$post_id));
20     if ($post->isEmpty()) {
21          $post_id = null;
22     }
23     $post_title = $post->post_title;
24     unset($post);
25}
26
27$file = null;
28$popup = (integer) !empty($_GET['popup']);
29$page_url = 'media_item.php?popup='.$popup.'&post_id='.$post_id;
30$media_page_url = 'media.php?popup='.$popup.'&post_id='.$post_id;
31
32$id = !empty($_REQUEST['id']) ? (integer) $_REQUEST['id'] : '';
33
34if ($popup) {
35     $open_f = array('dcPage','openPopup');
36     $close_f = array('dcPage','closePopup');
37} else {
38     $open_f = array('dcPage','open');
39     $close_f = create_function('',"dcPage::helpBlock('core_media'); dcPage::close();");
40}
41
42$core_media_writable = false;
43try
44{
45     $core->media = new dcMedia($core);
46     
47     if ($id) {
48          $file = $core->media->getFile($id);
49     }
50     
51     if ($file === null) {
52          throw new Exception(__('Not a valid file'));
53     }
54     
55     $core->media->chdir(dirname($file->relname));
56     $core_media_writable = $core->media->writable();
57     
58     # Prepare directories combo box
59     $dirs_combo = array();
60     foreach ($core->media->getRootDirs() as $v) {
61          if ($v->w) {
62               $dirs_combo['/'.$v->relname] = $v->relname;
63          }
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');
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');
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)
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               $res[] = dt::str($m[1],$file->media_dt);
148          } elseif (preg_match('/^DateTimeOriginal\((.+?)\)$/u',$v,$m) && $file->media_meta->DateTimeOriginal) {
149               $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal);
150          } elseif (preg_match('/^separator\((.*?)\)$/u',$v,$m)) {
151               $sep = $m[1];
152          }
153     }
154     return implode($sep,$res);
155}
156
157/* DISPLAY Main page
158-------------------------------------------------------- */
159$starting_scripts = dcPage::jsLoad('js/_media_item.js');
160if ($popup) {
161     $starting_scripts .=
162     dcPage::jsLoad('js/tiny_mce/tiny_mce_popup.js').
163     dcPage::jsLoad('js/tiny_mce/plugins/dcControls/js/popup_media.js');
164}
165call_user_func($open_f,__('Media manager'),
166     $starting_scripts.
167     dcPage::jsDatePicker().
168     dcPage::jsPageTabs()
169);
170
171if ($file === null) {
172     call_user_func($close_f);
173     exit;
174}
175
176if (!empty($_GET['fupd']) || !empty($_GET['fupl'])) {
177     echo '<p class="message">'.__('File has been successfully updated.').'</p>';
178}
179if (!empty($_GET['thumbupd'])) {
180     echo '<p class="message">'.__('Thumbnails have been successfully updated.').'</p>';
181}
182
183echo '<h2><a href="'.html::escapeURL($media_page_url).'">'.__('Media manager').'</a>'.
184' / '.$core->media->breadCrumb(html::escapeURL($media_page_url).'&amp;d=%s').
185$file->basename.'</h2>';
186
187# Insertion popup
188if ($popup)
189{
190     $media_desc = $file->media_title;
191     
192     echo
193     '<div id="media-insert" class="multi-part" title="'.__('Insert media item').'">'.
194     '<form id="media-insert-form" action="" method="get">';
195     
196     if ($file->media_type == 'image')
197     {
198          $media_type = 'image';
199          $media_desc = dcGetImageTitle($file,$core->blog->settings->system->media_img_title_pattern);
200          if ($media_desc == $file->basename) {
201               $media_desc = '';
202          }
203         
204          echo
205          '<h3>'.__('Image size:').'</h3> ';
206         
207          $s_checked = false;
208          echo '<p>';
209          foreach (array_reverse($file->media_thumb) as $s => $v) {
210               $s_checked = ($s == 'm');
211               echo '<label class="classic">'.
212               form::radio(array('src'),html::escapeHTML($v),$s_checked).' '.
213               $core->media->thumb_sizes[$s][2].'</label><br /> ';
214          }
215          $s_checked = (!isset($file->media_thumb['m']));
216          echo '<label class="classic">'.
217          form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> ';
218          echo '</p>';
219         
220         
221          echo '<h3>'.__('Image alignment').'</h3>';
222          $i_align = array(
223               'none' => array(__('None'),1),
224               'left' => array(__('Left'),0),
225               'right' => array(__('Right'),0),
226               'center' => array(__('Center'),0)
227          );
228         
229          echo '<p>';
230          foreach ($i_align as $k => $v) {
231               echo '<label class="classic">'.
232               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
233          }
234          echo '</p>';
235         
236          echo
237          '<h3>'.__('Image insertion').'</h3>'.
238          '<p>'.
239          '<label for="insert1" class="classic">'.form::radio(array('insertion','insert1'),'simple',true).
240          __('As a single image').'</label><br />'.
241          '<label for="insert2" class="classic">'.form::radio(array('insertion','insert2'),'link',false).
242          __('As a link to original image').'</label>'.
243          '</p>';
244     }
245     elseif ($file->type == 'audio/mpeg3')
246     {
247          $media_type = 'mp3';
248         
249          echo '<h3>'.__('MP3 disposition').'</h3>'.
250         
251          $i_align = array(
252               'none' => array(__('None'),0),
253               'left' => array(__('Left'),0),
254               'right' => array(__('Right'),0),
255               'center' => array(__('Center'),1)
256          );
257         
258          echo '<p>';
259          foreach ($i_align as $k => $v) {
260               echo '<label for="alignment" class="classic">'.
261               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
262          }
263         
264          $public_player_style = unserialize($core->blog->settings->themes->mp3player_style);
265          $public_player = dcMedia::mp3player($file->file_url,$core->blog->getQmarkURL().'pf=player_mp3.swf',$public_player_style);
266          echo form::hidden('public_player',html::escapeHTML($public_player));
267          echo '</p>';
268     }
269     elseif ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v')
270     {
271          $media_type = 'flv';
272         
273          echo
274          '<h3>'.__('Video size').'</h3>'.
275          '<p><label for="video_w" class="classic">'.__('Width:').' '.
276          form::field('video_w',3,4,400).'  '.
277          '<label for="video_h" class="classic">'.__('Height:').' '.
278          form::field('video_h',3,4,300).
279          '</p>';
280         
281          echo '<h3>'.__('Video disposition').'</h3>';
282         
283          $i_align = array(
284               'none' => array(__('None'),0),
285               'left' => array(__('Left'),0),
286               'right' => array(__('Right'),0),
287               'center' => array(__('Center'),1)
288          );
289         
290          echo '<p>';
291          foreach ($i_align as $k => $v) {
292               echo '<label for="alignment" class="classic">'.
293               form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
294          }
295         
296          $public_player_style = unserialize($core->blog->settings->themes->flvplayer_style);
297          $public_player = dcMedia::flvplayer($file->file_url,$core->blog->getQmarkURL().'pf=player_flv.swf',$public_player_style);
298          echo form::hidden('public_player',html::escapeHTML($public_player));
299          echo '</p>';
300     }
301     else
302     {
303          $media_type = 'default';
304          echo '<p>'.__('Media item will be inserted as a link.').'</p>';
305     }
306     
307     echo
308     '<p><a id="media-insert-cancel" class="button" href="#">'.__('Cancel').'</a> - '.
309     '<strong><a id="media-insert-ok" class="button" href="#">'.__('Insert').'</a></strong>'.
310     form::hidden(array('type'),html::escapeHTML($media_type)).
311     form::hidden(array('title'),html::escapeHTML($file->media_title)).
312     form::hidden(array('description'),html::escapeHTML($media_desc)).
313     form::hidden(array('url'),$file->file_url).
314     '</p>';
315     
316     echo '</form></div>';
317}
318
319echo
320'<div class="multi-part" title="'.__('Media details').'" id="media-details-tab">'.
321'<p id="media-icon"><img src="'.$file->media_icon.'" alt="" /></p>';
322
323echo
324'<div id="media-details">';
325
326if ($file->media_image)
327{
328     $thumb_size = !empty($_GET['size']) ? $_GET['size'] : 's';
329     
330     if (!isset($core->media->thumb_sizes[$thumb_size]) && $thumb_size != 'o') {
331          $thumb_size = 's';
332     }
333     
334     echo '<p>'.__('Available sizes:').' ';
335     foreach (array_reverse($file->media_thumb) as $s => $v)
336     {
337          $strong_link = ($s == $thumb_size) ? '<strong>%s</strong>' : '%s';
338          printf($strong_link,'<a href="'.html::escapeURL($page_url).
339          '&amp;id='.$id.'&amp;size='.$s.'">'.$core->media->thumb_sizes[$s][2].'</a> | ');
340     }
341     echo '<a href="'.html::escapeURL($page_url).'&amp;id='.$id.'&amp;size=o">'.__('original').'</a>';
342     echo '</p>';
343     
344     if (isset($file->media_thumb[$thumb_size])) {
345          echo '<p><img src="'.$file->media_thumb[$thumb_size].'" alt="" /></p>';
346     } elseif ($thumb_size == 'o') {
347          $S = getimagesize($file->file);
348          $class = ($S[1] > 500) ? ' class="overheight"' : '';
349          unset($S);
350          echo '<p id="media-original-image"'.$class.'><img src="'.$file->file_url.'" alt="" /></p>';
351     }
352}
353
354if ($file->type == 'audio/mpeg3')
355{
356     echo dcMedia::mp3player($file->file_url,'index.php?pf=player_mp3.swf');
357}
358
359if ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v')
360{
361     echo dcMedia::flvplayer($file->file_url,'index.php?pf=player_flv.swf');
362}
363
364echo
365'<h3>'.__('Media details').'</h3>'.
366'<ul>'.
367     '<li><strong>'.__('File owner:').'</strong> '.$file->media_user.'</li>'.
368     '<li><strong>'.__('File type:').'</strong> '.$file->type.'</li>'.
369     '<li><strong>'.__('File size:').'</strong> '.files::size($file->size).'</li>'.
370     '<li><strong>'.__('File URL:').'</strong> <a href="'.$file->file_url.'">'.$file->file_url.'</a></li>'.
371'</ul>';
372
373if (empty($_GET['find_posts']))
374{
375     echo
376     '<p><strong><a href="'.html::escapeHTML($page_url).'&amp;id='.$id.'&amp;find_posts=1">'.
377     __('Show entries containing this media').'</a></strong></p>';
378}
379else
380{
381     echo '<h3>'.__('Entries containing this media').'</h3>';
382     $params = array(
383          'post_type' => '',
384          'from' => 'LEFT OUTER JOIN '.$core->prefix.'post_media PM ON P.post_id = PM.post_id ',
385          'sql' => 'AND ('.
386               'PM.media_id = '.(integer) $id.' '.
387               "OR post_content_xhtml LIKE '%".$core->con->escape($file->relname)."%' ".
388               "OR post_excerpt_xhtml LIKE '%".$core->con->escape($file->relname)."%' "
389     );
390     
391     if ($file->media_image)
392     { # We look for thumbnails too
393          $media_root = $core->blog->host.path::clean($core->blog->settings->system->public_url).'/';
394          foreach ($file->media_thumb as $v) {
395               $v = preg_replace('/^'.preg_quote($media_root,'/').'/','',$v);
396               $params['sql'] .= "OR post_content_xhtml LIKE '%".$core->con->escape($v)."%' ";
397               $params['sql'] .= "OR post_excerpt_xhtml LIKE '%".$core->con->escape($v)."%' ";
398          }
399     }
400     
401     $params['sql'] .= ') ';
402     
403     $rs = $core->blog->getPosts($params);
404     
405     if ($rs->isEmpty())
406     {
407          echo '<p>'.__('No entry seems contain this media.').'</p>';
408     }
409     else
410     {
411          echo '<ul>';
412          while ($rs->fetch()) {
413               echo '<li><a href="'.$core->getPostAdminURL($rs->post_type,$rs->post_id).'">'.
414               $rs->post_title.'</a>'.
415               ($rs->post_type != 'post' ? ' ('.html::escapeHTML($rs->post_type).')' : '').
416               ' - '.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->post_dt).'</li>';
417          }
418          echo '</ul>';
419     }
420}
421
422if ($file->type == 'image/jpeg')
423{
424     echo '<h3>'.__('Image details').'</h3>';
425     
426     if (count($file->media_meta) == 0)
427     {
428          echo '<p>'.__('No detail').'</p>';
429     }
430     else
431     {
432          echo '<ul>';
433          foreach ($file->media_meta as $k => $v)
434          {
435               if ((string) $v) {
436                    echo '<li><strong>'.$k.':</strong> '.html::escapeHTML($v).'</li>';
437               }
438          }
439          echo '</ul>';
440     }
441}
442
443if ($file->editable && $core_media_writable)
444{
445     if ($file->media_type == 'image')
446     {
447          echo
448          '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'.
449          '<fieldset><legend>'.__('Update thumbnails').'</legend>'.
450          '<p>'.__('This will create or update thumbnails for this image.').'</p>'.
451          '<p><input type="submit" name="thumbs" value="'.__('update thumbnails').'" />'.
452          form::hidden(array('id'),$id).
453          $core->formNonce().'</p>'.
454          '</fieldset></form>';
455     }
456     
457     if ($file->type == 'application/zip')
458     {
459          $inflate_combo = array(
460               __('Extract in a new directory') => 'new',
461               __('Extract in current directory') => 'current'
462          );
463         
464          echo
465          '<form class="clear" id="file-unzip" action="'.html::escapeURL($page_url).'" method="post">'.
466          '<fieldset><legend>'.__('Extract archive').'</legend>'.
467          '<ul>'.
468          '<li><strong>'.__('Extract in a new directory').'</strong> : '.
469          __('This will extract archive in a new directory that should not exist yet.').'</li>'.
470          '<li><strong>'.__('Extract in current directory').'</strong> : '.
471          __('This will extract archive in current directory and will overwrite existing files or directory.').'</li>'.
472          '</ul>'.
473          '<p><label for="inflate_mode" class="classic">'.__('Extract mode:').' '.
474          form::combo('inflate_mode',$inflate_combo,'new').'</label> '.
475          '<input type="submit" name="unzip" value="'.__('extract').'" />'.
476          form::hidden(array('id'),$id).
477          $core->formNonce().'</p>'.
478          '</fieldset></form>';
479     }
480     
481     echo
482     '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'.
483     '<fieldset><legend>'.__('Change media properties').'</legend>'.
484     '<p><label for="media_file">'.__('File name:').
485     form::field('media_file',30,255,html::escapeHTML($file->basename)).'</label></p>'.
486     '<p><label for="media_title">'.__('File title:').
487     form::field('media_title',30,255,html::escapeHTML($file->media_title)).'</label></p>'.
488     '<p><label for="media_dt">'.__('File date:').
489     form::field('media_dt',16,16,html::escapeHTML($file->media_dtstr)).'</label></p>'.
490     '<p><label for="media_private" class="classic">'.form::checkbox('media_private',1,$file->media_priv).' '.
491     __('Private').'</label></p>'.
492     '<p><label for="media_path">'.__('New directory:').
493     form::combo('media_path',$dirs_combo,dirname($file->relname)).'</label></p>'.
494     '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'.
495     form::hidden(array('id'),$id).
496     $core->formNonce().'</p>'.
497     '</fieldset></form>';
498     
499     echo
500     '<form class="clear" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data">'.
501     '<fieldset><legend>'.__('Change file').'</legend>'.
502     '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'.
503     '<p><label for="upfile">'.__('Choose a file:').
504     ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).') '.
505     '<input type="file" id="upfile" name="upfile" size="35" />'.
506     '</label></p>'.
507     '<p><input type="submit" value="'.__('send').'" />'.
508     form::hidden(array('id'),$id).
509     $core->formNonce().'</p>'.
510     '</fieldset></form>';
511
512     # --BEHAVIOR-- adminMediaItemForm
513     $core->callBehavior('adminMediaItemForm',$file);
514}
515
516echo
517'</div>'.
518'</div>';
519
520call_user_func($close_f);
521?>
Note: See TracBrowser for help on using the repository browser.

Sites map