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