Dotclear

source: inc/public/class.dc.template.php @ 3172:e675d86e4e4e

Revision 3172:e675d86e4e4e, 90.3 KB checked in by franck <carnet.franck.paul@…>, 10 years ago (diff)

Add {{tpl:EntryCategoryDescription}}, closes #2162

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

Sites map