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 | /* HTML page |
---|
14 | -------------------------------------------------------- */ |
---|
15 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
16 | |
---|
17 | dcPage::check('media,media_admin'); |
---|
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,'post_type'=>'')); |
---|
22 | if ($post->isEmpty()) { |
---|
23 | $post_id = null; |
---|
24 | } |
---|
25 | $post_title = $post->post_title; |
---|
26 | $post_type = $post->post_type; |
---|
27 | unset($post); |
---|
28 | } |
---|
29 | $d = isset($_REQUEST['d']) ? $_REQUEST['d'] : null; |
---|
30 | $plugin_id = isset($_REQUEST['plugin_id']) ? html::sanitizeURL($_REQUEST['plugin_id']) : ''; |
---|
31 | $dir = null; |
---|
32 | |
---|
33 | // Attachement type if any |
---|
34 | $link_type = !empty($_REQUEST['link_type']) ? html::escapeHTML($_REQUEST['link_type']) : null; |
---|
35 | |
---|
36 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
37 | $nb_per_page = ((integer) $core->auth->user_prefs->interface->media_by_page ?: 30); |
---|
38 | |
---|
39 | # We are on home not comming from media manager |
---|
40 | if ($d === null && isset($_SESSION['media_manager_dir'])) { |
---|
41 | # We get session information |
---|
42 | $d = $_SESSION['media_manager_dir']; |
---|
43 | } |
---|
44 | |
---|
45 | if (!isset($_GET['page']) && isset($_SESSION['media_manager_page'])) { |
---|
46 | $page = $_SESSION['media_manager_page']; |
---|
47 | } |
---|
48 | |
---|
49 | # We set session information about directory, page and display mode |
---|
50 | if ($d) { |
---|
51 | $_SESSION['media_manager_dir'] = $d; |
---|
52 | } else { |
---|
53 | unset($_SESSION['media_manager_dir']); |
---|
54 | } |
---|
55 | if ($page != 1) { |
---|
56 | $_SESSION['media_manager_page'] = $page; |
---|
57 | } else { |
---|
58 | unset($_SESSION['media_manager_page']); |
---|
59 | } |
---|
60 | |
---|
61 | # Get query if any |
---|
62 | $q = isset($_REQUEST['q']) ? html::escapeHTML($_REQUEST['q']) : null; |
---|
63 | |
---|
64 | # Sort combo |
---|
65 | $sort_combo = array( |
---|
66 | __('By names, in ascending order') => 'name-asc', |
---|
67 | __('By names, in descending order') => 'name-desc', |
---|
68 | __('By dates, in ascending order') => 'date-asc', |
---|
69 | __('By dates, in descending order') => 'date-desc' |
---|
70 | ); |
---|
71 | |
---|
72 | if (!empty($_GET['file_mode'])) { |
---|
73 | $_SESSION['media_file_mode'] = $_GET['file_mode']; |
---|
74 | } |
---|
75 | $file_mode = !empty($_SESSION['media_file_mode']) ? $_SESSION['media_file_mode'] : 'grid'; |
---|
76 | |
---|
77 | $file_sort = null; |
---|
78 | if (!empty($_GET['file_sort'])) { |
---|
79 | $file_sort = $_SESSION['media_file_sort'] = $_GET['file_sort']; |
---|
80 | setcookie('dc_media_sort',json_encode($file_sort)); |
---|
81 | } elseif (isset($_COOKIE['dc_media_sort'])) { |
---|
82 | $file_sort = json_decode($_COOKIE['dc_media_sort']); |
---|
83 | } elseif (!empty($_SESSION['media_file_sort'])) { |
---|
84 | $file_sort = $_SESSION['media_file_sort']; |
---|
85 | } |
---|
86 | $file_sort = in_array($file_sort,$sort_combo) ? $file_sort : null; |
---|
87 | |
---|
88 | $nb_per_page = !empty($_SESSION['nb_per_page']) ? (integer)$_SESSION['nb_per_page'] : $nb_per_page; |
---|
89 | if (!empty($_GET['nb_per_page']) && (integer)$_GET['nb_per_page'] > 0) { |
---|
90 | $nb_per_page = $_SESSION['nb_per_page'] = (integer)$_GET['nb_per_page']; |
---|
91 | } |
---|
92 | |
---|
93 | $popup = (integer) !empty($_REQUEST['popup']); |
---|
94 | $select = !empty($_REQUEST['select']) ? (integer)$_REQUEST['select'] : 0; // 0 : none, 1 : single media, >1 : multiple medias |
---|
95 | |
---|
96 | $page_url_params = new ArrayObject(array('popup' => $popup,'select' => $select,'post_id' => $post_id,'link_type' => $link_type)); |
---|
97 | if ($d) { |
---|
98 | $page_url_params['d'] = $d; |
---|
99 | } |
---|
100 | if ($plugin_id != '') { |
---|
101 | $page_url_params['plugin_id'] = $plugin_id; |
---|
102 | } |
---|
103 | if ($q) { |
---|
104 | $page_url_params['q'] = $q; |
---|
105 | } |
---|
106 | |
---|
107 | $core->callBehavior('adminMediaURLParams',$page_url_params); |
---|
108 | $page_url_params = (array) $page_url_params; |
---|
109 | |
---|
110 | if ($popup) { |
---|
111 | $open_f = array('dcPage','openPopup'); |
---|
112 | $close_f = array('dcPage','closePopup'); |
---|
113 | } else { |
---|
114 | $open_f = array('dcPage','open'); |
---|
115 | $close_f = create_function('',"dcPage::helpBlock('core_media'); dcPage::close();"); |
---|
116 | } |
---|
117 | |
---|
118 | $core_media_writable = false; |
---|
119 | try { |
---|
120 | $core->media = new dcMedia($core); |
---|
121 | if ($file_sort) { |
---|
122 | $core->media->setFileSort($file_sort); |
---|
123 | } |
---|
124 | $query = false; |
---|
125 | if ($q) { |
---|
126 | $query = $core->media->searchMedia($q); |
---|
127 | } |
---|
128 | if (!$query) { |
---|
129 | $try_d = $d; |
---|
130 | // Reset current dir |
---|
131 | $d = null; |
---|
132 | // Change directory (may cause an exception if directory doesn't exist) |
---|
133 | $core->media->chdir($try_d); |
---|
134 | // Restore current dir variable |
---|
135 | $d = $try_d; |
---|
136 | $core->media->getDir(); |
---|
137 | } else { |
---|
138 | $d = null; |
---|
139 | $core->media->chdir($d); |
---|
140 | } |
---|
141 | $core_media_writable = $core->media->writable(); |
---|
142 | $dir =& $core->media->dir; |
---|
143 | if (!$core_media_writable) { |
---|
144 | // throw new Exception('you do not have sufficient permissions to write to this folder: '); |
---|
145 | } |
---|
146 | } catch (Exception $e) { |
---|
147 | $core->error->add($e->getMessage()); |
---|
148 | } |
---|
149 | |
---|
150 | # Zip download |
---|
151 | if (!empty($_GET['zipdl']) && $core->auth->check('media_admin',$core->blog->id)) |
---|
152 | { |
---|
153 | try |
---|
154 | { |
---|
155 | if (strpos(realpath($core->media->root.'/'.$d),realpath($core->media->root)) === 0) { |
---|
156 | // Media folder or one of it's sub-folder(s) |
---|
157 | @set_time_limit(300); |
---|
158 | $fp = fopen('php://output','wb'); |
---|
159 | $zip = new fileZip($fp); |
---|
160 | $zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#'); |
---|
161 | $zip->addDirectory($core->media->root.'/'.$d,'',true); |
---|
162 | |
---|
163 | header('Content-Disposition: attachment;filename='.date('Y-m-d').'-'.$core->blog->id.'-'.($d ?: 'media').'.zip'); |
---|
164 | header('Content-Type: application/x-zip'); |
---|
165 | $zip->write(); |
---|
166 | unset($zip); |
---|
167 | exit; |
---|
168 | } else { |
---|
169 | $d = null; |
---|
170 | $core->media->chdir($d); |
---|
171 | throw new Exception(__('Not a valid directory')); |
---|
172 | } |
---|
173 | } |
---|
174 | catch (Exception $e) |
---|
175 | { |
---|
176 | $core->error->add($e->getMessage()); |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | # Cope with fav/unfav dir |
---|
181 | $fav_dirs = null; |
---|
182 | if (!empty($_GET['fav'])) { |
---|
183 | if (!$q) { // Ignore search results |
---|
184 | $fav_dir = rtrim($d,'/'); |
---|
185 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
186 | $nb_last_dirs = (integer)($core->auth->user_prefs->interface->media_nb_last_dirs); |
---|
187 | if ($nb_last_dirs > 0) { |
---|
188 | $fav_dirs = $core->auth->user_prefs->interface->media_fav_dirs; |
---|
189 | if (!is_array($fav_dirs)) { |
---|
190 | $fav_dirs = array(); |
---|
191 | } |
---|
192 | if (!in_array($fav_dir,$fav_dirs) && $_GET['fav'] == 'y') { |
---|
193 | // Add directory in favorites |
---|
194 | array_unshift($fav_dirs,$fav_dir); |
---|
195 | } elseif (in_array($fav_dir,$fav_dirs) && $_GET['fav'] == 'n') { |
---|
196 | // Remove directory from favorites |
---|
197 | unset($fav_dirs[array_search($fav_dir,$fav_dirs)]); |
---|
198 | } |
---|
199 | // Store new list |
---|
200 | $core->auth->user_prefs->interface->put('media_fav_dirs',$fav_dirs,'array'); |
---|
201 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | # Recent media dirs |
---|
207 | $last_dirs = null; |
---|
208 | if (!$q) { // Ignore search results |
---|
209 | $recent_dir = rtrim($d,'/'); |
---|
210 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
211 | $nb_last_dirs = (integer)($core->auth->user_prefs->interface->media_nb_last_dirs); |
---|
212 | if ($nb_last_dirs > 0) { |
---|
213 | $last_dirs = $core->auth->user_prefs->interface->media_last_dirs; |
---|
214 | if (!is_array($last_dirs)) { |
---|
215 | $last_dirs = array(); |
---|
216 | } |
---|
217 | if (!in_array($recent_dir,$last_dirs)) { |
---|
218 | // Add new dir at the top of the list |
---|
219 | array_unshift($last_dirs,$recent_dir); |
---|
220 | // Remove oldest dir(s) |
---|
221 | while (count($last_dirs) > $nb_last_dirs) { |
---|
222 | array_pop($last_dirs); |
---|
223 | } |
---|
224 | } else { |
---|
225 | // Move current dir at the top of list |
---|
226 | unset($last_dirs[array_search($recent_dir,$last_dirs)]); |
---|
227 | array_unshift($last_dirs,$recent_dir); |
---|
228 | } |
---|
229 | // Store new list |
---|
230 | $core->auth->user_prefs->interface->put('media_last_dirs',$last_dirs,'array'); |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | # New directory |
---|
235 | if ($dir && !empty($_POST['newdir'])) |
---|
236 | { |
---|
237 | try { |
---|
238 | $core->media->makeDir($_POST['newdir']); |
---|
239 | dcPage::addSuccessNotice(sprintf( |
---|
240 | __('Directory "%s" has been successfully created.'), |
---|
241 | html::escapeHTML($_POST['newdir'])) |
---|
242 | ); |
---|
243 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
244 | } catch (Exception $e) { |
---|
245 | $core->error->add($e->getMessage()); |
---|
246 | } |
---|
247 | } |
---|
248 | |
---|
249 | # Adding a file |
---|
250 | if ($dir && !empty($_FILES['upfile'])) { |
---|
251 | // only one file per request : @see option singleFileUploads in admin/js/jsUpload/jquery.fileupload |
---|
252 | $upfile = array('name' => $_FILES['upfile']['name'][0], |
---|
253 | 'type' => $_FILES['upfile']['type'][0], |
---|
254 | 'tmp_name' => $_FILES['upfile']['tmp_name'][0], |
---|
255 | 'error' => $_FILES['upfile']['error'][0], |
---|
256 | 'size' => $_FILES['upfile']['size'][0] |
---|
257 | ); |
---|
258 | |
---|
259 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
---|
260 | header('Content-type: application/json'); |
---|
261 | $message = array(); |
---|
262 | |
---|
263 | try { |
---|
264 | files::uploadStatus($upfile); |
---|
265 | $new_file_id = $core->media->uploadFile($upfile['tmp_name'], $upfile['name']); |
---|
266 | |
---|
267 | $message['files'][] = array( |
---|
268 | 'name' => $upfile['name'], |
---|
269 | 'size' => $upfile['size'], |
---|
270 | 'html' => mediaItemLine($core->media->getFile($new_file_id),1,$query) |
---|
271 | ); |
---|
272 | } catch (Exception $e) { |
---|
273 | $message['files'][] = array('name' => $upfile['name'], |
---|
274 | 'size' => $upfile['size'], |
---|
275 | 'error' => $e->getMessage() |
---|
276 | ); |
---|
277 | } |
---|
278 | echo json_encode($message); |
---|
279 | exit(); |
---|
280 | } else { |
---|
281 | try { |
---|
282 | files::uploadStatus($upfile); |
---|
283 | |
---|
284 | $f_title = (isset($_POST['upfiletitle']) ? $_POST['upfiletitle'] : ''); |
---|
285 | $f_private = (isset($_POST['upfilepriv']) ? $_POST['upfilepriv'] : false); |
---|
286 | |
---|
287 | $core->media->uploadFile($upfile['tmp_name'],$upfile['name'],$f_title,$f_private); |
---|
288 | |
---|
289 | dcPage::addSuccessNotice(__('Files have been successfully uploaded.')); |
---|
290 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
291 | } catch (Exception $e) { |
---|
292 | $core->error->add($e->getMessage()); |
---|
293 | } |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | # Removing items |
---|
298 | if ($dir && !empty($_POST['medias']) && !empty($_POST['delete_medias'])) { |
---|
299 | try { |
---|
300 | foreach ($_POST['medias'] as $media) { |
---|
301 | $core->media->removeItem(rawurldecode($media)); |
---|
302 | } |
---|
303 | dcPage::addSuccessNotice( |
---|
304 | sprintf(__('Successfully delete one media.', |
---|
305 | 'Successfully delete %d medias.', |
---|
306 | count($_POST['medias']) |
---|
307 | ), |
---|
308 | count($_POST['medias']) |
---|
309 | ) |
---|
310 | ); |
---|
311 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
312 | } catch (Exception $e) { |
---|
313 | $core->error->add($e->getMessage()); |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | # Removing item from popup only |
---|
318 | if ($dir && !empty($_POST['rmyes']) && !empty($_POST['remove'])) |
---|
319 | { |
---|
320 | $_POST['remove'] = rawurldecode($_POST['remove']); |
---|
321 | |
---|
322 | try { |
---|
323 | if (is_dir(path::real($core->media->getPwd().'/'.path::clean($_POST['remove'])))) { |
---|
324 | $msg = __('Directory has been successfully removed.'); |
---|
325 | } else { |
---|
326 | $msg = __('File has been successfully removed.'); |
---|
327 | } |
---|
328 | $core->media->removeItem($_POST['remove']); |
---|
329 | dcPage::addSuccessNotice($msg); |
---|
330 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
331 | } catch (Exception $e) { |
---|
332 | $core->error->add($e->getMessage()); |
---|
333 | } |
---|
334 | } |
---|
335 | |
---|
336 | # Rebuild directory |
---|
337 | if ($dir && $core->auth->isSuperAdmin() && !empty($_POST['rebuild'])) |
---|
338 | { |
---|
339 | try { |
---|
340 | $core->media->rebuild($d); |
---|
341 | |
---|
342 | dcPage::success(sprintf( |
---|
343 | __('Directory "%s" has been successfully rebuilt.'), |
---|
344 | html::escapeHTML($d)) |
---|
345 | ); |
---|
346 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
347 | } catch (Exception $e) { |
---|
348 | $core->error->add($e->getMessage()); |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | # DISPLAY confirm page for rmdir & rmfile |
---|
353 | if ($dir && !empty($_GET['remove']) && empty($_GET['noconfirm'])) |
---|
354 | { |
---|
355 | call_user_func($open_f,__('Media manager'),'', |
---|
356 | dcPage::breadcrumb( |
---|
357 | array( |
---|
358 | html::escapeHTML($core->blog->name) => '', |
---|
359 | __('Media manager') => '', |
---|
360 | __('confirm removal') => '' |
---|
361 | ), |
---|
362 | array('home_link' => !$popup) |
---|
363 | ) |
---|
364 | ); |
---|
365 | |
---|
366 | echo |
---|
367 | '<form action="'.html::escapeURL($core->adminurl->get('admin.media')).'" method="post">'. |
---|
368 | '<p>'.sprintf(__('Are you sure you want to remove %s?'), |
---|
369 | html::escapeHTML($_GET['remove'])).'</p>'. |
---|
370 | '<p><input type="submit" value="'.__('Cancel').'" /> '. |
---|
371 | ' <input type="submit" name="rmyes" value="'.__('Yes').'" />'. |
---|
372 | form::hidden('d',$d). |
---|
373 | form::hidden('q',$q). |
---|
374 | $core->adminurl->getHiddenFormFields('admin.media',$page_url_params). |
---|
375 | $core->formNonce(). |
---|
376 | form::hidden('remove',html::escapeHTML($_GET['remove'])).'</p>'. |
---|
377 | '</form>'; |
---|
378 | |
---|
379 | call_user_func($close_f); |
---|
380 | exit; |
---|
381 | } |
---|
382 | |
---|
383 | /* DISPLAY Main page |
---|
384 | -------------------------------------------------------- */ |
---|
385 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
386 | $user_ui_enhanceduploader = $core->auth->user_prefs->interface->enhanceduploader; |
---|
387 | |
---|
388 | if (!isset($core->media)) { |
---|
389 | $breadcrumb = dcPage::breadcrumb( |
---|
390 | array( |
---|
391 | html::escapeHTML($core->blog->name) => '', |
---|
392 | __('Media manager') => '' |
---|
393 | ), |
---|
394 | array('home_link' => !$popup) |
---|
395 | ); |
---|
396 | } else { |
---|
397 | $home_params = $page_url_params; |
---|
398 | $home_params['d']=''; |
---|
399 | $home_params['q']=''; |
---|
400 | if ($query || (!$query && $q)) { |
---|
401 | $count = $query ? count($dir['files']) : 0; |
---|
402 | $breadcrumb = dcPage::breadcrumb( |
---|
403 | array( |
---|
404 | html::escapeHTML($core->blog->name) => '', |
---|
405 | __('Media manager') => $core->adminurl->get('admin.media',$home_params), |
---|
406 | __('Search:').' '.$q.' ('.sprintf(__('%s file found','%s files found',$count),$count).')' => '' |
---|
407 | ), |
---|
408 | array('home_link' => !$popup) |
---|
409 | ); |
---|
410 | } else { |
---|
411 | $temp_params = $page_url_params; |
---|
412 | $temp_params['d']='%s'; |
---|
413 | $bc_template = $core->adminurl->get('admin.media',$temp_params,'&',true); |
---|
414 | $breadcrumb_media = $core->media->breadCrumb($bc_template,'<span class="page-title">%s</span>'); |
---|
415 | if ($breadcrumb_media == '') { |
---|
416 | $breadcrumb = dcPage::breadcrumb( |
---|
417 | array( |
---|
418 | html::escapeHTML($core->blog->name) => '', |
---|
419 | __('Media manager') => $core->adminurl->get('admin.media',$home_params) |
---|
420 | ), |
---|
421 | array('home_link' => !$popup) |
---|
422 | ); |
---|
423 | } else { |
---|
424 | $home_params = $page_url_params; |
---|
425 | $home_params['d']=''; |
---|
426 | |
---|
427 | $breadcrumb = dcPage::breadcrumb( |
---|
428 | array( |
---|
429 | html::escapeHTML($core->blog->name) => '', |
---|
430 | __('Media manager') => $core->adminurl->get('admin.media',$home_params), |
---|
431 | $breadcrumb_media => '' |
---|
432 | ), |
---|
433 | array( |
---|
434 | 'home_link' => !$popup, |
---|
435 | 'hl' => false |
---|
436 | ) |
---|
437 | ); |
---|
438 | } |
---|
439 | } |
---|
440 | } |
---|
441 | |
---|
442 | // Recent media folders |
---|
443 | $last_folders = ''; |
---|
444 | $last_folders_item = ''; |
---|
445 | $fav_url = ''; |
---|
446 | $fav_img = ''; |
---|
447 | $fav_alt = ''; |
---|
448 | $nb_last_dirs = (integer)($core->auth->user_prefs->interface->media_nb_last_dirs); |
---|
449 | if ($nb_last_dirs > 0) { |
---|
450 | // Favorites directories |
---|
451 | $fav_dirs = $core->auth->user_prefs->interface->media_fav_dirs; |
---|
452 | if (!is_array($fav_dirs)) { |
---|
453 | $fav_dirs = array(); |
---|
454 | } |
---|
455 | foreach ($fav_dirs as $ld) { |
---|
456 | // Add favorites dirs on top of combo |
---|
457 | $ld_params = $page_url_params; |
---|
458 | $ld_params['d'] = $ld; |
---|
459 | $ld_params['q'] = ''; // Reset search |
---|
460 | $last_folders_item .= |
---|
461 | '<option value="'.urldecode($core->adminurl->get('admin.media',$ld_params)).'"'. |
---|
462 | ($ld == rtrim($d,'/') ? ' selected="selected"' : '').'>'. |
---|
463 | '/'.$ld.'</option>'."\n"; |
---|
464 | if ($ld == rtrim($d,'/')) { |
---|
465 | // Current directory is a favorite → button will un-fav |
---|
466 | $ld_params['fav'] = 'n'; |
---|
467 | $fav_url = urldecode($core->adminurl->get('admin.media',$ld_params)); |
---|
468 | unset($ld_params['fav']); |
---|
469 | $fav_img = 'images/fav-on.png'; |
---|
470 | $fav_alt = __('Remove this folder from your favorites'); |
---|
471 | } |
---|
472 | } |
---|
473 | if ($last_folders_item != '') { |
---|
474 | // add a separator between favorite dirs and recent dirs |
---|
475 | $last_folders_item .= '<option disabled>_________</option>'; |
---|
476 | } |
---|
477 | // Recent directories |
---|
478 | if (!is_array($last_dirs)) { |
---|
479 | $last_dirs = $core->auth->user_prefs->interface->media_last_dirs; |
---|
480 | } |
---|
481 | if (is_array($last_dirs)) { |
---|
482 | foreach ($last_dirs as $ld) { |
---|
483 | if (!in_array($ld,$fav_dirs)) { |
---|
484 | $ld_params = $page_url_params; |
---|
485 | $ld_params['d'] = $ld; |
---|
486 | $ld_params['q'] = ''; // Reset search |
---|
487 | $last_folders_item .= |
---|
488 | '<option value="'.urldecode($core->adminurl->get('admin.media',$ld_params)).'"'. |
---|
489 | ($ld == rtrim($d,'/') ? ' selected="selected"' : '').'>'. |
---|
490 | '/'.$ld.'</option>'."\n"; |
---|
491 | if ($ld == rtrim($d,'/')) { |
---|
492 | // Current directory is not a favorite → button will fav |
---|
493 | $ld_params['fav'] = 'y'; |
---|
494 | $fav_url = urldecode($core->adminurl->get('admin.media',$ld_params)); |
---|
495 | unset($ld_params['fav']); |
---|
496 | $fav_img = 'images/fav-off.png'; |
---|
497 | $fav_alt = __('Add this folder to your favorites'); |
---|
498 | } |
---|
499 | } |
---|
500 | } |
---|
501 | } |
---|
502 | if ($last_folders_item != '') { |
---|
503 | $last_folders = |
---|
504 | '<p class="media-recent hidden-if-no-js">'. |
---|
505 | '<label class="classic" for="switchfolder">'.__('Goto recent folder:').'</label> '. |
---|
506 | '<select name="switchfolder" id="switchfolder">'. |
---|
507 | $last_folders_item. |
---|
508 | '</select>'. |
---|
509 | '<script type="text/javascript">var urlmenu = document.getElementById(\'switchfolder\'); |
---|
510 | urlmenu.onchange = function() { window.location = this.options[this.selectedIndex].value; }; |
---|
511 | </script>'. |
---|
512 | ' <a id="media-fav-dir" href="'.$fav_url.'" title="'.$fav_alt.'"><img src="'.$fav_img.'" alt="'.$fav_alt.'" /></a>'. |
---|
513 | '</p>'; |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | call_user_func($open_f,__('Media manager'), |
---|
518 | dcPage::jsLoad('js/_media.js'). |
---|
519 | ($core_media_writable ? dcPage::jsUpload(array('d='.$d)) : ''), |
---|
520 | $breadcrumb |
---|
521 | ); |
---|
522 | |
---|
523 | if ($popup) { |
---|
524 | // Display notices |
---|
525 | echo dcPage::notices(); |
---|
526 | } |
---|
527 | |
---|
528 | if (!$core_media_writable) { |
---|
529 | dcPage::warning(__('You do not have sufficient permissions to write to this folder.')); |
---|
530 | } |
---|
531 | |
---|
532 | if (!empty($_GET['mkdok'])) { |
---|
533 | dcPage::success(__('Directory has been successfully created.')); |
---|
534 | } |
---|
535 | |
---|
536 | if (!empty($_GET['upok'])) { |
---|
537 | dcPage::success(__('Files have been successfully uploaded.')); |
---|
538 | } |
---|
539 | |
---|
540 | if (!empty($_GET['rmfok'])) { |
---|
541 | dcPage::success(__('File has been successfully removed.')); |
---|
542 | } |
---|
543 | |
---|
544 | if (!empty($_GET['rmdok'])) { |
---|
545 | dcPage::success(__('Directory has been successfully removed.')); |
---|
546 | } |
---|
547 | |
---|
548 | if (!empty($_GET['rebuildok'])) { |
---|
549 | dcPage::success(__('Directory has been successfully rebuilt.')); |
---|
550 | } |
---|
551 | |
---|
552 | if (!empty($_GET['unzipok'])) { |
---|
553 | dcPage::success(__('Zip file has been successfully extracted.')); |
---|
554 | } |
---|
555 | |
---|
556 | if (!$dir) { |
---|
557 | call_user_func($close_f); |
---|
558 | exit; |
---|
559 | } |
---|
560 | |
---|
561 | if ($select) { |
---|
562 | // Select mode (popup or not) |
---|
563 | echo '<div class="'.($popup ? 'form-note ' : '').'info"><p>'; |
---|
564 | if ($select == 1) { |
---|
565 | echo sprintf(__('Select a file by clicking on %s'),'<img src="images/plus.png" alt="'.__('Select this file').'" />'); |
---|
566 | } else { |
---|
567 | echo sprintf(__('Select files and click on <strong>%s</strong> button'),__('Choose selected medias')); |
---|
568 | } |
---|
569 | if ($core_media_writable) { |
---|
570 | echo ' '.__('or').' '.sprintf('<a href="#fileupload">%s</a>',__('upload a new file')); |
---|
571 | } |
---|
572 | echo '</p></div>'; |
---|
573 | } else { |
---|
574 | if ($post_id) { |
---|
575 | echo '<div class="form-note info"><p>'.sprintf(__('Choose a file to attach to entry %s by clicking on %s'), |
---|
576 | '<a href="'.$core->getPostAdminURL($post_type,$post_id).'">'.html::escapeHTML($post_title).'</a>', |
---|
577 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />'); |
---|
578 | if ($core_media_writable) { |
---|
579 | echo ' '.__('or').' '.sprintf('<a href="#fileupload">%s</a>',__('upload a new file')); |
---|
580 | } |
---|
581 | echo '</p></div>'; |
---|
582 | } |
---|
583 | if ($popup) { |
---|
584 | echo '<div class="info"><p>'.sprintf(__('Choose a file to insert into entry by clicking on %s'), |
---|
585 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />'); |
---|
586 | if ($core_media_writable) { |
---|
587 | echo ' '.__('or').' '.sprintf('<a href="#fileupload">%s</a>',__('upload a new file')); |
---|
588 | } |
---|
589 | echo '</p></div>'; |
---|
590 | } |
---|
591 | } |
---|
592 | |
---|
593 | // Remove hidden directories (unless DC_SHOW_HIDDEN_DIRS is set to true) |
---|
594 | if (!defined('DC_SHOW_HIDDEN_DIRS') || (DC_SHOW_HIDDEN_DIRS == false)) { |
---|
595 | for ($i = count($dir['dirs']) - 1; $i >= 0; $i--) { |
---|
596 | if ($dir['dirs'][$i]->d) { |
---|
597 | if (strpos($dir['dirs'][$i]->relname,'.') !== false) { |
---|
598 | unset($dir['dirs'][$i]); |
---|
599 | } |
---|
600 | } |
---|
601 | } |
---|
602 | } |
---|
603 | $items = array_values(array_merge($dir['dirs'],$dir['files'])); |
---|
604 | |
---|
605 | $fmt_form_media = '<form action="'.$core->adminurl->get("admin.media").'" method="post" id="form-medias">'. |
---|
606 | '<div class="files-group">%s</div>'. |
---|
607 | '<p class="hidden">'.$core->formNonce(). |
---|
608 | form::hidden(array('d'),$d). |
---|
609 | form::hidden(array('q'),$q). |
---|
610 | form::hidden(array('popup'),$popup). |
---|
611 | form::hidden(array('select'),$select). |
---|
612 | form::hidden(array('plugin_id'),$plugin_id). |
---|
613 | form::hidden(array('post_id'),$post_id). |
---|
614 | form::hidden(array('link_type'),$link_type). |
---|
615 | '</p>'; |
---|
616 | |
---|
617 | if (!$popup || $select > 1) { |
---|
618 | // Checkboxes and action |
---|
619 | $fmt_form_media .= |
---|
620 | '<div class="'.(!$popup ? 'medias-delete' : '').' '.($select > 1 ? 'medias-select' : '').'">'. |
---|
621 | '<p class="checkboxes-helpers"></p>'. |
---|
622 | '<p>'; |
---|
623 | if ($select > 1) { |
---|
624 | $fmt_form_media .= |
---|
625 | '<input type="submit" class="select" id="select_medias" name="select_medias" value="'.__('Choose selected medias').'"/> '; |
---|
626 | } |
---|
627 | if (!$popup) { |
---|
628 | $fmt_form_media .= |
---|
629 | '<input type="submit" class="delete" id="delete_medias" name="delete_medias" value="'.__('Remove selected medias').'"/>'; |
---|
630 | } |
---|
631 | $fmt_form_media .= |
---|
632 | '</p>'. |
---|
633 | '</div>'; |
---|
634 | } |
---|
635 | $fmt_form_media .= |
---|
636 | '</form>'; |
---|
637 | |
---|
638 | echo '<div class="media-list">'; |
---|
639 | echo $last_folders; |
---|
640 | echo // Search form |
---|
641 | '<form action="'.$core->adminurl->get("admin.media").'" method="get" id="search-form">'. |
---|
642 | '<p><label for="search" class="classic">'.__('Search:').'</label> '. |
---|
643 | form::field('q',20,255,$q).' '. |
---|
644 | '<input type="submit" value="'.__('OK').'" />'.' '. |
---|
645 | '<span class="form-note">'.__('Will search into media filename (including path), title and description').'</span>'. |
---|
646 | form::hidden(array('popup'),$popup). |
---|
647 | form::hidden(array('select'),$select). |
---|
648 | form::hidden(array('plugin_id'),$plugin_id). |
---|
649 | form::hidden(array('post_id'),$post_id). |
---|
650 | form::hidden(array('link_type'),$link_type). |
---|
651 | '</p>'. |
---|
652 | '</form>'; |
---|
653 | |
---|
654 | if (count($items) == 0) |
---|
655 | { |
---|
656 | echo |
---|
657 | '<p>'.__('No file.').'</p>'. |
---|
658 | sprintf($fmt_form_media,'',' hide'); // need for jsUpload to append new media |
---|
659 | } |
---|
660 | else |
---|
661 | { |
---|
662 | $pager = new dcPager($page,count($items),$nb_per_page,10); |
---|
663 | |
---|
664 | echo |
---|
665 | '<form action="'.$core->adminurl->get("admin.media").'" method="get" id="filters-form">'. |
---|
666 | '<span class="media-file-mode">'. |
---|
667 | '<a href="'.$core->adminurl->get("admin.media",array_merge($page_url_params,array('file_mode' => 'grid'))).'" title="'.__('Grid display mode').'">'. |
---|
668 | '<img src="images/grid-'.($file_mode == 'grid' ? 'on' : 'off').'.png" alt="'.__('Grid display mode').'" />'. |
---|
669 | '</a>'. |
---|
670 | '<a href="'.$core->adminurl->get("admin.media",array_merge($page_url_params,array('file_mode' => 'list'))).'" title="'.__('List display mode').'">'. |
---|
671 | '<img src="images/list-'.($file_mode == 'list' ? 'on' : 'off').'.png" alt="'.__('List display mode').'" />'. |
---|
672 | '</a>'. |
---|
673 | '</span>'. |
---|
674 | '<p class="three-boxes"><label for="file_sort" class="classic">'.__('Sort files:').'</label> '. |
---|
675 | form::combo('file_sort',$sort_combo,$file_sort).'</p>'. |
---|
676 | '<p class="three-boxes"><label for="nb_per_page" class="classic">'.__('Number of elements displayed per page:').'</label> '. |
---|
677 | form::field('nb_per_page',5,3,(integer) $nb_per_page).' '. |
---|
678 | '<input type="submit" value="'.__('OK').'" />'. |
---|
679 | form::hidden(array('popup'),$popup). |
---|
680 | form::hidden(array('select'),$select). |
---|
681 | form::hidden(array('plugin_id'),$plugin_id). |
---|
682 | form::hidden(array('post_id'),$post_id). |
---|
683 | form::hidden(array('link_type'),$link_type). |
---|
684 | form::hidden(array('q'),$q). |
---|
685 | '</p>'. |
---|
686 | '</form>'. |
---|
687 | $pager->getLinks(); |
---|
688 | |
---|
689 | if ($file_mode == 'list') { |
---|
690 | $table = |
---|
691 | '<div class="table-outer">'. |
---|
692 | '<table>'. |
---|
693 | '<caption class="hidden">'.__('Media list').'</caption>'. |
---|
694 | '<tr>'. |
---|
695 | '<th colspan="2" class="first">'.__('Name').'</th>'. |
---|
696 | '<th scope="col">'.__('Date').'</th>'. |
---|
697 | '<th scope="col">'.__('Size').'</th>'. |
---|
698 | '</tr>'; |
---|
699 | |
---|
700 | $dlist = ''; |
---|
701 | $flist = ''; |
---|
702 | for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++,$j++) |
---|
703 | { |
---|
704 | if ($items[$i]->d) { |
---|
705 | $dlist .= mediaItemLine($items[$i],$j,$query,true); |
---|
706 | } else { |
---|
707 | $flist .= mediaItemLine($items[$i],$j,$query,true); |
---|
708 | } |
---|
709 | } |
---|
710 | $table .= $dlist.$flist; |
---|
711 | |
---|
712 | $table .= |
---|
713 | '</table></div>'; |
---|
714 | echo sprintf($fmt_form_media,$table,''); |
---|
715 | } else { |
---|
716 | $dgroup = ''; |
---|
717 | $fgroup = ''; |
---|
718 | for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++,$j++) |
---|
719 | { |
---|
720 | if ($items[$i]->d) { |
---|
721 | $dgroup .= mediaItemLine($items[$i],$j,$query); |
---|
722 | } else { |
---|
723 | $fgroup .= mediaItemLine($items[$i],$j,$query); |
---|
724 | } |
---|
725 | } |
---|
726 | echo |
---|
727 | ($dgroup != '' ? '<div class="folders-group">'.$dgroup.'</div>' : ''). |
---|
728 | sprintf($fmt_form_media,$fgroup,''); |
---|
729 | } |
---|
730 | |
---|
731 | echo $pager->getLinks(); |
---|
732 | } |
---|
733 | if (!isset($pager)) { |
---|
734 | echo |
---|
735 | '<p class="clear"></p>'; |
---|
736 | } |
---|
737 | echo |
---|
738 | '</div>'; |
---|
739 | |
---|
740 | $core_media_archivable = $core->auth->check('media_admin',$core->blog->id) && |
---|
741 | !(count($items) == 0 || (count($items) == 1 && $items[0]->parent)); |
---|
742 | |
---|
743 | if ((!$query) && ($core_media_writable || $core_media_archivable)) { |
---|
744 | echo |
---|
745 | '<div class="vertical-separator">'. |
---|
746 | '<h3 class="out-of-screen-if-js">'.sprintf(__('In %s:'),($d == '' ? '“'.__('Media manager').'”' : '“'.$d.'”')).'</h3>'; |
---|
747 | } |
---|
748 | |
---|
749 | if ((!$query) && ($core_media_writable || $core_media_archivable)) { |
---|
750 | echo |
---|
751 | '<div class="two-boxes odd">'; |
---|
752 | |
---|
753 | # Create directory |
---|
754 | if ($core_media_writable) |
---|
755 | { |
---|
756 | echo |
---|
757 | '<form action="'.$core->adminurl->getBase('admin.media').'" method="post" class="fieldset">'. |
---|
758 | '<div id="new-dir-f">'. |
---|
759 | '<h4 class="pretty-title">'.__('Create new directory').'</h4>'. |
---|
760 | $core->formNonce(). |
---|
761 | '<p><label for="newdir">'.__('Directory Name:').'</label>'. |
---|
762 | form::field(array('newdir','newdir'),35,255).'</p>'. |
---|
763 | '<p><input type="submit" value="'.__('Create').'" />'. |
---|
764 | $core->adminurl->getHiddenFormFields('admin.media',$page_url_params). |
---|
765 | '</p>'. |
---|
766 | '</div>'. |
---|
767 | '</form>'; |
---|
768 | } |
---|
769 | |
---|
770 | # Get zip directory |
---|
771 | if ($core_media_archivable && !$popup) |
---|
772 | { |
---|
773 | echo |
---|
774 | '<div class="fieldset">'. |
---|
775 | '<h4 class="pretty-title">'.sprintf(__('Backup content of %s'),($d == '' ? '“'.__('Media manager').'”' : '“'.$d.'”')).'</h4>'. |
---|
776 | '<p><a class="button submit" href="'.$core->adminurl->get('admin.media', |
---|
777 | array_merge($page_url_params,array('zipdl' => 1))).'">'.__('Download zip file').'</a></p>'. |
---|
778 | '</div>'; |
---|
779 | } |
---|
780 | |
---|
781 | echo |
---|
782 | '</div>'; |
---|
783 | } |
---|
784 | |
---|
785 | if (!$query && $core_media_writable) |
---|
786 | { |
---|
787 | echo |
---|
788 | '<div class="two-boxes fieldset even">'; |
---|
789 | if ($user_ui_enhanceduploader) { |
---|
790 | echo |
---|
791 | '<div class="enhanced_uploader">'; |
---|
792 | } else { |
---|
793 | echo |
---|
794 | '<div>'; |
---|
795 | } |
---|
796 | |
---|
797 | echo |
---|
798 | '<h4>'.__('Add files').'</h4>'. |
---|
799 | '<p>'.__('Please take care to publish media that you own and that are not protected by copyright.').'</p>'. |
---|
800 | '<form id="fileupload" action="'.html::escapeURL($core->adminurl->get('admin.media',$page_url_params)).'" method="post" enctype="multipart/form-data" aria-disabled="false">'. |
---|
801 | '<p>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). |
---|
802 | $core->formNonce().'</p>'. |
---|
803 | '<div class="fileupload-ctrl"><p class="queue-message"></p><ul class="files"></ul></div>'; |
---|
804 | |
---|
805 | echo |
---|
806 | '<div class="fileupload-buttonbar clear">'; |
---|
807 | |
---|
808 | echo |
---|
809 | '<p><label for="upfile">'.'<span class="add-label one-file">'.__('Choose file').'</span>'.'</label>'. |
---|
810 | '<button class="button choose_files">'.__('Choose files').'</button>'. |
---|
811 | '<input type="file" id="upfile" name="upfile[]"'.($user_ui_enhanceduploader?' multiple="mutiple"':'').' data-url="'.html::escapeURL($core->adminurl->get('admin.media',$page_url_params)).'" /></p>'; |
---|
812 | |
---|
813 | echo |
---|
814 | '<p class="max-sizer form-note"> '.__('Maximum file size allowed:').' '.files::size(DC_MAX_UPLOAD_SIZE).'</p>'; |
---|
815 | |
---|
816 | echo |
---|
817 | '<p class="one-file"><label for="upfiletitle">'.__('Title:').'</label>'.form::field(array('upfiletitle','upfiletitle'),35,255).'</p>'. |
---|
818 | '<p class="one-file"><label for="upfilepriv" class="classic">'.__('Private').'</label> '. |
---|
819 | form::checkbox(array('upfilepriv','upfilepriv'),1).'</p>'; |
---|
820 | |
---|
821 | if (!$user_ui_enhanceduploader) { |
---|
822 | echo |
---|
823 | '<p class="one-file form-help info">'.__('To send several files at the same time, you can activate the enhanced uploader in'). |
---|
824 | ' <a href="'.$core->adminurl->get("admin.user.preferences",array('tab' => 'user-options')).'">'.__('My preferences').'</a></p>'; |
---|
825 | } |
---|
826 | |
---|
827 | echo |
---|
828 | '<p class="clear"><button class="button clean">'.__('Refresh').'</button>'. |
---|
829 | '<input class="button cancel one-file" type="reset" value="'.__('Clear all').'"/>'. |
---|
830 | '<input class="button start" type="submit" value="'.__('Upload').'"/></p>'. |
---|
831 | '</div>'; |
---|
832 | |
---|
833 | echo |
---|
834 | '<p style="clear:both;">'. |
---|
835 | form::hidden(array('d'),$d). |
---|
836 | form::hidden(array('q'),$q). |
---|
837 | form::hidden(array('popup'),$popup). |
---|
838 | form::hidden(array('select'),$select). |
---|
839 | form::hidden(array('plugin_id'),$plugin_id). |
---|
840 | form::hidden(array('post_id'),$post_id). |
---|
841 | form::hidden(array('link_type'),$link_type). |
---|
842 | '</p>'. |
---|
843 | '</form>'. |
---|
844 | '</div>'. |
---|
845 | '</div>'; |
---|
846 | } |
---|
847 | |
---|
848 | # Empty remove form (for javascript actions) |
---|
849 | echo |
---|
850 | '<form id="media-remove-hide" action="'.html::escapeURL($core->adminurl->get('admin.media',$page_url_params)).'" method="post" class="hidden">'. |
---|
851 | '<div>'. |
---|
852 | form::hidden('rmyes',1). |
---|
853 | form::hidden('d',html::escapeHTML($d)). |
---|
854 | form::hidden(array('q'),$q). |
---|
855 | form::hidden(array('popup'),$popup). |
---|
856 | form::hidden(array('select'),$select). |
---|
857 | form::hidden(array('plugin_id'),$plugin_id). |
---|
858 | form::hidden(array('post_id'),$post_id). |
---|
859 | form::hidden(array('link_type'),$link_type). |
---|
860 | form::hidden('remove',''). |
---|
861 | $core->formNonce(). |
---|
862 | '</div>'. |
---|
863 | '</form>'; |
---|
864 | |
---|
865 | if ((!$query) && ($core_media_writable || $core_media_archivable)) { |
---|
866 | echo |
---|
867 | '</div>'; |
---|
868 | } |
---|
869 | |
---|
870 | if (!$popup) { |
---|
871 | echo '<div class="info"><p>'.sprintf(__('Current settings for medias and images are defined in %s'), |
---|
872 | '<a href="'.$core->adminurl->get("admin.blog.pref").'#medias-settings">'.__('Blog parameters').'</a>').'</p></div>'; |
---|
873 | } |
---|
874 | |
---|
875 | call_user_func($close_f); |
---|
876 | |
---|
877 | /* ----------------------------------------------------- */ |
---|
878 | function mediaItemLine($f,$i,$query,$table=false) |
---|
879 | { |
---|
880 | global $core, $page_url, $popup, $select, $post_id, $plugin_id, $page_url_params, $link_type; |
---|
881 | |
---|
882 | $fname = $f->basename; |
---|
883 | $file = $query ? $f->relname : $f->basename; |
---|
884 | |
---|
885 | $class = $table ? '' : 'media-item media-col-'.($i%2); |
---|
886 | |
---|
887 | if ($f->d) { |
---|
888 | // Folder |
---|
889 | $link = $core->adminurl->get('admin.media',array_merge($page_url_params,array('d' => html::sanitizeURL($f->relname) ))); |
---|
890 | if ($f->parent) { |
---|
891 | $fname = '..'; |
---|
892 | $class .= ' media-folder-up'; |
---|
893 | } else { |
---|
894 | $class .= ' media-folder'; |
---|
895 | } |
---|
896 | } else { |
---|
897 | // Item |
---|
898 | $params = new ArrayObject( |
---|
899 | array( |
---|
900 | 'id' => $f->media_id, |
---|
901 | 'plugin_id' => $plugin_id, |
---|
902 | 'popup' => $popup, |
---|
903 | 'select' => $select, |
---|
904 | 'post_id' => $post_id, |
---|
905 | 'link_type' => $link_type |
---|
906 | ) |
---|
907 | ); |
---|
908 | $core->callBehavior('adminMediaURLParams',$params); |
---|
909 | $params = (array) $params; |
---|
910 | $link = $core->adminurl->get( |
---|
911 | 'admin.media.item', $params |
---|
912 | ); |
---|
913 | } |
---|
914 | |
---|
915 | $maxchars = 36; |
---|
916 | if (strlen($fname) > $maxchars) { |
---|
917 | $fname = substr($fname, 0, $maxchars-4).'...'.($f->d ? '' : files::getExtension($fname)); |
---|
918 | } |
---|
919 | |
---|
920 | $act = ''; |
---|
921 | if (!$f->d) { |
---|
922 | if ($select > 0) { |
---|
923 | if ($select == 1) { |
---|
924 | // Single media selection button |
---|
925 | $act .= '<a href="'.$link.'"><img src="images/plus.png" alt="'.__('Select this file').'" '. |
---|
926 | 'title="'.__('Select this file').'" /></a> '; |
---|
927 | } else { |
---|
928 | // Multiple media selection checkbox |
---|
929 | $act .= form::checkbox(array('medias[]', 'media_'.rawurlencode($file)),$file); |
---|
930 | } |
---|
931 | } else { |
---|
932 | // Item |
---|
933 | if ($post_id) { |
---|
934 | // Media attachment button |
---|
935 | $act .= |
---|
936 | '<a class="attach-media" title="'.__('Attach this file to entry').'" href="'. |
---|
937 | $core->adminurl->get("admin.post.media", |
---|
938 | array('media_id' => $f->media_id, 'post_id' => $post_id,'attach' => 1,'link_type' => $link_type)). |
---|
939 | '">'. |
---|
940 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'"/>'. |
---|
941 | '</a>'; |
---|
942 | } |
---|
943 | if ($popup) { |
---|
944 | // Media insertion button |
---|
945 | $act .= '<a href="'.$link.'"><img src="images/plus.png" alt="'.__('Insert this file into entry').'" '. |
---|
946 | 'title="'.__('Insert this file into entry').'" /></a> '; |
---|
947 | } |
---|
948 | } |
---|
949 | } |
---|
950 | if ($f->del) { |
---|
951 | // Deletion button or checkbox |
---|
952 | if (!$popup && !$f->d) { |
---|
953 | if ($select < 2) { |
---|
954 | // Already set for multiple media selection |
---|
955 | $act .= form::checkbox(array('medias[]', 'media_'.rawurlencode($file)),$file); |
---|
956 | } |
---|
957 | } else { |
---|
958 | $act .= '<a class="media-remove" '. |
---|
959 | 'href="'.html::escapeURL($page_url). |
---|
960 | '&plugin_id='.$plugin_id. |
---|
961 | '&d='.rawurlencode($GLOBALS['d']). |
---|
962 | '&q='.rawurlencode($GLOBALS['q']). |
---|
963 | '&remove='.rawurlencode($file).'">'. |
---|
964 | '<img src="images/trash.png" alt="'.__('Delete').'" title="'.__('delete').'" /></a>'; |
---|
965 | } |
---|
966 | } |
---|
967 | |
---|
968 | // Render markup |
---|
969 | if (!$table) { |
---|
970 | $res = |
---|
971 | '<div class="'.$class.'"><p><a class="media-icon media-link" href="'.rawurldecode($link).'">'. |
---|
972 | '<img src="'.$f->media_icon.'" alt="" />'.($query ? $file : $fname).'</a></p>'; |
---|
973 | |
---|
974 | $lst = ''; |
---|
975 | if (!$f->d) { |
---|
976 | $lst .= |
---|
977 | '<li>'.$f->media_title.'</li>'. |
---|
978 | '<li>'. |
---|
979 | $f->media_dtstr.' - '. |
---|
980 | files::size($f->size).' - '. |
---|
981 | '<a href="'.$f->file_url.'">'.__('open').'</a>'. |
---|
982 | '</li>'; |
---|
983 | } |
---|
984 | $lst .= ($act != '' ? '<li class="media-action"> '.$act.'</li>' : ''); |
---|
985 | |
---|
986 | // Show player if relevant |
---|
987 | $file_type = explode('/',$f->type); |
---|
988 | if ($file_type[0] == 'audio') |
---|
989 | { |
---|
990 | $lst .= '<li>'.dcMedia::audioPlayer($f->type,$f->file_url,$core->adminurl->get("admin.home",array('pf' => 'player_mp3.swf')),null,$core->blog->settings->system->media_flash_fallback,false).'</li>'; |
---|
991 | } |
---|
992 | |
---|
993 | $res .= ($lst != '' ? '<ul>'.$lst.'</ul>' : ''); |
---|
994 | $res .= '</div>'; |
---|
995 | } else { |
---|
996 | $res = '<tr class="'.$class.'">'; |
---|
997 | $res .= '<td class="media-action">'.$act.'</td>'; |
---|
998 | $res .= '<td class="maximal" scope="row"><a class="media-flag media-link" href="'.rawurldecode($link).'">'. |
---|
999 | '<img src="'.$f->media_icon.'" alt="" />'.($query ? $file : $fname).'</a>'. |
---|
1000 | '<br />'.($f->d ? '' : $f->media_title).'</td>'; |
---|
1001 | $res .= '<td class="nowrap count">'.($f->d ? '' : $f->media_dtstr).'</td>'; |
---|
1002 | $res .= '<td class="nowrap count">'.($f->d ? '' : files::size($f->size).' - '.'<a href="'.$f->file_url.'">'.__('open').'</a>').'</td>'; |
---|
1003 | $res .= '</tr>'; |
---|
1004 | } |
---|
1005 | |
---|
1006 | return $res; |
---|
1007 | } |
---|