BxBaseServices.php 60 KB

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