BxBaseServices.php 60 KB

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