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