BxBaseServices.php 48 KB

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