Dotclear

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

Revision 3321, 27.0 KB checked in by Moe, 9 years ago (diff)

DL Manager 1.1.7 : Mise à jour par brol

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

Sites map