BxBaseServices.php 47 KB

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