BxBaseServices.php 47 KB

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