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