function &parseXMLTemplate($xmlTemplate) { $tpl = array("container" => "%items%"); if ($xmlTemplate == "") { trigger_error("Empty template for parsing", PM_FATAL); } $xmlTemplate = set_safe_newlines($xmlTemplate); $tpl["tpl"] = $xmlTemplate; $matches = array(); if (preg_match("/\\<type\\>(.*?)\\<\\/type\\>/", $xmlTemplate, $match_t)) { $tpl["type"] = $match_t[1]; } else { $tpl["type"] = "VerticalTree"; } if (preg_match_all('/<menu\\s+level="(\\d+)"\\s*>(.*?)<\\/menu>/is', $xmlTemplate, $match3)) { for ($i = 0; $i < count($match3[0]); $i++) { if (preg_match("/\\<container\\>(.*?)\\<\\/container\\>/s", $match3[2][$i], $match4)) { $tpl[$match3[1][$i]]["container"] = remove_safe_newlines($match4[1]); } if (preg_match("/\\<separator\\>(.*?)\\<\\/separator\\>/s", $match3[2][$i], $match5)) { $tpl[$match3[1][$i]]["separator"] = remove_safe_newlines($match5[1]); } if (preg_match("/\\<item\\s+active=\"1\"\\s*\\>(.*?)\\<\\/item\\>/s", $match3[2][$i], $match6)) { $tpl[$match3[1][$i]]["activeitem"] = remove_safe_newlines($match6[1]); } if (preg_match("/\\<item\\s+active=\"0\"\\s*\\>(.*?)\\<\\/item\\>/s", $match3[2][$i], $match7)) { $tpl[$match3[1][$i]]["item"] = remove_safe_newlines($match7[1]); } } } else { die('—овпадени¤ не найдены'); } $tpl["tpl"] = remove_safe_newlines($tpl["tpl"]); return $tpl; }
function getValidTags($tpl, $validTags) { $blocks = array(); $tpl = set_safe_newlines($tpl); for ($i = 0; $i < count($validTags); $i++) { if (preg_match('/<' . $validTags[$i] . '>(.*?)<\\/' . $validTags[$i] . '>/s', $tpl, $match)) { $blocks[$validTags[$i]] = $match[1]; $blocks[$validTags[$i]] = remove_safe_newlines($blocks[$validTags[$i]]); } } return $blocks; }
function getNewsList($pageID, $tplFilename, $count) { global $structureMgr, $templatesMgr; $res = ""; $branch = $structureMgr->getStructureForPageID($pageID, 1); if (count($branch) == 0) { $clubHandler = new ClubHandler(); return $clubHandler->getContent(); } $tpl = $templatesMgr->getTemplate(-1, GetCfg("TemplatesPath") . "/News/" . $tplFilename); $tpl = set_safe_newlines($tpl); $blocks = $templatesMgr->getValidTags(&$tpl, array("container", "item", "separator")); $from = count($branch); if ($count == -1 || $count > $from) { $to = 0; } else { $to = $from - $count; } for ($i = $from - 1; $i >= $to; $i--) { $news = $branch[$i]; $URL = $structureMgr->getPathByPageID($news["sID"], true); $bl = $blocks["item"]; $bl = str_replace("%short_title%", $news["ShortTitle"], $bl); $bl = str_replace("%date%", $news["CreateDate"], $bl); $bl = str_replace("%news_link%", $URL, $bl); $bl = str_replace("%summary%", $structureMgr->getData($news["sID"]), $bl); if ($res && isset($blocks["separator"])) { $res .= $blocks["separator"]; } $res .= $bl; } $blocks["container"] = str_replace("%items%", $res, $blocks["container"]); return $blocks["container"]; }