1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
lpa.php
См. документацию.
1<?php
2
8class LPA
9{
10 public static function PrepareContent($filesrc)
11 {
13 $l = count($arPHP);
14 if ($l > 0)
15 {
16 $new_filesrc = '';
17 $end = 0;
18 $php_count = 0;
19 for ($n = 0; $n<$l; $n++)
20 {
21 $start = $arPHP[$n][0];
22 $new_filesrc .= mb_substr($filesrc, $end, $start - $end);
23 $end = $arPHP[$n][1];
24
25 //Trim php tags
26 $src = $arPHP[$n][2];
27 if (str_starts_with($src, "<?php"))
28 $src = substr($src, 5);
29 else
30 $src = substr($src, 2);
31 $src = substr($src, 0, -2);
32
33 //If it's Component 2, keep the php code. If it's component 1 or ordinary PHP - than replace code by #PHPXXXX# (XXXX - count of PHP scripts)
34 $isComponent2Begin = false;
35 $arIncludeComponentFunctionStrings = PHPParser::getComponentFunctionStrings();
36 foreach($arIncludeComponentFunctionStrings as $functionName)
37 {
38 $comp2_begin = mb_strtoupper($functionName).'(';
39 if(mb_strtoupper(mb_substr($src, 0, mb_strlen($comp2_begin))) == $comp2_begin)
40 {
41 $isComponent2Begin = true;
42 break;
43 }
44 }
45 if ($isComponent2Begin)
46 $new_filesrc .= $arPHP[$n][2];
47 else
48 $new_filesrc .= '#PHP'.str_pad(++$php_count, 4, "0", STR_PAD_LEFT).'#';
49 }
50 $new_filesrc .= mb_substr($filesrc, $end);
51 $filesrc = $new_filesrc;
52 }
53
54 return $filesrc;
55 }
56
57 public static function Process($filesrc = false, $old_filesrc = false)
58 {
59 if ($filesrc === false)
60 return '';
61
62 // Find all php fragments in $filesrc and:
63 // 1. Kill all non-component 2.0 fragments
64 // 2. Get and check params of components
66 $l = count($arPHP);
67 if ($l > 0)
68 {
69 $new_filesrc = '';
70 $end = 0;
71 for ($n = 0; $n<$l; $n++)
72 {
73 $start = $arPHP[$n][0];
74 $new_filesrc .= self::EncodePHPTags(mb_substr($filesrc, $end, $start - $end));
75 $end = $arPHP[$n][1];
76
77 //Trim php tags
78 $src = $arPHP[$n][2];
79 if (str_starts_with($src, "<?php"))
80 $src = '<?'.substr($src, 5);
81
82 //If it's Component 2 - we handle it's params, non components2 will be somehow erased
83 $isComponent2Begin = false;
84 $component2FunctionName = '';
85 $arIncludeComponentFunctionStrings = PHPParser::getComponentFunctionStrings();
86 foreach($arIncludeComponentFunctionStrings as $functionName)
87 {
88 $comp2_begin = '<?'.mb_strtoupper($functionName).'(';
89 if(mb_strtoupper(mb_substr($src, 0, mb_strlen($comp2_begin))) == $comp2_begin)
90 {
91 $isComponent2Begin = true;
92 $component2FunctionName = $functionName;
93 break;
94 }
95 }
96
97 if ($isComponent2Begin)
98 {
100 if ($arRes)
101 {
102 $comp_name = $arRes['COMPONENT_NAME'];
103 $template_name = $arRes['TEMPLATE_NAME'];
104 $arParams = $arRes['PARAMS'];
105 $arPHPparams = array();
106 self::ComponentChecker($arParams, $arPHPparams);
107 $len = count($arPHPparams);
108 $br = "\r\n";
109 $code = $component2FunctionName.'('.$br.
110 "\t".'"'.EscapePHPString($comp_name).'",'.$br.
111 "\t".'"'.EscapePHPString($template_name).'",'.$br;
112 // If exist at least one parameter with php code inside
113 if (!empty($arParams))
114 {
115 // Get array with description of component params
116 $arCompParams = CComponentUtil::GetComponentProps($comp_name);
117 $arTemplParams = CComponentUtil::GetTemplateProps($comp_name, $template_name);
118
119 $arParameters = array();
120 if (isset($arCompParams["PARAMETERS"]) && is_array($arCompParams["PARAMETERS"]))
121 $arParameters = $arParameters + $arCompParams["PARAMETERS"];
122 if (is_array($arTemplParams))
123 $arParameters = $arParameters + $arTemplParams;
124
125 // Replace values from 'DEFAULT'
126 for ($e = 0; $e < $len; $e++)
127 {
128 $par_name = $arPHPparams[$e];
129 $arParams[$par_name] = $arParameters[$par_name]['DEFAULT'] ?? '';
130 }
131
132 //ReturnPHPStr
133 $params = PHPParser::ReturnPHPStr2($arParams, $arParameters);
134 $code .= "\t".'array('.$br."\t".$params.$br."\t".')';
135 }
136 else
137 {
138 $code .= "\t".'array()';
139 }
140 $parent_comp = $arRes['PARENT_COMP'];
141 $arExParams_ = $arRes['FUNCTION_PARAMS'];
142
143 $bEx = isset($arExParams_) && is_array($arExParams_) && !empty($arExParams_);
144
145 if (!$parent_comp || mb_strtolower($parent_comp) == 'false')
146 $parent_comp = false;
147 if ($parent_comp)
148 {
149 if ($parent_comp == 'true' || is_numeric($parent_comp))
150 $code .= ','.$br."\t".$parent_comp;
151 else
152 $code .= ','.$br."\t\"".EscapePHPString($parent_comp).'"';
153 }
154 if ($bEx)
155 {
156 if (!$parent_comp)
157 $code .= ','.$br."\tfalse";
158
159 $arExParams = array();
160 foreach ($arExParams_ as $k => $v)
161 {
164 if ($k <> '' && $v <> '')
165 $arExParams[$k] = $v;
166 }
167 $exParams = PHPParser::ReturnPHPStr2($arExParams);
168 $code .= ','.$br."\tarray(".$exParams.')';
169 }
170 $code .= $br.');';
171 $code = '<?'.$code.'?>';
172 $new_filesrc .= $code;
173 }
174 }
175 }
176 $new_filesrc .= self::EncodePHPTags(mb_substr($filesrc, $end));
177 $filesrc = $new_filesrc;
178 }
179 else
180 {
181 $filesrc = self::EncodePHPTags($filesrc);
182 }
183
184 if (str_contains($filesrc, '#PHP') && $old_filesrc !== false) // We have to handle php fragments
185 {
186 // Get array of PHP scripts from old saved file
187 $arPHP = PHPParser::ParseFile($old_filesrc);
188 $arPHPscripts = array();
189 $l = count($arPHP);
190 if ($l > 0)
191 {
192 for ($n = 0; $n < $l; $n++)
193 {
194 $src = $arPHP[$n][2];
195 $src = substr($src, (str_starts_with($src, "<?php"))? 5 : 2, -2); // Trim php tags
196
197 $isComponent2Begin = false;
198 $arIncludeComponentFunctionStrings = PHPParser::getComponentFunctionStrings();
199 foreach($arIncludeComponentFunctionStrings as $functionName)
200 {
201 $comp2_begin = mb_strtoupper($functionName).'(';
202 if(mb_strtoupper(mb_substr($src, 0, mb_strlen($comp2_begin))) == $comp2_begin)
203 {
204 $isComponent2Begin = true;
205 break;
206 }
207 }
208 if (!$isComponent2Begin)
209 $arPHPscripts[] = $src;
210 }
211 }
212
213 // Ok, so we already have array of php scripts lets check our new content
214 // LPA-users CAN delete PHP fragments and swap them but CAN'T add new or modify existent:
215 while (preg_match('/#PHP\d{4}#/iu', $filesrc, $res))
216 {
217 $php_begin = mb_strpos($filesrc, $res[0]);
218 $php_fr_num = intval(mb_substr($filesrc, $php_begin + 4, 4)) - 1; // Number of PHP fragment from #PHPXXXX# conctruction
219
220 if (isset($arPHPscripts[$php_fr_num]))
221 {
222 $code = '<?'.$arPHPscripts[$php_fr_num].'?>';
223 }
224 else
225 {
226 $code = '<??>';
227 }
228 $filesrc = mb_substr($filesrc, 0, $php_begin).$code.mb_substr($filesrc, $php_begin + 9);
229 }
230 }
231
232 return $filesrc;
233 }
234
235 public static function EncodePHPTags($str)
236 {
237 $str = str_replace(array("<?","?>", "<%", "%>"),array("&lt;?","?&gt;","&lt;%","%&gt;"), $str);
238
239 static $pattern = "/(<script[^>]*language\\s*=\\s*)('|\"|)php('|\"|)([^>]*>)/i";
240 $str = preg_replace($pattern, "&lt;??&gt;", $str);
241
242 return $str;
243 }
244
245 public static function ComponentChecker(&$arParams, &$arPHPparams, $parentParamName = false)
246 {
247 //all php fragments wraped by ={}
248 foreach ($arParams as $param_name => $paramval)
249 {
250 if (str_starts_with($param_name, '={') && str_ends_with($param_name, '}'))
251 {
252 $key = substr($param_name, 2, -1);
253 if ($key !== strval(intval($key)))
254 {
255 unset($arParams[$param_name]);
256 continue;
257 }
258 }
259 if (is_array($paramval))
260 {
261 self::ComponentChecker($paramval, $arPHPparams, ($parentParamName !== false? $parentParamName : $param_name));
262 $arParams[$param_name] = $paramval;
263 }
264 elseif (str_starts_with($paramval, '={') && str_ends_with($paramval, '}'))
265 {
266 $arPHPparams[] = ($parentParamName !== false? $parentParamName : $param_name);
267 }
268 }
269 }
270}
$arParams
Определения access_dialog.php:21
static _ReplaceNonLatin($str)
Определения main.php:2377
static GetTemplateProps($componentName, $templateName, $siteTemplate="", $arCurrentValues=array())
Определения component_util.php:963
static GetComponentProps($componentName, $arCurrentValues=array(), $templateProperties=array())
Определения component_util.php:461
static CheckForComponent2($str)
Определения php_parser.php:505
static ParseFile($filesrc, $limit=false)
Определения php_parser.php:651
$str
Определения commerceml2.php:63
$filesrc
Определения component_props.php:53
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$start
Определения get_search.php:9
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$l
Определения options.php:783
EscapePHPString($str, $encloser='"')
Определения tools.php:4917
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
if(!Loader::includeModule('sale')) $pattern
Определения index.php:20
$arRes
Определения options.php:104
$k
Определения template_pdf.php:567
$n
Определения update_log.php:107