BxBaseServices.php 50 KB

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