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