PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/bitrix/modules/main/install/wizard_sol/utils.php

https://gitlab.com/Rad1calDreamer/honey
PHP | 461 lines | 377 code | 79 blank | 5 comment | 96 complexity | 0c6d7b7a1da70f3ce6af38a2e68db2d8 MD5 | raw file
  1. <?
  2. class WizardServices
  3. {
  4. function PatchHtaccess($path)
  5. {
  6. if (strtoupper(substr(PHP_OS, 0, 3)) === "WIN")
  7. {
  8. $io = CBXVirtualIo::GetInstance();
  9. $fnhtaccess = $io->CombinePath($path, '.htaccess');
  10. if ($io->FileExists($fnhtaccess))
  11. {
  12. $ffhtaccess = $io->GetFile($fnhtaccess);
  13. $ffhtaccessContent = $ffhtaccess->GetContents();
  14. if (strpos($ffhtaccessContent, "/bitrix/virtual_file_system.php") === false)
  15. {
  16. $ffhtaccessContent = preg_replace('/RewriteEngine On/is', "RewriteEngine On\r\n\r\n".
  17. "RewriteCond %{REQUEST_FILENAME} -f [OR]\r\n".
  18. "RewriteCond %{REQUEST_FILENAME} -l [OR]\r\n".
  19. "RewriteCond %{REQUEST_FILENAME} -d\r\n".
  20. "RewriteCond %{REQUEST_FILENAME} [\\xC2-\\xDF][\\x80-\\xBF] [OR]\r\n".
  21. "RewriteCond %{REQUEST_FILENAME} \\xE0[\\xA0-\\xBF][\\x80-\\xBF] [OR]\r\n".
  22. "RewriteCond %{REQUEST_FILENAME} [\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2} [OR]\r\n".
  23. "RewriteCond %{REQUEST_FILENAME} \\xED[\\x80-\\x9F][\\x80-\\xBF] [OR]\r\n".
  24. "RewriteCond %{REQUEST_FILENAME} \\xF0[\\x90-\\xBF][\\x80-\\xBF]{2} [OR]\r\n".
  25. "RewriteCond %{REQUEST_FILENAME} [\\xF1-\\xF3][\\x80-\\xBF]{3} [OR]\r\n".
  26. "RewriteCond %{REQUEST_FILENAME} \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2}\r\n".
  27. "RewriteCond %{REQUEST_FILENAME} !/bitrix/virtual_file_system.php$\r\n".
  28. "RewriteRule ^(.*)$ /bitrix/virtual_file_system.php [L]", $ffhtaccessContent);
  29. $ffhtaccess->PutContents($ffhtaccessContent);
  30. }
  31. }
  32. }
  33. }
  34. function GetTemplates($relativePath)
  35. {
  36. $absolutePath = $_SERVER["DOCUMENT_ROOT"].$relativePath;
  37. $absolutePath = str_replace("\\", "/", $absolutePath);
  38. $arWizardTemplates = Array();
  39. if (!$handle = @opendir($absolutePath))
  40. return $arWizardTemplates;
  41. while(($dirName = @readdir($handle)) !== false)
  42. {
  43. if ($dirName == "." || $dirName == ".." || !is_dir($absolutePath."/".$dirName))
  44. continue;
  45. $arTemplate = Array(
  46. "DESCRIPTION"=>"",
  47. "NAME" => $dirName,
  48. );
  49. if (file_exists($absolutePath."/".$dirName."/description.php"))
  50. {
  51. if (LANGUAGE_ID != "en" && LANGUAGE_ID != "ru")
  52. {
  53. if (file_exists(($fname = $absolutePath."/".$dirName."/lang/".LangSubst(LANGUAGE_ID)."/description.php")))
  54. __IncludeLang($fname);
  55. }
  56. if (file_exists(($fname = $absolutePath."/".$dirName."/lang/".LANGUAGE_ID."/description.php")))
  57. __IncludeLang($fname);
  58. include($absolutePath."/".$dirName."/description.php");
  59. }
  60. $arTemplate["ID"] = $dirName;
  61. if(intval($arTemplate["SORT"])<=0)
  62. $arTemplate["SORT"] = 100;
  63. if (file_exists($absolutePath."/".$dirName."/lang/".LANGUAGE_ID."/screen.gif"))
  64. $arTemplate["SCREENSHOT"] = $relativePath."/".$dirName."/lang/".LANGUAGE_ID."/screen.gif";
  65. elseif (file_exists($absolutePath."/".$dirName."/screen.gif"))
  66. $arTemplate["SCREENSHOT"] = $relativePath."/".$dirName."/screen.gif";
  67. else
  68. $arTemplate["SCREENSHOT"] = false;
  69. if (file_exists($absolutePath."/".$dirName."/lang/".LANGUAGE_ID."/preview.gif"))
  70. $arTemplate["PREVIEW"] = $relativePath."/".$dirName."/lang/".LANGUAGE_ID."/preview.gif";
  71. elseif (file_exists($absolutePath."/".$dirName."/preview.gif"))
  72. $arTemplate["PREVIEW"] = $relativePath."/".$dirName."/preview.gif";
  73. else
  74. $arTemplate["PREVIEW"] = false;
  75. $arWizardTemplates[$arTemplate["ID"]] = $arTemplate;
  76. }
  77. closedir($handle);
  78. uasort($arWizardTemplates, create_function('$a, $b', 'return strcmp($a["SORT"], $b["SORT"]);'));
  79. return $arWizardTemplates;
  80. }
  81. function GetTemplatesPath($path)
  82. {
  83. $templatesPath = $path."/templates";
  84. if (file_exists($_SERVER["DOCUMENT_ROOT"].$templatesPath."/".LANGUAGE_ID))
  85. $templatesPath .= "/".LANGUAGE_ID;
  86. return $templatesPath;
  87. }
  88. function GetServices($wizardPath, $serviceFolder = "", $arFilter = Array())
  89. {
  90. $arServices = Array();
  91. $wizardPath = rtrim($wizardPath, "/");
  92. $serviceFolder = rtrim($serviceFolder, "/");
  93. if (LANGUAGE_ID != "en" && LANGUAGE_ID != "ru")
  94. {
  95. if (file_exists(($fname = $wizardPath."/lang/".LangSubst(LANGUAGE_ID).$serviceFolder."/.services.php")))
  96. __IncludeLang($fname);
  97. }
  98. if (file_exists(($fname = $wizardPath."/lang/".LANGUAGE_ID.$serviceFolder."/.services.php")))
  99. __IncludeLang($fname);
  100. $servicePath = $wizardPath."/".$serviceFolder;
  101. include($servicePath."/.services.php");
  102. if (empty($arServices))
  103. return $arServices;
  104. $servicePosition = 1;
  105. foreach ($arServices as $serviceID => $arService)
  106. {
  107. if (isset($arFilter["SKIP_INSTALL_ONLY"]) && array_key_exists("INSTALL_ONLY", $arService) && $arService["INSTALL_ONLY"] == $arFilter["SKIP_INSTALL_ONLY"])
  108. {
  109. unset($arServices[$serviceID]);
  110. continue;
  111. }
  112. if (isset($arFilter["SERVICES"]) && is_array($arFilter["SERVICES"]) && !in_array($serviceID, $arFilter["SERVICES"]) && !array_key_exists("INSTALL_ONLY", $arService))
  113. {
  114. unset($arServices[$serviceID]);
  115. continue;
  116. }
  117. //Check service dependencies
  118. $modulesCheck = Array($serviceID);
  119. if (array_key_exists("MODULE_ID", $arService))
  120. $modulesCheck = (is_array($arService["MODULE_ID"]) ? $arService["MODULE_ID"] : Array($arService["MODULE_ID"]));
  121. foreach ($modulesCheck as $moduleID)
  122. {
  123. if (!IsModuleInstalled($moduleID))
  124. {
  125. unset($arServices[$serviceID]);
  126. continue 2;
  127. }
  128. }
  129. $arServices[$serviceID]["POSITION"] = $servicePosition;
  130. $servicePosition += (isset($arService["STAGES"]) && !empty($arService["STAGES"]) ? count($arService["STAGES"]) : 1);
  131. }
  132. return $arServices;
  133. }
  134. function IncludeServiceLang($relativePath, $lang = false, $bReturnArray = false)
  135. {
  136. if($lang === false)
  137. $lang = LANGUAGE_ID;
  138. $arMessages = Array();
  139. if ($lang != "en" && $lang != "ru")
  140. {
  141. if (file_exists(($fname = WIZARD_SERVICE_ABSOLUTE_PATH."/lang/".LangSubst($lang)."/".$relativePath)))
  142. {
  143. if ($bReturnArray)
  144. $arMessages = __IncludeLang($fname, true);
  145. else
  146. __IncludeLang($fname);
  147. }
  148. }
  149. if (file_exists(($fname = WIZARD_SERVICE_ABSOLUTE_PATH."/lang/".$lang."/".$relativePath)))
  150. {
  151. if ($bReturnArray)
  152. $arMessages = array_merge($arMessages, __IncludeLang($fname, true));
  153. else
  154. __IncludeLang($fname);
  155. }
  156. return $arMessages;
  157. }
  158. function GetCurrentSiteID($selectedSiteID = null)
  159. {
  160. if (strlen($selectedSiteID) > 0)
  161. {
  162. $obSite = CSite::GetList($by = "def", $order = "desc", Array("LID" => $selectedSiteID));
  163. if (!$arSite = $obSite->Fetch())
  164. $selectedSiteID = null;
  165. }
  166. $currentSiteID = $selectedSiteID;
  167. if ($currentSiteID == null)
  168. {
  169. $currentSiteID = SITE_ID;
  170. if (defined("ADMIN_SECTION"))
  171. {
  172. $obSite = CSite::GetList($by = "def", $order = "desc", Array("ACTIVE" => "Y"));
  173. if ($arSite = $obSite->Fetch())
  174. $currentSiteID = $arSite["LID"];
  175. }
  176. }
  177. return $currentSiteID;
  178. }
  179. function GetThemes($relativePath)
  180. {
  181. $arThemes = Array();
  182. if (!is_dir($_SERVER["DOCUMENT_ROOT"].$relativePath))
  183. return $arThemes;
  184. $themePath = $_SERVER["DOCUMENT_ROOT"].$relativePath;
  185. $themePath = str_replace("\\", "/", $themePath);
  186. if ($handle = @opendir($themePath))
  187. {
  188. while (($file = readdir($handle)) !== false)
  189. {
  190. if ($file == "." || $file == ".." || !is_dir($themePath."/".$file))
  191. continue;
  192. $arTemplate = Array();
  193. if (is_file($themePath."/".$file."/description.php"))
  194. {
  195. if (LANGUAGE_ID != "en" && LANGUAGE_ID != "ru")
  196. {
  197. if (file_exists(($fname = $themePath."/".$file."/lang/".LangSubst(LANGUAGE_ID)."/description.php")))
  198. __IncludeLang($fname);
  199. }
  200. if (file_exists(($fname = $themePath."/".$file."/lang/".LANGUAGE_ID."/description.php")))
  201. __IncludeLang($fname);
  202. @include($themePath."/".$file."/description.php");
  203. }
  204. $arTheme = Array(
  205. "ID" => $file,
  206. "SORT" => (isset($arTemplate["SORT"]) && intval($arTemplate["SORT"]) > 0 ? intval($arTemplate["SORT"]) : 10),
  207. "NAME" => (isset($arTemplate["NAME"]) ? $arTemplate["NAME"] : $file),
  208. );
  209. if(file_exists($themePath."/".$file."/lang/".LANGUAGE_ID."/small.png"))
  210. $arTheme["PREVIEW"] = $relativePath."/".$file."/lang/".LANGUAGE_ID."/small.png";
  211. elseif(file_exists($themePath."/".$file."/lang/".LANGUAGE_ID."/preview.gif"))
  212. $arTheme["PREVIEW"] = $relativePath."/".$file."/lang/".LANGUAGE_ID."/preview.gif";
  213. elseif(file_exists($themePath."/".$file."/small.png"))
  214. $arTheme["PREVIEW"] = $relativePath."/".$file."/small.png";
  215. elseif(file_exists($themePath."/".$file."/preview.gif"))
  216. $arTheme["PREVIEW"] = $relativePath."/".$file."/preview.gif";
  217. else
  218. $arTheme["PREVIEW"] = false;
  219. if(file_exists($themePath."/".$file."/lang/".LANGUAGE_ID."/big.png"))
  220. $arTheme["SCREENSHOT"] = $relativePath."/".$file."/lang/".LANGUAGE_ID."/big.png";
  221. elseif(file_exists($themePath."/".$file."/lang/".LANGUAGE_ID."/screen.gif"))
  222. $arTheme["SCREENSHOT"] = $relativePath."/".$file."/lang/".LANGUAGE_ID."/screen.gif";
  223. elseif(file_exists($themePath."/".$file."/big.png"))
  224. $arTheme["SCREENSHOT"] = $relativePath."/".$file."/big.png";
  225. elseif(file_exists($themePath."/".$file."/screen.gif"))
  226. $arTheme["SCREENSHOT"] = $relativePath."/".$file."/screen.gif" ;
  227. else
  228. $arTheme["SCREENSHOT"] = false;
  229. $arThemes[$file] = $arTemplate + $arTheme;
  230. }
  231. @closedir($handle);
  232. }
  233. uasort($arThemes, create_function('$a, $b', 'return strcmp($a["SORT"], $b["SORT"]);'));
  234. return $arThemes;
  235. }
  236. function SetFilePermission($path, $permissions)
  237. {
  238. $originalPath = $path;
  239. CMain::InitPathVars($site, $path);
  240. $documentRoot = CSite::GetSiteDocRoot($site);
  241. $path = rtrim($path, "/");
  242. if (strlen($path) <= 0)
  243. $path = "/";
  244. if( ($position = strrpos($path, "/")) !== false)
  245. {
  246. $pathFile = substr($path, $position+1);
  247. $pathDir = substr($path, 0, $position);
  248. }
  249. else
  250. return false;
  251. if ($pathFile == "" && $pathDir == "")
  252. $pathFile = "/";
  253. $PERM = Array();
  254. if(file_exists($documentRoot.$pathDir."/.access.php"))
  255. {
  256. //include replaced with eval in order to honor of ZendServer
  257. eval("?>".file_get_contents($documentRoot.$pathDir."/.access.php"));
  258. }
  259. if (!isset($PERM[$pathFile]) || !is_array($PERM[$pathFile]))
  260. $arPermisson = $permissions;
  261. else
  262. $arPermisson = $permissions + $PERM[$pathFile];
  263. return $GLOBALS["APPLICATION"]->SetFileAccessPermission($originalPath, $arPermisson);
  264. }
  265. function AddMenuItem($menuFile, $menuItem, $siteID, $pos = -1)
  266. {
  267. if (CModule::IncludeModule('fileman'))
  268. {
  269. $arResult = CFileMan::GetMenuArray($_SERVER["DOCUMENT_ROOT"].$menuFile);
  270. $arMenuItems = $arResult["aMenuLinks"];
  271. $menuTemplate = $arResult["sMenuTemplate"];
  272. $bFound = false;
  273. foreach($arMenuItems as $item)
  274. if($item[1] == $menuItem[1])
  275. $bFound = true;
  276. if(!$bFound)
  277. {
  278. if($pos<0 || $pos>=count($arMenuItems))
  279. $arMenuItems[] = $menuItem;
  280. else
  281. {
  282. for($i=count($arMenuItems); $i>$pos; $i--)
  283. $arMenuItems[$i] = $arMenuItems[$i-1];
  284. $arMenuItems[$pos] = $menuItem;
  285. }
  286. CFileMan::SaveMenu(Array($siteID, $menuFile), $arMenuItems, $menuTemplate);
  287. }
  288. }
  289. }
  290. function CopyFile($fileFrom, $fileTo)
  291. {
  292. CopyDirFiles($_SERVER['DOCUMENT_ROOT'].$fileFrom, $_SERVER['DOCUMENT_ROOT'].$fileTo, false, true);
  293. }
  294. function ImportIBlockFromXML($xmlFile, $iblockCode, $iblockType, $siteID, $permissions = Array())
  295. {
  296. if (!CModule::IncludeModule("iblock"))
  297. return false;
  298. $rsIBlock = CIBlock::GetList(array(), array("CODE" => $iblockCode, "TYPE" => $iblockType, "SITE_ID" => $siteID));
  299. if ($arIBlock = $rsIBlock->Fetch())
  300. return false;
  301. if (!is_array($siteID))
  302. $siteID = Array($siteID);
  303. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/iblock/classes/".strtolower($GLOBALS["DB"]->type)."/cml2.php");
  304. $iblockID = ImportXMLFile(
  305. $xmlFile,
  306. $iblockType,
  307. $siteID,
  308. $section_action = "N",
  309. $element_action = "N",
  310. $use_crc = false,
  311. $preview = false,
  312. $sync = false,
  313. $return_last_error = false,
  314. $return_iblock_id = true
  315. );
  316. //Import was not able to return iblock_id by error
  317. if ((!is_integer($iblockID)) || ($iblockID <= 0))
  318. {
  319. //try to find iblock
  320. $rsIBlock = CIBlock::GetList(array(), array("CODE" => $iblockCode, "TYPE" => $iblockType, "SITE_ID" => $siteID));
  321. if ($arIBlock = $rsIBlock->Fetch())
  322. $iblockID = $arIBlock["ID"];
  323. else
  324. $iblockID = false;
  325. }
  326. //Set iblock permissions
  327. if ($iblockID > 0)
  328. {
  329. if (empty($permissions))
  330. $permissions = Array(1 => "X", 2 => "R");
  331. CIBlock::SetPermission($iblockID, $permissions);
  332. }
  333. return $iblockID;
  334. }
  335. function SetIBlockFormSettings($iblockID, $settings)
  336. {
  337. global $DBType;
  338. require_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/classes/".strtolower($DBType)."/favorites.php");
  339. CUserOptions::SetOption(
  340. "form",
  341. "form_element_".$iblockID,
  342. $settings,
  343. $common = true
  344. );
  345. }
  346. function SetUserOption($category, $option, $settings, $common = false, $userID = false)
  347. {
  348. global $DBType;
  349. require_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/classes/".strtolower($DBType)."/favorites.php");
  350. CUserOptions::SetOption(
  351. $category,
  352. $option,
  353. $settings,
  354. $common,
  355. $userID
  356. );
  357. }
  358. function CreateSectionProperty($iblockID, $fieldCode, $arFieldName = Array())
  359. {
  360. $entityID = "IBLOCK_".$iblockID."_SECTION";
  361. $dbField = CUserTypeEntity::GetList(Array(), array("ENTITY_ID" => $entityID, "FIELD_NAME" => $fieldCode));
  362. if ($arField = $dbField->Fetch())
  363. return $arField["ID"];
  364. $arFields = Array(
  365. "ENTITY_ID" => $entityID,
  366. "FIELD_NAME" => $fieldCode,
  367. "USER_TYPE_ID" => "string",
  368. "MULTIPLE" => "N",
  369. "MANDATORY" => "N",
  370. "EDIT_FORM_LABEL" => $arFieldName
  371. );
  372. $obUserField = new CUserTypeEntity;
  373. $fieldID = $obUserField->Add($arFields);
  374. $GLOBALS["USER_FIELD_MANAGER"]->arFieldsCache = array();
  375. return $fieldID;
  376. }
  377. function ReplaceMacrosRecursive($filePath, $arReplace)
  378. {
  379. CWizardUtil::ReplaceMacrosRecursive($filePath, $arReplace);
  380. }
  381. }
  382. ?>