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