PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/bitrix/wizards/bitrix/demo/scripts/utils.php

https://gitlab.com/Rad1calDreamer/honey
PHP | 225 lines | 179 code | 45 blank | 1 comment | 46 complexity | 398473b956a9ba1cfaf2f4c20e313a3e MD5 | raw file
  1. <?
  2. class DemoSiteUtil
  3. {
  4. function GetServices($servicePath, $arFilter = Array())
  5. {
  6. $arServices = Array();
  7. include($servicePath.".services.php");
  8. if (empty($arServices))
  9. return $arServices;
  10. $servicePosition = 1;
  11. foreach ($arServices as $serviceID => $arService)
  12. {
  13. if (isset($arFilter["SKIP_INSTALL_ONLY"]) && array_key_exists("INSTALL_ONLY", $arService) && $arService["INSTALL_ONLY"] == $arFilter["SKIP_INSTALL_ONLY"])
  14. {
  15. unset($arServices[$serviceID]);
  16. continue;
  17. }
  18. if (isset($arFilter["SERVICES"]) && is_array($arFilter["SERVICES"]) && !in_array($serviceID, $arFilter["SERVICES"]) && !array_key_exists("INSTALL_ONLY", $arService))
  19. {
  20. unset($arServices[$serviceID]);
  21. continue;
  22. }
  23. //Check service dependencies
  24. $modulesCheck = Array($serviceID);
  25. if (array_key_exists("MODULE_ID", $arService))
  26. $modulesCheck = (is_array($arService["MODULE_ID"]) ? $arService["MODULE_ID"] : Array($arService["MODULE_ID"]));
  27. foreach ($modulesCheck as $moduleID)
  28. {
  29. if (!IsModuleInstalled($moduleID))
  30. {
  31. unset($arServices[$serviceID]);
  32. continue 2;
  33. }
  34. }
  35. $arServices[$serviceID]["POSITION"] = $servicePosition;
  36. $servicePosition += (isset($arService["STAGES"]) && !empty($arService["STAGES"]) ? count($arService["STAGES"]) : 1);
  37. }
  38. return $arServices;
  39. }
  40. function GetSelectedServices($string)
  41. {
  42. $arServices = Array();
  43. $arRootCnt = Array();
  44. if (strlen($string) <= 0)
  45. return $arServices;
  46. $arItems = explode(";", $string);
  47. foreach ($arItems as $itemPathID)
  48. {
  49. if (strlen($itemPathID) <= 0)
  50. continue;
  51. @list($itemID, $rootPathID) = explode(":", $itemPathID);
  52. if ( ($position = strrpos($itemID, "-")) !== false)
  53. $itemID = substr($itemID, $position+1);
  54. if ($rootPathID)
  55. {
  56. if ( ($position = strrpos($rootPathID, "-")) !== false)
  57. $rootPathID = substr($rootPathID, $position+1);
  58. if (array_key_exists($rootPathID, $arRootCnt))
  59. $rootPathID .= $arRootCnt[$rootPathID];
  60. $itemPath = "/".$rootPathID."/".$itemID;
  61. }
  62. else
  63. {
  64. if (array_key_exists($itemID, $arRootCnt))
  65. $arRootCnt[$itemID] += 1;
  66. else
  67. $arRootCnt[$itemID] = "";
  68. $itemPath = "/".$itemID.$arRootCnt[$itemID];
  69. }
  70. if (!array_key_exists($itemID, $arServices))
  71. $arServices[$itemID] = Array();
  72. $number = 1;
  73. $currentItemPath = $itemPath;
  74. while (array_search($currentItemPath, $arServices[$itemID]) !== false)
  75. $currentItemPath = $itemPath.$number++;
  76. $arServices[$itemID][] = $currentItemPath;
  77. }
  78. return $arServices;
  79. }
  80. function GetThemes($themePath)
  81. {
  82. $arThemes = Array();
  83. if (!is_dir($themePath))
  84. return $arThemes;
  85. if ($handle = @opendir($themePath))
  86. {
  87. while (($file = readdir($handle)) !== false)
  88. {
  89. if ($file == "." || $file == ".." || !is_dir($themePath."/".$file))
  90. continue;
  91. $arTemplate = Array();
  92. if (is_file($themePath."/".$file."/description.php"))
  93. @include($themePath."/".$file."/description.php");
  94. $arThemes[$file] = $arTemplate + Array(
  95. "ID" => $file,
  96. "SORT" => (isset($arTemplate["SORT"]) && intval($arTemplate["SORT"]) > 0 ? intval($arTemplate["SORT"]) : 10),
  97. "NAME" => (isset($arTemplate["NAME"]) ? $arTemplate["NAME"] : $file),
  98. "PREVIEW" => (file_exists($themePath."/".$file."/preview.gif")),
  99. "SCREENSHOT" => (file_exists($themePath."/".$file."/screen.gif")),
  100. );
  101. }
  102. @closedir($handle);
  103. }
  104. uasort($arThemes, Array("DemoSiteUtil", "__SortTheme"));
  105. return $arThemes;
  106. }
  107. function __SortTheme($a, $b)
  108. {
  109. if ($a["SORT"] > $b["SORT"])
  110. return 1;
  111. elseif ($a["SORT"] < $b["SORT"])
  112. return -1;
  113. else
  114. return 0;
  115. }
  116. function SetFilePermission($path, $permissions)
  117. {
  118. $originalPath = $path;
  119. CMain::InitPathVars($site, $path);
  120. $documentRoot = CSite::GetSiteDocRoot($site);
  121. $path = rtrim($path, "/");
  122. if (strlen($path) <= 0)
  123. $path = "/";
  124. if( ($position = strrpos($path, "/")) !== false)
  125. {
  126. $pathFile = substr($path, $position+1);
  127. $pathDir = substr($path, 0, $position);
  128. }
  129. else
  130. return false;
  131. if ($pathFile == "" && $pathDir == "")
  132. $pathFile = "/";
  133. $PERM = Array();
  134. if(file_exists($documentRoot.$pathDir."/.access.php"))
  135. @include($documentRoot.$pathDir."/.access.php");
  136. if (!isset($PERM[$pathFile]) || !is_array($PERM[$pathFile]))
  137. $arPermisson = $permissions;
  138. else
  139. $arPermisson = $PERM[$pathFile] + $permissions;
  140. return $GLOBALS["APPLICATION"]->SetFileAccessPermission($originalPath, $arPermisson);
  141. }
  142. function AddMenuItem($menuFile, $menuItem)
  143. {
  144. if(CModule::IncludeModule('fileman'))
  145. {
  146. $arResult = CFileMan::GetMenuArray($_SERVER["DOCUMENT_ROOT"].$menuFile);
  147. $arMenuItems = $arResult["aMenuLinks"];
  148. $menuTemplate = $arResult["sMenuTemplate"];
  149. $bFound = false;
  150. foreach($arMenuItems as $item)
  151. if($item[1] == $menuItem[1])
  152. $bFound = true;
  153. if(!$bFound)
  154. {
  155. $arMenuItems[] = $menuItem;
  156. CFileMan::SaveMenu(Array("s1", $menuFile), $arMenuItems, $menuTemplate);
  157. }
  158. }
  159. }
  160. function GetTemplatesPath($wizardPath)
  161. {
  162. $templatesPath = $wizardPath."/templates";
  163. if (file_exists($_SERVER["DOCUMENT_ROOT"].$templatesPath."/".LANGUAGE_ID))
  164. $templatesPath .= "/".LANGUAGE_ID;
  165. return $templatesPath;
  166. }
  167. function SetUserOption($category, $option, $settings, $common = false, $userID = false)
  168. {
  169. global $DBType;
  170. require_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/classes/".strtolower($DBType)."/favorites.php");
  171. CUserOptions::SetOption(
  172. $category,
  173. $option,
  174. $settings,
  175. $common,
  176. $userID
  177. );
  178. }
  179. }
  180. ?>