BxBaseServices.php 50 KB

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