Dotclear

source: inc/public/class.dc.template.php @ 1122:a3930c0388b2

Revision 1122:a3930c0388b2, 92.3 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Add LoopIndex? template tag (return current loop index, 1 to n, and return 0 if no current loop).

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcTemplate extends template
15{
16     private $core;
17     private $current_tag;
18     
19     protected $unknown_value_handler = null;
20     protected $unknown_block_handler = null;
21     
22     function __construct($cache_dir,$self_name,$core)
23     {
24          parent::__construct($cache_dir,$self_name);
25         
26          $this->remove_php = !$core->blog->settings->system->tpl_allow_php;
27          $this->use_cache = $core->blog->settings->system->tpl_use_cache;
28         
29          $this->tag_block = '<tpl:(\w+)(?:(\s+.*?)>|>)((?:[^<]|<(?!/?tpl:\1)|(?R))*)</tpl:\1>';
30          $this->tag_value = '{{tpl:(\w+)(\s(.*?))?}}';
31         
32          $this->core =& $core;
33         
34          # Transitional tags
35          $this->addValue('EntryTrackbackCount',array($this,'EntryPingCount'));
36          $this->addValue('EntryTrackbackData',array($this,'EntryPingData'));
37          $this->addValue('EntryTrackbackLink',array($this,'EntryPingLink'));
38         
39          # l10n
40          $this->addValue('lang',array($this,'l10n'));
41         
42          # Loops test tags
43          $this->addBlock('LoopPosition',array($this,'LoopPosition'));
44          $this->addValue('LoopIndex',array($this,'LoopIndex'));
45         
46          # Archives
47          $this->addBlock('Archives',array($this,'Archives'));
48          $this->addBlock('ArchivesHeader',array($this,'ArchivesHeader'));
49          $this->addBlock('ArchivesFooter',array($this,'ArchivesFooter'));
50          $this->addBlock('ArchivesYearHeader',array($this,'ArchivesYearHeader'));
51          $this->addBlock('ArchivesYearFooter',array($this,'ArchivesYearFooter'));
52          $this->addValue('ArchiveDate',array($this,'ArchiveDate'));
53          $this->addBlock('ArchiveNext',array($this,'ArchiveNext'));
54          $this->addBlock('ArchivePrevious',array($this,'ArchivePrevious'));
55          $this->addValue('ArchiveEntriesCount',array($this,'ArchiveEntriesCount'));
56          $this->addValue('ArchiveURL',array($this,'ArchiveURL'));
57         
58          # Blog
59          $this->addValue('BlogArchiveURL',array($this,'BlogArchiveURL'));
60          $this->addValue('BlogCopyrightNotice',array($this,'BlogCopyrightNotice'));
61          $this->addValue('BlogDescription',array($this,'BlogDescription'));
62          $this->addValue('BlogEditor',array($this,'BlogEditor'));
63          $this->addValue('BlogFeedID',array($this,'BlogFeedID'));
64          $this->addValue('BlogFeedURL',array($this,'BlogFeedURL'));
65          $this->addValue('BlogRSDURL',array($this,'BlogRSDURL'));
66          $this->addValue('BlogName',array($this,'BlogName'));
67          $this->addValue('BlogLanguage',array($this,'BlogLanguage'));
68          $this->addValue('BlogThemeURL',array($this,'BlogThemeURL'));
69          $this->addValue('BlogUpdateDate',array($this,'BlogUpdateDate'));
70          $this->addValue('BlogID',array($this,'BlogID'));
71          $this->addValue('BlogURL',array($this,'BlogURL'));
72          $this->addValue('BlogPublicURL',array($this,'BlogPublicURL'));
73          $this->addValue('BlogQmarkURL',array($this,'BlogQmarkURL'));
74          $this->addValue('BlogMetaRobots',array($this,'BlogMetaRobots'));
75         
76          # Categories
77          $this->addBlock('Categories',array($this,'Categories'));
78          $this->addBlock('CategoriesHeader',array($this,'CategoriesHeader'));
79          $this->addBlock('CategoriesFooter',array($this,'CategoriesFooter'));
80          $this->addBlock('CategoryIf',array($this,'CategoryIf'));
81          $this->addBlock('CategoryFirstChildren',array($this,'CategoryFirstChildren'));
82          $this->addBlock('CategoryParents',array($this,'CategoryParents'));
83          $this->addValue('CategoryFeedURL',array($this,'CategoryFeedURL'));
84          $this->addValue('CategoryURL',array($this,'CategoryURL'));
85          $this->addValue('CategoryShortURL',array($this,'CategoryShortURL'));
86          $this->addValue('CategoryDescription',array($this,'CategoryDescription'));
87          $this->addValue('CategoryTitle',array($this,'CategoryTitle'));
88          $this->addValue('CategoryEntriesCount',array($this,'CategoryEntriesCount'));
89         
90          # Comments
91          $this->addBlock('Comments',array($this,'Comments'));
92          $this->addValue('CommentAuthor',array($this,'CommentAuthor'));
93          $this->addValue('CommentAuthorDomain',array($this,'CommentAuthorDomain'));
94          $this->addValue('CommentAuthorLink',array($this,'CommentAuthorLink'));
95          $this->addValue('CommentAuthorMailMD5',array($this,'CommentAuthorMailMD5'));
96          $this->addValue('CommentAuthorURL',array($this,'CommentAuthorURL'));
97          $this->addValue('CommentContent',array($this,'CommentContent'));
98          $this->addValue('CommentDate',array($this,'CommentDate'));
99          $this->addValue('CommentTime',array($this,'CommentTime'));
100          $this->addValue('CommentEmail',array($this,'CommentEmail'));
101          $this->addValue('CommentEntryTitle',array($this,'CommentEntryTitle'));
102          $this->addValue('CommentFeedID',array($this,'CommentFeedID'));
103          $this->addValue('CommentID',array($this,'CommentID'));
104          $this->addBlock('CommentIf',array($this,'CommentIf'));
105          $this->addValue('CommentIfFirst',array($this,'CommentIfFirst'));
106          $this->addValue('CommentIfMe',array($this,'CommentIfMe'));
107          $this->addValue('CommentIfOdd',array($this,'CommentIfOdd'));
108          $this->addValue('CommentIP',array($this,'CommentIP'));
109          $this->addValue('CommentOrderNumber',array($this,'CommentOrderNumber'));
110          $this->addBlock('CommentsFooter',array($this,'CommentsFooter'));
111          $this->addBlock('CommentsHeader',array($this,'CommentsHeader'));
112          $this->addValue('CommentPostURL',array($this,'CommentPostURL'));
113          $this->addBlock('IfCommentAuthorEmail',array($this,'IfCommentAuthorEmail'));
114          $this->addValue('CommentHelp',array($this,'CommentHelp'));
115         
116          # Comment preview
117          $this->addBlock('IfCommentPreview',array($this,'IfCommentPreview'));
118          $this->addValue('CommentPreviewName',array($this,'CommentPreviewName'));
119          $this->addValue('CommentPreviewEmail',array($this,'CommentPreviewEmail'));
120          $this->addValue('CommentPreviewSite',array($this,'CommentPreviewSite'));
121          $this->addValue('CommentPreviewContent',array($this,'CommentPreviewContent'));
122          $this->addValue('CommentPreviewCheckRemember',array($this,'CommentPreviewCheckRemember'));
123         
124          # Entries
125          $this->addBlock('DateFooter',array($this,'DateFooter'));
126          $this->addBlock('DateHeader',array($this,'DateHeader'));
127          $this->addBlock('Entries',array($this,'Entries'));
128          $this->addBlock('EntriesFooter',array($this,'EntriesFooter'));
129          $this->addBlock('EntriesHeader',array($this,'EntriesHeader'));
130          $this->addValue('EntryExcerpt',array($this,'EntryExcerpt'));
131          $this->addValue('EntryAuthorCommonName',array($this,'EntryAuthorCommonName'));
132          $this->addValue('EntryAuthorDisplayName',array($this,'EntryAuthorDisplayName'));
133          $this->addValue('EntryAuthorEmail',array($this,'EntryAuthorEmail'));
134          $this->addValue('EntryAuthorID',array($this,'EntryAuthorID'));
135          $this->addValue('EntryAuthorLink',array($this,'EntryAuthorLink'));
136          $this->addValue('EntryAuthorURL',array($this,'EntryAuthorURL'));
137          $this->addValue('EntryBasename',array($this,'EntryBasename'));
138          $this->addValue('EntryCategory',array($this,'EntryCategory'));
139          $this->addBlock('EntryCategoriesBreadcrumb',array($this,'EntryCategoriesBreadcrumb'));
140          $this->addValue('EntryCategoryID',array($this,'EntryCategoryID'));
141          $this->addValue('EntryCategoryURL',array($this,'EntryCategoryURL'));
142          $this->addValue('EntryCategoryShortURL',array($this,'EntryCategoryShortURL'));
143          $this->addValue('EntryCommentCount',array($this,'EntryCommentCount'));
144          $this->addValue('EntryContent',array($this,'EntryContent'));
145          $this->addValue('EntryDate',array($this,'EntryDate'));
146          $this->addValue('EntryFeedID',array($this,'EntryFeedID'));
147          $this->addValue('EntryFirstImage',array($this,'EntryFirstImage'));
148          $this->addValue('EntryID',array($this,'EntryID'));
149          $this->addBlock('EntryIf',array($this,'EntryIf'));
150          $this->addValue('EntryIfFirst',array($this,'EntryIfFirst'));
151          $this->addValue('EntryIfOdd',array($this,'EntryIfOdd'));
152          $this->addValue('EntryIfSelected',array($this,'EntryIfSelected'));
153          $this->addValue('EntryLang',array($this,'EntryLang'));
154          $this->addBlock('EntryNext',array($this,'EntryNext'));
155          $this->addValue('EntryPingCount',array($this,'EntryPingCount'));
156          $this->addValue('EntryPingData',array($this,'EntryPingData'));
157          $this->addValue('EntryPingLink',array($this,'EntryPingLink'));
158          $this->addBlock('EntryPrevious',array($this,'EntryPrevious'));
159          $this->addValue('EntryTitle',array($this,'EntryTitle'));
160          $this->addValue('EntryTime',array($this,'EntryTime'));
161          $this->addValue('EntryURL',array($this,'EntryURL'));
162         
163          # Languages
164          $this->addBlock('Languages',array($this,'Languages'));
165          $this->addBlock('LanguagesHeader',array($this,'LanguagesHeader'));
166          $this->addBlock('LanguagesFooter',array($this,'LanguagesFooter'));
167          $this->addValue('LanguageCode',array($this,'LanguageCode'));
168          $this->addBlock('LanguageIfCurrent',array($this,'LanguageIfCurrent'));
169          $this->addValue('LanguageURL',array($this,'LanguageURL'));
170         
171          # Pagination
172          $this->addBlock('Pagination',array($this,'Pagination'));
173          $this->addValue('PaginationCounter',array($this,'PaginationCounter'));
174          $this->addValue('PaginationCurrent',array($this,'PaginationCurrent'));
175          $this->addBlock('PaginationIf',array($this,'PaginationIf'));
176          $this->addValue('PaginationURL',array($this,'PaginationURL'));
177         
178          # Trackbacks
179          $this->addValue('PingBlogName',array($this,'PingBlogName'));
180          $this->addValue('PingContent',array($this,'PingContent'));
181          $this->addValue('PingDate',array($this,'PingDate'));
182          $this->addValue('PingEntryTitle',array($this,'PingEntryTitle'));
183          $this->addValue('PingFeedID',array($this,'PingFeedID'));
184          $this->addValue('PingID',array($this,'PingID'));
185          $this->addValue('PingIfFirst',array($this,'PingIfFirst'));
186          $this->addValue('PingIfOdd',array($this,'PingIfOdd'));
187          $this->addValue('PingIP',array($this,'PingIP'));
188          $this->addValue('PingNoFollow',array($this,'PingNoFollow'));
189          $this->addValue('PingOrderNumber',array($this,'PingOrderNumber'));
190          $this->addValue('PingPostURL',array($this,'PingPostURL'));
191          $this->addBlock('Pings',array($this,'Pings'));
192          $this->addBlock('PingsFooter',array($this,'PingsFooter'));
193          $this->addBlock('PingsHeader',array($this,'PingsHeader'));
194          $this->addValue('PingTime',array($this,'PingTime'));
195          $this->addValue('PingTitle',array($this,'PingTitle'));
196          $this->addValue('PingAuthorURL',array($this,'PingAuthorURL'));
197         
198          # System
199          $this->addValue('SysBehavior',array($this,'SysBehavior'));
200          $this->addBlock('SysIf',array($this,'SysIf'));
201          $this->addBlock('SysIfCommentPublished',array($this,'SysIfCommentPublished'));
202          $this->addBlock('SysIfCommentPending',array($this,'SysIfCommentPending'));
203          $this->addBlock('SysIfFormError',array($this,'SysIfFormError'));
204          $this->addValue('SysFeedSubtitle',array($this,'SysFeedSubtitle'));
205          $this->addValue('SysFormError',array($this,'SysFormError'));
206          $this->addValue('SysPoweredBy',array($this,'SysPoweredBy'));
207          $this->addValue('SysSearchString',array($this,'SysSearchString'));
208          $this->addValue('SysSelfURI',array($this,'SysSelfURI'));
209
210          # Generic
211          $this->addValue('else',array($this,'GenericElse'));
212     }
213     
214     public function getData($________)
215     {
216          # --BEHAVIOR-- tplBeforeData
217          if ($this->core->hasBehavior('tplBeforeData'))
218          {
219               self::$_r = $this->core->callBehavior('tplBeforeData',$this->core);
220               if (self::$_r) {
221                    return self::$_r;
222               }
223          }
224         
225          parent::getData($________);
226         
227          # --BEHAVIOR-- tplAfterData
228          if ($this->core->hasBehavior('tplAfterData')) {
229               $this->core->callBehavior('tplAfterData',$this->core,self::$_r);
230          }
231         
232          return self::$_r;
233     }
234     
235     protected function compileFile($file)
236     {
237          $fc = file_get_contents($file);
238         
239          $this->compile_stack[] = $file;
240         
241          # Remove every PHP tags
242          if ($this->remove_php)
243          {
244               $fc = preg_replace('/<\?(?=php|=|\s).*?\?>/ms','',$fc);
245          }
246         
247          # Transform what could be considered as PHP short tags
248          $fc = preg_replace('/(<\?(?!php|=|\s))(.*?)(\?>)/ms',
249          '<?php echo "$1"; ?>$2<?php echo "$3"; ?>',$fc);
250         
251          # Remove template comments <!-- #... -->
252          $fc = preg_replace('/(^\s*)?<!-- #(.*?)-->/ms','',$fc);
253         
254          # Lexer part : split file into small pieces
255          # each array entry will be either a tag or plain text
256          $blocks = preg_split(
257               '#(<tpl:\w+[^>]*>)|(</tpl:\w+>)|({{tpl:\w+[^}]*}})#msu',$fc,-1,
258               PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
259         
260          # Next : build semantic tree from tokens.
261          $rootNode = new tplNode();
262          $node = $rootNode;
263          $errors = array();
264          foreach ($blocks as $id => $block) {
265               $isblock = preg_match('#<tpl:(\w+)(?:(\s+.*?)>|>)|</tpl:(\w+)>|{{tpl:(\w+)(\s(.*?))?}}#ms',$block,$match);
266               if ($isblock == 1) {
267                    if (substr($match[0],1,1) == '/') {
268                         // Closing tag, check if it matches current opened node
269                         $tag = $match[3];
270                         if (($node instanceof tplNodeBlock) && $node->getTag() == $tag) {
271                              $node->setClosing();
272                              $node = $node->getParent();
273                         } else {
274                              // Closing tag does not match opening tag
275                              // Search if it closes a parent tag
276                              $search = $node;
277                              while($search->getTag() != 'ROOT' && $search->getTag() != $tag) {
278                                   $search = $search->getParent();
279                              }
280                              if ($search->getTag() == $tag) {
281                                   $errors[] = sprintf(
282                                        __('Did not find closing tag for block <tpl:%s>. Content has been ignored.'),
283                                        html::escapeHTML($node->getTag()));
284                                   $search->setClosing();
285                                   $node = $search->getParent();
286                              } else {
287                                   $errors[]=sprintf(
288                                        __('Unexpected closing tag </tpl:%s> found.'),
289                                        $tag);;
290                              }
291                         }
292                    } elseif (substr($match[0],0,1) == '{') {
293                         // Value tag
294                         $tag = $match[4];
295                         $str_attr = '';
296                         $attr = array();
297                         if (isset($match[6])) {
298                              $str_attr = $match[6];
299                              $attr = $this->getAttrs($match[6]);
300                         }
301                         $node->addChild(new tplNodeValue($tag,$attr,$str_attr));
302                    } else {
303                         // Opening tag, create new node and dive into it
304                         $tag = $match[1];
305                         $newnode = new tplNodeBlock($tag,isset($match[2])?$this->getAttrs($match[2]):array());
306                         $node->addChild($newnode);
307                         $node = $newnode;
308                    }
309               } else {
310                    // Simple text
311                    $node->addChild(new tplNodeText($block));
312               }
313          }
314         
315          if (($node instanceof tplNodeBlock) && !$node->isClosed()) {
316               $errors[] = sprintf(
317                    __('Did not find closing tag for block <tpl:%s>. Content has been ignored.'),
318                    html::escapeHTML($node->getTag()));
319          }
320         
321          $err = "";
322          if (count($errors) > 0) {
323               $err = "\n\n<!-- \n".
324                    __('WARNING: the following errors have been found while parsing template file :').
325                    "\n * ".
326                    join("\n * ",$errors).
327                    "\n -->\n";
328          }
329         
330          return $rootNode->compile($this).$err;
331     }
332   
333     public function compileBlockNode($tag,$attr,$content)
334     {
335          $this->current_tag = $tag;
336          $attr = new ArrayObject($attr);
337          # --BEHAVIOR-- templateBeforeBlock
338          $res = $this->core->callBehavior('templateBeforeBlock',$this->core,$this->current_tag,$attr);
339         
340          # --BEHAVIOR-- templateInsideBlock
341          $this->core->callBehavior('templateInsideBlock',$this->core,$this->current_tag,$attr,array(&$content));
342         
343          if (isset($this->blocks[$this->current_tag])) {
344               $res .= call_user_func($this->blocks[$this->current_tag],$attr,$content);
345          } elseif ($this->unknown_block_handler != null) {
346               $res .= call_user_func($this->unknown_block_handler,$this->current_tag,$attr,$content);
347          }
348         
349          # --BEHAVIOR-- templateAfterBlock
350          $res .= $this->core->callBehavior('templateAfterBlock',$this->core,$this->current_tag,$attr);
351         
352          return $res;
353     }
354     
355     public function compileValueNode($tag,$attr,$str_attr)
356     {
357          $this->current_tag = $tag;
358         
359          $attr = new ArrayObject($attr);
360          # --BEHAVIOR-- templateBeforeValue
361          $res = $this->core->callBehavior('templateBeforeValue',$this->core,$this->current_tag,$attr);
362         
363          if (isset($this->values[$this->current_tag])) {
364               $res .= call_user_func($this->values[$this->current_tag],$attr,ltrim($str_attr));
365          } elseif ($this->unknown_value_handler != null) {
366               $res .= call_user_func($this->unknown_value_handler,$this->current_tag,$attr,$str_attr);
367          }
368       
369          # --BEHAVIOR-- templateAfterValue
370          $res .= $this->core->callBehavior('templateAfterValue',$this->core,$this->current_tag,$attr);
371         
372          return $res;
373     }
374   
375     public function setUnknownValueHandler($callback)
376     {
377          if (is_callable($callback)) {
378               $this->unknown_value_handler = $callback;
379          }
380     }
381   
382     public function setUnknownBlockHandler($callback)
383     {
384          if (is_callable($callback)) {
385               $this->unknown_block_handler = $callback;
386          }
387     }
388   
389     public function getFilters($attr)
390     {
391          $p[0] = '0';   # encode_xml
392          $p[1] = '0';   # remove_html
393          $p[2] = '0';   # cut_string
394          $p[3] = '0';   # lower_case
395          $p[4] = '0';   # upper_case or capitalize
396         
397          $p[0] = (integer) (!empty($attr['encode_xml']) || !empty($attr['encode_html']));
398          $p[1] = (integer) !empty($attr['remove_html']);
399         
400          if (!empty($attr['cut_string']) && (integer) $attr['cut_string'] > 0) {
401               $p[2] = (integer) $attr['cut_string'];
402          }
403         
404          $p[3] = (integer) !empty($attr['lower_case']);
405          $p[4] = (integer) !empty($attr['upper_case']);
406          $p[4] = (!empty($attr['capitalize']) ? 2 : $p[4]);
407         
408          return "context::global_filter(%s,".implode(",",$p).",'".addslashes($this->current_tag)."')";
409     }
410     
411     public static function getOperator($op)
412     {
413          switch (strtolower($op))
414          {
415               case 'or':
416               case '||':
417                    return '||';
418               case 'and':
419               case '&&':
420               default:
421                    return '&&';
422          }
423     }
424     
425     public function getSortByStr($attr,$table = null)
426     {
427          $res = array();
428         
429          $default_order = 'desc';
430         
431          $default_alias = array(
432               'post' => array(
433                    'title' => 'post_title',
434                    'selected' => 'post_selected',
435                    'author' => 'user_id',
436                    'date' => 'post_dt',
437                    'id' => 'post_id',
438                    'comment' => 'nb_comment',
439                    'trackback' => 'nb_trackback'
440               ),
441               'comment' => array(
442                    'author' => 'comment_author',
443                    'date' => 'comment_dt',
444                    'id' => 'comment_id'
445               )
446          );
447         
448          $alias = new ArrayObject();
449         
450          # --BEHAVIOR-- templateCustomSortByAlias
451          $this->core->callBehavior('templateCustomSortByAlias',$alias);
452         
453          $alias = $alias->getArrayCopy();
454         
455          if (is_array($alias)) {
456               foreach ($alias as $k => $v) {
457                    if (!is_array($v)) {
458                         $alias[$k] = array();
459                    }
460                    if (!is_array($v)) {
461                         $default_alias[$k] = array();
462                    }
463                    $default_alias[$k] = array_merge($default_alias[$k],$alias[$k]);
464               }
465          }
466         
467          if (!array_key_exists($table,$default_alias)) {
468               return implode(', ',$res);
469          }
470         
471          if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) {
472               $default_order = $attr['order'];
473          }
474          if (isset($attr['sortby'])) {
475               $sorts = explode(',',$attr['sortby']);
476               foreach ($sorts as $k => $sort) {
477                    $order = $default_order;
478                    if (preg_match('/([a-z]*)\s*\?(desc|asc)$/i',$sort,$matches)) {
479                         $sort = $matches[1];
480                         $order = $matches[2];
481                    }
482                    if (array_key_exists($sort,$default_alias[$table])) {
483                         array_push($res,$default_alias[$table][$sort].' '.$order);
484                    }
485               }
486          }
487         
488          if (count($res) === 0) {
489               array_push($res,$default_alias[$table]['date'].' '.$default_order);
490          }
491         
492          return implode(', ',$res);
493     }
494     
495     public static function getAge($attr)
496     {
497          if (isset($attr['age']) && preg_match('/^(\-[0-9]+|last).*$/i',$attr['age'])) {
498               if (($ts = strtotime($attr['age'])) !== false) {
499                    return dt::str('%Y-%m-%d %H:%m:%S',$ts);
500               }
501          }
502          return '';
503     }
504     
505     /* TEMPLATE FUNCTIONS
506     ------------------------------------------------------- */
507     
508     public function l10n($attr,$str_attr)
509     {
510          # Normalize content
511          $str_attr = preg_replace('/\s+/x',' ',$str_attr);
512         
513          return "<?php echo __('".str_replace("'","\\'",$str_attr)."'); ?>";
514     }
515     
516     public function LoopPosition($attr,$content)
517     {
518          $start = isset($attr['start']) ? (integer) $attr['start'] : '0';
519          $length = isset($attr['length']) ? (integer) $attr['length'] : 'null';
520          $even = isset($attr['even']) ? (integer) (boolean) $attr['even'] : 'null';
521         
522          if ($start > 0) {
523               $start--;
524          }
525         
526          return
527          '<?php if ($_ctx->loopPosition('.$start.','.$length.','.$even.')) : ?>'.
528          $content.
529          "<?php endif; ?>";
530     }
531
532     public function LoopIndex($attr)
533     {
534          $f = $this->getFilters($attr);
535          return '<?php '.sprintf($f,'(!$_ctx->cur_loop ? 0 : $_ctx->cur_loop->index() + 1)').' ?>';
536     }
537     
538     
539     /* Archives ------------------------------------------- */
540     /*dtd
541     <!ELEMENT tpl:Archives - - -- Archives dates loop -->
542     <!ATTLIST tpl:Archives
543     type      (day|month|year)    #IMPLIED  -- Get days, months or years, default to month --
544     category  CDATA               #IMPLIED  -- Get dates of given category --
545     no_context (1|0)              #IMPLIED  -- Override context information
546     order     (asc|desc)          #IMPLIED  -- Sort asc or desc --
547     post_type CDATA               #IMPLIED  -- Get dates of given type of entries, default to post --
548     post_lang CDATA          #IMPLIED  -- Filter on the given language
549     >
550     */
551     public function Archives($attr,$content)
552     {
553          $p = "if (!isset(\$params)) \$params = array();\n";
554          $p .= "\$params['type'] = 'month';\n";
555          if (isset($attr['type'])) {
556               $p .= "\$params['type'] = '".addslashes($attr['type'])."';\n";
557          }
558         
559          if (isset($attr['category'])) {
560               $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";
561          }
562       
563          if (isset($attr['post_type'])) {
564               $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n";
565          }
566       
567          if (isset($attr['post_lang'])) {
568               $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n";
569          }
570         
571          if (empty($attr['no_context']) && !isset($attr['category']))
572          {
573               $p .=
574               'if ($_ctx->exists("categories")) { '.
575                    "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
576               "}\n";
577          }
578         
579          $order = 'desc';
580          if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) {
581               $p .= "\$params['order'] = '".$attr['order']."';\n ";
582          }
583         
584          $res = "<?php\n";
585          $res .= $p;
586          $res .= $this->core->callBehavior("templatePrepareParams", 
587               array("tag" => "Archives","method" => "blog::getDates"), 
588               $attr,$content);
589          $res .= '$_ctx->archives = $core->blog->getDates($params); unset($params);'."\n";
590          $res .= "?>\n";
591         
592          $res .=
593          '<?php while ($_ctx->archives->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->archives = null; ?>';
594         
595          return $res;
596     }
597     
598     /*dtd
599     <!ELEMENT tpl:ArchivesHeader - - -- First archives result container -->
600     */
601     public function ArchivesHeader($attr,$content)
602     {
603          return
604          "<?php if (\$_ctx->archives->isStart()) : ?>".
605          $content.
606          "<?php endif; ?>";
607     }
608     
609     /*dtd
610     <!ELEMENT tpl:ArchivesFooter - - -- Last archives result container -->
611     */
612     public function ArchivesFooter($attr,$content)
613     {
614          return
615          "<?php if (\$_ctx->archives->isEnd()) : ?>".
616          $content.
617          "<?php endif; ?>";
618     }
619     
620     /*dtd
621     <!ELEMENT tpl:ArchivesYearHeader - - -- First result of year in archives container -->
622     */
623     public function ArchivesYearHeader($attr,$content)
624     {
625          return
626          "<?php if (\$_ctx->archives->yearHeader()) : ?>".
627          $content.
628          "<?php endif; ?>";
629     }
630     
631     /*dtd
632     <!ELEMENT tpl:ArchivesYearFooter - - -- Last result of year in archives container -->
633     */
634     public function ArchivesYearFooter($attr,$content)
635     {
636          return
637          "<?php if (\$_ctx->archives->yearFooter()) : ?>".
638          $content.
639          "<?php endif; ?>";
640     }
641     
642     /*dtd
643     <!ELEMENT tpl:ArchiveDate - O -- Archive result date -->
644     <!ATTLIST tpl:ArchiveDate
645     format    CDATA     #IMPLIED  -- Date format (Default %B %Y) --
646     >
647     */
648     public function ArchiveDate($attr)
649     {
650          $format = '%B %Y';
651          if (!empty($attr['format'])) {
652               $format = addslashes($attr['format']);
653          }
654         
655          $f = $this->getFilters($attr);
656          return '<?php echo '.sprintf($f,"dt::dt2str('".$format."',\$_ctx->archives->dt)").'; ?>';
657     }
658     
659     /*dtd
660     <!ELEMENT tpl:ArchiveEntriesCount - O -- Current archive result number of entries -->
661     */
662     public function ArchiveEntriesCount($attr)
663     {
664          $f = $this->getFilters($attr);
665          return '<?php echo '.sprintf($f,'$_ctx->archives->nb_post').'; ?>';
666     }
667     
668     /*dtd
669     <!ELEMENT tpl:ArchiveNext - - -- Next archive result container -->
670     <!ATTLIST tpl:ArchiveNext
671     type      (day|month|year)    #IMPLIED  -- Get days, months or years, default to month --
672     post_type CDATA               #IMPLIED  -- Get dates of given type of entries, default to post --
673     post_lang CDATA          #IMPLIED  -- Filter on the given language
674     >
675     */
676     public function ArchiveNext($attr,$content)
677     {
678          $p = "if (!isset(\$params)) \$params = array();\n";
679          $p .= "\$params['type'] = 'month';\n";
680          if (isset($attr['type'])) {
681               $p .= "\$params['type'] = '".addslashes($attr['type'])."';\n";
682          }
683         
684          if (isset($attr['post_type'])) {
685               $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n";
686          }
687         
688          if (isset($attr['post_lang'])) {
689               $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n";
690          }
691       
692          $p .= "\$params['next'] = \$_ctx->archives->dt;";
693         
694          $res = "<?php\n";
695          $res .= $p;
696          $res .= $this->core->callBehavior("templatePrepareParams",
697               array("tag" => "ArchiveNext","method" => "blog::getDates"), 
698               $attr, $content);
699          $res .= '$_ctx->archives = $core->blog->getDates($params); unset($params);'."\n";
700          $res .= "?>\n";
701         
702          $res .=
703          '<?php while ($_ctx->archives->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->archives = null; ?>';
704         
705          return $res;
706     }
707     
708     /*dtd
709     <!ELEMENT tpl:ArchivePrevious - - -- Previous archive result container -->
710     <!ATTLIST tpl:ArchivePrevious
711     type      (day|month|year)    #IMPLIED  -- Get days, months or years, default to month --
712     post_type CDATA               #IMPLIED  -- Get dates of given type of entries, default to post --
713     post_lang CDATA          #IMPLIED  -- Filter on the given language
714     >
715     */
716     public function ArchivePrevious($attr,$content)
717     {
718          $p = 'if (!isset($params)) $params = array();';
719          $p .= "\$params['type'] = 'month';\n";
720          if (isset($attr['type'])) {
721               $p .= "\$params['type'] = '".addslashes($attr['type'])."';\n";
722          }
723         
724          if (isset($attr['post_type'])) {
725               $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n";
726          }
727       
728          if (isset($attr['post_lang'])) {
729               $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n";
730          }
731       
732          $p .= "\$params['previous'] = \$_ctx->archives->dt;";
733         
734          $res = "<?php\n";
735          $res .= $this->core->callBehavior("templatePrepareParams",
736               array("tag" => "ArchivePrevious","method" => "blog::getDates"), 
737               $attr, $content);
738          $res .= $p;
739          $res .= '$_ctx->archives = $core->blog->getDates($params); unset($params);'."\n";
740          $res .= "?>\n";
741         
742          $res .=
743          '<?php while ($_ctx->archives->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->archives = null; ?>';
744         
745          return $res;
746     }
747     
748     /*dtd
749     <!ELEMENT tpl:ArchiveURL - O -- Current archive result URL -->
750     */
751     public function ArchiveURL($attr)
752     {
753          $f = $this->getFilters($attr);
754          return '<?php echo '.sprintf($f,'$_ctx->archives->url($core)').'; ?>';
755     }
756     
757     
758     /* Blog ----------------------------------------------- */
759     /*dtd
760     <!ELEMENT tpl:BlogArchiveURL - O -- Blog Archives URL -->
761     */
762     public function BlogArchiveURL($attr)
763     {
764          $f = $this->getFilters($attr);
765          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("archive")').'; ?>';
766     }
767     
768     /*dtd
769     <!ELEMENT tpl:BlogCopyrightNotice - O -- Blog copyrght notices -->
770     */
771     public function BlogCopyrightNotice($attr)
772     {
773          $f = $this->getFilters($attr);
774          return '<?php echo '.sprintf($f,'$core->blog->settings->system->copyright_notice').'; ?>';
775     }
776     
777     /*dtd
778     <!ELEMENT tpl:BlogDescription - O -- Blog Description -->
779     */
780     public function BlogDescription($attr)
781     {
782          $f = $this->getFilters($attr);
783          return '<?php echo '.sprintf($f,'$core->blog->desc').'; ?>';
784     }
785     
786     /*dtd
787     <!ELEMENT tpl:BlogEditor - O -- Blog Editor -->
788     */
789     public function BlogEditor($attr)
790     {
791          $f = $this->getFilters($attr);
792          return '<?php echo '.sprintf($f,'$core->blog->settings->system->editor').'; ?>';
793     }
794     
795     /*dtd
796     <!ELEMENT tpl:BlogFeedID - O -- Blog Feed ID -->
797     */
798     public function BlogFeedID($attr)
799     {
800          $f = $this->getFilters($attr);
801          return '<?php echo '.sprintf($f,'"urn:md5:".$core->blog->uid').'; ?>';
802     }
803     
804     /*dtd
805     <!ELEMENT tpl:BlogFeedURL - O -- Blog Feed URL -->
806     <!ATTLIST tpl:BlogFeedURL
807     type (rss2|atom)    #IMPLIED  -- feed type (default : rss2)
808     >
809     */
810     public function BlogFeedURL($attr)
811     {
812          $type = !empty($attr['type']) ? $attr['type'] : 'atom';
813         
814          if (!preg_match('#^(rss2|atom)$#',$type)) {
815               $type = 'atom';
816          }
817         
818          $f = $this->getFilters($attr);
819          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("feed","'.$type.'")').'; ?>';
820     }
821     
822     /*dtd
823     <!ELEMENT tpl:BlogName - O -- Blog Name -->
824     */
825     public function BlogName($attr)
826     {
827          $f = $this->getFilters($attr);
828          return '<?php echo '.sprintf($f,'$core->blog->name').'; ?>';
829     }
830     
831     /*dtd
832     <!ELEMENT tpl:BlogLanguage - O -- Blog Language -->
833     */
834     public function BlogLanguage($attr)
835     {
836          $f = $this->getFilters($attr);
837          return '<?php echo '.sprintf($f,'$core->blog->settings->system->lang').'; ?>';
838     }
839     
840     /*dtd
841     <!ELEMENT tpl:BlogThemeURL - O -- Blog's current Themei URL -->
842     */
843     public function BlogThemeURL($attr)
844     {
845          $f = $this->getFilters($attr);
846          return '<?php echo '.sprintf($f,'$core->blog->settings->system->themes_url."/".$core->blog->settings->system->theme').'; ?>';
847     }
848   
849     /*dtd
850     <!ELEMENT tpl:BlogPublicURL - O -- Blog Public directory URL -->
851     */
852     public function BlogPublicURL($attr)
853     {
854          $f = $this->getFilters($attr);
855          return '<?php echo '.sprintf($f,'$core->blog->settings->system->public_url').'; ?>';
856     }
857     
858     /*dtd
859     <!ELEMENT tpl:BlogUpdateDate - O -- Blog last update date -->
860     <!ATTLIST tpl:BlogUpdateDate
861     format    CDATA     #IMPLIED  -- date format (encoded in dc:str by default if iso8601 or rfc822 not specified)
862     iso8601   CDATA     #IMPLIED  -- if set, tells that date format is ISO 8601
863     rfc822    CDATA     #IMPLIED  -- if set, tells that date format is RFC 822
864     >
865     */
866     public function BlogUpdateDate($attr)
867     {
868          $format = '';
869          if (!empty($attr['format'])) {
870               $format = addslashes($attr['format']);
871          } else {
872               $format = '%Y-%m-%d %H:%M:%S';
873          }
874         
875          $iso8601 = !empty($attr['iso8601']);
876          $rfc822 = !empty($attr['rfc822']);
877         
878          $f = $this->getFilters($attr);
879         
880          if ($rfc822) {
881               return '<?php echo '.sprintf($f,"dt::rfc822(\$core->blog->upddt,\$core->blog->settings->system->blog_timezone)").'; ?>';
882          } elseif ($iso8601) {
883               return '<?php echo '.sprintf($f,"dt::iso8601(\$core->blog->upddt,\$core->blog->settings->system->blog_timezone)").'; ?>';
884          } else {
885               return '<?php echo '.sprintf($f,"dt::str('".$format."',\$core->blog->upddt)").'; ?>';
886          }
887     }
888     
889     /*dtd
890     <!ELEMENT tpl:BlogID - 0 -- Blog ID -->
891     */
892     public function BlogID($attr)
893     {
894          $f = $this->getFilters($attr);
895          return '<?php echo '.sprintf($f,'$core->blog->id').'; ?>';
896     }
897     
898     /*dtd
899     <!ELEMENT tpl:BlogRSDURL - O -- Blog RSD URL -->
900     */
901     public function BlogRSDURL($attr)
902     {
903          $f = $this->getFilters($attr);
904          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor(\'rsd\')').'; ?>';
905     }
906     
907     /*dtd
908     <!ELEMENT tpl:BlogURL - O -- Blog URL -->
909     */
910     public function BlogURL($attr)
911     {
912          $f = $this->getFilters($attr);
913          return '<?php echo '.sprintf($f,'$core->blog->url').'; ?>';
914     }
915     
916     /*dtd
917     <!ELEMENT tpl:BlogQmarkURL - O -- Blog URL, ending with a question mark -->
918     */
919     public function BlogQmarkURL($attr)
920     {
921          $f = $this->getFilters($attr);
922          return '<?php echo '.sprintf($f,'$core->blog->getQmarkURL()').'; ?>';
923     }
924     
925     /*dtd
926     <!ELEMENT tpl:BlogMetaRobots - O -- Blog meta robots tag definition, overrides robots_policy setting -->
927     <!ATTLIST tpl:BlogMetaRobots
928     robots    CDATA     #IMPLIED  -- can be INDEX,FOLLOW,NOINDEX,NOFOLLOW,ARCHIVE,NOARCHIVE
929     >
930     */
931     public function BlogMetaRobots($attr)
932     {
933          $robots = isset($attr['robots']) ? addslashes($attr['robots']) : '';
934          return "<?php echo context::robotsPolicy(\$core->blog->settings->system->robots_policy,'".$robots."'); ?>";
935     }
936     
937     /* Categories ----------------------------------------- */
938     
939     /*dtd
940     <!ELEMENT tpl:Categories - - -- Categories loop -->
941     */
942     public function Categories($attr,$content)
943     {
944          $p = "if (!isset(\$params)) \$params = array();\n";
945         
946          if (isset($attr['url'])) {
947               $p .= "\$params['cat_url'] = '".addslashes($attr['url'])."';\n";
948          }
949         
950          if (!empty($attr['post_type'])) {
951               $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n";
952          }
953         
954          if (!empty($attr['level'])) {
955               $p .= "\$params['level'] = ".(integer) $attr['level'].";\n";
956          }
957         
958          $res = "<?php\n";
959          $res .= $p;
960          $res .= $this->core->callBehavior("templatePrepareParams", 
961               array("tag" => "Categories","method" => "blog::getCategories"), 
962               $attr,$content);
963          $res .= '$_ctx->categories = $core->blog->getCategories($params);'."\n";
964          $res .= "?>\n";
965          $res .= '<?php while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; unset($params); ?>';
966         
967          return $res;
968     }
969     
970     /*dtd
971     <!ELEMENT tpl:CategoriesHeader - - -- First Categories result container -->
972     */
973     public function CategoriesHeader($attr,$content)
974     {
975          return
976          "<?php if (\$_ctx->categories->isStart()) : ?>".
977          $content.
978          "<?php endif; ?>";
979     }
980     
981     /*dtd
982     <!ELEMENT tpl:CategoriesFooter - - -- Last Categories result container -->
983     */
984     public function CategoriesFooter($attr,$content)
985     {
986          return
987          "<?php if (\$_ctx->categories->isEnd()) : ?>".
988          $content.
989          "<?php endif; ?>";
990     }
991     
992     /*dtd
993     <!ELEMENT tpl:CategoryIf - - -- tests on current entry -->
994     <!ATTLIST tpl:CategoryIf
995     url       CDATA     #IMPLIED  -- category has given url
996     has_entries    (0|1)     #IMPLIED  -- post is the first post from list (value : 1) or not (value : 0)
997     has_description     (0|1)     #IMPLIED  -- category has description (value : 1) or not (value : 0)
998     >
999     */
1000     public function CategoryIf($attr,$content)
1001     {
1002          $if = new ArrayObject();
1003          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';
1004         
1005          if (isset($attr['url'])) {
1006               $url = addslashes(trim($attr['url']));
1007               if (substr($url,0,1) == '!') {
1008                    $url = substr($url,1);
1009                    $if[] = '($_ctx->categories->cat_url != "'.$url.'")';
1010               } else {
1011                    $if[] = '($_ctx->categories->cat_url == "'.$url.'")';
1012               }
1013          }
1014         
1015          if (isset($attr['has_entries'])) {
1016               $sign = (boolean) $attr['has_entries'] ? '>' : '==';
1017               $if[] = '$_ctx->categories->nb_post '.$sign.' 0';
1018          }
1019         
1020          if (isset($attr['has_description'])) { 
1021               $sign = (boolean) $attr['has_description'] ? '!=' : '=='; 
1022               $if[] = '$_ctx->categories->cat_desc '.$sign.' ""'; 
1023          } 
1024         
1025          $this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if);
1026         
1027          if (count($if) != 0) {
1028               return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
1029          } else {
1030               return $content;
1031          }
1032     }
1033     
1034     /*dtd
1035     <!ELEMENT tpl:CategoryFirstChildren - - -- Current category first children loop -->
1036     */
1037     public function CategoryFirstChildren($attr,$content)
1038     {
1039          return
1040          "<?php\n".
1041          '$_ctx->categories = $core->blog->getCategoryFirstChildren($_ctx->categories->cat_id);'."\n".
1042          'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';
1043     }
1044     
1045     /*dtd
1046     <!ELEMENT tpl:CategoryParents - - -- Current category parents loop -->
1047     */
1048     public function CategoryParents($attr,$content)
1049     {
1050          return
1051          "<?php\n".
1052          '$_ctx->categories = $core->blog->getCategoryParents($_ctx->categories->cat_id);'."\n".
1053          'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';
1054     }
1055     
1056     /*dtd
1057     <!ELEMENT tpl:CategoryFeedURL - O -- Category feed URL -->
1058     <!ATTLIST tpl:CategoryFeedURL
1059     type (rss2|atom)    #IMPLIED  -- feed type (default : rss2)
1060     >
1061     */
1062     public function CategoryFeedURL($attr)
1063     {
1064          $type = !empty($attr['type']) ? $attr['type'] : 'atom';
1065         
1066          if (!preg_match('#^(rss2|atom)$#',$type)) {
1067               $type = 'atom';
1068          }
1069         
1070          $f = $this->getFilters($attr);
1071          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("feed","category/".'.
1072          '$_ctx->categories->cat_url."/'.$type.'")').'; ?>';
1073     }
1074     
1075     /*dtd
1076     <!ELEMENT tpl:CategoryURL - O -- Category URL (complete iabsolute URL, including blog URL) -->
1077     */
1078     public function CategoryURL($attr)
1079     {
1080          $f = $this->getFilters($attr);
1081          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("category",'.
1082               '$_ctx->categories->cat_url)').'; ?>';
1083     }
1084     
1085     /*dtd
1086     <!ELEMENT tpl:CategoryShortURL - O -- Category short URL (relative URL, from /category/) -->
1087     */
1088     public function CategoryShortURL($attr)
1089     {
1090          $f = $this->getFilters($attr);
1091          return '<?php echo '.sprintf($f,'$_ctx->categories->cat_url').'; ?>';
1092     }
1093     
1094     /*dtd
1095     <!ELEMENT tpl:CategoryDescription - O -- Category description -->
1096     */
1097     public function CategoryDescription($attr)
1098     {
1099          $f = $this->getFilters($attr);
1100          return '<?php echo '.sprintf($f,'$_ctx->categories->cat_desc').'; ?>';
1101     }
1102     
1103     /*dtd
1104     <!ELEMENT tpl:CategoryTitle - O -- Category title -->
1105     */
1106     public function CategoryTitle($attr)
1107     {
1108          $f = $this->getFilters($attr);
1109          return '<?php echo '.sprintf($f,'$_ctx->categories->cat_title').'; ?>';
1110     }
1111
1112     /*dtd
1113     <!ELEMENT tpl:CategoryEntriesCount - O -- Category number of entries -->
1114     */
1115     public function CategoryEntriesCount($attr)
1116     {
1117          $f = $this->getFilters($attr);
1118          return '<?php echo '.sprintf($f,'$_ctx->categories->nb_post').'; ?>';
1119     }
1120     
1121     /* Entries -------------------------------------------- */
1122     /*dtd
1123     <!ELEMENT tpl:Entries - - -- Blog Entries loop -->
1124     <!ATTLIST tpl:Entries
1125     lastn     CDATA     #IMPLIED  -- limit number of results to specified value
1126     author    CDATA     #IMPLIED  -- get entries for a given user id
1127     category  CDATA     #IMPLIED  -- get entries for specific categories only (multiple comma-separated categories can be specified. Use "!" as prefix to exclude a category)
1128     no_category    CDATA     #IMPLIED  -- get entries without category
1129     no_context (1|0)    #IMPLIED  -- Override context information
1130     sortby    (title|selected|author|date|id)    #IMPLIED  -- specify entries sort criteria (default : date) (multiple comma-separated sortby can be specified. Use "?asc" or "?desc" as suffix to provide an order for each sorby)
1131     order     (desc|asc)     #IMPLIED  -- specify entries order (default : desc)
1132     no_content     (0|1)     #IMPLIED  -- do not retrieve entries content
1133     selected  (0|1)     #IMPLIED  -- retrieve posts marked as selected only (value: 1) or not selected only (value: 0)
1134     url       CDATA     #IMPLIED  -- retrieve post by its url
1135     type      CDATA     #IMPLIED  -- retrieve post with given post_type (there can be many ones separated by comma)
1136     age       CDATA     #IMPLIED  -- retrieve posts by maximum age (ex: -2 days, last month, last week)
1137     ignore_pagination   (0|1)     #IMPLIED  -- ignore page number provided in URL (useful when using multiple tpl:Entries on the same page)
1138     >
1139     */
1140     public function Entries($attr,$content)
1141     {
1142          $lastn = -1;
1143          if (isset($attr['lastn'])) {
1144               $lastn = abs((integer) $attr['lastn'])+0;
1145          }
1146         
1147          $p = 'if (!isset($_page_number)) { $_page_number = 1; }'."\n";
1148         
1149          if ($lastn != 0) {
1150               if ($lastn > 0) {
1151                    $p .= "\$params['limit'] = ".$lastn.";\n";
1152               } else {
1153                    $p .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n";
1154               }
1155               
1156               if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0") {
1157                    $p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n";
1158               } else {
1159                    $p .= "\$params['limit'] = array(0, \$params['limit']);\n";
1160               }
1161          }
1162         
1163          if (isset($attr['author'])) {
1164               $p .= "\$params['user_id'] = '".addslashes($attr['author'])."';\n";
1165          }
1166         
1167          if (isset($attr['category'])) {
1168               $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";
1169               $p .= "context::categoryPostParam(\$params);\n";
1170          }
1171         
1172          if (isset($attr['no_category']) && $attr['no_category']) {
1173               $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n";
1174               $p .= "unset(\$params['cat_url']);\n";
1175          }
1176         
1177          if (!empty($attr['type'])) {
1178               $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
1179          }
1180         
1181          if (!empty($attr['url'])) {
1182               $p .= "\$params['post_url'] = '".addslashes($attr['url'])."';\n";
1183          }
1184         
1185          if (empty($attr['no_context']))
1186          {
1187               if (!isset($attr['author']))
1188               {
1189                    $p .=
1190                    'if ($_ctx->exists("users")) { '.
1191                         "\$params['user_id'] = \$_ctx->users->user_id; ".
1192                    "}\n";
1193               }
1194               
1195               if (!isset($attr['category']) && (!isset($attr['no_category']) || !$attr['no_category']))
1196               {
1197                    $p .=
1198                    'if ($_ctx->exists("categories")) { '.
1199                         "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
1200                    "}\n";
1201               }
1202               
1203               $p .=
1204               'if ($_ctx->exists("archives")) { '.
1205                    "\$params['post_year'] = \$_ctx->archives->year(); ".
1206                    "\$params['post_month'] = \$_ctx->archives->month(); ";
1207               if (!isset($attr['lastn'])) {
1208                    $p .= "unset(\$params['limit']); ";
1209               }
1210               $p .=
1211               "}\n";
1212               
1213               $p .=
1214               'if ($_ctx->exists("langs")) { '.
1215                    "\$params['post_lang'] = \$_ctx->langs->post_lang; ".
1216               "}\n";
1217               
1218               $p .=
1219               'if (isset($_search)) { '.
1220                    "\$params['search'] = \$_search; ".
1221               "}\n";
1222          }
1223         
1224          $p .= "\$params['order'] = '".$this->getSortByStr($attr,'post')."';\n";
1225         
1226          if (isset($attr['no_content']) && $attr['no_content']) {
1227               $p .= "\$params['no_content'] = true;\n";
1228          }
1229         
1230          if (isset($attr['selected'])) {
1231               $p .= "\$params['post_selected'] = ".(integer) (boolean) $attr['selected'].";";
1232          }
1233         
1234          if (isset($attr['age'])) {
1235               $age = $this->getAge($attr);
1236               $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : '';
1237          }
1238         
1239          $res = "<?php\n";
1240          $res .= $p;
1241          $res .= $this->core->callBehavior("templatePrepareParams", 
1242               array("tag" => "Entries","method" => "blog::getPosts"), 
1243               $attr,$content);
1244          $res .= '$_ctx->post_params = $params;'."\n";
1245          $res .= '$_ctx->posts = $core->blog->getPosts($params); unset($params);'."\n";
1246          $res .= "?>\n";
1247          $res .=
1248          '<?php while ($_ctx->posts->fetch()) : ?>'.$content.'<?php endwhile; '.
1249          '$_ctx->posts = null; $_ctx->post_params = null; ?>';
1250         
1251          return $res;
1252     }
1253     
1254     /*dtd
1255     <!ELEMENT tpl:DateHeader - O -- Displays date, if post is the first post of the given day -->
1256     */
1257     public function DateHeader($attr,$content)
1258     {
1259          return
1260          "<?php if (\$_ctx->posts->firstPostOfDay()) : ?>".
1261          $content.
1262          "<?php endif; ?>";
1263     }
1264     
1265     /*dtd
1266     <!ELEMENT tpl:DateFooter - O -- Displays date,  if post is the last post of the given day -->
1267     */
1268     public function DateFooter($attr,$content)
1269     {
1270          return
1271          "<?php if (\$_ctx->posts->lastPostOfDay()) : ?>".
1272          $content.
1273          "<?php endif; ?>";
1274     }
1275     
1276     /*dtd
1277     <!ELEMENT tpl:EntryIf - - -- tests on current entry -->
1278     <!ATTLIST tpl:EntryIf
1279     type CDATA     #IMPLIED  -- post has a given type (default: "post")
1280     category  CDATA     #IMPLIED  -- post has a given category
1281     first     (0|1)     #IMPLIED  -- post is the first post from list (value : 1) or not (value : 0)
1282     odd  (0|1)     #IMPLIED  -- post is in an odd position (value : 1) or not (value : 0)
1283     even (0|1)     #IMPLIED  -- post is in an even position (value : 1) or not (value : 0)
1284     extended  (0|1)     #IMPLIED  -- post has an excerpt (value : 1) or not (value : 0)
1285     selected  (0|1)     #IMPLIED  -- post is selected (value : 1) or not (value : 0)
1286     has_category   (0|1)     #IMPLIED  -- post has a category (value : 1) or not (value : 0)
1287     has_attachment (0|1)     #IMPLIED  -- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code)
1288     comments_active     (0|1)     #IMPLIED  -- comments are active for this post (value : 1) or not (value : 0)
1289     pings_active   (0|1)     #IMPLIED  -- trackbacks are active for this post (value : 1) or not (value : 0)
1290     show_comments  (0|1)     #IMPLIED  -- there are comments for this post (value : 1) or not (value : 0)
1291     show_pings     (0|1)     #IMPLIED  -- there are trackbacks for this post (value : 1) or not (value : 0)
1292     republished    (0|1)     #IMPLIED  -- post has been updated since publication (value : 1) or not (value : 0)
1293     operator  (and|or)  #IMPLIED  -- combination of conditions, if more than 1 specifiec (default: and)
1294     url       CDATA     #IMPLIED  -- post has given url
1295     >
1296     */
1297     public function EntryIf($attr,$content)
1298     {
1299          $if = new ArrayObject();
1300          $extended = null;
1301          $hascategory = null;
1302         
1303          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';
1304       
1305          if (isset($attr['type'])) {
1306               $type = trim($attr['type']);
1307               $type = !empty($type)?$type:'post';
1308               $if[] = '$_ctx->posts->post_type == "'.addslashes($type).'"';
1309          }
1310         
1311          if (isset($attr['url'])) {
1312               $url = trim($attr['url']);
1313               if (substr($url,0,1) == '!') {
1314                    $url = substr($url,1);
1315                    $if[] = '$_ctx->posts->post_url != "'.addslashes($url).'"';
1316               } else {
1317                    $if[] = '$_ctx->posts->post_url == "'.addslashes($url).'"';
1318               }
1319          }
1320         
1321          if (isset($attr['category'])) {
1322               $category = addslashes(trim($attr['category']));
1323               if (substr($category,0,1) == '!') {
1324                    $category = substr($category,1);
1325                    $if[] = '($_ctx->posts->cat_url != "'.$category.'")';
1326               } else {
1327                    $if[] = '($_ctx->posts->cat_url == "'.$category.'")';
1328               }
1329          }
1330         
1331          if (isset($attr['first'])) {
1332               $sign = (boolean) $attr['first'] ? '=' : '!';
1333               $if[] = '$_ctx->posts->index() '.$sign.'= 0';
1334          }
1335         
1336          if (isset($attr['odd'])) {
1337               $sign = (boolean) $attr['odd'] ? '=' : '!';
1338               $if[] = '($_ctx->posts->index()+1)%2 '.$sign.'= 1';
1339          }
1340         
1341          if (isset($attr['extended'])) {
1342               $sign = (boolean) $attr['extended'] ? '' : '!';
1343               $if[] = $sign.'$_ctx->posts->isExtended()';
1344          }
1345         
1346          if (isset($attr['selected'])) {
1347               $sign = (boolean) $attr['selected'] ? '' : '!';
1348               $if[] = $sign.'(boolean)$_ctx->posts->post_selected';
1349          }
1350         
1351          if (isset($attr['has_category'])) {
1352               $sign = (boolean) $attr['has_category'] ? '' : '!';
1353               $if[] = $sign.'$_ctx->posts->cat_id';
1354          }
1355         
1356          if (isset($attr['comments_active'])) {
1357               $sign = (boolean) $attr['comments_active'] ? '' : '!';
1358               $if[] = $sign.'$_ctx->posts->commentsActive()';
1359          }
1360         
1361          if (isset($attr['pings_active'])) {
1362               $sign = (boolean) $attr['pings_active'] ? '' : '!';
1363               $if[] = $sign.'$_ctx->posts->trackbacksActive()';
1364          }
1365         
1366          if (isset($attr['has_comment'])) {
1367               $sign = (boolean) $attr['has_comment'] ? '' : '!';
1368               $if[] = $sign.'$_ctx->posts->hasComments()';
1369          }
1370         
1371          if (isset($attr['has_ping'])) {
1372               $sign = (boolean) $attr['has_ping'] ? '' : '!';
1373               $if[] = $sign.'$_ctx->posts->hasTrackbacks()';
1374          }
1375         
1376          if (isset($attr['show_comments'])) {
1377               if ((boolean) $attr['show_comments']) {
1378                    $if[] = '($_ctx->posts->hasComments() || $_ctx->posts->commentsActive())';
1379               } else {
1380                    $if[] = '(!$_ctx->posts->hasComments() && !$_ctx->posts->commentsActive())';
1381               }
1382          }
1383         
1384          if (isset($attr['show_pings'])) {
1385               if ((boolean) $attr['show_pings']) {
1386                    $if[] = '($_ctx->posts->hasTrackbacks() || $_ctx->posts->trackbacksActive())';
1387               } else {
1388                    $if[] = '(!$_ctx->posts->hasTrackbacks() && !$_ctx->posts->trackbacksActive())';
1389               }
1390          }
1391         
1392          if (isset($attr['republished'])) {
1393               $sign = (boolean) $attr['republished'] ? '' : '!';
1394               $if[] = $sign.'(boolean)$_ctx->posts->isRepublished()';
1395          }
1396         
1397          $this->core->callBehavior('tplIfConditions','EntryIf',$attr,$content,$if);
1398         
1399          if (count($if) != 0) {
1400               return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
1401          } else {
1402               return $content;
1403          }
1404     }
1405     
1406     /*dtd
1407     <!ELEMENT tpl:EntryIfFirst - O -- displays value if entry is the first one -->
1408     <!ATTLIST tpl:EntryIfFirst
1409     return    CDATA     #IMPLIED  -- value to display in case of success (default: first)
1410     >
1411     */
1412     public function EntryIfFirst($attr)
1413     {
1414          $ret = isset($attr['return']) ? $attr['return'] : 'first';
1415          $ret = html::escapeHTML($ret);
1416         
1417          return
1418          '<?php if ($_ctx->posts->index() == 0) { '.
1419          "echo '".addslashes($ret)."'; } ?>";
1420     }
1421     
1422     /*dtd
1423     <!ELEMENT tpl:EntryIfOdd - O -- displays value if entry is in an odd position -->
1424     <!ATTLIST tpl:EntryIfOdd
1425     return    CDATA     #IMPLIED  -- value to display in case of success (default: odd)
1426     >
1427     */
1428     public function EntryIfOdd($attr)
1429     {
1430          $ret = isset($attr['return']) ? $attr['return'] : 'odd';
1431          $ret = html::escapeHTML($ret);
1432         
1433          return
1434          '<?php if (($_ctx->posts->index()+1)%2 == 1) { '.
1435          "echo '".addslashes($ret)."'; } ?>";
1436     }
1437     
1438     /*dtd
1439     <!ELEMENT tpl:EntryIfSelected - O -- displays value if entry is selected -->
1440     <!ATTLIST tpl:EntryIfSelected
1441     return    CDATA     #IMPLIED  -- value to display in case of success (default: selected)
1442     >
1443     */
1444     public function EntryIfSelected($attr)
1445     {
1446          $ret = isset($attr['return']) ? $attr['return'] : 'selected';
1447          $ret = html::escapeHTML($ret);
1448         
1449          return
1450          '<?php if ($_ctx->posts->post_selected) { '.
1451          "echo '".addslashes($ret)."'; } ?>";
1452     }
1453     
1454     /*dtd
1455     <!ELEMENT tpl:EntryContent - O -- Entry content -->
1456     <!ATTLIST tpl:EntryContent
1457     absolute_urls  CDATA     #IMPLIED -- transforms local URLs to absolute one
1458     full           (1|0)     #IMPLIED -- returns full content with excerpt
1459     >
1460     */
1461     public function EntryContent($attr)
1462     {
1463          $urls = '0';
1464          if (!empty($attr['absolute_urls'])) {
1465               $urls = '1';
1466          }
1467         
1468          $f = $this->getFilters($attr);
1469         
1470          if (!empty($attr['full'])) {
1471               return '<?php echo '.sprintf($f,
1472                    '$_ctx->posts->getExcerpt('.$urls.')." ".$_ctx->posts->getContent('.$urls.')').'; ?>';
1473          } else {
1474               return '<?php echo '.sprintf($f,'$_ctx->posts->getContent('.$urls.')').'; ?>';
1475          }
1476     }
1477     
1478     /*dtd
1479     <!ELEMENT tpl:EntryExcerpt - O -- Entry excerpt -->
1480     <!ATTLIST tpl:EntryExcerpt
1481     absolute_urls  CDATA     #IMPLIED -- transforms local URLs to absolute one
1482     >
1483     */
1484     public function EntryExcerpt($attr)
1485     {
1486          $urls = '0';
1487          if (!empty($attr['absolute_urls'])) {
1488               $urls = '1';
1489          }
1490         
1491          $f = $this->getFilters($attr);
1492          return '<?php echo '.sprintf($f,'$_ctx->posts->getExcerpt('.$urls.')').'; ?>';
1493     }
1494     
1495     
1496     /*dtd
1497     <!ELEMENT tpl:EntryAuthorCommonName - O -- Entry author common name -->
1498     */
1499     public function EntryAuthorCommonName($attr)
1500     {
1501          $f = $this->getFilters($attr);
1502          return '<?php echo '.sprintf($f,'$_ctx->posts->getAuthorCN()').'; ?>';
1503     }
1504     
1505     /*dtd
1506     <!ELEMENT tpl:EntryAuthorDisplayName - O -- Entry author display name -->
1507     */
1508     public function EntryAuthorDisplayName($attr)
1509     {
1510          $f = $this->getFilters($attr);
1511          return '<?php echo '.sprintf($f,'$_ctx->posts->user_displayname').'; ?>';
1512     }
1513     
1514     /*dtd
1515     <!ELEMENT tpl:EntryAuthorID - O -- Entry author ID -->
1516     */
1517     public function EntryAuthorID($attr)
1518     {
1519          $f = $this->getFilters($attr);
1520          return '<?php echo '.sprintf($f,'$_ctx->posts->user_id').'; ?>';
1521     }
1522     
1523     /*dtd
1524     <!ELEMENT tpl:EntryAuthorEmail - O -- Entry author email -->
1525     <!ATTLIST tpl:EntryAuthorEmail
1526     spam_protected (0|1)     #IMPLIED  -- protect email from spam (default: 1)
1527     >
1528     */
1529     public function EntryAuthorEmail($attr)
1530     {
1531          $p = 'true';
1532          if (isset($attr['spam_protected']) && !$attr['spam_protected']) {
1533               $p = 'false';
1534          }
1535         
1536          $f = $this->getFilters($attr);
1537          return '<?php echo '.sprintf($f,"\$_ctx->posts->getAuthorEmail(".$p.")").'; ?>';
1538     }
1539     
1540     /*dtd
1541     <!ELEMENT tpl:EntryAuthorLink - O -- Entry author link -->
1542     */
1543     public function EntryAuthorLink($attr)
1544     {
1545          $f = $this->getFilters($attr);
1546          return '<?php echo '.sprintf($f,'$_ctx->posts->getAuthorLink()').'; ?>';
1547     }
1548     
1549     /*dtd
1550     <!ELEMENT tpl:EntryAuthorURL - O -- Entry author URL -->
1551     */
1552     public function EntryAuthorURL($attr)
1553     {
1554          $f = $this->getFilters($attr);
1555          return '<?php echo '.sprintf($f,'$_ctx->posts->user_url').'; ?>';
1556     }
1557     
1558     /*dtd
1559     <!ELEMENT tpl:EntryBasename - O -- Entry short URL (relative to /post) -->
1560     */
1561     public function EntryBasename($attr)
1562     {
1563          $f = $this->getFilters($attr);
1564          return '<?php echo '.sprintf($f,'$_ctx->posts->post_url').'; ?>';
1565     }
1566     
1567     /*dtd
1568     <!ELEMENT tpl:EntryCategory - O -- Entry category (full name) -->
1569     */
1570     public function EntryCategory($attr)
1571     {
1572          $f = $this->getFilters($attr);
1573          return '<?php echo '.sprintf($f,'$_ctx->posts->cat_title').'; ?>';
1574     }
1575     
1576     /*dtd
1577     <!ELEMENT tpl:EntryCategoriesBreadcrumb - - -- Current entry parents loop (without last one) -->
1578     */
1579     public function EntryCategoriesBreadcrumb($attr,$content)
1580     {
1581          return
1582          "<?php\n".
1583          '$_ctx->categories = $core->blog->getCategoryParents($_ctx->posts->cat_id);'."\n".
1584          'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';
1585     }
1586     
1587     /*dtd
1588     <!ELEMENT tpl:EntryCategoryID - O -- Entry category ID -->
1589     */
1590     public function EntryCategoryID($attr)
1591     {
1592          $f = $this->getFilters($attr);
1593          return '<?php echo '.sprintf($f,'$_ctx->posts->cat_id').'; ?>';
1594     }
1595     
1596     /*dtd
1597     <!ELEMENT tpl:EntryCategoryURL - O -- Entry category URL -->
1598     */
1599     public function EntryCategoryURL($attr)
1600     {
1601          $f = $this->getFilters($attr);
1602          return '<?php echo '.sprintf($f,'$_ctx->posts->getCategoryURL()').'; ?>';
1603     }
1604     
1605     /*dtd
1606     <!ELEMENT tpl:EntryCategoryShortURL - O -- Entry category short URL (relative URL, from /category/) -->
1607     */
1608     public function EntryCategoryShortURL($attr)
1609     {
1610          $f = $this->getFilters($attr);
1611          return '<?php echo '.sprintf($f,'$_ctx->posts->cat_url').'; ?>';
1612     }
1613     
1614     
1615     /*dtd
1616     <!ELEMENT tpl:EntryFeedID - O -- Entry feed ID -->
1617     */
1618     public function EntryFeedID($attr)
1619     {
1620          $f = $this->getFilters($attr);
1621          return '<?php echo '.sprintf($f,'$_ctx->posts->getFeedID()').'; ?>';
1622     }
1623     
1624     /*dtd
1625     <!ELEMENT tpl:EntryFirstImage - O -- Extracts entry first image if exists -->
1626     <!ATTLIST tpl:EntryAuthorEmail
1627     size           (sq|t|s|m|o)   #IMPLIED  -- Image size to extract
1628     class          CDATA          #IMPLIED  -- Class to add on image tag
1629     with_category  (1|0)          #IMPLIED  -- Search in entry category description if present (default 0)
1630     no_tag    (1|0)     #IMPLIED  -- Return image URL without HTML tag (default 0)
1631     content_only   (1|0)          #IMPLIED  -- Search in content entry only, not in excerpt (default 0)
1632     cat_only  (1|0)          #IMPLIED  -- Search in category description only (default 0)
1633     >
1634     */
1635     public function EntryFirstImage($attr)
1636     {
1637          $size = !empty($attr['size']) ? $attr['size'] : '';
1638          $class = !empty($attr['class']) ? $attr['class'] : '';
1639          $with_category = !empty($attr['with_category']) ? 1 : 0;
1640          $no_tag = !empty($attr['no_tag']) ? 1 : 0;
1641          $content_only = !empty($attr['content_only']) ? 1 : 0;
1642          $cat_only = !empty($attr['cat_only']) ? 1 : 0;
1643         
1644          return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."',".$with_category.",'".addslashes($class)."',".
1645               $no_tag.",".$content_only.",".$cat_only."); ?>";
1646     }
1647     
1648     /*dtd
1649     <!ELEMENT tpl:EntryID - O -- Entry ID -->
1650     */
1651     public function EntryID($attr)
1652     {
1653          $f = $this->getFilters($attr);
1654          return '<?php echo '.sprintf($f,'$_ctx->posts->post_id').'; ?>';
1655     }
1656     
1657     /*dtd
1658     <!ELEMENT tpl:EntryLang - O --  Entry language or blog lang if not defined -->
1659     */
1660     public function EntryLang($attr)
1661     {
1662          $f = $this->getFilters($attr);
1663          return
1664          '<?php if ($_ctx->posts->post_lang) { '.
1665               'echo '.sprintf($f,'$_ctx->posts->post_lang').'; '.
1666          '} else {'.
1667               'echo '.sprintf($f,'$core->blog->settings->system->lang').'; '.
1668          '} ?>';
1669     }
1670     
1671     /*dtd
1672     <!ELEMENT tpl:EntryNext - - -- Next entry block -->
1673     <!ATTLIST tpl:EntryNext
1674     restrict_to_category     (0|1)     #IMPLIED  -- find next post in the same category (default: 0)
1675     restrict_to_lang         (0|1)     #IMPLIED  -- find next post in the same language (default: 0)
1676     >
1677     */
1678     public function EntryNext($attr,$content)
1679     {
1680          $restrict_to_category = !empty($attr['restrict_to_category']) ? '1' : '0';
1681          $restrict_to_lang = !empty($attr['restrict_to_lang']) ? '1' : '0';
1682         
1683          return
1684          '<?php $next_post = $core->blog->getNextPost($_ctx->posts,1,'.$restrict_to_category.','.$restrict_to_lang.'); ?>'."\n".
1685          '<?php if ($next_post !== null) : ?>'.
1686               
1687               '<?php $_ctx->posts = $next_post; unset($next_post);'."\n".
1688               'while ($_ctx->posts->fetch()) : ?>'.
1689               $content.
1690               '<?php endwhile; $_ctx->posts = null; ?>'.
1691          "<?php endif; ?>\n";
1692     }
1693     
1694     /*dtd
1695     <!ELEMENT tpl:EntryPrevious - - -- Previous entry block -->
1696     <!ATTLIST tpl:EntryPrevious
1697     restrict_to_category     (0|1)     #IMPLIED  -- find previous post in the same category (default: 0)
1698     restrict_to_lang         (0|1)     #IMPLIED  -- find next post in the same language (default: 0)
1699     >
1700     */
1701     public function EntryPrevious($attr,$content)
1702     {
1703          $restrict_to_category = !empty($attr['restrict_to_category']) ? '1' : '0';
1704          $restrict_to_lang = !empty($attr['restrict_to_lang']) ? '1' : '0';
1705         
1706          return
1707          '<?php $prev_post = $core->blog->getNextPost($_ctx->posts,-1,'.$restrict_to_category.','.$restrict_to_lang.'); ?>'."\n".
1708          '<?php if ($prev_post !== null) : ?>'.
1709               
1710               '<?php $_ctx->posts = $prev_post; unset($prev_post);'."\n".
1711               'while ($_ctx->posts->fetch()) : ?>'.
1712               $content.
1713               '<?php endwhile; $_ctx->posts = null; ?>'.
1714          "<?php endif; ?>\n";
1715     }
1716     
1717     /*dtd
1718     <!ELEMENT tpl:EntryTitle - O -- Entry title -->
1719     */
1720     public function EntryTitle($attr)
1721     {
1722          $f = $this->getFilters($attr);
1723          return '<?php echo '.sprintf($f,'$_ctx->posts->post_title').'; ?>';
1724     }
1725     
1726     /*dtd
1727     <!ELEMENT tpl:EntryURL - O -- Entry URL -->
1728     */
1729     public function EntryURL($attr)
1730     {
1731          $f = $this->getFilters($attr);
1732          return '<?php echo '.sprintf($f,'$_ctx->posts->getURL()').'; ?>';
1733     }
1734     
1735     /*dtd
1736     <!ELEMENT tpl:EntryDate - O -- Entry date -->
1737     <!ATTLIST tpl:EntryDate
1738     format    CDATA     #IMPLIED  -- date format (encoded in dc:str by default if iso8601 or rfc822 not specified)
1739     iso8601   CDATA     #IMPLIED  -- if set, tells that date format is ISO 8601
1740     rfc822    CDATA     #IMPLIED  -- if set, tells that date format is RFC 822
1741     upddt     CDATA     #IMPLIED  -- if set, uses the post update time
1742     creadt    CDATA     #IMPLIED  -- if set, uses the post creation time
1743     >
1744     */
1745     public function EntryDate($attr)
1746     {
1747          $format = '';
1748          if (!empty($attr['format'])) {
1749               $format = addslashes($attr['format']);
1750          }
1751         
1752          $iso8601 = !empty($attr['iso8601']);
1753          $rfc822 = !empty($attr['rfc822']);
1754          $type = (!empty($attr['creadt']) ? 'creadt' : '');
1755          $type = (!empty($attr['upddt']) ? 'upddt' : $type);
1756         
1757          $f = $this->getFilters($attr);
1758         
1759          if ($rfc822) {
1760               return '<?php echo '.sprintf($f,"\$_ctx->posts->getRFC822Date('".$type."')").'; ?>';
1761          } elseif ($iso8601) {
1762               return '<?php echo '.sprintf($f,"\$_ctx->posts->getISO8601Date('".$type."')").'; ?>';
1763          } else {
1764               return '<?php echo '.sprintf($f,"\$_ctx->posts->getDate('".$format."','".$type."')").'; ?>';
1765          }
1766     }
1767     
1768     /*dtd
1769     <!ELEMENT tpl:EntryTime - O -- Entry date -->
1770     <!ATTLIST tpl:EntryTime
1771     format    CDATA     #IMPLIED  -- time format
1772     upddt     CDATA     #IMPLIED  -- if set, uses the post update time
1773     creadt    CDATA     #IMPLIED  -- if set, uses the post creation time
1774     >
1775     */
1776     public function EntryTime($attr)
1777     {
1778          $format = '';
1779          if (!empty($attr['format'])) {
1780               $format = addslashes($attr['format']);
1781          }
1782         
1783          $type = (!empty($attr['creadt']) ? 'creadt' : '');
1784          $type = (!empty($attr['upddt']) ? 'upddt' : $type);
1785       
1786          $f = $this->getFilters($attr);
1787          return '<?php echo '.sprintf($f,"\$_ctx->posts->getTime('".$format."','".$type."')").'; ?>';
1788     }
1789     
1790     /*dtd
1791     <!ELEMENT tpl:EntriesHeader - - -- First entries result container -->
1792     */
1793     public function EntriesHeader($attr,$content)
1794     {
1795          return
1796          "<?php if (\$_ctx->posts->isStart()) : ?>".
1797          $content.
1798          "<?php endif; ?>";
1799     }
1800     
1801     /*dtd
1802     <!ELEMENT tpl:EntriesFooter - - -- Last entries result container -->
1803     */
1804     public function EntriesFooter($attr,$content)
1805     {
1806          return
1807          "<?php if (\$_ctx->posts->isEnd()) : ?>".
1808          $content.
1809          "<?php endif; ?>";
1810     }
1811     
1812     /*dtd
1813     <!ELEMENT tpl:EntryCommentCount - O -- Number of comments for entry -->
1814     <!ATTLIST tpl:EntryCommentCount
1815     none      CDATA     #IMPLIED  -- text to display for "no comment" (default: no comment)
1816     one       CDATA     #IMPLIED  -- text to display for "one comment" (default: one comment)
1817     more      CDATA     #IMPLIED  -- text to display for "more comments" (default: %s comments, %s is replaced by the number of comment)
1818     count_all CDATA     #IMPLIED  -- count comments and trackbacks
1819     >
1820     */
1821     public function EntryCommentCount($attr)
1822     {
1823          $none = 'no comment';
1824          $one = 'one comment';
1825          $more = '%d comments';
1826         
1827          if (isset($attr['none'])) {
1828               $none = addslashes($attr['none']);
1829          }
1830          if (isset($attr['one'])) {
1831               $one = addslashes($attr['one']);
1832          }
1833          if (isset($attr['more'])) {
1834               $more = addslashes($attr['more']);
1835          }
1836         
1837          if (empty($attr['count_all'])) {
1838               $operation = '$_ctx->posts->nb_comment';
1839          } else {
1840               $operation = '($_ctx->posts->nb_comment + $_ctx->posts->nb_trackback)';
1841          }
1842         
1843          return
1844          "<?php if (".$operation." == 0) {\n".
1845          "  printf(__('".$none."'),".$operation.");\n".
1846          "} elseif (".$operation." == 1) {\n".
1847          "  printf(__('".$one."'),".$operation.");\n".
1848          "} else {\n".
1849          "  printf(__('".$more."'),".$operation.");\n".
1850          "} ?>";
1851     }
1852     
1853     /*dtd
1854     <!ELEMENT tpl:EntryPingCount - O -- Number of trackbacks for entry -->
1855     <!ATTLIST tpl:EntryPingCount
1856     none CDATA     #IMPLIED  -- text to display for "no ping" (default: no ping)
1857     one  CDATA     #IMPLIED  -- text to display for "one ping" (default: one ping)
1858     more CDATA     #IMPLIED  -- text to display for "more pings" (default: %s trackbacks, %s is replaced by the number of pings)
1859     >
1860     */
1861     public function EntryPingCount($attr)
1862     {
1863          $none = 'no trackback';
1864          $one = 'one trackback';
1865          $more = '%d trackbacks';
1866         
1867          if (isset($attr['none'])) {
1868               $none = addslashes($attr['none']);
1869          }
1870          if (isset($attr['one'])) {
1871               $one = addslashes($attr['one']);
1872          }
1873          if (isset($attr['more'])) {
1874               $more = addslashes($attr['more']);
1875          }
1876         
1877          return
1878          "<?php if (\$_ctx->posts->nb_trackback == 0) {\n".
1879          "  printf(__('".$none."'),(integer) \$_ctx->posts->nb_trackback);\n".
1880          "} elseif (\$_ctx->posts->nb_trackback == 1) {\n".
1881          "  printf(__('".$one."'),(integer) \$_ctx->posts->nb_trackback);\n".
1882          "} else {\n".
1883          "  printf(__('".$more."'),(integer) \$_ctx->posts->nb_trackback);\n".
1884          "} ?>";
1885     }
1886     
1887     /*dtd
1888     <!ELEMENT tpl:EntryPingData - O -- Display trackback RDF information -->
1889     */
1890     public function EntryPingData($attr)
1891     {
1892          return "<?php if (\$_ctx->posts->trackbacksActive()) { echo \$_ctx->posts->getTrackbackData(); } ?>\n";
1893     }
1894     
1895     /*dtd
1896     <!ELEMENT tpl:EntryPingLink - O -- Entry trackback link -->
1897     */
1898     public function EntryPingLink($attr)
1899     {
1900          return "<?php if (\$_ctx->posts->trackbacksActive()) { echo \$_ctx->posts->getTrackbackLink(); } ?>\n";
1901     }
1902     
1903     /* Languages -------------------------------------- */
1904     /*dtd
1905     <!ELEMENT tpl:Languages - - -- Languages loop -->
1906     <!ATTLIST tpl:Languages
1907     lang CDATA     #IMPLIED  -- restrict loop on given lang
1908     order     (desc|asc)     #IMPLIED  -- languages ordering (default: desc)
1909     >
1910     */
1911     public function Languages($attr,$content)
1912     {
1913          $p = "if (!isset(\$params)) \$params = array();\n";
1914         
1915          if (isset($attr['lang'])) {
1916               $p = "\$params['lang'] = '".addslashes($attr['lang'])."';\n";
1917          }
1918         
1919          $order = 'desc';
1920          if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) {
1921               $p .= "\$params['order'] = '".$attr['order']."';\n ";
1922          }
1923         
1924          $res = "<?php\n";
1925          $res .= $p;
1926          $res .= $this->core->callBehavior("templatePrepareParams", 
1927               array("tag" => "Languages","method" => "blog::getLangs"), 
1928               $attr,$content);
1929          $res .= '$_ctx->langs = $core->blog->getLangs($params); unset($params);'."\n";
1930          $res .= "?>\n";
1931         
1932          $res .=
1933          '<?php if ($_ctx->langs->count() > 1) : '.
1934          'while ($_ctx->langs->fetch()) : ?>'.$content.
1935          '<?php endwhile; $_ctx->langs = null; endif; ?>';
1936         
1937          return $res;
1938     }
1939     
1940     /*dtd
1941     <!ELEMENT tpl:LanguagesHeader - - -- First languages result container -->
1942     */
1943     public function LanguagesHeader($attr,$content)
1944     {
1945          return
1946          "<?php if (\$_ctx->langs->isStart()) : ?>".
1947          $content.
1948          "<?php endif; ?>";
1949     }
1950     
1951     /*dtd
1952     <!ELEMENT tpl:LanguagesFooter - - -- Last languages result container -->
1953     */
1954     public function LanguagesFooter($attr,$content)
1955     {
1956          return
1957          "<?php if (\$_ctx->langs->isEnd()) : ?>".
1958          $content.
1959          "<?php endif; ?>";
1960     }
1961     
1962     /*dtd
1963     <!ELEMENT tpl:LanguageCode - O -- Language code -->
1964     */
1965     public function LanguageCode($attr)
1966     {
1967          $f = $this->getFilters($attr);
1968          return '<?php echo '.sprintf($f,'$_ctx->langs->post_lang').'; ?>';
1969     }
1970     
1971     /*dtd
1972     <!ELEMENT tpl:LanguageIfCurrent - - -- tests if post language is current language -->
1973     */
1974     public function LanguageIfCurrent($attr,$content)
1975     {
1976          return
1977          "<?php if (\$_ctx->cur_lang == \$_ctx->langs->post_lang) : ?>".
1978          $content.
1979          "<?php endif; ?>";
1980     }
1981     
1982     /*dtd
1983     <!ELEMENT tpl:LanguageURL - O -- Language URL -->
1984     */
1985     public function LanguageURL($attr)
1986     {
1987          $f = $this->getFilters($attr);
1988          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("lang",'.
1989               '$_ctx->langs->post_lang)').'; ?>';
1990     }
1991     
1992     /* Pagination ------------------------------------- */
1993     /*dtd
1994     <!ELEMENT tpl:Pagination - - -- Pagination container -->
1995     <!ATTLIST tpl:Pagination
1996     no_context     (0|1)     #IMPLIED  -- override test on posts count vs number of posts per page
1997     >
1998     */
1999     public function Pagination($attr,$content)
2000     {
2001          $p = "<?php\n";
2002          $p .= '$params = $_ctx->post_params;'."\n";
2003          $p .= $this->core->callBehavior("templatePrepareParams", 
2004               array("tag" => "Pagination","method" => "blog::getPosts"), 
2005               $attr,$content);
2006          $p .= '$_ctx->pagination = $core->blog->getPosts($params,true); unset($params);'."\n";
2007          $p .= "?>\n";
2008         
2009          if (isset($attr['no_context']) && $attr['no_context']) {
2010               return $p.$content;
2011          }
2012       
2013          return
2014               $p.
2015               '<?php if ($_ctx->pagination->f(0) > $_ctx->posts->count()) : ?>'.
2016               $content.
2017               '<?php endif; ?>';
2018     }
2019     
2020     /*dtd
2021     <!ELEMENT tpl:PaginationCounter - O -- Number of pages -->
2022     */
2023     public function PaginationCounter($attr)
2024     {
2025          $f = $this->getFilters($attr);
2026          return '<?php echo '.sprintf($f,"context::PaginationNbPages()").'; ?>';
2027     }
2028     
2029     /*dtd
2030     <!ELEMENT tpl:PaginationCurrent - O -- current page -->
2031     */
2032     public function PaginationCurrent($attr)
2033     {
2034          $offset = 0;
2035          if (isset($attr['offset'])) {
2036               $offset = (integer) $attr['offset'];
2037          }
2038         
2039          $f = $this->getFilters($attr);
2040          return '<?php echo '.sprintf($f,"context::PaginationPosition(".$offset.")").'; ?>';
2041     }
2042     
2043     /*dtd
2044     <!ELEMENT tpl:PaginationIf - - -- pages tests -->
2045     <!ATTLIST tpl:PaginationIf
2046     start     (0|1)     #IMPLIED  -- test if we are at first page (value : 1) or not (value : 0)
2047     end  (0|1)     #IMPLIED  -- test if we are at last page (value : 1) or not (value : 0)
2048     >
2049     */
2050     public function PaginationIf($attr,$content)
2051     {
2052          $if = array();
2053         
2054          if (isset($attr['start'])) {
2055               $sign = (boolean) $attr['start'] ? '' : '!';
2056               $if[] = $sign.'context::PaginationStart()';
2057          }
2058         
2059          if (isset($attr['end'])) {
2060               $sign = (boolean) $attr['end'] ? '' : '!';
2061               $if[] = $sign.'context::PaginationEnd()';
2062          }
2063         
2064          $this->core->callBehavior('tplIfConditions','PaginationIf',$attr,$content,$if);
2065         
2066          if (count($if) != 0) {
2067               return '<?php if('.implode(' && ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
2068          } else {
2069               return $content;
2070          }
2071     }
2072     
2073     /*dtd
2074     <!ELEMENT tpl:PaginationURL - O -- link to previoux/next page -->
2075     <!ATTLIST tpl:PaginationURL
2076     offset    CDATA     #IMPLIED  -- page offset (negative for previous pages), default: 0
2077     >
2078     */
2079     public function PaginationURL($attr)
2080     {
2081          $offset = 0;
2082          if (isset($attr['offset'])) {
2083               $offset = (integer) $attr['offset'];
2084          }
2085         
2086          $f = $this->getFilters($attr);
2087          return '<?php echo '.sprintf($f,"context::PaginationURL(".$offset.")").'; ?>';
2088     }
2089     
2090     /* Comments --------------------------------------- */
2091     /*dtd
2092     <!ELEMENT tpl:Comments - - -- Comments container -->
2093     <!ATTLIST tpl:Comments
2094     with_pings     (0|1)     #IMPLIED  -- include trackbacks in request
2095     lastn     CDATA     #IMPLIED  -- restrict the number of entries
2096     no_context (1|0)         #IMPLIED  -- Override context information
2097     sortby    (title|selected|author|date|id)    #IMPLIED  -- specify comments sort criteria (default : date) (multiple comma-separated sortby can be specified. Use "?asc" or "?desc" as suffix to provide an order for each sorby)
2098     order     (desc|asc)     #IMPLIED  -- result ordering (default: asc)
2099     age       CDATA     #IMPLIED  -- retrieve comments by maximum age (ex: -2 days, last month, last week)
2100     >
2101     */
2102     public function Comments($attr,$content)
2103     {
2104          $p = "";
2105          if (empty($attr['with_pings'])) {
2106               $p .= "\$params['comment_trackback'] = false;\n";
2107          }
2108         
2109          $lastn = 0;
2110          if (isset($attr['lastn'])) {
2111               $lastn = abs((integer) $attr['lastn'])+0;
2112          }
2113         
2114          if ($lastn > 0) {
2115               $p .= "\$params['limit'] = ".$lastn.";\n";
2116          } else {
2117               $p .= "if (\$_ctx->nb_comment_per_page !== null) { \$params['limit'] = \$_ctx->nb_comment_per_page; }\n";
2118          }
2119         
2120          if (empty($attr['no_context']))
2121          {
2122               $p .=
2123               "if (\$_ctx->posts !== null) { ".
2124                    "\$params['post_id'] = \$_ctx->posts->post_id; ".
2125                    "\$core->blog->withoutPassword(false);\n".
2126               "}\n";
2127               $p .=
2128               'if ($_ctx->exists("categories")) { '.
2129                    "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
2130               "}\n";
2131               
2132               $p .=
2133               'if ($_ctx->exists("langs")) { '.
2134                    "\$params['sql'] = \"AND P.post_lang = '\".\$core->blog->con->escape(\$_ctx->langs->post_lang).\"' \"; ".
2135               "}\n";
2136          }
2137         
2138          if (!isset($attr['order'])) {
2139               $attr['order'] = 'asc';
2140          }
2141         
2142          $p .= "\$params['order'] = '".$this->getSortByStr($attr,'comment')."';\n";
2143         
2144          if (isset($attr['no_content']) && $attr['no_content']) {
2145               $p .= "\$params['no_content'] = true;\n";
2146          }
2147         
2148          if (isset($attr['age'])) {
2149               $age = $this->getAge($attr);
2150               $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : '';
2151          }
2152         
2153          $res = "<?php\n";
2154          $res .= $this->core->callBehavior("templatePrepareParams", 
2155               array("tag" => "Comments","method" => "blog::getComments"), 
2156               $attr,$content);
2157          $res .= $p;
2158          $res .= '$_ctx->comments = $core->blog->getComments($params); unset($params);'."\n";
2159          $res .= "if (\$_ctx->posts !== null) { \$core->blog->withoutPassword(true);}\n";
2160         
2161          if (!empty($attr['with_pings'])) {
2162               $res .= '$_ctx->pings = $_ctx->comments;'."\n";
2163          }
2164         
2165          $res .= "?>\n";
2166         
2167          $res .=
2168          '<?php while ($_ctx->comments->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->comments = null; ?>';
2169         
2170          return $res;
2171     }
2172     
2173     /*dtd
2174     <!ELEMENT tpl:CommentAuthor - O -- Comment author -->
2175     */
2176     public function CommentAuthor($attr)
2177     {
2178          $f = $this->getFilters($attr);
2179          return '<?php echo '.sprintf($f,"\$_ctx->comments->comment_author").'; ?>';
2180     }
2181     
2182     /*dtd
2183     <!ELEMENT tpl:CommentAuthorDomain - O -- Comment author website domain -->
2184     */
2185     public function CommentAuthorDomain($attr)
2186     {
2187          return '<?php echo preg_replace("#^http(?:s?)://(.+?)/.*$#msu",\'$1\',$_ctx->comments->comment_site); ?>';
2188     }
2189     
2190     /*dtd
2191     <!ELEMENT tpl:CommentAuthorLink - O -- Comment author link -->
2192     */
2193     public function CommentAuthorLink($attr)
2194     {
2195          $f = $this->getFilters($attr);
2196          return '<?php echo '.sprintf($f,'$_ctx->comments->getAuthorLink()').'; ?>';
2197     }
2198     
2199     /*dtd
2200     <!ELEMENT tpl:CommentAuthorMailMD5 - O -- Comment author email MD5 sum -->
2201     */
2202     public function CommentAuthorMailMD5($attr)
2203     {
2204          return '<?php echo md5($_ctx->comments->comment_email) ; ?>';
2205     }
2206     
2207     /*dtd
2208     <!ELEMENT tpl:CommentAuthorURL - O -- Comment author URL -->
2209     */
2210     public function CommentAuthorURL($attr)
2211     {
2212          $f = $this->getFilters($attr);
2213          return '<?php echo '.sprintf($f,'$_ctx->comments->getAuthorURL()').'; ?>';
2214     }
2215     
2216     /*dtd
2217     <!ELEMENT tpl:CommentContent - O --  Comment content -->
2218     <!ATTLIST tpl:CommentContent
2219     absolute_urls  (0|1)     #IMPLIED  -- convert URLS to absolute urls
2220     >
2221     */
2222     public function CommentContent($attr)
2223     {
2224          $urls = '0';
2225          if (!empty($attr['absolute_urls'])) {
2226               $urls = '1';
2227          }
2228         
2229          $f = $this->getFilters($attr);
2230          return '<?php echo '.sprintf($f,'$_ctx->comments->getContent('.$urls.')').'; ?>';
2231     }
2232     
2233     /*dtd
2234     <!ELEMENT tpl:CommentDate - O -- Comment date -->
2235     <!ATTLIST tpl:CommentDate
2236     format    CDATA     #IMPLIED  -- date format (encoded in dc:str by default if iso8601 or rfc822 not specified)
2237     iso8601   CDATA     #IMPLIED  -- if set, tells that date format is ISO 8601
2238     rfc822    CDATA     #IMPLIED  -- if set, tells that date format is RFC 822
2239     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2240     >
2241     */
2242     public function CommentDate($attr)
2243     {
2244          $format = '';
2245          if (!empty($attr['format'])) {
2246               $format = addslashes($attr['format']);
2247          }
2248         
2249          $iso8601 = !empty($attr['iso8601']);
2250          $rfc822 = !empty($attr['rfc822']);
2251          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2252         
2253          $f = $this->getFilters($attr);
2254         
2255          if ($rfc822) {
2256               return '<?php echo '.sprintf($f,"\$_ctx->comments->getRFC822Date('".$type."')").'; ?>';
2257          } elseif ($iso8601) {
2258               return '<?php echo '.sprintf($f,"\$_ctx->comments->getISO8601Date('".$type."')").'; ?>';
2259          } else {
2260               return '<?php echo '.sprintf($f,"\$_ctx->comments->getDate('".$format."','".$type."')").'; ?>';
2261          }
2262     }
2263     
2264     /*dtd
2265     <!ELEMENT tpl:CommentTime - O -- Comment date -->
2266     <!ATTLIST tpl:CommentTime
2267     format    CDATA     #IMPLIED  -- time format
2268     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2269     >
2270     */
2271     public function CommentTime($attr)
2272     {
2273          $format = '';
2274          if (!empty($attr['format'])) {
2275               $format = addslashes($attr['format']);
2276          }
2277          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2278       
2279          $f = $this->getFilters($attr);
2280          return '<?php echo '.sprintf($f,"\$_ctx->comments->getTime('".$format."','".$type."')").'; ?>';
2281     }
2282     
2283     /*dtd
2284     <!ELEMENT tpl:CommentEmail - O -- Comment author email -->
2285     <!ATTLIST tpl:CommentEmail
2286     spam_protected (0|1)     #IMPLIED  -- protect email from spam (default: 1)
2287     >
2288     */
2289     public function CommentEmail($attr)
2290     {
2291          $p = 'true';
2292          if (isset($attr['spam_protected']) && !$attr['spam_protected']) {
2293               $p = 'false';
2294          }
2295         
2296          $f = $this->getFilters($attr);
2297          return '<?php echo '.sprintf($f,"\$_ctx->comments->getEmail(".$p.")").'; ?>';
2298     }
2299     
2300     /*dtd
2301     <!ELEMENT tpl:CommentEntryTitle - O -- Title of the comment entry -->
2302     */
2303     public function CommentEntryTitle($attr)
2304     {
2305          $f = $this->getFilters($attr);
2306          return '<?php echo '.sprintf($f,'$_ctx->comments->post_title').'; ?>';
2307     }
2308     
2309     /*dtd
2310     <!ELEMENT tpl:CommentFeedID - O -- Comment feed ID -->
2311     */
2312     public function CommentFeedID($attr)
2313     {
2314          $f = $this->getFilters($attr);
2315          return '<?php echo '.sprintf($f,'$_ctx->comments->getFeedID()').'; ?>';
2316     }
2317     
2318     /*dtd
2319     <!ELEMENT tpl:CommentID - O -- Comment ID -->
2320     */
2321     public function CommentID($attr)
2322     {
2323          return '<?php echo $_ctx->comments->comment_id; ?>';
2324     }
2325   
2326     /*dtd
2327     <!ELEMENT tpl:CommentIf - - -- test container for comments -->
2328     <!ATTLIST tpl:CommentIf
2329     is_ping   (0|1)     #IMPLIED  -- test if comment is a trackback (value : 1) or not (value : 0)
2330     >
2331     */
2332     public function CommentIf($attr,$content)
2333     {
2334          $if = array();
2335          $is_ping = null;
2336         
2337          if (isset($attr['is_ping'])) {
2338               $sign = (boolean) $attr['is_ping'] ? '' : '!';
2339               $if[] = $sign.'$_ctx->comments->comment_trackback';
2340          }
2341         
2342          $this->core->callBehavior('tplIfConditions','CommentIf',$attr,$content,$if);
2343         
2344          if (count($if) != 0) {
2345               return '<?php if('.implode(' && ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
2346          } else {
2347               return $content;
2348          }
2349     }
2350     
2351     /*dtd
2352     <!ELEMENT tpl:CommentIfFirst - O -- displays value if comment is the first one -->
2353     <!ATTLIST tpl:CommentIfFirst
2354     return    CDATA     #IMPLIED  -- value to display in case of success (default: first)
2355     >
2356     */
2357     public function CommentIfFirst($attr)
2358     {
2359          $ret = isset($attr['return']) ? $attr['return'] : 'first';
2360          $ret = html::escapeHTML($ret);
2361         
2362          return
2363          '<?php if ($_ctx->comments->index() == 0) { '.
2364          "echo '".addslashes($ret)."'; } ?>";
2365     }
2366     
2367     /*dtd
2368     <!ELEMENT tpl:CommentIfMe - O -- displays value if comment is the from the entry author -->
2369     <!ATTLIST tpl:CommentIfMe
2370     return    CDATA     #IMPLIED  -- value to display in case of success (default: me)
2371     >
2372     */
2373     public function CommentIfMe($attr)
2374     {
2375          $ret = isset($attr['return']) ? $attr['return'] : 'me';
2376          $ret = html::escapeHTML($ret);
2377         
2378          return
2379          '<?php if ($_ctx->comments->isMe()) { '.
2380          "echo '".addslashes($ret)."'; } ?>";
2381     }
2382     
2383     /*dtd
2384     <!ELEMENT tpl:CommentIfOdd - O -- displays value if comment is  at an odd position -->
2385     <!ATTLIST tpl:CommentIfOdd
2386     return    CDATA     #IMPLIED  -- value to display in case of success (default: odd)
2387     >
2388     */
2389     public function CommentIfOdd($attr)
2390     {
2391          $ret = isset($attr['return']) ? $attr['return'] : 'odd';
2392          $ret = html::escapeHTML($ret);
2393         
2394          return
2395          '<?php if (($_ctx->comments->index()+1)%2) { '.
2396          "echo '".addslashes($ret)."'; } ?>";
2397     }
2398     
2399     /*dtd
2400     <!ELEMENT tpl:CommentIP - O -- Comment author IP -->
2401     */
2402     public function CommentIP($attr)
2403     {
2404          return '<?php echo $_ctx->comments->comment_ip; ?>';
2405     }
2406     
2407     /*dtd
2408     <!ELEMENT tpl:CommentOrderNumber - O -- Comment order in page -->
2409     */
2410     public function CommentOrderNumber($attr)
2411     {
2412          return '<?php echo $_ctx->comments->index()+1; ?>';
2413     }
2414     
2415     /*dtd
2416     <!ELEMENT tpl:CommentsFooter - - -- Last comments result container -->
2417     */
2418     public function CommentsFooter($attr,$content)
2419     {
2420          return
2421          "<?php if (\$_ctx->comments->isEnd()) : ?>".
2422          $content.
2423          "<?php endif; ?>";
2424     }
2425     
2426     /*dtd
2427     <!ELEMENT tpl:CommentsHeader - - -- First comments result container -->
2428     */
2429     public function CommentsHeader($attr,$content)
2430     {
2431          return
2432          "<?php if (\$_ctx->comments->isStart()) : ?>".
2433          $content.
2434          "<?php endif; ?>";
2435     }
2436     
2437     /*dtd
2438     <!ELEMENT tpl:CommentPostURL - O -- Comment Entry URL -->
2439     */
2440     public function CommentPostURL($attr)
2441     {
2442          $f = $this->getFilters($attr);
2443          return '<?php echo '.sprintf($f,'$_ctx->comments->getPostURL()').'; ?>';
2444     }
2445     
2446     /*dtd
2447     <!ELEMENT tpl:IfCommentAuthorEmail - - -- Container displayed if comment author email is set -->
2448     */
2449     public function IfCommentAuthorEmail($attr,$content)
2450     {
2451          return
2452          "<?php if (\$_ctx->comments->comment_email) : ?>".
2453          $content.
2454          "<?php endif; ?>";
2455     }
2456     
2457     /*dtd
2458     <!ELEMENT tpl:CommentHelp - 0 -- Comment syntax mini help -->
2459     */
2460     public function CommentHelp($attr,$content)
2461     {
2462          return
2463          "<?php if (\$core->blog->settings->system->wiki_comments) {\n".
2464          "  echo __('Comments can be formatted using a simple wiki syntax.');\n".
2465          "} else {\n".
2466          "  echo __('HTML code is displayed as text and web addresses are automatically converted.');\n".
2467          "} ?>";
2468     }
2469     
2470     /* Comment preview -------------------------------- */
2471     /*dtd
2472     <!ELEMENT tpl:IfCommentPreview - - -- Container displayed if comment is being previewed -->
2473     */
2474     public function IfCommentPreview($attr,$content)
2475     {
2476          return
2477          '<?php if ($_ctx->comment_preview !== null && $_ctx->comment_preview["preview"]) : ?>'.
2478          $content.
2479          '<?php endif; ?>';
2480     }
2481     
2482     /*dtd
2483     <!ELEMENT tpl:CommentPreviewName - O -- Author name for the previewed comment -->
2484     */
2485     public function CommentPreviewName($attr)
2486     {
2487          $f = $this->getFilters($attr);
2488          return '<?php echo '.sprintf($f,'$_ctx->comment_preview["name"]').'; ?>';
2489     }
2490     
2491     /*dtd
2492     <!ELEMENT tpl:CommentPreviewEmail - O -- Author email for the previewed comment -->
2493     */
2494     public function CommentPreviewEmail($attr)
2495     {
2496          $f = $this->getFilters($attr);
2497          return '<?php echo '.sprintf($f,'$_ctx->comment_preview["mail"]').'; ?>';
2498     }
2499     
2500     /*dtd
2501     <!ELEMENT tpl:CommentPreviewSite - O -- Author site for the previewed comment -->
2502     */
2503     public function CommentPreviewSite($attr)
2504     {
2505          $f = $this->getFilters($attr);
2506          return '<?php echo '.sprintf($f,'$_ctx->comment_preview["site"]').'; ?>';
2507     }
2508     
2509     /*dtd
2510     <!ELEMENT tpl:CommentPreviewContent - O -- Content of the previewed comment -->
2511     <!ATTLIST tpl:CommentPreviewContent
2512     raw  (0|1)     #IMPLIED  -- display comment in raw content
2513     >
2514     */
2515     public function CommentPreviewContent($attr)
2516     {
2517          $f = $this->getFilters($attr);
2518         
2519          if (!empty($attr['raw'])) {
2520               $co = '$_ctx->comment_preview["rawcontent"]';
2521          } else {
2522               $co = '$_ctx->comment_preview["content"]';
2523          }
2524         
2525          return '<?php echo '.sprintf($f,$co).'; ?>';
2526     }
2527     
2528     /*dtd
2529     <!ELEMENT tpl:CommentPreviewCheckRemember - O -- checkbox attribute for "remember me" (same value as before preview) -->
2530     */
2531     public function CommentPreviewCheckRemember($attr)
2532     {
2533          return
2534          "<?php if (\$_ctx->comment_preview['remember']) { echo ' checked=\"checked\"'; } ?>";
2535     }
2536     
2537     /* Trackbacks ------------------------------------- */
2538     /*dtd
2539     <!ELEMENT tpl:PingBlogName - O -- Trackback blog name -->
2540     */
2541     public function PingBlogName($attr)
2542     {
2543          $f = $this->getFilters($attr);
2544          return '<?php echo '.sprintf($f,'$_ctx->pings->comment_author').'; ?>';
2545     }
2546     
2547     /*dtd
2548     <!ELEMENT tpl:PingContent - O -- Trackback content -->
2549     */
2550     public function PingContent($attr)
2551     {
2552          $f = $this->getFilters($attr);
2553          return '<?php echo '.sprintf($f,'$_ctx->pings->getTrackbackContent()').'; ?>';
2554     }
2555     
2556     /*dtd
2557     <!ELEMENT tpl:PingDate - O -- Trackback date -->
2558     <!ATTLIST tpl:PingDate
2559     format    CDATA     #IMPLIED  -- date format (encoded in dc:str by default if iso8601 or rfc822 not specified)
2560     iso8601   CDATA     #IMPLIED  -- if set, tells that date format is ISO 8601
2561     rfc822    CDATA     #IMPLIED  -- if set, tells that date format is RFC 822
2562     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2563     >
2564     */
2565     public function PingDate($attr,$type='')
2566     {
2567          $format = '';
2568          if (!empty($attr['format'])) {
2569               $format = addslashes($attr['format']);
2570          }
2571         
2572          $iso8601 = !empty($attr['iso8601']);
2573          $rfc822 = !empty($attr['rfc822']);
2574          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2575         
2576          $f = $this->getFilters($attr);
2577         
2578          if ($rfc822) {
2579               return '<?php echo '.sprintf($f,"\$_ctx->pings->getRFC822Date('".$type."')").'; ?>';
2580          } elseif ($iso8601) {
2581               return '<?php echo '.sprintf($f,"\$_ctx->pings->getISO8601Date('".$type."')").'; ?>';
2582          } else {
2583               return '<?php echo '.sprintf($f,"\$_ctx->pings->getDate('".$format."','".$type."')").'; ?>';
2584          }
2585     }
2586     
2587     /*dtd
2588     <!ELEMENT tpl:PingTime - O -- Trackback date -->
2589     <!ATTLIST tpl:PingTime
2590     format    CDATA     #IMPLIED  -- time format
2591     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2592     >
2593     */
2594     public function PingTime($attr)
2595     {
2596          $format = '';
2597          if (!empty($attr['format'])) {
2598               $format = addslashes($attr['format']);
2599          }
2600          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2601         
2602          $f = $this->getFilters($attr);
2603          return '<?php echo '.sprintf($f,"\$_ctx->pings->getTime('".$format."','".$type."')").'; ?>';
2604     }
2605     
2606     /*dtd
2607     <!ELEMENT tpl:PingEntryTitle - O -- Trackback entry title -->
2608     */
2609     public function PingEntryTitle($attr)
2610     {
2611          $f = $this->getFilters($attr);
2612          return '<?php echo '.sprintf($f,'$_ctx->pings->post_title').'; ?>';
2613     }
2614     
2615     /*dtd
2616     <!ELEMENT tpl:PingFeedID - O -- Trackback feed ID -->
2617     */
2618     public function PingFeedID($attr)
2619     {
2620          $f = $this->getFilters($attr);
2621          return '<?php echo '.sprintf($f,'$_ctx->pings->getFeedID()').'; ?>';
2622     }
2623     
2624     /*dtd
2625     <!ELEMENT tpl:PingID - O -- Trackback ID -->
2626     */
2627     public function PingID($attr)
2628     {
2629          return '<?php echo $_ctx->pings->comment_id; ?>';
2630     }
2631     
2632     /*dtd
2633     <!ELEMENT tpl:PingIfFirst - O -- displays value if trackback is the first one -->
2634     <!ATTLIST tpl:PingIfFirst
2635     return    CDATA     #IMPLIED  -- value to display in case of success (default: first)
2636     >
2637     */
2638     public function PingIfFirst($attr)
2639     {
2640          $ret = isset($attr['return']) ? $attr['return'] : 'first';
2641          $ret = html::escapeHTML($ret);
2642         
2643          return
2644          '<?php if ($_ctx->pings->index() == 0) { '.
2645          "echo '".addslashes($ret)."'; } ?>";
2646     }
2647     
2648     /*dtd
2649     <!ELEMENT tpl:PingIfOdd - O -- displays value if trackback is  at an odd position -->
2650     <!ATTLIST tpl:PingIfOdd
2651     return    CDATA     #IMPLIED  -- value to display in case of success (default: odd)
2652     >
2653     */
2654     public function PingIfOdd($attr)
2655     {
2656          $ret = isset($attr['return']) ? $attr['return'] : 'odd';
2657          $ret = html::escapeHTML($ret);
2658         
2659          return
2660          '<?php if (($_ctx->pings->index()+1)%2) { '.
2661          "echo '".addslashes($ret)."'; } ?>";
2662     }
2663     
2664     /*dtd
2665     <!ELEMENT tpl:PingIP - O -- Trackback author IP -->
2666     */
2667     public function PingIP($attr)
2668     {
2669          return '<?php echo $_ctx->pings->comment_ip; ?>';
2670     }
2671     
2672     /*dtd
2673     <!ELEMENT tpl:PingNoFollow - O -- displays 'rel="nofollow"' if set in blog -->
2674     */
2675     public function PingNoFollow($attr)
2676     {
2677          return
2678          '<?php if($core->blog->settings->system->comments_nofollow) { '.
2679          'echo \' rel="nofollow"\';'.
2680          '} ?>';
2681     }
2682     
2683     /*dtd
2684     <!ELEMENT tpl:PingOrderNumber - O -- Trackback order in page -->
2685     */
2686     public function PingOrderNumber($attr)
2687     {
2688          return '<?php echo $_ctx->pings->index()+1; ?>';
2689     }
2690     
2691     /*dtd
2692     <!ELEMENT tpl:PingPostURL - O -- Trackback Entry URL -->
2693     */
2694     public function PingPostURL($attr)
2695     {
2696          $f = $this->getFilters($attr);
2697          return '<?php echo '.sprintf($f,'$_ctx->pings->getPostURL()').'; ?>';
2698     }
2699     
2700     /*dtd
2701     <!ELEMENT tpl:Pings - - -- Trackbacks container -->
2702     <!ATTLIST tpl:Pings
2703     with_pings     (0|1)     #IMPLIED  -- include trackbacks in request
2704     lastn     CDATA          #IMPLIED  -- restrict the number of entries
2705     no_context (1|0)         #IMPLIED  -- Override context information
2706     order     (desc|asc)     #IMPLIED  -- result ordering (default: asc)
2707     >
2708     */
2709     public function Pings($attr,$content)
2710     {
2711          $p =
2712          "if (\$_ctx->posts !== null) { ".
2713               "\$params['post_id'] = \$_ctx->posts->post_id; ".
2714               "\$core->blog->withoutPassword(false);\n".
2715          "}\n";
2716         
2717          $p .= "\$params['comment_trackback'] = true;\n";
2718         
2719          $lastn = 0;
2720          if (isset($attr['lastn'])) {
2721               $lastn = abs((integer) $attr['lastn'])+0;
2722          }
2723         
2724          if ($lastn > 0) {
2725               $p .= "\$params['limit'] = ".$lastn.";\n";
2726          } else {
2727               $p .= "if (\$_ctx->nb_comment_per_page !== null) { \$params['limit'] = \$_ctx->nb_comment_per_page; }\n";
2728          }
2729         
2730          if (empty($attr['no_context']))
2731          {
2732               $p .=
2733               'if ($_ctx->exists("categories")) { '.
2734                    "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
2735               "}\n";
2736               
2737               $p .=
2738               'if ($_ctx->exists("langs")) { '.
2739                    "\$params['sql'] = \"AND P.post_lang = '\".\$core->blog->con->escape(\$_ctx->langs->post_lang).\"' \"; ".
2740               "}\n";
2741          }
2742         
2743          $order = 'asc';
2744          if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) {
2745               $order = $attr['order'];
2746          }
2747         
2748          $p .= "\$params['order'] = 'comment_dt ".$order."';\n";
2749         
2750          if (isset($attr['no_content']) && $attr['no_content']) {
2751               $p .= "\$params['no_content'] = true;\n";
2752          }
2753         
2754          $res = "<?php\n";
2755          $res .= $p;
2756          $res .= $this->core->callBehavior("templatePrepareParams", 
2757               array("tag" => "Pings","method" => "blog::getComments"), 
2758               $attr,$content);
2759          $res .= '$_ctx->pings = $core->blog->getComments($params); unset($params);'."\n";
2760          $res .= "if (\$_ctx->posts !== null) { \$core->blog->withoutPassword(true);}\n";
2761          $res .= "?>\n";
2762         
2763          $res .=
2764          '<?php while ($_ctx->pings->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->pings = null; ?>';
2765         
2766          return $res;
2767     }
2768     
2769     /*dtd
2770     <!ELEMENT tpl:PingsFooter - - -- Last trackbacks result container -->
2771     */
2772     public function PingsFooter($attr,$content)
2773     {
2774          return
2775          "<?php if (\$_ctx->pings->isEnd()) : ?>".
2776          $content.
2777          "<?php endif; ?>";
2778     }
2779     
2780     /*dtd
2781     <!ELEMENT tpl:PingsHeader - - -- First trackbacks result container -->
2782     */
2783     public function PingsHeader($attr,$content)
2784     {
2785          return
2786          "<?php if (\$_ctx->pings->isStart()) : ?>".
2787          $content.
2788          "<?php endif; ?>";
2789     }
2790     
2791     /*dtd
2792     <!ELEMENT tpl:PingTitle - O -- Trackback title -->
2793     */
2794     public function PingTitle($attr)
2795     {
2796          $f = $this->getFilters($attr);
2797          return '<?php echo '.sprintf($f,'$_ctx->pings->getTrackbackTitle()').'; ?>';
2798     }
2799     
2800     /*dtd
2801     <!ELEMENT tpl:PingAuthorURL - O -- Trackback author URL -->
2802     */
2803     public function PingAuthorURL($attr)
2804     {
2805          $f = $this->getFilters($attr);
2806          return '<?php echo '.sprintf($f,'$_ctx->pings->getAuthorURL()').'; ?>';
2807     }
2808     
2809     # System
2810     /*dtd
2811     <!ELEMENT tpl:SysBehavior - O -- Call a given behavior -->
2812     <!ATTLIST tpl:SysBehavior
2813     behavior  CDATA     #IMPLIED  -- behavior to call
2814     >
2815     */
2816     public function SysBehavior($attr,$raw)
2817     {
2818          if (!isset($attr['behavior'])) {
2819               return;
2820          }
2821         
2822          $b = addslashes($attr['behavior']);
2823          return
2824          '<?php if ($core->hasBehavior(\''.$b.'\')) { '.
2825               '$core->callBehavior(\''.$b.'\',$core,$_ctx);'.
2826          '} ?>';
2827     }
2828     
2829     /*dtd
2830     <!ELEMENT tpl:SysIf - - -- System settings tester container -->
2831     <!ATTLIST tpl:SysIf
2832     categories          (0|1)     #IMPLIED  -- test if categories are set in current context (value : 1) or not (value : 0)
2833     posts               (0|1)     #IMPLIED  -- test if posts are set in current context (value : 1) or not (value : 0)
2834     blog_lang           CDATA     #IMPLIED  -- tests if blog language is the one given in parameter
2835     current_tpl         CDATA     #IMPLIED  -- tests if current template is the one given in paramater
2836     current_mode        CDATA     #IMPLIED  -- tests if current URL mode is the one given in parameter
2837     has_tpl             CDATA     #IMPLIED  -- tests if a named template exists
2838     has_tag             CDATA     #IMPLIED  -- tests if a named template block or value exists
2839     blog_id             CDATA     #IMPLIED  -- tests if current blog ID is the one given in parameter
2840     comments_active     (0|1)     #IMPLIED  -- test if comments are enabled blog-wide
2841     pings_active        (0|1)     #IMPLIED  -- test if trackbacks are enabled blog-wide
2842     wiki_comments       (0|1)     #IMPLIED  -- test if wiki syntax is enabled for comments
2843     operator            (and|or)  #IMPLIED  -- combination of conditions, if more than 1 specifiec (default: and)
2844     >
2845     */
2846     public function SysIf($attr,$content)
2847     {
2848          $if = new ArrayObject();
2849          $is_ping = null;
2850         
2851          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';
2852         
2853          if (isset($attr['categories'])) {
2854               $sign = (boolean) $attr['categories'] ? '!' : '=';
2855               $if[] = '$_ctx->categories '.$sign.'== null';
2856          }
2857         
2858          if (isset($attr['posts'])) {
2859               $sign = (boolean) $attr['posts'] ? '!' : '=';
2860               $if[] = '$_ctx->posts '.$sign.'== null';
2861          }
2862         
2863          if (isset($attr['blog_lang'])) {
2864               $if[] = "\$core->blog->settings->system->lang == '".addslashes($attr['blog_lang'])."'";
2865          }
2866         
2867          if (isset($attr['current_tpl'])) {
2868               $sign = '=';
2869               if (substr($attr['current_tpl'],0,1) == '!') {
2870                    $sign = '!';
2871                    $attr['current_tpl'] = substr($attr['current_tpl'],1);
2872               }
2873               $if[] = "\$_ctx->current_tpl ".$sign."= '".addslashes($attr['current_tpl'])."'";
2874          }
2875         
2876          if (isset($attr['current_mode'])) {
2877               $sign = '=';
2878               if (substr($attr['current_mode'],0,1) == '!') {
2879                    $sign = '!';
2880                    $attr['current_mode'] = substr($attr['current_mode'],1);
2881               }
2882               $if[] = "\$core->url->type ".$sign."= '".addslashes($attr['current_mode'])."'";
2883          }
2884         
2885          if (isset($attr['has_tpl'])) {
2886               $sign = '';
2887               if (substr($attr['has_tpl'],0,1) == '!') {
2888                    $sign = '!';
2889                    $attr['has_tpl'] = substr($attr['has_tpl'],1);
2890               }
2891               $if[] = $sign."\$core->tpl->getFilePath('".addslashes($attr['has_tpl'])."') !== false";
2892          }
2893         
2894          if (isset($attr['has_tag'])) {
2895               $sign = 'true';
2896               if (substr($attr['has_tag'],0,1) == '!') {
2897                    $sign = 'false';
2898                    $attr['has_tag'] = substr($attr['has_tag'],1);
2899               }
2900               $if[] =  "\$core->tpl->tagExists('".addslashes($attr['has_tag'])."') === ".$sign;
2901          }
2902         
2903          if (isset($attr['blog_id'])) {
2904               $sign = '';
2905               if (substr($attr['blog_id'],0,1) == '!') {
2906                    $sign = '!';
2907                    $attr['blog_id'] = substr($attr['blog_id'],1);
2908               }
2909               $if[] = $sign."(\$core->blog->id == '".addslashes($attr['blog_id'])."')";
2910          }
2911         
2912          if (isset($attr['comments_active'])) {
2913               $sign = (boolean) $attr['comments_active'] ? '' : '!';
2914               $if[] = $sign.'$core->blog->settings->system->allow_comments';
2915          }
2916         
2917          if (isset($attr['pings_active'])) {
2918               $sign = (boolean) $attr['pings_active'] ? '' : '!';
2919               $if[] = $sign.'$core->blog->settings->system->allow_trackbacks';
2920          }
2921       
2922          if (isset($attr['wiki_comments'])) {
2923               $sign = (boolean) $attr['wiki_comments'] ? '' : '!';
2924               $if[] = $sign.'$core->blog->settings->system->wiki_comments';
2925          }
2926         
2927          if (isset($attr['search_count']) &&
2928               preg_match('/^((=|!|&gt;|&lt;)=|(&gt;|&lt;))\s*[0-9]+$/',trim($attr['search_count']))) {
2929               $if[] = '(isset($_search_count) && $_search_count '.html::decodeEntities($attr['search_count']).')';
2930          }
2931         
2932          $this->core->callBehavior('tplIfConditions','SysIf',$attr,$content,$if);
2933         
2934          if (count($if) != 0) {
2935               return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
2936          } else {
2937               return $content;
2938          }
2939     }
2940     
2941     /*dtd
2942     <!ELEMENT tpl:SysIfCommentPublished - - -- Container displayed if comment has been published -->
2943     */
2944     public function SysIfCommentPublished($attr,$content)
2945     {
2946          return
2947          '<?php if (!empty($_GET[\'pub\'])) : ?>'.
2948          $content.
2949          '<?php endif; ?>';
2950     }
2951     
2952     /*dtd
2953     <!ELEMENT tpl:SysIfCommentPending - - -- Container displayed if comment is pending after submission -->
2954     */
2955     public function SysIfCommentPending($attr,$content)
2956     {
2957          return
2958          '<?php if (isset($_GET[\'pub\']) && $_GET[\'pub\'] == 0) : ?>'.
2959          $content.
2960          '<?php endif; ?>';
2961     }
2962     
2963     /*dtd
2964     <!ELEMENT tpl:SysFeedSubtitle - O -- Feed subtitle -->
2965     */
2966     public function SysFeedSubtitle($attr)
2967     {
2968          $f = $this->getFilters($attr);
2969          return '<?php if ($_ctx->feed_subtitle !== null) { echo '.sprintf($f,'$_ctx->feed_subtitle').';} ?>';
2970     }
2971     
2972     /*dtd
2973     <!ELEMENT tpl:SysIfFormError - O -- Container displayed if an error has been detected after form submission -->
2974     */
2975     public function SysIfFormError($attr,$content)
2976     {
2977          return
2978          '<?php if ($_ctx->form_error !== null) : ?>'.
2979          $content.
2980          '<?php endif; ?>';
2981     }
2982     
2983     /*dtd
2984     <!ELEMENT tpl:SysFormError - O -- Form error -->
2985     */
2986     public function SysFormError($attr)
2987     {
2988          return
2989          '<?php if ($_ctx->form_error !== null) { echo $_ctx->form_error; } ?>';
2990     }
2991     
2992     public function SysPoweredBy($attr)
2993     {
2994          return
2995          '<?php printf(__("Powered by %s"),"<a href=\"http://dotclear.org/\">Dotclear</a>"); ?>';
2996     }
2997     
2998     public function SysSearchString($attr)
2999     {
3000          $s = isset($attr['string']) ? $attr['string'] : '%1$s';
3001         
3002          $f = $this->getFilters($attr);
3003          return '<?php if (isset($_search)) { echo sprintf(__(\''.$s.'\'),'.sprintf($f,'$_search').',$_search_count);} ?>';
3004     }
3005     
3006     public function SysSelfURI($attr)
3007     {
3008          $f = $this->getFilters($attr);
3009          return '<?php echo '.sprintf($f,'http::getSelfURI()').'; ?>';
3010     }
3011
3012     /*dtd
3013     <!ELEMENT tpl:else - O -- else: statement -->
3014     */
3015     public function GenericElse($attr)
3016     {
3017          return '<?php else: ?>';
3018     }
3019}
3020
3021# Template nodes, for parsing purposes
3022
3023# Generic list node, this one may only be instanciated
3024# once for root element
3025class tplNode 
3026{
3027     # Basic tree structure : links to parent, children forrest
3028     protected $parentNode;
3029     protected $children;
3030     
3031     public function __construct() {
3032          $this->children = array();
3033          $this->parentNode = null;
3034     }
3035     
3036     // Returns compiled block
3037     public function compile($tpl) {
3038          $res='';
3039          foreach ($this->children as $child) {
3040               $res .= $child->compile($tpl);
3041          }
3042          return $res;
3043     }
3044     
3045     # Add a children to current node
3046     public function addChild ($child) {
3047          $this->children[] = $child;
3048          $child->setParent($this);
3049     }
3050     
3051     # Defines parent for current node
3052     protected function setParent($parent) {
3053          $this->parentNode = $parent;
3054     }
3055     
3056     # Retrieves current node parent.
3057     # If parent is root node, null is returned
3058     public function getParent() {
3059          return $this->parentNode;
3060     }
3061     
3062     # Current node tag
3063     public function getTag() {
3064          return "ROOT";
3065     }
3066}
3067
3068// Text node, for any non-tpl content
3069class tplNodeText extends tplNode 
3070{
3071     // Simple text node, only holds its content
3072     protected $content;
3073     
3074     public function __construct($text) {
3075          parent::__construct();
3076          $this->content=$text;
3077     }
3078     
3079     public function compile($tpl) {
3080          return $this->content;
3081     }
3082     
3083     public function getTag() {
3084          return "TEXT";
3085     }
3086}
3087
3088// Block node, for all <tpl:Tag>...</tpl:Tag>
3089class tplNodeBlock extends tplNode 
3090{
3091     protected $attr;
3092     protected $tag;
3093     protected $closed;
3094   
3095     public function __construct($tag,$attr) {
3096          parent::__construct();
3097          $this->content='';
3098          $this->tag = $tag;
3099          $this->attr = $attr;
3100          $this->closed=false;
3101     }
3102     public function setClosing() {
3103          $this->closed = true;
3104     }
3105     public function isClosed() {
3106          return $this->closed;
3107     }
3108     public function compile($tpl) {
3109          if ($this->closed) {
3110               $content = parent::compile($tpl);
3111               return $tpl->compileBlockNode($this->tag,$this->attr,$content);
3112          } else {
3113               // if tag has not been closed, silently ignore its content...
3114               return '';
3115          }
3116     }
3117     public function getTag() {
3118          return $this->tag;
3119     }
3120}
3121
3122// Value node, for all {{tpl:Tag}}
3123class tplNodeValue extends tplNode 
3124{
3125     protected $attr;
3126     protected $str_attr;
3127     protected $tag;
3128     
3129     public function __construct($tag,$attr,$str_attr) {
3130          parent::__construct();
3131          $this->content='';
3132          $this->tag = $tag;
3133          $this->attr = $attr;
3134          $this->str_attr = $str_attr;
3135     }
3136     
3137     public function compile($tpl) {
3138          return $tpl->compileValueNode($this->tag,$this->attr,$this->str_attr);
3139     }
3140     
3141     public function getTag() {
3142          return $this->tag;
3143     }
3144}
3145
3146?>
Note: See TracBrowser for help on using the repository browser.

Sites map