Dotclear

source: plugins/dlManager/trunk/_public.php @ 3316

Revision 3316, 26.2 KB checked in by Moe, 9 years ago (diff)

Prise en compte des *nouveaux* paramètres et suppression des ?>

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

Sites map