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', [$this, 'EntryPingCount']); $this->addValue('EntryTrackbackData', [$this, 'EntryPingData']); $this->addValue('EntryTrackbackLink', [$this, 'EntryPingLink']); # l10n $this->addValue('lang', [$this, 'l10n']); # Loops test tags $this->addBlock('LoopPosition', [$this, 'LoopPosition']); $this->addValue('LoopIndex', [$this, 'LoopIndex']); # Archives $this->addBlock('Archives', [$this, 'Archives']); $this->addBlock('ArchivesHeader', [$this, 'ArchivesHeader']); $this->addBlock('ArchivesFooter', [$this, 'ArchivesFooter']); $this->addBlock('ArchivesYearHeader', [$this, 'ArchivesYearHeader']); $this->addBlock('ArchivesYearFooter', [$this, 'ArchivesYearFooter']); $this->addValue('ArchiveDate', [$this, 'ArchiveDate']); $this->addBlock('ArchiveNext', [$this, 'ArchiveNext']); $this->addBlock('ArchivePrevious', [$this, 'ArchivePrevious']); $this->addValue('ArchiveEntriesCount', [$this, 'ArchiveEntriesCount']); $this->addValue('ArchiveURL', [$this, 'ArchiveURL']); # Blog $this->addValue('BlogArchiveURL', [$this, 'BlogArchiveURL']); $this->addValue('BlogCopyrightNotice', [$this, 'BlogCopyrightNotice']); $this->addValue('BlogDescription', [$this, 'BlogDescription']); $this->addValue('BlogEditor', [$this, 'BlogEditor']); $this->addValue('BlogFeedID', [$this, 'BlogFeedID']); $this->addValue('BlogFeedURL', [$this, 'BlogFeedURL']); $this->addValue('BlogRSDURL', [$this, 'BlogRSDURL']); $this->addValue('BlogName', [$this, 'BlogName']); $this->addValue('BlogLanguage', [$this, 'BlogLanguage']); $this->addValue('BlogThemeURL', [$this, 'BlogThemeURL']); $this->addValue('BlogParentThemeURL', [$this, 'BlogParentThemeURL']); $this->addValue('BlogUpdateDate', [$this, 'BlogUpdateDate']); $this->addValue('BlogID', [$this, 'BlogID']); $this->addValue('BlogURL', [$this, 'BlogURL']); $this->addValue('BlogXMLRPCURL', [$this, 'BlogXMLRPCURL']); $this->addValue('BlogPublicURL', [$this, 'BlogPublicURL']); $this->addValue('BlogQmarkURL', [$this, 'BlogQmarkURL']); $this->addValue('BlogMetaRobots', [$this, 'BlogMetaRobots']); $this->addValue('BlogJsJQuery', [$this, 'BlogJsJQuery']); # Categories $this->addBlock('Categories', [$this, 'Categories']); $this->addBlock('CategoriesHeader', [$this, 'CategoriesHeader']); $this->addBlock('CategoriesFooter', [$this, 'CategoriesFooter']); $this->addBlock('CategoryIf', [$this, 'CategoryIf']); $this->addBlock('CategoryFirstChildren', [$this, 'CategoryFirstChildren']); $this->addBlock('CategoryParents', [$this, 'CategoryParents']); $this->addValue('CategoryFeedURL', [$this, 'CategoryFeedURL']); $this->addValue('CategoryURL', [$this, 'CategoryURL']); $this->addValue('CategoryShortURL', [$this, 'CategoryShortURL']); $this->addValue('CategoryDescription', [$this, 'CategoryDescription']); $this->addValue('CategoryTitle', [$this, 'CategoryTitle']); $this->addValue('CategoryEntriesCount', [$this, 'CategoryEntriesCount']); # Comments $this->addBlock('Comments', [$this, 'Comments']); $this->addValue('CommentAuthor', [$this, 'CommentAuthor']); $this->addValue('CommentAuthorDomain', [$this, 'CommentAuthorDomain']); $this->addValue('CommentAuthorLink', [$this, 'CommentAuthorLink']); $this->addValue('CommentAuthorMailMD5', [$this, 'CommentAuthorMailMD5']); $this->addValue('CommentAuthorURL', [$this, 'CommentAuthorURL']); $this->addValue('CommentContent', [$this, 'CommentContent']); $this->addValue('CommentDate', [$this, 'CommentDate']); $this->addValue('CommentTime', [$this, 'CommentTime']); $this->addValue('CommentEmail', [$this, 'CommentEmail']); $this->addValue('CommentEntryTitle', [$this, 'CommentEntryTitle']); $this->addValue('CommentFeedID', [$this, 'CommentFeedID']); $this->addValue('CommentID', [$this, 'CommentID']); $this->addBlock('CommentIf', [$this, 'CommentIf']); $this->addValue('CommentIfFirst', [$this, 'CommentIfFirst']); $this->addValue('CommentIfMe', [$this, 'CommentIfMe']); $this->addValue('CommentIfOdd', [$this, 'CommentIfOdd']); $this->addValue('CommentIP', [$this, 'CommentIP']); $this->addValue('CommentOrderNumber', [$this, 'CommentOrderNumber']); $this->addBlock('CommentsFooter', [$this, 'CommentsFooter']); $this->addBlock('CommentsHeader', [$this, 'CommentsHeader']); $this->addValue('CommentPostURL', [$this, 'CommentPostURL']); $this->addBlock('IfCommentAuthorEmail', [$this, 'IfCommentAuthorEmail']); $this->addValue('CommentHelp', [$this, 'CommentHelp']); # Comment preview $this->addBlock('IfCommentPreview', [$this, 'IfCommentPreview']); $this->addBlock('IfCommentPreviewOptional', [$this, 'IfCommentPreviewOptional']); $this->addValue('CommentPreviewName', [$this, 'CommentPreviewName']); $this->addValue('CommentPreviewEmail', [$this, 'CommentPreviewEmail']); $this->addValue('CommentPreviewSite', [$this, 'CommentPreviewSite']); $this->addValue('CommentPreviewContent', [$this, 'CommentPreviewContent']); $this->addValue('CommentPreviewCheckRemember', [$this, 'CommentPreviewCheckRemember']); # Entries $this->addBlock('DateFooter', [$this, 'DateFooter']); $this->addBlock('DateHeader', [$this, 'DateHeader']); $this->addBlock('Entries', [$this, 'Entries']); $this->addBlock('EntriesFooter', [$this, 'EntriesFooter']); $this->addBlock('EntriesHeader', [$this, 'EntriesHeader']); $this->addValue('EntryAuthorCommonName', [$this, 'EntryAuthorCommonName']); $this->addValue('EntryAuthorDisplayName', [$this, 'EntryAuthorDisplayName']); $this->addValue('EntryAuthorEmail', [$this, 'EntryAuthorEmail']); $this->addValue('EntryAuthorEmailMD5', [$this, 'EntryAuthorEmailMD5']); $this->addValue('EntryAuthorID', [$this, 'EntryAuthorID']); $this->addValue('EntryAuthorLink', [$this, 'EntryAuthorLink']); $this->addValue('EntryAuthorURL', [$this, 'EntryAuthorURL']); $this->addValue('EntryBasename', [$this, 'EntryBasename']); $this->addValue('EntryCategory', [$this, 'EntryCategory']); $this->addValue('EntryCategoryDescription', [$this, 'EntryCategoryDescription']); $this->addBlock('EntryCategoriesBreadcrumb', [$this, 'EntryCategoriesBreadcrumb']); $this->addValue('EntryCategoryID', [$this, 'EntryCategoryID']); $this->addValue('EntryCategoryURL', [$this, 'EntryCategoryURL']); $this->addValue('EntryCategoryShortURL', [$this, 'EntryCategoryShortURL']); $this->addValue('EntryCommentCount', [$this, 'EntryCommentCount']); $this->addValue('EntryContent', [$this, 'EntryContent']); $this->addValue('EntryDate', [$this, 'EntryDate']); $this->addValue('EntryExcerpt', [$this, 'EntryExcerpt']); $this->addValue('EntryFeedID', [$this, 'EntryFeedID']); $this->addValue('EntryFirstImage', [$this, 'EntryFirstImage']); $this->addValue('EntryID', [$this, 'EntryID']); $this->addBlock('EntryIf', [$this, 'EntryIf']); $this->addBlock('EntryIfContentCut', [$this, 'EntryIfContentCut']); $this->addValue('EntryIfFirst', [$this, 'EntryIfFirst']); $this->addValue('EntryIfOdd', [$this, 'EntryIfOdd']); $this->addValue('EntryIfSelected', [$this, 'EntryIfSelected']); $this->addValue('EntryLang', [$this, 'EntryLang']); $this->addBlock('EntryNext', [$this, 'EntryNext']); $this->addValue('EntryPingCount', [$this, 'EntryPingCount']); $this->addValue('EntryPingData', [$this, 'EntryPingData']); $this->addValue('EntryPingLink', [$this, 'EntryPingLink']); $this->addBlock('EntryPrevious', [$this, 'EntryPrevious']); $this->addValue('EntryTitle', [$this, 'EntryTitle']); $this->addValue('EntryTime', [$this, 'EntryTime']); $this->addValue('EntryURL', [$this, 'EntryURL']); # Languages $this->addBlock('Languages', [$this, 'Languages']); $this->addBlock('LanguagesHeader', [$this, 'LanguagesHeader']); $this->addBlock('LanguagesFooter', [$this, 'LanguagesFooter']); $this->addValue('LanguageCode', [$this, 'LanguageCode']); $this->addBlock('LanguageIfCurrent', [$this, 'LanguageIfCurrent']); $this->addValue('LanguageURL', [$this, 'LanguageURL']); # Pagination $this->addBlock('Pagination', [$this, 'Pagination']); $this->addValue('PaginationCounter', [$this, 'PaginationCounter']); $this->addValue('PaginationCurrent', [$this, 'PaginationCurrent']); $this->addBlock('PaginationIf', [$this, 'PaginationIf']); $this->addValue('PaginationURL', [$this, 'PaginationURL']); # Trackbacks $this->addValue('PingBlogName', [$this, 'PingBlogName']); $this->addValue('PingContent', [$this, 'PingContent']); $this->addValue('PingDate', [$this, 'PingDate']); $this->addValue('PingEntryTitle', [$this, 'PingEntryTitle']); $this->addValue('PingFeedID', [$this, 'PingFeedID']); $this->addValue('PingID', [$this, 'PingID']); $this->addValue('PingIfFirst', [$this, 'PingIfFirst']); $this->addValue('PingIfOdd', [$this, 'PingIfOdd']); $this->addValue('PingIP', [$this, 'PingIP']); $this->addValue('PingNoFollow', [$this, 'PingNoFollow']); $this->addValue('PingOrderNumber', [$this, 'PingOrderNumber']); $this->addValue('PingPostURL', [$this, 'PingPostURL']); $this->addBlock('Pings', [$this, 'Pings']); $this->addBlock('PingsFooter', [$this, 'PingsFooter']); $this->addBlock('PingsHeader', [$this, 'PingsHeader']); $this->addValue('PingTime', [$this, 'PingTime']); $this->addValue('PingTitle', [$this, 'PingTitle']); $this->addValue('PingAuthorURL', [$this, 'PingAuthorURL']); # System $this->addValue('SysBehavior', [$this, 'SysBehavior']); $this->addBlock('SysIf', [$this, 'SysIf']); $this->addBlock('SysIfCommentPublished', [$this, 'SysIfCommentPublished']); $this->addBlock('SysIfCommentPending', [$this, 'SysIfCommentPending']); $this->addBlock('SysIfFormError', [$this, 'SysIfFormError']); $this->addValue('SysFeedSubtitle', [$this, 'SysFeedSubtitle']); $this->addValue('SysFormError', [$this, 'SysFormError']); $this->addValue('SysPoweredBy', [$this, 'SysPoweredBy']); $this->addValue('SysSearchString', [$this, 'SysSearchString']); $this->addValue('SysSelfURI', [$this, 'SysSelfURI']); # Generic $this->addValue('else', [$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, [ & $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, $default = []) { if (!is_array($attr) && !($attr instanceof arrayObject)) { $attr = []; } $p = array_merge( [ 0 => null, 'encode_xml' => 0, 'encode_html' => 0, 'cut_string' => 0, 'lower_case' => 0, 'upper_case' => 0, 'encode_url' => 0, 'remove_html' => 0, 'capitalize' => 0, 'strip_tags' => 0 ], $default ); foreach ($attr as $k => $v) { // attributes names must follow this rule $k = preg_filter('/[a-zA-Z0-9_]/', '$0', $k); if ($k) { // addslashes protect var_export, str_replace protect sprintf; $p[$k] = str_replace('%', '%%', addslashes($v)); } } return "context::global_filters(%s," . var_export($p, true) . ",'" . 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 = []; $default_order = 'desc'; $default_alias = [ 'post' => [ 'title' => 'post_title', 'selected' => 'post_selected', 'author' => 'user_id', 'date' => 'post_dt', 'id' => 'post_id', 'comment' => 'nb_comment', 'trackback' => 'nb_trackback' ], 'comment' => [ '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] = []; } if (!isset($default_alias[$k]) || !is_array($default_alias[$k])) { $default_alias[$k] = []; } $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 = [];\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", ["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'), [ 'none' => 'no archive', 'one' => 'one archive', 'more' => '%d archives' ], $attr, true ); } /*dtd */ public function ArchiveNext($attr, $content) { $p = "if (!isset(\$params)) \$params = [];\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", ["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 = [];'; $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", ["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 = [];\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", ["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'])); $args = preg_split('/\s*[?]\s*/', $url, -1, PREG_SPLIT_NO_EMPTY); $url = array_shift($args); $args = array_flip($args); if (substr($url, 0, 1) == '!') { $url = substr($url, 1); if (isset($args['sub'])) { $if[] = '(!$core->blog->IsInCatSubtree($_ctx->categories->cat_url, "' . $url . '"))'; } else { $if[] = '($_ctx->categories->cat_url != "' . $url . '")'; } } else { if (isset($args['sub'])) { $if[] = '($core->blog->IsInCatSubtree($_ctx->categories->cat_url, "' . $url . '"))'; } else { $if[] = '($_ctx->categories->cat_url == "' . $url . '")'; } } } if (isset($attr['urls'])) { $urls = explode(',', addslashes(trim($attr['urls']))); if (is_array($urls) && count($urls)) { foreach ($urls as $url) { $args = preg_split('/\s*[?]\s*/', trim($url), -1, PREG_SPLIT_NO_EMPTY); $url = array_shift($args); $args = array_flip($args); if (substr($url, 0, 1) == '!') { $url = substr($url, 1); if (isset($args['sub'])) { $if[] = '(!$core->blog->IsInCatSubtree($_ctx->categories->cat_url, "' . $url . '"))'; } else { $if[] = '($_ctx->categories->cat_url != "' . $url . '")'; } } else { if (isset($args['sub'])) { $if[] = '($core->blog->IsInCatSubtree($_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'), [ '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'] = [(\$_page_number == 1 ? 0 : (\$_page_number - 2) * \$nb_entry_per_page + \$nb_entry_first_page),\$params['limit']];\n"; $p .= "} else {\n"; $p .= " \$params['limit'] = [(\$_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'] = [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['with_category']) && $attr['with_category']) { $p .= "@\$params['sql'] .= ' AND P.cat_id IS NOT NULL ';\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", ["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'])); $args = preg_split('/\s*[?]\s*/', $category, -1, PREG_SPLIT_NO_EMPTY); $category = array_shift($args); $args = array_flip($args); if (substr($category, 0, 1) == '!') { $category = substr($category, 1); if (isset($args['sub'])) { $if[] = '(!$_ctx->posts->underCat("' . $category . '"))'; } else { $if[] = '($_ctx->posts->cat_url != "' . $category . '")'; } } else { if (isset($args['sub'])) { $if[] = '($_ctx->posts->underCat("' . $category . '"))'; } else { $if[] = '($_ctx->posts->cat_url == "' . $category . '")'; } } } if (isset($attr['categories'])) { $categories = explode(',', addslashes(trim($attr['categories']))); if (is_array($categories) && count($categories)) { foreach ($categories as $category) { $args = preg_split('/\s*[?]\s*/', trim($category), -1, PREG_SPLIT_NO_EMPTY); $category = array_shift($args); $args = array_flip($args); if (substr($category, 0, 1) == '!') { $category = substr($category, 1); if (isset($args['sub'])) { $if[] = '(!$_ctx->posts->underCat("' . $category . '"))'; } else { $if[] = '($_ctx->posts->cat_url != "' . $category . '")'; } } else { if (isset($args['sub'])) { $if[] = '($_ctx->posts->underCat("' . $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 EntryIfContentCut($attr, $content) { if (empty($attr['cut_string']) || !empty($attr['full'])) { return ''; } $urls = '0'; if (!empty($attr['absolute_urls'])) { $urls = '1'; } $short = $this->getFilters($attr); $cut = $attr['cut_string']; $attr['cut_string'] = 0; $full = $this->getFilters($attr); $attr['cut_string'] = $cut; return 'posts->getContent(' . $urls . ')') . ') > ' . 'strlen(' . sprintf($short, '$_ctx->posts->getContent(' . $urls . ')') . ')) : ?>' . $content . ''; } /*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 EntryAuthorEmailMD5($attr) { $f = $this->getFilters($attr); return 'posts->getAuthorEmail(false))') . '; ?>'; } /*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 EntryCategoryDescription($attr) { $f = $this->getFilters($attr); return 'posts->cat_desc') . '; ?>'; } /*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, [ 'none' => 'no comments', 'one' => 'one comment', 'more' => '%d comments' ], $attr, false ); } /*dtd */ public function EntryPingCount($attr) { return $this->displayCounter( '$_ctx->posts->nb_trackback', [ 'none' => 'no trackbacks', 'one' => 'one trackback', 'more' => '%d trackbacks' ], $attr, false ); } /*dtd */ public function EntryPingData($attr) { $format = !empty($attr['format']) && $attr['format'] == 'xml' ? 'xml' : 'html'; return "posts->trackbacksActive()) { echo \$_ctx->posts->getTrackbackData('" . $format . "'); } ?>\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 = [];\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", ["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", ["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 = []; 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", ["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 = []; $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", ["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'])) { $sign = '='; if (substr($attr['blog_lang'], 0, 1) == '!') { $sign = '!'; $attr['blog_lang'] = substr($attr['blog_lang'], 1); } $if[] = "\$core->blog->settings->system->lang " . $sign . "= '" . 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 ''; } }