BxBaseServices.php 57 KB

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