BxBaseServices.php 49 KB

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