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 | $plugin_id = isset($_REQUEST['plugin_id']) ? html::sanitizeURL($_REQUEST['plugin_id']) : ''; |
---|
31 | $dir = null; |
---|
32 | |
---|
33 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
34 | $nb_per_page = ((integer) $core->auth->user_prefs->interface->media_by_page ? (integer) $core->auth->user_prefs->interface->media_by_page : 30); |
---|
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' |
---|
64 | ); |
---|
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; |
---|
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 | } |
---|
74 | |
---|
75 | $popup = (integer) !empty($_GET['popup']); |
---|
76 | |
---|
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))!='') { |
---|
79 | $page_url = $temp; |
---|
80 | } |
---|
81 | |
---|
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) { |
---|
101 | // throw new Exception('you do not have sufficient permissions to write to this folder: '); |
---|
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); |
---|
117 | |
---|
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']); |
---|
135 | dcPage::addSuccessNotice(sprintf( |
---|
136 | __('Directory "%s" has been successfully created.'), |
---|
137 | html::escapeHTML($_POST['newdir'])) |
---|
138 | ); |
---|
139 | http::redirect($page_url.'&plugin_id='.$plugin_id.'&d='.rawurlencode($d)); |
---|
140 | } catch (Exception $e) { |
---|
141 | $core->error->add($e->getMessage()); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | # Adding a file |
---|
146 | if ($dir && !empty($_FILES['upfile'])) { |
---|
147 | // only one file per request : @see option singleFileUploads in admin/js/jsUpload/jquery.fileupload |
---|
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 | ); |
---|
154 | |
---|
155 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
---|
156 | header('Content-type: application/json'); |
---|
157 | $message = array(); |
---|
158 | |
---|
159 | try { |
---|
160 | files::uploadStatus($upfile); |
---|
161 | $new_file_id = $core->media->uploadFile($upfile['tmp_name'], $upfile['name']); |
---|
162 | |
---|
163 | $message['files'][] = array( |
---|
164 | 'name' => $upfile['name'], |
---|
165 | 'size' => $upfile['size'], |
---|
166 | 'html' => mediaItemLine($core->media->getFile($new_file_id), 1) |
---|
167 | ); |
---|
168 | } catch (Exception $e) { |
---|
169 | $message['files'][] = array('name' => $upfile['name'], |
---|
170 | 'size' => $upfile['size'], |
---|
171 | 'error' => $e->getMessage() |
---|
172 | ); |
---|
173 | } |
---|
174 | echo json_encode($message); |
---|
175 | exit(); |
---|
176 | } else { |
---|
177 | try { |
---|
178 | files::uploadStatus($upfile); |
---|
179 | |
---|
180 | $f_title = (isset($_POST['upfiletitle']) ? $_POST['upfiletitle'] : ''); |
---|
181 | $f_private = (isset($_POST['upfilepriv']) ? $_POST['upfilepriv'] : false); |
---|
182 | |
---|
183 | $core->media->uploadFile($upfile['tmp_name'], $upfile['name'], $f_title, $f_private); |
---|
184 | |
---|
185 | dcPage::addSuccessNotice(__('Files have been successfully uploaded.')); |
---|
186 | http::redirect($page_url.'&plugin_id='.$plugin_id.'&d='.rawurlencode($d)); |
---|
187 | } catch (Exception $e) { |
---|
188 | $core->error->add($e->getMessage()); |
---|
189 | } |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
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 | ); |
---|
207 | http::redirect($page_url.'&plugin_id='.$plugin_id.'&d='.rawurlencode($d)); |
---|
208 | } catch (Exception $e) { |
---|
209 | $core->error->add($e->getMessage()); |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | # Removing item from popup only |
---|
214 | if ($dir && !empty($_POST['rmyes']) && !empty($_POST['remove'])) |
---|
215 | { |
---|
216 | $_POST['remove'] = rawurldecode($_POST['remove']); |
---|
217 | |
---|
218 | try { |
---|
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 | } |
---|
224 | $core->media->removeItem($_POST['remove']); |
---|
225 | dcPage::addSuccessNotice($msg); |
---|
226 | http::redirect($page_url.'&plugin_id='.$plugin_id.'&d='.rawurlencode($d)); |
---|
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); |
---|
237 | |
---|
238 | dcPage::success(sprintf( |
---|
239 | __('Directory "%s" has been successfully rebuilt.'), |
---|
240 | html::escapeHTML($d)) |
---|
241 | ); |
---|
242 | http::redirect($page_url.'&plugin_id='.$plugin_id.'&d='.rawurlencode($d)); |
---|
243 | } catch (Exception $e) { |
---|
244 | $core->error->add($e->getMessage()); |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | # DISPLAY confirm page for rmdir & rmfile |
---|
249 | if ($dir && !empty($_GET['remove']) && empty($_GET['noconfirm'])) |
---|
250 | { |
---|
251 | call_user_func($open_f,__('Media manager'),'', |
---|
252 | dcPage::breadcrumb( |
---|
253 | array( |
---|
254 | html::escapeHTML($core->blog->name) => '', |
---|
255 | __('Media manager') => '', |
---|
256 | __('confirm removal') => '' |
---|
257 | ), |
---|
258 | array('home_link' => !$popup) |
---|
259 | ) |
---|
260 | ); |
---|
261 | |
---|
262 | echo |
---|
263 | '<form action="'.html::escapeURL($page_url).'" method="post">'. |
---|
264 | '<p>'.sprintf(__('Are you sure you want to remove %s?'), |
---|
265 | html::escapeHTML($_GET['remove'])).'</p>'. |
---|
266 | '<p><input type="submit" value="'.__('Cancel').'" /> '. |
---|
267 | ' <input type="submit" name="rmyes" value="'.__('Yes').'" />'. |
---|
268 | form::hidden('d',$d). |
---|
269 | $core->formNonce(). |
---|
270 | form::hidden('remove',html::escapeHTML($_GET['remove'])).'</p>'. |
---|
271 | '</form>'; |
---|
272 | |
---|
273 | call_user_func($close_f); |
---|
274 | exit; |
---|
275 | } |
---|
276 | |
---|
277 | /* DISPLAY Main page |
---|
278 | -------------------------------------------------------- */ |
---|
279 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
280 | $user_ui_enhanceduploader = $core->auth->user_prefs->interface->enhanceduploader; |
---|
281 | |
---|
282 | if (!isset($core->media)) { |
---|
283 | $breadcrumb = dcPage::breadcrumb( |
---|
284 | array( |
---|
285 | html::escapeHTML($core->blog->name) => '', |
---|
286 | __('Media manager') => '' |
---|
287 | ), |
---|
288 | array('home_link' => !$popup) |
---|
289 | ); |
---|
290 | } else { |
---|
291 | $breadcrumb_media = $core->media->breadCrumb(html::escapeURL($page_url).'&plugin_id='.$plugin_id.'&d=%s','<span class="page-title">%s</span>'); |
---|
292 | if ($breadcrumb_media == '') { |
---|
293 | $breadcrumb = dcPage::breadcrumb( |
---|
294 | array( |
---|
295 | html::escapeHTML($core->blog->name) => '', |
---|
296 | __('Media manager') => '' |
---|
297 | ), |
---|
298 | array('home_link' => !$popup) |
---|
299 | ); |
---|
300 | } else { |
---|
301 | $breadcrumb = dcPage::breadcrumb( |
---|
302 | array( |
---|
303 | html::escapeHTML($core->blog->name) => '', |
---|
304 | __('Media manager') => html::escapeURL($page_url.'&plugin_id='.$plugin_id.'&d='), |
---|
305 | $breadcrumb_media => '' |
---|
306 | ), |
---|
307 | array( |
---|
308 | 'home_link' => !$popup, |
---|
309 | 'hl' => false |
---|
310 | ) |
---|
311 | ); |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | call_user_func($open_f,__('Media manager'), |
---|
316 | dcPage::jsLoad('js/_media.js'). |
---|
317 | ($core_media_writable ? dcPage::jsUpload(array('d='.$d)) : ''), |
---|
318 | $breadcrumb |
---|
319 | ); |
---|
320 | |
---|
321 | if ($popup) { |
---|
322 | // Display notices |
---|
323 | echo dcPage::notices(); |
---|
324 | } |
---|
325 | |
---|
326 | if (!$core_media_writable) { |
---|
327 | dcPage::warning(__('You do not have sufficient permissions to write to this folder.')); |
---|
328 | } |
---|
329 | |
---|
330 | if (!empty($_GET['mkdok'])) { |
---|
331 | dcPage::success(__('Directory has been successfully created.')); |
---|
332 | } |
---|
333 | |
---|
334 | if (!empty($_GET['upok'])) { |
---|
335 | dcPage::success(__('Files have been successfully uploaded.')); |
---|
336 | } |
---|
337 | |
---|
338 | if (!empty($_GET['rmfok'])) { |
---|
339 | dcPage::success(__('File has been successfully removed.')); |
---|
340 | } |
---|
341 | |
---|
342 | if (!empty($_GET['rmdok'])) { |
---|
343 | dcPage::success(__('Directory has been successfully removed.')); |
---|
344 | } |
---|
345 | |
---|
346 | if (!empty($_GET['rebuildok'])) { |
---|
347 | dcPage::success(__('Directory has been successfully rebuilt.')); |
---|
348 | } |
---|
349 | |
---|
350 | if (!empty($_GET['unzipok'])) { |
---|
351 | dcPage::success(__('Zip file has been successfully extracted.')); |
---|
352 | } |
---|
353 | |
---|
354 | if (!$dir) { |
---|
355 | call_user_func($close_f); |
---|
356 | exit; |
---|
357 | } |
---|
358 | |
---|
359 | if ($post_id) { |
---|
360 | echo '<div class="form-note info"><p>'.sprintf(__('Choose a file to attach to entry %s by clicking on %s.'), |
---|
361 | '<a href="'.$core->getPostAdminURL($post_type,$post_id).'">'.html::escapeHTML($post_title).'</a>', |
---|
362 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />').'</p></div>'; |
---|
363 | } |
---|
364 | if ($popup) { |
---|
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>'; |
---|
367 | } |
---|
368 | |
---|
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 | } |
---|
379 | $items = array_values(array_merge($dir['dirs'],$dir['files'])); |
---|
380 | |
---|
381 | $fmt_form_media = '<form action="'.$core->adminurl->get("admin.media").'" method="post" id="form-medias">'. |
---|
382 | '<div class="files-group">%s</div>'. |
---|
383 | '<p class="hidden">'.$core->formNonce() . form::hidden(array('d'),$d).form::hidden(array('plugin_id'),$plugin_id).'</p>'; |
---|
384 | |
---|
385 | if (!$popup) { |
---|
386 | $fmt_form_media .= |
---|
387 | '<div class="medias-delete%s">'. |
---|
388 | '<p class="checkboxes-helpers"></p>'. |
---|
389 | '<p><input type="submit" class="delete" name="delete_medias" value="'.__('Remove selected medias').'"/></p>'. |
---|
390 | '</div>'; |
---|
391 | } |
---|
392 | $fmt_form_media .= |
---|
393 | '</form>'; |
---|
394 | |
---|
395 | echo '<div class="media-list">'; |
---|
396 | if (count($items) == 0) |
---|
397 | { |
---|
398 | echo |
---|
399 | '<p>'.__('No file.').'</p>'. |
---|
400 | sprintf($fmt_form_media,'',' hide'); // need for jsUpload to append new media |
---|
401 | } |
---|
402 | else |
---|
403 | { |
---|
404 | $pager = new dcPager($page,count($items),$nb_per_page,10); |
---|
405 | |
---|
406 | echo |
---|
407 | '<form action="'.$core->adminurl->get("admin.media").'" method="get" id="filters-form">'. |
---|
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> '. |
---|
411 | form::field('nb_per_page',5,3,(integer) $nb_per_page).' '. |
---|
412 | '<input type="submit" value="'.__('OK').'" />'. |
---|
413 | form::hidden(array('popup'),$popup). |
---|
414 | form::hidden(array('plugin_id'),$plugin_id). |
---|
415 | form::hidden(array('post_id'),$post_id). |
---|
416 | '</p>'. |
---|
417 | '</form>'. |
---|
418 | $pager->getLinks(); |
---|
419 | |
---|
420 | $dgroup = ''; |
---|
421 | $fgroup = ''; |
---|
422 | for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++,$j++) |
---|
423 | { |
---|
424 | if ($items[$i]->d) { |
---|
425 | $dgroup .= mediaItemLine($items[$i],$j); |
---|
426 | } else { |
---|
427 | $fgroup .= mediaItemLine($items[$i],$j); |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | echo |
---|
432 | ($dgroup != '' ? '<div class="folders-group">'.$dgroup.'</div>' : ''). |
---|
433 | sprintf($fmt_form_media,$fgroup,''); |
---|
434 | |
---|
435 | echo $pager->getLinks(); |
---|
436 | } |
---|
437 | if (!isset($pager)) { |
---|
438 | echo |
---|
439 | '<p class="clear"></p>'; |
---|
440 | } |
---|
441 | echo |
---|
442 | '</div>'; |
---|
443 | |
---|
444 | $core_media_archivable = $core->auth->check('media_admin',$core->blog->id) && |
---|
445 | !(count($items) == 0 || (count($items) == 1 && $items[0]->parent)); |
---|
446 | |
---|
447 | if ($core_media_writable || $core_media_archivable) { |
---|
448 | echo |
---|
449 | '<div class="vertical-separator">'. |
---|
450 | '<h3 class="out-of-screen-if-js">'.sprintf(__('In %s:'),($d == '' ? '“'.__('Media manager').'”' : '“'.$d.'”')).'</h3>'; |
---|
451 | } |
---|
452 | |
---|
453 | if ($core_media_writable || $core_media_archivable) { |
---|
454 | echo |
---|
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').'" />'. |
---|
468 | form::hidden(array('d'),html::escapeHTML($d)). |
---|
469 | form::hidden(array('plugin_id'),$plugin_id).'</p>'. |
---|
470 | '</div>'. |
---|
471 | '</form>'; |
---|
472 | } |
---|
473 | |
---|
474 | # Get zip directory |
---|
475 | if ($core_media_archivable && !$popup) |
---|
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 | |
---|
485 | echo |
---|
486 | '</div>'; |
---|
487 | } |
---|
488 | |
---|
489 | if ($core_media_writable) |
---|
490 | { |
---|
491 | echo |
---|
492 | '<div class="two-boxes fieldset even">'; |
---|
493 | if ($user_ui_enhanceduploader) { |
---|
494 | echo |
---|
495 | '<div class="enhanced_uploader">'; |
---|
496 | } else { |
---|
497 | echo |
---|
498 | '<div>'; |
---|
499 | } |
---|
500 | |
---|
501 | echo |
---|
502 | '<h4>'.__('Add files').'</h4>'. |
---|
503 | '<p>'.__('Please take care to publish media that you own and that are not protected by copyright.').'</p>'. |
---|
504 | '<form id="fileupload" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data" aria-disabled="false">'. |
---|
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>'; |
---|
508 | |
---|
509 | echo |
---|
510 | '<div class="fileupload-buttonbar clear">'; |
---|
511 | |
---|
512 | echo |
---|
513 | '<p><label for="upfile">'.'<span class="add-label one-file">'.__('Choose file').'</span>'.'</label>'. |
---|
514 | '<button class="button choose_files">'.__('Choose files').'</button>'. |
---|
515 | '<input type="file" id="upfile" name="upfile[]"'.($user_ui_enhanceduploader?' multiple="mutiple"':'').' data-url="'.html::escapeURL($page_url).'" /></p>'; |
---|
516 | |
---|
517 | echo |
---|
518 | '<p class="max-sizer form-note"> '.__('Maximum file size allowed:').' '.files::size(DC_MAX_UPLOAD_SIZE).'</p>'; |
---|
519 | |
---|
520 | echo |
---|
521 | '<p class="one-file"><label for="upfiletitle">'.__('Title:').'</label>'.form::field(array('upfiletitle','upfiletitle'),35,255).'</p>'. |
---|
522 | '<p class="one-file"><label for="upfilepriv" class="classic">'.__('Private').'</label> '. |
---|
523 | form::checkbox(array('upfilepriv','upfilepriv'),1).'</p>'; |
---|
524 | |
---|
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'). |
---|
528 | ' <a href="'.$core->adminurl->get("admin.user.preferences",array('tab' => 'user-options')).'">'.__('My preferences').'</a></p>'; |
---|
529 | } |
---|
530 | |
---|
531 | echo |
---|
532 | '<p class="clear"><button class="button clean">'.__('Refresh').'</button>'. |
---|
533 | '<input class="button cancel one-file" type="reset" value="'.__('Clear all').'"/>'. |
---|
534 | '<input class="button start" type="submit" value="'.__('Upload').'"/></p>'. |
---|
535 | '</div>'; |
---|
536 | |
---|
537 | echo |
---|
538 | '<p style="clear:both;">'.form::hidden(array('d'),$d).'</p>'. |
---|
539 | '</form>'. |
---|
540 | '</div>'. |
---|
541 | '</div>'; |
---|
542 | } |
---|
543 | |
---|
544 | # Empty remove form (for javascript actions) |
---|
545 | echo |
---|
546 | '<form id="media-remove-hide" action="'.html::escapeURL($page_url).'" method="post" class="hidden">'. |
---|
547 | '<div>'. |
---|
548 | form::hidden('rmyes',1).form::hidden('d',html::escapeHTML($d)). |
---|
549 | form::hidden(array('plugin_id'),$plugin_id).form::hidden('remove',''). |
---|
550 | $core->formNonce(). |
---|
551 | '</div>'. |
---|
552 | '</form>'; |
---|
553 | |
---|
554 | if ($core_media_writable || $core_media_archivable) { |
---|
555 | echo |
---|
556 | '</div>'; |
---|
557 | } |
---|
558 | |
---|
559 | if (!$popup) { |
---|
560 | echo '<div class="info"><p>'.sprintf(__('Current settings for medias and images are defined in %s'), |
---|
561 | '<a href="'.$core->adminurl->get("admin.blog.pref").'#medias-settings">'.__('Blog parameters').'</a>').'</p></div>'; |
---|
562 | } |
---|
563 | |
---|
564 | call_user_func($close_f); |
---|
565 | |
---|
566 | /* ----------------------------------------------------- */ |
---|
567 | function mediaItemLine($f,$i) |
---|
568 | { |
---|
569 | global $core, $page_url, $popup, $post_id, $plugin_id; |
---|
570 | |
---|
571 | $fname = $f->basename; |
---|
572 | |
---|
573 | $class = 'media-item media-col-'.($i%2); |
---|
574 | |
---|
575 | if ($f->d) { |
---|
576 | $link = html::escapeURL($page_url).'&plugin_id='.$plugin_id.'&d='.html::sanitizeURL($f->relname); |
---|
577 | if ($f->parent) { |
---|
578 | $fname = '..'; |
---|
579 | $class .= ' media-folder-up'; |
---|
580 | } else { |
---|
581 | $class .= ' media-folder'; |
---|
582 | } |
---|
583 | } else { |
---|
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 | } |
---|
596 | } |
---|
597 | |
---|
598 | $maxchars = 36; |
---|
599 | if (strlen($fname) > $maxchars) { |
---|
600 | $fname = substr($fname, 0, $maxchars-4).'...'.($f->d ? '' : files::getExtension($fname)); |
---|
601 | } |
---|
602 | $res = |
---|
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 = ''; |
---|
607 | |
---|
608 | if (!$f->d) { |
---|
609 | $lst .= |
---|
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 | } |
---|
617 | |
---|
618 | $act = ''; |
---|
619 | |
---|
620 | if ($post_id && !$f->d) { |
---|
621 | $act .= |
---|
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 | '">'. |
---|
625 | '<img src="images/plus.png" alt="'.__('Attach this file to entry').'"/>'. |
---|
626 | '</a>'; |
---|
627 | } |
---|
628 | |
---|
629 | if ($popup && !$f->d) { |
---|
630 | $act .= '<a href="'.$link.'"><img src="images/plus.png" alt="'.__('Insert this file into entry').'" '. |
---|
631 | 'title="'.__('Insert this file into entry').'" /></a> '; |
---|
632 | } |
---|
633 | |
---|
634 | if ($f->del) { |
---|
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" '. |
---|
639 | 'href="'.html::escapeURL($page_url).'&plugin_id='.$plugin_id.'&d='. |
---|
640 | rawurlencode($GLOBALS['d']).'&remove='.rawurlencode($f->basename).'">'. |
---|
641 | '<img src="images/trash.png" alt="'.__('Delete').'" title="'.__('delete').'" /></a>'; |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | $lst .= ($act != '' ? '<li class="media-action"> '.$act.'</li>' : ''); |
---|
646 | |
---|
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>'; |
---|
652 | } |
---|
653 | |
---|
654 | $res .= ($lst != '' ? '<ul>'.$lst.'</ul>' : ''); |
---|
655 | |
---|
656 | $res .= '</div>'; |
---|
657 | |
---|
658 | return $res; |
---|
659 | } |
---|