BxBaseServices.php 52 KB

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