BxBaseServices.php 57 KB

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