| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear | 
|---|
| 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) { | 
|---|
| 21 | $post = $core->blog->getPosts(array('post_id'=>$post_id,'post_type'=>'')); | 
|---|
| 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 |  | 
|---|
| 32 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; | 
|---|
| 33 | $nb_per_page = ((integer) $core->auth->user_prefs->interface->media_by_page ? (integer) $core->auth->user_prefs->interface->media_by_page : 30); | 
|---|
| 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' | 
|---|
| 63 | ); | 
|---|
| 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; | 
|---|
| 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 | } | 
|---|
| 73 |  | 
|---|
| 74 | $popup = (integer) !empty($_GET['popup']); | 
|---|
| 75 |  | 
|---|
| 76 | $page_url = 'media.php?popup='.$popup.'&post_id='.$post_id; | 
|---|
| 77 | if (($temp = $core->callBehavior('adminMediaURL',$page_url))!='') { | 
|---|
| 78 | $page_url = $temp; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 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) { | 
|---|
| 100 | //        throw new Exception('you do not have sufficient permissions to write to this folder: '); | 
|---|
| 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); | 
|---|
| 116 |  | 
|---|
| 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']); | 
|---|
| 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)); | 
|---|
| 139 | } catch (Exception $e) { | 
|---|
| 140 | $core->error->add($e->getMessage()); | 
|---|
| 141 | } | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | # Adding a file | 
|---|
| 145 | if ($dir && !empty($_FILES['upfile'])) { | 
|---|
| 146 | // only one file per request : @see option singleFileUploads in admin/js/jsUpload/jquery.fileupload | 
|---|
| 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 | ); | 
|---|
| 153 |  | 
|---|
| 154 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { | 
|---|
| 155 | header('Content-type: application/json'); | 
|---|
| 156 | $message = array(); | 
|---|
| 157 |  | 
|---|
| 158 | try { | 
|---|
| 159 | files::uploadStatus($upfile); | 
|---|
| 160 | $new_file_id = $core->media->uploadFile($upfile['tmp_name'], $upfile['name']); | 
|---|
| 161 |  | 
|---|
| 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'], | 
|---|
| 168 | 'size' => $upfile['size'], | 
|---|
| 169 | 'error' => $e->getMessage() | 
|---|
| 170 | ); | 
|---|
| 171 | } | 
|---|
| 172 | echo json_encode($message); | 
|---|
| 173 | exit(); | 
|---|
| 174 | } else { | 
|---|
| 175 | try { | 
|---|
| 176 | files::uploadStatus($upfile); | 
|---|
| 177 |  | 
|---|
| 178 | $f_title = (isset($_POST['upfiletitle']) ? $_POST['upfiletitle'] : ''); | 
|---|
| 179 | $f_private = (isset($_POST['upfilepriv']) ? $_POST['upfilepriv'] : false); | 
|---|
| 180 |  | 
|---|
| 181 | $core->media->uploadFile($upfile['tmp_name'], $upfile['name'], $f_title, $f_private); | 
|---|
| 182 |  | 
|---|
| 183 | dcPage::addSuccessNotice(__('Files have been successfully uploaded.')); | 
|---|
| 184 | http::redirect($page_url.'&d='.rawurlencode($d)); | 
|---|
| 185 | } catch (Exception $e) { | 
|---|
| 186 | $core->error->add($e->getMessage()); | 
|---|
| 187 | } | 
|---|
| 188 | } | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 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 | 
|---|
| 212 | if ($dir && !empty($_POST['rmyes']) && !empty($_POST['remove'])) | 
|---|
| 213 | { | 
|---|
| 214 | $_POST['remove'] = rawurldecode($_POST['remove']); | 
|---|
| 215 |  | 
|---|
| 216 | try { | 
|---|
| 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 | } | 
|---|
| 222 | $core->media->removeItem($_POST['remove']); | 
|---|
| 223 | dcPage::addSuccessNotice($msg); | 
|---|
| 224 | http::redirect($page_url.'&d='.rawurlencode($d)); | 
|---|
| 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); | 
|---|
| 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)); | 
|---|
| 241 | } catch (Exception $e) { | 
|---|
| 242 | $core->error->add($e->getMessage()); | 
|---|
| 243 | } | 
|---|
| 244 | } | 
|---|
| 245 |  | 
|---|
| 246 | # DISPLAY confirm page for rmdir & rmfile | 
|---|
| 247 | if ($dir && !empty($_GET['remove']) && empty($_GET['noconfirm'])) | 
|---|
| 248 | { | 
|---|
| 249 | call_user_func($open_f,__('Media manager'),'', | 
|---|
| 250 | dcPage::breadcrumb( | 
|---|
| 251 | array( | 
|---|
| 252 | html::escapeHTML($core->blog->name) => '', | 
|---|
| 253 | __('Media manager') => '', | 
|---|
| 254 | __('confirm removal') => '' | 
|---|
| 255 | ), | 
|---|
| 256 | array('home_link' => !$popup) | 
|---|
| 257 | ) | 
|---|
| 258 | ); | 
|---|
| 259 |  | 
|---|
| 260 | echo | 
|---|
| 261 | '<form action="'.html::escapeURL($page_url).'" method="post">'. | 
|---|
| 262 | '<p>'.sprintf(__('Are you sure you want to remove %s?'), | 
|---|
| 263 | html::escapeHTML($_GET['remove'])).'</p>'. | 
|---|
| 264 | '<p><input type="submit" value="'.__('Cancel').'" /> '. | 
|---|
| 265 | '   <input type="submit" name="rmyes" value="'.__('Yes').'" />'. | 
|---|
| 266 | form::hidden('d',$d). | 
|---|
| 267 | $core->formNonce(). | 
|---|
| 268 | form::hidden('remove',html::escapeHTML($_GET['remove'])).'</p>'. | 
|---|
| 269 | '</form>'; | 
|---|
| 270 |  | 
|---|
| 271 | call_user_func($close_f); | 
|---|
| 272 | exit; | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | /* DISPLAY Main page | 
|---|
| 276 | -------------------------------------------------------- */ | 
|---|
| 277 | $core->auth->user_prefs->addWorkspace('interface'); | 
|---|
| 278 | $user_ui_enhanceduploader = $core->auth->user_prefs->interface->enhanceduploader; | 
|---|
| 279 |  | 
|---|
| 280 | if (!isset($core->media)) { | 
|---|
| 281 | $breadcrumb = dcPage::breadcrumb( | 
|---|
| 282 | array( | 
|---|
| 283 | html::escapeHTML($core->blog->name) => '', | 
|---|
| 284 | __('Media manager') => '' | 
|---|
| 285 | ), | 
|---|
| 286 | array('home_link' => !$popup) | 
|---|
| 287 | ); | 
|---|
| 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) => '', | 
|---|
| 294 | __('Media manager') => '' | 
|---|
| 295 | ), | 
|---|
| 296 | array('home_link' => !$popup) | 
|---|
| 297 | ); | 
|---|
| 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 => '' | 
|---|
| 304 | ), | 
|---|
| 305 | array( | 
|---|
| 306 | 'home_link' => !$popup, | 
|---|
| 307 | 'hl' => false | 
|---|
| 308 | ) | 
|---|
| 309 | ); | 
|---|
| 310 | } | 
|---|
| 311 | } | 
|---|
| 312 |  | 
|---|
| 313 | call_user_func($open_f,__('Media manager'), | 
|---|
| 314 | dcPage::jsLoad('js/_media.js'). | 
|---|
| 315 | ($core_media_writable ? dcPage::jsUpload(array('d='.$d)) : ''), | 
|---|
| 316 | $breadcrumb | 
|---|
| 317 | ); | 
|---|
| 318 |  | 
|---|
| 319 | if ($popup) { | 
|---|
| 320 | // Display notices | 
|---|
| 321 | echo dcPage::notices(); | 
|---|
| 322 | } | 
|---|
| 323 |  | 
|---|
| 324 | if (!$core_media_writable) { | 
|---|
| 325 | dcPage::warning(__('You do not have sufficient permissions to write to this folder.')); | 
|---|
| 326 | } | 
|---|
| 327 |  | 
|---|
| 328 | if (!empty($_GET['mkdok'])) { | 
|---|
| 329 | dcPage::success(__('Directory has been successfully created.')); | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 | if (!empty($_GET['upok'])) { | 
|---|
| 333 | dcPage::success(__('Files have been successfully uploaded.')); | 
|---|
| 334 | } | 
|---|
| 335 |  | 
|---|
| 336 | if (!empty($_GET['rmfok'])) { | 
|---|
| 337 | dcPage::success(__('File has been successfully removed.')); | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 | if (!empty($_GET['rmdok'])) { | 
|---|
| 341 | dcPage::success(__('Directory has been successfully removed.')); | 
|---|
| 342 | } | 
|---|
| 343 |  | 
|---|
| 344 | if (!empty($_GET['rebuildok'])) { | 
|---|
| 345 | dcPage::success(__('Directory has been successfully rebuilt.')); | 
|---|
| 346 | } | 
|---|
| 347 |  | 
|---|
| 348 | if (!empty($_GET['unzipok'])) { | 
|---|
| 349 | dcPage::success(__('Zip file has been successfully extracted.')); | 
|---|
| 350 | } | 
|---|
| 351 |  | 
|---|
| 352 | if (!$dir) { | 
|---|
| 353 | call_user_func($close_f); | 
|---|
| 354 | exit; | 
|---|
| 355 | } | 
|---|
| 356 |  | 
|---|
| 357 | if ($post_id) { | 
|---|
| 358 | echo '<div class="form-note info"><p>'.sprintf(__('Choose a file to attach to entry %s by clicking on %s.'), | 
|---|
| 359 | '<a href="'.$core->getPostAdminURL($post_type,$post_id).'">'.html::escapeHTML($post_title).'</a>', | 
|---|
| 360 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />').'</p></div>'; | 
|---|
| 361 | } | 
|---|
| 362 | if ($popup) { | 
|---|
| 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>'; | 
|---|
| 365 | } | 
|---|
| 366 |  | 
|---|
| 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 | } | 
|---|
| 377 | $items = array_values(array_merge($dir['dirs'],$dir['files'])); | 
|---|
| 378 |  | 
|---|
| 379 | $fmt_form_media = '<form action="media.php" method="post" id="form-medias">'. | 
|---|
| 380 | '<div class="files-group">%s</div>'. | 
|---|
| 381 | '<p class="hidden">'.$core->formNonce() . form::hidden(array('d'),$d).'</p>'; | 
|---|
| 382 |  | 
|---|
| 383 | if (!$popup) { | 
|---|
| 384 | $fmt_form_media .= | 
|---|
| 385 | '<div class="medias-delete%s">'. | 
|---|
| 386 | '<p class="checkboxes-helpers"></p>'. | 
|---|
| 387 | '<p><input type="submit" class="delete" name="delete_medias" value="'.__('Remove selected medias').'"/></p>'. | 
|---|
| 388 | '</div>'; | 
|---|
| 389 | } | 
|---|
| 390 | $fmt_form_media .= | 
|---|
| 391 | '</form>'; | 
|---|
| 392 |  | 
|---|
| 393 | echo '<div class="media-list">'; | 
|---|
| 394 | if (count($items) == 0) | 
|---|
| 395 | { | 
|---|
| 396 | echo | 
|---|
| 397 | '<p>'.__('No file.').'</p>'. | 
|---|
| 398 | sprintf($fmt_form_media,'',' hide'); // need for jsUpload to append new media | 
|---|
| 399 | } | 
|---|
| 400 | else | 
|---|
| 401 | { | 
|---|
| 402 | $pager = new dcPager($page,count($items),$nb_per_page,10); | 
|---|
| 403 |  | 
|---|
| 404 | echo | 
|---|
| 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> '. | 
|---|
| 409 | form::field('nb_per_page',5,3,(integer) $nb_per_page).' '. | 
|---|
| 410 | '<input type="submit" value="'.__('OK').'" />'. | 
|---|
| 411 | form::hidden(array('popup'),$popup). | 
|---|
| 412 | form::hidden(array('post_id'),$post_id). | 
|---|
| 413 | '</p>'. | 
|---|
| 414 | '</form>'. | 
|---|
| 415 | $pager->getLinks(); | 
|---|
| 416 |  | 
|---|
| 417 | $dgroup = ''; | 
|---|
| 418 | $fgroup = ''; | 
|---|
| 419 | for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++,$j++) | 
|---|
| 420 | { | 
|---|
| 421 | if ($items[$i]->d) { | 
|---|
| 422 | $dgroup .= mediaItemLine($items[$i],$j); | 
|---|
| 423 | } else { | 
|---|
| 424 | $fgroup .= mediaItemLine($items[$i],$j); | 
|---|
| 425 | } | 
|---|
| 426 | } | 
|---|
| 427 |  | 
|---|
| 428 | echo | 
|---|
| 429 | ($dgroup != '' ? '<div class="folders-group">'.$dgroup.'</div>' : ''). | 
|---|
| 430 | sprintf($fmt_form_media,$fgroup,''); | 
|---|
| 431 |  | 
|---|
| 432 | echo $pager->getLinks(); | 
|---|
| 433 | } | 
|---|
| 434 | if (!isset($pager)) { | 
|---|
| 435 | echo | 
|---|
| 436 | '<p class="clear"></p>'; | 
|---|
| 437 | } | 
|---|
| 438 | echo | 
|---|
| 439 | '</div>'; | 
|---|
| 440 |  | 
|---|
| 441 | $core_media_archivable = $core->auth->check('media_admin',$core->blog->id) && | 
|---|
| 442 | !(count($items) == 0 || (count($items) == 1 && $items[0]->parent)); | 
|---|
| 443 |  | 
|---|
| 444 | if ($core_media_writable || $core_media_archivable) { | 
|---|
| 445 | echo | 
|---|
| 446 | '<div class="vertical-separator">'. | 
|---|
| 447 | '<h3 class="out-of-screen-if-js">'.sprintf(__('In %s:'),($d == '' ? '“'.__('Media manager').'”' : '“'.$d.'”')).'</h3>'; | 
|---|
| 448 | } | 
|---|
| 449 |  | 
|---|
| 450 | if ($core_media_writable || $core_media_archivable) { | 
|---|
| 451 | echo | 
|---|
| 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 | 
|---|
| 471 | if ($core_media_archivable && !$popup) | 
|---|
| 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 |  | 
|---|
| 481 | echo | 
|---|
| 482 | '</div>'; | 
|---|
| 483 | } | 
|---|
| 484 |  | 
|---|
| 485 | if ($core_media_writable) | 
|---|
| 486 | { | 
|---|
| 487 | echo | 
|---|
| 488 | '<div class="two-boxes fieldset even">'; | 
|---|
| 489 | if ($user_ui_enhanceduploader) { | 
|---|
| 490 | echo | 
|---|
| 491 | '<div class="enhanced_uploader">'; | 
|---|
| 492 | } else { | 
|---|
| 493 | echo | 
|---|
| 494 | '<div>'; | 
|---|
| 495 | } | 
|---|
| 496 |  | 
|---|
| 497 | echo | 
|---|
| 498 | '<h4>'.__('Add files').'</h4>'. | 
|---|
| 499 | '<p>'.__('Please take care to publish media that you own and that are not protected by copyright.').'</p>'. | 
|---|
| 500 | '<form id="fileupload" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data" aria-disabled="false">'. | 
|---|
| 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>'; | 
|---|
| 504 |  | 
|---|
| 505 | echo | 
|---|
| 506 | '<div class="fileupload-buttonbar clear">'; | 
|---|
| 507 |  | 
|---|
| 508 | echo | 
|---|
| 509 | '<p><label for="upfile">'.'<span class="add-label one-file">'.__('Choose file').'</span>'.'</label>'. | 
|---|
| 510 | '<button class="button choose_files">'.__('Choose files').'</button>'. | 
|---|
| 511 | '<input type="file" id="upfile" name="upfile[]"'.($user_ui_enhanceduploader?' multiple="mutiple"':'').' data-url="'.html::escapeURL($page_url).'" /></p>'; | 
|---|
| 512 |  | 
|---|
| 513 | echo | 
|---|
| 514 | '<p class="max-sizer form-note"> '.__('Maximum file size allowed:').' '.files::size(DC_MAX_UPLOAD_SIZE).'</p>'; | 
|---|
| 515 |  | 
|---|
| 516 | echo | 
|---|
| 517 | '<p class="one-file"><label for="upfiletitle">'.__('Title:').'</label>'.form::field(array('upfiletitle','upfiletitle'),35,255).'</p>'. | 
|---|
| 518 | '<p class="one-file"><label for="upfilepriv" class="classic">'.__('Private').'</label> '. | 
|---|
| 519 | form::checkbox(array('upfilepriv','upfilepriv'),1).'</p>'; | 
|---|
| 520 |  | 
|---|
| 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 | } | 
|---|
| 526 |  | 
|---|
| 527 | echo | 
|---|
| 528 | '<p class="clear"><button class="button clean">'.__('Refresh').'</button>'. | 
|---|
| 529 | '<input class="button cancel one-file" type="reset" value="'.__('Clear all').'"/>'. | 
|---|
| 530 | '<input class="button start" type="submit" value="'.__('Upload').'"/></p>'. | 
|---|
| 531 | '</div>'; | 
|---|
| 532 |  | 
|---|
| 533 | echo | 
|---|
| 534 | '<p style="clear:both;">'.form::hidden(array('d'),$d).'</p>'. | 
|---|
| 535 | '</form>'. | 
|---|
| 536 | '</div>'. | 
|---|
| 537 | '</div>'; | 
|---|
| 538 | } | 
|---|
| 539 |  | 
|---|
| 540 | # Empty remove form (for javascript actions) | 
|---|
| 541 | echo | 
|---|
| 542 | '<form id="media-remove-hide" action="'.html::escapeURL($page_url).'" method="post" class="hidden">'. | 
|---|
| 543 | '<div>'. | 
|---|
| 544 | form::hidden('rmyes',1).form::hidden('d',html::escapeHTML($d)). | 
|---|
| 545 | form::hidden('remove',''). | 
|---|
| 546 | $core->formNonce(). | 
|---|
| 547 | '</div>'. | 
|---|
| 548 | '</form>'; | 
|---|
| 549 |  | 
|---|
| 550 | if ($core_media_writable || $core_media_archivable) { | 
|---|
| 551 | echo | 
|---|
| 552 | '</div>'; | 
|---|
| 553 | } | 
|---|
| 554 |  | 
|---|
| 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 |  | 
|---|
| 560 | call_user_func($close_f); | 
|---|
| 561 |  | 
|---|
| 562 | /* ----------------------------------------------------- */ | 
|---|
| 563 | function mediaItemLine($f,$i) | 
|---|
| 564 | { | 
|---|
| 565 | global $core, $page_url, $popup, $post_id; | 
|---|
| 566 |  | 
|---|
| 567 | $fname = $f->basename; | 
|---|
| 568 |  | 
|---|
| 569 | $class = 'media-item media-col-'.($i%2); | 
|---|
| 570 |  | 
|---|
| 571 | if ($f->d) { | 
|---|
| 572 | $link = html::escapeURL($page_url).'&d='.html::sanitizeURL($f->relname); | 
|---|
| 573 | if ($f->parent) { | 
|---|
| 574 | $fname = '..'; | 
|---|
| 575 | $class .= ' media-folder-up'; | 
|---|
| 576 | } else { | 
|---|
| 577 | $class .= ' media-folder'; | 
|---|
| 578 | } | 
|---|
| 579 | } else { | 
|---|
| 580 | $link = 'media_item.php?id='.$f->media_id.'&popup='.$popup.'&post_id='.$post_id; | 
|---|
| 581 | if (($temp = $core->callBehavior('adminMediaURL',$link))!='') { | 
|---|
| 582 | $link = $temp; | 
|---|
| 583 | } | 
|---|
| 584 | } | 
|---|
| 585 |  | 
|---|
| 586 | $maxchars = 36; | 
|---|
| 587 | if (strlen($fname) > $maxchars) { | 
|---|
| 588 | $fname = substr($fname, 0, $maxchars-4).'...'.($f->d ? '' : files::getExtension($fname)); | 
|---|
| 589 | } | 
|---|
| 590 | $res = | 
|---|
| 591 | '<div class="'.$class.'"><p><a class="media-icon media-link" href="'.$link.'">'. | 
|---|
| 592 | '<img src="'.$f->media_icon.'" alt="" />'.$fname.'</a></p>'; | 
|---|
| 593 |  | 
|---|
| 594 | $lst = ''; | 
|---|
| 595 |  | 
|---|
| 596 | if (!$f->d) { | 
|---|
| 597 | $lst .= | 
|---|
| 598 | '<li>'.$f->media_title.'</li>'. | 
|---|
| 599 | '<li>'. | 
|---|
| 600 | $f->media_dtstr.' - '. | 
|---|
| 601 | files::size($f->size).' - '. | 
|---|
| 602 | '<a href="'.$f->file_url.'">'.__('open').'</a>'. | 
|---|
| 603 | '</li>'; | 
|---|
| 604 | } | 
|---|
| 605 |  | 
|---|
| 606 | $act = ''; | 
|---|
| 607 |  | 
|---|
| 608 | if ($post_id && !$f->d) { | 
|---|
| 609 | $act .= | 
|---|
| 610 | '<a class="attach-media" title="'.__('Attach this file to entry').'" href="post_media.php?media_id='.$f->media_id. | 
|---|
| 611 | '&post_id='.$post_id.'&attach=1">'. | 
|---|
| 612 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'"/>'. | 
|---|
| 613 | '</a>'; | 
|---|
| 614 | } | 
|---|
| 615 |  | 
|---|
| 616 | if ($popup && !$f->d) { | 
|---|
| 617 | $act .= '<a href="'.$link.'"><img src="images/plus.png" alt="'.__('Insert this file into entry').'" '. | 
|---|
| 618 | 'title="'.__('Insert this file into entry').'" /></a> '; | 
|---|
| 619 | } | 
|---|
| 620 |  | 
|---|
| 621 | if ($f->del) { | 
|---|
| 622 | if (!$popup && !$f->d) { | 
|---|
| 623 | $act .= form::checkbox(array('medias[]', 'media_'.rawurlencode($f->basename)),rawurlencode($f->basename)); | 
|---|
| 624 | } else { | 
|---|
| 625 | $act .= '<a class="media-remove" '. | 
|---|
| 626 | 'href="'.html::escapeURL($page_url).'&d='. | 
|---|
| 627 | rawurlencode($GLOBALS['d']).'&remove='.rawurlencode($f->basename).'">'. | 
|---|
| 628 | '<img src="images/trash.png" alt="'.__('Delete').'" title="'.__('delete').'" /></a>'; | 
|---|
| 629 | } | 
|---|
| 630 | } | 
|---|
| 631 |  | 
|---|
| 632 | $lst .= ($act != '' ? '<li class="media-action"> '.$act.'</li>' : ''); | 
|---|
| 633 |  | 
|---|
| 634 | if ($f->type == 'audio/mpeg3') { | 
|---|
| 635 | $lst .= '<li>'.dcMedia::mp3player($f->file_url,'index.php?pf=player_mp3.swf').'</li>'; | 
|---|
| 636 | } | 
|---|
| 637 |  | 
|---|
| 638 | $res .=   ($lst != '' ? '<ul>'.$lst.'</ul>' : ''); | 
|---|
| 639 |  | 
|---|
| 640 | $res .= '</div>'; | 
|---|
| 641 |  | 
|---|
| 642 | return $res; | 
|---|
| 643 | } | 
|---|