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