Пример #1
0
 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;
 }
Пример #2
0
 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;
 }