BxBaseServices.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services.
  11. */
  12. class BxBaseServices extends BxDol implements iBxDolProfileService
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceIsPublicService($s)
  19. {
  20. $sService = bx_gen_method_name($s);
  21. $aServices = $this->serviceGetPublicServices();
  22. return isset($aServices[$sService]);
  23. }
  24. public function serviceGetPublicServices()
  25. {
  26. return array (
  27. 'GetProductsNames' => 'BxBaseServices',
  28. 'GetPageByRequest' => 'BxBaseServicePages',
  29. );
  30. }
  31. public function serviceIsSafeService($s)
  32. {
  33. $sService = bx_gen_method_name($s);
  34. $aSafeServices = $this->serviceGetSafeServices();
  35. return isset($aSafeServices[$sService]);
  36. }
  37. public function serviceGetSafeServices()
  38. {
  39. return array(
  40. 'GetCreatePostForm' => 'BxBaseServices',
  41. 'GetProductsNames' => 'BxBaseServices',
  42. 'KeywordSearch' => 'BxBaseServices',
  43. 'GetDataSearchApi' => 'BxBaseServices',
  44. 'Cmts' => 'BxBaseServices',
  45. 'GetFooter' => 'BxBaseServices',
  46. 'CreateAccountForm' => 'BxBaseServiceAccount',
  47. 'AccountSettingsEmail' => 'BxBaseServiceAccount',
  48. 'AccountSettingsPassword' => 'BxBaseServiceAccount',
  49. 'AccountSettingsDelAccount' => 'BxBaseServiceAccount',
  50. 'AccountSettingsInfo' => 'BxBaseServiceAccount',
  51. 'ForgotPassword' => 'BxBaseServiceAccount',
  52. 'SwitchProfile' => 'BxBaseServiceAccount',
  53. 'AccountProfileSwitcher' => 'BxBaseServiceAccount',
  54. 'EmailConfirmation' => 'BxBaseServiceAccount',
  55. 'ConfirmEmail' => 'BxBaseServiceAccount',
  56. 'CategoriesList' => 'BxBaseServiceCategory',
  57. 'Test' => 'BxBaseServiceLogin',
  58. 'MemberAuthCode' => 'BxBaseServiceLogin',
  59. 'LoginForm' => 'BxBaseServiceLogin',
  60. 'LoginFormOnly' => 'BxBaseServiceLogin',
  61. 'Logout' => 'BxBaseServiceLogin',
  62. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  63. 'AccountProfileSwitcher' => 'BxBaseServiceProfiles',
  64. 'ProfileMembership' => 'BxBaseServiceProfiles',
  65. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  66. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  67. 'BrowseRecommendationsFriends' => 'BxBaseServiceProfiles',
  68. 'BrowseRecommendationsSubscriptions' => 'BxBaseServiceProfiles',
  69. 'BrowseFriends' => 'BxBaseServiceProfiles',
  70. 'BrowseFriendRequests' => 'BxBaseServiceProfiles',
  71. 'BrowseFriendRequested' => 'BxBaseServiceProfiles',
  72. 'BrowseSubscribedMe' => 'BxBaseServiceProfiles',
  73. 'BrowseSubscriptions' => 'BxBaseServiceProfiles',
  74. 'BrowseMembers' => 'BxBaseServiceProfiles',
  75. 'UpdateSettings' => 'BxBaseServiceProfiles',
  76. 'Befriend' => 'BxBaseServiceProfiles',
  77. 'GetChartGrowth' => 'BxBaseChartServices',
  78. 'GetChartStats' => 'BxBaseChartServices',
  79. 'GetDataByInterval' => 'BxBaseChartServices',
  80. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  81. 'GetOrdersCount' => 'BxBasePaymentsServices',
  82. 'Do' => 'BxBaseReportServices',
  83. 'GetPerformedBy' => 'BxBaseReportServices',
  84. 'Do' => 'BxBaseVoteServices',
  85. 'GetPerformedBy' => 'BxBaseVoteServices',
  86. 'Perform' => 'BxBaseServiceConnections',
  87. 'Perform' => 'BxBaseServiceRecommendations',
  88. 'GetDataApi' => 'BxBaseCmtsServices',
  89. 'GetDataApi' => 'BxBaseUploaderServices',
  90. 'GetStatBlock' => 'BxBaseDashboardServices',
  91. 'PerfomActionApi' => 'BxBaseServiceGrid',
  92. );
  93. }
  94. public function serviceGetPreloaderContent($sName) {
  95. $sResult = '';
  96. switch($sName) {
  97. case 'icons':
  98. $sResult = getParam('sys_css_icons_default');
  99. break;
  100. case 'tailwind':
  101. $sFile = getParam('sys_css_tailwind_default');
  102. if(empty($sFile))
  103. $sFile = 'tailwind.min.css';
  104. $sResult = '{dir_plugins_public}tailwind/css/|' . $sFile;
  105. break;
  106. }
  107. return $sResult;
  108. }
  109. /**
  110. * @page service Service Calls
  111. * @section bx_system_general System Services
  112. * @subsection bx_system_general-general General
  113. * @subsubsection bx_system_general-module_check_for_update module_check_for_update
  114. *
  115. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
  116. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
  117. * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
  118. *
  119. * Checks whether an update is available for requested module or not.
  120. * @param $mixedModule - module ID/name to check the updates for.
  121. * @return array with information about the update, false if nothing was found
  122. *
  123. * @see BxBaseServices::serviceModuleCheckForUpdate
  124. */
  125. /**
  126. * @ref bx_system_general-module_check_for_update "module_check_for_update"
  127. */
  128. public function serviceModuleCheckForUpdate($mixedModule)
  129. {
  130. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  131. if(empty($aModule) || !is_array($aModule))
  132. return false;
  133. $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
  134. if(empty($aUpdates) || !is_array($aUpdates))
  135. return false;
  136. $aUpdate = array_shift($aUpdates);
  137. return array(
  138. 'version_from' => $aUpdate['file_version'],
  139. 'version_to' => $aUpdate['file_version_to'],
  140. 'file_id' => $aUpdate['file_id']
  141. );
  142. }
  143. /**
  144. * @page service Service Calls
  145. * @section bx_system_general System Services
  146. * @subsection bx_system_general-general General
  147. * @subsubsection bx_system_general-module_update module_update
  148. *
  149. * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
  150. * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
  151. * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
  152. *
  153. * Download and install an update for requested module. The operation may be performed
  154. * immediately or by Transient Cron task. The second way is more common.
  155. * @param $mixedModule - module ID/name to check the updates for.
  156. * @return integer value determining the result of the operation. It can be one of the following values:
  157. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  158. *
  159. * @see BxBaseServices::serviceModuleUpdate
  160. */
  161. /**
  162. * @ref bx_system_general-module_update "module_update"
  163. */
  164. public function serviceModuleUpdate($mixedModule)
  165. {
  166. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  167. if(empty($aModule) || !is_array($aModule))
  168. return BX_DOL_STUDIO_IU_RC_FAILED;
  169. $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
  170. return $aResult['code'];
  171. }
  172. /**
  173. * @page service Service Calls
  174. * @section bx_system_general System Services
  175. * @subsection bx_system_general-general General
  176. * @subsubsection bx_system_general-module_delete module_delete
  177. *
  178. * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
  179. * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
  180. * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
  181. *
  182. * Delete the requested module. By default only uninstalled module can be deleted.
  183. * The operation may be performed immediately or by Transient Cron task. The second way is more common.
  184. * @param $sModule - module name to delete.
  185. * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
  186. * @return integer value determining the result of the operation. It can be one of the following values:
  187. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  188. *
  189. * @see BxBaseServices::serviceModuleDelete
  190. */
  191. /**
  192. * @ref bx_system_general-module_delete "module_delete"
  193. */
  194. public function serviceModuleDelete($sModule, $bForceUninstall = false)
  195. {
  196. $sModulePath = '';
  197. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  198. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
  199. if(!empty($aModule) && is_array($aModule)) {
  200. if(!$bForceUninstall)
  201. return BX_DOL_STUDIO_IU_RC_FAILED;
  202. $sModulePath = $aModule['path'];
  203. $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
  204. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  205. return BX_DOL_STUDIO_IU_RC_FAILED;
  206. }
  207. else {
  208. $aModules = $oInstallerUtils->getModules(false);
  209. if(!isset($aModules[$sModule]))
  210. return BX_DOL_STUDIO_IU_RC_FAILED;
  211. $sModulePath = $aModules[$sModule]['dir'];
  212. }
  213. $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
  214. return $aResult['code'];
  215. }
  216. /**
  217. * @page service Service Calls
  218. * @section bx_system_general System Services
  219. * @subsection bx_system_general-general General
  220. * @subsubsection bx_system_general-module_install module_install
  221. *
  222. * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
  223. * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
  224. * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
  225. *
  226. * Install the requested module. By default the module will be installed only.
  227. * @param $sModule - module name to install.
  228. * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
  229. * @return boolean value determining the result of the operation.
  230. *
  231. * @see BxBaseServices::serviceModuleInstall
  232. */
  233. /**
  234. * @ref bx_system_general-module_install "module_install"
  235. */
  236. public function serviceModuleInstall($sModule, $bForceEnable = false)
  237. {
  238. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  239. $aModules = $oInstallerUtils->getModules(false);
  240. if(!isset($aModules[$sModule]))
  241. return false;
  242. $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
  243. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  244. return false;
  245. return true;
  246. }
  247. /**
  248. * @page service Service Calls
  249. * @section bx_system_general System Services
  250. * @subsection bx_system_general-general General
  251. * @subsubsection bx_system_general-module_uninstall module_uninstall
  252. *
  253. * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
  254. * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
  255. * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
  256. *
  257. * Uninstall the requested module. By default only disabled module can be uninstalled.
  258. * @param $mixedModule - module ID/name to uninstall.
  259. * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
  260. * @return boolean value determining the result of the operation.
  261. *
  262. * @see BxBaseServices::serviceModuleUninstall
  263. */
  264. /**
  265. * @ref bx_system_general-module_uninstall "module_uninstall"
  266. */
  267. public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
  268. {
  269. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  270. if(empty($aModule) || !is_array($aModule))
  271. return false;
  272. if((int)$aModule['enabled'] != 0 && !$bForceDisable)
  273. return false;
  274. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
  275. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  276. return false;
  277. return true;
  278. }
  279. /**
  280. * @page service Service Calls
  281. * @section bx_system_general System Services
  282. * @subsection bx_system_general-general General
  283. * @subsubsection bx_system_general-module_enable module_enable
  284. *
  285. * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
  286. * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
  287. * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
  288. *
  289. * Enable the requested module.
  290. * @param $mixedModule - module ID/name to enable.
  291. * @return boolean value determining the result of the operation.
  292. *
  293. * @see BxBaseServices::serviceModuleEnable
  294. */
  295. /**
  296. * @ref bx_system_general-module_enable "module_enable"
  297. */
  298. public function serviceModuleEnable($mixedModule)
  299. {
  300. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  301. if(empty($aModule) || !is_array($aModule))
  302. return false;
  303. if((int)$aModule['enabled'] != 0)
  304. return false;
  305. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
  306. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  307. return false;
  308. return true;
  309. }
  310. /**
  311. * @page service Service Calls
  312. * @section bx_system_general System Services
  313. * @subsection bx_system_general-general General
  314. * @subsubsection bx_system_general-module_disable module_disable
  315. *
  316. * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
  317. * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
  318. * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
  319. *
  320. * Disable the requested module.
  321. * @param $mixedModule - module ID/name to disable.
  322. * @return boolean value determining the result of the operation.
  323. *
  324. * @see BxBaseServices::serviceModuleDisable
  325. */
  326. /**
  327. * @ref bx_system_general-module_disable "module_disable"
  328. */
  329. public function serviceModuleDisable($mixedModule)
  330. {
  331. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  332. if(empty($aModule) || !is_array($aModule))
  333. return false;
  334. if((int)$aModule['enabled'] == 0)
  335. return false;
  336. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
  337. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  338. return false;
  339. return true;
  340. }
  341. /**
  342. * @page service Service Calls
  343. * @section bx_system_general System Services
  344. * @subsection bx_system_general-general General
  345. * @subsubsection bx_system_general-is_module_installed is_module_installed
  346. *
  347. * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
  348. * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
  349. * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
  350. *
  351. * Checks whether the requested module is installed or not.
  352. * @param $mixedModule - module ID/name to check.
  353. * @return boolean value determining the result of the operation.
  354. *
  355. * @see BxBaseServices::serviceIsModuleInstalled
  356. */
  357. /**
  358. * @ref bx_system_general-is_module_installed "is_module_installed"
  359. */
  360. public function serviceIsModuleInstalled($mixedModule)
  361. {
  362. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  363. return !empty($aModule) && is_array($aModule);
  364. }
  365. /**
  366. * @page service Service Calls
  367. * @section bx_system_general System Services
  368. * @subsection bx_system_general-general General
  369. * @subsubsection bx_system_general-is_module_enabled is_module_enabled
  370. *
  371. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
  372. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
  373. * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
  374. *
  375. * Checks whether the requested module is enabled or not.
  376. * @param $mixedModule - module ID/name to check.
  377. * @return boolean value determining the result of the operation.
  378. *
  379. * @see BxBaseServices::serviceIsModuleEnabled
  380. */
  381. /**
  382. * @ref bx_system_general-is_module_enabled "is_module_enabled"
  383. */
  384. public function serviceIsModuleEnabled($mixedModule)
  385. {
  386. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  387. return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
  388. }
  389. /**
  390. * Checks whether a module is a 'Content' module or not.
  391. *
  392. * @param string $mixedModule - module name or an instance of Module class.
  393. * @return boolean result of operation.
  394. */
  395. public function serviceIsModuleContent($mixedModule)
  396. {
  397. if(is_string($mixedModule))
  398. $mixedModule = BxDolModule::getInstance($mixedModule);
  399. return
  400. $mixedModule instanceof BxDolModule &&
  401. $mixedModule instanceof iBxDolContentInfoService &&
  402. !($mixedModule instanceof iBxDolProfileService) &&
  403. BxDolRequest::serviceExists($mixedModule->_aModule, 'is_allowed_post_in_context') &&
  404. bx_srv($mixedModule->getName(), 'is_allowed_post_in_context');
  405. }
  406. /**
  407. * Checks whether a module is a 'Context' module or not.
  408. *
  409. * @param string $mixedModule - module name or an instance of Module class.
  410. * @return boolean result of operation.
  411. */
  412. public function serviceIsModuleContext($mixedModule)
  413. {
  414. if(is_string($mixedModule))
  415. $mixedModule = BxDolModule::getInstance($mixedModule);
  416. return $mixedModule instanceof BxDolModule && $mixedModule instanceof iBxDolProfileService;
  417. }
  418. /**
  419. * Checks whether a module is a 'Profile' module or not.
  420. *
  421. * @param string $mixedModule - module name or an instance of Module class.
  422. * @return boolean result of operation.
  423. */
  424. public function serviceIsModuleProfile($mixedModule)
  425. {
  426. if(is_string($mixedModule))
  427. $mixedModule = BxDolModule::getInstance($mixedModule);
  428. return $mixedModule instanceof BxDolModule && $mixedModule instanceof iBxDolProfileService && $mixedModule->serviceActAsProfile();
  429. }
  430. /**
  431. * Get modules by type. Available types are 'content', 'context', 'profile'.
  432. *
  433. * @param type $sType - string with type.
  434. * @return array of modules.
  435. */
  436. public function serviceGetModulesByType($sType, $aParams = [])
  437. {
  438. $aResults = [];
  439. $bIdAsKey = isset($aParams['id_as_key']) && $aParams['id_as_key'] === true;
  440. $bNameAsKey = !$bIdAsKey && isset($aParams['name_as_key']) && $aParams['name_as_key'] === true;
  441. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules', 'active' => 1]);
  442. foreach($aModules as $aModule) {
  443. $oModule = BxDolModule::getInstance($aModule['name']);
  444. if(!$oModule)
  445. continue;
  446. if($sType == 'content' && !$this->serviceIsModuleContent($oModule))
  447. continue;
  448. if($sType == 'context' && !$this->serviceIsModuleContext($oModule))
  449. continue;
  450. if($sType == 'profile' && !$this->serviceIsModuleProfile($oModule))
  451. continue;
  452. if($bIdAsKey)
  453. $aResults[$aModule['id']] = $aModule;
  454. else if($bNameAsKey)
  455. $aResults[$aModule['name']] = $aModule;
  456. else
  457. $aResults[] = $aModule;
  458. }
  459. return $aResults;
  460. }
  461. public function serviceProfileUnit ($iContentId, $aParams = array())
  462. {
  463. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  464. }
  465. public function serviceHasImage ($iContentId)
  466. {
  467. return false;
  468. }
  469. public function serviceProfilePicture ($iContentId)
  470. {
  471. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  472. }
  473. public function serviceProfileAvatar ($iContentId)
  474. {
  475. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  476. }
  477. public function serviceProfileCover ($iContentId)
  478. {
  479. return '';
  480. }
  481. public function serviceProfileEditUrl ($iContentId)
  482. {
  483. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info'));
  484. }
  485. public function serviceProfileThumb ($iContentId)
  486. {
  487. return $this->_serviceProfileFunc('getThumb', $iContentId);
  488. }
  489. public function serviceProfileIcon ($iContentId)
  490. {
  491. return $this->_serviceProfileFunc('getIcon', $iContentId);
  492. }
  493. public function serviceProfileName ($iContentId)
  494. {
  495. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  496. }
  497. public function serviceProfileUrl ($iContentId)
  498. {
  499. return $this->_serviceProfileFunc('getUrl', $iContentId);
  500. }
  501. /**
  502. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  503. */
  504. public function serviceCheckAllowedProfileView($iContentId)
  505. {
  506. return _t('_Access denied');
  507. }
  508. /**
  509. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  510. */
  511. public function serviceCheckAllowedProfileContact($iContentId)
  512. {
  513. return _t('_Access denied');
  514. }
  515. /**
  516. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  517. */
  518. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  519. {
  520. return _t('_Access denied');
  521. }
  522. /**
  523. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  524. */
  525. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  526. {
  527. return _t('_Access denied');
  528. }
  529. /**
  530. * @see iBxDolProfileService::serviceGetSpaceTitle
  531. */
  532. public function serviceGetSpaceTitle()
  533. {
  534. return '';
  535. }
  536. /**
  537. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  538. */
  539. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  540. {
  541. return array();
  542. }
  543. /**
  544. * @page service Service Calls
  545. * @section bx_system_general System Services
  546. * @subsection bx_system_general-general General
  547. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  548. *
  549. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  550. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  551. *
  552. * Get United Create Post form.
  553. * @param $mixedContextId - context which the post will be created in:
  554. * - false = 'Public' post form;
  555. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  556. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  557. * @param $sDefault - tab selected by default.
  558. * @param $aCustom - an array with custom paramaters.
  559. * @return string with form content
  560. *
  561. * @see BxBaseServices::serviceGetCreatePostForm
  562. */
  563. /**
  564. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  565. */
  566. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  567. {
  568. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  569. return '';
  570. $oProfile = BxDolProfile::getInstance();
  571. if(!$oProfile)
  572. return '';
  573. if($mixedContextId !== false)
  574. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  575. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  576. if(!$oMenu)
  577. return '';
  578. $oMenu->setContextId($mixedContextId);
  579. $aMenuItems = $oMenu->getMenuItems();
  580. if(empty($aMenuItems) || !is_array($aMenuItems))
  581. return '';
  582. if(empty($sDefault)) {
  583. $aDefault = array_shift($aMenuItems);
  584. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  585. }
  586. $oMenu->setSelected($sDefault, $sDefault);
  587. $bContext = $mixedContextId !== false;
  588. if($bContext && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($mixedContextId))))
  589. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $sDefault]) !== CHECK_ACTION_RESULT_ALLOWED)
  590. return '';
  591. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  592. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  593. $oDbModules = BxDolModuleQuery::getInstance();
  594. $oTemplate = BxDolTemplate::getInstance();
  595. $oTemplate->addJs(['BxDolCreatePost.js']);
  596. $aPreloadingList = [];
  597. $aModules = explode(',', getParam('sys_create_post_form_preloading_list'));
  598. if(!empty($aModules))
  599. foreach($aModules as $sModule) {
  600. $aModule = $oDbModules->getModuleByName($sModule);
  601. if(empty($aModule) || !is_array($aModule))
  602. continue;
  603. $aPreloadingList[$sModule] = $aModule['uri'];
  604. }
  605. if(bx_is_api()) {
  606. return [
  607. 'title' => $sTitle,
  608. 'content' => '',
  609. 'menu' => $oMenu->getCodeAPI()
  610. ];
  611. }
  612. $sJsObject = 'oBxDolCreatePost';
  613. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
  614. 'sObjName' => $sJsObject,
  615. 'sRootUrl' => BX_DOL_URL_ROOT,
  616. 'sDefault' => $sDefault,
  617. 'iContextId' => $bContext ? $mixedContextId : 0,
  618. 'oPreloadingList' => $aPreloadingList,
  619. 'oCustom' => $aCustom
  620. ]) . ");");
  621. return [
  622. 'title' => $sTitle,
  623. 'content' => $oTemplate->parseHtmlByName('create_post_form.html', [
  624. 'default' => $sDefault,
  625. 'placeholder' => $sPlaceholder,
  626. 'user_thumb' => $oProfile->getUnit(0, ['template' => 'unit_wo_info_links']),
  627. 'form' => bx_srv($sDefault, 'get_create_post_form', [[
  628. 'context_id' => $mixedContextId,
  629. 'ajax_mode' => true,
  630. 'absolute_action_url' => true,
  631. 'custom' => $aCustom
  632. ]]),
  633. 'js_object' => $sJsObject,
  634. 'js_content' => $sJsContent
  635. ]),
  636. 'menu' => $oMenu
  637. ];
  638. }
  639. public function serviceGetOptionsCreatePostFormPreloadingList()
  640. {
  641. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  642. if(!$oMenu)
  643. return [];
  644. $aMenuItems = $oMenu->getMenuItems();
  645. $aResult = [];
  646. foreach($aMenuItems as $aMenuItem) {
  647. $sModule = !empty($aMenuItem['module']) ? $aMenuItem['module'] : $aMenuItem['name'];
  648. if(!bx_srv('system', 'is_module_enabled', [$sModule]))
  649. continue;
  650. $aResult[] = [
  651. 'key' => $sModule,
  652. 'value' => _t('_' . $sModule)
  653. ];
  654. }
  655. return $aResult;
  656. }
  657. public function serviceGetBlockAuthor($sModule, $iContentId = 0)
  658. {
  659. if(!$iContentId && bx_get('id') !== false)
  660. $iContentId = (int)bx_get('id');
  661. $sMethodGetAuthor = 'get_author';
  662. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  663. return '';
  664. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  665. if(!$iAuthor)
  666. return '';
  667. $oAuthor = BxDolProfile::getInstance($iAuthor);
  668. if(!$oAuthor)
  669. return '';
  670. $sModuleAuthor = $oAuthor->getModule();
  671. $sMethodGetCover = 'entity_cover';
  672. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  673. return '';
  674. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  675. 'use_as_author' => true,
  676. 'show_text' => false
  677. ]]);
  678. }
  679. /**
  680. * @page service Service Calls
  681. * @section bx_system_general System Services
  682. * @subsection bx_system_general-general General
  683. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  684. *
  685. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  686. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  687. *
  688. * Get Site Submenu code.
  689. * @see BxBaseServices::serviceGetSiteSubmenu
  690. */
  691. /**
  692. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  693. */
  694. public function serviceGetSiteSubmenu()
  695. {
  696. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  697. return $oMenu ? $oMenu->getCode() : '';
  698. }
  699. /**
  700. * @page service Service Calls
  701. * @section bx_system_general System Services
  702. * @subsection bx_system_general-general General
  703. * @subsubsection bx_system_general-get_products_names get_products_names
  704. *
  705. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  706. *
  707. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  708. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  709. *
  710. * Get an array of products names from all modules with payments functionality.
  711. * @param $iVendorId filter products by vendor ID.
  712. * @param $iLimit limit number of records from one module.
  713. * @return array of products where key id product name and value is module name
  714. *
  715. * @see BxBaseServices::serviceGetProductsNames
  716. */
  717. /**
  718. * @ref bx_system_general-get_products_names "get_products_names"
  719. */
  720. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  721. {
  722. $o = BxDolPayments::getInstance();
  723. if (!$o)
  724. return array();
  725. return $o->getProductsNames($iVendorId, $iLimit);
  726. }
  727. /**
  728. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  729. */
  730. public function serviceCheckSpacePrivacy($iContentId)
  731. {
  732. return _t('_Access denied');
  733. }
  734. public function serviceFormsHelper ()
  735. {
  736. return new BxTemplAccountForms();
  737. }
  738. public function serviceActAsProfile ()
  739. {
  740. return false;
  741. }
  742. public function servicePrepareFields ($aFieldsProfile)
  743. {
  744. return $aFieldsProfile;
  745. }
  746. public function serviceProfilesSearch ($sTerm, $iLimit)
  747. {
  748. $oDb = BxDolAccountQuery::getInstance();
  749. $aRet = array();
  750. $a = $oDb->searchByTerm($sTerm, $iLimit);
  751. foreach ($a as $r)
  752. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  753. return $aRet;
  754. }
  755. /**
  756. * @page service Service Calls
  757. * @section bx_system_general System Services
  758. * @subsection bx_system_general-general General
  759. * @subsubsection bx_system_general-keyword_search keyword_search
  760. *
  761. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  762. *
  763. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  764. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  765. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  766. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  767. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  768. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  769. *
  770. * Search by keyword
  771. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  772. * @param $aCondition - condition for search, supported conditions:
  773. * - search by keyword: ["keyword" => "test"]
  774. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  775. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  776. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  777. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  778. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  779. * @param $sTemplate - template for displaying search results, for example: unit.html
  780. * @param $iStart - paginate, display records starting from this number
  781. * @param $iPerPage - paginate, display this number of records per page
  782. * @param $bLiveSearch - search results like in live search
  783. *
  784. * @see BxBaseServices::serviceKeywordSearch
  785. */
  786. /**
  787. * @ref bx_system_general-keyword_search "keyword_search"
  788. */
  789. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  790. {
  791. if (!$sSection || !isset($aCondition['keyword']))
  792. return '';
  793. $sClass = 'BxTemplSearch';
  794. $sElsName = 'bx_elasticsearch';
  795. $sElsMethod = 'is_configured';
  796. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  797. $oModule = BxDolModule::getInstance($sElsName);
  798. bx_import('Search', $oModule->_aModule);
  799. $sClass = 'BxElsSearch';
  800. }
  801. $oSearch = new $sClass(array($sSection));
  802. $oSearch->setLiveSearch($bLiveSearch);
  803. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  804. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  805. $oSearch->setCustomSearchCondition($aCondition);
  806. if (!$bPaginate)
  807. $oSearch->setRawProcessing(true);
  808. $oSearch->setCustomCurrentCondition(array(
  809. 'paginate' => array (
  810. 'start' => $iStart,
  811. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  812. )));
  813. if ($sTemplate)
  814. $oSearch->setUnitTemplate($sTemplate);
  815. return $oSearch->response();
  816. }
  817. /**
  818. * @page service Service Calls
  819. * @section bx_system_general System Services
  820. * @subsection bx_system_general-general General
  821. * @subsubsection bx_system_general-keyword_search keyword_search
  822. *
  823. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  824. *
  825. * Block with Search by Keywords Form
  826. *
  827. * @see BxBaseServices::serviceSearchKeywordForm
  828. */
  829. /**
  830. * @ref bx_system_general-keyword_search "keyword_search"
  831. */
  832. public function serviceSearchKeywordForm ()
  833. {
  834. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  835. }
  836. /**
  837. * @page service Service Calls
  838. * @section bx_system_general System Services
  839. * @subsection bx_system_general-general General
  840. * @subsubsection bx_system_general-keyword_search keyword_search
  841. *
  842. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  843. *
  844. * Block with Search by Keywords Results
  845. *
  846. * @see BxBaseServices::serviceSearchKeywordResult
  847. */
  848. /**
  849. * @ref bx_system_general-keyword_search "keyword_search"
  850. */
  851. public function serviceSearchKeywordResult ()
  852. {
  853. $sKeyword = bx_process_input(bx_get('keyword'));
  854. $bKeyword = $sKeyword !== false;
  855. if(bx_is_api())
  856. return $this->serviceGetDataSearchApi(['params' =>
  857. [
  858. 'keyword' => $sKeyword,
  859. 'section' => bx_process_input(bx_get('section')),
  860. 'cat' => bx_process_input(bx_get('cat'))
  861. ]
  862. ]);
  863. $sCode = '';
  864. if($bKeyword) {
  865. $oSearch = $this->_getSearchObject();
  866. $sCode = $oSearch->response();
  867. if(!$sCode)
  868. $sCode = $oSearch->getEmptyResult();
  869. }
  870. return $sCode;
  871. }
  872. /**
  873. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  874. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  875. */
  876. public function serviceGetDataSearchApi ($aParams)
  877. {
  878. if(!bx_is_api())
  879. return false;
  880. if(is_string($aParams))
  881. $aParams = json_decode($aParams, true);
  882. $aSections = [];
  883. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  884. 'sys_global_search_pairs',
  885. 'getPairs',
  886. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  887. 'name', 'title'
  888. );
  889. $aSectionNames = explode(',', getParam('sys_api_search_sections'));
  890. foreach($aSectionNames as $sSectionName) {
  891. if(!isset($aSectionsAll[$sSectionName]))
  892. continue;
  893. $aSections[$sSectionName] = [
  894. 'name' => $sSectionName,
  895. 'title' => _t($aSectionsAll[$sSectionName])
  896. ];
  897. }
  898. $aParamsBrowse = array_merge([
  899. 'keyword' => '',
  900. 'section' => '',
  901. 'sections' => array_values($aSections),
  902. 'start' => 0,
  903. 'per_page' => 12
  904. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  905. if(empty($aParamsBrowse['section']))
  906. $aParamsBrowse['section'] = array_keys($aSections);
  907. else if(is_string($aParamsBrowse['section']))
  908. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  909. $sClass = 'BxTemplSearch';
  910. $oSearch = new $sClass($aParamsBrowse['section']);
  911. $oSearch->setLiveSearch(true);
  912. $oSearch->setDataProcessing(true);
  913. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  914. $oSearch->setCustomCurrentCondition([
  915. 'paginate' => [
  916. 'forceStart' => $aParamsBrowse['start'],
  917. 'perPage' => $aParamsBrowse['per_page'],
  918. ]
  919. ]);
  920. $aData = $oSearch->response();
  921. if(count($aData) > $aParamsBrowse['per_page'])
  922. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  923. return [
  924. bx_api_get_block('browse', [
  925. 'unit' => 'search-results',
  926. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  927. 'params' => $aParamsBrowse,
  928. 'data' => $aData
  929. ])
  930. ];
  931. }
  932. /**
  933. * @page service Service Calls
  934. * @section bx_system_general System Services
  935. * @subsection bx_system_general-general General
  936. * @subsubsection bx_system_general-cmts cmts
  937. *
  938. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  939. *
  940. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  941. *
  942. * Comments block
  943. * @param $sObject - comments object name
  944. * @param $sId - content id assiciated tith the comments
  945. *
  946. * @see BxBaseServices::serviceCmts
  947. */
  948. /**
  949. * @ref bx_system_general-cmts "cmts"
  950. */
  951. public function serviceCmts ($sObject, $sId)
  952. {
  953. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  954. if (!$o || !$o->isEnabled())
  955. return '';
  956. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  957. }
  958. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  959. {
  960. if (!$iContentId)
  961. return false;
  962. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  963. return false;
  964. return $oAccount->$sFunc(false, $aParams);
  965. }
  966. public function serviceAlertResponseProcessInstalled()
  967. {
  968. BxDolTranscoderImage::registerHandlersSystem();
  969. }
  970. public function serviceAlertResponseProcessStorageChange ($oAlert)
  971. {
  972. if ('sys_storage_default' != $oAlert->aExtras['option'])
  973. return;
  974. $aStorages = BxDolStorageQuery::getStorageObjects();
  975. foreach ($aStorages as $r) {
  976. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  977. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  978. }
  979. }
  980. public function serviceGetOptionsProfileBot()
  981. {
  982. $aResult = array(
  983. array('key' => '', 'value' => _t('_Select_one'))
  984. );
  985. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  986. foreach($aAccountsIds as $iAccountId) {
  987. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  988. foreach($aProfilesIds as $iProfileId) {
  989. $oProfile = BxDolProfile::getInstance($iProfileId);
  990. $aResult[] = array(
  991. 'key' => $iProfileId,
  992. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  993. );
  994. }
  995. }
  996. return $aResult;
  997. }
  998. public function serviceGetOptionsModuleListForPrivacySelector()
  999. {
  1000. $aResult = array();
  1001. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  1002. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  1003. foreach($aModules as $aModule){
  1004. $oModule = BxDolModule::getInstance($aModule['name']);
  1005. if($oModule instanceof iBxDolContentInfoService){
  1006. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  1007. continue;
  1008. $aResult[$aModule['name']] = $aModule['title'];
  1009. }
  1010. }
  1011. return $aResult;
  1012. }
  1013. public function serviceGetOptionsCaptchaDefault()
  1014. {
  1015. $aResults = [];
  1016. $aObjects = BxDolCaptchaQuery::getObjects();
  1017. foreach($aObjects as $aObject)
  1018. $aResults[$aObject['object']] = $aObject['title'];
  1019. return $aResults;
  1020. }
  1021. public function serviceGetOptionsEmbedDefault()
  1022. {
  1023. $aResults = array(
  1024. '' => _t('_None')
  1025. );
  1026. $aObjects = BxDolEmbedQuery::getObjects();
  1027. foreach($aObjects as $aObject)
  1028. $aResults[$aObject['object']] = $aObject['title'];
  1029. return $aResults;
  1030. }
  1031. public function serviceGetOptionsLocationFieldDefault()
  1032. {
  1033. $aResults = array();
  1034. $aObjects = BxDolLocationFieldQuery::getObjects();
  1035. foreach($aObjects as $aObject)
  1036. $aResults[$aObject['object']] = _t($aObject['title']);
  1037. return $aResults;
  1038. }
  1039. public function serviceGetOptionsLocationMapDefault()
  1040. {
  1041. $aResults = array();
  1042. $aObjects = BxDolLocationMapQuery::getObjects();
  1043. foreach($aObjects as $aObject)
  1044. $aResults[$aObject['object']] = _t($aObject['title']);
  1045. return $aResults;
  1046. }
  1047. public function serviceGetOptionsSocketsFieldDefault()
  1048. {
  1049. $aResults = [];
  1050. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1051. foreach($aObjects as $sObject)
  1052. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1053. return $aResults;
  1054. }
  1055. public function serviceGetOptionsLocationLeafletGetProviders()
  1056. {
  1057. return BxDolLocationMapLeaflet::getProviders();
  1058. }
  1059. public function serviceGetOptionsRelations()
  1060. {
  1061. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1062. $aProfiles = array();
  1063. foreach($aModules as $aModule) {
  1064. $sMethod = 'act_as_profile';
  1065. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1066. continue;
  1067. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1068. }
  1069. $aResults = array();
  1070. foreach($aProfiles as $sName1 => $sTitle1)
  1071. foreach($aProfiles as $sName2 => $sTitle2)
  1072. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1073. return $aResults;
  1074. }
  1075. public function serviceGetOptionsCfProhibited()
  1076. {
  1077. return BxDolFormQuery::getDataItems('sys_content_filter');
  1078. }
  1079. public function serviceGetOptionsTaiwindDefault()
  1080. {
  1081. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1082. $aExcludes = ['.', '..', 'tailwind.css'];
  1083. $aResults = [];
  1084. if(($oHandle = opendir($sPath)) !== false) {
  1085. while(($sFile = readdir($oHandle)) !== false) {
  1086. if(in_array($sFile, $aExcludes))
  1087. continue;
  1088. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1089. continue;
  1090. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1091. $aResults[$sFile] = $sFile;
  1092. fclose($oHandlerFile);
  1093. }
  1094. closedir($oHandle);
  1095. }
  1096. return $aResults;
  1097. }
  1098. public function serviceGetOptionsApiMenuTop()
  1099. {
  1100. $aMenus = BxDolMenuQuery::getMenuObjects();
  1101. $aResults = ['' => _t('_sys_please_select')];
  1102. foreach($aMenus as $aMenu)
  1103. if($aMenu['module'] == 'system')
  1104. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1105. return $aResults;
  1106. }
  1107. public function serviceRedirect($sUrl = false)
  1108. {
  1109. if (!getParam('sys_confirmation_before_redirect')) {
  1110. BxDolTemplate::getInstance()->displayPageNotFound();
  1111. exit;
  1112. }
  1113. if (false === $sUrl)
  1114. $sUrl = bx_get('url');
  1115. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1116. http_response_code(500);
  1117. return MsgBox(_t('_error occured'));
  1118. }
  1119. else {
  1120. $bSpam = null;
  1121. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sUrl, 'where' => 'redirect'));
  1122. $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
  1123. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1124. 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
  1125. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1126. ]);
  1127. }
  1128. }
  1129. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1130. {
  1131. $sClass = '';
  1132. $sStyleFont = '';
  1133. $sStyleBg = '';
  1134. if ($aBadge['color'] == '')
  1135. $aBadge['color'] = 'purple-600';
  1136. if ($bIsCompact && $aBadge['icon'] != ''){
  1137. $aBadge['is_icon_only'] = 1;
  1138. }
  1139. if ($aBadge['is_icon_only'] == 1){
  1140. $sClass .= ' bx-badge-compact';
  1141. if (substr_count($aBadge['color'], 'rgb('))
  1142. $sStyleFont = 'color: ' . $aBadge['color'];
  1143. else
  1144. $sClass .= ' text-' . $aBadge['color'];
  1145. }
  1146. else{
  1147. if (substr_count($aBadge['color'], 'rgb('))
  1148. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1149. else
  1150. $sClass .= ' bg-' . $aBadge['color'];
  1151. }
  1152. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1153. 'bx_if:content' => array(
  1154. 'condition' => $aBadge['is_icon_only'] != '1',
  1155. 'content' => array('content' => _t($aBadge['text'])),
  1156. ),
  1157. 'bx_if:icon' => array(
  1158. 'condition' => $aBadge['icon'] != '',
  1159. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1160. ),
  1161. 'title' => $aBadge['text'],
  1162. 'style_font' => $sStyleFont,
  1163. 'style_bg' => $sStyleBg,
  1164. 'class' => $sClass,
  1165. )
  1166. );
  1167. }
  1168. public function serviceGetFooter()
  1169. {
  1170. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1171. }
  1172. private function _getSearchObject()
  1173. {
  1174. $sClass = 'BxTemplSearch';
  1175. $sElsName = 'bx_elasticsearch';
  1176. $sElsMethod = 'is_configured';
  1177. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1178. $oModule = BxDolModule::getInstance($sElsName);
  1179. bx_import('Search', $oModule->_aModule);
  1180. $sClass = 'BxElsSearch';
  1181. }
  1182. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  1183. $oSearch = new $sClass(bx_get('section'));
  1184. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1185. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1186. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1187. return $oSearch;
  1188. }
  1189. }
  1190. /** @} */