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