BxBaseServices.php 53 KB

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