Dotclear

source: inc/public/class.dc.template.php @ 776:4ce635c0ca26

Revision 776:4ce635c0ca26, 89.4 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

Last updates to getURLFor : removed blog url from function

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

Sites map