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