1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
admin_tools.php
См. документацию.
1<?php
2
9
10IncludeModuleLangFile(__FILE__);
11
12function GetTemplateContent($filename, $lang=LANG, $arTemplates=array())
13{
14 global $APPLICATION;
15
17
18 $arDirs = array();
19 foreach($arTemplates as $val)
20 $arDirs[] = "templates/".$val."/page_templates";
21 $arDirs[] = "templates/.default/page_templates";
22 $arDirs[] = "php_interface/".$lang."templates";
23 $arDirs[] = "php_interface/templates";
24
25 foreach($arDirs as $dir)
26 {
27 $path = getLocalPath($dir."/".$filename, BX_PERSONAL_ROOT);
28 if($path !== false && is_file($_SERVER["DOCUMENT_ROOT"].$path))
29 return $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"].$path);
30 }
31
32 return false;
33}
34
35function GetFileTemplates($lang = LANG, $arTemplates = array())
36{
37 global $APPLICATION;
38
39 $arDirs = array(
40 "php_interface/".$lang."/templates",
41 "templates/.default/page_templates",
42 "php_interface/templates",
43 );
44 foreach($arTemplates as $val)
45 $arDirs[] = "templates/".$val."/page_templates";
46
47 $res = array();
48 foreach($arDirs as $dir)
49 {
50 $templDir = getLocalPath($dir, BX_PERSONAL_ROOT);
51 if($templDir === false)
52 continue;
53 $dirPath = $_SERVER["DOCUMENT_ROOT"].$templDir;
54 if(file_exists($dirPath))
55 {
56 $sDescFile = $dirPath."/.content.php";
57 $TEMPLATE = array();
58 if(file_exists($sDescFile))
59 include($sDescFile);
60
61 if($handle = @opendir($dirPath))
62 {
63 while(($file = readdir($handle)) !== false)
64 {
65 if(is_dir($dirPath."/".$file))
66 continue;
67 if(str_starts_with($file, "."))
68 continue;
69
70 $path = $templDir."/".$file;
71 if($APPLICATION->GetFileAccessPermission($path) < "R")
72 continue;
73
74 $restmp = array(
75 "name" => mb_substr($file, 0, bxstrrpos($file, ".")),
76 "file" => $file,
77 "sort" => 150,
78 "path" => $path,
79 );
80
81 if(array_key_exists($file, $TEMPLATE))
82 {
83 if(array_key_exists("name", $TEMPLATE[$file]))
84 $restmp["name"] = $TEMPLATE[$file]["name"];
85 if(array_key_exists("sort", $TEMPLATE[$file]))
86 $restmp["sort"] = $TEMPLATE[$file]["sort"];
87 }
88
89 $res[$file] = $restmp;
90 }
91 closedir($handle);
92 }
93 }
94 }
95 sortByColumn($res, "sort");
96
97 return array_values($res);
98}
99
100function ParsePath($path, $bLast=false, $url=false, $param="", $bLogical = false)
101{
102 CMain::InitPathVars($site, $path);
103 $DOC_ROOT = CSite::GetSiteDocRoot($site);
104
105 if($url===false)
106 $url = BX_ROOT."/admin/fileman_admin.php";
107
108 $arSite = array();
109 if($site!==false && $site <> '')
110 {
111 $res = CSite::GetByID($site);
112 if(!($arSite = $res->Fetch()))
113 $site=false;
114 }
115
116 $addUrl = ($bLogical?"logical=Y":"");
117
118 $arDirPath = explode("/", $path);
119 $full_path = "";
120 $prev_path = "";
121 $arPath = array();
122 if($bLast || $path <> '' || $site <> '')
123 {
124 $html_path = '<a href="'.$url.'?lang='.LANG.'&'.$addUrl.'">'.GetMessage("MAIN_ROOT_FOLDER").'</a>/';
125 }
126 else
127 {
128 $html_path = GetMessage("MAIN_ROOT_FOLDER")."/";
129 }
130
131 if($site!==false)
132 {
133 if($bLast || $path <> '')
134 {
135 $html_path .= '<a href="'.$url.'?lang='.LANG.'&'.$addUrl.'&amp;site='.$site.'">'.$arSite["NAME"].'</a>/';
136 }
137 else
138 {
139 $html_path .= $arSite["NAME"]."/";
140 }
141 }
142
144 $pathLast = count($arDirPath)-1;
145 $last = "";
146 foreach($arDirPath as $i => $pathPart)
147 {
148 if($pathPart == '')
149 continue;
150
151 $prev_path = $full_path;
152 $full_path .= "/".$pathPart;
153 $last = $pathPart;
154
155 $sSectionName = $pathPart;
156 if($bLogical && $io->DirectoryExists($DOC_ROOT.$full_path))
157 {
158 if(!$io->FileExists($DOC_ROOT.$full_path."/.section.php"))
159 continue;
160
161 include($io->GetPhysicalName($DOC_ROOT.$full_path."/.section.php"));
162 if($sSectionName == '')
163 $sSectionName = GetMessage("admin_tools_no_name");
164 }
165
166 if($i==$pathLast && (!$bLast || !$io->DirectoryExists($DOC_ROOT.$full_path)))
167 {
168 $html_path .= $sSectionName;
169 $arPath[] = array(
170 "LINK" => "",
171 "TITLE" => $sSectionName
172 );
173 }
174 else
175 {
176 $html_path .= "<a href=\"".$url."?lang=".LANG.'&'.$addUrl."&path=".UrlEncode($full_path).($site?"&site=".$site : "").($param<>""? "&".$param:"")."\">".$sSectionName."</a>/";
177 if(!$arSite || !$bLogical || rtrim($arSite["DIR"], "/") != rtrim($full_path, "/"))
178 {
179 $arPath[] = array(
180 "LINK" => $url."?lang=".LANG."&".$addUrl."&path=".UrlEncode($full_path).($site?"&site=".$site : "").($param<>""? "&".$param:""),
181 "TITLE" => $sSectionName
182 );
183 }
184 }
185 }
186
187 return array(
188 "PREV" => $prev_path,
189 "FULL" => $full_path,
190 "HTML" => $html_path,
191 "LAST" => $last,
192 "AR_PATH" => $arPath,
193 );
194}
195
196function CompareFiles($f1, $f2, $sort=array())
197{
198 $by = key($sort);
199 $order = $sort[$by];
200 if(mb_strtolower($order) == "desc")
201 {
202 if($by=="size") return intval($f1["SIZE"])<intval($f2["SIZE"]);
203 if($by=="timestamp") return intval($f1["TIMESTAMP"])<intval($f2["TIMESTAMP"]);
204 return $f1["NAME"]<$f2["NAME"];
205 }
206 else
207 {
208 if($by=="size") return intval($f1["SIZE"])>intval($f2["SIZE"]);
209 if($by=="timestamp") return intval($f1["TIMESTAMP"])>intval($f2["TIMESTAMP"]);
210 return $f1["NAME"]>$f2["NAME"];
211 }
212}
213
214function GetDirList($path, &$arDirs, &$arFiles, $arFilter=array(), $sort=array(), $type="DF", $bLogical=false,$task_mode=false)
215{
216 global $USER, $APPLICATION;
217
218 CMain::InitPathVars($site, $path);
219 $DOC_ROOT = CSite::GetSiteDocRoot($site);
220
221 $arDirs=array();
222 $arFiles=array();
223
224 $exts = mb_strtolower($arFilter["EXTENSIONS"] ?? '');
225 $arexts=explode(",", $exts);
226 if(isset($arFilter["TYPE"]))
227 $type = mb_strtoupper($arFilter["TYPE"]);
228
230 $path = $io->CombinePath("/", $path);
231 $abs_path = $io->CombinePath($DOC_ROOT, $path);
232
233 if(!$io->DirectoryExists($abs_path))
234 return false;
235
236 $date_format = CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL"));
237 $tzOffset = CTimeZone::GetOffset();
238
239 $dir = $io->GetDirectory($abs_path);
240 $arChildren = $dir->GetChildren();
241 $arExtension = array("php"=>1, "html"=>1, "php3"=>1, "php4"=>1, "php5"=>1, "php6"=>1, "phtml"=>1, "htm"=>1);
242 foreach ($arChildren as $child)
243 {
244 $arFile = array();
245
246 if(($type=="F" || $type=="") && $child->IsDirectory())
247 continue;
248 if(($type=="D" || $type=="") && !$child->IsDirectory())
249 continue;
250
251 $file = $child->GetName();
252
253 if($bLogical)
254 {
255 if($child->IsDirectory())
256 {
257 $sSectionName = "";
258 $fsn = $io->CombinePath($abs_path, $file, ".section.php");
259 if(!$io->FileExists($fsn))
260 continue;
261
262 include($io->GetPhysicalName($fsn));
263 $arFile["LOGIC_NAME"] = $sSectionName;
264 }
265 else
266 {
267 $ext = CFileMan::GetFileTypeEx($file);
268 if(!isset($arExtension[$ext]))
269 continue;
270
271 if($file=='.section.php')
272 continue;
273
274 if(!preg_match('/^\.(.*)?\.menu\.(php|html|php3|php4|php5|php6|phtml)$/', $file, $regs))
275 {
276 $f = $io->GetFile($abs_path."/".$file);
277 $filesrc = $f->GetContents();
278
279 $title = PHPParser::getPageTitle($filesrc);
280 if($title===false)
281 continue;
282 $arFile["LOGIC_NAME"] = $title;
283 }
284 }
285 }
286
287 $arFile["PATH"] = $abs_path."/".$file;
288 $arFile["ABS_PATH"] = $path."/".$file;
289 $arFile["NAME"] = $file;
290
291 $arPerm = $APPLICATION->GetFileAccessPermission(array($site, $path."/".$file), $USER->GetUserGroupArray(),$task_mode);
292 if ($task_mode)
293 {
294 $arFile["PERMISSION"] = $arPerm[0];
295 if (!empty($arPerm[1]))
296 $arFile["PERMISSION_EX"] = $arPerm[1];
297 }
298 else
299 $arFile["PERMISSION"] = $arPerm;
300
301 $arFile["TIMESTAMP"] = $child->GetModificationTime() + $tzOffset;
302 $arFile["DATE"] = date($date_format, $arFile["TIMESTAMP"]);
303
304 if (isset($arFilter["TIMESTAMP_1"]) && strtotime($arFile["DATE"]) < strtotime($arFilter["TIMESTAMP_1"]))
305 continue;
306 if (isset($arFilter["TIMESTAMP_2"]) && strtotime($arFile["DATE"]) > strtotime($arFilter["TIMESTAMP_2"]))
307 continue;
308
309 if(is_set($arFilter, "MIN_PERMISSION") && $arFile["PERMISSION"]<$arFilter["MIN_PERMISSION"] && !$task_mode)
310 continue;
311
312 if(!$child->IsDirectory() && $arFile["PERMISSION"]<="R" && !$task_mode)
313 continue;
314
315 if ($bLogical)
316 {
317 if(!empty($arFilter["NAME"]) && mb_strpos($arFile["LOGIC_NAME"], $arFilter["NAME"]) === false)
318 continue;
319 }
320 else
321 {
322 if(!empty($arFilter["NAME"]) && mb_strpos($arFile["NAME"], $arFilter["NAME"]) === false)
323 continue;
324 }
325
326 //if(strlen($arFilter["NAME"])>0 && strpos($arFile["NAME"], $arFilter["NAME"])===false)
327 // continue;
328
329 if(str_starts_with($arFile["ABS_PATH"], BX_ROOT . "/modules") && !$USER->CanDoOperation('edit_php') && !$task_mode)
330 continue;
331
332 if ($arFile["PERMISSION"]=="U" && !$task_mode)
333 {
334 $ftype = GetFileType($arFile["NAME"]);
335 if ($ftype!="SOURCE" && $ftype!="IMAGE" && $ftype!="UNKNOWN") continue;
336 if (str_starts_with($arFile["NAME"], ".")) continue;
337 }
338
339 if($child->IsDirectory())
340 {
341 $arFile["SIZE"] = 0;
342 $arFile["TYPE"] = "D";
343 $arDirs[]=$arFile;
344 }
345 else
346 {
347 if($exts!="")
348 if(!in_array(mb_strtolower(mb_substr($file, bxstrrpos($file, ".") + 1)), $arexts))
349 continue;
350
351 $arFile["TYPE"] = "F";
352 $arFile["SIZE"] = $child->GetFileSize();
353 $arFiles[]=$arFile;
354 }
355 }
356
357 if(is_array($sort) && !empty($sort))
358 {
359 $by = key($sort);
360 $order = mb_strtolower($sort[$by]);
361 $by = mb_strtolower($by);
362 if($order!="desc")
363 $order="asc";
364 if($by!="size" && $by!="timestamp" && $by!="name_nat")
365 $by="name";
366
367 usort($arDirs, array("FilesCmp", "cmp_".$by."_".$order));
368 usort($arFiles, array("FilesCmp", "cmp_".$by."_".$order));
369 }
370
371 return null;
372}
373
374function SetPrologTitle($prolog, $title)
375{
376 if(preg_match('/
377 (\$APPLICATION->SetTitle\‍()
378 (
379 "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" # match double quoted string
380 |
381 \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' # match single quoted string
382 )
383 (\‍);)
384 /ix', $prolog, $regs)
385 )
386 {
387 $prolog = str_replace($regs[0], $regs[1]."\"".EscapePHPString($title)."\");", $prolog);
388 }
389 else
390 {
391 $p = mb_strpos($prolog, "prolog_before");
392 if($p===false)
393 $p = mb_strpos($prolog, "prolog.php");
394 if($p===false)
395 $p = mb_strpos($prolog, "header.php");
396
397 if($p===false)
398 {
399 if($title == '')
400 $prolog = preg_replace("#<title>[^<]*</title>#i", "", $prolog);
401 elseif(preg_match("#<title>[^<]*</title>#i", $prolog))
402 $prolog = preg_replace("#<title>[^<]*</title>#i", "<title>".$title."</title>", $prolog);
403 else
404 $prolog = $prolog."\n<title>".htmlspecialcharsbx($title)."</title>\n";
405 }
406 else
407 {
408 $p = mb_strpos(mb_substr($prolog, $p), ")") + $p;
409 $prolog = mb_substr($prolog, 0, $p + 1).";\n\$APPLICATION->SetTitle(\"".EscapePHPString($title)."\")".mb_substr($prolog, $p + 1);
410 }
411 }
412 return $prolog;
413}
414
415function SetPrologProperty($prolog, $property_key, $property_val)
416{
417 if(preg_match("'(\\\$APPLICATION->SetPageProperty\\(\"".preg_quote(EscapePHPString($property_key), "'")."\" *, *)([\"\\'])(.*?)(?<!\\\\)([\"\\'])(\\);[\r\n]*)'i", $prolog, $regs)
418 || preg_match("'(\\\$APPLICATION->SetPageProperty\\(\\'".preg_quote(EscapePHPString($property_key, "'"), "'")."\\' *, *)([\"\\'])(.*?)(?<!\\\\)([\"\\'])(\\);[\r\n]*)'i", $prolog, $regs))
419 {
420 if ($property_val == '')
421 $prolog = str_replace($regs[1].$regs[2].$regs[3].$regs[4].$regs[5], "", $prolog);
422 else
423 $prolog = str_replace($regs[1].$regs[2].$regs[3].$regs[4].$regs[5], $regs[1].$regs[2].EscapePHPString($property_val, $regs[2]).$regs[4].$regs[5], $prolog);
424 }
425 else
426 {
427 if ($property_val <> '')
428 {
429 $p = mb_strpos($prolog, "prolog_before");
430 if($p===false)
431 $p = mb_strpos($prolog, "prolog.php");
432 if($p===false)
433 $p = mb_strpos($prolog, "header.php");
434 if($p!==false)
435 {
436 $p = mb_strpos(mb_substr($prolog, $p), ")") + $p;
437 $prolog = mb_substr($prolog, 0, $p + 1).";\n\$APPLICATION->SetPageProperty(\"".EscapePHPString($property_key)."\", \"".EscapePHPString($property_val)."\")".mb_substr($prolog, $p + 1);
438 }
439 }
440 }
441 return $prolog;
442}
443
444function IsPHP($src)
445{
446 if(str_contains($src, "<?"))
447 return true;
448 if(preg_match("/(<script[^>]*language\\s*=\\s*)('|\"|)php('|\"|)([^>]*>)/i", $src))
449 return true;
450 return false;
451}
$path
Определения access_edit.php:21
$type
Определения options.php:106
const BX_ROOT
Определения bx_root.php:3
global $APPLICATION
Определения include.php:80
static GetInstance()
Определения virtual_io.php:60
static GetFileTypeEx($fileName)
Определения fileman.php:810
$abs_path
Определения component_props2.php:76
$f
Определения component_props.php:52
$filesrc
Определения component_props.php:53
$filename
Определения file_edit.php:47
$DOC_ROOT
Определения file_edit.php:66
$arPath
Определения file_edit.php:72
$addUrl
Определения file_edit.php:6
</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
$handle
Определения include.php:55
$p
Определения group_list_element_edit.php:23
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $USER
Определения csv_new_run.php:40
$io
Определения csv_new_run.php:98
SetPrologProperty($prolog, $property_key, $property_val)
Определения admin_tools.php:415
SetPrologTitle($prolog, $title)
Определения admin_tools.php:374
IsPHP($src)
Определения admin_tools.php:444
GetDirList($path, &$arDirs, &$arFiles, $arFilter=array(), $sort=array(), $type="DF", $bLogical=false, $task_mode=false)
Определения admin_tools.php:214
GetTemplateContent($filename, $lang=LANG, $arTemplates=array())
Определения admin_tools.php:12
CompareFiles($f1, $f2, $sort=array())
Определения admin_tools.php:196
ParsePath($path, $bLast=false, $url=false, $param="", $bLogical=false)
Определения admin_tools.php:100
GetFileTemplates($lang=LANG, $arTemplates=array())
Определения admin_tools.php:35
if(!defined('SITE_ID')) $lang
Определения include.php:91
EscapePHPString($str, $encloser='"')
Определения tools.php:4917
bxstrrpos($haystack, $needle)
Определения tools.php:3292
GetFileType($path)
Определения tools.php:3047
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
sortByColumn(array &$array, $columns, $callbacks='', $defaultValueIfNotSetValue=null, $preserveKeys=false)
Определения tools.php:5087
getLocalPath($path, $baseFolder="/bitrix")
Определения tools.php:5092
_normalizePath($strPath)
Определения tools.php:3341
$order
Определения payment.php:8
$arFiles
Определения options.php:60
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$dir
Определения quickway.php:303
$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
$title
Определения pdf.php:123
$sSectionName
Определения .section.php:2
$val
Определения options.php:1793
$arDirs
Определения translate_tools.php:10
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7
$site
Определения yandex_run.php:614