BxBaseServices.php 56 KB

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