BxBaseServices.php 52 KB

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