BxBaseServices.php 54 KB

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