PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/main/public/component_props.php

https://gitlab.com/alexprowars/bitrix
PHP | 378 lines | 333 code | 37 blank | 8 comment | 72 complexity | 337f04e039b9ecf808a57e8dcfb7956d MD5 | raw file
  1. <?
  2. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_js.php");
  4. if(!$USER->CanDoOperation('edit_php'))
  5. die(GetMessage("ACCESS_DENIED"));
  6. IncludeModuleLangFile(__FILE__);
  7. CUtil::JSPostUnescape();
  8. $obJSPopup = new CJSPopup('',
  9. array(
  10. 'TITLE' => GetMessage("comp_prop_title"),
  11. 'ARGS' => 'path='.urlencode(CUtil::addslashes($_GET["path"])).
  12. '&amp;template_id='.urlencode(CUtil::addslashes($_GET["template_id"])).
  13. '&amp;lang='.LANGUAGE_ID.
  14. '&amp;src_path='.urlencode(CUtil::addslashes($_GET["src_path"])).
  15. '&amp;src_line='.intval($_GET["src_line"]).
  16. '&amp;action=save'
  17. )
  18. );
  19. $obJSPopup->ShowTitlebar();
  20. $strWarning = "";
  21. $arValues = array();
  22. $arTemplate = false;
  23. $aComponent = false;
  24. $io = CBXVirtualIo::GetInstance();
  25. if($_SERVER["REQUEST_METHOD"] == "POST" && $_GET["action"] == "refresh")
  26. {
  27. // parameters were changed by "ok" button
  28. // we need to refresh the component description with new values
  29. $arValues = $_POST;
  30. }
  31. else
  32. {
  33. // try to read parameters from script file
  34. /* Try to open script containing the component call */
  35. $src_path = $_GET["src_path"];
  36. $src_line = intval($_GET["src_line"]);
  37. if(!$src_path || $src_line <= 0)
  38. {
  39. $strWarning .= GetMessage("comp_prop_err_param")."<br>";
  40. }
  41. else
  42. {
  43. $abs_path = $src_path;
  44. $f = $io->GetFile($abs_path);
  45. $filesrc = $f->GetContents();
  46. if(!$filesrc || $filesrc == "")
  47. $strWarning .= GetMessage("comp_prop_err_open")."<br>";
  48. }
  49. if($strWarning == "")
  50. {
  51. /* parse source file for PHP code */
  52. $arScripts = PHPParser::ParseFile($filesrc);
  53. /* identify the component by line number */
  54. $aComponents = array();
  55. foreach($arScripts as $script)
  56. {
  57. $nLineFrom = substr_count(mb_substr($filesrc, 0, $script[0]), "\n")+1;
  58. $nLineTo = substr_count(mb_substr($filesrc, 0, $script[1]), "\n")+1;
  59. if($nLineFrom <= $src_line && $nLineTo >= $src_line)
  60. $aComponents[] = $script;
  61. if($nLineTo > $src_line)
  62. break;
  63. }
  64. foreach($aComponents as $component)
  65. {
  66. $arRes = PHPParser::CheckForComponent($component[2]);
  67. if($arRes && $arRes["SCRIPT_NAME"] == $_GET["path"])
  68. {
  69. $arValues = $arRes["PARAMS"];
  70. $aComponent = $component;
  71. break;
  72. }
  73. }
  74. }
  75. if($aComponent === false)
  76. $strWarning .= GetMessage("comp_prop_err_comp")."<br>";
  77. } //$_SERVER["REQUEST_METHOD"] == "POST" && $_GET["action"] == "refresh"
  78. if($strWarning == "")
  79. {
  80. $arTemplate = CTemplates::GetByID($_GET["path"], $arValues, $_GET["template_id"]);
  81. /* save parameters to file */
  82. if($_SERVER["REQUEST_METHOD"] == "POST" && $_GET["action"] == "save" && $aComponent !== false && $arTemplate !== false)
  83. {
  84. if (!check_bitrix_sessid())
  85. {
  86. $strWarning .= GetMessage("comp_prop_err_save")."<br>";
  87. }
  88. else
  89. {
  90. $params = PHPParser::ReturnPHPStr($_POST, $arTemplate["PARAMS"]);
  91. if($params <> "")
  92. $code = "<"."?".($arRes["VARIABLE"]?$arRes["VARIABLE"]."=":"")."\$APPLICATION->IncludeFile(\"".$_GET["path"]."\", Array(\r\n\t".$params."\r\n\t)\r\n);?".">";
  93. else
  94. $code = "<"."?".($arRes["VARIABLE"]?$arRes["VARIABLE"]."=":"")."\$APPLICATION->IncludeFile(\"".$_GET["path"]."\");?".">";
  95. $filesrc_for_save = mb_substr($filesrc, 0, $aComponent[0]).$code.mb_substr($filesrc, $aComponent[1]);
  96. if($APPLICATION->SaveFileContent($abs_path, $filesrc_for_save))
  97. {
  98. $obJSPopup->Close();
  99. }
  100. else
  101. $strWarning .= GetMessage("comp_prop_err_save")."<br />";
  102. }
  103. }
  104. }
  105. if($arTemplate["ICON"] == "" || !is_file($_SERVER["DOCUMENT_ROOT"].$arTemplate["ICON"]))
  106. $arTemplate["ICON"] = "/bitrix/images/fileman/htmledit2/component.gif";
  107. $obJSPopup->StartDescription($arTemplate['ICON']);
  108. ?>
  109. <?if($arTemplate["NAME"] <> ""):?>
  110. <p title="<?echo GetMessage("comp_prop_name")?>"><b><?echo htmlspecialcharsbx($arTemplate["NAME"])?></b></p>
  111. <?endif;?>
  112. <?if($arTemplate["DESCRIPTION"] <> ""):?>
  113. <p title="<?echo GetMessage("comp_prop_desc")?>"><?echo htmlspecialcharsbx($arTemplate["DESCRIPTION"])?></p>
  114. <?endif;?>
  115. <p class="note" title="<?echo GetMessage("comp_prop_path")?>"><?echo htmlspecialcharsbx($arTemplate["REAL_PATH"]<>""? $arTemplate["REAL_PATH"]:$_GET["path"])?></p>
  116. <?
  117. if($strWarning <> "")
  118. //ShowError($strWarning);
  119. $obJSPopup->ShowValidationError($strWarning);
  120. ?>
  121. <?
  122. $obJSPopup->StartContent();
  123. if(!empty($arTemplate["PARAMS"])):
  124. ?>
  125. <table cellspacing="0" class="bx-width100">
  126. <?
  127. foreach($arTemplate["PARAMS"] as $ID=>$prop):
  128. ?>
  129. <tr>
  130. <td><?echo htmlspecialcharsbx($prop["NAME"]).":"?></td>
  131. <td>
  132. <?
  133. if(!array_key_exists($ID, $arValues) && isset($prop["DEFAULT"]))
  134. $arValues[$ID] = $prop["DEFAULT"];
  135. if($prop["MULTIPLE"]=='Y' && !is_array($arValues[$ID]))
  136. {
  137. if(isset($arValues[$ID]))
  138. $val = Array($arValues[$ID]);
  139. else
  140. $val = Array();
  141. }
  142. elseif($prop["TYPE"]=="LIST" && !is_array($arValues[$ID]))
  143. $val = Array($arValues[$ID]);
  144. else
  145. $val = $arValues[$ID];
  146. $res = "";
  147. if($prop["COLS"]<1)
  148. $prop["COLS"] = '30';
  149. if($prop["MULTIPLE"]=='Y')
  150. {
  151. $prop["CNT"] = intval($prop["CNT"]);
  152. if($prop["CNT"]<1)
  153. $prop["CNT"] = 1;
  154. }
  155. switch(mb_strtoupper($prop["TYPE"]))
  156. {
  157. case "LIST":
  158. $prop["SIZE"] = ($prop["MULTIPLE"] == 'Y' && intval($prop["SIZE"]) <= 1? '3' : $prop["SIZE"]);
  159. if(intval($prop["SIZE"]) <= 0)
  160. {
  161. $prop["SIZE"] = 1;
  162. }
  163. $res .= '<select name="'.$ID.($prop["MULTIPLE"] == "Y"? '[]' : '').'"'.
  164. ($prop["MULTIPLE"] == "Y"?
  165. ' multiple ' :
  166. ($prop['ADDITIONAL_VALUES'] !== 'N'?
  167. ' onChange="this.form.elements[\''.$ID.'_alt\'].disabled = (this.selectedIndex!=0);" '
  168. : '')
  169. ).
  170. ' size="'.$prop["SIZE"].'">';
  171. if(!is_array($prop["VALUES"]))
  172. {
  173. $prop["VALUES"] = Array();
  174. }
  175. $tmp = '';
  176. $bFound = false;
  177. foreach($prop["VALUES"] as $v_id => $v_name)
  178. {
  179. $key = array_search($v_id, $val);
  180. if($key === FALSE || $key === NULL)
  181. {
  182. $tmp .= '<option value="'.htmlspecialcharsbx($v_id).'">'.htmlspecialcharsbx($v_name).'</option>';
  183. }
  184. else
  185. {
  186. unset($val[$key]);
  187. $bFound = true;
  188. $tmp .= '<option value="'.htmlspecialcharsbx($v_id).'" selected>'.htmlspecialcharsbx($v_name).'</option>';
  189. }
  190. }
  191. if($prop['ADDITIONAL_VALUES'] !== 'N')
  192. {
  193. $res .= '<option value=""'.(!$bFound? ' selected' : '').'>'.($prop["MULTIPLE"] == "Y"? GetMessage("comp_prop_not_sel") : GetMessage("comp_prop_other").' -&gt;').'</option>';
  194. }
  195. $res .= $tmp;
  196. $res .= '</select>';
  197. if($prop['ADDITIONAL_VALUES'] !== 'N')
  198. {
  199. if($prop["MULTIPLE"] == 'Y')
  200. {
  201. reset($val);
  202. foreach($val as $v)
  203. {
  204. $res .= '<br>';
  205. if($prop['ROWS'] > 1)
  206. {
  207. $res .= '<textarea name="'.$ID.'[]" cols='.$prop["COLS"].'>'.htmlspecialcharsbx($v).'</textarea>';
  208. }
  209. else
  210. {
  211. $res .= '<input type="text" name="'.$ID.'[]" size='.$prop["COLS"].' value="'.htmlspecialcharsbx($v).'">';
  212. }
  213. }
  214. for($i = 0; $i < $prop["CNT"]; $i++)
  215. {
  216. $res .= '<br>';
  217. if($prop['ROWS'] > 1)
  218. {
  219. $res .= '<textarea name="'.$ID.'[]" cols='.$prop["COLS"].'></textarea>';
  220. }
  221. else
  222. {
  223. $res .= '<input type="text" name="'.$ID.'[]" size='.$prop["COLS"].' value="">';
  224. }
  225. }
  226. $res .= '<input type="button" value="+" onClick="var span = document.createElement(\'SPAN\'); this.parentNode.insertBefore(span, this); span.innerHTML=\''.
  227. '<br>';
  228. if($prop['ROWS'] > 1)
  229. {
  230. $res .= '<textarea name=\\\''.$ID.'[]\\\' cols=\\\''.$prop["COLS"].'\\\'></textarea>';
  231. }
  232. else
  233. {
  234. $res .= '<input type=\\\'text\\\' name=\\\''.$ID.'[]\\\' size=\\\''.$prop["COLS"].'\\\'>';
  235. }
  236. $res .= '\'">';
  237. }
  238. else
  239. {
  240. $res .= '<br>';
  241. if($prop['ROWS'] > 1)
  242. {
  243. $res .= '<textarea name="'.$ID.'_alt" '.($bFound? ' disabled ' : '').' cols='.$prop["COLS"].'>'.htmlspecialcharsbx(count($val) > 0? $val[0] : '').'</textarea>';
  244. }
  245. else
  246. {
  247. $res .= '<input type="text" name="'.$ID.'_alt" '.($bFound? ' disabled ' : '').'size='.$prop["COLS"].' value="'.htmlspecialcharsbx(count($val) > 0? $val[0] : '').'">';
  248. }
  249. }
  250. }
  251. break;
  252. default:
  253. if($prop["MULTIPLE"] == 'Y')
  254. {
  255. $bBr = false;
  256. foreach($val as $v)
  257. {
  258. if($bBr)
  259. {
  260. $res .= '<br>';
  261. }
  262. else
  263. {
  264. $bBr = true;
  265. }
  266. if($prop['ROWS'] > 1)
  267. {
  268. $res .= '<textarea name="'.$ID.'[]" cols='.$prop["COLS"].'>'.htmlspecialcharsbx($v).'</textarea>';
  269. }
  270. else
  271. {
  272. $res .= '<input type="text" name="'.$ID.'[]" size='.$prop["COLS"].' value="'.htmlspecialcharsbx($v).'">';
  273. }
  274. }
  275. for($i = 0; $i < $prop["CNT"]; $i++)
  276. {
  277. if($bBr)
  278. {
  279. $res .= '<br>';
  280. }
  281. else
  282. {
  283. $bBr = true;
  284. }
  285. if($prop['ROWS'] > 1)
  286. {
  287. $res .= '<textarea name="'.$ID.'[]" cols='.$prop["COLS"].'></textarea>';
  288. }
  289. else
  290. {
  291. $res .= '<input type="text" name="'.$ID.'[]" size='.$prop["COLS"].' value="">';
  292. }
  293. }
  294. $res .= '<input type="button" value="+" onClick="var span = document.createElement(\'SPAN\'); this.parentNode.insertBefore(span, this); span.innerHTML=\''.
  295. '<br>';
  296. if($prop['ROWS'] > 1)
  297. {
  298. $res .= '<textarea name=\\\''.$ID.'[]\\\' cols=\\\''.$prop["COLS"].'\\\'></textarea>';
  299. }
  300. else
  301. {
  302. $res .= '<input type=\\\'text\\\' name=\\\''.$ID.'[]\\\' size=\\\''.$prop["COLS"].'\\\'>';
  303. }
  304. $res .= '\'">';
  305. }
  306. else
  307. {
  308. if($prop['ROWS'] > 1)
  309. {
  310. $res .= '<textarea name="'.$ID.'" cols='.$prop["COLS"].'>'.htmlspecialcharsbx($val).'</textarea>';
  311. }
  312. else
  313. {
  314. $res .= '<input name="'.$ID.'" size='.$prop["COLS"].' value="'.htmlspecialcharsbx($val).'" type="text">';
  315. }
  316. }
  317. break;
  318. }
  319. if($prop["REFRESH"]=="Y")
  320. $res .= '<input type="button" value="OK" onclick="'.$obJSPopup->jsPopup.'.PostParameters(\''.
  321. 'path='.urlencode(CUtil::addslashes($_GET["path"])).
  322. '&amp;template_id='.urlencode(CUtil::addslashes($_GET["template_id"])).
  323. '&amp;lang='.LANGUAGE_ID.
  324. '&amp;src_path='.urlencode(CUtil::addslashes($_GET["src_path"])).
  325. '&amp;src_line='.intval($_GET["src_line"]).
  326. '&amp;action=refresh\');">';
  327. echo $res;
  328. ?>
  329. </td>
  330. </tr>
  331. <?endforeach?>
  332. </table>
  333. <?
  334. $obJSPopup->StartButtons();
  335. echo '<input id="btn_popup_save" name="btn_popup_save" type="button" value="'.GetMessage("JSPOPUP_SAVE_CAPTION").'" onclick="'.$obJSPopup->jsPopup.'.PostParameters(\'action=save\');" title="'.GetMessage("JSPOPUP_SAVE_CAPTION").'" />'."\r\n";
  336. $obJSPopup->ShowStandardButtons(array('close'));
  337. else: //!empty($arTemplate["PARAMS"])
  338. $obJSPopup->ShowStandardButtons(array('close'));
  339. endif; //!empty($arTemplate["PARAMS"])
  340. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin_js.php");
  341. ?>