BxBaseServices.php 50 KB

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