1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # |
---|
4 | # This file is part of DL Manager, a plugin for Dotclear 2 |
---|
5 | # Copyright (C) 2008,2010 Moe (http://gniark.net/) and Tomtom (http://blog.zenstyle.fr) |
---|
6 | # |
---|
7 | # DL Manager is free software; you can redistribute it and/or |
---|
8 | # modify it under the terms of the GNU General Public License v2.0 |
---|
9 | # as published by the Free Software Foundation. |
---|
10 | # |
---|
11 | # DL Manager is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with this program; if not, write to the Free Software Foundation, |
---|
18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
19 | # |
---|
20 | # Images are from Silk Icons : http://www.famfamfam.com/lab/icons/silk/ |
---|
21 | # |
---|
22 | # ***** END LICENSE BLOCK ***** |
---|
23 | |
---|
24 | if (!defined('DC_RC_PATH')) {return;} |
---|
25 | |
---|
26 | if (!$core->blog->settings->dlManager->dlmanager_active) {return;} |
---|
27 | |
---|
28 | /** |
---|
29 | @ingroup Download manager |
---|
30 | @brief Document |
---|
31 | */ |
---|
32 | class dlManagerPageDocument extends dcUrlHandlers |
---|
33 | { |
---|
34 | private static function check() |
---|
35 | { |
---|
36 | |
---|
37 | global $core; |
---|
38 | |
---|
39 | # if the plugin is disabled |
---|
40 | if (!$core->blog->settings->dlManager->dlmanager_active) |
---|
41 | { |
---|
42 | self::p404(); |
---|
43 | return; |
---|
44 | } |
---|
45 | |
---|
46 | # exit if the public_path (and Media root) doesn't exist |
---|
47 | if (!is_dir($core->blog->public_path)) |
---|
48 | { |
---|
49 | self::p404(); |
---|
50 | return; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | serve the document |
---|
56 | @param args <b>string</b> Argument |
---|
57 | */ |
---|
58 | public static function page($args) |
---|
59 | { |
---|
60 | global $core; |
---|
61 | |
---|
62 | self::check(); |
---|
63 | |
---|
64 | # start session |
---|
65 | $session_id = session_id(); |
---|
66 | if (empty($session_id)) {session_start();} |
---|
67 | |
---|
68 | $_ctx =& $GLOBALS['_ctx']; |
---|
69 | |
---|
70 | try |
---|
71 | { |
---|
72 | # define root of DL Manager |
---|
73 | $page_root = $core->blog->settings->dlManager->dlmanager_root; |
---|
74 | |
---|
75 | # used to remove root from path |
---|
76 | $page_root_len = strlen($page_root); |
---|
77 | |
---|
78 | # remove slash at the beginning of the string |
---|
79 | if ($page_root_len > 0) {$page_root_len += 1;} |
---|
80 | |
---|
81 | $page_dir = $page_root; |
---|
82 | |
---|
83 | $dir = '/'; |
---|
84 | $_ctx->dlManager_currentDir = __('Home'); |
---|
85 | |
---|
86 | $root = true; |
---|
87 | |
---|
88 | # if the visitor request a directory |
---|
89 | if ((!empty($args)) && (substr($args,0,1) == '/')) |
---|
90 | { |
---|
91 | $_ctx->dlManager_currentDir = substr($args,1); |
---|
92 | $dir = substr($args,1); |
---|
93 | $page_dir = $page_root.'/'.$dir; |
---|
94 | $root = false; |
---|
95 | } |
---|
96 | |
---|
97 | # BreadCrumb |
---|
98 | $_ctx->dlManager_BreadCrumb = dlManager::breadCrumb($dir); |
---|
99 | # /BreadCrumb |
---|
100 | |
---|
101 | # file sort |
---|
102 | # if visitor can choose how to sort files |
---|
103 | if ($core->blog->settings->dlManager->dlmanager_enable_sort === true) |
---|
104 | { |
---|
105 | # from /dotclear/admin/media.php |
---|
106 | if ((!empty($_POST['media_file_sort'])) |
---|
107 | && (in_array($_POST['media_file_sort'],dlManager::getSortValues()))) |
---|
108 | { |
---|
109 | $_SESSION['media_file_sort'] = $_POST['media_file_sort']; |
---|
110 | } |
---|
111 | if (!empty($_SESSION['media_file_sort'])) |
---|
112 | { |
---|
113 | $core->media->setFileSort($_SESSION['media_file_sort']); |
---|
114 | $_ctx->dlManager_fileSort = $_SESSION['media_file_sort']; |
---|
115 | } |
---|
116 | # /from /dotclear/admin/media.php |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | # default value |
---|
121 | $_ctx->dlManager_fileSort = $core->blog->settings->dlManager->dlmanager_file_sort; |
---|
122 | } |
---|
123 | |
---|
124 | # exit if the directory doesn't exist |
---|
125 | $dir_full_path = $core->media->root.'/'.$page_dir; |
---|
126 | if (!is_dir($dir_full_path)) |
---|
127 | { |
---|
128 | self::p404(); |
---|
129 | return; |
---|
130 | } |
---|
131 | |
---|
132 | # used to remove link to root directory |
---|
133 | $parent_dir_full_path = path::real(dirname($dir_full_path)); |
---|
134 | |
---|
135 | # get the content of the directory |
---|
136 | $core->media->setFileSort($_ctx->dlManager_fileSort); |
---|
137 | |
---|
138 | $core->media->chdir($page_dir); |
---|
139 | $core->media->getDir(); |
---|
140 | |
---|
141 | # get relative paths from root of DL Manager |
---|
142 | foreach ($core->media->dir['dirs'] as $k => $v) |
---|
143 | { |
---|
144 | $item =& $core->media->dir['dirs'][$k]; |
---|
145 | $item->media_type = 'folder'; |
---|
146 | |
---|
147 | # if the current page is the root |
---|
148 | if ($root && ($item->file == $parent_dir_full_path)) |
---|
149 | { |
---|
150 | # remove link to root directory |
---|
151 | unset($core->media->dir['dirs'][$k]); |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | $item->relname = substr($item->relname,$page_root_len); |
---|
156 | |
---|
157 | # rename link to parent directory |
---|
158 | if ($item->file == $parent_dir_full_path) |
---|
159 | { |
---|
160 | $item->basename = __('parent directory'); |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | $_ctx->dlManager_dirs = dlManager::getItems($core->media->dir['dirs']); |
---|
166 | unset($core->media->dir['dirs']); |
---|
167 | |
---|
168 | # pager |
---|
169 | $files =& $core->media->dir['files']; |
---|
170 | |
---|
171 | $_ctx->dlManager_multiple_pages = (boolean) (count($files) > |
---|
172 | $core->blog->settings->dlManager->dlmanager_nb_per_page); |
---|
173 | |
---|
174 | $_ctx->dlManager_pager = new pager( |
---|
175 | # current page |
---|
176 | ((isset($_GET['page'])) ? $_GET['page'] : 1),count($files), |
---|
177 | $core->blog->settings->dlManager->dlmanager_nb_per_page,10); |
---|
178 | |
---|
179 | $_ctx->dlManager_pager->html_prev = '« '.__('previous'); |
---|
180 | $_ctx->dlManager_pager->html_next = __('next').' »'; |
---|
181 | $_ctx->dlManager_pager->var_page = 'page'; |
---|
182 | $_ctx->dlManager_pager->html_link_sep = ' '; |
---|
183 | $_ctx->dlManager_pager->html_prev_grp = '…'; |
---|
184 | $_ctx->dlManager_pager->html_next_grp = '…'; |
---|
185 | |
---|
186 | $files_array = array(); |
---|
187 | |
---|
188 | for ($i=$_ctx->dlManager_pager->index_start, $j=0; |
---|
189 | $i<=$_ctx->dlManager_pager->index_end; $i++, $j++) |
---|
190 | { |
---|
191 | $item =& $files[$i]; |
---|
192 | |
---|
193 | $item->relname = substr($item->relname,$page_root_len); |
---|
194 | |
---|
195 | $files_array[] = $item; |
---|
196 | } |
---|
197 | $_ctx->dlManager_files = dlManager::getItems($files_array); |
---|
198 | unset($core->media->dir['files'],$files_array); |
---|
199 | # /pager |
---|
200 | |
---|
201 | unset($files_array); |
---|
202 | } |
---|
203 | catch (Exception $e) |
---|
204 | { |
---|
205 | $_ctx->form_error = $e->getMessage(); |
---|
206 | } |
---|
207 | |
---|
208 | $core->tpl->setPath($core->tpl->getPath(), |
---|
209 | dirname(__FILE__).'/default-templates/'); |
---|
210 | |
---|
211 | self::serveDocument('media.html','text/html',true,false); |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | serve the media player document |
---|
216 | @param args <b>string</b> Argument |
---|
217 | */ |
---|
218 | public static function player($args) |
---|
219 | { |
---|
220 | global $core; |
---|
221 | |
---|
222 | self::check(); |
---|
223 | |
---|
224 | $_ctx =& $GLOBALS['_ctx']; |
---|
225 | |
---|
226 | try |
---|
227 | { |
---|
228 | $file = $core->media->getFile($args); |
---|
229 | |
---|
230 | if ((empty($file->file)) || (!is_readable($file->file))) |
---|
231 | { |
---|
232 | self::p404(); |
---|
233 | return; |
---|
234 | } |
---|
235 | |
---|
236 | # file_url for mp3, flv, mp4 and m4v players |
---|
237 | if ($core->blog->settings->dlManager->dlmanager_hide_urls) |
---|
238 | { |
---|
239 | $_ctx->file_url = $core->blog->url.$core->url->getBase('viewfile'). |
---|
240 | '/'.$file->media_id; |
---|
241 | } |
---|
242 | else |
---|
243 | { |
---|
244 | $_ctx->file_url = $file->file_url; |
---|
245 | } |
---|
246 | |
---|
247 | # define root of DL Manager |
---|
248 | $page_root = $core->blog->settings->dlManager->dlmanager_root; |
---|
249 | |
---|
250 | # used to remove root from path |
---|
251 | $page_root_len = strlen($page_root); |
---|
252 | |
---|
253 | # remove slash at the beginning of the string |
---|
254 | if ($page_root_len > 0) {$page_root_len += 1;} |
---|
255 | |
---|
256 | if (!dlManager::inJail($file->relname)) |
---|
257 | { |
---|
258 | self::p404(); |
---|
259 | return; |
---|
260 | } |
---|
261 | |
---|
262 | $file->relname = |
---|
263 | dirname(substr($file->relname,$page_root_len)); |
---|
264 | if ($file->relname == '.') |
---|
265 | { |
---|
266 | $file->relname = ''; |
---|
267 | } |
---|
268 | |
---|
269 | # BreadCrumb |
---|
270 | $_ctx->dlManager_BreadCrumb = dlManager::breadCrumb($file->relname); |
---|
271 | # /BreadCrumb |
---|
272 | |
---|
273 | # get static record |
---|
274 | $files = array(); |
---|
275 | $files[] = $file; |
---|
276 | $_ctx->items = dlManager::getItems($files); |
---|
277 | unset($files); |
---|
278 | # /get static record |
---|
279 | |
---|
280 | $core->tpl->setPath($core->tpl->getPath(), |
---|
281 | dirname(__FILE__).'/default-templates/'); |
---|
282 | |
---|
283 | self::serveDocument('media_player.html','text/html',true,false); |
---|
284 | } |
---|
285 | catch (Exception $e) |
---|
286 | { |
---|
287 | $_ctx->form_error = $e->getMessage(); |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | /** |
---|
292 | serve file |
---|
293 | @param args <b>string</b> Argument |
---|
294 | @param count <b>boolean</b> Count download |
---|
295 | */ |
---|
296 | public static function download($args) |
---|
297 | { |
---|
298 | global $core; |
---|
299 | |
---|
300 | self::check(); |
---|
301 | |
---|
302 | if (!preg_match('/^[0-9]+$/',$args)) |
---|
303 | { |
---|
304 | self::p404(); |
---|
305 | return; |
---|
306 | } |
---|
307 | |
---|
308 | try |
---|
309 | { |
---|
310 | $file = $core->media->getFile($args); |
---|
311 | |
---|
312 | if (empty($file->file)) |
---|
313 | { |
---|
314 | self::p404(); |
---|
315 | return; |
---|
316 | } |
---|
317 | |
---|
318 | if (!dlManager::inJail($file->relname)) |
---|
319 | { |
---|
320 | self::p404(); |
---|
321 | return; |
---|
322 | } |
---|
323 | |
---|
324 | if (is_readable($file->file)) |
---|
325 | { |
---|
326 | if ($core->blog->settings->dlManager->dlmanager_counter) |
---|
327 | { |
---|
328 | $count = unserialize($core->blog->settings->dlManager->dlmanager_count_dl); |
---|
329 | if (!is_array($count)) {$count = array();} |
---|
330 | $count[$file->media_id] = array_key_exists($file->media_id,$count) |
---|
331 | ? $count[$file->media_id]+1 : 1; |
---|
332 | |
---|
333 | $settings =& $core->blog->settings; |
---|
334 | |
---|
335 | $settings->addNamespace('dlManager'); |
---|
336 | $settings->dlManager->put('dlmanager_count_dl',serialize($count),'string', |
---|
337 | 'Download counter'); |
---|
338 | //$core->callBehavior('publicDownloadedFile',(integer)$args); |
---|
339 | } |
---|
340 | http::$cache_max_age = 36000; |
---|
341 | http::cache(array_merge(array($file->file),get_included_files())); |
---|
342 | header('Content-type: '.$file->type); |
---|
343 | header('Content-Length: '.$file->size); |
---|
344 | header('Content-Disposition: attachment; filename="'.$file->basename.'"'); |
---|
345 | readfile($file->file); |
---|
346 | exit; |
---|
347 | # header('Location:'.$file->file_url); |
---|
348 | exit; |
---|
349 | } |
---|
350 | else |
---|
351 | { |
---|
352 | self::p404(); |
---|
353 | return; |
---|
354 | } |
---|
355 | } |
---|
356 | catch (Exception $e) |
---|
357 | { |
---|
358 | $_ctx->form_error = $e->getMessage(); |
---|
359 | } |
---|
360 | } |
---|
361 | |
---|
362 | /** |
---|
363 | serve a file without incrementing the download counter |
---|
364 | @param args <b>string</b> Argument |
---|
365 | */ |
---|
366 | public static function viewfile($args) |
---|
367 | { |
---|
368 | global $core; |
---|
369 | |
---|
370 | if (!$GLOBALS['core']->blog->settings->dlManager->dlmanager_hide_urls |
---|
371 | || empty($args) || !$core->blog->settings->dlManager->dlmanager_active) |
---|
372 | { |
---|
373 | self::p404(); |
---|
374 | return; |
---|
375 | } |
---|
376 | |
---|
377 | try |
---|
378 | { |
---|
379 | # standard file |
---|
380 | if (preg_match('/^[0-9]+$/',$args,$matches)) |
---|
381 | { |
---|
382 | $file = $core->media->getFile($matches[0]); |
---|
383 | |
---|
384 | if (empty($file->file) || ($file->type != 'audio/mpeg3' |
---|
385 | && $file->type != 'video/x-flv' && $file->type != 'video/mp4' |
---|
386 | && $file->type != 'video/x-m4v' && $file->media_type != 'image')) |
---|
387 | { |
---|
388 | self::p404(); |
---|
389 | return; |
---|
390 | } |
---|
391 | |
---|
392 | $file_path = $file->file; |
---|
393 | } |
---|
394 | # image thumbnail |
---|
395 | # \see http://fr.php.net/preg_match |
---|
396 | elseif (preg_match('@^([0-9]+)/(m|s|t|sq)$@',$args,$matches)) |
---|
397 | { |
---|
398 | $file_id = $matches[1]; |
---|
399 | $size = $matches[2]; |
---|
400 | |
---|
401 | $file = $core->media->getFile($file_id); |
---|
402 | |
---|
403 | # check that the file is an image and the requested size is valid |
---|
404 | if ((empty($file->file)) || ($file->media_type != 'image') |
---|
405 | || !array_key_exists($size,$core->media->thumb_sizes)) |
---|
406 | { |
---|
407 | self::p404(); |
---|
408 | return; |
---|
409 | } |
---|
410 | |
---|
411 | if (isset($file->media_thumb[$size])) |
---|
412 | { |
---|
413 | # get the directory of the file and the filename of the thumbnail |
---|
414 | $file_path = dirname($file->file).'/'.basename($file->media_thumb[$size]); |
---|
415 | } else |
---|
416 | { |
---|
417 | $file_path = $file->file; |
---|
418 | } |
---|
419 | } |
---|
420 | else |
---|
421 | { |
---|
422 | self::p404(); |
---|
423 | return; |
---|
424 | } |
---|
425 | |
---|
426 | if ((!dlManager::inJail($file->relname)) || (!is_readable($file_path))) |
---|
427 | { |
---|
428 | self::p404(); |
---|
429 | return; |
---|
430 | } |
---|
431 | |
---|
432 | http::$cache_max_age = 36000; |
---|
433 | http::cache(array_merge(array($file_path),get_included_files())); |
---|
434 | header('Content-type: '.$file->type); |
---|
435 | header('Content-Length: '.filesize($file_path)); |
---|
436 | readfile($file_path); |
---|
437 | exit; |
---|
438 | } |
---|
439 | catch (Exception $e) |
---|
440 | { |
---|
441 | $_ctx->form_error = $e->getMessage(); |
---|
442 | } |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | $core->tpl->addValue('DLMCurrentDir',array('dlManagerPageTpl','currentDir')); |
---|
447 | |
---|
448 | # sort files |
---|
449 | $core->tpl->addBlock('DLMIfSortIsEnabled',array('dlManagerPageTpl', |
---|
450 | 'ifSortIsEnabled')); |
---|
451 | |
---|
452 | $core->tpl->addValue('DLMFileSortOptions',array('dlManagerPageTpl', |
---|
453 | 'fileSortOptions')); |
---|
454 | |
---|
455 | # Bread Crumb |
---|
456 | $core->tpl->addValue('DLMBaseURL',array('dlManagerPageTpl','baseURL')); |
---|
457 | |
---|
458 | $core->tpl->addBlock('DLMBreadCrumb',array('dlManagerPageTpl','breadCrumb')); |
---|
459 | $core->tpl->addValue('DLMBreadCrumbDirName',array('dlManagerPageTpl', |
---|
460 | 'breadCrumbDirName')); |
---|
461 | $core->tpl->addValue('DLMBreadCrumbDirURL',array('dlManagerPageTpl', |
---|
462 | 'breadCrumbDirURL')); |
---|
463 | |
---|
464 | # items |
---|
465 | $core->tpl->addBlock('DLMItems',array('dlManagerPageTpl','items')); |
---|
466 | |
---|
467 | $core->tpl->addBlock('DLMIfNoItem',array('dlManagerPageTpl','ifNoItem')); |
---|
468 | |
---|
469 | $core->tpl->addBlock('DLMIfPages',array('dlManagerPageTpl','ifPages')); |
---|
470 | |
---|
471 | # item |
---|
472 | $core->tpl->addBlock('DLMItemIf',array('dlManagerPageTpl','itemIf')); |
---|
473 | $core->tpl->addValue('DLMItemDirURL',array('dlManagerPageTpl','itemDirURL')); |
---|
474 | $core->tpl->addValue('DLMItemDirPath',array('dlManagerPageTpl','itemDirPath')); |
---|
475 | |
---|
476 | $core->tpl->addValue('DLMItemTitle',array('dlManagerPageTpl','itemTitle')); |
---|
477 | $core->tpl->addValue('DLMItemSize',array('dlManagerPageTpl','itemSize')); |
---|
478 | $core->tpl->addValue('DLMItemFileURL',array('dlManagerPageTpl','itemFileURL')); |
---|
479 | $core->tpl->addValue('DLMItemDlURL',array('dlManagerPageTpl','itemDlURL')); |
---|
480 | $core->tpl->addValue('DLMItemPlayerURL',array('dlManagerPageTpl','itemPlayerURL')); |
---|
481 | |
---|
482 | $core->tpl->addValue('DLMItemBasename',array('dlManagerPageTpl', |
---|
483 | 'itemBasename')); |
---|
484 | $core->tpl->addValue('DLMItemExtension',array('dlManagerPageTpl', |
---|
485 | 'itemExtension')); |
---|
486 | $core->tpl->addValue('DLMItemType',array('dlManagerPageTpl','itemType')); |
---|
487 | $core->tpl->addValue('DLMItemMediaType',array('dlManagerPageTpl', |
---|
488 | 'itemMediaType')); |
---|
489 | $core->tpl->addValue('DLMItemMTime',array('dlManagerPageTpl','itemMTime')); |
---|
490 | $core->tpl->addValue('DLMItemDlCount',array('dlManagerPageTpl','itemDlCount')); |
---|
491 | $core->tpl->addValue('DLMItemImageThumbPath',array('dlManagerPageTpl', |
---|
492 | 'itemImageThumbPath')); |
---|
493 | |
---|
494 | $core->tpl->addBlock('DLMIfDownloadCounter',array('dlManagerPageTpl','ifDownloadCounter')); |
---|
495 | |
---|
496 | # image meta |
---|
497 | $core->tpl->addBlock('DLMItemImageMeta',array('dlManagerPageTpl', |
---|
498 | 'itemImageMeta')); |
---|
499 | $core->tpl->addValue('DLMItemImageMetaName',array('dlManagerPageTpl', |
---|
500 | 'itemImageMetaName')); |
---|
501 | $core->tpl->addValue('DLMItemImageMetaValue',array('dlManagerPageTpl', |
---|
502 | 'itemImageMetaValue')); |
---|
503 | |
---|
504 | # zip content |
---|
505 | $core->tpl->addBlock('DLMItemZipContent',array('dlManagerPageTpl', |
---|
506 | 'itemZipContent')); |
---|
507 | $core->tpl->addValue('DLMItemZipContentFile',array('dlManagerPageTpl', |
---|
508 | 'itemZipContentFile')); |
---|
509 | |
---|
510 | # text file content |
---|
511 | $core->tpl->addValue('DLMItemFileContent',array('dlManagerPageTpl', |
---|
512 | 'itemFileContent')); |
---|
513 | |
---|
514 | # find entries containing a media |
---|
515 | $core->tpl->addBlock('DLMItemEntries',array('dlManagerPageTpl', |
---|
516 | 'itemEntries')); |
---|
517 | |
---|
518 | # |
---|
519 | $core->tpl->addValue('DLMPageLinks',array('dlManagerPageTpl', |
---|
520 | 'pageLinks')); |
---|
521 | |
---|
522 | if ($core->blog->settings->dlManager->dlmanager_attachment_url) |
---|
523 | { |
---|
524 | # redefine {{tpl:AttachmentURL}} |
---|
525 | $core->tpl->addValue('AttachmentURL',array('dlManagerPageTpl', |
---|
526 | 'AttachmentURL')); |
---|
527 | } |
---|
528 | |
---|
529 | /** |
---|
530 | @ingroup Download manager |
---|
531 | @brief Template |
---|
532 | */ |
---|
533 | class dlManagerPageTpl |
---|
534 | { |
---|
535 | /** |
---|
536 | display current directory |
---|
537 | @return <b>string</b> PHP block |
---|
538 | */ |
---|
539 | public static function currentDir() |
---|
540 | { |
---|
541 | return("<?php echo(\$_ctx->dlManager_currentDir); ?>"); |
---|
542 | } |
---|
543 | |
---|
544 | /** |
---|
545 | if sort is enabled |
---|
546 | @param attr <b>array</b> Attribute |
---|
547 | @param content <b>string</b> Content |
---|
548 | @return <b>string</b> PHP block |
---|
549 | */ |
---|
550 | public static function ifSortIsEnabled($attr,$content) |
---|
551 | { |
---|
552 | return |
---|
553 | '<?php if ($core->blog->settings->dlManager->dlmanager_enable_sort === true) : ?>'."\n". |
---|
554 | $content. |
---|
555 | '<?php endif; ?>'; |
---|
556 | } |
---|
557 | |
---|
558 | /** |
---|
559 | display file sort <select ...><option ...> |
---|
560 | @return <b>string</b> PHP block |
---|
561 | */ |
---|
562 | public static function fileSortOptions() |
---|
563 | { |
---|
564 | return('<?php echo form::combo(\'media_file_sort\', |
---|
565 | dlManager::getSortValues(),$_ctx->dlManager_fileSort); ?>'); |
---|
566 | } |
---|
567 | |
---|
568 | /** |
---|
569 | display base URL |
---|
570 | @param attr <b>array</b> Attribute |
---|
571 | @return <b>string</b> PHP block |
---|
572 | */ |
---|
573 | public static function baseURL($attr) |
---|
574 | { |
---|
575 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
576 | |
---|
577 | return('<?php echo('.sprintf($f,'dlManager::pageURL()').'); ?>'); |
---|
578 | } |
---|
579 | |
---|
580 | /** |
---|
581 | BreadCrumb |
---|
582 | @param attr <b>array</b> Attribute |
---|
583 | @param content <b>string</b> Content |
---|
584 | @return <b>string</b> PHP block |
---|
585 | */ |
---|
586 | public static function breadCrumb($attr,$content) |
---|
587 | { |
---|
588 | return('<?php while ($_ctx->dlManager_BreadCrumb->fetch()) : ?>'. |
---|
589 | $content. |
---|
590 | '<?php endwhile; ?>'); |
---|
591 | } |
---|
592 | |
---|
593 | /** |
---|
594 | display current directory |
---|
595 | @return <b>string</b> PHP block |
---|
596 | */ |
---|
597 | public static function breadCrumbDirURL($attr) |
---|
598 | { |
---|
599 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
600 | |
---|
601 | return('<?php echo('.sprintf($f,'$_ctx->dlManager_BreadCrumb->url').'); ?>'); |
---|
602 | } |
---|
603 | |
---|
604 | /** |
---|
605 | display current directory |
---|
606 | @return <b>string</b> PHP block |
---|
607 | */ |
---|
608 | public static function breadCrumbDirName($attr) |
---|
609 | { |
---|
610 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
611 | |
---|
612 | return('<?php echo('.sprintf($f,'$_ctx->dlManager_BreadCrumb->name').'); ?>'); |
---|
613 | } |
---|
614 | |
---|
615 | /** |
---|
616 | No item |
---|
617 | @param attr <b>array</b> Attribute |
---|
618 | @param content <b>string</b> Content |
---|
619 | @return <b>string</b> PHP block |
---|
620 | */ |
---|
621 | public static function ifNoItem($attr,$content) |
---|
622 | { |
---|
623 | $type = ($attr['type'] == 'dirs') ? 'dirs' : 'files'; |
---|
624 | |
---|
625 | return('<?php if ($_ctx->{\'dlManager_'.$type.'\'}->isEmpty()) : ?>'. |
---|
626 | $content. |
---|
627 | '<?php endif; ?>'); |
---|
628 | } |
---|
629 | |
---|
630 | /** |
---|
631 | If there is more than one page |
---|
632 | @param attr <b>array</b> Attribute |
---|
633 | @param content <b>string</b> Content |
---|
634 | @return <b>string</b> PHP block |
---|
635 | */ |
---|
636 | public static function ifPages($attr,$content) |
---|
637 | { |
---|
638 | return('<?php if ($_ctx->dlManager_multiple_pages) : ?>'. |
---|
639 | $content. |
---|
640 | '<?php endif; ?>'); |
---|
641 | } |
---|
642 | |
---|
643 | /** |
---|
644 | loop on items |
---|
645 | @param attr <b>array</b> Attribute |
---|
646 | @param content <b>string</b> Content |
---|
647 | @return <b>string</b> PHP block |
---|
648 | */ |
---|
649 | public static function items($attr,$content) |
---|
650 | { |
---|
651 | $type = (($attr['type'] == 'dirs') ? 'dirs' : 'files'); |
---|
652 | |
---|
653 | return |
---|
654 | '<?php '. |
---|
655 | '$_ctx->items = $_ctx->{\'dlManager_'.$type.'\'}; '. |
---|
656 | 'while ($_ctx->items->fetch()) : ?>'."\n". |
---|
657 | $content. |
---|
658 | '<?php endwhile; unset($_ctx->items); ?>'; |
---|
659 | } |
---|
660 | |
---|
661 | /** |
---|
662 | Item directory URL |
---|
663 | @param attr <b>array</b> Attribute |
---|
664 | @return <b>string</b> PHP block |
---|
665 | */ |
---|
666 | public static function itemDirURL($attr) |
---|
667 | { |
---|
668 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
669 | return('<?php echo '.sprintf($f,'$_ctx->items->dir_url').'; ?>'); |
---|
670 | } |
---|
671 | |
---|
672 | /** |
---|
673 | Item directory path |
---|
674 | @return <b>string</b> PHP block |
---|
675 | */ |
---|
676 | public static function itemDirPath() |
---|
677 | { |
---|
678 | global $core; |
---|
679 | return('<?php echo '. |
---|
680 | # empty can't be used with $_ctx->items->relname, use strlen() instead |
---|
681 | 'dlManager::pageURL().'.'((strlen($_ctx->items->relname) > 0) ?'. |
---|
682 | '\'/\'.$_ctx->items->relname : \'\'); ?>'); |
---|
683 | } |
---|
684 | |
---|
685 | /** |
---|
686 | Item if |
---|
687 | @param attr <b>array</b> Attribute |
---|
688 | @param content <b>string</b> Content |
---|
689 | @return <b>string</b> PHP block |
---|
690 | \see /dotclear/inc/public/class.dc.template.php > EntryIf() |
---|
691 | */ |
---|
692 | public static function itemIf($attr,$content) |
---|
693 | { |
---|
694 | $if = array(); |
---|
695 | $operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&'; |
---|
696 | |
---|
697 | if (isset($attr['type'])) { |
---|
698 | $type = trim($attr['type']); |
---|
699 | $sign = '='; |
---|
700 | if (substr($type,0,1) == '!') |
---|
701 | { |
---|
702 | $sign = '!'; |
---|
703 | $type = substr($type,1); |
---|
704 | } |
---|
705 | $types = explode(',',$type); |
---|
706 | foreach ($types as $type) |
---|
707 | { |
---|
708 | $if[] = '$_ctx->items->type '.$sign.'= "'.$type.'"'; |
---|
709 | } |
---|
710 | } |
---|
711 | |
---|
712 | if (isset($attr['media_type'])) { |
---|
713 | $type = trim($attr['media_type']); |
---|
714 | $sign = '='; |
---|
715 | if (substr($type,0,1) == '!') |
---|
716 | { |
---|
717 | $sign = '!'; |
---|
718 | $type = substr($type,1); |
---|
719 | } |
---|
720 | $types = explode(',',$type); |
---|
721 | foreach ($types as $type) |
---|
722 | { |
---|
723 | $if[] = '$_ctx->items->media_type '.$sign.'= "'.$type.'"'; |
---|
724 | } |
---|
725 | } |
---|
726 | |
---|
727 | if (!empty($if)) { |
---|
728 | return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'. |
---|
729 | $content. |
---|
730 | '<?php endif; ?>'; |
---|
731 | } else { |
---|
732 | return $content; |
---|
733 | } |
---|
734 | } |
---|
735 | |
---|
736 | /** |
---|
737 | Get operator |
---|
738 | @param op <b>string</b> Operator |
---|
739 | @return <b>string</b> Operator |
---|
740 | \see /dotclear/inc/public/class.dc.template.php > getOperator() |
---|
741 | */ |
---|
742 | protected static function getOperator($op) |
---|
743 | { |
---|
744 | switch (strtolower($op)) |
---|
745 | { |
---|
746 | case 'or': |
---|
747 | case '||': |
---|
748 | return '||'; |
---|
749 | case 'and': |
---|
750 | case '&&': |
---|
751 | default: |
---|
752 | return '&&'; |
---|
753 | } |
---|
754 | } |
---|
755 | |
---|
756 | /** |
---|
757 | Item title |
---|
758 | @param attr <b>array</b> Attribute |
---|
759 | @param content <b>string</b> Content |
---|
760 | @return <b>string</b> PHP block |
---|
761 | */ |
---|
762 | public static function itemTitle($attr) |
---|
763 | { |
---|
764 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
765 | |
---|
766 | return('<?php echo '.sprintf($f,'$_ctx->items->media_title').'; ?>'); |
---|
767 | } |
---|
768 | |
---|
769 | /** |
---|
770 | Item size |
---|
771 | @param attr <b>array</b> Attribute |
---|
772 | @return <b>string</b> PHP block |
---|
773 | */ |
---|
774 | public static function itemSize($attr) |
---|
775 | { |
---|
776 | $format_open = $format_close = ''; |
---|
777 | if (isset($attr['format']) && $attr['format'] == '1') |
---|
778 | { |
---|
779 | $format_open = 'files::size('; |
---|
780 | $format_close = ')'; |
---|
781 | } |
---|
782 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
783 | |
---|
784 | return('<?php echo '.sprintf($f, |
---|
785 | $format_open.'$_ctx->items->size'.$format_close).'; ?>'); |
---|
786 | } |
---|
787 | |
---|
788 | /** |
---|
789 | Item file URL |
---|
790 | @param attr <b>array</b> Attribute |
---|
791 | @return <b>string</b> PHP block |
---|
792 | */ |
---|
793 | public static function itemFileURL($attr) |
---|
794 | { |
---|
795 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
796 | |
---|
797 | if ($GLOBALS['core']->blog->settings->dlManager->dlmanager_hide_urls) |
---|
798 | { |
---|
799 | return('<?php echo($core->blog->url.'. |
---|
800 | '$core->url->getBase(\'viewfile\').\'/\'.'. |
---|
801 | sprintf($f,'$_ctx->items->media_id').'); ?>'); |
---|
802 | } |
---|
803 | return('<?php echo '.sprintf($f,'$_ctx->items->file_url').'; ?>'); |
---|
804 | } |
---|
805 | |
---|
806 | /** |
---|
807 | Item download URL |
---|
808 | @param attr <b>array</b> Attribute |
---|
809 | @return <b>string</b> PHP block |
---|
810 | */ |
---|
811 | public static function itemDlURL($attr) |
---|
812 | { |
---|
813 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
814 | |
---|
815 | return('<?php echo($core->blog->url.$core->url->getBase(\'download\').'. |
---|
816 | '\'/\'.'.sprintf($f,'$_ctx->items->media_id').'); ?>'); |
---|
817 | } |
---|
818 | |
---|
819 | /** |
---|
820 | Item player URL |
---|
821 | @param attr <b>array</b> Attribute |
---|
822 | @return <b>string</b> PHP block |
---|
823 | */ |
---|
824 | public static function itemPlayerURL($attr) |
---|
825 | { |
---|
826 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
827 | |
---|
828 | return('<?php echo($core->blog->url.$core->url->getBase(\'mediaplayer\').'. |
---|
829 | '\'/\'.'.sprintf($f,'$_ctx->items->media_id').'); ?>'); |
---|
830 | } |
---|
831 | |
---|
832 | /** |
---|
833 | Item basename |
---|
834 | @param attr <b>array</b> Attribute |
---|
835 | @return <b>string</b> PHP block |
---|
836 | */ |
---|
837 | public static function itemBasename($attr) |
---|
838 | { |
---|
839 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
840 | |
---|
841 | return('<?php echo '.sprintf($f,'$_ctx->items->basename').'; ?>'); |
---|
842 | } |
---|
843 | |
---|
844 | /** |
---|
845 | Item extension |
---|
846 | @param attr <b>array</b> Attribute |
---|
847 | @return <b>string</b> PHP block |
---|
848 | */ |
---|
849 | public static function itemExtension($attr) |
---|
850 | { |
---|
851 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
852 | |
---|
853 | return('<?php echo '.sprintf($f,'$_ctx->items->extension').'; ?>'); |
---|
854 | } |
---|
855 | |
---|
856 | /** |
---|
857 | Item type : text/plain |
---|
858 | @param attr <b>array</b> Attribute |
---|
859 | @return <b>string</b> PHP block |
---|
860 | */ |
---|
861 | public static function itemType($attr) |
---|
862 | { |
---|
863 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
864 | |
---|
865 | return('<?php echo '.sprintf($f,'$_ctx->items->type').'; ?>'); |
---|
866 | } |
---|
867 | |
---|
868 | /** |
---|
869 | Item media type : text |
---|
870 | @param attr <b>array</b> Attribute |
---|
871 | @return <b>string</b> PHP block |
---|
872 | */ |
---|
873 | public static function itemMediaType($attr) |
---|
874 | { |
---|
875 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
876 | |
---|
877 | return('<?php echo '.sprintf($f,'$_ctx->items->media_type').'; ?>'); |
---|
878 | } |
---|
879 | |
---|
880 | /** |
---|
881 | Item mtime |
---|
882 | @param attr <b>array</b> Attribute |
---|
883 | @return <b>string</b> PHP block |
---|
884 | */ |
---|
885 | public static function itemMTime($attr) |
---|
886 | { |
---|
887 | global $core; |
---|
888 | |
---|
889 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
890 | |
---|
891 | $str = '$_ctx->items->media_dtstr'; |
---|
892 | |
---|
893 | if (isset($attr['format'])) |
---|
894 | { |
---|
895 | if ($attr['format'] == 'date_format') |
---|
896 | { |
---|
897 | $format = $GLOBALS['core']->blog->settings->system->date_format; |
---|
898 | } |
---|
899 | elseif ($attr['format'] == 'time_format') |
---|
900 | { |
---|
901 | $format = $GLOBALS['core']->blog->settings->system->time_format; |
---|
902 | } |
---|
903 | else |
---|
904 | { |
---|
905 | $format = $attr['format']; |
---|
906 | } |
---|
907 | |
---|
908 | $str = 'dt::dt2str(\''.$format.'\','.$str.')'; |
---|
909 | } |
---|
910 | |
---|
911 | return('<?php echo '.sprintf($f,$str).'; ?>'); |
---|
912 | } |
---|
913 | |
---|
914 | /** |
---|
915 | Item download counter |
---|
916 | @param attr <b>array</b> Attribute |
---|
917 | @return <b>string</b> PHP block |
---|
918 | */ |
---|
919 | public static function itemDlCount() |
---|
920 | { |
---|
921 | return('<?php echo $_ctx->items->count_dl; ?>'); |
---|
922 | } |
---|
923 | |
---|
924 | /** |
---|
925 | Test if the download counter is active |
---|
926 | @param attr <b>array</b> Attribute |
---|
927 | @param content <b>string</b> Content of the loop |
---|
928 | @return <b>string</b> PHP block |
---|
929 | */ |
---|
930 | public static function ifDownloadCounter($attr,$content) |
---|
931 | { |
---|
932 | return('<?php if ($core->blog->settings->dlManager->dlmanager_counter) : ?>'. |
---|
933 | $content. |
---|
934 | '<?php endif; ?>'); |
---|
935 | } |
---|
936 | |
---|
937 | /** |
---|
938 | Item image thumbnail |
---|
939 | @param attr <b>array</b> Attribute |
---|
940 | @return <b>string</b> PHP block |
---|
941 | */ |
---|
942 | public static function itemImageThumbPath($attr) |
---|
943 | { |
---|
944 | global $core; |
---|
945 | |
---|
946 | $size = 'sq'; |
---|
947 | |
---|
948 | if ((isset($attr['size'])) |
---|
949 | && array_key_exists($attr['size'],$core->media->thumb_sizes)) |
---|
950 | {$size = $attr['size'];} |
---|
951 | |
---|
952 | if ($GLOBALS['core']->blog->settings->dlManager->dlmanager_hide_urls) |
---|
953 | { |
---|
954 | return('<?php '. |
---|
955 | 'echo($core->blog->url.$core->url->getBase(\'viewfile\').\'/\'.'. |
---|
956 | '$_ctx->items->media_id.\'/'.$size.'\'); ?>'); |
---|
957 | } |
---|
958 | return('<?php if (isset($_ctx->items->media_thumb[\''.$size.'\'])) :'. |
---|
959 | 'echo($_ctx->items->media_thumb[\''.$size.'\']);'. |
---|
960 | 'else :'. |
---|
961 | 'echo($_ctx->items->file_url);'. |
---|
962 | 'endif; ?>'); |
---|
963 | } |
---|
964 | |
---|
965 | /** |
---|
966 | Loop on image meta |
---|
967 | @param attr <b>array</b> Attribute |
---|
968 | @param content <b>string</b> Content of the loop |
---|
969 | @return <b>string</b> PHP block |
---|
970 | */ |
---|
971 | public static function itemImageMeta($attr,$content) |
---|
972 | { |
---|
973 | return |
---|
974 | '<?php '. |
---|
975 | '$_ctx->imagemeta = dlManager::getImageMeta($_ctx->items); '. |
---|
976 | 'while ($_ctx->imagemeta->fetch()) : ?>'."\n". |
---|
977 | $content. |
---|
978 | '<?php endwhile; unset($_ctx->imagemeta); ?>'; |
---|
979 | } |
---|
980 | |
---|
981 | /** |
---|
982 | Image meta name |
---|
983 | @param attr <b>array</b> Attribute |
---|
984 | @return <b>string</b> PHP block |
---|
985 | */ |
---|
986 | public static function itemImageMetaName($attr) |
---|
987 | { |
---|
988 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
989 | |
---|
990 | return('<?php echo '.sprintf($f,'$_ctx->imagemeta->name').'; ?>'); |
---|
991 | } |
---|
992 | |
---|
993 | /** |
---|
994 | Image meta value |
---|
995 | @param attr <b>array</b> Attribute |
---|
996 | @return <b>string</b> PHP block |
---|
997 | */ |
---|
998 | public static function itemImageMetaValue($attr) |
---|
999 | { |
---|
1000 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
1001 | |
---|
1002 | return('<?php echo '.sprintf($f,'$_ctx->imagemeta->value').'; ?>'); |
---|
1003 | } |
---|
1004 | |
---|
1005 | /** |
---|
1006 | Loop on zip content |
---|
1007 | @param attr <b>array</b> Attribute |
---|
1008 | @return <b>string</b> PHP block |
---|
1009 | */ |
---|
1010 | public static function itemZipContent($attr,$content) |
---|
1011 | { |
---|
1012 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
1013 | |
---|
1014 | return |
---|
1015 | '<?php '. |
---|
1016 | '$_ctx->files = dlManager::getZipContent($_ctx->items); '. |
---|
1017 | 'while ($_ctx->files->fetch()) : ?>'."\n". |
---|
1018 | $content. |
---|
1019 | '<?php endwhile; unset($_ctx->files); ?>'; |
---|
1020 | } |
---|
1021 | |
---|
1022 | /** |
---|
1023 | Zip content file |
---|
1024 | @param attr <b>array</b> Attribute |
---|
1025 | @return <b>string</b> PHP block |
---|
1026 | */ |
---|
1027 | public static function itemZipContentFile($attr) |
---|
1028 | { |
---|
1029 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
1030 | |
---|
1031 | return('<?php echo '.sprintf($f,'$_ctx->files->file').'; ?>'); |
---|
1032 | } |
---|
1033 | |
---|
1034 | /** |
---|
1035 | Text file content |
---|
1036 | @return <b>string</b> PHP block |
---|
1037 | */ |
---|
1038 | public static function itemFileContent($attr) |
---|
1039 | { |
---|
1040 | return('<?php if ((is_readable($_ctx->items->file)) '. |
---|
1041 | '&& ($_ctx->items->size < 1000000)) : '. |
---|
1042 | 'echo html::escapeHTML(file_get_contents($_ctx->items->file));'. |
---|
1043 | 'endif; ?>'); |
---|
1044 | } |
---|
1045 | |
---|
1046 | /** |
---|
1047 | loop on posts which contain this item |
---|
1048 | @param attr <b>array</b> Attribute |
---|
1049 | @param content <b>string</b> Content |
---|
1050 | @return <b>string</b> PHP block |
---|
1051 | */ |
---|
1052 | public static function itemEntries($attr,$content) |
---|
1053 | { |
---|
1054 | return("<?php ". |
---|
1055 | '$_ctx->posts = dlManager::findPosts($_ctx->items->media_id);'. |
---|
1056 | "while (\$_ctx->posts->fetch()) : ?>"."\n". |
---|
1057 | $content. |
---|
1058 | "<?php endwhile; unset(\$_ctx->posts); ?>"); |
---|
1059 | } |
---|
1060 | |
---|
1061 | /** |
---|
1062 | redefine {{tpl:AttachmentURL}} to point to download/id |
---|
1063 | @param attr <b>array</b> Attribute |
---|
1064 | @return <b>string</b> PHP block |
---|
1065 | */ |
---|
1066 | public static function AttachmentURL($attr) |
---|
1067 | { |
---|
1068 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
1069 | |
---|
1070 | return('<?php echo($core->blog->url.$core->url->getBase(\'download\').'. |
---|
1071 | '\'/\'.'.sprintf($f,'$attach_f->media_id').'); ?>'); |
---|
1072 | } |
---|
1073 | |
---|
1074 | /** |
---|
1075 | get page links |
---|
1076 | @return <b>string</b> PHP block |
---|
1077 | */ |
---|
1078 | public static function pageLinks() |
---|
1079 | { |
---|
1080 | return('<?php echo($_ctx->dlManager_pager->getLinks()); ?>'); |
---|
1081 | } |
---|
1082 | } |
---|