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