BxBaseServices.php 48 KB

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