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