BxBaseServices.php 49 KB

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