BxBaseServices.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  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. 'GetDataSearch' => '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. $oSearch = $this->_getSearchObject();
  819. $sCode = '';
  820. if (bx_get('keyword') !== false) {
  821. $sCode = $oSearch->response();
  822. if (!$sCode)
  823. $sCode = $oSearch->getEmptyResult();
  824. }
  825. return $sCode;
  826. }
  827. /**
  828. * @ref bx_system_general-get_date_search "get_date_search"
  829. * @api @ref bx_system_general-get_date_search "get_date_search"
  830. */
  831. public function serviceGetDataSearch ($aParams)
  832. {
  833. if(!bx_is_api())
  834. return false;
  835. $aParams = array_merge([
  836. 'keyword' => '',
  837. 'section' => '',
  838. 'start' => 0,
  839. 'per_page' => 12
  840. ], is_string($aParams) ? json_decode($aParams, true) : $aParams);
  841. if(!empty($aParams['section']))
  842. $aParams['section'] = explode(',', $aParams['section']);
  843. $sClass = 'BxTemplSearch';
  844. $oSearch = new $sClass($aParams['section']);
  845. $oSearch->setLiveSearch(true);
  846. $oSearch->setDataProcessing(true);
  847. $oSearch->setCustomSearchCondition(['keyword' => $aParams['keyword']]);
  848. $oSearch->setCustomCurrentCondition([
  849. 'paginate' => [
  850. 'start' => $aParams['start'],
  851. 'perPage' => $aParams['per_page'],
  852. ]
  853. ]);
  854. $aData = [];
  855. $aResponse = $oSearch->response();
  856. foreach($aResponse as $sSection => $aItems) {
  857. if(empty($aItems))
  858. continue;
  859. $aData = array_merge($aData, $aItems);
  860. }
  861. if(count($aData) > $aParams['per_page'])
  862. $aData = array_slice($aData, $aParams['start'], $aParams['per_page']);
  863. return [
  864. bx_api_get_block('browse', [
  865. 'unit' => 'search-results',
  866. 'request_url' => '/api.php?r=system/get_data_search/TemplServices&params[]=',
  867. 'params' => $aParams,
  868. 'data' => $aData
  869. ])
  870. ];
  871. }
  872. /**
  873. * @page service Service Calls
  874. * @section bx_system_general System Services
  875. * @subsection bx_system_general-general General
  876. * @subsubsection bx_system_general-cmts cmts
  877. *
  878. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  879. *
  880. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  881. *
  882. * Comments block
  883. * @param $sObject - comments object name
  884. * @param $sId - content id assiciated tith the comments
  885. *
  886. * @see BxBaseServices::serviceCmts
  887. */
  888. /**
  889. * @ref bx_system_general-cmts "cmts"
  890. */
  891. public function serviceCmts ($sObject, $sId)
  892. {
  893. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  894. if (!$o || !$o->isEnabled())
  895. return '';
  896. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  897. }
  898. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  899. {
  900. if (!$iContentId)
  901. return false;
  902. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  903. return false;
  904. return $oAccount->$sFunc(false, $aParams);
  905. }
  906. public function serviceAlertResponseProcessInstalled()
  907. {
  908. BxDolTranscoderImage::registerHandlersSystem();
  909. }
  910. public function serviceAlertResponseProcessStorageChange ($oAlert)
  911. {
  912. if ('sys_storage_default' != $oAlert->aExtras['option'])
  913. return;
  914. $aStorages = BxDolStorageQuery::getStorageObjects();
  915. foreach ($aStorages as $r) {
  916. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  917. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  918. }
  919. }
  920. public function serviceGetOptionsProfileBot()
  921. {
  922. $aResult = array(
  923. array('key' => '', 'value' => _t('_Select_one'))
  924. );
  925. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  926. foreach($aAccountsIds as $iAccountId) {
  927. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  928. foreach($aProfilesIds as $iProfileId) {
  929. $oProfile = BxDolProfile::getInstance($iProfileId);
  930. $aResult[] = array(
  931. 'key' => $iProfileId,
  932. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  933. );
  934. }
  935. }
  936. return $aResult;
  937. }
  938. public function serviceGetOptionsModuleListForPrivacySelector()
  939. {
  940. $aResult = array();
  941. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  942. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  943. foreach($aModules as $aModule){
  944. $oModule = BxDolModule::getInstance($aModule['name']);
  945. if($oModule instanceof iBxDolContentInfoService){
  946. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  947. continue;
  948. $aResult[$aModule['name']] = $aModule['title'];
  949. }
  950. }
  951. return $aResult;
  952. }
  953. public function serviceGetOptionsCaptchaDefault()
  954. {
  955. $aResults = [];
  956. $aObjects = BxDolCaptchaQuery::getObjects();
  957. foreach($aObjects as $aObject)
  958. $aResults[$aObject['object']] = $aObject['title'];
  959. return $aResults;
  960. }
  961. public function serviceGetOptionsEmbedDefault()
  962. {
  963. $aResults = array(
  964. '' => _t('_None')
  965. );
  966. $aObjects = BxDolEmbedQuery::getObjects();
  967. foreach($aObjects as $aObject)
  968. $aResults[$aObject['object']] = $aObject['title'];
  969. return $aResults;
  970. }
  971. public function serviceGetOptionsLocationFieldDefault()
  972. {
  973. $aResults = array();
  974. $aObjects = BxDolLocationFieldQuery::getObjects();
  975. foreach($aObjects as $aObject)
  976. $aResults[$aObject['object']] = _t($aObject['title']);
  977. return $aResults;
  978. }
  979. public function serviceGetOptionsLocationMapDefault()
  980. {
  981. $aResults = array();
  982. $aObjects = BxDolLocationMapQuery::getObjects();
  983. foreach($aObjects as $aObject)
  984. $aResults[$aObject['object']] = _t($aObject['title']);
  985. return $aResults;
  986. }
  987. public function serviceGetOptionsLocationLeafletGetProviders()
  988. {
  989. return BxDolLocationMapLeaflet::getProviders();
  990. }
  991. public function serviceGetOptionsRelations()
  992. {
  993. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  994. $aProfiles = array();
  995. foreach($aModules as $aModule) {
  996. $sMethod = 'act_as_profile';
  997. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  998. continue;
  999. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1000. }
  1001. $aResults = array();
  1002. foreach($aProfiles as $sName1 => $sTitle1)
  1003. foreach($aProfiles as $sName2 => $sTitle2)
  1004. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1005. return $aResults;
  1006. }
  1007. public function serviceGetOptionsCfProhibited()
  1008. {
  1009. return BxDolFormQuery::getDataItems('sys_content_filter');
  1010. }
  1011. public function serviceGetOptionsTaiwindDefault()
  1012. {
  1013. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1014. $aExcludes = ['.', '..', 'tailwind.css'];
  1015. $aResults = [];
  1016. if(($oHandle = opendir($sPath)) !== false) {
  1017. while(($sFile = readdir($oHandle)) !== false) {
  1018. if(in_array($sFile, $aExcludes))
  1019. continue;
  1020. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1021. continue;
  1022. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1023. $aResults[$sFile] = $sFile;
  1024. fclose($oHandlerFile);
  1025. }
  1026. closedir($oHandle);
  1027. }
  1028. return $aResults;
  1029. }
  1030. public function serviceGetOptionsApiMenuTop()
  1031. {
  1032. $aMenus = BxDolMenuQuery::getMenuObjects();
  1033. $aResults = [];
  1034. foreach($aMenus as $aMenu)
  1035. if($aMenu['module'] == 'system')
  1036. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1037. return $aResults;
  1038. }
  1039. public function serviceRedirect($sUrl = false)
  1040. {
  1041. if (false === $sUrl)
  1042. $sUrl = bx_get('url');
  1043. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1044. return MsgBox(_t('_error occured'));
  1045. }
  1046. else {
  1047. $bSpam = null;
  1048. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sUrl, 'where' => 'redirect'));
  1049. if (false === $bSpam) {
  1050. header('Location: ' . $sUrl);
  1051. }
  1052. elseif (true === $bSpam || null === $bSpam) {
  1053. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1054. 'text' => _t('_sys_redirect_confirmation', bx_process_output($sUrl), getParam('site_title')),
  1055. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1056. ]);
  1057. }
  1058. }
  1059. }
  1060. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1061. {
  1062. $sClass = '';
  1063. $sStyleFont = '';
  1064. $sStyleBg = '';
  1065. if ($aBadge['color'] == '')
  1066. $aBadge['color'] = 'purple-600';
  1067. if ($bIsCompact && $aBadge['icon'] != ''){
  1068. $aBadge['is_icon_only'] = 1;
  1069. }
  1070. if ($aBadge['is_icon_only'] == 1){
  1071. $sClass .= ' bx-badge-compact';
  1072. if (substr_count($aBadge['color'], 'rgb('))
  1073. $sStyleFont = 'color: ' . $aBadge['color'];
  1074. else
  1075. $sClass .= ' text-' . $aBadge['color'];
  1076. }
  1077. else{
  1078. if (substr_count($aBadge['color'], 'rgb('))
  1079. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1080. else
  1081. $sClass .= ' bg-' . $aBadge['color'];
  1082. }
  1083. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1084. 'bx_if:content' => array(
  1085. 'condition' => $aBadge['is_icon_only'] != '1',
  1086. 'content' => array('content' => _t($aBadge['text'])),
  1087. ),
  1088. 'bx_if:icon' => array(
  1089. 'condition' => $aBadge['icon'] != '',
  1090. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1091. ),
  1092. 'title' => $aBadge['text'],
  1093. 'style_font' => $sStyleFont,
  1094. 'style_bg' => $sStyleBg,
  1095. 'class' => $sClass,
  1096. )
  1097. );
  1098. }
  1099. private function _getSearchObject()
  1100. {
  1101. $sClass = 'BxTemplSearch';
  1102. $sElsName = 'bx_elasticsearch';
  1103. $sElsMethod = 'is_configured';
  1104. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1105. $oModule = BxDolModule::getInstance($sElsName);
  1106. bx_import('Search', $oModule->_aModule);
  1107. $sClass = 'BxElsSearch';
  1108. }
  1109. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  1110. $oSearch = new $sClass(bx_get('section'));
  1111. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1112. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1113. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1114. return $oSearch;
  1115. }
  1116. }
  1117. /** @} */