[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 | |
---|
[1912] | 33 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
[2021] | 34 | $nb_per_page = ((integer) $core->auth->user_prefs->interface->media_by_page ? (integer) $core->auth->user_prefs->interface->media_by_page : 30); |
---|
[0] | 35 | |
---|
| 36 | # We are on home not comming from media manager |
---|
| 37 | if ($d === null && isset($_SESSION['media_manager_dir'])) { |
---|
| 38 | # We get session information |
---|
| 39 | $d = $_SESSION['media_manager_dir']; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | if (!isset($_GET['page']) && isset($_SESSION['media_manager_page'])) { |
---|
| 43 | $page = $_SESSION['media_manager_page']; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | # We set session information about directory and page |
---|
| 47 | if ($d) { |
---|
| 48 | $_SESSION['media_manager_dir'] = $d; |
---|
| 49 | } else { |
---|
| 50 | unset($_SESSION['media_manager_dir']); |
---|
| 51 | } |
---|
| 52 | if ($page != 1) { |
---|
| 53 | $_SESSION['media_manager_page'] = $page; |
---|
| 54 | } else { |
---|
| 55 | unset($_SESSION['media_manager_page']); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | # Sort combo |
---|
| 59 | $sort_combo = array( |
---|
| 60 | __('By names, in ascending order') => 'name-asc', |
---|
| 61 | __('By names, in descending order') => 'name-desc', |
---|
| 62 | __('By dates, in ascending order') => 'date-asc', |
---|
| 63 | __('By dates, in descending order') => 'date-desc' |
---|
[1161] | 64 | ); |
---|
[0] | 65 | |
---|
| 66 | if (!empty($_GET['file_sort']) && in_array($_GET['file_sort'],$sort_combo)) { |
---|
| 67 | $_SESSION['media_file_sort'] = $_GET['file_sort']; |
---|
| 68 | } |
---|
| 69 | $file_sort = !empty($_SESSION['media_file_sort']) ? $_SESSION['media_file_sort'] : null; |
---|
[2090] | 70 | $nb_per_page = !empty($_SESSION['nb_per_page']) ? (integer)$_SESSION['nb_per_page'] : $nb_per_page; |
---|
| 71 | if (!empty($_GET['nb_per_page']) && (integer)$_GET['nb_per_page'] > 0) { |
---|
| 72 | $nb_per_page = $_SESSION['nb_per_page'] = (integer)$_GET['nb_per_page']; |
---|
| 73 | } |
---|
[0] | 74 | |
---|
[2884] | 75 | $popup = (integer) !empty($_REQUEST['popup']); |
---|
[0] | 76 | |
---|
[2852] | 77 | $page_url_params = new ArrayObject(array('popup' => $popup,'post_id' => $post_id)); |
---|
| 78 | if ($d) { |
---|
[2873] | 79 | $page_url_params['d'] = $d; |
---|
[2629] | 80 | } |
---|
[2852] | 81 | if ($plugin_id != '') { |
---|
[2873] | 82 | $page_url_params['plugin_id'] = $plugin_id; |
---|
[2852] | 83 | } |
---|
| 84 | |
---|
| 85 | $core->callBehavior('adminMediaURLParams',$page_url_params); |
---|
| 86 | $page_url_params = (array) $page_url_params; |
---|
[2664] | 87 | |
---|
[0] | 88 | if ($popup) { |
---|
| 89 | $open_f = array('dcPage','openPopup'); |
---|
| 90 | $close_f = array('dcPage','closePopup'); |
---|
| 91 | } else { |
---|
| 92 | $open_f = array('dcPage','open'); |
---|
| 93 | $close_f = create_function('',"dcPage::helpBlock('core_media'); dcPage::close();"); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | $core_media_writable = false; |
---|
| 97 | try { |
---|
| 98 | $core->media = new dcMedia($core); |
---|
| 99 | if ($file_sort) { |
---|
| 100 | $core->media->setFileSort($file_sort); |
---|
| 101 | } |
---|
| 102 | $core->media->chdir($d); |
---|
| 103 | $core->media->getDir(); |
---|
| 104 | $core_media_writable = $core->media->writable(); |
---|
| 105 | $dir =& $core->media->dir; |
---|
| 106 | if (!$core_media_writable) { |
---|
[1725] | 107 | // throw new Exception('you do not have sufficient permissions to write to this folder: '); |
---|
[0] | 108 | } |
---|
| 109 | } catch (Exception $e) { |
---|
| 110 | $core->error->add($e->getMessage()); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | # Zip download |
---|
| 114 | if (!empty($_GET['zipdl']) && $core->auth->check('media_admin',$core->blog->id)) |
---|
| 115 | { |
---|
| 116 | try |
---|
| 117 | { |
---|
| 118 | @set_time_limit(300); |
---|
| 119 | $fp = fopen('php://output','wb'); |
---|
| 120 | $zip = new fileZip($fp); |
---|
| 121 | $zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#'); |
---|
| 122 | $zip->addDirectory($core->media->root.'/'.$d,'',true); |
---|
[2512] | 123 | |
---|
[0] | 124 | header('Content-Disposition: attachment;filename='.($d ? $d : 'media').'.zip'); |
---|
| 125 | header('Content-Type: application/x-zip'); |
---|
| 126 | $zip->write(); |
---|
| 127 | unset($zip); |
---|
| 128 | exit; |
---|
| 129 | } |
---|
| 130 | catch (Exception $e) |
---|
| 131 | { |
---|
| 132 | $core->error->add($e->getMessage()); |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | # New directory |
---|
| 137 | if ($dir && !empty($_POST['newdir'])) |
---|
| 138 | { |
---|
| 139 | try { |
---|
| 140 | $core->media->makeDir($_POST['newdir']); |
---|
[2256] | 141 | dcPage::addSuccessNotice(sprintf( |
---|
| 142 | __('Directory "%s" has been successfully created.'), |
---|
| 143 | html::escapeHTML($_POST['newdir'])) |
---|
| 144 | ); |
---|
[2852] | 145 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
[0] | 146 | } catch (Exception $e) { |
---|
| 147 | $core->error->add($e->getMessage()); |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | # Adding a file |
---|
[1159] | 152 | if ($dir && !empty($_FILES['upfile'])) { |
---|
[2751] | 153 | // only one file per request : @see option singleFileUploads in admin/js/jsUpload/jquery.fileupload |
---|
[1161] | 154 | $upfile = array('name' => $_FILES['upfile']['name'][0], |
---|
| 155 | 'type' => $_FILES['upfile']['type'][0], |
---|
| 156 | 'tmp_name' => $_FILES['upfile']['tmp_name'][0], |
---|
| 157 | 'error' => $_FILES['upfile']['error'][0], |
---|
| 158 | 'size' => $_FILES['upfile']['size'][0] |
---|
| 159 | ); |
---|
[1144] | 160 | |
---|
[1161] | 161 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
---|
| 162 | header('Content-type: application/json'); |
---|
| 163 | $message = array(); |
---|
[1144] | 164 | |
---|
[1161] | 165 | try { |
---|
| 166 | files::uploadStatus($upfile); |
---|
| 167 | $new_file_id = $core->media->uploadFile($upfile['tmp_name'], $upfile['name']); |
---|
[1144] | 168 | |
---|
[2751] | 169 | $message['files'][] = array( |
---|
| 170 | 'name' => $upfile['name'], |
---|
[1161] | 171 | 'size' => $upfile['size'], |
---|
[2764] | 172 | 'html' => mediaItemLine($core->media->getFile($new_file_id), 1) |
---|
[2751] | 173 | ); |
---|
[1161] | 174 | } catch (Exception $e) { |
---|
| 175 | $message['files'][] = array('name' => $upfile['name'], |
---|
[1162] | 176 | 'size' => $upfile['size'], |
---|
[1161] | 177 | 'error' => $e->getMessage() |
---|
| 178 | ); |
---|
| 179 | } |
---|
| 180 | echo json_encode($message); |
---|
| 181 | exit(); |
---|
| 182 | } else { |
---|
| 183 | try { |
---|
| 184 | files::uploadStatus($upfile); |
---|
[1159] | 185 | |
---|
[1161] | 186 | $f_title = (isset($_POST['upfiletitle']) ? $_POST['upfiletitle'] : ''); |
---|
| 187 | $f_private = (isset($_POST['upfilepriv']) ? $_POST['upfilepriv'] : false); |
---|
[1159] | 188 | |
---|
[1161] | 189 | $core->media->uploadFile($upfile['tmp_name'], $upfile['name'], $f_title, $f_private); |
---|
[2256] | 190 | |
---|
| 191 | dcPage::addSuccessNotice(__('Files have been successfully uploaded.')); |
---|
[2852] | 192 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
[1161] | 193 | } catch (Exception $e) { |
---|
| 194 | $core->error->add($e->getMessage()); |
---|
| 195 | } |
---|
| 196 | } |
---|
[0] | 197 | } |
---|
| 198 | |
---|
[2202] | 199 | # Removing items |
---|
| 200 | if ($dir && !empty($_POST['medias']) && !empty($_POST['delete_medias'])) { |
---|
| 201 | try { |
---|
| 202 | foreach ($_POST['medias'] as $media) { |
---|
| 203 | $core->media->removeItem(rawurldecode($media)); |
---|
| 204 | } |
---|
| 205 | dcPage::addSuccessNotice( |
---|
| 206 | sprintf(__('Successfully delete one media.', |
---|
| 207 | 'Successfully delete %d medias.', |
---|
| 208 | count($_POST['medias']) |
---|
| 209 | ), |
---|
| 210 | count($_POST['medias']) |
---|
| 211 | ) |
---|
| 212 | ); |
---|
[2852] | 213 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
[2202] | 214 | } catch (Exception $e) { |
---|
| 215 | $core->error->add($e->getMessage()); |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | # Removing item from popup only |
---|
[0] | 220 | if ($dir && !empty($_POST['rmyes']) && !empty($_POST['remove'])) |
---|
| 221 | { |
---|
| 222 | $_POST['remove'] = rawurldecode($_POST['remove']); |
---|
[2512] | 223 | |
---|
[0] | 224 | try { |
---|
[2512] | 225 | if (is_dir(path::real($core->media->getPwd().'/'.path::clean($_POST['remove'])))) { |
---|
| 226 | $msg = __('Directory has been successfully removed.'); |
---|
| 227 | } else { |
---|
| 228 | $msg = __('File has been successfully removed.'); |
---|
| 229 | } |
---|
[0] | 230 | $core->media->removeItem($_POST['remove']); |
---|
[2512] | 231 | dcPage::addSuccessNotice($msg); |
---|
[2852] | 232 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
[0] | 233 | } catch (Exception $e) { |
---|
| 234 | $core->error->add($e->getMessage()); |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | # Rebuild directory |
---|
| 239 | if ($dir && $core->auth->isSuperAdmin() && !empty($_POST['rebuild'])) |
---|
| 240 | { |
---|
| 241 | try { |
---|
| 242 | $core->media->rebuild($d); |
---|
[2256] | 243 | |
---|
| 244 | dcPage::success(sprintf( |
---|
| 245 | __('Directory "%s" has been successfully rebuilt.'), |
---|
| 246 | html::escapeHTML($d)) |
---|
| 247 | ); |
---|
[2852] | 248 | $core->adminurl->redirect('admin.media',$page_url_params); |
---|
[0] | 249 | } catch (Exception $e) { |
---|
| 250 | $core->error->add($e->getMessage()); |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | # DISPLAY confirm page for rmdir & rmfile |
---|
[947] | 255 | if ($dir && !empty($_GET['remove']) && empty($_GET['noconfirm'])) |
---|
[0] | 256 | { |
---|
[1358] | 257 | call_user_func($open_f,__('Media manager'),'', |
---|
| 258 | dcPage::breadcrumb( |
---|
| 259 | array( |
---|
| 260 | html::escapeHTML($core->blog->name) => '', |
---|
| 261 | __('Media manager') => '', |
---|
[2166] | 262 | __('confirm removal') => '' |
---|
| 263 | ), |
---|
| 264 | array('home_link' => !$popup) |
---|
| 265 | ) |
---|
[1358] | 266 | ); |
---|
[2512] | 267 | |
---|
[0] | 268 | echo |
---|
[2852] | 269 | '<form action="'.html::escapeURL($core->adminurl->get('admin.media')).'" method="post">'. |
---|
[0] | 270 | '<p>'.sprintf(__('Are you sure you want to remove %s?'), |
---|
[1161] | 271 | html::escapeHTML($_GET['remove'])).'</p>'. |
---|
[557] | 272 | '<p><input type="submit" value="'.__('Cancel').'" /> '. |
---|
| 273 | ' <input type="submit" name="rmyes" value="'.__('Yes').'" />'. |
---|
[0] | 274 | form::hidden('d',$d). |
---|
[2852] | 275 | $core->adminurl->getHiddenFormFields('admin.media',$page_url_params). |
---|
[0] | 276 | $core->formNonce(). |
---|
| 277 | form::hidden('remove',html::escapeHTML($_GET['remove'])).'</p>'. |
---|
| 278 | '</form>'; |
---|
[2512] | 279 | |
---|
[0] | 280 | call_user_func($close_f); |
---|
| 281 | exit; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /* DISPLAY Main page |
---|
| 285 | -------------------------------------------------------- */ |
---|
[240] | 286 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
| 287 | $user_ui_enhanceduploader = $core->auth->user_prefs->interface->enhanceduploader; |
---|
| 288 | |
---|
[1358] | 289 | if (!isset($core->media)) { |
---|
| 290 | $breadcrumb = dcPage::breadcrumb( |
---|
| 291 | array( |
---|
| 292 | html::escapeHTML($core->blog->name) => '', |
---|
[2166] | 293 | __('Media manager') => '' |
---|
| 294 | ), |
---|
| 295 | array('home_link' => !$popup) |
---|
| 296 | ); |
---|
[1358] | 297 | } else { |
---|
[2852] | 298 | $temp_params = $page_url_params; |
---|
| 299 | $temp_params['d']='%s'; |
---|
[2858] | 300 | $bc_template = $core->adminurl->get('admin.media',$temp_params,'&',true); |
---|
[2852] | 301 | $breadcrumb_media = $core->media->breadCrumb($bc_template,'<span class="page-title">%s</span>'); |
---|
[1358] | 302 | if ($breadcrumb_media == '') { |
---|
| 303 | $breadcrumb = dcPage::breadcrumb( |
---|
| 304 | array( |
---|
| 305 | html::escapeHTML($core->blog->name) => '', |
---|
[2166] | 306 | __('Media manager') => '' |
---|
| 307 | ), |
---|
| 308 | array('home_link' => !$popup) |
---|
| 309 | ); |
---|
[1358] | 310 | } else { |
---|
[2852] | 311 | $home_params = $page_url_params; |
---|
| 312 | $home_params['d']=''; |
---|
| 313 | |
---|
[1358] | 314 | $breadcrumb = dcPage::breadcrumb( |
---|
| 315 | array( |
---|
| 316 | html::escapeHTML($core->blog->name) => '', |
---|
[2852] | 317 | __('Media manager') => $core->adminurl->get('admin.media',$home_params), |
---|
[1358] | 318 | $breadcrumb_media => '' |
---|
[2166] | 319 | ), |
---|
| 320 | array( |
---|
| 321 | 'home_link' => !$popup, |
---|
[2167] | 322 | 'hl' => false |
---|
[2166] | 323 | ) |
---|
| 324 | ); |
---|
[1358] | 325 | } |
---|
| 326 | } |
---|
| 327 | |
---|
[0] | 328 | call_user_func($open_f,__('Media manager'), |
---|
| 329 | dcPage::jsLoad('js/_media.js'). |
---|
[1358] | 330 | ($core_media_writable ? dcPage::jsUpload(array('d='.$d)) : ''), |
---|
| 331 | $breadcrumb |
---|
[240] | 332 | ); |
---|
[0] | 333 | |
---|
[2529] | 334 | if ($popup) { |
---|
| 335 | // Display notices |
---|
| 336 | echo dcPage::notices(); |
---|
| 337 | } |
---|
| 338 | |
---|
[1725] | 339 | if (!$core_media_writable) { |
---|
| 340 | dcPage::warning(__('You do not have sufficient permissions to write to this folder.')); |
---|
| 341 | } |
---|
| 342 | |
---|
[0] | 343 | if (!empty($_GET['mkdok'])) { |
---|
[1553] | 344 | dcPage::success(__('Directory has been successfully created.')); |
---|
[0] | 345 | } |
---|
| 346 | |
---|
| 347 | if (!empty($_GET['upok'])) { |
---|
[1553] | 348 | dcPage::success(__('Files have been successfully uploaded.')); |
---|
[0] | 349 | } |
---|
| 350 | |
---|
| 351 | if (!empty($_GET['rmfok'])) { |
---|
[1553] | 352 | dcPage::success(__('File has been successfully removed.')); |
---|
[0] | 353 | } |
---|
| 354 | |
---|
| 355 | if (!empty($_GET['rmdok'])) { |
---|
[1553] | 356 | dcPage::success(__('Directory has been successfully removed.')); |
---|
[0] | 357 | } |
---|
| 358 | |
---|
| 359 | if (!empty($_GET['rebuildok'])) { |
---|
[1553] | 360 | dcPage::success(__('Directory has been successfully rebuilt.')); |
---|
[0] | 361 | } |
---|
| 362 | |
---|
| 363 | if (!empty($_GET['unzipok'])) { |
---|
[1553] | 364 | dcPage::success(__('Zip file has been successfully extracted.')); |
---|
[0] | 365 | } |
---|
| 366 | |
---|
| 367 | if (!$dir) { |
---|
| 368 | call_user_func($close_f); |
---|
| 369 | exit; |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | if ($post_id) { |
---|
[2430] | 373 | echo '<div class="form-note info"><p>'.sprintf(__('Choose a file to attach to entry %s by clicking on %s.'), |
---|
[1161] | 374 | '<a href="'.$core->getPostAdminURL($post_type,$post_id).'">'.html::escapeHTML($post_title).'</a>', |
---|
[2430] | 375 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />').'</p></div>'; |
---|
[0] | 376 | } |
---|
| 377 | if ($popup) { |
---|
[2006] | 378 | echo '<div class="info"><p>'.sprintf(__('Choose a file to insert into entry by clicking on %s.'), |
---|
| 379 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />').'</p></div>'; |
---|
[0] | 380 | } |
---|
| 381 | |
---|
[2582] | 382 | // Remove hidden directories (unless DC_SHOW_HIDDEN_DIRS is set to true) |
---|
| 383 | if (!defined('DC_SHOW_HIDDEN_DIRS') || (DC_SHOW_HIDDEN_DIRS == false)) { |
---|
| 384 | for ($i = count($dir['dirs']) - 1; $i >= 0; $i--) { |
---|
| 385 | if ($dir['dirs'][$i]->d) { |
---|
| 386 | if (strpos($dir['dirs'][$i]->relname,'.') !== false) { |
---|
| 387 | unset($dir['dirs'][$i]); |
---|
| 388 | } |
---|
| 389 | } |
---|
| 390 | } |
---|
| 391 | } |
---|
[0] | 392 | $items = array_values(array_merge($dir['dirs'],$dir['files'])); |
---|
[2202] | 393 | |
---|
[2720] | 394 | $fmt_form_media = '<form action="'.$core->adminurl->get("admin.media").'" method="post" id="form-medias">'. |
---|
[2202] | 395 | '<div class="files-group">%s</div>'. |
---|
[2751] | 396 | '<p class="hidden">'.$core->formNonce() . form::hidden(array('d'),$d).form::hidden(array('plugin_id'),$plugin_id).'</p>'; |
---|
[2204] | 397 | |
---|
| 398 | if (!$popup) { |
---|
| 399 | $fmt_form_media .= |
---|
[2228] | 400 | '<div class="medias-delete%s">'. |
---|
[2263] | 401 | '<p class="checkboxes-helpers"></p>'. |
---|
| 402 | '<p><input type="submit" class="delete" name="delete_medias" value="'.__('Remove selected medias').'"/></p>'. |
---|
[2204] | 403 | '</div>'; |
---|
| 404 | } |
---|
| 405 | $fmt_form_media .= |
---|
[2202] | 406 | '</form>'; |
---|
| 407 | |
---|
[1160] | 408 | echo '<div class="media-list">'; |
---|
[0] | 409 | if (count($items) == 0) |
---|
| 410 | { |
---|
[2512] | 411 | echo |
---|
[1982] | 412 | '<p>'.__('No file.').'</p>'. |
---|
[2202] | 413 | sprintf($fmt_form_media,'',' hide'); // need for jsUpload to append new media |
---|
[0] | 414 | } |
---|
| 415 | else |
---|
| 416 | { |
---|
[1926] | 417 | $pager = new dcPager($page,count($items),$nb_per_page,10); |
---|
[2512] | 418 | |
---|
[0] | 419 | echo |
---|
[2720] | 420 | '<form action="'.$core->adminurl->get("admin.media").'" method="get" id="filters-form">'. |
---|
[2224] | 421 | '<p class="two-boxes"><label for="file_sort" class="classic">'.__('Sort files:').'</label> '. |
---|
| 422 | form::combo('file_sort',$sort_combo,$file_sort).'</p>'. |
---|
| 423 | '<p class="two-boxes"><label for="nb_per_page" class="classic">'.__('Number of elements displayed per page:').'</label> '. |
---|
[2090] | 424 | form::field('nb_per_page',5,3,(integer) $nb_per_page).' '. |
---|
| 425 | '<input type="submit" value="'.__('OK').'" />'. |
---|
[0] | 426 | form::hidden(array('popup'),$popup). |
---|
[2751] | 427 | form::hidden(array('plugin_id'),$plugin_id). |
---|
[0] | 428 | form::hidden(array('post_id'),$post_id). |
---|
[2090] | 429 | '</p>'. |
---|
[0] | 430 | '</form>'. |
---|
[1926] | 431 | $pager->getLinks(); |
---|
[1855] | 432 | |
---|
| 433 | $dgroup = ''; |
---|
| 434 | $fgroup = ''; |
---|
| 435 | for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++,$j++) |
---|
[0] | 436 | { |
---|
[1855] | 437 | if ($items[$i]->d) { |
---|
[2764] | 438 | $dgroup .= mediaItemLine($items[$i],$j); |
---|
[1855] | 439 | } else { |
---|
[2764] | 440 | $fgroup .= mediaItemLine($items[$i],$j); |
---|
[1855] | 441 | } |
---|
[0] | 442 | } |
---|
[2512] | 443 | |
---|
| 444 | echo |
---|
[2202] | 445 | ($dgroup != '' ? '<div class="folders-group">'.$dgroup.'</div>' : ''). |
---|
| 446 | sprintf($fmt_form_media,$fgroup,''); |
---|
[2512] | 447 | |
---|
[1926] | 448 | echo $pager->getLinks(); |
---|
[0] | 449 | } |
---|
[1162] | 450 | if (!isset($pager)) { |
---|
| 451 | echo |
---|
| 452 | '<p class="clear"></p>'; |
---|
| 453 | } |
---|
[1160] | 454 | echo |
---|
[1161] | 455 | '</div>'; |
---|
[1144] | 456 | |
---|
[2649] | 457 | $core_media_archivable = $core->auth->check('media_admin',$core->blog->id) && |
---|
| 458 | !(count($items) == 0 || (count($items) == 1 && $items[0]->parent)); |
---|
| 459 | |
---|
[1979] | 460 | if ($core_media_writable || $core_media_archivable) { |
---|
| 461 | echo |
---|
| 462 | '<div class="vertical-separator">'. |
---|
[2512] | 463 | '<h3 class="out-of-screen-if-js">'.sprintf(__('In %s:'),($d == '' ? '“'.__('Media manager').'”' : '“'.$d.'”')).'</h3>'; |
---|
[1979] | 464 | } |
---|
| 465 | |
---|
| 466 | if ($core_media_writable || $core_media_archivable) { |
---|
[2512] | 467 | echo |
---|
[1979] | 468 | '<div class="two-boxes odd">'; |
---|
| 469 | |
---|
| 470 | # Create directory |
---|
| 471 | if ($core_media_writable) |
---|
| 472 | { |
---|
| 473 | echo |
---|
[2852] | 474 | '<form action="'.$core->adminurl->getBase('admin.media').'" method="post" class="fieldset">'. |
---|
[1979] | 475 | '<div id="new-dir-f">'. |
---|
| 476 | '<h4 class="pretty-title">'.__('Create new directory').'</h4>'. |
---|
| 477 | $core->formNonce(). |
---|
| 478 | '<p><label for="newdir">'.__('Directory Name:').'</label>'. |
---|
| 479 | form::field(array('newdir','newdir'),35,255).'</p>'. |
---|
| 480 | '<p><input type="submit" value="'.__('Create').'" />'. |
---|
[2852] | 481 | $core->adminurl->getHiddenFormFields('admin.media',$page_url_params). |
---|
| 482 | '</p>'. |
---|
[1979] | 483 | '</div>'. |
---|
| 484 | '</form>'; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | # Get zip directory |
---|
[2263] | 488 | if ($core_media_archivable && !$popup) |
---|
[1979] | 489 | { |
---|
| 490 | echo |
---|
| 491 | '<div class="fieldset">'. |
---|
| 492 | '<h4 class="pretty-title">'.sprintf(__('Backup content of %s'),($d == '' ? '“'.__('Media manager').'”' : '“'.$d.'”')).'</h4>'. |
---|
[2852] | 493 | '<p><a class="button submit" href="'.$core->adminurl->get('admin.media', |
---|
| 494 | array_merge($page_url_params,array('zipdl' => 1))).'">'.__('Download zip file').'</a></p>'. |
---|
[1979] | 495 | '</div>'; |
---|
| 496 | } |
---|
| 497 | |
---|
[2512] | 498 | echo |
---|
[1979] | 499 | '</div>'; |
---|
| 500 | } |
---|
| 501 | |
---|
[0] | 502 | if ($core_media_writable) |
---|
| 503 | { |
---|
[1979] | 504 | echo |
---|
[2512] | 505 | '<div class="two-boxes fieldset even">'; |
---|
[1161] | 506 | if ($user_ui_enhanceduploader) { |
---|
| 507 | echo |
---|
[1681] | 508 | '<div class="enhanced_uploader">'; |
---|
[1161] | 509 | } else { |
---|
| 510 | echo |
---|
[1681] | 511 | '<div>'; |
---|
[1161] | 512 | } |
---|
[1159] | 513 | |
---|
[1161] | 514 | echo |
---|
[1681] | 515 | '<h4>'.__('Add files').'</h4>'. |
---|
[1161] | 516 | '<p>'.__('Please take care to publish media that you own and that are not protected by copyright.').'</p>'. |
---|
[1519] | 517 | '<form id="fileupload" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data" aria-disabled="false">'. |
---|
[1450] | 518 | '<p>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). |
---|
| 519 | $core->formNonce().'</p>'. |
---|
| 520 | '<div class="fileupload-ctrl"><p class="queue-message"></p><ul class="files"></ul></div>'; |
---|
[1159] | 521 | |
---|
[1161] | 522 | echo |
---|
[1519] | 523 | '<div class="fileupload-buttonbar clear">'; |
---|
[1162] | 524 | |
---|
| 525 | echo |
---|
[1450] | 526 | '<p><label for="upfile">'.'<span class="add-label one-file">'.__('Choose file').'</span>'.'</label>'. |
---|
[1852] | 527 | '<button class="button choose_files">'.__('Choose files').'</button>'. |
---|
[1450] | 528 | '<input type="file" id="upfile" name="upfile[]"'.($user_ui_enhanceduploader?' multiple="mutiple"':'').' data-url="'.html::escapeURL($page_url).'" /></p>'; |
---|
[1159] | 529 | |
---|
[1161] | 530 | echo |
---|
[1854] | 531 | '<p class="max-sizer form-note"> '.__('Maximum file size allowed:').' '.files::size(DC_MAX_UPLOAD_SIZE).'</p>'; |
---|
| 532 | |
---|
| 533 | echo |
---|
[1450] | 534 | '<p class="one-file"><label for="upfiletitle">'.__('Title:').'</label>'.form::field(array('upfiletitle','upfiletitle'),35,255).'</p>'. |
---|
[1452] | 535 | '<p class="one-file"><label for="upfilepriv" class="classic">'.__('Private').'</label> '. |
---|
[1450] | 536 | form::checkbox(array('upfilepriv','upfilepriv'),1).'</p>'; |
---|
[1159] | 537 | |
---|
[1161] | 538 | if (!$user_ui_enhanceduploader) { |
---|
| 539 | echo |
---|
| 540 | '<p class="one-file form-help info">'.__('To send several files at the same time, you can activate the enhanced uploader in'). |
---|
[2720] | 541 | ' <a href="'.$core->adminurl->get("admin.user.preferences",array('tab' => 'user-options')).'">'.__('My preferences').'</a></p>'; |
---|
[1161] | 542 | } |
---|
[1159] | 543 | |
---|
[1161] | 544 | echo |
---|
[1526] | 545 | '<p class="clear"><button class="button clean">'.__('Refresh').'</button>'. |
---|
[1183] | 546 | '<input class="button cancel one-file" type="reset" value="'.__('Clear all').'"/>'. |
---|
[1450] | 547 | '<input class="button start" type="submit" value="'.__('Upload').'"/></p>'. |
---|
[1161] | 548 | '</div>'; |
---|
[1159] | 549 | |
---|
[1161] | 550 | echo |
---|
[1526] | 551 | '<p style="clear:both;">'.form::hidden(array('d'),$d).'</p>'. |
---|
[1161] | 552 | '</form>'. |
---|
[1681] | 553 | '</div>'. |
---|
| 554 | '</div>'; |
---|
[1725] | 555 | } |
---|
[1450] | 556 | |
---|
[0] | 557 | # Empty remove form (for javascript actions) |
---|
| 558 | echo |
---|
[1681] | 559 | '<form id="media-remove-hide" action="'.html::escapeURL($page_url).'" method="post" class="hidden">'. |
---|
| 560 | '<div>'. |
---|
[0] | 561 | form::hidden('rmyes',1).form::hidden('d',html::escapeHTML($d)). |
---|
[2764] | 562 | form::hidden(array('plugin_id'),$plugin_id).form::hidden('remove',''). |
---|
[0] | 563 | $core->formNonce(). |
---|
[1681] | 564 | '</div>'. |
---|
| 565 | '</form>'; |
---|
[0] | 566 | |
---|
[1979] | 567 | if ($core_media_writable || $core_media_archivable) { |
---|
[2512] | 568 | echo |
---|
[1979] | 569 | '</div>'; |
---|
| 570 | } |
---|
| 571 | |
---|
[2224] | 572 | if (!$popup) { |
---|
| 573 | echo '<div class="info"><p>'.sprintf(__('Current settings for medias and images are defined in %s'), |
---|
[2720] | 574 | '<a href="'.$core->adminurl->get("admin.blog.pref").'#medias-settings">'.__('Blog parameters').'</a>').'</p></div>'; |
---|
[2224] | 575 | } |
---|
| 576 | |
---|
[0] | 577 | call_user_func($close_f); |
---|
| 578 | |
---|
| 579 | /* ----------------------------------------------------- */ |
---|
[2764] | 580 | function mediaItemLine($f,$i) |
---|
[0] | 581 | { |
---|
[2852] | 582 | global $core, $page_url, $popup, $post_id, $plugin_id,$page_url_params; |
---|
[2512] | 583 | |
---|
[0] | 584 | $fname = $f->basename; |
---|
[2512] | 585 | |
---|
[2858] | 586 | $class = 'media-item media-col-'.($i%2); |
---|
[2512] | 587 | |
---|
[0] | 588 | if ($f->d) { |
---|
[2852] | 589 | |
---|
| 590 | $link = $core->adminurl->get('admin.media',array_merge($page_url_params,array('d' => html::sanitizeURL($f->relname) ))); |
---|
[0] | 591 | if ($f->parent) { |
---|
| 592 | $fname = '..'; |
---|
[1849] | 593 | $class .= ' media-folder-up'; |
---|
| 594 | } else { |
---|
| 595 | $class .= ' media-folder'; |
---|
[0] | 596 | } |
---|
| 597 | } else { |
---|
[2852] | 598 | $params = new ArrayObject( |
---|
[2751] | 599 | array( |
---|
| 600 | 'id' => $f->media_id, |
---|
| 601 | 'plugin_id' => $plugin_id, |
---|
| 602 | 'popup' => $popup, |
---|
| 603 | 'post_id' => $post_id |
---|
| 604 | ) |
---|
| 605 | ); |
---|
[2852] | 606 | $core->callBehavior('adminMediaURLParams',$params); |
---|
| 607 | $params = (array) $params; |
---|
| 608 | $link = $core->adminurl->get( |
---|
| 609 | 'admin.media.item', $params |
---|
| 610 | ); |
---|
[0] | 611 | } |
---|
[2512] | 612 | |
---|
[2097] | 613 | $maxchars = 36; |
---|
| 614 | if (strlen($fname) > $maxchars) { |
---|
[2099] | 615 | $fname = substr($fname, 0, $maxchars-4).'...'.($f->d ? '' : files::getExtension($fname)); |
---|
[2097] | 616 | } |
---|
[0] | 617 | $res = |
---|
[2885] | 618 | '<div class="'.$class.'"><p><a class="media-icon media-link" href="'.rawurldecode($link).'">'. |
---|
[1855] | 619 | '<img src="'.$f->media_icon.'" alt="" />'.$fname.'</a></p>'; |
---|
| 620 | |
---|
| 621 | $lst = ''; |
---|
[2512] | 622 | |
---|
[0] | 623 | if (!$f->d) { |
---|
[1855] | 624 | $lst .= |
---|
[0] | 625 | '<li>'.$f->media_title.'</li>'. |
---|
| 626 | '<li>'. |
---|
| 627 | $f->media_dtstr.' - '. |
---|
| 628 | files::size($f->size).' - '. |
---|
| 629 | '<a href="'.$f->file_url.'">'.__('open').'</a>'. |
---|
| 630 | '</li>'; |
---|
| 631 | } |
---|
[2512] | 632 | |
---|
[1855] | 633 | $act = ''; |
---|
[2512] | 634 | |
---|
[0] | 635 | if ($post_id && !$f->d) { |
---|
[2512] | 636 | $act .= |
---|
[2720] | 637 | '<a class="attach-media" title="'.__('Attach this file to entry').'" href="'. |
---|
| 638 | $core->adminurl->get("admin.post.media", array('media_id' => $f->media_id, 'post_id' => $post_id,'attach' => 1)). |
---|
| 639 | '">'. |
---|
[2320] | 640 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'"/>'. |
---|
| 641 | '</a>'; |
---|
[0] | 642 | } |
---|
[2512] | 643 | |
---|
[0] | 644 | if ($popup && !$f->d) { |
---|
[1855] | 645 | $act .= '<a href="'.$link.'"><img src="images/plus.png" alt="'.__('Insert this file into entry').'" '. |
---|
[0] | 646 | 'title="'.__('Insert this file into entry').'" /></a> '; |
---|
| 647 | } |
---|
[2512] | 648 | |
---|
[0] | 649 | if ($f->del) { |
---|
[2202] | 650 | if (!$popup && !$f->d) { |
---|
| 651 | $act .= form::checkbox(array('medias[]', 'media_'.rawurlencode($f->basename)),rawurlencode($f->basename)); |
---|
| 652 | } else { |
---|
| 653 | $act .= '<a class="media-remove" '. |
---|
[2764] | 654 | 'href="'.html::escapeURL($page_url).'&plugin_id='.$plugin_id.'&d='. |
---|
[2202] | 655 | rawurlencode($GLOBALS['d']).'&remove='.rawurlencode($f->basename).'">'. |
---|
| 656 | '<img src="images/trash.png" alt="'.__('Delete').'" title="'.__('delete').'" /></a>'; |
---|
| 657 | } |
---|
[0] | 658 | } |
---|
[2512] | 659 | |
---|
[1855] | 660 | $lst .= ($act != '' ? '<li class="media-action"> '.$act.'</li>' : ''); |
---|
[2512] | 661 | |
---|
[2767] | 662 | // Show player if relevant |
---|
| 663 | $file_type = explode('/',$f->type); |
---|
| 664 | if ($file_type[0] == 'audio') |
---|
| 665 | { |
---|
| 666 | $lst .= '<li>'.dcMedia::audioPlayer($f->type,$f->file_url,$core->adminurl->get("admin.home",array('pf' => 'player_mp3.swf'))).'</li>'; |
---|
[0] | 667 | } |
---|
[2512] | 668 | |
---|
[1855] | 669 | $res .= ($lst != '' ? '<ul>'.$lst.'</ul>' : ''); |
---|
| 670 | |
---|
| 671 | $res .= '</div>'; |
---|
[2512] | 672 | |
---|
[0] | 673 | return $res; |
---|
| 674 | } |
---|