BxBaseServices.php 48 KB

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