- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/lpa.php
- Класс: LPA
- Вызов: LPA::Process
static function Process($filesrc = false, $old_filesrc = false)
{
if ($filesrc === false)
return '';
// Find all php fragments in $filesrc and:
// 1. Kill all non-component 2.0 fragments
// 2. Get and check params of components
$arPHP = PHPParser::ParseFile($filesrc);
$l = count($arPHP);
if ($l > 0)
{
$new_filesrc = '';
$end = 0;
for ($n = 0; $n<$l; $n++)
{
$start = $arPHP[$n][0];
$new_filesrc .= self::EncodePHPTags(mb_substr($filesrc, $end, $start - $end));
$end = $arPHP[$n][1];
//Trim php tags
$src = $arPHP[$n][2];
if (mb_substr($src, 0, 5) == " $v)
{
$k = CMain::_ReplaceNonLatin($k);
$v = CMain::_ReplaceNonLatin($v);
if ($k <> '' && $v <> '')
$arExParams[$k] = $v;
}
$exParams = PHPParser::ReturnPHPStr2($arExParams);
$code .= ','.$br."tarray(".$exParams.')';
}
$code .= $br.');';
$code = ''.$code.'?>';
$new_filesrc .= $code;
}
}
}
$new_filesrc .= self::EncodePHPTags(mb_substr($filesrc, $end));
$filesrc = $new_filesrc;
}
else
{
$filesrc = self::EncodePHPTags($filesrc);
}
if (strpos($filesrc, '#PHP') !== false && $old_filesrc !== false) // We have to handle php fragments
{
// Get array of PHP scripts from old saved file
$arPHP = PHPParser::ParseFile($old_filesrc);
$arPHPscripts = array();
$l = count($arPHP);
if ($l > 0)
{
$new_filesrc = '';
$end = 0;
for ($n = 0; $n < $l; $n++)
{
$start = $arPHP[$n][0];
$new_filesrc .= mb_substr($old_filesrc, $end, $start - $end);
$end = $arPHP[$n][1];
$src = $arPHP[$n][2];
$src = mb_substr($src, (mb_substr($src, 0, 5) == ""."php")? 5 : 2, -2); // Trim php tags
$isComponent2Begin = false;
$arIncludeComponentFunctionStrings = PHPParser::getComponentFunctionStrings();
foreach($arIncludeComponentFunctionStrings as $functionName)
{
$comp2_begin = mb_strtoupper($functionName).'(';
if(mb_strtoupper(mb_substr($src, 0, mb_strlen($comp2_begin))) == $comp2_begin)
{
$isComponent2Begin = true;
break;
}
}
if (!$isComponent2Begin)
$arPHPscripts[] = $src;
}
}
// Ok, so we already have array of php scripts lets check our new content
// LPA-users CAN delete PHP fragments and swap them but CAN'T add new or modify existent:
while (preg_match('/#PHPd{4}#/i'.BX_UTF_PCRE_MODIFIER, $filesrc, $res))
{
$php_begin = mb_strpos($filesrc, $res[0]);
$php_fr_num = intval(mb_substr($filesrc, $php_begin + 4, 4)) - 1; // Number of PHP fragment from #PHPXXXX# conctruction
if (isset($arPHPscripts[$php_fr_num]))
{
$code = ''.$arPHPscripts[$php_fr_num].'?>';
}
else
{
$code = '?>';
}
$filesrc = mb_substr($filesrc, 0, $php_begin).$code.mb_substr($filesrc, $php_begin + 9);
}
}
return $filesrc;
}