BxBaseServices.php 58 KB

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