remove_php = !$core->blog->settings->system->tpl_allow_php; $this->use_cache = $core->blog->settings->system->tpl_use_cache; $this->tag_block = '|>)((?:[^<]|<(?!/?tpl:\1)|(?R))*)'; $this->tag_value = '{{tpl:(\w+)(\s(.*?))?}}'; $this->core =& $core; # Transitional tags $this->addValue('EntryTrackbackCount',array($this,'EntryPingCount')); $this->addValue('EntryTrackbackData',array($this,'EntryPingData')); $this->addValue('EntryTrackbackLink',array($this,'EntryPingLink')); # l10n $this->addValue('lang',array($this,'l10n')); # Loops test tags $this->addBlock('LoopPosition',array($this,'LoopPosition')); $this->addValue('LoopIndex',array($this,'LoopIndex')); # Archives $this->addBlock('Archives',array($this,'Archives')); $this->addBlock('ArchivesHeader',array($this,'ArchivesHeader')); $this->addBlock('ArchivesFooter',array($this,'ArchivesFooter')); $this->addBlock('ArchivesYearHeader',array($this,'ArchivesYearHeader')); $this->addBlock('ArchivesYearFooter',array($this,'ArchivesYearFooter')); $this->addValue('ArchiveDate',array($this,'ArchiveDate')); $this->addBlock('ArchiveNext',array($this,'ArchiveNext')); $this->addBlock('ArchivePrevious',array($this,'ArchivePrevious')); $this->addValue('ArchiveEntriesCount',array($this,'ArchiveEntriesCount')); $this->addValue('ArchiveURL',array($this,'ArchiveURL')); # Blog $this->addValue('BlogArchiveURL',array($this,'BlogArchiveURL')); $this->addValue('BlogCopyrightNotice',array($this,'BlogCopyrightNotice')); $this->addValue('BlogDescription',array($this,'BlogDescription')); $this->addValue('BlogEditor',array($this,'BlogEditor')); $this->addValue('BlogFeedID',array($this,'BlogFeedID')); $this->addValue('BlogFeedURL',array($this,'BlogFeedURL')); $this->addValue('BlogRSDURL',array($this,'BlogRSDURL')); $this->addValue('BlogName',array($this,'BlogName')); $this->addValue('BlogLanguage',array($this,'BlogLanguage')); $this->addValue('BlogThemeURL',array($this,'BlogThemeURL')); $this->addValue('BlogParentThemeURL',array($this,'BlogParentThemeURL')); $this->addValue('BlogUpdateDate',array($this,'BlogUpdateDate')); $this->addValue('BlogID',array($this,'BlogID')); $this->addValue('BlogURL',array($this,'BlogURL')); $this->addValue('BlogXMLRPCURL',array($this,'BlogXMLRPCURL')); $this->addValue('BlogPublicURL',array($this,'BlogPublicURL')); $this->addValue('BlogQmarkURL',array($this,'BlogQmarkURL')); $this->addValue('BlogMetaRobots',array($this,'BlogMetaRobots')); $this->addValue('BlogJsJQuery',array($this,'BlogJsJQuery')); # Categories $this->addBlock('Categories',array($this,'Categories')); $this->addBlock('CategoriesHeader',array($this,'CategoriesHeader')); $this->addBlock('CategoriesFooter',array($this,'CategoriesFooter')); $this->addBlock('CategoryIf',array($this,'CategoryIf')); $this->addBlock('CategoryFirstChildren',array($this,'CategoryFirstChildren')); $this->addBlock('CategoryParents',array($this,'CategoryParents')); $this->addValue('CategoryFeedURL',array($this,'CategoryFeedURL')); $this->addValue('CategoryURL',array($this,'CategoryURL')); $this->addValue('CategoryShortURL',array($this,'CategoryShortURL')); $this->addValue('CategoryDescription',array($this,'CategoryDescription')); $this->addValue('CategoryTitle',array($this,'CategoryTitle')); $this->addValue('CategoryEntriesCount',array($this,'CategoryEntriesCount')); # Comments $this->addBlock('Comments',array($this,'Comments')); $this->addValue('CommentAuthor',array($this,'CommentAuthor')); $this->addValue('CommentAuthorDomain',array($this,'CommentAuthorDomain')); $this->addValue('CommentAuthorLink',array($this,'CommentAuthorLink')); $this->addValue('CommentAuthorMailMD5',array($this,'CommentAuthorMailMD5')); $this->addValue('CommentAuthorURL',array($this,'CommentAuthorURL')); $this->addValue('CommentContent',array($this,'CommentContent')); $this->addValue('CommentDate',array($this,'CommentDate')); $this->addValue('CommentTime',array($this,'CommentTime')); $this->addValue('CommentEmail',array($this,'CommentEmail')); $this->addValue('CommentEntryTitle',array($this,'CommentEntryTitle')); $this->addValue('CommentFeedID',array($this,'CommentFeedID')); $this->addValue('CommentID',array($this,'CommentID')); $this->addBlock('CommentIf',array($this,'CommentIf')); $this->addValue('CommentIfFirst',array($this,'CommentIfFirst')); $this->addValue('CommentIfMe',array($this,'CommentIfMe')); $this->addValue('CommentIfOdd',array($this,'CommentIfOdd')); $this->addValue('CommentIP',array($this,'CommentIP')); $this->addValue('CommentOrderNumber',array($this,'CommentOrderNumber')); $this->addBlock('CommentsFooter',array($this,'CommentsFooter')); $this->addBlock('CommentsHeader',array($this,'CommentsHeader')); $this->addValue('CommentPostURL',array($this,'CommentPostURL')); $this->addBlock('IfCommentAuthorEmail',array($this,'IfCommentAuthorEmail')); $this->addValue('CommentHelp',array($this,'CommentHelp')); # Comment preview $this->addBlock('IfCommentPreview',array($this,'IfCommentPreview')); $this->addBlock('IfCommentPreviewOptional',array($this,'IfCommentPreviewOptional')); $this->addValue('CommentPreviewName',array($this,'CommentPreviewName')); $this->addValue('CommentPreviewEmail',array($this,'CommentPreviewEmail')); $this->addValue('CommentPreviewSite',array($this,'CommentPreviewSite')); $this->addValue('CommentPreviewContent',array($this,'CommentPreviewContent')); $this->addValue('CommentPreviewCheckRemember',array($this,'CommentPreviewCheckRemember')); # Entries $this->addBlock('DateFooter',array($this,'DateFooter')); $this->addBlock('DateHeader',array($this,'DateHeader')); $this->addBlock('Entries',array($this,'Entries')); $this->addBlock('EntriesFooter',array($this,'EntriesFooter')); $this->addBlock('EntriesHeader',array($this,'EntriesHeader')); $this->addValue('EntryExcerpt',array($this,'EntryExcerpt')); $this->addValue('EntryAuthorCommonName',array($this,'EntryAuthorCommonName')); $this->addValue('EntryAuthorDisplayName',array($this,'EntryAuthorDisplayName')); $this->addValue('EntryAuthorEmail',array($this,'EntryAuthorEmail')); $this->addValue('EntryAuthorID',array($this,'EntryAuthorID')); $this->addValue('EntryAuthorLink',array($this,'EntryAuthorLink')); $this->addValue('EntryAuthorURL',array($this,'EntryAuthorURL')); $this->addValue('EntryBasename',array($this,'EntryBasename')); $this->addValue('EntryCategory',array($this,'EntryCategory')); $this->addBlock('EntryCategoriesBreadcrumb',array($this,'EntryCategoriesBreadcrumb')); $this->addValue('EntryCategoryID',array($this,'EntryCategoryID')); $this->addValue('EntryCategoryURL',array($this,'EntryCategoryURL')); $this->addValue('EntryCategoryShortURL',array($this,'EntryCategoryShortURL')); $this->addValue('EntryCommentCount',array($this,'EntryCommentCount')); $this->addValue('EntryContent',array($this,'EntryContent')); $this->addValue('EntryDate',array($this,'EntryDate')); $this->addValue('EntryFeedID',array($this,'EntryFeedID')); $this->addValue('EntryFirstImage',array($this,'EntryFirstImage')); $this->addValue('EntryID',array($this,'EntryID')); $this->addBlock('EntryIf',array($this,'EntryIf')); $this->addValue('EntryIfFirst',array($this,'EntryIfFirst')); $this->addValue('EntryIfOdd',array($this,'EntryIfOdd')); $this->addValue('EntryIfSelected',array($this,'EntryIfSelected')); $this->addValue('EntryLang',array($this,'EntryLang')); $this->addBlock('EntryNext',array($this,'EntryNext')); $this->addValue('EntryPingCount',array($this,'EntryPingCount')); $this->addValue('EntryPingData',array($this,'EntryPingData')); $this->addValue('EntryPingLink',array($this,'EntryPingLink')); $this->addBlock('EntryPrevious',array($this,'EntryPrevious')); $this->addValue('EntryTitle',array($this,'EntryTitle')); $this->addValue('EntryTime',array($this,'EntryTime')); $this->addValue('EntryURL',array($this,'EntryURL')); # Languages $this->addBlock('Languages',array($this,'Languages')); $this->addBlock('LanguagesHeader',array($this,'LanguagesHeader')); $this->addBlock('LanguagesFooter',array($this,'LanguagesFooter')); $this->addValue('LanguageCode',array($this,'LanguageCode')); $this->addBlock('LanguageIfCurrent',array($this,'LanguageIfCurrent')); $this->addValue('LanguageURL',array($this,'LanguageURL')); # Pagination $this->addBlock('Pagination',array($this,'Pagination')); $this->addValue('PaginationCounter',array($this,'PaginationCounter')); $this->addValue('PaginationCurrent',array($this,'PaginationCurrent')); $this->addBlock('PaginationIf',array($this,'PaginationIf')); $this->addValue('PaginationURL',array($this,'PaginationURL')); # Trackbacks $this->addValue('PingBlogName',array($this,'PingBlogName')); $this->addValue('PingContent',array($this,'PingContent')); $this->addValue('PingDate',array($this,'PingDate')); $this->addValue('PingEntryTitle',array($this,'PingEntryTitle')); $this->addValue('PingFeedID',array($this,'PingFeedID')); $this->addValue('PingID',array($this,'PingID')); $this->addValue('PingIfFirst',array($this,'PingIfFirst')); $this->addValue('PingIfOdd',array($this,'PingIfOdd')); $this->addValue('PingIP',array($this,'PingIP')); $this->addValue('PingNoFollow',array($this,'PingNoFollow')); $this->addValue('PingOrderNumber',array($this,'PingOrderNumber')); $this->addValue('PingPostURL',array($this,'PingPostURL')); $this->addBlock('Pings',array($this,'Pings')); $this->addBlock('PingsFooter',array($this,'PingsFooter')); $this->addBlock('PingsHeader',array($this,'PingsHeader')); $this->addValue('PingTime',array($this,'PingTime')); $this->addValue('PingTitle',array($this,'PingTitle')); $this->addValue('PingAuthorURL',array($this,'PingAuthorURL')); # System $this->addValue('SysBehavior',array($this,'SysBehavior')); $this->addBlock('SysIf',array($this,'SysIf')); $this->addBlock('SysIfCommentPublished',array($this,'SysIfCommentPublished')); $this->addBlock('SysIfCommentPending',array($this,'SysIfCommentPending')); $this->addBlock('SysIfFormError',array($this,'SysIfFormError')); $this->addValue('SysFeedSubtitle',array($this,'SysFeedSubtitle')); $this->addValue('SysFormError',array($this,'SysFormError')); $this->addValue('SysPoweredBy',array($this,'SysPoweredBy')); $this->addValue('SysSearchString',array($this,'SysSearchString')); $this->addValue('SysSelfURI',array($this,'SysSelfURI')); # Generic $this->addValue('else',array($this,'GenericElse')); } public function getData($________) { # --BEHAVIOR-- tplBeforeData if ($this->core->hasBehavior('tplBeforeData')) { self::$_r = $this->core->callBehavior('tplBeforeData',$this->core); if (self::$_r) { return self::$_r; } } parent::getData($________); # --BEHAVIOR-- tplAfterData if ($this->core->hasBehavior('tplAfterData')) { $this->core->callBehavior('tplAfterData',$this->core,self::$_r); } return self::$_r; } public function compileBlockNode($tag,$attr,$content) { $this->current_tag = $tag; $attr = new ArrayObject($attr); # --BEHAVIOR-- templateBeforeBlock $res = $this->core->callBehavior('templateBeforeBlock',$this->core,$this->current_tag,$attr); # --BEHAVIOR-- templateInsideBlock $this->core->callBehavior('templateInsideBlock',$this->core,$this->current_tag,$attr,array(&$content)); $res .= parent::compileBlockNode($this->current_tag,$attr,$content); # --BEHAVIOR-- templateAfterBlock $res .= $this->core->callBehavior('templateAfterBlock',$this->core,$this->current_tag,$attr); return $res; } public function compileValueNode($tag,$attr,$str_attr) { $this->current_tag = $tag; $attr = new ArrayObject($attr); # --BEHAVIOR-- templateBeforeValue $res = $this->core->callBehavior('templateBeforeValue',$this->core,$this->current_tag,$attr); $res .= parent::compileValueNode($this->current_tag,$attr,$str_attr); # --BEHAVIOR-- templateAfterValue $res .= $this->core->callBehavior('templateAfterValue',$this->core,$this->current_tag,$attr); return $res; } public function getFilters($attr) { $p[0] = '0'; # encode_xml $p[1] = '0'; # remove_html $p[2] = '0'; # cut_string $p[3] = '0'; # lower_case $p[4] = '0'; # upper_case or capitalize $p[5] = '0'; # encode_url $p[0] = (integer) (!empty($attr['encode_xml']) || !empty($attr['encode_html'])); $p[1] = (integer) !empty($attr['remove_html']); if (!empty($attr['cut_string']) && (integer) $attr['cut_string'] > 0) { $p[2] = (integer) $attr['cut_string']; } $p[3] = (integer) !empty($attr['lower_case']); $p[4] = (integer) !empty($attr['upper_case']); $p[4] = (!empty($attr['capitalize']) ? 2 : $p[4]); $p[5] = (integer) !empty($attr['encode_url']); return "context::global_filter(%s,".implode(",",$p).",'".addslashes($this->current_tag)."')"; } public static function getOperator($op) { switch (strtolower($op)) { case 'or': case '||': return '||'; case 'and': case '&&': default: return '&&'; } } public function getSortByStr($attr,$table = null) { $res = array(); $default_order = 'desc'; $default_alias = array( 'post' => array( 'title' => 'post_title', 'selected' => 'post_selected', 'author' => 'user_id', 'date' => 'post_dt', 'id' => 'post_id', 'comment' => 'nb_comment', 'trackback' => 'nb_trackback' ), 'comment' => array( 'author' => 'comment_author', 'date' => 'comment_dt', 'id' => 'comment_id' ) ); $alias = new ArrayObject(); # --BEHAVIOR-- templateCustomSortByAlias $this->core->callBehavior('templateCustomSortByAlias',$alias); $alias = $alias->getArrayCopy(); if (is_array($alias)) { foreach ($alias as $k => $v) { if (!is_array($v)) { $alias[$k] = array(); } if (!is_array($v)) { $default_alias[$k] = array(); } $default_alias[$k] = array_merge($default_alias[$k],$alias[$k]); } } if (!array_key_exists($table,$default_alias)) { return implode(', ',$res); } if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) { $default_order = $attr['order']; } if (isset($attr['sortby'])) { $sorts = explode(',',$attr['sortby']); foreach ($sorts as $k => $sort) { $order = $default_order; if (preg_match('/([a-z]*)\s*\?(desc|asc)$/i',$sort,$matches)) { $sort = $matches[1]; $order = $matches[2]; } if (array_key_exists($sort,$default_alias[$table])) { array_push($res,$default_alias[$table][$sort].' '.$order); } } } if (count($res) === 0) { array_push($res,$default_alias[$table]['date'].' '.$default_order); } return implode(', ',$res); } public static function getAge($attr) { if (isset($attr['age']) && preg_match('/^(\-[0-9]+|last).*$/i',$attr['age'])) { if (($ts = strtotime($attr['age'])) !== false) { return dt::str('%Y-%m-%d %H:%m:%S',$ts); } } return ''; } public function displayCounter($variable,$values,$attr,$count_only_by_default=false) { if (isset($attr['count_only'])) { $count_only=($attr['count_only']==1); } else { $count_only = $count_only_by_default; } if ($count_only) { return ""; } else { $v=$values; if (isset($attr['none'])) { $v['none'] = addslashes($attr['none']); } if (isset($attr['one'])) { $v['one'] = addslashes($attr['one']); } if (isset($attr['more'])) { $v['more'] = addslashes($attr['more']); } return ""; } } /* TEMPLATE FUNCTIONS ------------------------------------------------------- */ public function l10n($attr,$str_attr) { # Normalize content $str_attr = preg_replace('/\s+/x',' ',$str_attr); return ""; } public function LoopPosition($attr,$content) { $start = isset($attr['start']) ? (integer) $attr['start'] : '0'; $length = isset($attr['length']) ? (integer) $attr['length'] : 'null'; $even = isset($attr['even']) ? (integer) (boolean) $attr['even'] : 'null'; $modulo = isset($attr['modulo']) ? (integer) $attr['modulo'] : 'null'; if ($start > 0) { $start--; } return 'loopPosition('.$start.','.$length.','.$even.','.$modulo.')) : ?>'. $content. ""; } public function LoopIndex($attr) { $f = $this->getFilters($attr); return 'cur_loop ? 0 : $_ctx->cur_loop->index() + 1)').'; ?>'; } /* Archives ------------------------------------------- */ /*dtd */ public function Archives($attr,$content) { $p = "if (!isset(\$params)) \$params = array();\n"; $p .= "\$params['type'] = 'month';\n"; if (isset($attr['type'])) { $p .= "\$params['type'] = '".addslashes($attr['type'])."';\n"; } if (isset($attr['category'])) { $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n"; } if (isset($attr['post_type'])) { $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; } if (isset($attr['post_lang'])) { $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n"; } if (empty($attr['no_context']) && !isset($attr['category'])) { $p .= 'if ($_ctx->exists("categories")) { '. "\$params['cat_id'] = \$_ctx->categories->cat_id; ". "}\n"; } $order = 'desc'; if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) { $p .= "\$params['order'] = '".$attr['order']."';\n "; } $res = "core->callBehavior("templatePrepareParams", array("tag" => "Archives","method" => "blog::getDates"), $attr,$content); $res .= '$_ctx->archives = $core->blog->getDates($params); unset($params);'."\n"; $res .= "?>\n"; $res .= 'archives->fetch()) : ?>'.$content.'archives = null; ?>'; return $res; } /*dtd */ public function ArchivesHeader($attr,$content) { return "archives->isStart()) : ?>". $content. ""; } /*dtd */ public function ArchivesFooter($attr,$content) { return "archives->isEnd()) : ?>". $content. ""; } /*dtd */ public function ArchivesYearHeader($attr,$content) { return "archives->yearHeader()) : ?>". $content. ""; } /*dtd */ public function ArchivesYearFooter($attr,$content) { return "archives->yearFooter()) : ?>". $content. ""; } /*dtd */ public function ArchiveDate($attr) { $format = '%B %Y'; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } $f = $this->getFilters($attr); return 'archives->dt)").'; ?>'; } /*dtd */ public function ArchiveEntriesCount($attr) { $f = $this->getFilters($attr); return $this->displayCounter( sprintf($f,'$_ctx->archives->nb_post'), array( 'none' => 'no archive', 'one' => 'one archive', 'more' => '%d archives' ), $attr, true ); } /*dtd */ public function ArchiveNext($attr,$content) { $p = "if (!isset(\$params)) \$params = array();\n"; $p .= "\$params['type'] = 'month';\n"; if (isset($attr['type'])) { $p .= "\$params['type'] = '".addslashes($attr['type'])."';\n"; } if (isset($attr['post_type'])) { $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; } if (isset($attr['post_lang'])) { $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n"; } $p .= "\$params['next'] = \$_ctx->archives->dt;"; $res = "core->callBehavior("templatePrepareParams", array("tag" => "ArchiveNext","method" => "blog::getDates"), $attr, $content); $res .= '$_ctx->archives = $core->blog->getDates($params); unset($params);'."\n"; $res .= "?>\n"; $res .= 'archives->fetch()) : ?>'.$content.'archives = null; ?>'; return $res; } /*dtd */ public function ArchivePrevious($attr,$content) { $p = 'if (!isset($params)) $params = array();'; $p .= "\$params['type'] = 'month';\n"; if (isset($attr['type'])) { $p .= "\$params['type'] = '".addslashes($attr['type'])."';\n"; } if (isset($attr['post_type'])) { $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; } if (isset($attr['post_lang'])) { $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n"; } $p .= "\$params['previous'] = \$_ctx->archives->dt;"; $res = "core->callBehavior("templatePrepareParams", array("tag" => "ArchivePrevious","method" => "blog::getDates"), $attr, $content); $res .= $p; $res .= '$_ctx->archives = $core->blog->getDates($params); unset($params);'."\n"; $res .= "?>\n"; $res .= 'archives->fetch()) : ?>'.$content.'archives = null; ?>'; return $res; } /*dtd */ public function ArchiveURL($attr) { $f = $this->getFilters($attr); return 'archives->url($core)').'; ?>'; } /* Blog ----------------------------------------------- */ /*dtd */ public function BlogArchiveURL($attr) { $f = $this->getFilters($attr); return 'blog->url.$core->url->getURLFor("archive")').'; ?>'; } /*dtd */ public function BlogCopyrightNotice($attr) { $f = $this->getFilters($attr); return 'blog->settings->system->copyright_notice').'; ?>'; } /*dtd */ public function BlogDescription($attr) { $f = $this->getFilters($attr); return 'blog->desc').'; ?>'; } /*dtd */ public function BlogEditor($attr) { $f = $this->getFilters($attr); return 'blog->settings->system->editor').'; ?>'; } /*dtd */ public function BlogFeedID($attr) { $f = $this->getFilters($attr); return 'blog->uid').'; ?>'; } /*dtd */ public function BlogFeedURL($attr) { $type = !empty($attr['type']) ? $attr['type'] : 'atom'; if (!preg_match('#^(rss2|atom)$#',$type)) { $type = 'atom'; } $f = $this->getFilters($attr); return 'blog->url.$core->url->getURLFor("feed","'.$type.'")').'; ?>'; } /*dtd */ public function BlogName($attr) { $f = $this->getFilters($attr); return 'blog->name').'; ?>'; } /*dtd */ public function BlogLanguage($attr) { $f = $this->getFilters($attr); return 'blog->settings->system->lang').'; ?>'; } /*dtd */ public function BlogThemeURL($attr) { $f = $this->getFilters($attr); return 'blog->settings->system->themes_url."/".$core->blog->settings->system->theme').'; ?>'; } /*dtd */ public function BlogParentThemeURL($attr) { $f = $this->getFilters($attr); $parent = '$core->themes->moduleInfo($core->blog->settings->system->theme,\'parent\')'; return 'blog->settings->system->themes_url."/".('."$parent".' ? '."$parent".' : $core->blog->settings->system->theme)').'; ?>'; } /*dtd */ public function BlogPublicURL($attr) { $f = $this->getFilters($attr); return 'blog->settings->system->public_url').'; ?>'; } /*dtd */ public function BlogUpdateDate($attr) { $format = ''; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } else { $format = '%Y-%m-%d %H:%M:%S'; } $iso8601 = !empty($attr['iso8601']); $rfc822 = !empty($attr['rfc822']); $f = $this->getFilters($attr); if ($rfc822) { return 'blog->upddt,\$core->blog->settings->system->blog_timezone)").'; ?>'; } elseif ($iso8601) { return 'blog->upddt,\$core->blog->settings->system->blog_timezone)").'; ?>'; } else { return 'blog->upddt)").'; ?>'; } } /*dtd */ public function BlogID($attr) { $f = $this->getFilters($attr); return 'blog->id').'; ?>'; } /*dtd */ public function BlogRSDURL($attr) { $f = $this->getFilters($attr); return 'blog->url.$core->url->getURLFor(\'rsd\')').'; ?>'; } /*dtd */ public function BlogXMLRPCURL($attr) { $f = $this->getFilters($attr); return 'blog->url.$core->url->getURLFor(\'xmlrpc\',$core->blog->id)').'; ?>'; } /*dtd */ public function BlogURL($attr) { $f = $this->getFilters($attr); return 'blog->url').'; ?>'; } /*dtd */ public function BlogQmarkURL($attr) { $f = $this->getFilters($attr); return 'blog->getQmarkURL()').'; ?>'; } /*dtd */ public function BlogMetaRobots($attr) { $robots = isset($attr['robots']) ? addslashes($attr['robots']) : ''; return "blog->settings->system->robots_policy,'".$robots."'); ?>"; } /*dtd */ public function BlogJsJQuery($attr) { $f = $this->getFilters($attr); return 'blog->getJsJQuery()').'; ?>'; } /* Categories ----------------------------------------- */ /*dtd */ public function Categories($attr,$content) { $p = "if (!isset(\$params)) \$params = array();\n"; if (isset($attr['url'])) { $p .= "\$params['cat_url'] = '".addslashes($attr['url'])."';\n"; } if (!empty($attr['post_type'])) { $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; } if (!empty($attr['level'])) { $p .= "\$params['level'] = ".(integer) $attr['level'].";\n"; } if (isset($attr['with_empty']) && ((boolean) $attr['with_empty'] == true)) { $p .= '$params[\'without_empty\'] = false;'; } $res = "core->callBehavior("templatePrepareParams", array("tag" => "Categories","method" => "blog::getCategories"), $attr,$content); $res .= '$_ctx->categories = $core->blog->getCategories($params);'."\n"; $res .= "?>\n"; $res .= 'categories->fetch()) : ?>'.$content.'categories = null; unset($params); ?>'; return $res; } /*dtd */ public function CategoriesHeader($attr,$content) { return "categories->isStart()) : ?>". $content. ""; } /*dtd */ public function CategoriesFooter($attr,$content) { return "categories->isEnd()) : ?>". $content. ""; } /*dtd */ public function CategoryIf($attr,$content) { $if = new ArrayObject(); $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; if (isset($attr['url'])) { $url = addslashes(trim($attr['url'])); if (substr($url,0,1) == '!') { $url = substr($url,1); $if[] = '($_ctx->categories->cat_url != "'.$url.'")'; } else { $if[] = '($_ctx->categories->cat_url == "'.$url.'")'; } } if (isset($attr['has_entries'])) { $sign = (boolean) $attr['has_entries'] ? '>' : '=='; $if[] = '$_ctx->categories->nb_post '.$sign.' 0'; } if (isset($attr['has_description'])) { $sign = (boolean) $attr['has_description'] ? '!=' : '=='; $if[] = '$_ctx->categories->cat_desc '.$sign.' ""'; } $this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if); if (count($if) != 0) { return ''.$content.''; } else { return $content; } } /*dtd */ public function CategoryFirstChildren($attr,$content) { return "categories = $core->blog->getCategoryFirstChildren($_ctx->categories->cat_id);'."\n". 'while ($_ctx->categories->fetch()) : ?>'.$content.'categories = null; ?>'; } /*dtd */ public function CategoryParents($attr,$content) { return "categories = $core->blog->getCategoryParents($_ctx->categories->cat_id);'."\n". 'while ($_ctx->categories->fetch()) : ?>'.$content.'categories = null; ?>'; } /*dtd */ public function CategoryFeedURL($attr) { $type = !empty($attr['type']) ? $attr['type'] : 'atom'; if (!preg_match('#^(rss2|atom)$#',$type)) { $type = 'atom'; } $f = $this->getFilters($attr); return 'blog->url.$core->url->getURLFor("feed","category/".'. '$_ctx->categories->cat_url."/'.$type.'")').'; ?>'; } /*dtd */ public function CategoryURL($attr) { $f = $this->getFilters($attr); return 'blog->url.$core->url->getURLFor("category",'. '$_ctx->categories->cat_url)').'; ?>'; } /*dtd */ public function CategoryShortURL($attr) { $f = $this->getFilters($attr); return 'categories->cat_url').'; ?>'; } /*dtd */ public function CategoryDescription($attr) { $f = $this->getFilters($attr); return 'categories->cat_desc').'; ?>'; } /*dtd */ public function CategoryTitle($attr) { $f = $this->getFilters($attr); return 'categories->cat_title').'; ?>'; } /*dtd */ public function CategoryEntriesCount($attr) { $f = $this->getFilters($attr); return $this->displayCounter( sprintf($f,'$_ctx->categories->nb_post'), array( 'none' => 'No post', 'one' => 'One post', 'more' => '%d posts' ), $attr, true ); } /* Entries -------------------------------------------- */ /*dtd */ public function Entries($attr,$content) { $lastn = -1; if (isset($attr['lastn'])) { $lastn = abs((integer) $attr['lastn'])+0; } $p = 'if (!isset($_page_number)) { $_page_number = 1; }'."\n"; if ($lastn != 0) { // Set limit (aka nb of entries needed) if ($lastn > 0) { // nb of entries per page specified in template -> regular pagination $p .= "\$params['limit'] = ".$lastn.";\n"; $p .= "\$nb_entry_first_page = \$nb_entry_per_page = ".$lastn.";\n"; } else { // nb of entries per page not specified -> use ctx settings $p .= "\$nb_entry_first_page=\$_ctx->nb_entry_first_page; \$nb_entry_per_page = \$_ctx->nb_entry_per_page;\n"; $p .= "if ((\$core->url->type == 'default') || (\$core->url->type == 'default-page')) {\n"; $p .= " \$params['limit'] = (\$_page_number == 1 ? \$nb_entry_first_page : \$nb_entry_per_page);\n"; $p .= "} else {\n"; $p .= " \$params['limit'] = \$nb_entry_per_page;\n"; $p .= "}\n"; } // Set offset (aka index of first entry) if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0") { // standard pagination, set offset $p .= "if ((\$core->url->type == 'default') || (\$core->url->type == 'default-page')) {\n"; $p .= " \$params['limit'] = array((\$_page_number == 1 ? 0 : (\$_page_number - 2) * \$nb_entry_per_page + \$nb_entry_first_page),\$params['limit']);\n"; $p .= "} else {\n"; $p .= " \$params['limit'] = array((\$_page_number - 1) * \$nb_entry_per_page,\$params['limit']);\n"; $p .= "}\n"; } else { // no pagination, get all posts from 0 to limit $p .= "\$params['limit'] = array(0, \$params['limit']);\n"; } } if (isset($attr['author'])) { $p .= "\$params['user_id'] = '".addslashes($attr['author'])."';\n"; } if (isset($attr['category'])) { $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n"; $p .= "context::categoryPostParam(\$params);\n"; } if (isset($attr['no_category']) && $attr['no_category']) { $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n"; $p .= "unset(\$params['cat_url']);\n"; } if (!empty($attr['type'])) { $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n"; } if (!empty($attr['url'])) { $p .= "\$params['post_url'] = '".addslashes($attr['url'])."';\n"; } if (empty($attr['no_context'])) { if (!isset($attr['author'])) { $p .= 'if ($_ctx->exists("users")) { '. "\$params['user_id'] = \$_ctx->users->user_id; ". "}\n"; } if (!isset($attr['category']) && (!isset($attr['no_category']) || !$attr['no_category'])) { $p .= 'if ($_ctx->exists("categories")) { '. "\$params['cat_id'] = \$_ctx->categories->cat_id.(\$core->blog->settings->system->inc_subcats?' ?sub':'');". "}\n"; } $p .= 'if ($_ctx->exists("archives")) { '. "\$params['post_year'] = \$_ctx->archives->year(); ". "\$params['post_month'] = \$_ctx->archives->month(); "; if (!isset($attr['lastn'])) { $p .= "unset(\$params['limit']); "; } $p .= "}\n"; $p .= 'if ($_ctx->exists("langs")) { '. "\$params['post_lang'] = \$_ctx->langs->post_lang; ". "}\n"; $p .= 'if (isset($_search)) { '. "\$params['search'] = \$_search; ". "}\n"; } $p .= "\$params['order'] = '".$this->getSortByStr($attr,'post')."';\n"; if (isset($attr['no_content']) && $attr['no_content']) { $p .= "\$params['no_content'] = true;\n"; } if (isset($attr['selected'])) { $p .= "\$params['post_selected'] = ".(integer) (boolean) $attr['selected'].";"; } if (isset($attr['age'])) { $age = $this->getAge($attr); $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : ''; } $res = "core->callBehavior("templatePrepareParams", array("tag" => "Entries","method" => "blog::getPosts"), $attr,$content); $res .= '$_ctx->post_params = $params;'."\n"; $res .= '$_ctx->posts = $core->blog->getPosts($params); unset($params);'."\n"; $res .= "?>\n"; $res .= 'posts->fetch()) : ?>'.$content.'posts = null; $_ctx->post_params = null; ?>'; return $res; } /*dtd */ public function DateHeader($attr,$content) { return "posts->firstPostOfDay()) : ?>". $content. ""; } /*dtd */ public function DateFooter($attr,$content) { return "posts->lastPostOfDay()) : ?>". $content. ""; } /*dtd */ public function EntryIf($attr,$content) { $if = new ArrayObject(); $extended = null; $hascategory = null; $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; if (isset($attr['type'])) { $type = trim($attr['type']); $type = !empty($type)?$type:'post'; $if[] = '$_ctx->posts->post_type == "'.addslashes($type).'"'; } if (isset($attr['url'])) { $url = trim($attr['url']); if (substr($url,0,1) == '!') { $url = substr($url,1); $if[] = '$_ctx->posts->post_url != "'.addslashes($url).'"'; } else { $if[] = '$_ctx->posts->post_url == "'.addslashes($url).'"'; } } if (isset($attr['category'])) { $category = addslashes(trim($attr['category'])); if (substr($category,0,1) == '!') { $category = substr($category,1); $if[] = '($_ctx->posts->cat_url != "'.$category.'")'; } else { $if[] = '($_ctx->posts->cat_url == "'.$category.'")'; } } if (isset($attr['first'])) { $sign = (boolean) $attr['first'] ? '=' : '!'; $if[] = '$_ctx->posts->index() '.$sign.'= 0'; } if (isset($attr['odd'])) { $sign = (boolean) $attr['odd'] ? '=' : '!'; $if[] = '($_ctx->posts->index()+1)%2 '.$sign.'= 1'; } if (isset($attr['extended'])) { $sign = (boolean) $attr['extended'] ? '' : '!'; $if[] = $sign.'$_ctx->posts->isExtended()'; } if (isset($attr['selected'])) { $sign = (boolean) $attr['selected'] ? '' : '!'; $if[] = $sign.'(boolean)$_ctx->posts->post_selected'; } if (isset($attr['has_category'])) { $sign = (boolean) $attr['has_category'] ? '' : '!'; $if[] = $sign.'$_ctx->posts->cat_id'; } if (isset($attr['comments_active'])) { $sign = (boolean) $attr['comments_active'] ? '' : '!'; $if[] = $sign.'$_ctx->posts->commentsActive()'; } if (isset($attr['pings_active'])) { $sign = (boolean) $attr['pings_active'] ? '' : '!'; $if[] = $sign.'$_ctx->posts->trackbacksActive()'; } if (isset($attr['has_comment'])) { $sign = (boolean) $attr['has_comment'] ? '' : '!'; $if[] = $sign.'$_ctx->posts->hasComments()'; } if (isset($attr['has_ping'])) { $sign = (boolean) $attr['has_ping'] ? '' : '!'; $if[] = $sign.'$_ctx->posts->hasTrackbacks()'; } if (isset($attr['show_comments'])) { if ((boolean) $attr['show_comments']) { $if[] = '($_ctx->posts->hasComments() || $_ctx->posts->commentsActive())'; } else { $if[] = '(!$_ctx->posts->hasComments() && !$_ctx->posts->commentsActive())'; } } if (isset($attr['show_pings'])) { if ((boolean) $attr['show_pings']) { $if[] = '($_ctx->posts->hasTrackbacks() || $_ctx->posts->trackbacksActive())'; } else { $if[] = '(!$_ctx->posts->hasTrackbacks() && !$_ctx->posts->trackbacksActive())'; } } if (isset($attr['republished'])) { $sign = (boolean) $attr['republished'] ? '' : '!'; $if[] = $sign.'(boolean)$_ctx->posts->isRepublished()'; } $this->core->callBehavior('tplIfConditions','EntryIf',$attr,$content,$if); if (count($if) != 0) { return ''.$content.''; } else { return $content; } } /*dtd */ public function EntryIfFirst($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'first'; $ret = html::escapeHTML($ret); return 'posts->index() == 0) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function EntryIfOdd($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'odd'; $ret = html::escapeHTML($ret); return 'posts->index()+1)%2 == 1) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function EntryIfSelected($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'selected'; $ret = html::escapeHTML($ret); return 'posts->post_selected) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function EntryContent($attr) { $urls = '0'; if (!empty($attr['absolute_urls'])) { $urls = '1'; } $f = $this->getFilters($attr); if (!empty($attr['full'])) { return 'posts->getExcerpt('.$urls.')." ".$_ctx->posts->getContent('.$urls.')').'; ?>'; } else { return 'posts->getContent('.$urls.')').'; ?>'; } } /*dtd */ public function EntryExcerpt($attr) { $urls = '0'; if (!empty($attr['absolute_urls'])) { $urls = '1'; } $f = $this->getFilters($attr); return 'posts->getExcerpt('.$urls.')').'; ?>'; } /*dtd */ public function EntryAuthorCommonName($attr) { $f = $this->getFilters($attr); return 'posts->getAuthorCN()').'; ?>'; } /*dtd */ public function EntryAuthorDisplayName($attr) { $f = $this->getFilters($attr); return 'posts->user_displayname').'; ?>'; } /*dtd */ public function EntryAuthorID($attr) { $f = $this->getFilters($attr); return 'posts->user_id').'; ?>'; } /*dtd */ public function EntryAuthorEmail($attr) { $p = 'true'; if (isset($attr['spam_protected']) && !$attr['spam_protected']) { $p = 'false'; } $f = $this->getFilters($attr); return 'posts->getAuthorEmail(".$p.")").'; ?>'; } /*dtd */ public function EntryAuthorLink($attr) { $f = $this->getFilters($attr); return 'posts->getAuthorLink()').'; ?>'; } /*dtd */ public function EntryAuthorURL($attr) { $f = $this->getFilters($attr); return 'posts->user_url').'; ?>'; } /*dtd */ public function EntryBasename($attr) { $f = $this->getFilters($attr); return 'posts->post_url').'; ?>'; } /*dtd */ public function EntryCategory($attr) { $f = $this->getFilters($attr); return 'posts->cat_title').'; ?>'; } /*dtd */ public function EntryCategoriesBreadcrumb($attr,$content) { return "categories = $core->blog->getCategoryParents($_ctx->posts->cat_id);'."\n". 'while ($_ctx->categories->fetch()) : ?>'.$content.'categories = null; ?>'; } /*dtd */ public function EntryCategoryID($attr) { $f = $this->getFilters($attr); return 'posts->cat_id').'; ?>'; } /*dtd */ public function EntryCategoryURL($attr) { $f = $this->getFilters($attr); return 'posts->getCategoryURL()').'; ?>'; } /*dtd */ public function EntryCategoryShortURL($attr) { $f = $this->getFilters($attr); return 'posts->cat_url').'; ?>'; } /*dtd */ public function EntryFeedID($attr) { $f = $this->getFilters($attr); return 'posts->getFeedID()').'; ?>'; } /*dtd */ public function EntryFirstImage($attr) { $size = !empty($attr['size']) ? $attr['size'] : ''; $class = !empty($attr['class']) ? $attr['class'] : ''; $with_category = !empty($attr['with_category']) ? 1 : 0; $no_tag = !empty($attr['no_tag']) ? 1 : 0; $content_only = !empty($attr['content_only']) ? 1 : 0; $cat_only = !empty($attr['cat_only']) ? 1 : 0; return ""; } /*dtd */ public function EntryID($attr) { $f = $this->getFilters($attr); return 'posts->post_id').'; ?>'; } /*dtd */ public function EntryLang($attr) { $f = $this->getFilters($attr); return 'posts->post_lang) { '. 'echo '.sprintf($f,'$_ctx->posts->post_lang').'; '. '} else {'. 'echo '.sprintf($f,'$core->blog->settings->system->lang').'; '. '} ?>'; } /*dtd */ public function EntryNext($attr,$content) { $restrict_to_category = !empty($attr['restrict_to_category']) ? '1' : '0'; $restrict_to_lang = !empty($attr['restrict_to_lang']) ? '1' : '0'; return 'blog->getNextPost($_ctx->posts,1,'.$restrict_to_category.','.$restrict_to_lang.'); ?>'."\n". ''. 'posts = $next_post; unset($next_post);'."\n". 'while ($_ctx->posts->fetch()) : ?>'. $content. 'posts = null; ?>'. "\n"; } /*dtd */ public function EntryPrevious($attr,$content) { $restrict_to_category = !empty($attr['restrict_to_category']) ? '1' : '0'; $restrict_to_lang = !empty($attr['restrict_to_lang']) ? '1' : '0'; return 'blog->getNextPost($_ctx->posts,-1,'.$restrict_to_category.','.$restrict_to_lang.'); ?>'."\n". ''. 'posts = $prev_post; unset($prev_post);'."\n". 'while ($_ctx->posts->fetch()) : ?>'. $content. 'posts = null; ?>'. "\n"; } /*dtd */ public function EntryTitle($attr) { $f = $this->getFilters($attr); return 'posts->post_title').'; ?>'; } /*dtd */ public function EntryURL($attr) { $f = $this->getFilters($attr); return 'posts->getURL()').'; ?>'; } /*dtd */ public function EntryDate($attr) { $format = ''; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } $iso8601 = !empty($attr['iso8601']); $rfc822 = !empty($attr['rfc822']); $type = (!empty($attr['creadt']) ? 'creadt' : ''); $type = (!empty($attr['upddt']) ? 'upddt' : $type); $f = $this->getFilters($attr); if ($rfc822) { return 'posts->getRFC822Date('".$type."')").'; ?>'; } elseif ($iso8601) { return 'posts->getISO8601Date('".$type."')").'; ?>'; } else { return 'posts->getDate('".$format."','".$type."')").'; ?>'; } } /*dtd */ public function EntryTime($attr) { $format = ''; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } $type = (!empty($attr['creadt']) ? 'creadt' : ''); $type = (!empty($attr['upddt']) ? 'upddt' : $type); $f = $this->getFilters($attr); return 'posts->getTime('".$format."','".$type."')").'; ?>'; } /*dtd */ public function EntriesHeader($attr,$content) { return "posts->isStart()) : ?>". $content. ""; } /*dtd */ public function EntriesFooter($attr,$content) { return "posts->isEnd()) : ?>". $content. ""; } /*dtd */ public function EntryCommentCount($attr) { if (empty($attr['count_all'])) { $operation = '$_ctx->posts->nb_comment'; } else { $operation = '($_ctx->posts->nb_comment + $_ctx->posts->nb_trackback)'; } return $this->displayCounter( $operation, array( 'none' => 'no comments', 'one' => 'one comment', 'more' => '%d comments' ), $attr, false ); } /*dtd */ public function EntryPingCount($attr) { return $this->displayCounter( '$_ctx->posts->nb_trackback', array( 'none' => 'no trackbacks', 'one' => 'one trackback', 'more' => '%d trackbacks' ), $attr, false ); } /*dtd */ public function EntryPingData($attr) { return "posts->trackbacksActive()) { echo \$_ctx->posts->getTrackbackData(); } ?>\n"; } /*dtd */ public function EntryPingLink($attr) { return "posts->trackbacksActive()) { echo \$_ctx->posts->getTrackbackLink(); } ?>\n"; } /* Languages -------------------------------------- */ /*dtd */ public function Languages($attr,$content) { $p = "if (!isset(\$params)) \$params = array();\n"; if (isset($attr['lang'])) { $p = "\$params['lang'] = '".addslashes($attr['lang'])."';\n"; } $order = 'desc'; if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) { $p .= "\$params['order'] = '".$attr['order']."';\n "; } $res = "core->callBehavior("templatePrepareParams", array("tag" => "Languages","method" => "blog::getLangs"), $attr,$content); $res .= '$_ctx->langs = $core->blog->getLangs($params); unset($params);'."\n"; $res .= "?>\n"; $res .= 'langs->count() > 1) : '. 'while ($_ctx->langs->fetch()) : ?>'.$content. 'langs = null; endif; ?>'; return $res; } /*dtd */ public function LanguagesHeader($attr,$content) { return "langs->isStart()) : ?>". $content. ""; } /*dtd */ public function LanguagesFooter($attr,$content) { return "langs->isEnd()) : ?>". $content. ""; } /*dtd */ public function LanguageCode($attr) { $f = $this->getFilters($attr); return 'langs->post_lang').'; ?>'; } /*dtd */ public function LanguageIfCurrent($attr,$content) { return "cur_lang == \$_ctx->langs->post_lang) : ?>". $content. ""; } /*dtd */ public function LanguageURL($attr) { $f = $this->getFilters($attr); return 'blog->url.$core->url->getURLFor("lang",'. '$_ctx->langs->post_lang)').'; ?>'; } /* Pagination ------------------------------------- */ /*dtd */ public function Pagination($attr,$content) { $p = "post_params;'."\n"; $p .= $this->core->callBehavior("templatePrepareParams", array("tag" => "Pagination","method" => "blog::getPosts"), $attr,$content); $p .= '$_ctx->pagination = $core->blog->getPosts($params,true); unset($params);'."\n"; $p .= "?>\n"; if (isset($attr['no_context']) && $attr['no_context']) { return $p.$content; } return $p. 'pagination->f(0) > $_ctx->posts->count()) : ?>'. $content. ''; } /*dtd */ public function PaginationCounter($attr) { $f = $this->getFilters($attr); return ''; } /*dtd */ public function PaginationCurrent($attr) { $offset = 0; if (isset($attr['offset'])) { $offset = (integer) $attr['offset']; } $f = $this->getFilters($attr); return ''; } /*dtd */ public function PaginationIf($attr,$content) { $if = array(); if (isset($attr['start'])) { $sign = (boolean) $attr['start'] ? '' : '!'; $if[] = $sign.'context::PaginationStart()'; } if (isset($attr['end'])) { $sign = (boolean) $attr['end'] ? '' : '!'; $if[] = $sign.'context::PaginationEnd()'; } $this->core->callBehavior('tplIfConditions','PaginationIf',$attr,$content,$if); if (count($if) != 0) { return ''.$content.''; } else { return $content; } } /*dtd */ public function PaginationURL($attr) { $offset = 0; if (isset($attr['offset'])) { $offset = (integer) $attr['offset']; } $f = $this->getFilters($attr); return ''; } /* Comments --------------------------------------- */ /*dtd */ public function Comments($attr,$content) { $p = ""; if (empty($attr['with_pings'])) { $p .= "\$params['comment_trackback'] = false;\n"; } $lastn = 0; if (isset($attr['lastn'])) { $lastn = abs((integer) $attr['lastn'])+0; } if ($lastn > 0) { $p .= "\$params['limit'] = ".$lastn.";\n"; } else { $p .= "if (\$_ctx->nb_comment_per_page !== null) { \$params['limit'] = \$_ctx->nb_comment_per_page; }\n"; } if (empty($attr['no_context'])) { $p .= "if (\$_ctx->posts !== null) { ". "\$params['post_id'] = \$_ctx->posts->post_id; ". "\$core->blog->withoutPassword(false);\n". "}\n"; $p .= 'if ($_ctx->exists("categories")) { '. "\$params['cat_id'] = \$_ctx->categories->cat_id; ". "}\n"; $p .= 'if ($_ctx->exists("langs")) { '. "\$params['sql'] = \"AND P.post_lang = '\".\$core->blog->con->escape(\$_ctx->langs->post_lang).\"' \"; ". "}\n"; } if (!isset($attr['order'])) { $attr['order'] = 'asc'; } $p .= "\$params['order'] = '".$this->getSortByStr($attr,'comment')."';\n"; if (isset($attr['no_content']) && $attr['no_content']) { $p .= "\$params['no_content'] = true;\n"; } if (isset($attr['age'])) { $age = $this->getAge($attr); $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : ''; } $res = "core->callBehavior("templatePrepareParams", array("tag" => "Comments","method" => "blog::getComments"), $attr,$content); $res .= $p; $res .= '$_ctx->comments = $core->blog->getComments($params); unset($params);'."\n"; $res .= "if (\$_ctx->posts !== null) { \$core->blog->withoutPassword(true);}\n"; if (!empty($attr['with_pings'])) { $res .= '$_ctx->pings = $_ctx->comments;'."\n"; } $res .= "?>\n"; $res .= 'comments->fetch()) : ?>'.$content.'comments = null; ?>'; return $res; } /*dtd */ public function CommentAuthor($attr) { $f = $this->getFilters($attr); return 'comments->comment_author").'; ?>'; } /*dtd */ public function CommentAuthorDomain($attr) { return 'comments->comment_site); ?>'; } /*dtd */ public function CommentAuthorLink($attr) { $f = $this->getFilters($attr); return 'comments->getAuthorLink()').'; ?>'; } /*dtd */ public function CommentAuthorMailMD5($attr) { return 'comments->comment_email) ; ?>'; } /*dtd */ public function CommentAuthorURL($attr) { $f = $this->getFilters($attr); return 'comments->getAuthorURL()').'; ?>'; } /*dtd */ public function CommentContent($attr) { $urls = '0'; if (!empty($attr['absolute_urls'])) { $urls = '1'; } $f = $this->getFilters($attr); return 'comments->getContent('.$urls.')').'; ?>'; } /*dtd */ public function CommentDate($attr) { $format = ''; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } $iso8601 = !empty($attr['iso8601']); $rfc822 = !empty($attr['rfc822']); $type = (!empty($attr['upddt']) ? 'upddt' : ''); $f = $this->getFilters($attr); if ($rfc822) { return 'comments->getRFC822Date('".$type."')").'; ?>'; } elseif ($iso8601) { return 'comments->getISO8601Date('".$type."')").'; ?>'; } else { return 'comments->getDate('".$format."','".$type."')").'; ?>'; } } /*dtd */ public function CommentTime($attr) { $format = ''; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } $type = (!empty($attr['upddt']) ? 'upddt' : ''); $f = $this->getFilters($attr); return 'comments->getTime('".$format."','".$type."')").'; ?>'; } /*dtd */ public function CommentEmail($attr) { $p = 'true'; if (isset($attr['spam_protected']) && !$attr['spam_protected']) { $p = 'false'; } $f = $this->getFilters($attr); return 'comments->getEmail(".$p.")").'; ?>'; } /*dtd */ public function CommentEntryTitle($attr) { $f = $this->getFilters($attr); return 'comments->post_title').'; ?>'; } /*dtd */ public function CommentFeedID($attr) { $f = $this->getFilters($attr); return 'comments->getFeedID()').'; ?>'; } /*dtd */ public function CommentID($attr) { return 'comments->comment_id; ?>'; } /*dtd */ public function CommentIf($attr,$content) { $if = array(); $is_ping = null; if (isset($attr['is_ping'])) { $sign = (boolean) $attr['is_ping'] ? '' : '!'; $if[] = $sign.'$_ctx->comments->comment_trackback'; } $this->core->callBehavior('tplIfConditions','CommentIf',$attr,$content,$if); if (count($if) != 0) { return ''.$content.''; } else { return $content; } } /*dtd */ public function CommentIfFirst($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'first'; $ret = html::escapeHTML($ret); return 'comments->index() == 0) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function CommentIfMe($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'me'; $ret = html::escapeHTML($ret); return 'comments->isMe()) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function CommentIfOdd($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'odd'; $ret = html::escapeHTML($ret); return 'comments->index()+1)%2) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function CommentIP($attr) { return 'comments->comment_ip; ?>'; } /*dtd */ public function CommentOrderNumber($attr) { return 'comments->index()+1; ?>'; } /*dtd */ public function CommentsFooter($attr,$content) { return "comments->isEnd()) : ?>". $content. ""; } /*dtd */ public function CommentsHeader($attr,$content) { return "comments->isStart()) : ?>". $content. ""; } /*dtd */ public function CommentPostURL($attr) { $f = $this->getFilters($attr); return 'comments->getPostURL()').'; ?>'; } /*dtd */ public function IfCommentAuthorEmail($attr,$content) { return "comments->comment_email) : ?>". $content. ""; } /*dtd */ public function CommentHelp($attr,$content) { return "blog->settings->system->wiki_comments) {\n". " echo __('Comments can be formatted using a simple wiki syntax.');\n". "} else {\n". " echo __('HTML code is displayed as text and web addresses are automatically converted.');\n". "} ?>"; } /* Comment preview -------------------------------- */ /*dtd */ public function IfCommentPreviewOptional($attr,$content) { return 'blog->settings->system->comment_preview_optional || ($_ctx->comment_preview !== null && $_ctx->comment_preview["preview"])) : ?>'. $content. ''; } /*dtd */ public function IfCommentPreview($attr,$content) { return 'comment_preview !== null && $_ctx->comment_preview["preview"]) : ?>'. $content. ''; } /*dtd */ public function CommentPreviewName($attr) { $f = $this->getFilters($attr); return 'comment_preview["name"]').'; ?>'; } /*dtd */ public function CommentPreviewEmail($attr) { $f = $this->getFilters($attr); return 'comment_preview["mail"]').'; ?>'; } /*dtd */ public function CommentPreviewSite($attr) { $f = $this->getFilters($attr); return 'comment_preview["site"]').'; ?>'; } /*dtd */ public function CommentPreviewContent($attr) { $f = $this->getFilters($attr); if (!empty($attr['raw'])) { $co = '$_ctx->comment_preview["rawcontent"]'; } else { $co = '$_ctx->comment_preview["content"]'; } return ''; } /*dtd */ public function CommentPreviewCheckRemember($attr) { return "comment_preview['remember']) { echo ' checked=\"checked\"'; } ?>"; } /* Trackbacks ------------------------------------- */ /*dtd */ public function PingBlogName($attr) { $f = $this->getFilters($attr); return 'pings->comment_author').'; ?>'; } /*dtd */ public function PingContent($attr) { $f = $this->getFilters($attr); return 'pings->getTrackbackContent()').'; ?>'; } /*dtd */ public function PingDate($attr,$type='') { $format = ''; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } $iso8601 = !empty($attr['iso8601']); $rfc822 = !empty($attr['rfc822']); $type = (!empty($attr['upddt']) ? 'upddt' : ''); $f = $this->getFilters($attr); if ($rfc822) { return 'pings->getRFC822Date('".$type."')").'; ?>'; } elseif ($iso8601) { return 'pings->getISO8601Date('".$type."')").'; ?>'; } else { return 'pings->getDate('".$format."','".$type."')").'; ?>'; } } /*dtd */ public function PingTime($attr) { $format = ''; if (!empty($attr['format'])) { $format = addslashes($attr['format']); } $type = (!empty($attr['upddt']) ? 'upddt' : ''); $f = $this->getFilters($attr); return 'pings->getTime('".$format."','".$type."')").'; ?>'; } /*dtd */ public function PingEntryTitle($attr) { $f = $this->getFilters($attr); return 'pings->post_title').'; ?>'; } /*dtd */ public function PingFeedID($attr) { $f = $this->getFilters($attr); return 'pings->getFeedID()').'; ?>'; } /*dtd */ public function PingID($attr) { return 'pings->comment_id; ?>'; } /*dtd */ public function PingIfFirst($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'first'; $ret = html::escapeHTML($ret); return 'pings->index() == 0) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function PingIfOdd($attr) { $ret = isset($attr['return']) ? $attr['return'] : 'odd'; $ret = html::escapeHTML($ret); return 'pings->index()+1)%2) { '. "echo '".addslashes($ret)."'; } ?>"; } /*dtd */ public function PingIP($attr) { return 'pings->comment_ip; ?>'; } /*dtd */ public function PingNoFollow($attr) { return 'blog->settings->system->comments_nofollow) { '. 'echo \' rel="nofollow"\';'. '} ?>'; } /*dtd */ public function PingOrderNumber($attr) { return 'pings->index()+1; ?>'; } /*dtd */ public function PingPostURL($attr) { $f = $this->getFilters($attr); return 'pings->getPostURL()').'; ?>'; } /*dtd */ public function Pings($attr,$content) { $p = "if (\$_ctx->posts !== null) { ". "\$params['post_id'] = \$_ctx->posts->post_id; ". "\$core->blog->withoutPassword(false);\n". "}\n"; $p .= "\$params['comment_trackback'] = true;\n"; $lastn = 0; if (isset($attr['lastn'])) { $lastn = abs((integer) $attr['lastn'])+0; } if ($lastn > 0) { $p .= "\$params['limit'] = ".$lastn.";\n"; } else { $p .= "if (\$_ctx->nb_comment_per_page !== null) { \$params['limit'] = \$_ctx->nb_comment_per_page; }\n"; } if (empty($attr['no_context'])) { $p .= 'if ($_ctx->exists("categories")) { '. "\$params['cat_id'] = \$_ctx->categories->cat_id; ". "}\n"; $p .= 'if ($_ctx->exists("langs")) { '. "\$params['sql'] = \"AND P.post_lang = '\".\$core->blog->con->escape(\$_ctx->langs->post_lang).\"' \"; ". "}\n"; } $order = 'asc'; if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) { $order = $attr['order']; } $p .= "\$params['order'] = 'comment_dt ".$order."';\n"; if (isset($attr['no_content']) && $attr['no_content']) { $p .= "\$params['no_content'] = true;\n"; } $res = "core->callBehavior("templatePrepareParams", array("tag" => "Pings","method" => "blog::getComments"), $attr,$content); $res .= '$_ctx->pings = $core->blog->getComments($params); unset($params);'."\n"; $res .= "if (\$_ctx->posts !== null) { \$core->blog->withoutPassword(true);}\n"; $res .= "?>\n"; $res .= 'pings->fetch()) : ?>'.$content.'pings = null; ?>'; return $res; } /*dtd */ public function PingsFooter($attr,$content) { return "pings->isEnd()) : ?>". $content. ""; } /*dtd */ public function PingsHeader($attr,$content) { return "pings->isStart()) : ?>". $content. ""; } /*dtd */ public function PingTitle($attr) { $f = $this->getFilters($attr); return 'pings->getTrackbackTitle()').'; ?>'; } /*dtd */ public function PingAuthorURL($attr) { $f = $this->getFilters($attr); return 'pings->getAuthorURL()').'; ?>'; } # System /*dtd */ public function SysBehavior($attr,$raw) { if (!isset($attr['behavior'])) { return; } $b = addslashes($attr['behavior']); return 'hasBehavior(\''.$b.'\')) { '. '$core->callBehavior(\''.$b.'\',$core,$_ctx);'. '} ?>'; } /*dtd */ public function SysIf($attr,$content) { $if = new ArrayObject(); $is_ping = null; $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; if (isset($attr['categories'])) { $sign = (boolean) $attr['categories'] ? '!' : '='; $if[] = '$_ctx->categories '.$sign.'== null'; } if (isset($attr['posts'])) { $sign = (boolean) $attr['posts'] ? '!' : '='; $if[] = '$_ctx->posts '.$sign.'== null'; } if (isset($attr['blog_lang'])) { $if[] = "\$core->blog->settings->system->lang == '".addslashes($attr['blog_lang'])."'"; } if (isset($attr['current_tpl'])) { $sign = '='; if (substr($attr['current_tpl'],0,1) == '!') { $sign = '!'; $attr['current_tpl'] = substr($attr['current_tpl'],1); } $if[] = "\$_ctx->current_tpl ".$sign."= '".addslashes($attr['current_tpl'])."'"; } if (isset($attr['current_mode'])) { $sign = '='; if (substr($attr['current_mode'],0,1) == '!') { $sign = '!'; $attr['current_mode'] = substr($attr['current_mode'],1); } $if[] = "\$core->url->type ".$sign."= '".addslashes($attr['current_mode'])."'"; } if (isset($attr['has_tpl'])) { $sign = ''; if (substr($attr['has_tpl'],0,1) == '!') { $sign = '!'; $attr['has_tpl'] = substr($attr['has_tpl'],1); } $if[] = $sign."\$core->tpl->getFilePath('".addslashes($attr['has_tpl'])."') !== false"; } if (isset($attr['has_tag'])) { $sign = 'true'; if (substr($attr['has_tag'],0,1) == '!') { $sign = 'false'; $attr['has_tag'] = substr($attr['has_tag'],1); } $if[] = "\$core->tpl->tagExists('".addslashes($attr['has_tag'])."') === ".$sign; } if (isset($attr['blog_id'])) { $sign = ''; if (substr($attr['blog_id'],0,1) == '!') { $sign = '!'; $attr['blog_id'] = substr($attr['blog_id'],1); } $if[] = $sign."(\$core->blog->id == '".addslashes($attr['blog_id'])."')"; } if (isset($attr['comments_active'])) { $sign = (boolean) $attr['comments_active'] ? '' : '!'; $if[] = $sign.'$core->blog->settings->system->allow_comments'; } if (isset($attr['pings_active'])) { $sign = (boolean) $attr['pings_active'] ? '' : '!'; $if[] = $sign.'$core->blog->settings->system->allow_trackbacks'; } if (isset($attr['wiki_comments'])) { $sign = (boolean) $attr['wiki_comments'] ? '' : '!'; $if[] = $sign.'$core->blog->settings->system->wiki_comments'; } if (isset($attr['search_count']) && preg_match('/^((=|!|>|<)=|(>|<))\s*[0-9]+$/',trim($attr['search_count']))) { $if[] = '(isset($_search_count) && $_search_count '.html::decodeEntities($attr['search_count']).')'; } $this->core->callBehavior('tplIfConditions','SysIf',$attr,$content,$if); if (count($if) != 0) { return ''.$content.''; } else { return $content; } } /*dtd */ public function SysIfCommentPublished($attr,$content) { return ''. $content. ''; } /*dtd */ public function SysIfCommentPending($attr,$content) { return ''. $content. ''; } /*dtd */ public function SysFeedSubtitle($attr) { $f = $this->getFilters($attr); return 'feed_subtitle !== null) { echo '.sprintf($f,'$_ctx->feed_subtitle').';} ?>'; } /*dtd */ public function SysIfFormError($attr,$content) { return 'form_error !== null) : ?>'. $content. ''; } /*dtd */ public function SysFormError($attr) { return 'form_error !== null) { echo $_ctx->form_error; } ?>'; } public function SysPoweredBy($attr) { return 'Dotclear"); ?>'; } public function SysSearchString($attr) { $s = isset($attr['string']) ? $attr['string'] : '%1$s'; $f = $this->getFilters($attr); return ''; } public function SysSelfURI($attr) { $f = $this->getFilters($attr); return ''; } /*dtd */ public function GenericElse($attr) { return ''; } } # Template nodes, for parsing purposes # Generic list node, this one may only be instanciated # once for root element class tplNode { # Basic tree structure : links to parent, children forrest protected $parentNode; protected $children; public function __construct() { $this->children = array(); $this->parentNode = null; } // Returns compiled block public function compile($tpl) { $res=''; foreach ($this->children as $child) { $res .= $child->compile($tpl); } return $res; } # Add a children to current node public function addChild ($child) { $this->children[] = $child; $child->setParent($this); } # Defines parent for current node protected function setParent($parent) { $this->parentNode = $parent; } # Retrieves current node parent. # If parent is root node, null is returned public function getParent() { return $this->parentNode; } # Current node tag public function getTag() { return "ROOT"; } } // Text node, for any non-tpl content class tplNodeText extends tplNode { // Simple text node, only holds its content protected $content; public function __construct($text) { parent::__construct(); $this->content=$text; } public function compile($tpl) { return $this->content; } public function getTag() { return "TEXT"; } } // Block node, for all ... class tplNodeBlock extends tplNode { protected $attr; protected $tag; protected $closed; public function __construct($tag,$attr) { parent::__construct(); $this->content=''; $this->tag = $tag; $this->attr = $attr; $this->closed=false; } public function setClosing() { $this->closed = true; } public function isClosed() { return $this->closed; } public function compile($tpl) { if ($this->closed) { $content = parent::compile($tpl); return $tpl->compileBlockNode($this->tag,$this->attr,$content); } else { // if tag has not been closed, silently ignore its content... return ''; } } public function getTag() { return $this->tag; } } // Value node, for all {{tpl:Tag}} class tplNodeValue extends tplNode { protected $attr; protected $str_attr; protected $tag; public function __construct($tag,$attr,$str_attr) { parent::__construct(); $this->content=''; $this->tag = $tag; $this->attr = $attr; $this->str_attr = $str_attr; } public function compile($tpl) { return $tpl->compileValueNode($this->tag,$this->attr,$this->str_attr); } public function getTag() { return $this->tag; } }