Dotclear

source: inc/public/class.dc.template.php @ 2863:c14573122523

Revision 2863:c14573122523, 91.0 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Nb of post displayed on home page (first page) should not be applied on first pages of other contexts (tags, category, search, …) : fixed

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

Sites map