Example #1
0
 function _RenderOneComponent($arParams, $bLPA)
 {
     global $APPLICATION, $USER;
     $arProperties = CEditorUtils::GetCompProperties($arParams['name'], $arParams['template'], $arParams['siteTemplateId']);
     $code = '$APPLICATION->IncludeComponent("' . $arParams['name'] . '","' . $arParams['template'] . '",';
     $arProperties['BX_EDITOR_RENDER_MODE'] = array('NAME' => 'Workin in render mode *For Visual editor rendering only*', 'TYPE' => 'CHECKBOX', 'DEFAULT' => 'Y');
     // Add description of the system parameter
     $arProps = $arParams['params'];
     if (!$arProps) {
         $arProps = array();
         foreach ($arProperties as $key => $Prop) {
             $arProps[$key] = $Prop['DEFAULT'];
         }
     } else {
         if ($bLPA) {
             $arPHPparams = array();
             CMain::LPAComponentChecker($arProps, $arPHPparams);
             $len = count($arPHPparams);
             // Replace values from 'DEFAULT' field
             for ($e = 0; $e < $len; $e++) {
                 $par_name = $arPHPparams[$e];
                 $arProps[$par_name] = isset($arProperties[$par_name]['DEFAULT']) ? $arProperties[$par_name]['DEFAULT'] : '';
             }
         }
     }
     foreach ($arProps as $key => $val) {
         $val = trim($val);
         if ($key != addslashes($key)) {
             unset($arProps[$key]);
             continue;
         }
         if (strtolower($val) == 'array()') {
             $arProps[$key] = array();
         } elseif (substr(strtolower($val), 0, 6) == 'array(') {
             $str = array();
             $tArr = array();
             PHPParser::GetParamsRec($val, $str, $tArr);
             if (is_array($tArr)) {
                 foreach ($tArr as $k => $v) {
                     if (substr($v, 0, 2) == "={" && substr($v, -1, 1) == "}" && strlen($v) > 3) {
                         $v = substr($v, 2, -1);
                     }
                     unset($tArr[$k]);
                     $tArr[addslashes($k)] = addslashes(trim($v, " \"'"));
                 }
             }
             $arProps[$key] = $tArr;
         } else {
             $arProps[$key] = addslashes($val);
         }
     }
     $arProps['BX_EDITOR_RENDER_MODE'] = 'Y';
     //Set system parameter
     $params = PHPParser::ReturnPHPStr2($arProps, $arParameters);
     $code .= 'Array(' . $params . ')';
     $code .= ');';
     ob_start();
     echo '#BX_RENDERED_COMPONENT#';
     eval($code);
     echo '#BX_RENDERED_COMPONENT#';
     $s = ob_get_contents();
     ob_end_clean();
     return $s;
 }
Example #2
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;
 }