Example #1
0
 public static function CheckForComponent2($str)
 {
     if (substr($str, 0, 5) == "<?" . "php") {
         $str = substr($str, 5);
     } else {
         $str = substr($str, 2);
     }
     $str = substr($str, 0, -2);
     $bSlashed = false;
     $bInString = false;
     $arAllStr = array();
     $new_str = "";
     $string_tmp = "";
     $quote_ch = "";
     $i = -1;
     $length = strlen($str);
     while ($i < $length - 1) {
         $i++;
         $ch = substr($str, $i, 1);
         if (!$bInString) {
             if ($string_tmp != "") {
                 $arAllStr[] = $string_tmp;
                 $string_tmp = "";
                 $new_str .= chr(1) . (count($arAllStr) - 1) . chr(2);
             }
             //comment
             if ($ch == "/" && $i + 1 < $length) {
                 $ti = 0;
                 if (substr($str, $i + 1, 1) == "*" && ($ti = strpos($str, "*/", $i + 2)) !== false) {
                     $ti += 1;
                 } elseif (substr($str, $i + 1, 1) == "/" && ($ti = strpos($str, "\n", $i + 2)) !== false) {
                     $ti += 0;
                 }
                 if ($ti) {
                     $i = $ti;
                 }
                 continue;
             }
             if ($ch == " " || $ch == "\r" || $ch == "\n" || $ch == "\t") {
                 continue;
             }
         }
         if ($bInString && $ch == "\\" && !$bSlashed) {
             $bSlashed = true;
             continue;
         }
         if ($ch == "\"" || $ch == "'") {
             if ($bInString) {
                 if (!$bSlashed && $quote_ch == $ch) {
                     $bInString = false;
                     continue;
                 }
             } else {
                 $bInString = true;
                 $quote_ch = $ch;
                 continue;
             }
         }
         $bSlashed = false;
         if ($bInString) {
             $string_tmp .= $ch;
             continue;
         }
         $new_str .= $ch;
     }
     if ($pos = strpos($new_str, "(")) {
         $func_name = substr($new_str, 0, $pos + 1);
         if (preg_match("/^(\\\$[A-Z_][A-Z0-9_]*)(\\s*=\\s*)/i", $func_name, $arMatch)) {
             $var_name = $arMatch[1];
             $func_name = substr($func_name, strlen($arMatch[0]));
         } else {
             $var_name = "";
         }
         self::$arAllStr = $arAllStr;
         $func_name = preg_replace_callback("'([0-9]+)'s", "PHPParser::getString", $func_name);
         switch (strtoupper($func_name)) {
             case '$APPLICATION->INCLUDECOMPONENT(':
                 $params = substr($new_str, $pos + 1);
                 $arParams = PHPParser::GetParams($params);
                 $arIncludeParams = array();
                 $arFuncParams = array();
                 PHPParser::GetParamsRec($arParams[2], $arAllStr, $arIncludeParams);
                 PHPParser::GetParamsRec($arParams[4], $arAllStr, $arFuncParams);
                 return array("COMPONENT_NAME" => PHPParser::ReplString($arParams[0], $arAllStr), "TEMPLATE_NAME" => PHPParser::ReplString($arParams[1], $arAllStr), "PARAMS" => $arIncludeParams, "PARENT_COMP" => $arParams[3], "VARIABLE" => $var_name, "FUNCTION_PARAMS" => $arFuncParams);
         }
     }
     return false;
 }