1
0

BxBaseServices.php 50 KB

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