1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
template_copy.php
См. документацию.
1<?php
8
14require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
15require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_js.php");
16
18$src_path = $io->CombinePath("/", $_GET["src_path"]);
19$src_line = intval($_GET["src_line"]);
20$template_site_template = $_GET["template_site_template"];
21
22if(!$USER->CanDoOperation('edit_php') && !$USER->CanDoFileOperation('fm_lpa', array($_GET["src_site"], $src_path)))
23 die(GetMessage("ACCESS_DENIED"));
24
25IncludeModuleLangFile(__FILE__);
26
28 array(
29 'TITLE' => GetMessage("template_copy_title"),
30 'ARGS' => 'component_name='.urlencode($_GET["component_name"]).
31 '&amp;component_template='.urlencode($_GET["component_template"]).
32 '&amp;template_id='.urlencode($_GET["template_id"]).
33 '&amp;lang='.urlencode(LANGUAGE_ID).
34 '&amp;template_site_template='.urlencode($template_site_template).
35 '&amp;src_path='.urlencode($_GET["src_path"]).
36 '&amp;src_line='.intval($_GET["src_line"]).
37 '&amp;src_site='.intval($_GET["src_site"]).
38 '&amp;edit_file='.urlencode($_GET["edit_file"]).
39 '&amp;back_path='.urlencode($_GET["back_path"]).
40 '&amp;action=save'
41 )
42);
43
49
50// try to read parameters from script file
51
52/* Try to open script containing the component call */
53if(!$src_path || $src_line <= 0)
54{
55 $strWarning .= GetMessage("comp_prop_err_param")."<br>";
56}
57else
58{
59 $abs_path = $io->RelativeToAbsolutePath($src_path);
60 $f = $io->GetFile($abs_path);
61 $filesrc = $f->GetContents();
62
63 if(!$filesrc || $filesrc == "")
64 $strWarning .= GetMessage("comp_prop_err_open")."<br>";
65}
66
68if($strWarning == "")
69{
70 /* parse source file for PHP code */
71 $arComponents = PHPParser::ParseScript($filesrc);
72
73 /* identify the component by line number */
74 for ($i = 0, $cnt = count($arComponents); $i < $cnt; $i++)
75 {
76 $nLineFrom = substr_count(mb_substr($filesrc, 0, $arComponents[$i]["START"]), "\n") + 1;
77 $nLineTo = substr_count(mb_substr($filesrc, 0, $arComponents[$i]["END"]), "\n") + 1;
78
79 if ($nLineFrom <= $src_line && $nLineTo >= $src_line)
80 {
81 if ($arComponents[$i]["DATA"]["COMPONENT_NAME"] == $_GET["component_name"])
82 {
83 $arComponent = $arComponents[$i];
84 break;
85 }
86 }
87 if ($nLineTo > $src_line)
88 break;
89 }
90}
91
92if ($arComponent === false)
93 $strWarning .= GetMessage("comp_prop_err_comp")."<br>";
94
98
99if($strWarning == "")
100{
102
103 $arTemplatesList = CComponentUtil::GetTemplatesList($_GET["component_name"], $_GET["template_id"]);
104 for ($i = 0, $cnt = count($arTemplatesList); $i < $cnt; $i++)
105 {
106 if($arComponent["DATA"]["TEMPLATE_NAME"]<>"" && $arTemplatesList[$i]["NAME"] == $arComponent["DATA"]["TEMPLATE_NAME"]
107 || $arComponent["DATA"]["TEMPLATE_NAME"]=="" && $arTemplatesList[$i]["NAME"] == ".default")
108 {
110 break;
111 }
112 }
113
114 /* save parameters to file */
115 if($_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["action"] == "save" && $arComponent !== false && $arComponentDescription !== false && check_bitrix_sessid())
116 {
117 //check template name
118 $sTemplateName = trim($_POST["TEMPLATE_NAME"]);
119 if($sTemplateName == '' || !CBitrixComponentTemplate::CheckName($sTemplateName))
120 $sTemplateName = '.default';
121
122 if ($_POST["SITE_TEMPLATE"] != $_GET["template_id"] && $_POST["SITE_TEMPLATE"] != ".default")
123 $_POST["USE_TEMPLATE"] = "N";
124
125 if (CComponentUtil::CopyTemplate($arComponent["DATA"]["COMPONENT_NAME"], $arComponent["DATA"]["TEMPLATE_NAME"], (($templateSiteTemplate <> '') ? $templateSiteTemplate : false), $_POST["SITE_TEMPLATE"], $sTemplateName, false))
126 {
127 if (isset($_POST["USE_TEMPLATE"]) && $_POST["USE_TEMPLATE"] == "Y")
128 {
129 $code = PHPParser::buildComponentCode($arComponent, $sTemplateName);
130
131 $filesrc_for_save = mb_substr($filesrc, 0, $arComponent["START"]).$code.mb_substr($filesrc, $arComponent["END"]);
132
133 if(!$APPLICATION->SaveFileContent($abs_path, $filesrc_for_save))
134 $strWarning .= GetMessage("comp_prop_err_save")."<br>";
135 }
136
137 if($strWarning == "")
138 {
139 $strJSText = 'window.location = window.location.href;';
140
141 if (isset($_POST["EDIT_TEMPLATE"]) && $_POST["EDIT_TEMPLATE"] == "Y")
142 {
143 $component = new CBitrixComponent();
144 if ($component->InitComponent($arComponent["DATA"]["COMPONENT_NAME"], $_POST["TEMPLATE_NAME"]))
145 {
146 if ($component->InitComponentTemplate($_REQUEST["edit_file"], $_POST["SITE_TEMPLATE"]))
147 {
148 $template = $component->GetTemplate();
149 if (!is_null($template))
150 {
151 $strJSText = $APPLICATION->GetPopupLink(
152 array(
153 'URL' => '/bitrix/admin/public_file_edit_src.php?lang='.LANGUAGE_ID.'&site='.SITE_ID.'&back_url='.urlencode($_REQUEST["back_path"]).'&path='.urlencode($template->GetFile()),
154 "PARAMS" => Array("width" => 770, "height" => 570,"resize" => true,"dialog_type" => 'EDITOR', "min_width" => 700, "min_height" => 400),
155 )
156 );
157 }
158 }
159 }
160 }
161?>
162<script>
163<?=$obJSPopup->jsPopup?>.Close();
164//setTimeout(BX.showWait(), 30);
165
166<?=$strJSText?>
167</script>
168<?
169 die();
170 }
171 }
172 else
173 {
174 if ($ex = $APPLICATION->GetException())
175 $strWarning .= $ex->GetString()."<br>";
176 else
177 $strWarning .= GetMessage("comp_templ_error_copy")."<br>";
178 }
179 }
180}
181
182$componentPath = CComponentEngine::MakeComponentPath($_GET["component_name"]);
185if($localPath !== false && $arComponentDescription["ICON"] <> "" && $io->FileExists($io->RelativeToAbsolutePath($localPath."/".$arComponentDescription["ICON"])))
187else
188 $sIcon = "/bitrix/images/fileman/htmledit2/component.gif";
189
190$sCurrentTemplateName = ($arComponent["DATA"]["TEMPLATE_NAME"] <> ""? htmlspecialcharsbx($arComponent["DATA"]["TEMPLATE_NAME"]) : ".default");
191
192$obJSPopup->ShowTitlebar();
193$obJSPopup->StartDescription($sIcon);
194?>
195<?if($arComponentDescription["NAME"] <> ""):?>
196<p title="<?echo GetMessage("comp_prop_name")?>"><b><?echo htmlspecialcharsbx($arComponentDescription["NAME"])?></b></p>
197<?endif;?>
198<?if($arComponentDescription["DESCRIPTION"] <> ""):?>
199<p title="<?echo GetMessage("comp_prop_desc")?>"><?echo htmlspecialcharsbx($arComponentDescription["DESCRIPTION"])?></p>
200<?endif;?>
201<p class="note" title="<?echo GetMessage("comp_prop_path")?>"><a href="/bitrix/admin/fileman_admin.php?lang=<?echo LANGUAGE_ID?>&amp;path=<?echo urlencode($localPath)?>"><?echo htmlspecialcharsbx($_GET["component_name"])?></a></p>
202<?
203if (isset($_GET['system_template']) && $_GET['system_template'] == 'Y')
204 ShowNote(GetMessage("copy_comp_sys_templ"));
205
206if($strWarning <> "")
207{
208 //ShowError($strWarning);
209 $obJSPopup->ShowValidationError($strWarning);
210 echo '<script>jsPopup.AdjustShadow()</script>';
211}
212?>
213
214<?
215$obJSPopup->StartContent();
216?>
217<input type="hidden" name="action" value="save" />
218<script>
219window.CheckSiteTemplate = function(el)
220{
221 var bList = (el.id == 'SITE_TEMPLATE_sel');
222 if(el.form.USE_TEMPLATE)
223 {
224 el.form.USE_TEMPLATE.disabled = bList;
225 el.form.USE_TEMPLATE.checked = !bList;
226 }
227 el.form.SITE_TEMPLATE[el.form.SITE_TEMPLATE.length-1].disabled = !bList;
228}
229</script>
230<table cellspacing="0" class="bx-width100">
231 <tr>
232 <td class="bx-popup-label bx-width50"><?= GetMessage("comp_templ_cur_template") ?>:</td>
233 <td><b><?=$sCurrentTemplateName?></b><?if($templateSiteTemplate==""):?> (<?echo GetMessage("comp_templ_system")?>)<?endif?></td>
234 </tr>
235<?
236$arSiteTemplates = array(".default"=>GetMessage("comp_templ_def_templ"));
237$db_site_templates = CSiteTemplate::GetList(array("sort"=>"asc", "name"=>"asc"), array(), array());
238while($ar_site_templates = $db_site_templates->Fetch())
239 $arSiteTemplates[$ar_site_templates['ID']] = $ar_site_templates['NAME'];
240
242 $sSiteTemplate = $arSiteTemplates[$templateSiteTemplate];
243?>
244 <tr>
245 <td class="bx-popup-label bx-width50"><?= GetMessage("comp_templ_cur_site_template")?>:</td>
246 <td><b><?= htmlspecialcharsbx($templateSiteTemplate)?></b><?if($sSiteTemplate <> "") echo " (".htmlspecialcharsbx($sSiteTemplate).")"?></td>
247 </tr>
248<?
249endif;
250?>
251 <tr>
252 <td class="bx-popup-label bx-width50"><?= GetMessage("comp_templ_new_tpl") ?>:</td>
253 <td>
254<?
255$sParentComp = mb_strtolower($arComponent["DATA"]["PARENT_COMP"]);
256$bParentComp = ($sParentComp <> "" && $sParentComp !== "false" && $sParentComp !== "null");
257if(!$bParentComp):
258 //find next template name
259 $def = ($arComponent["DATA"]["TEMPLATE_NAME"] <> '' && $arComponent["DATA"]["TEMPLATE_NAME"]<>".default"? rtrim($arComponent["DATA"]["TEMPLATE_NAME"], "0..9") : "template");
260 if($def == '')
261 $def = "template";
262 $max = 0;
263 foreach($arTemplatesList as $templ)
264 if(mb_strpos($templ["NAME"], $def) === 0 && ($v = intval(mb_substr($templ["NAME"], mb_strlen($def))))>$max)
265 $max = $v;
266?>
267 <input type="text" name="TEMPLATE_NAME" value="<?echo (!empty($_REQUEST["TEMPLATE_NAME"]) ? htmlspecialcharsbx($_REQUEST["TEMPLATE_NAME"]) : htmlspecialcharsbx($def).($max+1)); ?>">
268<?else:?>
269 <?echo $sCurrentTemplateName?>
270 <input type="hidden" name="TEMPLATE_NAME" value="<?echo $sCurrentTemplateName?>">
271<?endif;?>
272 </td>
273 </tr>
274 <tr>
275 <td class="bx-popup-label bx-width50" valign="top"><?= GetMessage("comp_templ_new_template") ?>:</td>
276 <td>
277<input type="radio" name="SITE_TEMPLATE" value=".default" id="SITE_TEMPLATE_def"<?if(empty($_REQUEST["SITE_TEMPLATE"]) || $_REQUEST["SITE_TEMPLATE"] == ".default") echo " checked"?> onclick="CheckSiteTemplate(this)"><label for="SITE_TEMPLATE_def"><?echo GetMessage("template_copy_def")?> / .default (<?echo GetMessage("comp_templ_def_templ")?>)</label><br>
278<?if($_GET["template_id"] <> "" && $_GET["template_id"] <> ".default"):?>
279<input type="radio" name="SITE_TEMPLATE" value="<?echo htmlspecialcharsbx($_GET["template_id"])?>" id="SITE_TEMPLATE_cur"<?if(isset($_REQUEST["SITE_TEMPLATE"]) && $_REQUEST["SITE_TEMPLATE"] == $_GET["template_id"]) echo " checked"?> onclick="CheckSiteTemplate(this)"><label for="SITE_TEMPLATE_cur"><?echo GetMessage("template_copy_cur")?> / <?echo htmlspecialcharsbx($_GET["template_id"])?><?if($arSiteTemplates[$_GET["template_id"]] <> '') echo " (".$arSiteTemplates[$_GET["template_id"]].")"?></label><br>
280<?endif?>
281<?
282$bList = (!empty($_REQUEST["SITE_TEMPLATE"]) && $_REQUEST["SITE_TEMPLATE"] <> $_GET["template_id"] && $_REQUEST["SITE_TEMPLATE"] <> ".default")
283?>
284<input type="radio" name="SITE_TEMPLATE" value="" id="SITE_TEMPLATE_sel"<?if($bList) echo " checked"?> onclick="CheckSiteTemplate(this)"><label for="SITE_TEMPLATE_sel"><?echo GetMessage("template_copy_sel")?></label>
285 <select name="SITE_TEMPLATE"<?if(!$bList) echo " disabled"?>>
286 <?
287 foreach($arSiteTemplates as $templ_id=>$templ_name):
288 if($templ_id == ".default" || $templ_id == $_GET["template_id"])
289 continue;
290 ?>
291 <option value="<?= htmlspecialcharsbx($templ_id) ?>"<?if ((!empty($_REQUEST["SITE_TEMPLATE"]) && $_REQUEST["SITE_TEMPLATE"] == $templ_id) || (empty($_REQUEST["SITE_TEMPLATE"]) && $templ_id == $template_site_template)) echo " selected";?>><?= htmlspecialcharsbx($templ_id." (".$templ_name.")") ?></option>
293 </select>
294 </td>
295 </tr>
296<?if(!$bParentComp):?>
297 <tr>
298 <td class="bx-popup-label bx-width50"><?= GetMessage("comp_templ_use") ?>:</td>
299 <td>
300 <input type="checkbox" name="USE_TEMPLATE" value="Y"<?if (!(isset($_REQUEST["action"]) && $_REQUEST["action"] == "save" && $_REQUEST["USE_TEMPLATE"] <> "Y")) echo " checked";?><?if($bList) echo " disabled"?>>
301 </td>
302 </tr>
303<?endif?>
304<?if($USER->CanDoOperation('edit_php')):?>
305 <tr>
306 <td class="bx-popup-label bx-width50"><?= GetMessage("comp_templ_edit") ?>:</td>
307 <td>
308 <input type="checkbox" name="EDIT_TEMPLATE" value="Y"<?if (!(isset($_REQUEST["action"]) && $_REQUEST["action"] == "save" && $_REQUEST["EDIT_TEMPLATE"] <> "Y")) echo " checked";?>>
309 </td>
310 </tr>
311<?endif?>
312</table>
313
314<?
315$obJSPopup->ShowStandardButtons();
316
317require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin_js.php");
318?>
return select
Определения access_edit.php:440
global $APPLICATION
Определения include.php:80
if($canUseYandexMarket) $strWarning
Определения options.php:74
static GetInstance()
Определения virtual_io.php:60
static GetComponentDescr($componentName)
Определения component_util.php:402
static GetTemplatesList($componentName, $currentTemplate=false)
Определения component_util.php:1024
static CopyTemplate($componentName, $templateName, $siteTemplate, $newSiteTemplate, $newName=false, $bRewrite=false)
Определения component_util.php:1227
Определения jspopup.php:10
static GetList($arOrder=array(), $arFilter=array(), $arSelect=false)
Определения site_template.php:13
static ParseScript($scriptContent)
Определения php_parser.php:332
if( $strWarning=="") if($strWarning=="") $componentPath
Определения component_props2.php:197
$abs_path
Определения component_props2.php:76
$src_path
Определения component_props2.php:37
$arComponentDescription
Определения component_props2.php:73
$arComponent
Определения component_props2.php:72
$arTemplate
Определения component_props.php:26
$f
Определения component_props.php:52
$src_line
Определения component_props.php:43
$filesrc
Определения component_props.php:53
$aComponent
Определения component_props.php:27
$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
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $USER
Определения csv_new_run.php:40
$io
Определения csv_new_run.php:98
endif
Определения csv_new_setup.php:990
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
check_bitrix_sessid($varname='sessid')
Определения tools.php:4686
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
getLocalPath($path, $baseFolder="/bitrix")
Определения tools.php:5092
ShowNote($strNote, $cls="notetext")
Определения tools.php:4477
global_menu_<?echo $menu["menu_id"]?> adm main menu item icon adm main menu item text text adm main menu hover adm submenu menucontainer menu_id menu_id items_id items_id desktop menu_id block none adm global submenu<?=($subMenuDisplay=="block" ? " adm-global-submenu-active" :"")?> global_submenu_<?echo $menu["menu_id"]?> text MAIN_PR_ADMIN_FAV items adm submenu items wrap adm submenu items stretch wrap BX adminMenu itemsStretchScroll()"> <table class if (!empty( $menu["items"])) elseif ( $menu[ 'menu_id']=='desktop') if ( $menu[ 'menu_id']=='desktop') endforeach
Определения prolog_main_admin.php:255
<? endif;?> window document title
Определения prolog_main_admin.php:76
die
Определения quickway.php:367
$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
$obJSPopup
Определения settings_admin_form.php:102
const SITE_ID
Определения sonet_set_content_view.php:12
$sCurrentTemplateName
Определения template_copy.php:190
$db_site_templates
Определения template_copy.php:237
foreach($arTemplatesList as $templ) if(mb_strpos($templ["NAME"] $def
Определения template_copy.php:264
else $sIcon
Определения template_copy.php:188
$templateSiteTemplate
Определения template_copy.php:97
$bParentComp
Определения template_copy.php:256
$strWarning
Определения template_copy.php:44
$template_site_template
Определения template_copy.php:20
$max
Определения template_copy.php:262
$sParentComp
Определения template_copy.php:255
$arTemplatesList
Определения template_copy.php:96
$localPath
Определения template_copy.php:184