1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
php_parser.php
См. документацию.
1<?php
8
10{
11 protected static $arAllStr;
12
13 public static function ReplString($str, $arAllStr)
14 {
15 self::$arAllStr = $arAllStr;
16
17 if (preg_match("'^\x01([0-9]+)\x02$'s", $str))
18 {
19 return preg_replace_callback("'\x01([0-9]+)\x02's", "PHPParser::getString", $str);
20 }
21 if (strval(floatval($str)) == $str)
22 {
23 return preg_replace_callback("'\x01([0-9]+)\x02's", "PHPParser::getQuotedString", $str);
24 }
25 elseif ($str == "")
26 {
27 return "";
28 }
29 else
30 {
31 return "={" . preg_replace_callback("'\x01([0-9]+)\x02's", "PHPParser::getQuotedString", $str) . "}";
32 }
33 }
34
35 public static function getString($matches)
36 {
37 return self::$arAllStr[$matches[1]];
38 }
39
40 public static function getQuotedString($matches)
41 {
42 return '"' . self::$arAllStr[$matches[1]] . '"';
43 }
44
45 public static function GetParams($params)
46 {
47 $arParams = [];
48 $brackets = 0;
49 $param_tmp = "";
50 $params_l = mb_strlen($params);
51 for ($i = 0; $i < $params_l; $i++)
52 {
53 $ch = mb_substr($params, $i, 1);
54 if ($ch == "(" || $ch == "[")
55 {
56 $brackets++;
57 }
58 elseif ($ch == ")" || $ch == "]")
59 {
60 $brackets--;
61 }
62 elseif ($ch == "," && $brackets == 0)
63 {
64 $arParams[] = $param_tmp;
65 $param_tmp = "";
66 continue;
67 }
68
69 if ($brackets < 0)
70 {
71 break;
72 }
73
74 $param_tmp .= $ch;
75 }
76 if ($param_tmp <> "")
77 {
78 $arParams[] = $param_tmp;
79 }
80
81 return $arParams;
82 }
83
84 public static function GetParamsRec($params, &$arAllStr, &$arResult)
85 {
86 $found = false;
87 $paramsList = "";
88 if (strtolower(substr($params, 0, 6)) == 'array(')
89 {
90 $found = true;
91 $paramsList = substr($params, 6);
92 }
93 elseif (str_starts_with($params, "["))
94 {
95 $found = true;
96 $paramsList = substr($params, 1);
97 }
98 if ($found)
99 {
100 $arParams = static::GetParams($paramsList);
101 foreach ($arParams as $i => $el)
102 {
103 if (strtolower(substr($el, 0, 6)) == 'array(' || str_starts_with($el, '['))
104 {
105 // no index, value is an array. We should check it first, because this array can contain '=>' operator.
106 $p = false;
107 }
108 else
109 {
110 // possible index
111 $p = mb_strpos($el, "=>");
112 }
113 if ($p === false)
114 {
115 // value without index
116 if (is_string($arResult))
117 {
118 $arResult = static::ReplString($el, $arAllStr);
119 }
120 else
121 {
122 static::GetParamsRec($el, $arAllStr, $arResult[$i]);
123 }
124 }
125 else
126 {
127 // value with index
128 $el_ind = static::ReplString(mb_substr($el, 0, $p), $arAllStr);
129 $el_val = mb_substr($el, $p + 2);
130 static::GetParamsRec($el_val, $arAllStr, $arResult[$el_ind]);
131 }
132 }
133 }
134 else
135 {
136 $arResult = static::ReplString($params, $arAllStr);
137 }
138 }
139
140 // Parse string and check if it is a component call. Return call params array
141 public static function CheckForComponent($str)
142 {
143 if (str_starts_with($str, "<?php"))
144 {
145 $str = substr($str, 5);
146 }
147 else
148 {
149 $str = substr($str, 2);
150 }
151
152 $str = substr($str, 0, -2);
153
154 $bSlashed = false;
155 $bInString = false;
156 $arAllStr = [];
157 $new_str = "";
158 $string_tmp = "";
159 $quote_ch = "";
160 $i = -1;
161 $length = mb_strlen($str);
162 while ($i < $length - 1)
163 {
164 $i++;
165 $ch = mb_substr($str, $i, 1);
166 if (!$bInString)
167 {
168 if ($string_tmp != "")
169 {
170 $arAllStr[] = $string_tmp;
171 $string_tmp = "";
172 $new_str .= chr(1) . (count($arAllStr) - 1) . chr(2);
173 }
174
175 //comment
176 if ($ch == "/" && $i + 1 < $length)
177 {
178 $ti = 0;
179 if (mb_substr($str, $i + 1, 1) == "*" && ($ti = mb_strpos($str, "*/", $i + 2)) !== false)
180 {
181 $ti += 2;
182 }
183 elseif (mb_substr($str, $i + 1, 1) == "/" && ($ti = mb_strpos($str, "\n", $i + 2)) !== false)
184 {
185 $ti += 1;
186 }
187
188 if ($ti)
189 {
190 $i = $ti;
191 }
192
193 continue;
194 }
195
196 if ($ch == " " || $ch == "\r" || $ch == "\n" || $ch == "\t")
197 {
198 continue;
199 }
200 }
201
202 if ($bInString && $ch == "\\" && !$bSlashed)
203 {
204 $bSlashed = true;
205 continue;
206 }
207
208 if ($ch == "\"" || $ch == "'")
209 {
210 if ($bInString)
211 {
212 if (!$bSlashed && $quote_ch == $ch)
213 {
214 $bInString = false;
215 continue;
216 }
217 }
218 else
219 {
220 $bInString = true;
221 $quote_ch = $ch;
222 continue;
223 }
224 }
225
226 $bSlashed = false;
227 if ($bInString)
228 {
229 $string_tmp .= $ch;
230 continue;
231 }
232
233 $new_str .= $ch;
234 }
235
236 if ($pos = mb_strpos($new_str, "("))
237 {
238 $func_name = mb_substr($new_str, 0, $pos + 1);
239 if (preg_match("/^(\\\$[A-Z_][A-Z0-9_]*)(\\s*=\\s*)/i", $func_name, $arMatch))
240 {
241 $var_name = $arMatch[1];
242 $func_name = mb_substr($func_name, mb_strlen($arMatch[0]));
243 }
244 else
245 {
246 $var_name = "";
247 }
248 $func_name = preg_replace("'\\\$GLOBALS\\[(\"|\\')(.+?)(\"|\\')\\]'s", "\$\\2", $func_name);
249 switch (mb_strtoupper($func_name))
250 {
251 case '$APPLICATION->INCLUDEFILE(':
252 $params = mb_substr($new_str, $pos + 1);
253 $arParams = static::GetParams($params);
254 $arIncludeParams = [];
255
256 if (preg_match("/^array\\(/i", $arParams[1]))
257 {
258 $arParams2 = static::GetParams(mb_substr($arParams[1], 6));
259 foreach ($arParams2 as $el)
260 {
261 $p = mb_strpos($el, "=>");
262 $el_ind = static::ReplString(mb_substr($el, 0, $p), $arAllStr);
263 $el_val = mb_substr($el, $p + 2);
264 if (preg_match("/^array\\(/i", $el_val))
265 {
266 $res_ar = [];
267 $arParamsN = static::GetParams(mb_substr($el_val, 6));
268 foreach ($arParamsN as $param)
269 {
270 $res_ar[] = static::ReplString($param, $arAllStr);
271 }
272
273 $arIncludeParams[$el_ind] = $res_ar;
274 }
275 else
276 {
277 $arIncludeParams[$el_ind] = static::ReplString($el_val, $arAllStr);
278 }
279 }
280 }
281 return [
282 "SCRIPT_NAME" => static::ReplString($arParams[0], $arAllStr),
283 "PARAMS" => $arIncludeParams,
284 "VARIABLE" => $var_name,
285 ];
286 }
287 }
288 return false;
289 }
290
291 public static function GetComponentParams($instruction, $arAllStr)
292 {
293 if ($pos = mb_strpos($instruction, "("))
294 {
295 $func_name = mb_substr($instruction, 0, $pos + 1);
296 if (preg_match("/(\\\$[A-Z_][A-Z0-9_]*)(\\s*=\\s*)/i", $func_name, $arMatch))
297 {
298 $var_name = $arMatch[1];
299 }
300 else
301 {
302 $var_name = "";
303 }
304
305 $params = mb_substr($instruction, $pos + 1);
306 $arParams = static::GetParams($params);
307
308 $arIncludeParams = [];
309 $arFuncParams = [];
310 if (!empty($arParams[2]))
311 {
312 static::GetParamsRec($arParams[2], $arAllStr, $arIncludeParams);
313 }
314 if (!empty($arParams[4]))
315 {
316 static::GetParamsRec($arParams[4], $arAllStr, $arFuncParams);
317 }
318
319 return [
320 "COMPONENT_NAME" => static::ReplString($arParams[0] ?? '', $arAllStr),
321 "TEMPLATE_NAME" => static::ReplString($arParams[1] ?? '', $arAllStr),
322 "PARAMS" => $arIncludeParams,
323 "PARENT_COMP" => $arParams[3] ?? '',
324 "VARIABLE" => $var_name,
325 "FUNCTION_PARAMS" => $arFuncParams,
326 "RETURN_RESULT" => $arParams[5] ?? '',
327 ];
328 }
329 return [];
330 }
331
332 public static function ParseScript($scriptContent)
333 {
334 $arComponents = [];
335 $componentNumber = -1;
336
337 $bInComponent = false;
338 $bInPHP = false;
339
340 $bInString = false;
341 $quoteChar = "";
342 $bSlashed = false;
343
344 $string = false;
345 $instruction = "";
346
347 //mb_substr is catastrophic slow, so in UTF we use array of characters
348 $allChars = preg_split('//u', $scriptContent, -1, PREG_SPLIT_NO_EMPTY);
349
350 if ($allChars === false)
351 {
352 return [];
353 }
354
355 $scriptContentLength = mb_strlen($scriptContent);
356 $arAllStr = [];
357 $ind = -1;
358 while ($ind < $scriptContentLength - 1)
359 {
360 $ind++;
361 $ch = $allChars[$ind];
362
363 if ($bInPHP)
364 {
365 if (!$bInString)
366 {
367 if (!$bInComponent && $instruction <> '')
368 {
369 if (preg_match("#\\s*((\\\$[A-Z_][A-Z0-9_]*\\s*=)?\\s*\\\$APPLICATION->IncludeComponent\\s*\\()#is", $instruction, $arMatches))
370 {
371 $arAllStr = [];
372 $bInComponent = true;
373 $componentNumber++;
374 $instruction = $arMatches[1];
375
376 $arComponents[$componentNumber] = [
377 "START" => ($ind - mb_strlen($arMatches[1])),
378 "END" => false,
379 "DATA" => [],
380 ];
381 }
382 }
383 if ($string !== false)
384 {
385 if ($bInComponent)
386 {
387 $arAllStr[] = $string;
388 $instruction .= chr(1) . (count($arAllStr) - 1) . chr(2);
389 }
390 $string = false;
391 }
392 if ($ch == ";")
393 {
394 if ($bInComponent)
395 {
396 $bInComponent = false;
397 $arComponents[$componentNumber]["END"] = $ind + 1;
398 $arComponents[$componentNumber]["DATA"] = static::GetComponentParams(preg_replace("#[ \r\n\t]#", "", $instruction), $arAllStr);
399 }
400 $instruction = "";
401 continue;
402 }
403 if ($ch == "/" && $ind < $scriptContentLength - 2)
404 {
405 $nextChar = $allChars[$ind + 1];
406 if ($nextChar == "/")
407 {
408 $endPos = mb_strpos($scriptContent, "\n", $ind + 2);
409
410 if ($endPos === false)
411 {
412 $ind = $scriptContentLength - 1;
413 }
414 else
415 {
416 $ind = $endPos;
417 }
418
419 continue;
420 }
421 elseif ($nextChar == "*")
422 {
423 $endPos = mb_strpos($scriptContent, "*/", $ind + 2);
424
425 if ($endPos === false)
426 {
427 $ind = $scriptContentLength - 1;
428 }
429 else
430 {
431 $ind = $endPos + 1;
432 }
433
434 continue;
435 }
436 }
437
438 if ($ch == "\"" || $ch == "'")
439 {
440 $bInString = true;
441 $string = "";
442 $quoteChar = $ch;
443 continue;
444 }
445
446 if ($ch == "?" && $ind < $scriptContentLength - 2 && $allChars[$ind + 1] == ">")
447 {
448 $ind += 1;
449 if ($bInComponent)
450 {
451 $bInComponent = false;
452 $arComponents[$componentNumber]["END"] = $ind - 1;
453 $arComponents[$componentNumber]["DATA"] = static::GetComponentParams(preg_replace("#[ \r\n\t]#", "", $instruction), $arAllStr);
454 }
455 $instruction = "";
456 $bInPHP = false;
457 continue;
458 }
459
460 $instruction .= $ch;
461
462 if ($ch == " " || $ch == "\r" || $ch == "\n" || $ch == "\t")
463 {
464 continue;
465 }
466 }
467 else
468 {
469 if ($ch == "\\" && !$bSlashed)
470 {
471 $bSlashed = true;
472 continue;
473 }
474 if ($ch == $quoteChar && !$bSlashed)
475 {
476 $bInString = false;
477 continue;
478 }
479 $bSlashed = false;
480
481 $string .= $ch;
482 }
483 }
484 else
485 {
486 if ($ch == "<")
487 {
488 if ($ind < $scriptContentLength - 5 && $allChars[$ind + 1] . $allChars[$ind + 2] . $allChars[$ind + 3] . $allChars[$ind + 4] == "?php")
489 {
490 $bInPHP = true;
491 $ind += 4;
492 }
493 elseif ($ind < $scriptContentLength - 2 && $allChars[$ind + 1] == "?")
494 {
495 $bInPHP = true;
496 $ind += 1;
497 }
498 }
499 }
500 }
501 return $arComponents;
502 }
503
504 // Components 2. Parse string and check if it is a component call. Return call params array
505 public static function CheckForComponent2($str)
506 {
507 if (str_starts_with($str, "<?php"))
508 {
509 $str = substr($str, 5);
510 }
511 else
512 {
513 $str = substr($str, 2);
514 }
515
516 $str = substr($str, 0, -2);
517
518 $bSlashed = false;
519 $bInString = false;
520 $arAllStr = [];
521 $new_str = "";
522 $string_tmp = "";
523 $quote_ch = "";
524 $i = -1;
525 $length = mb_strlen($str);
526 while ($i < $length - 1)
527 {
528 $i++;
529 $ch = mb_substr($str, $i, 1);
530 if (!$bInString)
531 {
532 if ($string_tmp != "")
533 {
534 $arAllStr[] = $string_tmp;
535 $string_tmp = "";
536 $new_str .= chr(1) . (count($arAllStr) - 1) . chr(2);
537 }
538
539 //comment
540 if ($ch == "/" && $i + 1 < $length)
541 {
542 $ti = 0;
543 if (mb_substr($str, $i + 1, 1) == "*" && ($ti = mb_strpos($str, "*/", $i + 2)) !== false)
544 {
545 $ti += 1;
546 }
547 elseif (mb_substr($str, $i + 1, 1) == "/" && ($ti = mb_strpos($str, "\n", $i + 2)) !== false)
548 {
549 $ti += 0;
550 }
551
552 if ($ti)
553 {
554 $i = $ti;
555 }
556
557 continue;
558 }
559
560 if ($ch == " " || $ch == "\r" || $ch == "\n" || $ch == "\t")
561 {
562 continue;
563 }
564 }
565
566 if ($bInString && $ch == "\\" && !$bSlashed)
567 {
568 $bSlashed = true;
569 continue;
570 }
571
572 if ($ch == "\"" || $ch == "'")
573 {
574 if ($bInString)
575 {
576 if (!$bSlashed && $quote_ch == $ch)
577 {
578 $bInString = false;
579 continue;
580 }
581 }
582 else
583 {
584 $bInString = true;
585 $quote_ch = $ch;
586 continue;
587 }
588 }
589
590 $bSlashed = false;
591 if ($bInString)
592 {
593 $string_tmp .= $ch;
594 continue;
595 }
596
597 $new_str .= $ch;
598 }
599
600 if ($pos = mb_strpos($new_str, "("))
601 {
602 $func_name = mb_substr($new_str, 0, $pos + 1);
603 if (preg_match("/^(\\\$[A-Z_][A-Z0-9_]*)(\\s*=\\s*)/i", $func_name, $arMatch))
604 {
605 $var_name = $arMatch[1];
606 $func_name = mb_substr($func_name, mb_strlen($arMatch[0]));
607 }
608 else
609 {
610 $var_name = "";
611 }
612
613 self::$arAllStr = $arAllStr;
614 $func_name = preg_replace_callback("'\x01([0-9]+)\x02's", "PHPParser::getString", $func_name);
615
616 $isComponent2Begin = false;
617 $arIncludeComponentFunctionStrings = self::getComponentFunctionStrings();
618 foreach ($arIncludeComponentFunctionStrings as $functionName)
619 {
620 $component2Begin = mb_strtoupper($functionName) . '(';
621 if (mb_strtoupper($func_name) == $component2Begin)
622 {
623 $isComponent2Begin = true;
624 break;
625 }
626 }
627 if ($isComponent2Begin)
628 {
629 $params = mb_substr($new_str, $pos + 1);
630 $arParams = static::GetParams($params);
631
632 $arIncludeParams = [];
633 $arFuncParams = [];
634 static::GetParamsRec($arParams[2], $arAllStr, $arIncludeParams);
635 static::GetParamsRec($arParams[4], $arAllStr, $arFuncParams);
636
637 return [
638 "COMPONENT_NAME" => static::ReplString($arParams[0], $arAllStr),
639 "TEMPLATE_NAME" => static::ReplString($arParams[1], $arAllStr),
640 "PARAMS" => $arIncludeParams,
641 "PARENT_COMP" => $arParams[3],
642 "VARIABLE" => $var_name,
643 "FUNCTION_PARAMS" => $arFuncParams,
644 ];
645 }
646 }
647 return false;
648 }
649
650 // Parse file and return all PHP blocks in array
651 public static function ParseFile($filesrc, $limit = false)
652 {
653 $arScripts = [];
654 $p = 0;
655 $nLen = mb_strlen($filesrc);
656 while (($p = mb_strpos($filesrc, "<?", $p)) !== false)
657 {
658 $i = $p + 2;
659 $bSlashed = false;
660 $bInString = false;
661 $quote_ch = "";
662 while ($i < $nLen - 1)
663 {
664 $i++;
665 $ch = mb_substr($filesrc, $i, 1);
666 if (!$bInString)
667 {
668 //comment
669 if ($ch == "/" && $i + 1 < $nLen)
670 {
671 //php tag
672 $posnext = mb_strpos($filesrc, "?>", $i);
673 if ($posnext === false)
674 {
675 //no final tag
676 break;
677 }
678 $posnext += 2;
679
680 $ti = 0;
681 if (mb_substr($filesrc, $i + 1, 1) == "*" && ($ti = mb_strpos($filesrc, "*/", $i + 2)) !== false)
682 {
683 $ti += 2;
684 }
685 elseif (mb_substr($filesrc, $i + 1, 1) == "/" && ($ti = mb_strpos($filesrc, "\n", $i + 2)) !== false)
686 {
687 $ti += 1;
688 }
689
690 if ($ti)
691 {
692 // begin ($i) and end ($ti) of comment
693 // проверим что раньше конец скрипта или конец комментария (например в одной строке "//comment ? >")
694 if ($ti > $posnext && mb_substr($filesrc, $i + 1, 1) != "*")
695 {
696 // скрипт закончился раньше комментария
697 // вырежем скрипт
698 $arScripts[] = [$p, $posnext, mb_substr($filesrc, $p, $posnext - $p)];
699 break;
700 }
701 else
702 {
703 // комментарий закончился раньше скрипта
704 $i = $ti - 1;
705 }
706 }
707 continue;
708 }
709
710 if ($ch == "?" && $i + 1 < $nLen && mb_substr($filesrc, $i + 1, 1) == ">")
711 {
712 $i = $i + 2;
713 $arScripts[] = [$p, $i, mb_substr($filesrc, $p, $i - $p)];
714 break;
715 }
716 }
717
718 if ($bInString && $ch == "\\" && !$bSlashed)
719 {
720 $bSlashed = true;
721 continue;
722 }
723
724 if ($ch == "\"" || $ch == "'")
725 {
726 if ($bInString)
727 {
728 if (!$bSlashed && $quote_ch == $ch)
729 {
730 $bInString = false;
731 }
732 }
733 else
734 {
735 $bInString = true;
736 $quote_ch = $ch;
737 }
738 }
739
740 $bSlashed = false;
741 }
742 if ($i >= $nLen)
743 {
744 break;
745 }
746 if ($limit && count($arScripts) == $limit)
747 {
748 break;
749 }
750 $p = $i;
751 }
752 return $arScripts;
753 }
754
755 public static function PreparePHP($str)
756 {
757 if (str_starts_with($str, "={") && str_ends_with($str, "}") && mb_strlen($str) > 3)
758 {
759 return substr($str, 2, -1);
760 }
761
762 return '"' . EscapePHPString($str) . '"';
763 }
764
765 // Return PHP string of component call params
766 public static function ReturnPHPStr($arVals, $arParams)
767 {
768 $res = "";
769 $un = md5(uniqid());
770 $i = 0;
771 foreach ($arVals as $key => $val)
772 {
773 $i++;
774 $comm = ($arParams[$key]["NAME"] <> '' ? "$un|$i|// " . $arParams[$key]["NAME"] : "");
775 $res .= "\r\n\t\"" . $key . "\"\t=>\t";
776 if (is_array($val) && count($val) > 1)
777 {
778 $res .= "array(" . $comm . "\r\n";
779 }
780
781 if (is_array($val) && count($val) > 1)
782 {
783 $zn = '';
784 foreach ($val as $p)
785 {
786 if ($zn != '')
787 {
788 $zn .= ",\r\n";
789 }
790 $zn .= "\t\t\t\t\t" . static::PreparePHP($p);
791 }
792 $res .= $zn . "\r\n\t\t\t\t),";
793 }
794 elseif (is_array($val))
795 {
796 $res .= "array(" . static::PreparePHP($val[0]) . ")," . $comm;
797 }
798 else
799 {
800 $res .= static::PreparePHP($val) . "," . $comm;
801 }
802 }
803
804 $max = 0;
805 $lngth = [];
806 for ($j = 1; $j <= $i; $j++)
807 {
808 $p = mb_strpos($res, "$un|$j|");
809 $pn = mb_strrpos(mb_substr($res, 0, $p), "\n");
810 $l = ($p - $pn);
811 $lngth[$j] = $l;
812 if ($max < $l)
813 {
814 $max = $l;
815 }
816 }
817
818 for ($j = 1; $j <= $i; $j++)
819 {
820 $res = str_replace($un . "|$j|", str_repeat("\t", intval(($max - $lngth[$j] + 7) / 8)), $res);
821 }
822
823 return trim($res, " \t,\r\n");
824 }
825
826 public static function ReturnPHPStrRec($arVal, $level, $comm = "")
827 {
828 $result = "";
829 $pref = str_repeat("\t", $level + 1);
830 if (is_array($arVal))
831 {
832 $result .= "[" . (($level == 1) ? $comm : "") . "\n";
833 foreach ($arVal as $key => $value)
834 {
835 $result .= $pref . "\t" . ((intval($key) . "|" == $key . "|") ? $key : static::PreparePHP($key)) . " => " . static::ReturnPHPStrRec($value, $level + 1);
836 }
837 $result .= $pref . "],\n";
838 }
839 else
840 {
841 $result .= static::PreparePHP($arVal) . "," . (($level == 1) ? $comm : "") . "\n";
842 }
843 return $result;
844 }
845
846 // Components 2. Return PHP string of component call params
847 public static function ReturnPHPStr2($arVals, $arParams = [])
848 {
849 $res = "";
850 foreach ($arVals as $key => $val)
851 {
852 $res .= "\t\t\"" . EscapePHPString($key) . "\" => ";
853 $comm = (!empty($arParams[$key]["NAME"]) ? "\t// " . $arParams[$key]["NAME"] : "");
854 $res .= static::ReturnPHPStrRec($val, 1, $comm);
855 }
856
857 return trim($res, " \t,\r\n");
858 }
859
860 public static function FindComponent($component_name, $filesrc, $src_line)
861 {
862 /* parse source file for PHP code */
863 $arComponents = static::ParseScript($filesrc);
864
865 /* identify the component by line number */
866 $arComponent = false;
867 for ($i = 0, $cnt = count($arComponents); $i < $cnt; $i++)
868 {
869 $nLineFrom = substr_count(mb_substr($filesrc, 0, $arComponents[$i]["START"]), "\n") + 1;
870 $nLineTo = substr_count(mb_substr($filesrc, 0, $arComponents[$i]["END"]), "\n") + 1;
871
872 if ($nLineFrom <= $src_line && $nLineTo >= $src_line)
873 {
874 if ($arComponents[$i]["DATA"]["COMPONENT_NAME"] == $component_name)
875 {
876 $arComponent = $arComponents[$i];
877 break;
878 }
879 }
880 if ($nLineTo > $src_line)
881 {
882 break;
883 }
884 }
885 return $arComponent;
886 }
887
888 public static function getPhpChunks($filesrc, $limit = false)
889 {
890 $chunks = [];
891 $chunk = '';
892 $php = false;
893 if (function_exists("token_get_all"))
894 {
895 foreach (token_get_all($filesrc) as $token)
896 {
897 if ($php)
898 {
899 if (is_array($token))
900 {
901 $chunk .= $token[1];
902 if ($token[0] === T_CLOSE_TAG)
903 {
904 $chunks[] = $chunk;
905 $chunk = '';
906 $php = false;
907 if ($limit && count($chunks) == $limit)
908 {
909 break;
910 }
911 }
912 }
913 else
914 {
915 $chunk .= $token;
916 }
917 }
918 else
919 {
920 if (is_array($token))
921 {
922 if ($token[0] === T_OPEN_TAG || $token[0] === T_OPEN_TAG_WITH_ECHO)
923 {
924 $chunk .= $token[1];
925 $php = true;
926 }
927 }
928 }
929 }
930 }
931 else
932 {
933 foreach (static::ParseFile($filesrc, $limit) as $chunk)
934 {
935 $chunks[] = $chunk[2];
936 }
937 }
938
939 if ($php && $chunk != '')
940 {
941 $chunks[] = $chunk;
942 }
943
944 return $chunks;
945 }
946
947 public static function getPageTitle($filesrc, $prolog = false)
948 {
949 if ($prolog === false)
950 {
951 $chunks = static::getPhpChunks($filesrc, 1);
952 if (!empty($chunks))
953 {
954 $prolog = &$chunks[0];
955 }
956 else
957 {
958 $prolog = '';
959 }
960 }
961
962 $title = false;
963
964 if ($prolog != '')
965 {
966 if (preg_match("/\\\$APPLICATION->SetTitle\\s*\\(\\s*\"(.*?)(?<!\\\\)\"\\s*\\);/is", $prolog, $regs))
967 {
968 $title = UnEscapePHPString($regs[1]);
969 }
970 elseif (preg_match("/\\\$APPLICATION->SetTitle\\s*\\(\\s*'(.*?)(?<!\\\\)'\\s*\\);/is", $prolog, $regs))
971 {
972 $title = UnEscapePHPString($regs[1]);
973 }
974 elseif (preg_match("'<title[^>]*>([^>]+)</title[^>]*>'i", $prolog, $regs))
975 {
976 $title = $regs[1];
977 }
978 }
979
980 if (!$title && preg_match("'<title[^>]*>([^>]+)</title[^>]*>'i", $filesrc, $regs))
981 {
982 $title = $regs[1];
983 }
984
985 return $title;
986 }
987
988 public static function getComponentFunctionStrings()
989 {
990 return [
991 '$APPLICATION->IncludeComponent',
992 'EventMessageThemeCompiler::includeComponent',
993 ];
994 }
995
996 public static function buildComponentCode(array $component, ?string $templateName = null, ?array $parameters = null): string
997 {
998 if ($templateName === null)
999 {
1000 $templateName = $component['DATA']['TEMPLATE_NAME'];
1001 }
1002 if ($parameters === null)
1003 {
1004 $parameters = $component['DATA']['PARAMS'];
1005 }
1006
1007 $functionParams = '';
1008 if (!empty($component['DATA']['FUNCTION_PARAMS']))
1009 {
1010 $functionParams = ",\n"
1011 . "\t[\n"
1012 . "\t\t" . static::ReturnPHPStr2($component['DATA']['FUNCTION_PARAMS']) . "\n"
1013 . "\t]";
1014 }
1015 elseif (!empty($component['DATA']['RETURN_RESULT']))
1016 {
1017 $functionParams = ",\n\t[]";
1018 }
1019
1020 $code = ($component['DATA']['VARIABLE'] ? $component['DATA']['VARIABLE'] . ' = ' : '')
1021 . "\$APPLICATION->IncludeComponent(\n"
1022 . "\t\"" . $component['DATA']['COMPONENT_NAME'] . "\", \n"
1023 . "\t\"" . $templateName . "\", \n"
1024 . "\t[\n"
1025 . "\t\t" . static::ReturnPHPStr2($parameters) . "\n"
1026 . "\t],\n"
1027 . "\t" . (!empty($component['DATA']['PARENT_COMP']) ? $component['DATA']['PARENT_COMP'] : 'false')
1028 . $functionParams
1029 . (!empty($component['DATA']['RETURN_RESULT']) ? ",\n\t" . $component['DATA']['RETURN_RESULT'] : '')
1030 . "\n);";
1031
1032 return $code;
1033 }
1034}
$arParams
Определения access_dialog.php:21
$arVal
Определения options.php:1785
$arResult
Определения generate_coupon.php:16
Определения php_parser.php:10
static ReplString($str, $arAllStr)
Определения php_parser.php:13
static ParseScript($scriptContent)
Определения php_parser.php:332
static CheckForComponent2($str)
Определения php_parser.php:505
static getString($matches)
Определения php_parser.php:35
static GetParams($params)
Определения php_parser.php:45
static GetComponentParams($instruction, $arAllStr)
Определения php_parser.php:291
static $arAllStr
Определения php_parser.php:11
static getQuotedString($matches)
Определения php_parser.php:40
static GetParamsRec($params, &$arAllStr, &$arResult)
Определения php_parser.php:84
static PreparePHP($str)
Определения php_parser.php:755
static CheckForComponent($str)
Определения php_parser.php:141
static ReturnPHPStr($arVals, $arParams)
Определения php_parser.php:766
static ParseFile($filesrc, $limit=false)
Определения php_parser.php:651
$str
Определения commerceml2.php:63
$arComponent
Определения component_props2.php:72
$src_line
Определения component_props.php:43
$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
$result
Определения get_property_values.php:14
else $ch
Определения group_list_element_edit.php:27
$p
Определения group_list_element_edit.php:23
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$l
Определения options.php:783
EscapePHPString($str, $encloser='"')
Определения tools.php:4917
UnEscapePHPString($str, $encloser='"')
Определения tools.php:4933
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</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
$title
Определения pdf.php:123
$val
Определения options.php:1793
$matches
Определения index.php:22
$max
Определения template_copy.php:262