BxBaseServices.php 54 KB

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