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