BxBaseServices.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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. bx_api_get_block('get_create_post_form', [
  622. 'menu' => $oMenu->getCodeAPI(),
  623. 'params' => ['context_id' => $mixedContextId]])
  624. ]
  625. ];
  626. }
  627. $sJsObject = 'oBxDolCreatePost';
  628. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
  629. 'sObjName' => $sJsObject,
  630. 'sRootUrl' => BX_DOL_URL_ROOT,
  631. 'sDefault' => $sDefault,
  632. 'iContextId' => $bContext ? $mixedContextId : 0,
  633. 'oPreloadingList' => $aPreloadingList,
  634. 'oCustom' => $aCustom
  635. ]) . ");");
  636. return [
  637. 'title' => $sTitle,
  638. 'content' => $oTemplate->parseHtmlByName('create_post_form.html', [
  639. 'default' => $sDefault,
  640. 'placeholder' => $sPlaceholder,
  641. 'user_thumb' => $oProfile->getUnit(0, ['template' => 'unit_wo_info_links']),
  642. 'form' => bx_srv($sDefault, 'get_create_post_form', [[
  643. 'context_id' => $mixedContextId,
  644. 'ajax_mode' => true,
  645. 'absolute_action_url' => true,
  646. 'custom' => $aCustom
  647. ]]),
  648. 'js_object' => $sJsObject,
  649. 'js_content' => $sJsContent
  650. ]),
  651. 'menu' => $oMenu
  652. ];
  653. }
  654. public function serviceGetOptionsCreatePostFormPreloadingList()
  655. {
  656. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  657. if(!$oMenu)
  658. return [];
  659. $aMenuItems = $oMenu->getMenuItems();
  660. $aResult = [];
  661. foreach($aMenuItems as $aMenuItem) {
  662. $sModule = !empty($aMenuItem['module']) ? $aMenuItem['module'] : $aMenuItem['name'];
  663. if(!bx_srv('system', 'is_module_enabled', [$sModule]))
  664. continue;
  665. $aResult[] = [
  666. 'key' => $sModule,
  667. 'value' => _t('_' . $sModule)
  668. ];
  669. }
  670. return $aResult;
  671. }
  672. public function serviceGetBlockAuthor($sModule, $iContentId = 0)
  673. {
  674. if(!$iContentId && bx_get('id') !== false)
  675. $iContentId = (int)bx_get('id');
  676. $sMethodGetAuthor = 'get_author';
  677. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  678. return '';
  679. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  680. if(!$iAuthor)
  681. return '';
  682. $oAuthor = BxDolProfile::getInstance($iAuthor);
  683. if(!$oAuthor)
  684. return '';
  685. $sModuleAuthor = $oAuthor->getModule();
  686. $sMethodGetCover = 'entity_cover';
  687. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  688. return '';
  689. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  690. 'use_as_author' => true,
  691. 'show_text' => false
  692. ]]);
  693. }
  694. public function serviceGetBlockAskAssistant($aParams = [])
  695. {
  696. $iAssistant = BxDolAI::getAssistantForAskBlock();
  697. if(!$iAssistant)
  698. return '';
  699. return BxDolAIAssistant::getObjectInstance($iAssistant)->getAskBlock($aParams);
  700. }
  701. public function serviceGetMenu($aParams)
  702. {
  703. $bIsApi = bx_is_api();
  704. $mixedResulEmpty = $bIsApi ? [] : '';
  705. if($bIsApi && is_string($aParams))
  706. $aParams = bx_api_get_browse_params($aParams);
  707. if(!isset($aParams['object']))
  708. return $mixedResulEmpty;
  709. $oMenu = BxDolMenu::getObjectInstance($aParams['object']);
  710. if(!$oMenu)
  711. return $mixedResulEmpty;
  712. if(!empty($aParams['params']) && is_array($aParams['params']))
  713. $oMenu->setContentParams($aParams['params']);
  714. return $bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  715. }
  716. /**
  717. * @page service Service Calls
  718. * @section bx_system_general System Services
  719. * @subsection bx_system_general-general General
  720. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  721. *
  722. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  723. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  724. *
  725. * Get Site Submenu code.
  726. * @see BxBaseServices::serviceGetSiteSubmenu
  727. */
  728. /**
  729. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  730. */
  731. public function serviceGetSiteSubmenu()
  732. {
  733. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  734. return $oMenu ? $oMenu->getCode() : '';
  735. }
  736. /**
  737. * @page service Service Calls
  738. * @section bx_system_general System Services
  739. * @subsection bx_system_general-general General
  740. * @subsubsection bx_system_general-get_products_names get_products_names
  741. *
  742. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  743. *
  744. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  745. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  746. *
  747. * Get an array of products names from all modules with payments functionality.
  748. * @param $iVendorId filter products by vendor ID.
  749. * @param $iLimit limit number of records from one module.
  750. * @return array of products where key id product name and value is module name
  751. *
  752. * @see BxBaseServices::serviceGetProductsNames
  753. */
  754. /**
  755. * @ref bx_system_general-get_products_names "get_products_names"
  756. */
  757. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  758. {
  759. $o = BxDolPayments::getInstance();
  760. if (!$o)
  761. return array();
  762. return $o->getProductsNames($iVendorId, $iLimit);
  763. }
  764. /**
  765. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  766. */
  767. public function serviceCheckSpacePrivacy($iContentId)
  768. {
  769. return _t('_Access denied');
  770. }
  771. public function serviceFormsHelper ()
  772. {
  773. return new BxTemplAccountForms();
  774. }
  775. public function serviceActAsProfile ()
  776. {
  777. return false;
  778. }
  779. public function servicePrepareFields ($aFieldsProfile)
  780. {
  781. return $aFieldsProfile;
  782. }
  783. public function serviceProfilesSearch ($sTerm, $iLimit)
  784. {
  785. $oDb = BxDolAccountQuery::getInstance();
  786. $aRet = array();
  787. $a = $oDb->searchByTerm($sTerm, $iLimit);
  788. foreach ($a as $r)
  789. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  790. return $aRet;
  791. }
  792. /**
  793. * @page service Service Calls
  794. * @section bx_system_general System Services
  795. * @subsection bx_system_general-general General
  796. * @subsubsection bx_system_general-keyword_search keyword_search
  797. *
  798. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  799. *
  800. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  801. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  802. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  803. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  804. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  805. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  806. *
  807. * Search by keyword
  808. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  809. * @param $aCondition - condition for search, supported conditions:
  810. * - search by keyword: ["keyword" => "test"]
  811. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  812. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  813. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  814. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  815. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  816. * @param $sTemplate - template for displaying search results, for example: unit.html
  817. * @param $iStart - paginate, display records starting from this number
  818. * @param $iPerPage - paginate, display this number of records per page
  819. * @param $bLiveSearch - search results like in live search
  820. *
  821. * @see BxBaseServices::serviceKeywordSearch
  822. */
  823. /**
  824. * @ref bx_system_general-keyword_search "keyword_search"
  825. */
  826. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  827. {
  828. if (!$sSection || !isset($aCondition['keyword']))
  829. return '';
  830. $sClass = 'BxTemplSearch';
  831. $sElsName = 'bx_elasticsearch';
  832. $sElsMethod = 'is_configured';
  833. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  834. $oModule = BxDolModule::getInstance($sElsName);
  835. bx_import('Search', $oModule->_aModule);
  836. $sClass = 'BxElsSearch';
  837. }
  838. $oSearch = new $sClass(array($sSection));
  839. $oSearch->setLiveSearch($bLiveSearch);
  840. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  841. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  842. $oSearch->setCustomSearchCondition($aCondition);
  843. if (!$bPaginate)
  844. $oSearch->setRawProcessing(true);
  845. $oSearch->setCustomCurrentCondition(array(
  846. 'paginate' => array (
  847. 'start' => $iStart,
  848. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  849. )));
  850. if ($sTemplate)
  851. $oSearch->setUnitTemplate($sTemplate);
  852. return $oSearch->response();
  853. }
  854. /**
  855. * @page service Service Calls
  856. * @section bx_system_general System Services
  857. * @subsection bx_system_general-general General
  858. * @subsubsection bx_system_general-keyword_search keyword_search
  859. *
  860. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  861. *
  862. * Block with Search by Keywords Form
  863. *
  864. * @see BxBaseServices::serviceSearchKeywordForm
  865. */
  866. /**
  867. * @ref bx_system_general-keyword_search "keyword_search"
  868. */
  869. public function serviceSearchKeywordForm ()
  870. {
  871. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  872. }
  873. /**
  874. * @page service Service Calls
  875. * @section bx_system_general System Services
  876. * @subsection bx_system_general-general General
  877. * @subsubsection bx_system_general-keyword_search keyword_search
  878. *
  879. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  880. *
  881. * Block with Search by Keywords Results
  882. *
  883. * @see BxBaseServices::serviceSearchKeywordResult
  884. */
  885. /**
  886. * @ref bx_system_general-keyword_search "keyword_search"
  887. */
  888. public function serviceSearchKeywordResult ()
  889. {
  890. $sKeyword = bx_process_input(bx_get('keyword'));
  891. $bKeyword = $sKeyword !== false;
  892. if(bx_is_api())
  893. return $this->serviceGetDataSearchApi(['params' =>
  894. [
  895. 'keyword' => $sKeyword,
  896. 'section' => bx_process_input(bx_get('section')),
  897. 'cat' => bx_process_input(bx_get('cat'))
  898. ]
  899. ]);
  900. $sCode = '';
  901. if($bKeyword) {
  902. $oSearch = $this->_getSearchObject();
  903. $sCode = $oSearch->response();
  904. if(!$sCode)
  905. $sCode = $oSearch->getEmptyResult();
  906. }
  907. return $sCode;
  908. }
  909. /**
  910. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  911. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  912. */
  913. public function serviceGetDataSearchApi ($aParams)
  914. {
  915. if(!bx_is_api())
  916. return false;
  917. if(is_string($aParams))
  918. $aParams = json_decode($aParams, true);
  919. $aSections = [];
  920. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  921. 'sys_global_search_pairs',
  922. 'getPairs',
  923. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  924. 'name', 'title'
  925. );
  926. $aSectionNames = explode(',', getParam('sys_api_search_sections'));
  927. foreach($aSectionNames as $sSectionName) {
  928. if(!isset($aSectionsAll[$sSectionName]))
  929. continue;
  930. $aSections[$sSectionName] = [
  931. 'name' => $sSectionName,
  932. 'title' => _t($aSectionsAll[$sSectionName])
  933. ];
  934. }
  935. $aParamsBrowse = array_merge([
  936. 'keyword' => '',
  937. 'section' => '',
  938. 'sections' => array_values($aSections),
  939. 'start' => 0,
  940. 'per_page' => 12
  941. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  942. if(empty($aParamsBrowse['section']))
  943. $aParamsBrowse['section'] = array_keys($aSections);
  944. else if(is_string($aParamsBrowse['section']))
  945. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  946. $sClass = 'BxTemplSearch';
  947. $oSearch = new $sClass($aParamsBrowse['section']);
  948. $oSearch->setLiveSearch(true);
  949. $oSearch->setDataProcessing(true);
  950. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  951. $oSearch->setCustomCurrentCondition([
  952. 'paginate' => [
  953. 'forceStart' => $aParamsBrowse['start'],
  954. 'perPage' => $aParamsBrowse['per_page'],
  955. ]
  956. ]);
  957. $aData = $oSearch->response();
  958. if(count($aData) > $aParamsBrowse['per_page'])
  959. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  960. return [
  961. bx_api_get_block('browse', [
  962. 'unit' => 'search-results',
  963. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  964. 'params' => $aParamsBrowse,
  965. 'data' => $aData
  966. ])
  967. ];
  968. }
  969. /**
  970. * @page service Service Calls
  971. * @section bx_system_general System Services
  972. * @subsection bx_system_general-general General
  973. * @subsubsection bx_system_general-cmts cmts
  974. *
  975. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  976. *
  977. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  978. *
  979. * Comments block
  980. * @param $sObject - comments object name
  981. * @param $sId - content id assiciated tith the comments
  982. *
  983. * @see BxBaseServices::serviceCmts
  984. */
  985. /**
  986. * @ref bx_system_general-cmts "cmts"
  987. */
  988. public function serviceCmts ($sObject, $sId)
  989. {
  990. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  991. if (!$o || !$o->isEnabled())
  992. return '';
  993. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  994. }
  995. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  996. {
  997. if (!$iContentId)
  998. return false;
  999. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  1000. return false;
  1001. return $oAccount->$sFunc(false, $aParams);
  1002. }
  1003. public function serviceAlertResponseProcessInstalled()
  1004. {
  1005. BxDolTranscoderImage::registerHandlersSystem();
  1006. }
  1007. public function serviceAlertResponseProcessStorageChange ($oAlert)
  1008. {
  1009. if ('sys_storage_default' != $oAlert->aExtras['option'])
  1010. return;
  1011. $aStorages = BxDolStorageQuery::getStorageObjects();
  1012. foreach ($aStorages as $r) {
  1013. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  1014. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  1015. }
  1016. }
  1017. public function serviceGetOptionsProfileBot()
  1018. {
  1019. $aResult = array(
  1020. array('key' => '', 'value' => _t('_Select_one'))
  1021. );
  1022. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1023. foreach($aAccountsIds as $iAccountId) {
  1024. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1025. foreach($aProfilesIds as $iProfileId) {
  1026. $oProfile = BxDolProfile::getInstance($iProfileId);
  1027. $aResult[] = array(
  1028. 'key' => $iProfileId,
  1029. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  1030. );
  1031. }
  1032. }
  1033. return $aResult;
  1034. }
  1035. public function serviceGetOptionsModuleListForPrivacySelector()
  1036. {
  1037. $aResult = array();
  1038. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  1039. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  1040. foreach($aModules as $aModule){
  1041. $oModule = BxDolModule::getInstance($aModule['name']);
  1042. if($oModule instanceof iBxDolContentInfoService){
  1043. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  1044. continue;
  1045. $aResult[$aModule['name']] = $aModule['title'];
  1046. }
  1047. }
  1048. return $aResult;
  1049. }
  1050. public function serviceGetOptionsCaptchaDefault()
  1051. {
  1052. $aResults = [];
  1053. $aObjects = BxDolCaptchaQuery::getObjects();
  1054. foreach($aObjects as $aObject)
  1055. $aResults[$aObject['object']] = $aObject['title'];
  1056. return $aResults;
  1057. }
  1058. public function serviceGetOptionsEmbedDefault()
  1059. {
  1060. $aResults = array(
  1061. '' => _t('_None')
  1062. );
  1063. $aObjects = BxDolEmbedQuery::getObjects();
  1064. foreach($aObjects as $aObject)
  1065. $aResults[$aObject['object']] = $aObject['title'];
  1066. return $aResults;
  1067. }
  1068. public function serviceGetOptionsLocationFieldDefault()
  1069. {
  1070. $aResults = array();
  1071. $aObjects = BxDolLocationFieldQuery::getObjects();
  1072. foreach($aObjects as $aObject)
  1073. $aResults[$aObject['object']] = _t($aObject['title']);
  1074. return $aResults;
  1075. }
  1076. public function serviceGetOptionsLocationMapDefault()
  1077. {
  1078. $aResults = array();
  1079. $aObjects = BxDolLocationMapQuery::getObjects();
  1080. foreach($aObjects as $aObject)
  1081. $aResults[$aObject['object']] = _t($aObject['title']);
  1082. return $aResults;
  1083. }
  1084. public function serviceGetOptionsPushDefault()
  1085. {
  1086. $aResults = [
  1087. '' => _t('_None')
  1088. ];
  1089. $aObjects = BxDolPushQuery::getObjects();
  1090. foreach($aObjects as $aObject)
  1091. $aResults[$aObject['object']] = $aObject['title'];
  1092. return $aResults;
  1093. }
  1094. public function serviceGetOptionsSmsDefault()
  1095. {
  1096. $aResults = [
  1097. '' => _t('_None')
  1098. ];
  1099. $aObjects = BxDolSmsQuery::getObjects();
  1100. foreach($aObjects as $aObject)
  1101. $aResults[$aObject['object']] = $aObject['title'];
  1102. return $aResults;
  1103. }
  1104. public function serviceGetOptionsSocketsFieldDefault()
  1105. {
  1106. $aResults = [];
  1107. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1108. foreach($aObjects as $sObject)
  1109. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1110. return $aResults;
  1111. }
  1112. public function serviceGetOptionsLocationLeafletGetProviders()
  1113. {
  1114. return BxDolLocationMapLeaflet::getProviders();
  1115. }
  1116. public function serviceGetOptionsRelations()
  1117. {
  1118. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1119. $aProfiles = array();
  1120. foreach($aModules as $aModule) {
  1121. $sMethod = 'act_as_profile';
  1122. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1123. continue;
  1124. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1125. }
  1126. $aResults = array();
  1127. foreach($aProfiles as $sName1 => $sTitle1)
  1128. foreach($aProfiles as $sName2 => $sTitle2)
  1129. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1130. return $aResults;
  1131. }
  1132. public function serviceGetOptionsCfProhibited()
  1133. {
  1134. return BxDolFormQuery::getDataItems('sys_content_filter');
  1135. }
  1136. public function serviceGetOptionsCfUnauthenticated()
  1137. {
  1138. return BxDolFormQuery::getDataItems('sys_content_filter');
  1139. }
  1140. public function serviceGetOptionsTaiwindDefault()
  1141. {
  1142. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1143. $aExcludes = ['.', '..', 'tailwind.css'];
  1144. $aResults = [];
  1145. if(($oHandle = opendir($sPath)) !== false) {
  1146. while(($sFile = readdir($oHandle)) !== false) {
  1147. if(in_array($sFile, $aExcludes))
  1148. continue;
  1149. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1150. continue;
  1151. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1152. $aResults[$sFile] = $sFile;
  1153. fclose($oHandlerFile);
  1154. }
  1155. closedir($oHandle);
  1156. }
  1157. return $aResults;
  1158. }
  1159. public function serviceGetOptionsApiMenuTop()
  1160. {
  1161. $aMenus = BxDolMenuQuery::getMenuObjects();
  1162. $aResults = ['' => _t('_sys_please_select')];
  1163. foreach($aMenus as $aMenu)
  1164. if($aMenu['module'] == 'system')
  1165. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1166. return $aResults;
  1167. }
  1168. public function serviceGetOptionsAgentsModel()
  1169. {
  1170. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getModels(['active' => true, 'hidden' => false]);
  1171. }
  1172. public function serviceGetOptionsAgentsProfile($bSelectOne = true)
  1173. {
  1174. $aResult = [];
  1175. if($bSelectOne)
  1176. $aResult[] = ['key' => '', 'value' => _t('_Select_one')];
  1177. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1178. foreach($aAccountsIds as $iAccountId) {
  1179. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1180. foreach($aProfilesIds as $iProfileId)
  1181. if(($oProfile = BxDolProfile::getInstance($iProfileId)) !== false && ($sProfileModule = $oProfile->getModule()) != 'system')
  1182. $aResult[] = [
  1183. 'key' => $iProfileId,
  1184. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), _t('_' . $sProfileModule))
  1185. ];
  1186. }
  1187. return $aResult;
  1188. }
  1189. public function serviceGetOptionsStudioAssistant()
  1190. {
  1191. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1192. }
  1193. public function serviceGetOptionsLiveSearchAssistant()
  1194. {
  1195. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1196. }
  1197. public function serviceGetOptionsAskBlockAssistant()
  1198. {
  1199. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1200. }
  1201. public function serviceRedirect($sUrl = false)
  1202. {
  1203. if (!getParam('sys_confirmation_before_redirect')) {
  1204. BxDolTemplate::getInstance()->displayPageNotFound();
  1205. exit;
  1206. }
  1207. if (false === $sUrl)
  1208. $sUrl = bx_get('url');
  1209. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1210. http_response_code(500);
  1211. return MsgBox(_t('_error occured'));
  1212. }
  1213. else {
  1214. $bSpam = null;
  1215. /**
  1216. * @hooks
  1217. * @hookdef hook-system-check_spam_url 'system', 'check_spam_url' - hook to override sClass for search
  1218. * - $unit_name - equals `system`
  1219. * - $action - equals `check_spam_url`
  1220. * - $object_id - not used
  1221. * - $sender_id - logged account id
  1222. * - $extra_params - array of additional params with the following array keys:
  1223. * - `is_spam` - [bool] by ref, spam url or not, can be overridden in hook processing
  1224. * - `content` - [string] by ref, url of link, can be overridden in hook processing
  1225. * - `where` - [string] equal redirect
  1226. * @hook @ref hook-system-check_spam_url
  1227. */
  1228. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sUrl, 'where' => 'redirect'));
  1229. $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
  1230. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1231. 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
  1232. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1233. ]);
  1234. }
  1235. }
  1236. public function serviceSetBadges($iContentId, $sBadgesIds, $sModule)
  1237. {
  1238. $aSelectedBadges = explode(",", $sBadgesIds);
  1239. $iPerformerId = bx_get_logged_profile_id();
  1240. $aCheck = checkActionModule($iPerformerId, 'set badge', 'system', false);
  1241. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1242. return false;
  1243. $oBadges = BxDolBadges::getInstance();
  1244. $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => $iContentId, 'module' => $sModule));
  1245. foreach ($aBadges as $aBadge) {
  1246. if (isset($aBadge['badge_id'])){
  1247. $oBadges->delete($aBadge['badge_id']);
  1248. }
  1249. }
  1250. foreach ($aSelectedBadges as $iSelectedBadge) {
  1251. $oBadges->add($iSelectedBadge, $iContentId, $sModule);
  1252. }
  1253. checkActionModule($iPerformerId, 'set badge', 'system', true); // perform action
  1254. return true;
  1255. }
  1256. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1257. {
  1258. $sClass = '';
  1259. $sStyleFont = '';
  1260. $sStyleBg = '';
  1261. if ($aBadge['color'] == '')
  1262. $aBadge['color'] = 'purple-600';
  1263. if ($bIsCompact && $aBadge['icon'] != ''){
  1264. $aBadge['is_icon_only'] = 1;
  1265. }
  1266. if ($aBadge['is_icon_only'] == 1){
  1267. $sClass .= ' bx-badge-compact';
  1268. if (substr_count($aBadge['color'], 'rgb('))
  1269. $sStyleFont = 'color: ' . $aBadge['color'];
  1270. else
  1271. $sClass .= ' text-' . $aBadge['color'];
  1272. }
  1273. else{
  1274. if (substr_count($aBadge['color'], 'rgb('))
  1275. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1276. else
  1277. $sClass .= ' bg-' . $aBadge['color'];
  1278. }
  1279. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1280. 'bx_if:content' => array(
  1281. 'condition' => $aBadge['is_icon_only'] != '1',
  1282. 'content' => array('content' => _t($aBadge['text'])),
  1283. ),
  1284. 'bx_if:icon' => array(
  1285. 'condition' => $aBadge['icon'] != '',
  1286. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1287. ),
  1288. 'title' => $aBadge['text'],
  1289. 'style_font' => $sStyleFont,
  1290. 'style_bg' => $sStyleBg,
  1291. 'class' => $sClass,
  1292. )
  1293. );
  1294. }
  1295. public function serviceGetFooter()
  1296. {
  1297. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1298. }
  1299. private function _getSearchObject()
  1300. {
  1301. $sClass = 'BxTemplSearch';
  1302. $sElsName = 'bx_elasticsearch';
  1303. $sElsMethod = 'is_configured';
  1304. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1305. $oModule = BxDolModule::getInstance($sElsName);
  1306. bx_import('Search', $oModule->_aModule);
  1307. $sClass = 'BxElsSearch';
  1308. }
  1309. /**
  1310. * @hooks
  1311. * @hookdef hook-system-search_keyword 'system', 'search_keyword' - hook to override sClass for search
  1312. * - $unit_name - equals `system`
  1313. * - $action - equals `search_keyword`
  1314. * - $object_id - not used
  1315. * - $sender_id - not used
  1316. * - $extra_params - array of additional params with the following array keys:
  1317. * - `override_result` - [string] by ref, class name for search, can be overridden in hook processing
  1318. * @hook @ref hook-system-search_keyword
  1319. */
  1320. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  1321. $oSearch = new $sClass(bx_get('section'));
  1322. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1323. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1324. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1325. return $oSearch;
  1326. }
  1327. }
  1328. /** @} */