BxBaseServices.php 47 KB

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