BxBaseServices.php 52 KB

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