Dotclear

source: inc/public/class.dc.template.php @ 2800:92f82976773e

Revision 2800:92f82976773e, 90.6 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Add a jQuery js library selector in blog pref, closes #1897

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 .= "\$params['limit'] = (\$_page_number == 1 ? \$_ctx->nb_entry_first_page : \$_ctx->nb_entry_per_page);\n";
1123               }
1124               // Set offset (aka index of first entry)
1125               if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0") {
1126                    // standard pagination, set offset
1127                    $p .= "\$params['limit'] = array((\$_page_number == 1 ? 0 : (\$_page_number - 2) * \$_ctx->nb_entry_per_page + \$_ctx->nb_entry_first_page),\$params['limit']);\n";
1128               } else {
1129                    // no pagination, get all posts from 0 to limit
1130                    $p .= "\$params['limit'] = array(0, \$params['limit']);\n";
1131               }
1132          }
1133
1134          if (isset($attr['author'])) {
1135               $p .= "\$params['user_id'] = '".addslashes($attr['author'])."';\n";
1136          }
1137
1138          if (isset($attr['category'])) {
1139               $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";
1140               $p .= "context::categoryPostParam(\$params);\n";
1141          }
1142
1143          if (isset($attr['no_category']) && $attr['no_category']) {
1144               $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n";
1145               $p .= "unset(\$params['cat_url']);\n";
1146          }
1147
1148          if (!empty($attr['type'])) {
1149               $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
1150          }
1151
1152          if (!empty($attr['url'])) {
1153               $p .= "\$params['post_url'] = '".addslashes($attr['url'])."';\n";
1154          }
1155
1156          if (empty($attr['no_context']))
1157          {
1158               if (!isset($attr['author']))
1159               {
1160                    $p .=
1161                    'if ($_ctx->exists("users")) { '.
1162                         "\$params['user_id'] = \$_ctx->users->user_id; ".
1163                    "}\n";
1164               }
1165
1166               if (!isset($attr['category']) && (!isset($attr['no_category']) || !$attr['no_category']))
1167               {
1168                    $p .=
1169                    'if ($_ctx->exists("categories")) { '.
1170                         "\$params['cat_id'] = \$_ctx->categories->cat_id.(\$core->blog->settings->system->inc_subcats?' ?sub':'');".
1171                    "}\n";
1172               }
1173
1174               $p .=
1175               'if ($_ctx->exists("archives")) { '.
1176                    "\$params['post_year'] = \$_ctx->archives->year(); ".
1177                    "\$params['post_month'] = \$_ctx->archives->month(); ";
1178               if (!isset($attr['lastn'])) {
1179                    $p .= "unset(\$params['limit']); ";
1180               }
1181               $p .=
1182               "}\n";
1183
1184               $p .=
1185               'if ($_ctx->exists("langs")) { '.
1186                    "\$params['post_lang'] = \$_ctx->langs->post_lang; ".
1187               "}\n";
1188
1189               $p .=
1190               'if (isset($_search)) { '.
1191                    "\$params['search'] = \$_search; ".
1192               "}\n";
1193          }
1194
1195          $p .= "\$params['order'] = '".$this->getSortByStr($attr,'post')."';\n";
1196
1197          if (isset($attr['no_content']) && $attr['no_content']) {
1198               $p .= "\$params['no_content'] = true;\n";
1199          }
1200
1201          if (isset($attr['selected'])) {
1202               $p .= "\$params['post_selected'] = ".(integer) (boolean) $attr['selected'].";";
1203          }
1204
1205          if (isset($attr['age'])) {
1206               $age = $this->getAge($attr);
1207               $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : '';
1208          }
1209
1210          $res = "<?php\n";
1211          $res .= $p;
1212          $res .= $this->core->callBehavior("templatePrepareParams",
1213               array("tag" => "Entries","method" => "blog::getPosts"),
1214               $attr,$content);
1215          $res .= '$_ctx->post_params = $params;'."\n";
1216          $res .= '$_ctx->posts = $core->blog->getPosts($params); unset($params);'."\n";
1217          $res .= "?>\n";
1218          $res .=
1219          '<?php while ($_ctx->posts->fetch()) : ?>'.$content.'<?php endwhile; '.
1220          '$_ctx->posts = null; $_ctx->post_params = null; ?>';
1221
1222          return $res;
1223     }
1224
1225     /*dtd
1226     <!ELEMENT tpl:DateHeader - O -- Displays date, if post is the first post of the given day -->
1227     */
1228     public function DateHeader($attr,$content)
1229     {
1230          return
1231          "<?php if (\$_ctx->posts->firstPostOfDay()) : ?>".
1232          $content.
1233          "<?php endif; ?>";
1234     }
1235
1236     /*dtd
1237     <!ELEMENT tpl:DateFooter - O -- Displays date,  if post is the last post of the given day -->
1238     */
1239     public function DateFooter($attr,$content)
1240     {
1241          return
1242          "<?php if (\$_ctx->posts->lastPostOfDay()) : ?>".
1243          $content.
1244          "<?php endif; ?>";
1245     }
1246
1247     /*dtd
1248     <!ELEMENT tpl:EntryIf - - -- tests on current entry -->
1249     <!ATTLIST tpl:EntryIf
1250     type CDATA     #IMPLIED  -- post has a given type (default: "post")
1251     category  CDATA     #IMPLIED  -- post has a given category
1252     first     (0|1)     #IMPLIED  -- post is the first post from list (value : 1) or not (value : 0)
1253     odd  (0|1)     #IMPLIED  -- post is in an odd position (value : 1) or not (value : 0)
1254     even (0|1)     #IMPLIED  -- post is in an even position (value : 1) or not (value : 0)
1255     extended  (0|1)     #IMPLIED  -- post has an excerpt (value : 1) or not (value : 0)
1256     selected  (0|1)     #IMPLIED  -- post is selected (value : 1) or not (value : 0)
1257     has_category   (0|1)     #IMPLIED  -- post has a category (value : 1) or not (value : 0)
1258     has_attachment (0|1)     #IMPLIED  -- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code)
1259     comments_active     (0|1)     #IMPLIED  -- comments are active for this post (value : 1) or not (value : 0)
1260     pings_active   (0|1)     #IMPLIED  -- trackbacks are active for this post (value : 1) or not (value : 0)
1261     show_comments  (0|1)     #IMPLIED  -- there are comments for this post (value : 1) or not (value : 0)
1262     show_pings     (0|1)     #IMPLIED  -- there are trackbacks for this post (value : 1) or not (value : 0)
1263     republished    (0|1)     #IMPLIED  -- post has been updated since publication (value : 1) or not (value : 0)
1264     operator  (and|or)  #IMPLIED  -- combination of conditions, if more than 1 specifiec (default: and)
1265     url       CDATA     #IMPLIED  -- post has given url
1266     >
1267     */
1268     public function EntryIf($attr,$content)
1269     {
1270          $if = new ArrayObject();
1271          $extended = null;
1272          $hascategory = null;
1273
1274          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';
1275
1276          if (isset($attr['type'])) {
1277               $type = trim($attr['type']);
1278               $type = !empty($type)?$type:'post';
1279               $if[] = '$_ctx->posts->post_type == "'.addslashes($type).'"';
1280          }
1281
1282          if (isset($attr['url'])) {
1283               $url = trim($attr['url']);
1284               if (substr($url,0,1) == '!') {
1285                    $url = substr($url,1);
1286                    $if[] = '$_ctx->posts->post_url != "'.addslashes($url).'"';
1287               } else {
1288                    $if[] = '$_ctx->posts->post_url == "'.addslashes($url).'"';
1289               }
1290          }
1291
1292          if (isset($attr['category'])) {
1293               $category = addslashes(trim($attr['category']));
1294               if (substr($category,0,1) == '!') {
1295                    $category = substr($category,1);
1296                    $if[] = '($_ctx->posts->cat_url != "'.$category.'")';
1297               } else {
1298                    $if[] = '($_ctx->posts->cat_url == "'.$category.'")';
1299               }
1300          }
1301
1302          if (isset($attr['first'])) {
1303               $sign = (boolean) $attr['first'] ? '=' : '!';
1304               $if[] = '$_ctx->posts->index() '.$sign.'= 0';
1305          }
1306
1307          if (isset($attr['odd'])) {
1308               $sign = (boolean) $attr['odd'] ? '=' : '!';
1309               $if[] = '($_ctx->posts->index()+1)%2 '.$sign.'= 1';
1310          }
1311
1312          if (isset($attr['extended'])) {
1313               $sign = (boolean) $attr['extended'] ? '' : '!';
1314               $if[] = $sign.'$_ctx->posts->isExtended()';
1315          }
1316
1317          if (isset($attr['selected'])) {
1318               $sign = (boolean) $attr['selected'] ? '' : '!';
1319               $if[] = $sign.'(boolean)$_ctx->posts->post_selected';
1320          }
1321
1322          if (isset($attr['has_category'])) {
1323               $sign = (boolean) $attr['has_category'] ? '' : '!';
1324               $if[] = $sign.'$_ctx->posts->cat_id';
1325          }
1326
1327          if (isset($attr['comments_active'])) {
1328               $sign = (boolean) $attr['comments_active'] ? '' : '!';
1329               $if[] = $sign.'$_ctx->posts->commentsActive()';
1330          }
1331
1332          if (isset($attr['pings_active'])) {
1333               $sign = (boolean) $attr['pings_active'] ? '' : '!';
1334               $if[] = $sign.'$_ctx->posts->trackbacksActive()';
1335          }
1336
1337          if (isset($attr['has_comment'])) {
1338               $sign = (boolean) $attr['has_comment'] ? '' : '!';
1339               $if[] = $sign.'$_ctx->posts->hasComments()';
1340          }
1341
1342          if (isset($attr['has_ping'])) {
1343               $sign = (boolean) $attr['has_ping'] ? '' : '!';
1344               $if[] = $sign.'$_ctx->posts->hasTrackbacks()';
1345          }
1346
1347          if (isset($attr['show_comments'])) {
1348               if ((boolean) $attr['show_comments']) {
1349                    $if[] = '($_ctx->posts->hasComments() || $_ctx->posts->commentsActive())';
1350               } else {
1351                    $if[] = '(!$_ctx->posts->hasComments() && !$_ctx->posts->commentsActive())';
1352               }
1353          }
1354
1355          if (isset($attr['show_pings'])) {
1356               if ((boolean) $attr['show_pings']) {
1357                    $if[] = '($_ctx->posts->hasTrackbacks() || $_ctx->posts->trackbacksActive())';
1358               } else {
1359                    $if[] = '(!$_ctx->posts->hasTrackbacks() && !$_ctx->posts->trackbacksActive())';
1360               }
1361          }
1362
1363          if (isset($attr['republished'])) {
1364               $sign = (boolean) $attr['republished'] ? '' : '!';
1365               $if[] = $sign.'(boolean)$_ctx->posts->isRepublished()';
1366          }
1367
1368          $this->core->callBehavior('tplIfConditions','EntryIf',$attr,$content,$if);
1369
1370          if (count($if) != 0) {
1371               return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
1372          } else {
1373               return $content;
1374          }
1375     }
1376
1377     /*dtd
1378     <!ELEMENT tpl:EntryIfFirst - O -- displays value if entry is the first one -->
1379     <!ATTLIST tpl:EntryIfFirst
1380     return    CDATA     #IMPLIED  -- value to display in case of success (default: first)
1381     >
1382     */
1383     public function EntryIfFirst($attr)
1384     {
1385          $ret = isset($attr['return']) ? $attr['return'] : 'first';
1386          $ret = html::escapeHTML($ret);
1387
1388          return
1389          '<?php if ($_ctx->posts->index() == 0) { '.
1390          "echo '".addslashes($ret)."'; } ?>";
1391     }
1392
1393     /*dtd
1394     <!ELEMENT tpl:EntryIfOdd - O -- displays value if entry is in an odd position -->
1395     <!ATTLIST tpl:EntryIfOdd
1396     return    CDATA     #IMPLIED  -- value to display in case of success (default: odd)
1397     >
1398     */
1399     public function EntryIfOdd($attr)
1400     {
1401          $ret = isset($attr['return']) ? $attr['return'] : 'odd';
1402          $ret = html::escapeHTML($ret);
1403
1404          return
1405          '<?php if (($_ctx->posts->index()+1)%2 == 1) { '.
1406          "echo '".addslashes($ret)."'; } ?>";
1407     }
1408
1409     /*dtd
1410     <!ELEMENT tpl:EntryIfSelected - O -- displays value if entry is selected -->
1411     <!ATTLIST tpl:EntryIfSelected
1412     return    CDATA     #IMPLIED  -- value to display in case of success (default: selected)
1413     >
1414     */
1415     public function EntryIfSelected($attr)
1416     {
1417          $ret = isset($attr['return']) ? $attr['return'] : 'selected';
1418          $ret = html::escapeHTML($ret);
1419
1420          return
1421          '<?php if ($_ctx->posts->post_selected) { '.
1422          "echo '".addslashes($ret)."'; } ?>";
1423     }
1424
1425     /*dtd
1426     <!ELEMENT tpl:EntryContent - O -- Entry content -->
1427     <!ATTLIST tpl:EntryContent
1428     absolute_urls  CDATA     #IMPLIED -- transforms local URLs to absolute one
1429     full           (1|0)     #IMPLIED -- returns full content with excerpt
1430     >
1431     */
1432     public function EntryContent($attr)
1433     {
1434          $urls = '0';
1435          if (!empty($attr['absolute_urls'])) {
1436               $urls = '1';
1437          }
1438
1439          $f = $this->getFilters($attr);
1440
1441          if (!empty($attr['full'])) {
1442               return '<?php echo '.sprintf($f,
1443                    '$_ctx->posts->getExcerpt('.$urls.')." ".$_ctx->posts->getContent('.$urls.')').'; ?>';
1444          } else {
1445               return '<?php echo '.sprintf($f,'$_ctx->posts->getContent('.$urls.')').'; ?>';
1446          }
1447     }
1448
1449     /*dtd
1450     <!ELEMENT tpl:EntryExcerpt - O -- Entry excerpt -->
1451     <!ATTLIST tpl:EntryExcerpt
1452     absolute_urls  CDATA     #IMPLIED -- transforms local URLs to absolute one
1453     >
1454     */
1455     public function EntryExcerpt($attr)
1456     {
1457          $urls = '0';
1458          if (!empty($attr['absolute_urls'])) {
1459               $urls = '1';
1460          }
1461
1462          $f = $this->getFilters($attr);
1463          return '<?php echo '.sprintf($f,'$_ctx->posts->getExcerpt('.$urls.')').'; ?>';
1464     }
1465
1466
1467     /*dtd
1468     <!ELEMENT tpl:EntryAuthorCommonName - O -- Entry author common name -->
1469     */
1470     public function EntryAuthorCommonName($attr)
1471     {
1472          $f = $this->getFilters($attr);
1473          return '<?php echo '.sprintf($f,'$_ctx->posts->getAuthorCN()').'; ?>';
1474     }
1475
1476     /*dtd
1477     <!ELEMENT tpl:EntryAuthorDisplayName - O -- Entry author display name -->
1478     */
1479     public function EntryAuthorDisplayName($attr)
1480     {
1481          $f = $this->getFilters($attr);
1482          return '<?php echo '.sprintf($f,'$_ctx->posts->user_displayname').'; ?>';
1483     }
1484
1485     /*dtd
1486     <!ELEMENT tpl:EntryAuthorID - O -- Entry author ID -->
1487     */
1488     public function EntryAuthorID($attr)
1489     {
1490          $f = $this->getFilters($attr);
1491          return '<?php echo '.sprintf($f,'$_ctx->posts->user_id').'; ?>';
1492     }
1493
1494     /*dtd
1495     <!ELEMENT tpl:EntryAuthorEmail - O -- Entry author email -->
1496     <!ATTLIST tpl:EntryAuthorEmail
1497     spam_protected (0|1)     #IMPLIED  -- protect email from spam (default: 1)
1498     >
1499     */
1500     public function EntryAuthorEmail($attr)
1501     {
1502          $p = 'true';
1503          if (isset($attr['spam_protected']) && !$attr['spam_protected']) {
1504               $p = 'false';
1505          }
1506
1507          $f = $this->getFilters($attr);
1508          return '<?php echo '.sprintf($f,"\$_ctx->posts->getAuthorEmail(".$p.")").'; ?>';
1509     }
1510
1511     /*dtd
1512     <!ELEMENT tpl:EntryAuthorLink - O -- Entry author link -->
1513     */
1514     public function EntryAuthorLink($attr)
1515     {
1516          $f = $this->getFilters($attr);
1517          return '<?php echo '.sprintf($f,'$_ctx->posts->getAuthorLink()').'; ?>';
1518     }
1519
1520     /*dtd
1521     <!ELEMENT tpl:EntryAuthorURL - O -- Entry author URL -->
1522     */
1523     public function EntryAuthorURL($attr)
1524     {
1525          $f = $this->getFilters($attr);
1526          return '<?php echo '.sprintf($f,'$_ctx->posts->user_url').'; ?>';
1527     }
1528
1529     /*dtd
1530     <!ELEMENT tpl:EntryBasename - O -- Entry short URL (relative to /post) -->
1531     */
1532     public function EntryBasename($attr)
1533     {
1534          $f = $this->getFilters($attr);
1535          return '<?php echo '.sprintf($f,'$_ctx->posts->post_url').'; ?>';
1536     }
1537
1538     /*dtd
1539     <!ELEMENT tpl:EntryCategory - O -- Entry category (full name) -->
1540     */
1541     public function EntryCategory($attr)
1542     {
1543          $f = $this->getFilters($attr);
1544          return '<?php echo '.sprintf($f,'$_ctx->posts->cat_title').'; ?>';
1545     }
1546
1547     /*dtd
1548     <!ELEMENT tpl:EntryCategoriesBreadcrumb - - -- Current entry parents loop (without last one) -->
1549     */
1550     public function EntryCategoriesBreadcrumb($attr,$content)
1551     {
1552          return
1553          "<?php\n".
1554          '$_ctx->categories = $core->blog->getCategoryParents($_ctx->posts->cat_id);'."\n".
1555          'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';
1556     }
1557
1558     /*dtd
1559     <!ELEMENT tpl:EntryCategoryID - O -- Entry category ID -->
1560     */
1561     public function EntryCategoryID($attr)
1562     {
1563          $f = $this->getFilters($attr);
1564          return '<?php echo '.sprintf($f,'$_ctx->posts->cat_id').'; ?>';
1565     }
1566
1567     /*dtd
1568     <!ELEMENT tpl:EntryCategoryURL - O -- Entry category URL -->
1569     */
1570     public function EntryCategoryURL($attr)
1571     {
1572          $f = $this->getFilters($attr);
1573          return '<?php echo '.sprintf($f,'$_ctx->posts->getCategoryURL()').'; ?>';
1574     }
1575
1576     /*dtd
1577     <!ELEMENT tpl:EntryCategoryShortURL - O -- Entry category short URL (relative URL, from /category/) -->
1578     */
1579     public function EntryCategoryShortURL($attr)
1580     {
1581          $f = $this->getFilters($attr);
1582          return '<?php echo '.sprintf($f,'$_ctx->posts->cat_url').'; ?>';
1583     }
1584
1585
1586     /*dtd
1587     <!ELEMENT tpl:EntryFeedID - O -- Entry feed ID -->
1588     */
1589     public function EntryFeedID($attr)
1590     {
1591          $f = $this->getFilters($attr);
1592          return '<?php echo '.sprintf($f,'$_ctx->posts->getFeedID()').'; ?>';
1593     }
1594
1595     /*dtd
1596     <!ELEMENT tpl:EntryFirstImage - O -- Extracts entry first image if exists -->
1597     <!ATTLIST tpl:EntryAuthorEmail
1598     size           (sq|t|s|m|o)   #IMPLIED  -- Image size to extract
1599     class          CDATA          #IMPLIED  -- Class to add on image tag
1600     with_category  (1|0)          #IMPLIED  -- Search in entry category description if present (default 0)
1601     no_tag    (1|0)     #IMPLIED  -- Return image URL without HTML tag (default 0)
1602     content_only   (1|0)          #IMPLIED  -- Search in content entry only, not in excerpt (default 0)
1603     cat_only  (1|0)          #IMPLIED  -- Search in category description only (default 0)
1604     >
1605     */
1606     public function EntryFirstImage($attr)
1607     {
1608          $size = !empty($attr['size']) ? $attr['size'] : '';
1609          $class = !empty($attr['class']) ? $attr['class'] : '';
1610          $with_category = !empty($attr['with_category']) ? 1 : 0;
1611          $no_tag = !empty($attr['no_tag']) ? 1 : 0;
1612          $content_only = !empty($attr['content_only']) ? 1 : 0;
1613          $cat_only = !empty($attr['cat_only']) ? 1 : 0;
1614
1615          return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."',".$with_category.",'".addslashes($class)."',".
1616               $no_tag.",".$content_only.",".$cat_only."); ?>";
1617     }
1618
1619     /*dtd
1620     <!ELEMENT tpl:EntryID - O -- Entry ID -->
1621     */
1622     public function EntryID($attr)
1623     {
1624          $f = $this->getFilters($attr);
1625          return '<?php echo '.sprintf($f,'$_ctx->posts->post_id').'; ?>';
1626     }
1627
1628     /*dtd
1629     <!ELEMENT tpl:EntryLang - O --  Entry language or blog lang if not defined -->
1630     */
1631     public function EntryLang($attr)
1632     {
1633          $f = $this->getFilters($attr);
1634          return
1635          '<?php if ($_ctx->posts->post_lang) { '.
1636               'echo '.sprintf($f,'$_ctx->posts->post_lang').'; '.
1637          '} else {'.
1638               'echo '.sprintf($f,'$core->blog->settings->system->lang').'; '.
1639          '} ?>';
1640     }
1641
1642     /*dtd
1643     <!ELEMENT tpl:EntryNext - - -- Next entry block -->
1644     <!ATTLIST tpl:EntryNext
1645     restrict_to_category     (0|1)     #IMPLIED  -- find next post in the same category (default: 0)
1646     restrict_to_lang         (0|1)     #IMPLIED  -- find next post in the same language (default: 0)
1647     >
1648     */
1649     public function EntryNext($attr,$content)
1650     {
1651          $restrict_to_category = !empty($attr['restrict_to_category']) ? '1' : '0';
1652          $restrict_to_lang = !empty($attr['restrict_to_lang']) ? '1' : '0';
1653
1654          return
1655          '<?php $next_post = $core->blog->getNextPost($_ctx->posts,1,'.$restrict_to_category.','.$restrict_to_lang.'); ?>'."\n".
1656          '<?php if ($next_post !== null) : ?>'.
1657
1658               '<?php $_ctx->posts = $next_post; unset($next_post);'."\n".
1659               'while ($_ctx->posts->fetch()) : ?>'.
1660               $content.
1661               '<?php endwhile; $_ctx->posts = null; ?>'.
1662          "<?php endif; ?>\n";
1663     }
1664
1665     /*dtd
1666     <!ELEMENT tpl:EntryPrevious - - -- Previous entry block -->
1667     <!ATTLIST tpl:EntryPrevious
1668     restrict_to_category     (0|1)     #IMPLIED  -- find previous post in the same category (default: 0)
1669     restrict_to_lang         (0|1)     #IMPLIED  -- find next post in the same language (default: 0)
1670     >
1671     */
1672     public function EntryPrevious($attr,$content)
1673     {
1674          $restrict_to_category = !empty($attr['restrict_to_category']) ? '1' : '0';
1675          $restrict_to_lang = !empty($attr['restrict_to_lang']) ? '1' : '0';
1676
1677          return
1678          '<?php $prev_post = $core->blog->getNextPost($_ctx->posts,-1,'.$restrict_to_category.','.$restrict_to_lang.'); ?>'."\n".
1679          '<?php if ($prev_post !== null) : ?>'.
1680
1681               '<?php $_ctx->posts = $prev_post; unset($prev_post);'."\n".
1682               'while ($_ctx->posts->fetch()) : ?>'.
1683               $content.
1684               '<?php endwhile; $_ctx->posts = null; ?>'.
1685          "<?php endif; ?>\n";
1686     }
1687
1688     /*dtd
1689     <!ELEMENT tpl:EntryTitle - O -- Entry title -->
1690     */
1691     public function EntryTitle($attr)
1692     {
1693          $f = $this->getFilters($attr);
1694          return '<?php echo '.sprintf($f,'$_ctx->posts->post_title').'; ?>';
1695     }
1696
1697     /*dtd
1698     <!ELEMENT tpl:EntryURL - O -- Entry URL -->
1699     */
1700     public function EntryURL($attr)
1701     {
1702          $f = $this->getFilters($attr);
1703          return '<?php echo '.sprintf($f,'$_ctx->posts->getURL()').'; ?>';
1704     }
1705
1706     /*dtd
1707     <!ELEMENT tpl:EntryDate - O -- Entry date -->
1708     <!ATTLIST tpl:EntryDate
1709     format    CDATA     #IMPLIED  -- date format (encoded in dc:str by default if iso8601 or rfc822 not specified)
1710     iso8601   CDATA     #IMPLIED  -- if set, tells that date format is ISO 8601
1711     rfc822    CDATA     #IMPLIED  -- if set, tells that date format is RFC 822
1712     upddt     CDATA     #IMPLIED  -- if set, uses the post update time
1713     creadt    CDATA     #IMPLIED  -- if set, uses the post creation time
1714     >
1715     */
1716     public function EntryDate($attr)
1717     {
1718          $format = '';
1719          if (!empty($attr['format'])) {
1720               $format = addslashes($attr['format']);
1721          }
1722
1723          $iso8601 = !empty($attr['iso8601']);
1724          $rfc822 = !empty($attr['rfc822']);
1725          $type = (!empty($attr['creadt']) ? 'creadt' : '');
1726          $type = (!empty($attr['upddt']) ? 'upddt' : $type);
1727
1728          $f = $this->getFilters($attr);
1729
1730          if ($rfc822) {
1731               return '<?php echo '.sprintf($f,"\$_ctx->posts->getRFC822Date('".$type."')").'; ?>';
1732          } elseif ($iso8601) {
1733               return '<?php echo '.sprintf($f,"\$_ctx->posts->getISO8601Date('".$type."')").'; ?>';
1734          } else {
1735               return '<?php echo '.sprintf($f,"\$_ctx->posts->getDate('".$format."','".$type."')").'; ?>';
1736          }
1737     }
1738
1739     /*dtd
1740     <!ELEMENT tpl:EntryTime - O -- Entry date -->
1741     <!ATTLIST tpl:EntryTime
1742     format    CDATA     #IMPLIED  -- time format
1743     upddt     CDATA     #IMPLIED  -- if set, uses the post update time
1744     creadt    CDATA     #IMPLIED  -- if set, uses the post creation time
1745     >
1746     */
1747     public function EntryTime($attr)
1748     {
1749          $format = '';
1750          if (!empty($attr['format'])) {
1751               $format = addslashes($attr['format']);
1752          }
1753
1754          $type = (!empty($attr['creadt']) ? 'creadt' : '');
1755          $type = (!empty($attr['upddt']) ? 'upddt' : $type);
1756
1757          $f = $this->getFilters($attr);
1758          return '<?php echo '.sprintf($f,"\$_ctx->posts->getTime('".$format."','".$type."')").'; ?>';
1759     }
1760
1761     /*dtd
1762     <!ELEMENT tpl:EntriesHeader - - -- First entries result container -->
1763     */
1764     public function EntriesHeader($attr,$content)
1765     {
1766          return
1767          "<?php if (\$_ctx->posts->isStart()) : ?>".
1768          $content.
1769          "<?php endif; ?>";
1770     }
1771
1772     /*dtd
1773     <!ELEMENT tpl:EntriesFooter - - -- Last entries result container -->
1774     */
1775     public function EntriesFooter($attr,$content)
1776     {
1777          return
1778          "<?php if (\$_ctx->posts->isEnd()) : ?>".
1779          $content.
1780          "<?php endif; ?>";
1781     }
1782
1783
1784
1785
1786     /*dtd
1787     <!ELEMENT tpl:EntryCommentCount - O -- Number of comments for entry -->
1788     <!ATTLIST tpl:EntryCommentCount
1789     none      CDATA     #IMPLIED  -- text to display for "no comment" (default: no comment)
1790     one       CDATA     #IMPLIED  -- text to display for "one comment" (default: one comment)
1791     more      CDATA     #IMPLIED  -- text to display for "more comments" (default: %s comments, %s is replaced by the number of comment)
1792     count_all CDATA     #IMPLIED  -- count comments and trackbacks
1793     >
1794     */
1795     public function EntryCommentCount($attr)
1796     {
1797          if (empty($attr['count_all'])) {
1798               $operation = '$_ctx->posts->nb_comment';
1799          } else {
1800               $operation = '($_ctx->posts->nb_comment + $_ctx->posts->nb_trackback)';
1801          }
1802
1803          return $this->displayCounter(
1804               $operation,
1805               array(
1806                    'none' => 'no comments',
1807                    'one'  => 'one comment',
1808                    'more' => '%d comments'
1809                    ),
1810               $attr,
1811               false
1812          );
1813     }
1814
1815     /*dtd
1816     <!ELEMENT tpl:EntryPingCount - O -- Number of trackbacks for entry -->
1817     <!ATTLIST tpl:EntryPingCount
1818     none CDATA     #IMPLIED  -- text to display for "no ping" (default: no ping)
1819     one  CDATA     #IMPLIED  -- text to display for "one ping" (default: one ping)
1820     more CDATA     #IMPLIED  -- text to display for "more pings" (default: %s trackbacks, %s is replaced by the number of pings)
1821     >
1822     */
1823     public function EntryPingCount($attr)
1824     {
1825          return $this->displayCounter(
1826               '$_ctx->posts->nb_trackback',
1827               array(
1828                    'none' => 'no trackback',
1829                    'one'  => 'one trackback',
1830                    'more' => '%d trackbacks'
1831                    ),
1832               $attr,
1833               false
1834          );
1835     }
1836
1837     /*dtd
1838     <!ELEMENT tpl:EntryPingData - O -- Display trackback RDF information -->
1839     */
1840     public function EntryPingData($attr)
1841     {
1842          return "<?php if (\$_ctx->posts->trackbacksActive()) { echo \$_ctx->posts->getTrackbackData(); } ?>\n";
1843     }
1844
1845     /*dtd
1846     <!ELEMENT tpl:EntryPingLink - O -- Entry trackback link -->
1847     */
1848     public function EntryPingLink($attr)
1849     {
1850          return "<?php if (\$_ctx->posts->trackbacksActive()) { echo \$_ctx->posts->getTrackbackLink(); } ?>\n";
1851     }
1852
1853     /* Languages -------------------------------------- */
1854     /*dtd
1855     <!ELEMENT tpl:Languages - - -- Languages loop -->
1856     <!ATTLIST tpl:Languages
1857     lang CDATA     #IMPLIED  -- restrict loop on given lang
1858     order     (desc|asc)     #IMPLIED  -- languages ordering (default: desc)
1859     >
1860     */
1861     public function Languages($attr,$content)
1862     {
1863          $p = "if (!isset(\$params)) \$params = array();\n";
1864
1865          if (isset($attr['lang'])) {
1866               $p = "\$params['lang'] = '".addslashes($attr['lang'])."';\n";
1867          }
1868
1869          $order = 'desc';
1870          if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) {
1871               $p .= "\$params['order'] = '".$attr['order']."';\n ";
1872          }
1873
1874          $res = "<?php\n";
1875          $res .= $p;
1876          $res .= $this->core->callBehavior("templatePrepareParams",
1877               array("tag" => "Languages","method" => "blog::getLangs"),
1878               $attr,$content);
1879          $res .= '$_ctx->langs = $core->blog->getLangs($params); unset($params);'."\n";
1880          $res .= "?>\n";
1881
1882          $res .=
1883          '<?php if ($_ctx->langs->count() > 1) : '.
1884          'while ($_ctx->langs->fetch()) : ?>'.$content.
1885          '<?php endwhile; $_ctx->langs = null; endif; ?>';
1886
1887          return $res;
1888     }
1889
1890     /*dtd
1891     <!ELEMENT tpl:LanguagesHeader - - -- First languages result container -->
1892     */
1893     public function LanguagesHeader($attr,$content)
1894     {
1895          return
1896          "<?php if (\$_ctx->langs->isStart()) : ?>".
1897          $content.
1898          "<?php endif; ?>";
1899     }
1900
1901     /*dtd
1902     <!ELEMENT tpl:LanguagesFooter - - -- Last languages result container -->
1903     */
1904     public function LanguagesFooter($attr,$content)
1905     {
1906          return
1907          "<?php if (\$_ctx->langs->isEnd()) : ?>".
1908          $content.
1909          "<?php endif; ?>";
1910     }
1911
1912     /*dtd
1913     <!ELEMENT tpl:LanguageCode - O -- Language code -->
1914     */
1915     public function LanguageCode($attr)
1916     {
1917          $f = $this->getFilters($attr);
1918          return '<?php echo '.sprintf($f,'$_ctx->langs->post_lang').'; ?>';
1919     }
1920
1921     /*dtd
1922     <!ELEMENT tpl:LanguageIfCurrent - - -- tests if post language is current language -->
1923     */
1924     public function LanguageIfCurrent($attr,$content)
1925     {
1926          return
1927          "<?php if (\$_ctx->cur_lang == \$_ctx->langs->post_lang) : ?>".
1928          $content.
1929          "<?php endif; ?>";
1930     }
1931
1932     /*dtd
1933     <!ELEMENT tpl:LanguageURL - O -- Language URL -->
1934     */
1935     public function LanguageURL($attr)
1936     {
1937          $f = $this->getFilters($attr);
1938          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("lang",'.
1939               '$_ctx->langs->post_lang)').'; ?>';
1940     }
1941
1942     /* Pagination ------------------------------------- */
1943     /*dtd
1944     <!ELEMENT tpl:Pagination - - -- Pagination container -->
1945     <!ATTLIST tpl:Pagination
1946     no_context     (0|1)     #IMPLIED  -- override test on posts count vs number of posts per page
1947     >
1948     */
1949     public function Pagination($attr,$content)
1950     {
1951          $p = "<?php\n";
1952          $p .= '$params = $_ctx->post_params;'."\n";
1953          $p .= $this->core->callBehavior("templatePrepareParams",
1954               array("tag" => "Pagination","method" => "blog::getPosts"),
1955               $attr,$content);
1956          $p .= '$_ctx->pagination = $core->blog->getPosts($params,true); unset($params);'."\n";
1957          $p .= "?>\n";
1958
1959          if (isset($attr['no_context']) && $attr['no_context']) {
1960               return $p.$content;
1961          }
1962
1963          return
1964               $p.
1965               '<?php if ($_ctx->pagination->f(0) > $_ctx->posts->count()) : ?>'.
1966               $content.
1967               '<?php endif; ?>';
1968     }
1969
1970     /*dtd
1971     <!ELEMENT tpl:PaginationCounter - O -- Number of pages -->
1972     */
1973     public function PaginationCounter($attr)
1974     {
1975          $f = $this->getFilters($attr);
1976          return '<?php echo '.sprintf($f,"context::PaginationNbPages()").'; ?>';
1977     }
1978
1979     /*dtd
1980     <!ELEMENT tpl:PaginationCurrent - O -- current page -->
1981     */
1982     public function PaginationCurrent($attr)
1983     {
1984          $offset = 0;
1985          if (isset($attr['offset'])) {
1986               $offset = (integer) $attr['offset'];
1987          }
1988
1989          $f = $this->getFilters($attr);
1990          return '<?php echo '.sprintf($f,"context::PaginationPosition(".$offset.")").'; ?>';
1991     }
1992
1993     /*dtd
1994     <!ELEMENT tpl:PaginationIf - - -- pages tests -->
1995     <!ATTLIST tpl:PaginationIf
1996     start     (0|1)     #IMPLIED  -- test if we are at first page (value : 1) or not (value : 0)
1997     end  (0|1)     #IMPLIED  -- test if we are at last page (value : 1) or not (value : 0)
1998     >
1999     */
2000     public function PaginationIf($attr,$content)
2001     {
2002          $if = array();
2003
2004          if (isset($attr['start'])) {
2005               $sign = (boolean) $attr['start'] ? '' : '!';
2006               $if[] = $sign.'context::PaginationStart()';
2007          }
2008
2009          if (isset($attr['end'])) {
2010               $sign = (boolean) $attr['end'] ? '' : '!';
2011               $if[] = $sign.'context::PaginationEnd()';
2012          }
2013
2014          $this->core->callBehavior('tplIfConditions','PaginationIf',$attr,$content,$if);
2015
2016          if (count($if) != 0) {
2017               return '<?php if('.implode(' && ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
2018          } else {
2019               return $content;
2020          }
2021     }
2022
2023     /*dtd
2024     <!ELEMENT tpl:PaginationURL - O -- link to previoux/next page -->
2025     <!ATTLIST tpl:PaginationURL
2026     offset    CDATA     #IMPLIED  -- page offset (negative for previous pages), default: 0
2027     >
2028     */
2029     public function PaginationURL($attr)
2030     {
2031          $offset = 0;
2032          if (isset($attr['offset'])) {
2033               $offset = (integer) $attr['offset'];
2034          }
2035
2036          $f = $this->getFilters($attr);
2037          return '<?php echo '.sprintf($f,"context::PaginationURL(".$offset.")").'; ?>';
2038     }
2039
2040     /* Comments --------------------------------------- */
2041     /*dtd
2042     <!ELEMENT tpl:Comments - - -- Comments container -->
2043     <!ATTLIST tpl:Comments
2044     with_pings     (0|1)     #IMPLIED  -- include trackbacks in request
2045     lastn     CDATA     #IMPLIED  -- restrict the number of entries
2046     no_context (1|0)         #IMPLIED  -- Override context information
2047     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)
2048     order     (desc|asc)     #IMPLIED  -- result ordering (default: asc)
2049     age       CDATA     #IMPLIED  -- retrieve comments by maximum age (ex: -2 days, last month, last week)
2050     >
2051     */
2052     public function Comments($attr,$content)
2053     {
2054          $p = "";
2055          if (empty($attr['with_pings'])) {
2056               $p .= "\$params['comment_trackback'] = false;\n";
2057          }
2058
2059          $lastn = 0;
2060          if (isset($attr['lastn'])) {
2061               $lastn = abs((integer) $attr['lastn'])+0;
2062          }
2063
2064          if ($lastn > 0) {
2065               $p .= "\$params['limit'] = ".$lastn.";\n";
2066          } else {
2067               $p .= "if (\$_ctx->nb_comment_per_page !== null) { \$params['limit'] = \$_ctx->nb_comment_per_page; }\n";
2068          }
2069
2070          if (empty($attr['no_context']))
2071          {
2072               $p .=
2073               "if (\$_ctx->posts !== null) { ".
2074                    "\$params['post_id'] = \$_ctx->posts->post_id; ".
2075                    "\$core->blog->withoutPassword(false);\n".
2076               "}\n";
2077               $p .=
2078               'if ($_ctx->exists("categories")) { '.
2079                    "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
2080               "}\n";
2081
2082               $p .=
2083               'if ($_ctx->exists("langs")) { '.
2084                    "\$params['sql'] = \"AND P.post_lang = '\".\$core->blog->con->escape(\$_ctx->langs->post_lang).\"' \"; ".
2085               "}\n";
2086          }
2087
2088          if (!isset($attr['order'])) {
2089               $attr['order'] = 'asc';
2090          }
2091
2092          $p .= "\$params['order'] = '".$this->getSortByStr($attr,'comment')."';\n";
2093
2094          if (isset($attr['no_content']) && $attr['no_content']) {
2095               $p .= "\$params['no_content'] = true;\n";
2096          }
2097
2098          if (isset($attr['age'])) {
2099               $age = $this->getAge($attr);
2100               $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : '';
2101          }
2102
2103          $res = "<?php\n";
2104          $res .= $this->core->callBehavior("templatePrepareParams",
2105               array("tag" => "Comments","method" => "blog::getComments"),
2106               $attr,$content);
2107          $res .= $p;
2108          $res .= '$_ctx->comments = $core->blog->getComments($params); unset($params);'."\n";
2109          $res .= "if (\$_ctx->posts !== null) { \$core->blog->withoutPassword(true);}\n";
2110
2111          if (!empty($attr['with_pings'])) {
2112               $res .= '$_ctx->pings = $_ctx->comments;'."\n";
2113          }
2114
2115          $res .= "?>\n";
2116
2117          $res .=
2118          '<?php while ($_ctx->comments->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->comments = null; ?>';
2119
2120          return $res;
2121     }
2122
2123     /*dtd
2124     <!ELEMENT tpl:CommentAuthor - O -- Comment author -->
2125     */
2126     public function CommentAuthor($attr)
2127     {
2128          $f = $this->getFilters($attr);
2129          return '<?php echo '.sprintf($f,"\$_ctx->comments->comment_author").'; ?>';
2130     }
2131
2132     /*dtd
2133     <!ELEMENT tpl:CommentAuthorDomain - O -- Comment author website domain -->
2134     */
2135     public function CommentAuthorDomain($attr)
2136     {
2137          return '<?php echo preg_replace("#^http(?:s?)://(.+?)/.*$#msu",\'$1\',$_ctx->comments->comment_site); ?>';
2138     }
2139
2140     /*dtd
2141     <!ELEMENT tpl:CommentAuthorLink - O -- Comment author link -->
2142     */
2143     public function CommentAuthorLink($attr)
2144     {
2145          $f = $this->getFilters($attr);
2146          return '<?php echo '.sprintf($f,'$_ctx->comments->getAuthorLink()').'; ?>';
2147     }
2148
2149     /*dtd
2150     <!ELEMENT tpl:CommentAuthorMailMD5 - O -- Comment author email MD5 sum -->
2151     */
2152     public function CommentAuthorMailMD5($attr)
2153     {
2154          return '<?php echo md5($_ctx->comments->comment_email) ; ?>';
2155     }
2156
2157     /*dtd
2158     <!ELEMENT tpl:CommentAuthorURL - O -- Comment author URL -->
2159     */
2160     public function CommentAuthorURL($attr)
2161     {
2162          $f = $this->getFilters($attr);
2163          return '<?php echo '.sprintf($f,'$_ctx->comments->getAuthorURL()').'; ?>';
2164     }
2165
2166     /*dtd
2167     <!ELEMENT tpl:CommentContent - O --  Comment content -->
2168     <!ATTLIST tpl:CommentContent
2169     absolute_urls  (0|1)     #IMPLIED  -- convert URLS to absolute urls
2170     >
2171     */
2172     public function CommentContent($attr)
2173     {
2174          $urls = '0';
2175          if (!empty($attr['absolute_urls'])) {
2176               $urls = '1';
2177          }
2178
2179          $f = $this->getFilters($attr);
2180          return '<?php echo '.sprintf($f,'$_ctx->comments->getContent('.$urls.')').'; ?>';
2181     }
2182
2183     /*dtd
2184     <!ELEMENT tpl:CommentDate - O -- Comment date -->
2185     <!ATTLIST tpl:CommentDate
2186     format    CDATA     #IMPLIED  -- date format (encoded in dc:str by default if iso8601 or rfc822 not specified)
2187     iso8601   CDATA     #IMPLIED  -- if set, tells that date format is ISO 8601
2188     rfc822    CDATA     #IMPLIED  -- if set, tells that date format is RFC 822
2189     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2190     >
2191     */
2192     public function CommentDate($attr)
2193     {
2194          $format = '';
2195          if (!empty($attr['format'])) {
2196               $format = addslashes($attr['format']);
2197          }
2198
2199          $iso8601 = !empty($attr['iso8601']);
2200          $rfc822 = !empty($attr['rfc822']);
2201          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2202
2203          $f = $this->getFilters($attr);
2204
2205          if ($rfc822) {
2206               return '<?php echo '.sprintf($f,"\$_ctx->comments->getRFC822Date('".$type."')").'; ?>';
2207          } elseif ($iso8601) {
2208               return '<?php echo '.sprintf($f,"\$_ctx->comments->getISO8601Date('".$type."')").'; ?>';
2209          } else {
2210               return '<?php echo '.sprintf($f,"\$_ctx->comments->getDate('".$format."','".$type."')").'; ?>';
2211          }
2212     }
2213
2214     /*dtd
2215     <!ELEMENT tpl:CommentTime - O -- Comment date -->
2216     <!ATTLIST tpl:CommentTime
2217     format    CDATA     #IMPLIED  -- time format
2218     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2219     >
2220     */
2221     public function CommentTime($attr)
2222     {
2223          $format = '';
2224          if (!empty($attr['format'])) {
2225               $format = addslashes($attr['format']);
2226          }
2227          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2228
2229          $f = $this->getFilters($attr);
2230          return '<?php echo '.sprintf($f,"\$_ctx->comments->getTime('".$format."','".$type."')").'; ?>';
2231     }
2232
2233     /*dtd
2234     <!ELEMENT tpl:CommentEmail - O -- Comment author email -->
2235     <!ATTLIST tpl:CommentEmail
2236     spam_protected (0|1)     #IMPLIED  -- protect email from spam (default: 1)
2237     >
2238     */
2239     public function CommentEmail($attr)
2240     {
2241          $p = 'true';
2242          if (isset($attr['spam_protected']) && !$attr['spam_protected']) {
2243               $p = 'false';
2244          }
2245
2246          $f = $this->getFilters($attr);
2247          return '<?php echo '.sprintf($f,"\$_ctx->comments->getEmail(".$p.")").'; ?>';
2248     }
2249
2250     /*dtd
2251     <!ELEMENT tpl:CommentEntryTitle - O -- Title of the comment entry -->
2252     */
2253     public function CommentEntryTitle($attr)
2254     {
2255          $f = $this->getFilters($attr);
2256          return '<?php echo '.sprintf($f,'$_ctx->comments->post_title').'; ?>';
2257     }
2258
2259     /*dtd
2260     <!ELEMENT tpl:CommentFeedID - O -- Comment feed ID -->
2261     */
2262     public function CommentFeedID($attr)
2263     {
2264          $f = $this->getFilters($attr);
2265          return '<?php echo '.sprintf($f,'$_ctx->comments->getFeedID()').'; ?>';
2266     }
2267
2268     /*dtd
2269     <!ELEMENT tpl:CommentID - O -- Comment ID -->
2270     */
2271     public function CommentID($attr)
2272     {
2273          return '<?php echo $_ctx->comments->comment_id; ?>';
2274     }
2275
2276     /*dtd
2277     <!ELEMENT tpl:CommentIf - - -- test container for comments -->
2278     <!ATTLIST tpl:CommentIf
2279     is_ping   (0|1)     #IMPLIED  -- test if comment is a trackback (value : 1) or not (value : 0)
2280     >
2281     */
2282     public function CommentIf($attr,$content)
2283     {
2284          $if = array();
2285          $is_ping = null;
2286
2287          if (isset($attr['is_ping'])) {
2288               $sign = (boolean) $attr['is_ping'] ? '' : '!';
2289               $if[] = $sign.'$_ctx->comments->comment_trackback';
2290          }
2291
2292          $this->core->callBehavior('tplIfConditions','CommentIf',$attr,$content,$if);
2293
2294          if (count($if) != 0) {
2295               return '<?php if('.implode(' && ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
2296          } else {
2297               return $content;
2298          }
2299     }
2300
2301     /*dtd
2302     <!ELEMENT tpl:CommentIfFirst - O -- displays value if comment is the first one -->
2303     <!ATTLIST tpl:CommentIfFirst
2304     return    CDATA     #IMPLIED  -- value to display in case of success (default: first)
2305     >
2306     */
2307     public function CommentIfFirst($attr)
2308     {
2309          $ret = isset($attr['return']) ? $attr['return'] : 'first';
2310          $ret = html::escapeHTML($ret);
2311
2312          return
2313          '<?php if ($_ctx->comments->index() == 0) { '.
2314          "echo '".addslashes($ret)."'; } ?>";
2315     }
2316
2317     /*dtd
2318     <!ELEMENT tpl:CommentIfMe - O -- displays value if comment is the from the entry author -->
2319     <!ATTLIST tpl:CommentIfMe
2320     return    CDATA     #IMPLIED  -- value to display in case of success (default: me)
2321     >
2322     */
2323     public function CommentIfMe($attr)
2324     {
2325          $ret = isset($attr['return']) ? $attr['return'] : 'me';
2326          $ret = html::escapeHTML($ret);
2327
2328          return
2329          '<?php if ($_ctx->comments->isMe()) { '.
2330          "echo '".addslashes($ret)."'; } ?>";
2331     }
2332
2333     /*dtd
2334     <!ELEMENT tpl:CommentIfOdd - O -- displays value if comment is  at an odd position -->
2335     <!ATTLIST tpl:CommentIfOdd
2336     return    CDATA     #IMPLIED  -- value to display in case of success (default: odd)
2337     >
2338     */
2339     public function CommentIfOdd($attr)
2340     {
2341          $ret = isset($attr['return']) ? $attr['return'] : 'odd';
2342          $ret = html::escapeHTML($ret);
2343
2344          return
2345          '<?php if (($_ctx->comments->index()+1)%2) { '.
2346          "echo '".addslashes($ret)."'; } ?>";
2347     }
2348
2349     /*dtd
2350     <!ELEMENT tpl:CommentIP - O -- Comment author IP -->
2351     */
2352     public function CommentIP($attr)
2353     {
2354          return '<?php echo $_ctx->comments->comment_ip; ?>';
2355     }
2356
2357     /*dtd
2358     <!ELEMENT tpl:CommentOrderNumber - O -- Comment order in page -->
2359     */
2360     public function CommentOrderNumber($attr)
2361     {
2362          return '<?php echo $_ctx->comments->index()+1; ?>';
2363     }
2364
2365     /*dtd
2366     <!ELEMENT tpl:CommentsFooter - - -- Last comments result container -->
2367     */
2368     public function CommentsFooter($attr,$content)
2369     {
2370          return
2371          "<?php if (\$_ctx->comments->isEnd()) : ?>".
2372          $content.
2373          "<?php endif; ?>";
2374     }
2375
2376     /*dtd
2377     <!ELEMENT tpl:CommentsHeader - - -- First comments result container -->
2378     */
2379     public function CommentsHeader($attr,$content)
2380     {
2381          return
2382          "<?php if (\$_ctx->comments->isStart()) : ?>".
2383          $content.
2384          "<?php endif; ?>";
2385     }
2386
2387     /*dtd
2388     <!ELEMENT tpl:CommentPostURL - O -- Comment Entry URL -->
2389     */
2390     public function CommentPostURL($attr)
2391     {
2392          $f = $this->getFilters($attr);
2393          return '<?php echo '.sprintf($f,'$_ctx->comments->getPostURL()').'; ?>';
2394     }
2395
2396     /*dtd
2397     <!ELEMENT tpl:IfCommentAuthorEmail - - -- Container displayed if comment author email is set -->
2398     */
2399     public function IfCommentAuthorEmail($attr,$content)
2400     {
2401          return
2402          "<?php if (\$_ctx->comments->comment_email) : ?>".
2403          $content.
2404          "<?php endif; ?>";
2405     }
2406
2407     /*dtd
2408     <!ELEMENT tpl:CommentHelp - 0 -- Comment syntax mini help -->
2409     */
2410     public function CommentHelp($attr,$content)
2411     {
2412          return
2413          "<?php if (\$core->blog->settings->system->wiki_comments) {\n".
2414          "  echo __('Comments can be formatted using a simple wiki syntax.');\n".
2415          "} else {\n".
2416          "  echo __('HTML code is displayed as text and web addresses are automatically converted.');\n".
2417          "} ?>";
2418     }
2419
2420     /* Comment preview -------------------------------- */
2421     /*dtd
2422     <!ELEMENT tpl:IfCommentPreviewOptional - - -- Container displayed if comment preview is optional or currently previewed -->
2423     */
2424     public function IfCommentPreviewOptional($attr,$content)
2425     {
2426          return
2427          '<?php if ($core->blog->settings->system->comment_preview_optional || ($_ctx->comment_preview !== null && $_ctx->comment_preview["preview"])) : ?>'.
2428          $content.
2429          '<?php endif; ?>';
2430     }
2431
2432     /*dtd
2433     <!ELEMENT tpl:IfCommentPreview - - -- Container displayed if comment is being previewed -->
2434     */
2435     public function IfCommentPreview($attr,$content)
2436     {
2437          return
2438          '<?php if ($_ctx->comment_preview !== null && $_ctx->comment_preview["preview"]) : ?>'.
2439          $content.
2440          '<?php endif; ?>';
2441     }
2442
2443     /*dtd
2444     <!ELEMENT tpl:CommentPreviewName - O -- Author name for the previewed comment -->
2445     */
2446     public function CommentPreviewName($attr)
2447     {
2448          $f = $this->getFilters($attr);
2449          return '<?php echo '.sprintf($f,'$_ctx->comment_preview["name"]').'; ?>';
2450     }
2451
2452     /*dtd
2453     <!ELEMENT tpl:CommentPreviewEmail - O -- Author email for the previewed comment -->
2454     */
2455     public function CommentPreviewEmail($attr)
2456     {
2457          $f = $this->getFilters($attr);
2458          return '<?php echo '.sprintf($f,'$_ctx->comment_preview["mail"]').'; ?>';
2459     }
2460
2461     /*dtd
2462     <!ELEMENT tpl:CommentPreviewSite - O -- Author site for the previewed comment -->
2463     */
2464     public function CommentPreviewSite($attr)
2465     {
2466          $f = $this->getFilters($attr);
2467          return '<?php echo '.sprintf($f,'$_ctx->comment_preview["site"]').'; ?>';
2468     }
2469
2470     /*dtd
2471     <!ELEMENT tpl:CommentPreviewContent - O -- Content of the previewed comment -->
2472     <!ATTLIST tpl:CommentPreviewContent
2473     raw  (0|1)     #IMPLIED  -- display comment in raw content
2474     >
2475     */
2476     public function CommentPreviewContent($attr)
2477     {
2478          $f = $this->getFilters($attr);
2479
2480          if (!empty($attr['raw'])) {
2481               $co = '$_ctx->comment_preview["rawcontent"]';
2482          } else {
2483               $co = '$_ctx->comment_preview["content"]';
2484          }
2485
2486          return '<?php echo '.sprintf($f,$co).'; ?>';
2487     }
2488
2489     /*dtd
2490     <!ELEMENT tpl:CommentPreviewCheckRemember - O -- checkbox attribute for "remember me" (same value as before preview) -->
2491     */
2492     public function CommentPreviewCheckRemember($attr)
2493     {
2494          return
2495          "<?php if (\$_ctx->comment_preview['remember']) { echo ' checked=\"checked\"'; } ?>";
2496     }
2497
2498     /* Trackbacks ------------------------------------- */
2499     /*dtd
2500     <!ELEMENT tpl:PingBlogName - O -- Trackback blog name -->
2501     */
2502     public function PingBlogName($attr)
2503     {
2504          $f = $this->getFilters($attr);
2505          return '<?php echo '.sprintf($f,'$_ctx->pings->comment_author').'; ?>';
2506     }
2507
2508     /*dtd
2509     <!ELEMENT tpl:PingContent - O -- Trackback content -->
2510     */
2511     public function PingContent($attr)
2512     {
2513          $f = $this->getFilters($attr);
2514          return '<?php echo '.sprintf($f,'$_ctx->pings->getTrackbackContent()').'; ?>';
2515     }
2516
2517     /*dtd
2518     <!ELEMENT tpl:PingDate - O -- Trackback date -->
2519     <!ATTLIST tpl:PingDate
2520     format    CDATA     #IMPLIED  -- date format (encoded in dc:str by default if iso8601 or rfc822 not specified)
2521     iso8601   CDATA     #IMPLIED  -- if set, tells that date format is ISO 8601
2522     rfc822    CDATA     #IMPLIED  -- if set, tells that date format is RFC 822
2523     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2524     >
2525     */
2526     public function PingDate($attr,$type='')
2527     {
2528          $format = '';
2529          if (!empty($attr['format'])) {
2530               $format = addslashes($attr['format']);
2531          }
2532
2533          $iso8601 = !empty($attr['iso8601']);
2534          $rfc822 = !empty($attr['rfc822']);
2535          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2536
2537          $f = $this->getFilters($attr);
2538
2539          if ($rfc822) {
2540               return '<?php echo '.sprintf($f,"\$_ctx->pings->getRFC822Date('".$type."')").'; ?>';
2541          } elseif ($iso8601) {
2542               return '<?php echo '.sprintf($f,"\$_ctx->pings->getISO8601Date('".$type."')").'; ?>';
2543          } else {
2544               return '<?php echo '.sprintf($f,"\$_ctx->pings->getDate('".$format."','".$type."')").'; ?>';
2545          }
2546     }
2547
2548     /*dtd
2549     <!ELEMENT tpl:PingTime - O -- Trackback date -->
2550     <!ATTLIST tpl:PingTime
2551     format    CDATA     #IMPLIED  -- time format
2552     upddt     CDATA     #IMPLIED  -- if set, uses the comment update time
2553     >
2554     */
2555     public function PingTime($attr)
2556     {
2557          $format = '';
2558          if (!empty($attr['format'])) {
2559               $format = addslashes($attr['format']);
2560          }
2561          $type = (!empty($attr['upddt']) ? 'upddt' : '');
2562
2563          $f = $this->getFilters($attr);
2564          return '<?php echo '.sprintf($f,"\$_ctx->pings->getTime('".$format."','".$type."')").'; ?>';
2565     }
2566
2567     /*dtd
2568     <!ELEMENT tpl:PingEntryTitle - O -- Trackback entry title -->
2569     */
2570     public function PingEntryTitle($attr)
2571     {
2572          $f = $this->getFilters($attr);
2573          return '<?php echo '.sprintf($f,'$_ctx->pings->post_title').'; ?>';
2574     }
2575
2576     /*dtd
2577     <!ELEMENT tpl:PingFeedID - O -- Trackback feed ID -->
2578     */
2579     public function PingFeedID($attr)
2580     {
2581          $f = $this->getFilters($attr);
2582          return '<?php echo '.sprintf($f,'$_ctx->pings->getFeedID()').'; ?>';
2583     }
2584
2585     /*dtd
2586     <!ELEMENT tpl:PingID - O -- Trackback ID -->
2587     */
2588     public function PingID($attr)
2589     {
2590          return '<?php echo $_ctx->pings->comment_id; ?>';
2591     }
2592
2593     /*dtd
2594     <!ELEMENT tpl:PingIfFirst - O -- displays value if trackback is the first one -->
2595     <!ATTLIST tpl:PingIfFirst
2596     return    CDATA     #IMPLIED  -- value to display in case of success (default: first)
2597     >
2598     */
2599     public function PingIfFirst($attr)
2600     {
2601          $ret = isset($attr['return']) ? $attr['return'] : 'first';
2602          $ret = html::escapeHTML($ret);
2603
2604          return
2605          '<?php if ($_ctx->pings->index() == 0) { '.
2606          "echo '".addslashes($ret)."'; } ?>";
2607     }
2608
2609     /*dtd
2610     <!ELEMENT tpl:PingIfOdd - O -- displays value if trackback is  at an odd position -->
2611     <!ATTLIST tpl:PingIfOdd
2612     return    CDATA     #IMPLIED  -- value to display in case of success (default: odd)
2613     >
2614     */
2615     public function PingIfOdd($attr)
2616     {
2617          $ret = isset($attr['return']) ? $attr['return'] : 'odd';
2618          $ret = html::escapeHTML($ret);
2619
2620          return
2621          '<?php if (($_ctx->pings->index()+1)%2) { '.
2622          "echo '".addslashes($ret)."'; } ?>";
2623     }
2624
2625     /*dtd
2626     <!ELEMENT tpl:PingIP - O -- Trackback author IP -->
2627     */
2628     public function PingIP($attr)
2629     {
2630          return '<?php echo $_ctx->pings->comment_ip; ?>';
2631     }
2632
2633     /*dtd
2634     <!ELEMENT tpl:PingNoFollow - O -- displays 'rel="nofollow"' if set in blog -->
2635     */
2636     public function PingNoFollow($attr)
2637     {
2638          return
2639          '<?php if($core->blog->settings->system->comments_nofollow) { '.
2640          'echo \' rel="nofollow"\';'.
2641          '} ?>';
2642     }
2643
2644     /*dtd
2645     <!ELEMENT tpl:PingOrderNumber - O -- Trackback order in page -->
2646     */
2647     public function PingOrderNumber($attr)
2648     {
2649          return '<?php echo $_ctx->pings->index()+1; ?>';
2650     }
2651
2652     /*dtd
2653     <!ELEMENT tpl:PingPostURL - O -- Trackback Entry URL -->
2654     */
2655     public function PingPostURL($attr)
2656     {
2657          $f = $this->getFilters($attr);
2658          return '<?php echo '.sprintf($f,'$_ctx->pings->getPostURL()').'; ?>';
2659     }
2660
2661     /*dtd
2662     <!ELEMENT tpl:Pings - - -- Trackbacks container -->
2663     <!ATTLIST tpl:Pings
2664     with_pings     (0|1)     #IMPLIED  -- include trackbacks in request
2665     lastn     CDATA          #IMPLIED  -- restrict the number of entries
2666     no_context (1|0)         #IMPLIED  -- Override context information
2667     order     (desc|asc)     #IMPLIED  -- result ordering (default: asc)
2668     >
2669     */
2670     public function Pings($attr,$content)
2671     {
2672          $p =
2673          "if (\$_ctx->posts !== null) { ".
2674               "\$params['post_id'] = \$_ctx->posts->post_id; ".
2675               "\$core->blog->withoutPassword(false);\n".
2676          "}\n";
2677
2678          $p .= "\$params['comment_trackback'] = true;\n";
2679
2680          $lastn = 0;
2681          if (isset($attr['lastn'])) {
2682               $lastn = abs((integer) $attr['lastn'])+0;
2683          }
2684
2685          if ($lastn > 0) {
2686               $p .= "\$params['limit'] = ".$lastn.";\n";
2687          } else {
2688               $p .= "if (\$_ctx->nb_comment_per_page !== null) { \$params['limit'] = \$_ctx->nb_comment_per_page; }\n";
2689          }
2690
2691          if (empty($attr['no_context']))
2692          {
2693               $p .=
2694               'if ($_ctx->exists("categories")) { '.
2695                    "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
2696               "}\n";
2697
2698               $p .=
2699               'if ($_ctx->exists("langs")) { '.
2700                    "\$params['sql'] = \"AND P.post_lang = '\".\$core->blog->con->escape(\$_ctx->langs->post_lang).\"' \"; ".
2701               "}\n";
2702          }
2703
2704          $order = 'asc';
2705          if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) {
2706               $order = $attr['order'];
2707          }
2708
2709          $p .= "\$params['order'] = 'comment_dt ".$order."';\n";
2710
2711          if (isset($attr['no_content']) && $attr['no_content']) {
2712               $p .= "\$params['no_content'] = true;\n";
2713          }
2714
2715          $res = "<?php\n";
2716          $res .= $p;
2717          $res .= $this->core->callBehavior("templatePrepareParams",
2718               array("tag" => "Pings","method" => "blog::getComments"),
2719               $attr,$content);
2720          $res .= '$_ctx->pings = $core->blog->getComments($params); unset($params);'."\n";
2721          $res .= "if (\$_ctx->posts !== null) { \$core->blog->withoutPassword(true);}\n";
2722          $res .= "?>\n";
2723
2724          $res .=
2725          '<?php while ($_ctx->pings->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->pings = null; ?>';
2726
2727          return $res;
2728     }
2729
2730     /*dtd
2731     <!ELEMENT tpl:PingsFooter - - -- Last trackbacks result container -->
2732     */
2733     public function PingsFooter($attr,$content)
2734     {
2735          return
2736          "<?php if (\$_ctx->pings->isEnd()) : ?>".
2737          $content.
2738          "<?php endif; ?>";
2739     }
2740
2741     /*dtd
2742     <!ELEMENT tpl:PingsHeader - - -- First trackbacks result container -->
2743     */
2744     public function PingsHeader($attr,$content)
2745     {
2746          return
2747          "<?php if (\$_ctx->pings->isStart()) : ?>".
2748          $content.
2749          "<?php endif; ?>";
2750     }
2751
2752     /*dtd
2753     <!ELEMENT tpl:PingTitle - O -- Trackback title -->
2754     */
2755     public function PingTitle($attr)
2756     {
2757          $f = $this->getFilters($attr);
2758          return '<?php echo '.sprintf($f,'$_ctx->pings->getTrackbackTitle()').'; ?>';
2759     }
2760
2761     /*dtd
2762     <!ELEMENT tpl:PingAuthorURL - O -- Trackback author URL -->
2763     */
2764     public function PingAuthorURL($attr)
2765     {
2766          $f = $this->getFilters($attr);
2767          return '<?php echo '.sprintf($f,'$_ctx->pings->getAuthorURL()').'; ?>';
2768     }
2769
2770     # System
2771     /*dtd
2772     <!ELEMENT tpl:SysBehavior - O -- Call a given behavior -->
2773     <!ATTLIST tpl:SysBehavior
2774     behavior  CDATA     #IMPLIED  -- behavior to call
2775     >
2776     */
2777     public function SysBehavior($attr,$raw)
2778     {
2779          if (!isset($attr['behavior'])) {
2780               return;
2781          }
2782
2783          $b = addslashes($attr['behavior']);
2784          return
2785          '<?php if ($core->hasBehavior(\''.$b.'\')) { '.
2786               '$core->callBehavior(\''.$b.'\',$core,$_ctx);'.
2787          '} ?>';
2788     }
2789
2790     /*dtd
2791     <!ELEMENT tpl:SysIf - - -- System settings tester container -->
2792     <!ATTLIST tpl:SysIf
2793     categories          (0|1)     #IMPLIED  -- test if categories are set in current context (value : 1) or not (value : 0)
2794     posts               (0|1)     #IMPLIED  -- test if posts are set in current context (value : 1) or not (value : 0)
2795     blog_lang           CDATA     #IMPLIED  -- tests if blog language is the one given in parameter
2796     current_tpl         CDATA     #IMPLIED  -- tests if current template is the one given in paramater
2797     current_mode        CDATA     #IMPLIED  -- tests if current URL mode is the one given in parameter
2798     has_tpl             CDATA     #IMPLIED  -- tests if a named template exists
2799     has_tag             CDATA     #IMPLIED  -- tests if a named template block or value exists
2800     blog_id             CDATA     #IMPLIED  -- tests if current blog ID is the one given in parameter
2801     comments_active     (0|1)     #IMPLIED  -- test if comments are enabled blog-wide
2802     pings_active        (0|1)     #IMPLIED  -- test if trackbacks are enabled blog-wide
2803     wiki_comments       (0|1)     #IMPLIED  -- test if wiki syntax is enabled for comments
2804     operator            (and|or)  #IMPLIED  -- combination of conditions, if more than 1 specifiec (default: and)
2805     >
2806     */
2807     public function SysIf($attr,$content)
2808     {
2809          $if = new ArrayObject();
2810          $is_ping = null;
2811
2812          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';
2813
2814          if (isset($attr['categories'])) {
2815               $sign = (boolean) $attr['categories'] ? '!' : '=';
2816               $if[] = '$_ctx->categories '.$sign.'== null';
2817          }
2818
2819          if (isset($attr['posts'])) {
2820               $sign = (boolean) $attr['posts'] ? '!' : '=';
2821               $if[] = '$_ctx->posts '.$sign.'== null';
2822          }
2823
2824          if (isset($attr['blog_lang'])) {
2825               $if[] = "\$core->blog->settings->system->lang == '".addslashes($attr['blog_lang'])."'";
2826          }
2827
2828          if (isset($attr['current_tpl'])) {
2829               $sign = '=';
2830               if (substr($attr['current_tpl'],0,1) == '!') {
2831                    $sign = '!';
2832                    $attr['current_tpl'] = substr($attr['current_tpl'],1);
2833               }
2834               $if[] = "\$_ctx->current_tpl ".$sign."= '".addslashes($attr['current_tpl'])."'";
2835          }
2836
2837          if (isset($attr['current_mode'])) {
2838               $sign = '=';
2839               if (substr($attr['current_mode'],0,1) == '!') {
2840                    $sign = '!';
2841                    $attr['current_mode'] = substr($attr['current_mode'],1);
2842               }
2843               $if[] = "\$core->url->type ".$sign."= '".addslashes($attr['current_mode'])."'";
2844          }
2845
2846          if (isset($attr['has_tpl'])) {
2847               $sign = '';
2848               if (substr($attr['has_tpl'],0,1) == '!') {
2849                    $sign = '!';
2850                    $attr['has_tpl'] = substr($attr['has_tpl'],1);
2851               }
2852               $if[] = $sign."\$core->tpl->getFilePath('".addslashes($attr['has_tpl'])."') !== false";
2853          }
2854
2855          if (isset($attr['has_tag'])) {
2856               $sign = 'true';
2857               if (substr($attr['has_tag'],0,1) == '!') {
2858                    $sign = 'false';
2859                    $attr['has_tag'] = substr($attr['has_tag'],1);
2860               }
2861               $if[] =  "\$core->tpl->tagExists('".addslashes($attr['has_tag'])."') === ".$sign;
2862          }
2863
2864          if (isset($attr['blog_id'])) {
2865               $sign = '';
2866               if (substr($attr['blog_id'],0,1) == '!') {
2867                    $sign = '!';
2868                    $attr['blog_id'] = substr($attr['blog_id'],1);
2869               }
2870               $if[] = $sign."(\$core->blog->id == '".addslashes($attr['blog_id'])."')";
2871          }
2872
2873          if (isset($attr['comments_active'])) {
2874               $sign = (boolean) $attr['comments_active'] ? '' : '!';
2875               $if[] = $sign.'$core->blog->settings->system->allow_comments';
2876          }
2877
2878          if (isset($attr['pings_active'])) {
2879               $sign = (boolean) $attr['pings_active'] ? '' : '!';
2880               $if[] = $sign.'$core->blog->settings->system->allow_trackbacks';
2881          }
2882
2883          if (isset($attr['wiki_comments'])) {
2884               $sign = (boolean) $attr['wiki_comments'] ? '' : '!';
2885               $if[] = $sign.'$core->blog->settings->system->wiki_comments';
2886          }
2887
2888          if (isset($attr['search_count']) &&
2889               preg_match('/^((=|!|&gt;|&lt;)=|(&gt;|&lt;))\s*[0-9]+$/',trim($attr['search_count']))) {
2890               $if[] = '(isset($_search_count) && $_search_count '.html::decodeEntities($attr['search_count']).')';
2891          }
2892
2893          $this->core->callBehavior('tplIfConditions','SysIf',$attr,$content,$if);
2894
2895          if (count($if) != 0) {
2896               return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>';
2897          } else {
2898               return $content;
2899          }
2900     }
2901
2902     /*dtd
2903     <!ELEMENT tpl:SysIfCommentPublished - - -- Container displayed if comment has been published -->
2904     */
2905     public function SysIfCommentPublished($attr,$content)
2906     {
2907          return
2908          '<?php if (!empty($_GET[\'pub\'])) : ?>'.
2909          $content.
2910          '<?php endif; ?>';
2911     }
2912
2913     /*dtd
2914     <!ELEMENT tpl:SysIfCommentPending - - -- Container displayed if comment is pending after submission -->
2915     */
2916     public function SysIfCommentPending($attr,$content)
2917     {
2918          return
2919          '<?php if (isset($_GET[\'pub\']) && $_GET[\'pub\'] == 0) : ?>'.
2920          $content.
2921          '<?php endif; ?>';
2922     }
2923
2924     /*dtd
2925     <!ELEMENT tpl:SysFeedSubtitle - O -- Feed subtitle -->
2926     */
2927     public function SysFeedSubtitle($attr)
2928     {
2929          $f = $this->getFilters($attr);
2930          return '<?php if ($_ctx->feed_subtitle !== null) { echo '.sprintf($f,'$_ctx->feed_subtitle').';} ?>';
2931     }
2932
2933     /*dtd
2934     <!ELEMENT tpl:SysIfFormError - O -- Container displayed if an error has been detected after form submission -->
2935     */
2936     public function SysIfFormError($attr,$content)
2937     {
2938          return
2939          '<?php if ($_ctx->form_error !== null) : ?>'.
2940          $content.
2941          '<?php endif; ?>';
2942     }
2943
2944     /*dtd
2945     <!ELEMENT tpl:SysFormError - O -- Form error -->
2946     */
2947     public function SysFormError($attr)
2948     {
2949          return
2950          '<?php if ($_ctx->form_error !== null) { echo $_ctx->form_error; } ?>';
2951     }
2952
2953     public function SysPoweredBy($attr)
2954     {
2955          return
2956          '<?php printf(__("Powered by %s"),"<a href=\"http://dotclear.org/\">Dotclear</a>"); ?>';
2957     }
2958
2959     public function SysSearchString($attr)
2960     {
2961          $s = isset($attr['string']) ? $attr['string'] : '%1$s';
2962
2963          $f = $this->getFilters($attr);
2964          return '<?php if (isset($_search)) { echo sprintf(__(\''.$s.'\'),'.sprintf($f,'$_search').',$_search_count);} ?>';
2965     }
2966
2967     public function SysSelfURI($attr)
2968     {
2969          $f = $this->getFilters($attr);
2970          return '<?php echo '.sprintf($f,'http::getSelfURI()').'; ?>';
2971     }
2972
2973     /*dtd
2974     <!ELEMENT tpl:else - O -- else: statement -->
2975     */
2976     public function GenericElse($attr)
2977     {
2978          return '<?php else: ?>';
2979     }
2980}
2981
2982# Template nodes, for parsing purposes
2983
2984# Generic list node, this one may only be instanciated
2985# once for root element
2986class tplNode
2987{
2988     # Basic tree structure : links to parent, children forrest
2989     protected $parentNode;
2990     protected $children;
2991
2992     public function __construct() {
2993          $this->children = array();
2994          $this->parentNode = null;
2995     }
2996
2997     // Returns compiled block
2998     public function compile($tpl) {
2999          $res='';
3000          foreach ($this->children as $child) {
3001               $res .= $child->compile($tpl);
3002          }
3003          return $res;
3004     }
3005
3006     # Add a children to current node
3007     public function addChild ($child) {
3008          $this->children[] = $child;
3009          $child->setParent($this);
3010     }
3011
3012     # Defines parent for current node
3013     protected function setParent($parent) {
3014          $this->parentNode = $parent;
3015     }
3016
3017     # Retrieves current node parent.
3018     # If parent is root node, null is returned
3019     public function getParent() {
3020          return $this->parentNode;
3021     }
3022
3023     # Current node tag
3024     public function getTag() {
3025          return "ROOT";
3026     }
3027}
3028
3029// Text node, for any non-tpl content
3030class tplNodeText extends tplNode
3031{
3032     // Simple text node, only holds its content
3033     protected $content;
3034
3035     public function __construct($text) {
3036          parent::__construct();
3037          $this->content=$text;
3038     }
3039
3040     public function compile($tpl) {
3041          return $this->content;
3042     }
3043
3044     public function getTag() {
3045          return "TEXT";
3046     }
3047}
3048
3049// Block node, for all <tpl:Tag>...</tpl:Tag>
3050class tplNodeBlock extends tplNode
3051{
3052     protected $attr;
3053     protected $tag;
3054     protected $closed;
3055
3056     public function __construct($tag,$attr) {
3057          parent::__construct();
3058          $this->content='';
3059          $this->tag = $tag;
3060          $this->attr = $attr;
3061          $this->closed=false;
3062     }
3063     public function setClosing() {
3064          $this->closed = true;
3065     }
3066     public function isClosed() {
3067          return $this->closed;
3068     }
3069     public function compile($tpl) {
3070          if ($this->closed) {
3071               $content = parent::compile($tpl);
3072               return $tpl->compileBlockNode($this->tag,$this->attr,$content);
3073          } else {
3074               // if tag has not been closed, silently ignore its content...
3075               return '';
3076          }
3077     }
3078     public function getTag() {
3079          return $this->tag;
3080     }
3081}
3082
3083// Value node, for all {{tpl:Tag}}
3084class tplNodeValue extends tplNode
3085{
3086     protected $attr;
3087     protected $str_attr;
3088     protected $tag;
3089
3090     public function __construct($tag,$attr,$str_attr) {
3091          parent::__construct();
3092          $this->content='';
3093          $this->tag = $tag;
3094          $this->attr = $attr;
3095          $this->str_attr = $str_attr;
3096     }
3097
3098     public function compile($tpl) {
3099          return $tpl->compileValueNode($this->tag,$this->attr,$this->str_attr);
3100     }
3101
3102     public function getTag() {
3103          return $this->tag;
3104     }
3105}
Note: See TracBrowser for help on using the repository browser.

Sites map