BxBaseServices.php 50 KB

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