BxBaseServices.php 48 KB

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