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