1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
editor_utils.php
См. документацию.
1<?php
2
4
6{
7 public static function RenderComponents($arParams)
8 {
9 global $USER;
10 $bLPA = !$USER->CanDoOperation('edit_php');
11 $startCount = CEditorUtils::StartFetchCSS(); // Start fetch CSS files
12 $arParams['name'] = addslashes($arParams['name']);
13 $arParams['template'] = addslashes($arParams['template']);
14 $arParams['siteTemplateId'] = addslashes($arParams['siteTemplateId']);
15
16 if ($arParams['siteTemplateId'] && !defined("SITE_TEMPLATE_ID"))
17 define("SITE_TEMPLATE_ID", $arParams['siteTemplateId']);
18
19 // Report only errors
20 error_reporting(E_ERROR);
21
22 if ($arParams['name']) // one component by name
24 elseif ($arParams['source']) // all components from content
26
27 CEditorUtils::GetCSS($startCount); // Echo path to css
28
29 // Cut out all scripts
30 $s = preg_replace("/<script[^>]*?>[\s|\S]*?<\/script>/is", '', $s);
31 // Cut out <div class="bx-component-panel"> .... </div>
32 $s = preg_replace("/<div[^>]*?class=\"bx-component-panel\"[^>]*?>[^<]*?<table[\s|\S]*?<\/table>[^<]*?<\/div>/is", '', $s);
33
34 echo $s;
35 }
36
37 public static function _RenderOneComponent($arParams, $bLPA)
38 {
39 global $APPLICATION, $USER;
40
41 $arProperties = CEditorUtils::GetCompProperties($arParams['name'], $arParams['template'], $arParams['siteTemplateId']);
42 $code = '$APPLICATION->IncludeComponent("'.$arParams['name'].'","'.$arParams['template'].'",';
43 $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
44
45 $arProps = $arParams['params'];
46 if (!$arProps) // Get default properties
47 {
48 $arProps = array();
49 foreach($arProperties as $key => $Prop)
50 $arProps[$key] = $Prop['DEFAULT'];
51 }
52 else
53 {
54 if ($bLPA)
55 {
56 $arPHPparams = Array();
57 CMain::LPAComponentChecker($arProps, $arPHPparams);
58 $len = count($arPHPparams);
59
60 // Replace values from 'DEFAULT' field
61 for ($e = 0; $e < $len; $e++)
62 {
63 $par_name = $arPHPparams[$e];
64 $arProps[$par_name] = isset($arProperties[$par_name]['DEFAULT']) ? $arProperties[$par_name]['DEFAULT'] : '';
65 }
66 }
67 }
68
69 foreach($arProps as $key => $val)
70 {
71 $val = trim($val);
72 if ($key != addslashes($key))
73 {
74 unset($arProps[$key]);
75 continue;
76 }
77
78 if (mb_strtolower($val) == 'array()')
79 {
80 $arProps[$key] = Array();
81 }
82 elseif (mb_substr(mb_strtolower($val), 0, 6) == 'array(')
83 {
84 $str = array();
85 $tArr = array();
87
88 if (is_array($tArr))
89 {
90 foreach($tArr as $k => $v)
91 {
92 if(mb_substr($v, 0, 2) == "={" && mb_substr($v, -1, 1) == "}" && mb_strlen($v) > 3)
93 $v = mb_substr($v, 2, -1);
94 unset($tArr[$k]);
95 $tArr[addslashes($k)] = addslashes(trim($v, " \"'"));
96 }
97 }
98 $arProps[$key] = $tArr;
99 }
100 else
101 {
102 $arProps[$key] = addslashes($val);
103 }
104 }
105
106 $arProps['BX_EDITOR_RENDER_MODE'] = 'Y'; //Set system parameter
107 $params = PHPParser::ReturnPHPStr2($arProps, $arParameters);
108 $code .= 'Array('.$params.')';
109 $code .= ');';
110
111 ob_start();
112 echo '#BX_RENDERED_COMPONENT#';
113 eval($code);
114 echo '#BX_RENDERED_COMPONENT#';
115 $s = ob_get_contents();
116 ob_end_clean();
117
118 return $s;
119 }
120
121 public static function _RenderAllComponents($arParams, $bLPA)
122 {
123 global $APPLICATION, $USER;
124 $s = '';
125 $arPHP = PHPParser::ParseFile($arParams['source']);
126 $l = count($arPHP);
127 if ($l > 0)
128 {
129 $new_source = '';
130 $end = 0;
131 $comp_count = 0;
132 ob_start();
133 for ($n = 0; $n<$l; $n++)
134 {
135 //Trim php tags
136 $src = $arPHP[$n][2];
137 if (mb_substr($src, 0, 5) == "<?"."php")
138 $src = mb_substr($src, 5);
139 else
140 $src = mb_substr($src, 2);
141 $src = mb_substr($src, 0, -2);
142
143 $comp2_begin = '$APPLICATION->INCLUDECOMPONENT(';
144 if (mb_strtoupper(mb_substr($src, 0, mb_strlen($comp2_begin))) != $comp2_begin)
145 continue;
146
148
149 if ($arRes)
150 {
151 $comp_name = CMain::_ReplaceNonLatin($arRes['COMPONENT_NAME']);
152 $template_name = CMain::_ReplaceNonLatin($arRes['TEMPLATE_NAME']);
153 $arParams = $arRes['PARAMS'];
154
155 $arParams['BX_EDITOR_RENDER_MODE'] = 'Y';
156
157 if ($bLPA)
158 {
159 $arPHPparams = Array();
160 CMain::LPAComponentChecker($arParams, $arPHPparams);
161 $len = count($arPHPparams);
162 }
163 $br = "\r\n";
164 $code = '$APPLICATION->IncludeComponent('.$br.
165 "\t".'"'.$comp_name.'",'.$br.
166 "\t".'"'.$template_name.'",'.$br;
167 // If exist at least one parameter with php code inside
168 if (count($arParams) > 0)
169 {
170 // Get array with description of component params
171 $arCompParams = CComponentUtil::GetComponentProps($comp_name);
172 $arTemplParams = CComponentUtil::GetTemplateProps($comp_name,$template_name,$template);
173
174 $arParameters = array();
175 if (isset($arCompParams["PARAMETERS"]) && is_array($arCompParams["PARAMETERS"]))
176 $arParameters = $arParameters + $arCompParams["PARAMETERS"];
177 if (is_array($arTemplParams))
178 $arParameters = $arParameters + $arTemplParams;
179
180 if ($bLPA)
181 {
182 // Replace values from 'DEFAULT'
183 for ($e = 0; $e < $len; $e++)
184 {
185 $par_name = $arPHPparams[$e];
186 $arParams[$par_name] = isset($arParameters[$par_name]['DEFAULT']) ? $arParameters[$par_name]['DEFAULT'] : '';
187 }
188 }
189
190 foreach($arParams as $key => $val)
191 {
192 if ($key != addslashes($key))
193 unset($arParams[$key]);
194 else
195 $arParams[$key] = addslashes($val);
196 }
197
198 //ReturnPHPStr
199 $params = PHPParser::ReturnPHPStr2($arParams, $arParameters);
200 $code .= "\t".'Array('.$br."\t".$params.$br."\t".')';
201 }
202 else
203 {
204 $code .= "\t".'Array()';
205 }
206 $parent_comp = CMain::_ReplaceNonLatin($arRes['PARENT_COMP']);
207 $arExParams_ = $arRes['FUNCTION_PARAMS'];
208 $bEx = isset($arExParams_) && is_array($arExParams_) && count($arExParams_) > 0;
209 if (!$parent_comp || mb_strtolower($parent_comp) == 'false')
210 $parent_comp = false;
211 if ($parent_comp)
212 {
213 if ($parent_comp == 'true' || intval($parent_comp) == $parent_comp)
214 $code .= ','.$br."\t".$parent_comp;
215 else
216 $code .= ','.$br."\t\"".$parent_comp.'"';
217 }
218 if ($bEx)
219 {
220 if (!$parent_comp)
221 $code .= ','.$br."\tfalse";
222
223 $arExParams = array();
224 foreach ($arExParams_ as $k => $v)
225 {
226 $k = CMain::_ReplaceNonLatin($k);
227 $v = CMain::_ReplaceNonLatin($v);
228 if ($k <> '' && $v <> '')
229 $arExParams[$k] = $v;
230 }
231 $exParams = PHPParser::ReturnPHPStr2($arExParams);
232 $code .= ','.$br."\tArray(".$exParams.')';
233 }
234 $code .= $br.');';
235
236 echo '#BX_RENDERED_COMPONENT_'.$comp_count.'#';
237 eval($code);
238 echo '#BX_RENDERED_COMPONENT_'.$comp_count.'#';
239 }
240 $comp_count++;
241 }
242 $s = ob_get_contents();
243 ob_end_clean();
244 }
245 return $s;
246 }
247
248 public static function GetCompProperties($name, $template = '', $siteTemplateId = '', $arCurVals = array())
249 {
250 $stid = $siteTemplateId;
251 $arProps = CComponentUtil::GetComponentProps($name, $arCurVals);
252 $arTemplateProps = CComponentUtil::GetTemplateProps($name, $template, $stid, $arCurVals);
253 return $arProps['PARAMETERS'] + $arTemplateProps;
254 }
255
256 public static function StartFetchCSS()
257 {
258 return count($GLOBALS['APPLICATION']->sPath2css);
259 }
260
261 public static function GetCSS($startCount)
262 {
263 global $APPLICATION;
264 $arCSS = array();
265 $res = '';
266 $curCount = count($APPLICATION->sPath2css);
267 if ($curCount <= $startCount)
268 return;
269
270 for ($i = $startCount; $i < $curCount; $i++)
271 {
272 $path = $APPLICATION->sPath2css[$i];
273 if (!in_array($path, $arCSS))
274 $arCSS[] = $path;
275 }
276
277 echo "<script>window.arUsedCSS = [];\n";
278 for ($i = 0, $l = count($arCSS); $i < $l; $i++)
279 {
280 $path = $arCSS[$i];
281 if (mb_strpos($path, '?') !== false)
282 $path = mb_substr($path, 0, mb_strpos($path, '?'));
283 $filename = $_SERVER["DOCUMENT_ROOT"].$path;
284 if (file_exists($filename))
285 echo 'window.arUsedCSS.push("'.$path.'");'."\n";
286 }
287 echo '</script>';
288 }
289
290 public static function UnJSEscapeArray($ar)
291 {
292 //$APPLICATION->UnJSEscape
293 foreach($ar as $key => $val)
294 {
295 if (is_array($val))
297 elseif (is_string($val))
298 $ar[$key] = $GLOBALS['APPLICATION']->UnJSEscape($val);
299 }
300 return $ar;
301 }
302}
$arParams
Определения access_dialog.php:21
$path
Определения access_edit.php:21
global $APPLICATION
Определения include.php:80
static GetTemplateProps($componentName, $templateName, $siteTemplate="", $arCurrentValues=array())
Определения component_util.php:963
static GetComponentProps($componentName, $arCurrentValues=array(), $templateProperties=array())
Определения component_util.php:461
Определения editor_utils.php:6
static _RenderAllComponents($arParams, $bLPA)
Определения editor_utils.php:121
static StartFetchCSS()
Определения editor_utils.php:256
static GetCompProperties($name, $template='', $siteTemplateId='', $arCurVals=array())
Определения editor_utils.php:248
static RenderComponents($arParams)
Определения editor_utils.php:7
static GetCSS($startCount)
Определения editor_utils.php:261
static UnJSEscapeArray($ar)
Определения editor_utils.php:290
static _RenderOneComponent($arParams, $bLPA)
Определения editor_utils.php:37
static CheckForComponent2($str)
Определения php_parser.php:505
static GetParamsRec($params, &$arAllStr, &$arResult)
Определения php_parser.php:84
static ParseFile($filesrc, $limit=false)
Определения php_parser.php:651
$str
Определения commerceml2.php:63
$filename
Определения file_edit.php:47
$template
Определения file_edit.php:49
</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
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$l
Определения options.php:783
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
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
$val
Определения options.php:1793
$arRes
Определения options.php:104
$k
Определения template_pdf.php:567
$GLOBALS['_____370096793']
Определения update_client.php:1
$n
Определения update_log.php:107
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644