1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
wizard_util.php
См. документацию.
1<?php
3{
4 public static function GetRepositoryPath()
5 {
6 return BX_ROOT."/wizards";
7 }
8
9 public static function MakeWizardPath($wizardName)
10 {
11 if (!CWizardUtil::CheckName($wizardName))
12 return "";
13
14 return Rel2Abs("/", "/".str_replace(":", "/", $wizardName));
15 }
16
17 public static function CheckName($wizardName)
18 {
19 return (
20 $wizardName <> ''
21 && preg_match("#^([A-Za-z0-9_.-]+:)?([A-Za-z0-9_-]+\\.)*([A-Za-z0-9_-]+)$#i", $wizardName)
22 );
23 }
24
25 public static function GetWizardList($filterNamespace = false, $bLoadFromModules = false)
26 {
27 $arWizards = array();
28 $arLoadedWizards = array();
29
30 $wizardPath = $_SERVER["DOCUMENT_ROOT"].CWizardUtil::GetRepositoryPath();
31
32 if ($handle = @opendir($wizardPath))
33 {
34 while (($dirName = readdir($handle)) !== false)
35 {
36 if ($dirName == "." || $dirName == ".." || !is_dir($wizardPath."/".$dirName))
37 continue;
38
39 if (file_exists($wizardPath."/".$dirName."/.description.php"))
40 {
41 //Skip component without namespace
42 if ($filterNamespace !== false && $filterNamespace <> '')
43 continue;
44
45 if (LANGUAGE_ID != "en" && LANGUAGE_ID != "ru")
46 {
47 __IncludeLang($wizardPath."/".$dirName."/lang/".LangSubst(LANGUAGE_ID)."/.description.php", false);
48 }
49
50 __IncludeLang($wizardPath."/".$dirName."/lang/".LANGUAGE_ID."/.description.php", false);
51
52 $arWizardDescription = array();
53 include($wizardPath."/".$dirName."/.description.php");
54 $arWizards[] = array("ID" => $dirName) + $arWizardDescription;
55 $arLoadedWizards[] = $dirName;
56 }
57 else
58 {
59 if ($filterNamespace !== false && ($filterNamespace == '' || $filterNamespace != $dirName))
60 continue;
61
62 if ($nspaceHandle = @opendir($wizardPath."/".$dirName))
63 {
64 while (($file = readdir($nspaceHandle)) !== false)
65 {
66 $pathToWizard = $wizardPath."/".$dirName."/".$file;
67
68 if ($file == "." || $file == ".." || !is_dir($pathToWizard))
69 continue;
70
71 if (file_exists($pathToWizard."/.description.php"))
72 {
73 if (LANGUAGE_ID != "en" && LANGUAGE_ID != "ru")
74 {
75 __IncludeLang($pathToWizard."/lang/".LangSubst(LANGUAGE_ID)."/.description.php", false);
76 }
77
78 __IncludeLang($pathToWizard."/lang/".LANGUAGE_ID."/.description.php", false);
79
80 $arWizardDescription = array();
81 include($pathToWizard."/.description.php");
82 $arWizards[] = array("ID" => $dirName.":".$file) + $arWizardDescription;
83 $arLoadedWizards[] = $dirName.":".$file;
84 }
85 }
86
87 @closedir($nspaceHandle);
88 }
89 }
90 }
91 @closedir($handle);
92 }
93
94 if ($bLoadFromModules)
95 {
96 $modulesPath = $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules";
97
98 if ($handle = @opendir($modulesPath))
99 {
100 while (($moduleName = readdir($handle)) !== false)
101 {
102 if ($moduleName == "." || $moduleName == ".." || !is_dir($modulesPath."/".$moduleName))
103 continue;
104
105 if (!file_exists($modulesPath."/".$moduleName."/install/wizards"))
106 continue;
107
108 if ($handle1 = @opendir($modulesPath."/".$moduleName."/install/wizards"))
109 {
110 while (($dirName = readdir($handle1)) !== false)
111 {
112 if ($dirName == "." || $dirName == ".." || !is_dir($modulesPath."/".$moduleName."/install/wizards/".$dirName))
113 continue;
114
115 if ($filterNamespace !== false && ($filterNamespace == '' || $filterNamespace != $dirName))
116 continue;
117
118 if ($handle2 = @opendir($modulesPath."/".$moduleName."/install/wizards/".$dirName))
119 {
120 while (($file = readdir($handle2)) !== false)
121 {
122 $pathToWizard = $modulesPath."/".$moduleName."/install/wizards/".$dirName."/".$file;
123
124 if ($file == "." || $file == ".." || !is_dir($pathToWizard))
125 continue;
126
127 if (in_array($dirName.":".$file, $arLoadedWizards))
128 continue;
129
130 if (file_exists($pathToWizard."/.description.php"))
131 {
132 if (LANGUAGE_ID != "en" && LANGUAGE_ID != "ru")
133 {
134 __IncludeLang($pathToWizard."/lang/".LangSubst(LANGUAGE_ID)."/.description.php", false);
135 }
136
137 __IncludeLang($pathToWizard."/lang/".LANGUAGE_ID."/.description.php", false);
138
139 $arWizardDescription = array();
140 include($pathToWizard."/.description.php");
141 $arWizards[] = array("ID" => $moduleName.":".$dirName.":".$file) + $arWizardDescription;
142 $arLoadedWizards[] = $dirName.":".$file;
143 }
144 }
145
146 @closedir($handle2);
147 }
148 }
149 @closedir($handle1);
150 }
151 }
152 @closedir($handle);
153 }
154 }
155
156 return $arWizards;
157 }
158
159 public static function GetNamespaceList()
160 {
161 $arNamespaces = array();
162 $namespacePath = $_SERVER["DOCUMENT_ROOT"].CWizardUtil::GetRepositoryPath();
163
164 if ($handle = @opendir($namespacePath))
165 {
166 while (($file = readdir($handle)) !== false)
167 {
168 if ($file == "." || $file == "..")
169 continue;
170
171 if (is_dir($namespacePath."/".$file))
172 {
173 if (!file_exists($namespacePath."/".$file."/.description.php"))
174 $arNamespaces[] = $file;
175 }
176 }
177 @closedir($handle);
178 }
179
180 return $arNamespaces;
181 }
182
183 public static function DeleteWizard($wizardName)
184 {
185 if (!CWizardUtil::CheckName($wizardName))
186 return false;
187
188 $wizardPath = CWizardUtil::GetRepositoryPath().CWizardUtil::MakeWizardPath($wizardName);
189 if (!file_exists($_SERVER["DOCUMENT_ROOT"].$wizardPath))
190 return false;
191
192 $success = DeleteDirFilesEx($wizardPath);
193 return $success;
194 }
195
196 public static function CopyWizard($wizardName, $newName)
197 {
198 if (!CWizardUtil::CheckName($wizardName) || !CWizardUtil::CheckName($newName))
199 return false;
200
201 $wizardPath = $_SERVER["DOCUMENT_ROOT"].CWizardUtil::GetRepositoryPath().CWizardUtil::MakeWizardPath($wizardName);
202 $newNamePath = $_SERVER["DOCUMENT_ROOT"].CWizardUtil::GetRepositoryPath().CWizardUtil::MakeWizardPath($newName);
203 if (!file_exists($wizardPath) || file_exists($newNamePath))
204 return false;
205
207 $wizardPath,
208 $newNamePath,
209 $rewrite = false,
210 $recursive = true
211 );
212
213 return true;
214 }
215
216 public static function ReplaceMacros($filePath, $arReplace, $skipSharp = false)
217 {
218 clearstatcache();
219
220 if (!is_file($filePath) || !is_writable($filePath) || !is_array($arReplace))
221 return;
222
223 @chmod($filePath, BX_FILE_PERMISSIONS);
224
225 if (!$handle = @fopen($filePath, "rb"))
226 return;
227
228 $content = @fread($handle, filesize($filePath));
229 @fclose($handle);
230
231 if (!($handle = @fopen($filePath, "wb")))
232 return;
233
234 if (flock($handle, LOCK_EX))
235 {
236 $arSearch = array();
237 $arValue = array();
238
239 foreach ($arReplace as $search => $replace)
240 {
241 if ($skipSharp)
242 $arSearch[] = $search;
243 else
244 $arSearch[] = "#".$search."#";
245
246 $arValue[] = $replace;
247 }
248
249 $content = str_replace($arSearch, $arValue, $content);
250 @fwrite($handle, $content);
251 @flock($handle, LOCK_UN);
252 }
253 @fclose($handle);
254 }
255
256 public static function ReplaceMacrosRecursive($filePath, $arReplace)
257 {
258 clearstatcache();
259
260 if ((!is_dir($filePath) && !is_file($filePath)) || !is_array($arReplace))
261 return;
262
263 $root = (defined("WIZARD_SITE_ROOT_PATH")? WIZARD_SITE_ROOT_PATH : $_SERVER["DOCUMENT_ROOT"]);
264 $root = trim($root, "/");
265
266 if ($handle = @opendir($filePath))
267 {
268 while (($file = readdir($handle)) !== false)
269 {
270 if ($file == "." || $file == ".." || (trim($filePath, "/") == $root && ($file == "bitrix" || $file == "upload")))
271 continue;
272
273 if (is_dir($filePath."/".$file))
274 {
275 self::ReplaceMacrosRecursive($filePath.$file."/", $arReplace);
276 }
277 elseif (is_file($filePath."/".$file))
278 {
279 if(GetFileExtension($file) <> "php")
280 continue;
281
282 if (!is_writable($filePath."/".$file))
283 continue;
284
285 $size = filesize($filePath."/".$file);
286
287 if($size == 0)
288 {
289 continue;
290 }
291
292 @chmod($filePath."/".$file, BX_FILE_PERMISSIONS);
293
294 if (!$handleFile = @fopen($filePath."/".$file, "rb"))
295 continue;
296
297 $content = @fread($handleFile, $size);
298 @fclose($handleFile);
299
300 if (!($handleFile = @fopen($filePath."/".$file, "wb")))
301 continue;
302
303 if (flock($handleFile, LOCK_EX))
304 {
305 $arSearch = array();
306 $arValue = array();
307
308 foreach ($arReplace as $search => $replace)
309 {
310 $arSearch[] = "#".$search."#";
311 $arValue[] = $replace;
312 }
313
314 $content = str_replace($arSearch, $arValue, $content);
315 @fwrite($handleFile, $content);
316 @flock($handleFile, LOCK_UN);
317 }
318 @fclose($handleFile);
319
320 }
321 }
322 @closedir($handle);
323 }
324 }
325
326 public static function CopyFile($fileID, $destPath, $deleteAfterCopy = true)
327 {
328 $arFile = CFile::GetFileArray($fileID);
329 if (!$arFile)
330 return false;
331
332 $filePath = $_SERVER["DOCUMENT_ROOT"].$arFile["SRC"];
333 if (!is_file($filePath))
334 return false;
335
336 CheckDirPath($_SERVER["DOCUMENT_ROOT"].$destPath);
337 if(!@copy($filePath, $_SERVER["DOCUMENT_ROOT"].$destPath))
338 return false;
339
340 if ($deleteAfterCopy)
341 CFile::Delete($fileID);
342
343 return true;
344 }
345
346 public static function GetModules()
347 {
348 $arModules = array();
349
350 $arModules["main"] = array(
351 "MODULE_ID" => "main",
352 "MODULE_NAME" => GetMessage("MAIN_WIZARD_MAIN_MODULE_NAME"),
353 "MODULE_DESCRIPTION" => GetMessage("MAIN_WIZARD_MAIN_MODULE_DESC"),
354 "MODULE_VERSION" => SM_VERSION,
355 "MODULE_VERSION_DATE" => SM_VERSION_DATE,
356 "IsInstalled" => true,
357 );
358
359 $handle=@opendir($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules");
360 if($handle)
361 {
362 while (false !== ($dir = readdir($handle)))
363 {
364 if(is_dir($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/".$dir) && $dir!="." && $dir!="..")
365 {
366 if($info = CModule::CreateModuleObject($dir))
367 {
368 $arModules[$dir]["MODULE_ID"] = $info->MODULE_ID;
369 $arModules[$dir]["MODULE_NAME"] = $info->MODULE_NAME;
370 $arModules[$dir]["MODULE_DESCRIPTION"] = $info->MODULE_DESCRIPTION;
371 $arModules[$dir]["MODULE_VERSION"] = $info->MODULE_VERSION;
372 $arModules[$dir]["MODULE_VERSION_DATE"] = $info->MODULE_VERSION_DATE;
373 $arModules[$dir]["MODULE_SORT"] = $info->MODULE_SORT;
374 $arModules[$dir]["IsInstalled"] = $info->IsInstalled();
375 }
376 }
377 }
378 closedir($handle);
379 }
380
381 return $arModules;
382 }
383
384 public static function CreateThumbnail($sourcePath, $previewPath, $maxWidth, $maxHeight)
385 {
386 if (!is_file($sourcePath))
387 return false;
388
389 $maxWidth = intval($maxWidth);
390 $maxHeight = intval($maxHeight);
391
392 if ($maxWidth <= 0 || $maxHeight <= 0)
393 return false;
394
395 list($sourceWidth, $sourceHeight, $type) = @getimagesize($sourcePath);
396
397 //Image type
398 if ($type == 1)
399 $imageType = "gif";
400 elseif ($type == 2)
401 $imageType = "jpeg";
402 elseif ($type == 3)
403 $imageType = "png";
404 else
405 return false;
406
407 $imageFunction = "imagecreatefrom".$imageType;
408 $sourceImage = @$imageFunction($sourcePath);
409
410 if (!$sourceImage)
411 return false;
412
413 $ratioWidth = $sourceWidth / $maxWidth;
414 $ratioHeight = $sourceHeight / $maxHeight;
415 $ratio = ($ratioWidth > $ratioHeight) ? $ratioWidth : $ratioHeight;
416
417 //Biggest side
418 if ($ratio > 0)
419 {
420 $previewWidth = $sourceWidth / $ratio;
421 $previewHeight = $sourceHeight / $ratio;
422 }
423 else
424 {
425 $previewWidth = $maxWidth;
426 $previewHeight = $maxHeight;
427 }
428
429 //GD library version
430 $bGD2 = false;
431 if (function_exists("gd_info"))
432 {
433 $arGDInfo = gd_info();
434 $bGD2 = str_contains($arGDInfo['GD Version'], "2.");
435 }
436
437 //Create Preview
438 if ($bGD2)
439 {
440 $previewImage = imagecreatetruecolor($previewWidth, $previewHeight);
441 imagecopyresampled($previewImage, $sourceImage, 0, 0, 0, 0, $previewWidth, $previewHeight, $sourceWidth, $sourceHeight);
442 }
443 else
444 {
445 $previewImage = imagecreate($previewWidth, $previewHeight);
446 imagecopyresized($previewImage, $sourceImage, 0, 0, 0, 0, $previewWidth, $previewHeight, $sourceWidth, $sourceHeight);
447 }
448
449 //Save preview
450 $imageFunction = "image".$imageType;
451
452 if ($imageType == "jpeg")
453 $success = @$imageFunction($previewImage, $previewPath, 95);
454 else
455 $success = @$imageFunction($previewImage, $previewPath);
456
457 @imagedestroy($previewImage);
458 @imagedestroy($sourceImage);
459
460 return $success;
461
462 }
463}
$type
Определения options.php:106
const BX_ROOT
Определения bx_root.php:3
Определения wizard_util.php:3
static CopyFile($fileID, $destPath, $deleteAfterCopy=true)
Определения wizard_util.php:326
static GetWizardList($filterNamespace=false, $bLoadFromModules=false)
Определения wizard_util.php:25
static ReplaceMacrosRecursive($filePath, $arReplace)
Определения wizard_util.php:256
static CheckName($wizardName)
Определения wizard_util.php:17
static GetRepositoryPath()
Определения wizard_util.php:4
static DeleteWizard($wizardName)
Определения wizard_util.php:183
static CreateThumbnail($sourcePath, $previewPath, $maxWidth, $maxHeight)
Определения wizard_util.php:384
static CopyWizard($wizardName, $newName)
Определения wizard_util.php:196
static MakeWizardPath($wizardName)
Определения wizard_util.php:9
static GetNamespaceList()
Определения wizard_util.php:159
static GetModules()
Определения wizard_util.php:346
static ReplaceMacros($filePath, $arReplace, $skipSharp=false)
Определения wizard_util.php:216
$content
Определения commerceml.php:144
</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
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$success
Определения mail_entry.php:69
const SM_VERSION_DATE
Определения version.php:3
const SM_VERSION
Определения version.php:2
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
GetFileExtension($path)
Определения tools.php:2972
CheckDirPath($path)
Определения tools.php:2707
LangSubst($lang)
Определения tools.php:3854
DeleteDirFilesEx($path, $root=null)
Определения tools.php:2823
Rel2Abs($curdir, $relpath)
Определения tools.php:3297
CopyDirFiles($path_from, $path_to, $ReWrite=true, $Recursive=false, $bDeleteAfterCopy=false, $strExclude="")
Определения tools.php:2732
GetMessage($name, $aReplace=null)
Определения tools.php:3397
__IncludeLang($path, $bReturnArray=false, $bFileChecked=false)
Определения tools.php:3477
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$dir
Определения quickway.php:303