BxBaseServices.php 49 KB

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