1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
site_template.php
См. документацию.
1<?php
8
10{
12
13 public static function GetList($arOrder=array(), $arFilter=array(), $arSelect=false)
14 {
16 global $APPLICATION;
17
18 if(isset($arFilter["ID"]) && !is_array($arFilter["ID"]))
19 $arFilter["ID"] = array($arFilter["ID"]);
20 if(isset($arFilter["TYPE"]) && !is_array($arFilter["TYPE"]))
21 $arFilter["TYPE"] = array($arFilter["TYPE"]);
22
23 $folders = array(
24 "/local/templates",
25 BX_PERSONAL_ROOT."/templates",
26 );
27 $arRes = array();
28 foreach($folders as $folder)
29 {
30 $path = $_SERVER["DOCUMENT_ROOT"].$folder;
31 if(is_dir($path))
32 {
33 $handle = opendir($path);
34 if($handle)
35 {
36 while(($file = readdir($handle)) !== false)
37 {
38 if($file == "." || $file == ".." || !is_dir($path."/".$file))
39 continue;
40
41 if($file == ".default")
42 continue;
43
44 if(isset($arRes[$file]))
45 continue;
46
47 if(isset($arFilter["ID"]) && !in_array($file, $arFilter["ID"]))
48 continue;
49
50 $arTemplate = array("DESCRIPTION" => "");
51
52 $fname = $path."/".$file."/description.php";
53 if(file_exists(($fname)))
54 {
56 include($fname);
57 }
58
59 if(!isset($arTemplate["TYPE"])) $arTemplate["TYPE"] = '';
60 if(isset($arFilter["TYPE"]) && !in_array($arTemplate["TYPE"], $arFilter["TYPE"]))
61 continue;
62
63 $arTemplate["ID"] = $file;
64 $arTemplate["PATH"] = $folder."/".$file;
65
66 if(!isset($arTemplate["NAME"]))
67 $arTemplate["NAME"] = $file;
68
69 if($arSelect === false || in_array("SCREENSHOT", $arSelect))
70 {
71 if(file_exists($path."/".$file."/lang/".LANGUAGE_ID."/screen.gif"))
72 $arTemplate["SCREENSHOT"] = $folder."/".$file."/lang/".LANGUAGE_ID."/screen.gif";
73 elseif(file_exists($path."/".$file."/screen.gif"))
74 $arTemplate["SCREENSHOT"] = $folder."/".$file."/screen.gif";
75 else
76 $arTemplate["SCREENSHOT"] = false;
77
78 if(file_exists($path."/".$file."/lang/".LANGUAGE_ID."/preview.gif"))
79 $arTemplate["PREVIEW"] = $folder."/".$file."/lang/".LANGUAGE_ID."/preview.gif";
80 elseif(file_exists($path."/".$file."/preview.gif"))
81 $arTemplate["PREVIEW"] = $folder."/".$file."/preview.gif";
82 else
83 $arTemplate["PREVIEW"] = false;
84 }
85
86 if($arSelect === false || in_array("CONTENT", $arSelect))
87 {
88 $arTemplate["CONTENT"] = $APPLICATION->GetFileContent($path."/".$file."/header.php")."#WORK_AREA#".$APPLICATION->GetFileContent($path."/".$file."/footer.php");
89 }
90
91 if($arSelect === false || in_array("STYLES", $arSelect))
92 {
93 if(file_exists($path."/".$file."/styles.css"))
94 {
95 $arTemplate["STYLES"] = $APPLICATION->GetFileContent($path."/".$file."/styles.css");
96 $arTemplate["STYLES_TITLE"] = CSiteTemplate::__GetByStylesTitle($path."/".$file."/.styles.php");
97 }
98
99 if(file_exists($path."/".$file."/template_styles.css"))
100 $arTemplate["TEMPLATE_STYLES"] = $APPLICATION->GetFileContent($path."/".$file."/template_styles.css");
101 }
102
103 $arRes[$file] = $arTemplate;
104 }
105 closedir($handle);
106 }
107 }
108 }
109
110 if(is_array($arOrder))
111 {
112 $columns = array();
113 static $fields = array("ID"=>1, "NAME"=>1, "DESCRIPTION"=>1, "SORT"=>1);
114 foreach($arOrder as $key => $val)
115 {
116 $key = mb_strtoupper($key);
117 if(isset($fields[$key]))
118 {
119 $columns[$key] = (mb_strtoupper($val) == "DESC"? SORT_DESC : SORT_ASC);
120 }
121 }
122 if(!empty($columns))
123 {
125 }
126 }
127
128 $db_res = new CDBResult;
129 $db_res->InitFromArray($arRes);
130
131 return $db_res;
132 }
133
134 public static function __GetByStylesTitle($file)
135 {
137 if ($io->FileExists($file))
138 return include($file);
139 return false;
140 }
141
142 public static function GetByID($ID)
143 {
144 return CSiteTemplate::GetList(array(), array("ID"=>$ID));
145 }
146
147 public function CheckFields($arFields, $ID=false)
148 {
150 global $APPLICATION;
151
152 $this->LAST_ERROR = "";
153 $arMsg = array();
154
155 if($ID === false)
156 {
157 if($arFields["ID"] == '')
158 $this->LAST_ERROR .= GetMessage("MAIN_ENTER_TEMPLATE_ID")." ";
159 elseif(file_exists($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$arFields["ID"]))
160 $this->LAST_ERROR .= GetMessage("MAIN_TEMPLATE_ID_EX")." ";
161
162 if(!isset($arFields["CONTENT"]))
163 $this->LAST_ERROR .= GetMessage("MAIN_TEMPLATE_CONTENT_NA")." ";
164 }
165
166 if(isset($arFields["CONTENT"]) && $arFields["CONTENT"] == '')
167 {
168 $this->LAST_ERROR .= GetMessage("MAIN_TEMPLATE_CONTENT_NA")." ";
169 $arMsg[] = array("id"=>"CONTENT", "text"=> GetMessage("MAIN_TEMPLATE_CONTENT_NA"));
170 }
171 elseif(isset($arFields["CONTENT"]) && !str_contains($arFields["CONTENT"], "#WORK_AREA#"))
172 {
173 $this->LAST_ERROR .= GetMessage("MAIN_TEMPLATE_WORKAREA_NA")." ";
174 $arMsg[] = array("id"=>"CONTENT", "text"=> GetMessage("MAIN_TEMPLATE_WORKAREA_NA"));
175 }
176
177 if(!empty($arMsg))
178 {
179 $e = new CAdminException($arMsg);
180 $APPLICATION->ThrowException($e);
181 }
182
183 if($this->LAST_ERROR <> '')
184 return false;
185
186 return true;
187 }
188
189 public function Add($arFields)
190 {
191 if(!$this->CheckFields($arFields))
192 return false;
193
195 global $APPLICATION;
196
197 $path = BX_PERSONAL_ROOT."/templates/".$arFields["ID"];
198 CheckDirPath($_SERVER["DOCUMENT_ROOT"].$path);
199
200 if(isset($arFields["CONTENT"]))
201 {
202 $p = mb_strpos($arFields["CONTENT"], "#WORK_AREA#");
203 $header = mb_substr($arFields["CONTENT"], 0, $p);
204 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/header.php", $header);
205 $footer = mb_substr($arFields["CONTENT"], $p + mb_strlen("#WORK_AREA#"));
206 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/footer.php", $footer);
207 }
208 if(isset($arFields["STYLES"]))
209 {
210 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/styles.css", $arFields["STYLES"]);
211 }
212
213 if(isset($arFields["TEMPLATE_STYLES"]))
214 {
215 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/template_styles.css", $arFields["TEMPLATE_STYLES"]);
216 }
217
218 if(isset($arFields["NAME"]) || isset($arFields["DESCRIPTION"]) || isset($arFields["SORT"]))
219 {
220 self::SaveDescription($arFields, $_SERVER["DOCUMENT_ROOT"].$path."/description.php");
221 }
222
223 self::SaveStyleDescription($arFields["STYLES_DESCRIPTION"], $_SERVER["DOCUMENT_ROOT"].$path."/.styles.php");
224
225 return $arFields["ID"];
226 }
227
228
229 public function Update($ID, $arFields)
230 {
232 global $APPLICATION;
233
234 if(!$this->CheckFields($arFields, $ID))
235 {
236 return false;
237 }
238
239 $path = getLocalPath("templates/".$ID, BX_PERSONAL_ROOT);
240 if($path === false)
241 {
242 return false;
243 }
244 if(isset($arFields["CONTENT"]))
245 {
246 $p = mb_strpos($arFields["CONTENT"], "#WORK_AREA#");
247 $header = mb_substr($arFields["CONTENT"], 0, $p);
248 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/header.php", $header);
249 $footer = mb_substr($arFields["CONTENT"], $p + mb_strlen("#WORK_AREA#"));
250 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/footer.php", $footer);
251 }
252 if(isset($arFields["STYLES"]))
253 {
254 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/styles.css", $arFields["STYLES"]);
255 }
256
257 if(isset($arFields["TEMPLATE_STYLES"]))
258 {
259 $APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"].$path."/template_styles.css", $arFields["TEMPLATE_STYLES"]);
260 }
261
262 if(isset($arFields["NAME"]) || isset($arFields["DESCRIPTION"]) || isset($arFields["SORT"]) || isset($arFields["TYPE"]))
263 {
264 $db_t = CSiteTemplate::GetList(array(), array("ID" => $ID), array("NAME", "DESCRIPTION", "SORT"));
265 $ar_t = $db_t->Fetch();
266
267 if(!isset($arFields["NAME"]))
268 $arFields["NAME"] = $ar_t["NAME"];
269 if(!isset($arFields["DESCRIPTION"]))
270 $arFields["DESCRIPTION"] = $ar_t["DESCRIPTION"];
271 if(!isset($arFields["SORT"]))
272 $arFields["SORT"] = $ar_t["SORT"];
273 if(!isset($arFields["TYPE"]))
274 $arFields["TYPE"] = $ar_t["TYPE"];
275 if(!isset($arFields["EDITOR_STYLES"]))
276 $arFields["EDITOR_STYLES"] = $ar_t["EDITOR_STYLES"];
277
278 self::SaveDescription($arFields, $_SERVER["DOCUMENT_ROOT"].$path."/description.php");
279 }
280
281 self::SaveStyleDescription($arFields["STYLES_DESCRIPTION"], $_SERVER["DOCUMENT_ROOT"].$path."/.styles.php");
282
283 return true;
284 }
285
286 public static function Delete($ID)
287 {
288 if($ID == ".default")
289 {
290 return false;
291 }
292
293 $path = getLocalPath("templates/".$ID, BX_PERSONAL_ROOT);
294 if($path === false)
295 {
296 return false;
297 }
298
300 return true;
301 }
302
303 public static function GetContent($ID)
304 {
305 if($ID == '')
306 $arRes = array();
307 else
309 $db_res = new CDBResult;
310 $db_res->InitFromArray($arRes);
311 return $db_res;
312 }
313
314 public static function DirsRecursive($ID, $path="", $depth=0, $maxDepth=1)
315 {
316 $arRes = array();
317 $depth++;
318
319 $templPath = getLocalPath("templates/".$ID, BX_PERSONAL_ROOT);
320 if($templPath === false)
321 {
322 return $arRes;
323 }
324
325 GetDirList($templPath."/".$path, $arDirsTmp, $arResTmp);
326
327 foreach($arResTmp as $file)
328 {
329 switch($file["NAME"])
330 {
331 case "chain_template.php":
332 $file["DESCRIPTION"] = GetMessage("MAIN_TEMPLATE_NAV");
333 break;
334 case "":
335 $file["DESCRIPTION"] = "";
336 break;
337 default:
338 if(($p = mb_strpos($file["NAME"], ".menu_template.php"))!==false)
339 $file["DESCRIPTION"] = str_replace("#MENU_TYPE#", mb_substr($file["NAME"], 0, $p), GetMessage("MAIN_TEMPLATE_MENU"));
340 }
341 $arRes[] = $file;
342 }
343
344 $nTemplateLen = mb_strlen($templPath."/");
345 foreach($arDirsTmp as $dir)
346 {
347 $arDir = $dir;
348 $arDir["DEPTH_LEVEL"] = $depth;
349 $arRes[] = $arDir;
350
351 if($depth < $maxDepth)
352 {
353 $dirPath = mb_substr($arDir["ABS_PATH"], $nTemplateLen);
354 $arRes = array_merge($arRes, CSiteTemplate::DirsRecursive($ID, $dirPath, $depth, $maxDepth));
355 }
356 }
357 return $arRes;
358 }
359
360 public static function SaveStyleDescription($stylesDesc = array(), $stylesPath)
361 {
363 global $APPLICATION;
364
365 if(isset($stylesDesc) && is_array($stylesDesc))
366 {
367 $curStylesDesc = CSiteTemplate::__GetByStylesTitle($stylesPath);
368 if (is_array($curStylesDesc))
369 {
370 foreach($curStylesDesc as $code => $val)
371 {
372 if (!is_array($curStylesDesc[$code]))
373 unset($curStylesDesc[$code]);
374 }
375 }
376 foreach($stylesDesc as $code => $val)
377 {
378 if (!isset($curStylesDesc[EscapePHPString($code)]) || !is_array($curStylesDesc[EscapePHPString($code)]))
379 {
380 $curStylesDesc[EscapePHPString($code)] = EscapePHPString($val);
381 }
382 }
383 $APPLICATION->SaveFileContent($stylesPath, '<'.'?'."\nreturn ".var_export($curStylesDesc, 1).";\n".'?'.'>');
384 }
385 }
386
387 public static function SaveDescription($arFields = array(), $descPath)
388 {
390 global $APPLICATION;
391
392 $arDescription = array(
393 "NAME" => $arFields['NAME'],
394 "DESCRIPTION" => $arFields['DESCRIPTION'],
395 "SORT" => (intval($arFields['SORT']) > 0? intval($arFields['SORT']) : ''),
396 "TYPE" => $arFields['TYPE']
397 );
398 if (isset($arFields['EDITOR_STYLES']))
399 $arDescription["EDITOR_STYLES"] = $arFields['EDITOR_STYLES'];
400 $APPLICATION->SaveFileContent($descPath, '<'.'?'."\n\$arTemplate = ".var_export($arDescription, 1).";\n".'?'.'>');
401 }
402
403}
$path
Определения access_edit.php:21
$db_res
Определения options_user_settings.php:8
global $APPLICATION
Определения include.php:80
static loadLanguageFile($file, $language=null, $normalize=true)
Определения loc.php:225
static sortByColumn(array &$array, $columns, $callbacks='', $defaultValueIfNotSetValue=null, $preserveKeys=false)
Определения collection.php:24
static GetInstance()
Определения virtual_io.php:60
Определения site_template.php:10
CheckFields($arFields, $ID=false)
Определения site_template.php:147
static GetContent($ID)
Определения site_template.php:303
static Delete($ID)
Определения site_template.php:286
static GetList($arOrder=array(), $arFilter=array(), $arSelect=false)
Определения site_template.php:13
static SaveStyleDescription($stylesDesc=array(), $stylesPath)
Определения site_template.php:360
static SaveDescription($arFields=array(), $descPath)
Определения site_template.php:387
static GetByID($ID)
Определения site_template.php:142
static __GetByStylesTitle($file)
Определения site_template.php:134
static DirsRecursive($ID, $path="", $depth=0, $maxDepth=1)
Определения site_template.php:314
$LAST_ERROR
Определения site_template.php:11
Add($arFields)
Определения site_template.php:189
Update($ID, $arFields)
Определения site_template.php:229
$arTemplate
Определения component_props.php:26
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$handle
Определения include.php:55
if($ajaxMode) $ID
Определения get_user.php:27
$p
Определения group_list_element_edit.php:23
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$io
Определения csv_new_run.php:98
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
GetDirList($path, &$arDirs, &$arFiles, $arFilter=array(), $sort=array(), $type="DF", $bLogical=false, $task_mode=false)
Определения admin_tools.php:214
EscapePHPString($str, $encloser='"')
Определения tools.php:4917
CheckDirPath($path)
Определения tools.php:2707
DeleteDirFilesEx($path, $root=null)
Определения tools.php:2823
GetMessage($name, $aReplace=null)
Определения tools.php:3397
getLocalPath($path, $baseFolder="/bitrix")
Определения tools.php:5092
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$dir
Определения quickway.php:303
if(empty($signedUserToken)) $key
Определения quickway.php:257
$val
Определения options.php:1793
$arRes
Определения options.php:104
$arFilter
Определения user_search.php:106
$fields
Определения yandex_run.php:501