BxBaseServices.php 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  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. 'GetMenu' => 'BxBaseServices',
  41. 'GetCreatePostForm' => 'BxBaseServices',
  42. 'GetProductsNames' => 'BxBaseServices',
  43. 'KeywordSearch' => 'BxBaseServices',
  44. 'GetDataSearchApi' => 'BxBaseServices',
  45. 'Cmts' => 'BxBaseServices',
  46. 'GetFooter' => 'BxBaseServices',
  47. 'SetBadges' => 'BxBaseServices',
  48. 'GetPageContentByRequest' => 'BxBaseServicePages',
  49. 'GetPageBlockData' => 'BxBaseServicePages',
  50. 'SetPageBlockData' => 'BxBaseServicePages',
  51. 'GetUrlInfo' => 'BxBaseServicePages',
  52. 'CreateAccountForm' => 'BxBaseServiceAccount',
  53. 'AccountSettingsEmail' => 'BxBaseServiceAccount',
  54. 'AccountSettingsPassword' => 'BxBaseServiceAccount',
  55. 'AccountSettingsDelAccount' => 'BxBaseServiceAccount',
  56. 'AccountSettingsInfo' => 'BxBaseServiceAccount',
  57. 'ForgotPassword' => 'BxBaseServiceAccount',
  58. 'SwitchProfile' => 'BxBaseServiceAccount',
  59. 'AccountProfileSwitcher' => 'BxBaseServiceAccount',
  60. 'EmailConfirmation' => 'BxBaseServiceAccount',
  61. 'ConfirmEmail' => 'BxBaseServiceAccount',
  62. 'CategoriesList' => 'BxBaseServiceCategory',
  63. 'Test' => 'BxBaseServiceLogin',
  64. 'MemberAuthCode' => 'BxBaseServiceLogin',
  65. 'LoginForm' => 'BxBaseServiceLogin',
  66. 'LoginFormOnly' => 'BxBaseServiceLogin',
  67. 'Logout' => 'BxBaseServiceLogin',
  68. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  69. 'AccountProfileSwitcher' => 'BxBaseServiceProfiles',
  70. 'ProfileMembership' => 'BxBaseServiceProfiles',
  71. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  72. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  73. 'BrowseRecommendationsFriends' => 'BxBaseServiceProfiles',
  74. 'BrowseRecommendationsSubscriptions' => 'BxBaseServiceProfiles',
  75. 'BrowseFriends' => 'BxBaseServiceProfiles',
  76. 'SetMembership' => 'BxBaseServiceProfiles',
  77. 'BrowseFriendRequests' => 'BxBaseServiceProfiles',
  78. 'BrowseFriendRequested' => 'BxBaseServiceProfiles',
  79. 'BrowseSubscribedMe' => 'BxBaseServiceProfiles',
  80. 'BrowseSubscriptions' => 'BxBaseServiceProfiles',
  81. 'BrowseMembers' => 'BxBaseServiceProfiles',
  82. 'BrowseInvitations' => 'BxBaseServiceProfiles',
  83. 'UpdateSettings' => 'BxBaseServiceProfiles',
  84. 'Befriend' => 'BxBaseServiceProfiles',
  85. 'ProfileCounters' => 'BxBaseServiceProfiles',
  86. 'ProfileInfo' => 'BxBaseServiceProfiles',
  87. 'GetChartGrowth' => 'BxBaseChartServices',
  88. 'GetChartStats' => 'BxBaseChartServices',
  89. 'GetDataByInterval' => 'BxBaseChartServices',
  90. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  91. 'GetOrdersCount' => 'BxBasePaymentsServices',
  92. 'Do' => 'BxBaseReportServices',
  93. 'GetPerformedBy' => 'BxBaseReportServices',
  94. 'Do' => 'BxBaseVoteServices',
  95. 'GetPerformedBy' => 'BxBaseVoteServices',
  96. 'Perform' => 'BxBaseFeatureServices',
  97. 'Perform' => 'BxBaseFavoriteServices',
  98. 'GetPerformedBy' => 'BxBaseFavoriteServices',
  99. 'Perform' => 'BxBaseServiceConnections',
  100. 'Perform' => 'BxBaseServiceRecommendations',
  101. 'GetDataApi' => 'BxBaseCmtsServices',
  102. 'GetDataApi' => 'BxBaseUploaderServices',
  103. 'GetStatBlock' => 'BxBaseDashboardServices',
  104. 'PerfomActionApi' => 'BxBaseServiceGrid',
  105. 'GetLabels' => 'BxBaseLabelsServices',
  106. 'GetForm' => 'BxBaseSearchExtendedServices',
  107. 'GetResults' => 'BxBaseSearchExtendedServices'
  108. );
  109. }
  110. public function serviceGetPreloaderContent($sName) {
  111. $sResult = '';
  112. switch($sName) {
  113. case 'icons_css':
  114. if(($sCss = BxDolIconset::getObjectInstance()->getPreloaderCss()) !== false)
  115. $sResult = $sCss;
  116. break;
  117. case 'icons_js':
  118. if(($sJs = BxDolIconset::getObjectInstance()->getPreloaderJs()) !== false)
  119. $sResult = $sJs;
  120. break;
  121. case 'tailwind':
  122. $sFile = getParam('sys_css_tailwind_default');
  123. if(empty($sFile))
  124. $sFile = 'tailwind.min.css';
  125. $sResult = '{dir_plugins_public}tailwind/css/|' . $sFile;
  126. break;
  127. }
  128. return $sResult;
  129. }
  130. /**
  131. * @page service Service Calls
  132. * @section bx_system_general System Services
  133. * @subsection bx_system_general-general General
  134. * @subsubsection bx_system_general-module_check_for_update module_check_for_update
  135. *
  136. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
  137. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
  138. * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
  139. *
  140. * Checks whether an update is available for requested module or not.
  141. * @param $mixedModule - module ID/name to check the updates for.
  142. * @return array with information about the update, false if nothing was found
  143. *
  144. * @see BxBaseServices::serviceModuleCheckForUpdate
  145. */
  146. /**
  147. * @ref bx_system_general-module_check_for_update "module_check_for_update"
  148. */
  149. public function serviceModuleCheckForUpdate($mixedModule)
  150. {
  151. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  152. if(empty($aModule) || !is_array($aModule))
  153. return false;
  154. $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
  155. if(empty($aUpdates) || !is_array($aUpdates))
  156. return false;
  157. $aUpdate = array_shift($aUpdates);
  158. return array(
  159. 'version_from' => $aUpdate['file_version'],
  160. 'version_to' => $aUpdate['file_version_to'],
  161. 'file_id' => $aUpdate['file_id']
  162. );
  163. }
  164. /**
  165. * @page service Service Calls
  166. * @section bx_system_general System Services
  167. * @subsection bx_system_general-general General
  168. * @subsubsection bx_system_general-module_update module_update
  169. *
  170. * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
  171. * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
  172. * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
  173. *
  174. * Download and install an update for requested module. The operation may be performed
  175. * immediately or by Transient Cron task. The second way is more common.
  176. * @param $mixedModule - module ID/name to check the updates for.
  177. * @return integer value determining the result of the operation. It can be one of the following values:
  178. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  179. *
  180. * @see BxBaseServices::serviceModuleUpdate
  181. */
  182. /**
  183. * @ref bx_system_general-module_update "module_update"
  184. */
  185. public function serviceModuleUpdate($mixedModule)
  186. {
  187. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  188. if(empty($aModule) || !is_array($aModule))
  189. return BX_DOL_STUDIO_IU_RC_FAILED;
  190. $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
  191. return $aResult['code'];
  192. }
  193. /**
  194. * @page service Service Calls
  195. * @section bx_system_general System Services
  196. * @subsection bx_system_general-general General
  197. * @subsubsection bx_system_general-module_delete module_delete
  198. *
  199. * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
  200. * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
  201. * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
  202. *
  203. * Delete the requested module. By default only uninstalled module can be deleted.
  204. * The operation may be performed immediately or by Transient Cron task. The second way is more common.
  205. * @param $sModule - module name to delete.
  206. * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
  207. * @return integer value determining the result of the operation. It can be one of the following values:
  208. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  209. *
  210. * @see BxBaseServices::serviceModuleDelete
  211. */
  212. /**
  213. * @ref bx_system_general-module_delete "module_delete"
  214. */
  215. public function serviceModuleDelete($sModule, $bForceUninstall = false)
  216. {
  217. $sModulePath = '';
  218. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  219. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
  220. if(!empty($aModule) && is_array($aModule)) {
  221. if(!$bForceUninstall)
  222. return BX_DOL_STUDIO_IU_RC_FAILED;
  223. $sModulePath = $aModule['path'];
  224. $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
  225. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  226. return BX_DOL_STUDIO_IU_RC_FAILED;
  227. }
  228. else {
  229. $aModules = $oInstallerUtils->getModules(false);
  230. if(!isset($aModules[$sModule]))
  231. return BX_DOL_STUDIO_IU_RC_FAILED;
  232. $sModulePath = $aModules[$sModule]['dir'];
  233. }
  234. $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
  235. return $aResult['code'];
  236. }
  237. /**
  238. * @page service Service Calls
  239. * @section bx_system_general System Services
  240. * @subsection bx_system_general-general General
  241. * @subsubsection bx_system_general-module_install module_install
  242. *
  243. * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
  244. * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
  245. * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
  246. *
  247. * Install the requested module. By default the module will be installed only.
  248. * @param $sModule - module name to install.
  249. * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
  250. * @return boolean value determining the result of the operation.
  251. *
  252. * @see BxBaseServices::serviceModuleInstall
  253. */
  254. /**
  255. * @ref bx_system_general-module_install "module_install"
  256. */
  257. public function serviceModuleInstall($sModule, $bForceEnable = false)
  258. {
  259. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  260. $aModules = $oInstallerUtils->getModules(false);
  261. if(!isset($aModules[$sModule]))
  262. return false;
  263. $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
  264. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  265. return false;
  266. return true;
  267. }
  268. /**
  269. * @page service Service Calls
  270. * @section bx_system_general System Services
  271. * @subsection bx_system_general-general General
  272. * @subsubsection bx_system_general-module_uninstall module_uninstall
  273. *
  274. * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
  275. * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
  276. * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
  277. *
  278. * Uninstall the requested module. By default only disabled module can be uninstalled.
  279. * @param $mixedModule - module ID/name to uninstall.
  280. * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
  281. * @return boolean value determining the result of the operation.
  282. *
  283. * @see BxBaseServices::serviceModuleUninstall
  284. */
  285. /**
  286. * @ref bx_system_general-module_uninstall "module_uninstall"
  287. */
  288. public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
  289. {
  290. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  291. if(empty($aModule) || !is_array($aModule))
  292. return false;
  293. if((int)$aModule['enabled'] != 0 && !$bForceDisable)
  294. return false;
  295. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
  296. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  297. return false;
  298. return true;
  299. }
  300. /**
  301. * @page service Service Calls
  302. * @section bx_system_general System Services
  303. * @subsection bx_system_general-general General
  304. * @subsubsection bx_system_general-module_enable module_enable
  305. *
  306. * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
  307. * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
  308. * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
  309. *
  310. * Enable the requested module.
  311. * @param $mixedModule - module ID/name to enable.
  312. * @return boolean value determining the result of the operation.
  313. *
  314. * @see BxBaseServices::serviceModuleEnable
  315. */
  316. /**
  317. * @ref bx_system_general-module_enable "module_enable"
  318. */
  319. public function serviceModuleEnable($mixedModule)
  320. {
  321. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  322. if(empty($aModule) || !is_array($aModule))
  323. return false;
  324. if((int)$aModule['enabled'] != 0)
  325. return false;
  326. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
  327. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  328. return false;
  329. return true;
  330. }
  331. /**
  332. * @page service Service Calls
  333. * @section bx_system_general System Services
  334. * @subsection bx_system_general-general General
  335. * @subsubsection bx_system_general-module_disable module_disable
  336. *
  337. * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
  338. * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
  339. * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
  340. *
  341. * Disable the requested module.
  342. * @param $mixedModule - module ID/name to disable.
  343. * @return boolean value determining the result of the operation.
  344. *
  345. * @see BxBaseServices::serviceModuleDisable
  346. */
  347. /**
  348. * @ref bx_system_general-module_disable "module_disable"
  349. */
  350. public function serviceModuleDisable($mixedModule)
  351. {
  352. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  353. if(empty($aModule) || !is_array($aModule))
  354. return false;
  355. if((int)$aModule['enabled'] == 0)
  356. return false;
  357. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
  358. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  359. return false;
  360. return true;
  361. }
  362. /**
  363. * @page service Service Calls
  364. * @section bx_system_general System Services
  365. * @subsection bx_system_general-general General
  366. * @subsubsection bx_system_general-is_module_installed is_module_installed
  367. *
  368. * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
  369. * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
  370. * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
  371. *
  372. * Checks whether the requested module is installed or not.
  373. * @param $mixedModule - module ID/name to check.
  374. * @return boolean value determining the result of the operation.
  375. *
  376. * @see BxBaseServices::serviceIsModuleInstalled
  377. */
  378. /**
  379. * @ref bx_system_general-is_module_installed "is_module_installed"
  380. */
  381. public function serviceIsModuleInstalled($mixedModule)
  382. {
  383. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  384. return !empty($aModule) && is_array($aModule);
  385. }
  386. /**
  387. * @page service Service Calls
  388. * @section bx_system_general System Services
  389. * @subsection bx_system_general-general General
  390. * @subsubsection bx_system_general-is_module_enabled is_module_enabled
  391. *
  392. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
  393. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
  394. * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
  395. *
  396. * Checks whether the requested module is enabled or not.
  397. * @param $mixedModule - module ID/name to check.
  398. * @return boolean value determining the result of the operation.
  399. *
  400. * @see BxBaseServices::serviceIsModuleEnabled
  401. */
  402. /**
  403. * @ref bx_system_general-is_module_enabled "is_module_enabled"
  404. */
  405. public function serviceIsModuleEnabled($mixedModule)
  406. {
  407. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  408. return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
  409. }
  410. /**
  411. * Checks whether a module is a 'Content' module or not.
  412. *
  413. * @param string $mixedModule - module name or an instance of Module class.
  414. * @return boolean result of operation.
  415. */
  416. public function serviceIsModuleContent($mixedModule)
  417. {
  418. if($mixedModule instanceof BxDolModule)
  419. $mixedModule = $mixedModule->getName();
  420. return BxDolModuleQuery::getInstance()->isModuleContent($mixedModule);
  421. }
  422. /**
  423. * Checks whether a module is a 'Context' module or not.
  424. *
  425. * @param string $mixedModule - module name or an instance of Module class.
  426. * @return boolean result of operation.
  427. */
  428. public function serviceIsModuleContext($mixedModule)
  429. {
  430. if($mixedModule instanceof BxDolModule)
  431. $mixedModule = $mixedModule->getName();
  432. return BxDolModuleQuery::getInstance()->isModuleContext($mixedModule);
  433. }
  434. /**
  435. * Checks whether a module is a 'Profile' module or not.
  436. *
  437. * @param string $mixedModule - module name or an instance of Module class.
  438. * @return boolean result of operation.
  439. */
  440. public function serviceIsModuleProfile($mixedModule)
  441. {
  442. if($mixedModule instanceof BxDolModule)
  443. $mixedModule = $mixedModule->getName();
  444. return BxDolModuleQuery::getInstance()->isModuleProfile($mixedModule);
  445. }
  446. /**
  447. * Get modules by type. Available types are 'content', 'context', 'profile'.
  448. *
  449. * @param type $sType - string with type.
  450. * @return array of modules.
  451. */
  452. public function serviceGetModulesByType($sType, $aParams = [])
  453. {
  454. $oModuleQuery = BxDolModuleQuery::getInstance();
  455. if(!$oModuleQuery->checkModulesSubtypes()) {
  456. $oInstallerUtils = new BxDolInstallerUtils();
  457. $aModules = $oModuleQuery->getModulesBy(['type' => 'modules']);
  458. foreach($aModules as $aModule)
  459. if(($iModuleSubtypes = $oInstallerUtils->getSubtypes($aModule['name'])) != 0)
  460. $oModuleQuery->updateModule(['subtypes' => $iModuleSubtypes], ['id' => $aModule['id']]);
  461. }
  462. $iSubtypes = 0;
  463. switch($sType) {
  464. case 'content';
  465. $iSubtypes = BX_DOL_MODULE_SUBTYPE_TEXT;
  466. break;
  467. case 'context';
  468. $iSubtypes = BX_DOL_MODULE_SUBTYPE_CONTEXT;
  469. break;
  470. case 'profile';
  471. $iSubtypes = BX_DOL_MODULE_SUBTYPE_PROFILE;
  472. break;
  473. }
  474. $aResults = $oModuleQuery->getModulesBy(array_merge([
  475. 'type' => 'modules_subtypes',
  476. 'value' => $iSubtypes,
  477. 'active' => 1
  478. ], array_intersect_key($aParams, array_flip(['id_as_key', 'name_as_key']))));
  479. return $aResults;
  480. }
  481. public function serviceGetModulesBySubtypeSimple($sType)
  482. {
  483. $a = $this->serviceGetModulesByType($sType, ['name_as_key' => true]);
  484. return array_map(function ($r) {
  485. return $r['title'];
  486. }, $a);
  487. }
  488. public function serviceProfileUnit ($iContentId, $aParams = array())
  489. {
  490. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  491. }
  492. public function serviceProfileUnitApi ($iContentId, $aParams = [])
  493. {
  494. return $this->_serviceProfileFunc('getUnitApi', $iContentId, $aParams);
  495. }
  496. public function serviceHasImage ($iContentId)
  497. {
  498. return false;
  499. }
  500. public function serviceProfilePicture ($iContentId)
  501. {
  502. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  503. }
  504. public function serviceProfileAvatar ($iContentId)
  505. {
  506. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  507. }
  508. public function serviceProfileCover ($iContentId)
  509. {
  510. return '';
  511. }
  512. public function serviceProfileEditUrl ($iContentId)
  513. {
  514. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info'));
  515. }
  516. public function serviceProfileThumb ($iContentId)
  517. {
  518. return $this->_serviceProfileFunc('getThumb', $iContentId);
  519. }
  520. public function serviceProfileIcon ($iContentId)
  521. {
  522. return $this->_serviceProfileFunc('getIcon', $iContentId);
  523. }
  524. public function serviceProfileName ($iContentId)
  525. {
  526. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  527. }
  528. public function serviceProfileUrl ($iContentId)
  529. {
  530. return $this->_serviceProfileFunc('getUrl', $iContentId);
  531. }
  532. /**
  533. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  534. */
  535. public function serviceCheckAllowedProfileView($iContentId)
  536. {
  537. return _t('_Access denied');
  538. }
  539. /**
  540. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  541. */
  542. public function serviceCheckAllowedProfileContact($iContentId)
  543. {
  544. return _t('_Access denied');
  545. }
  546. /**
  547. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  548. */
  549. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  550. {
  551. return _t('_Access denied');
  552. }
  553. /**
  554. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  555. */
  556. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  557. {
  558. return _t('_Access denied');
  559. }
  560. /**
  561. * @see iBxDolProfileService::serviceGetSpaceTitle
  562. */
  563. public function serviceGetSpaceTitle()
  564. {
  565. return '';
  566. }
  567. /**
  568. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  569. */
  570. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  571. {
  572. return array();
  573. }
  574. /**
  575. * @page service Service Calls
  576. * @section bx_system_general System Services
  577. * @subsection bx_system_general-general General
  578. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  579. *
  580. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  581. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  582. *
  583. * Get United Create Post form.
  584. * @param $mixedContextId - context which the post will be created in:
  585. * - false = 'Public' post form;
  586. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  587. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  588. * @param $sDefault - tab selected by default.
  589. * @param $aCustom - an array with custom paramaters.
  590. * @return string with form content
  591. *
  592. * @see BxBaseServices::serviceGetCreatePostForm
  593. */
  594. /**
  595. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  596. */
  597. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  598. {
  599. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  600. return '';
  601. $oProfile = BxDolProfile::getInstance();
  602. if(!$oProfile)
  603. return '';
  604. if($mixedContextId !== false)
  605. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  606. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  607. if(!$oMenu)
  608. return '';
  609. $oMenu->setContextId($mixedContextId);
  610. $aMenuItems = $oMenu->getMenuItems();
  611. if(empty($aMenuItems) || !is_array($aMenuItems))
  612. return '';
  613. if(empty($sDefault)) {
  614. $aDefault = array_shift($aMenuItems);
  615. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  616. }
  617. $oMenu->setSelected($sDefault, $sDefault);
  618. $oContext = false;
  619. $bContext = $mixedContextId !== false;
  620. if($bContext && ($oContext = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  621. if(bx_srv($oContext->getModule(), 'check_allowed_post_in_profile', [$oContext->getContentId(), $sDefault]) !== CHECK_ACTION_RESULT_ALLOWED)
  622. return '';
  623. $sTitle = '_sys_page_block_title_create_post';
  624. if(!$bContext)
  625. $sTitle = _t($sTitle . '_public');
  626. else if($mixedContextId < 0) {
  627. $sTitle = _t($sTitle . '_context');
  628. if($oContext)
  629. $sTitle = bx_replace_markers($sTitle, [
  630. 'display_name' => $oContext->getDisplayName()
  631. ]);
  632. }
  633. else
  634. $sTitle = _t($sTitle);
  635. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  636. $oDbModules = BxDolModuleQuery::getInstance();
  637. $oTemplate = BxDolTemplate::getInstance();
  638. $oTemplate->addJs(['BxDolCreatePost.js']);
  639. $aPreloadingList = [];
  640. $aModules = explode(',', getParam('sys_create_post_form_preloading_list'));
  641. if(!empty($aModules))
  642. foreach($aModules as $sModule) {
  643. $aModule = $oDbModules->getModuleByName($sModule);
  644. if(empty($aModule) || !is_array($aModule))
  645. continue;
  646. $aPreloadingList[$sModule] = $aModule['uri'];
  647. }
  648. if(bx_is_api()) {
  649. return [
  650. 'title' => $sTitle,
  651. 'content' => [
  652. bx_api_get_block('get_create_post_form', [
  653. 'menu' => $oMenu->getCodeAPI(),
  654. 'params' => ['context_id' => $mixedContextId]])
  655. ]
  656. ];
  657. }
  658. $sJsObject = 'oBxDolCreatePost';
  659. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
  660. 'sObjName' => $sJsObject,
  661. 'sRootUrl' => BX_DOL_URL_ROOT,
  662. 'sDefault' => $sDefault,
  663. 'iContextId' => $bContext ? $mixedContextId : 0,
  664. 'oPreloadingList' => $aPreloadingList,
  665. 'oCustom' => $aCustom
  666. ]) . ");");
  667. return [
  668. 'title' => $sTitle,
  669. 'content' => $oTemplate->parseHtmlByName('create_post_form.html', [
  670. 'default' => $sDefault,
  671. 'placeholder' => $sPlaceholder,
  672. 'user_thumb' => $oProfile->getUnit(0, ['template' => 'unit_wo_info_links']),
  673. 'form' => bx_srv($sDefault, 'get_create_post_form', [[
  674. 'context_id' => $mixedContextId,
  675. 'ajax_mode' => true,
  676. 'absolute_action_url' => true,
  677. 'custom' => $aCustom
  678. ]]),
  679. 'js_object' => $sJsObject,
  680. 'js_content' => $sJsContent
  681. ]),
  682. 'menu' => $oMenu
  683. ];
  684. }
  685. public function serviceGetOptionsCreatePostFormPreloadingList()
  686. {
  687. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  688. if(!$oMenu)
  689. return [];
  690. $aMenuItems = $oMenu->getMenuItems();
  691. $aResult = [];
  692. foreach($aMenuItems as $aMenuItem) {
  693. $sModule = !empty($aMenuItem['module']) ? $aMenuItem['module'] : $aMenuItem['name'];
  694. if(!bx_srv('system', 'is_module_enabled', [$sModule]))
  695. continue;
  696. $aResult[] = [
  697. 'key' => $sModule,
  698. 'value' => _t('_' . $sModule)
  699. ];
  700. }
  701. return $aResult;
  702. }
  703. public function serviceGetBlockAuthor($sModule, $iContentId = 0)
  704. {
  705. if(!$iContentId && bx_get('id') !== false)
  706. $iContentId = (int)bx_get('id');
  707. $sMethodGetAuthor = 'get_author';
  708. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  709. return '';
  710. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  711. if(!$iAuthor)
  712. return '';
  713. $oAuthor = BxDolProfile::getInstance($iAuthor);
  714. if(!$oAuthor)
  715. return '';
  716. $sModuleAuthor = $oAuthor->getModule();
  717. $sMethodGetCover = 'entity_cover';
  718. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  719. return '';
  720. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  721. 'use_as_author' => true,
  722. 'show_text' => false
  723. ]]);
  724. }
  725. public function serviceGetBlockAskAssistant($aParams = [])
  726. {
  727. $iAssistant = BxDolAI::getAssistantForAskBlock();
  728. if(!$iAssistant)
  729. return '';
  730. return BxDolAIAssistant::getObjectInstance($iAssistant)->getAskBlock($aParams);
  731. }
  732. public function serviceGetMenu($aParams)
  733. {
  734. $bIsApi = bx_is_api();
  735. $mixedResulEmpty = $bIsApi ? [] : '';
  736. if($bIsApi && is_string($aParams))
  737. $aParams = bx_api_get_browse_params($aParams);
  738. if(!isset($aParams['object']))
  739. return $mixedResulEmpty;
  740. $oMenu = BxDolMenu::getObjectInstance($aParams['object']);
  741. if(!$oMenu)
  742. return $mixedResulEmpty;
  743. if(!empty($aParams['params']) && is_array($aParams['params']))
  744. $oMenu->setContentParams($aParams['params']);
  745. return $bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  746. }
  747. /**
  748. * @page service Service Calls
  749. * @section bx_system_general System Services
  750. * @subsection bx_system_general-general General
  751. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  752. *
  753. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  754. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  755. *
  756. * Get Site Submenu code.
  757. * @see BxBaseServices::serviceGetSiteSubmenu
  758. */
  759. /**
  760. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  761. */
  762. public function serviceGetSiteSubmenu()
  763. {
  764. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  765. return $oMenu ? $oMenu->getCode() : '';
  766. }
  767. /**
  768. * @page service Service Calls
  769. * @section bx_system_general System Services
  770. * @subsection bx_system_general-general General
  771. * @subsubsection bx_system_general-get_products_names get_products_names
  772. *
  773. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  774. *
  775. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  776. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  777. *
  778. * Get an array of products names from all modules with payments functionality.
  779. * @param $iVendorId filter products by vendor ID.
  780. * @param $iLimit limit number of records from one module.
  781. * @return array of products where key id product name and value is module name
  782. *
  783. * @see BxBaseServices::serviceGetProductsNames
  784. */
  785. /**
  786. * @ref bx_system_general-get_products_names "get_products_names"
  787. */
  788. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  789. {
  790. $o = BxDolPayments::getInstance();
  791. if (!$o)
  792. return array();
  793. return $o->getProductsNames($iVendorId, $iLimit);
  794. }
  795. /**
  796. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  797. */
  798. public function serviceCheckSpacePrivacy($iContentId)
  799. {
  800. return _t('_Access denied');
  801. }
  802. public function serviceFormsHelper ()
  803. {
  804. return new BxTemplAccountForms();
  805. }
  806. public function serviceActAsProfile ()
  807. {
  808. return false;
  809. }
  810. public function serviceGetModerators($iContentId)
  811. {
  812. $aModerators = BxDolAclQuery::getInstance()->getProfilesByMembership([
  813. MEMBERSHIP_ID_MODERATOR,
  814. MEMBERSHIP_ID_ADMINISTRATOR
  815. ]);
  816. $aIds = [];
  817. array_walk($aModerators, function ($aItem, $iKey, $aParams) {
  818. if(!empty($aItem['id']))
  819. $aParams[0][] = (int)$aItem['id'];
  820. }, [&$aIds]);
  821. return $aIds;
  822. }
  823. public function servicePrepareFields ($aFieldsProfile)
  824. {
  825. return $aFieldsProfile;
  826. }
  827. public function serviceProfilesSearch ($sTerm, $iLimit)
  828. {
  829. $oDb = BxDolAccountQuery::getInstance();
  830. $aRet = array();
  831. $a = $oDb->searchByTerm($sTerm, $iLimit);
  832. foreach ($a as $r)
  833. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  834. return $aRet;
  835. }
  836. /**
  837. * @page service Service Calls
  838. * @section bx_system_general System Services
  839. * @subsection bx_system_general-general General
  840. * @subsubsection bx_system_general-keyword_search keyword_search
  841. *
  842. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  843. *
  844. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  845. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  846. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  847. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  848. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  849. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  850. *
  851. * Search by keyword
  852. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  853. * @param $aCondition - condition for search, supported conditions:
  854. * - search by keyword: ["keyword" => "test"]
  855. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  856. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  857. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  858. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  859. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  860. * @param $sTemplate - template for displaying search results, for example: unit.html
  861. * @param $iStart - paginate, display records starting from this number
  862. * @param $iPerPage - paginate, display this number of records per page
  863. * @param $bLiveSearch - search results like in live search
  864. *
  865. * @see BxBaseServices::serviceKeywordSearch
  866. */
  867. /**
  868. * @ref bx_system_general-keyword_search "keyword_search"
  869. */
  870. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  871. {
  872. if (!$sSection || !isset($aCondition['keyword']))
  873. return '';
  874. $sClass = 'BxTemplSearch';
  875. $sElsName = 'bx_elasticsearch';
  876. $sElsMethod = 'is_configured';
  877. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  878. $oModule = BxDolModule::getInstance($sElsName);
  879. bx_import('Search', $oModule->_aModule);
  880. $sClass = 'BxElsSearch';
  881. }
  882. $oSearch = new $sClass(array($sSection));
  883. $oSearch->setLiveSearch($bLiveSearch);
  884. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  885. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  886. $oSearch->setCustomSearchCondition($aCondition);
  887. if (!$bPaginate)
  888. $oSearch->setRawProcessing(true);
  889. $oSearch->setCustomCurrentCondition(array(
  890. 'paginate' => array (
  891. 'start' => $iStart,
  892. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  893. )));
  894. if ($sTemplate)
  895. $oSearch->setUnitTemplate($sTemplate);
  896. return $oSearch->response();
  897. }
  898. /**
  899. * @page service Service Calls
  900. * @section bx_system_general System Services
  901. * @subsection bx_system_general-general General
  902. * @subsubsection bx_system_general-keyword_search keyword_search
  903. *
  904. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  905. *
  906. * Block with Search by Keywords Form
  907. *
  908. * @see BxBaseServices::serviceSearchKeywordForm
  909. */
  910. /**
  911. * @ref bx_system_general-keyword_search "keyword_search"
  912. */
  913. public function serviceSearchKeywordForm ()
  914. {
  915. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  916. }
  917. /**
  918. * @page service Service Calls
  919. * @section bx_system_general System Services
  920. * @subsection bx_system_general-general General
  921. * @subsubsection bx_system_general-keyword_search keyword_search
  922. *
  923. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  924. *
  925. * Block with Search by Keywords Results
  926. *
  927. * @see BxBaseServices::serviceSearchKeywordResult
  928. */
  929. /**
  930. * @ref bx_system_general-keyword_search "keyword_search"
  931. */
  932. public function serviceSearchKeywordResult ()
  933. {
  934. $sKeyword = bx_process_input(bx_get('keyword'));
  935. $bKeyword = $sKeyword !== false;
  936. if(bx_is_api())
  937. return $this->serviceGetDataSearchApi(['params' => [
  938. 'keyword' => $sKeyword,
  939. 'section' => bx_process_input(bx_get('section')),
  940. 'cat' => bx_process_input(bx_get('cat'))
  941. ]
  942. ]);
  943. $sCode = '';
  944. if($bKeyword) {
  945. $oSearch = $this->_getSearchObject();
  946. if(($sCode = $oSearch->response()))
  947. $sCode = BxDolTemplate::getInstance()->parseHtmlByName('search_result_block.html', [
  948. 'html_id' => 'bx-search-results-keyword',
  949. 'class' => 'bx-search-results-container',
  950. 'attrs' => '',
  951. 'content' => $sCode,
  952. 'bx_if:do_center' => [
  953. 'condition' => false,
  954. 'content' => [
  955. 'html_id' => '',
  956. 'selector_content' => ''
  957. ]
  958. ]
  959. ]);
  960. else
  961. $sCode = $oSearch->getEmptyResult();
  962. }
  963. return $sCode;
  964. }
  965. /**
  966. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  967. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  968. */
  969. public function serviceGetDataSearchApi ($aParams)
  970. {
  971. if(!bx_is_api())
  972. return false;
  973. if(is_string($aParams))
  974. $aParams = json_decode($aParams, true);
  975. $aSections = [];
  976. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  977. 'sys_global_search_pairs',
  978. 'getPairs',
  979. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  980. 'name', 'title'
  981. );
  982. $aSectionNames = explode(',', getParam('sys_api_search_sections'));
  983. foreach($aSectionNames as $sSectionName) {
  984. if(!isset($aSectionsAll[$sSectionName]))
  985. continue;
  986. $aSections[$sSectionName] = [
  987. 'name' => $sSectionName,
  988. 'title' => _t($aSectionsAll[$sSectionName])
  989. ];
  990. }
  991. $aParamsBrowse = array_merge([
  992. 'keyword' => '',
  993. 'section' => '',
  994. 'sections' => array_values($aSections),
  995. 'start' => 0,
  996. 'per_page' => 12
  997. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  998. if(empty($aParamsBrowse['section']))
  999. $aParamsBrowse['section'] = array_keys($aSections);
  1000. else if(is_string($aParamsBrowse['section']))
  1001. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  1002. $sClass = 'BxTemplSearch';
  1003. $sSections = $aParamsBrowse['section'];
  1004. if ($aParamsBrowse['live'] !== true && count($sSections) > 1){
  1005. $aParamsBrowse['section'] = [];
  1006. $aParamsBrowse['sections'] = [];
  1007. $aDataRv = [];
  1008. foreach ($sSections as $sSection) {
  1009. $oSearch = new $sClass($sSection);
  1010. $oSearch->setLiveSearch(true);
  1011. $oSearch->setDataProcessing(true);
  1012. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1013. $oSearch->setCustomCurrentCondition([
  1014. 'paginate' => [
  1015. 'forceStart' => $aParamsBrowse['start'],
  1016. 'perPage' => $aParamsBrowse['per_page'],
  1017. ]
  1018. ]);
  1019. $aData = $oSearch->response();
  1020. if(count($aData) > $aParamsBrowse['per_page'])
  1021. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1022. if (count($aData) > 0) {
  1023. $oSearchResult = $oSearch->getSearchResultObject($sSection);
  1024. $sSectionTitle = $oSearchResult->aCurrent['title'];
  1025. $aParamsBrowse['section'][] = $sSection;
  1026. $aParamsBrowse['sections'][] = ['name' => $sSection, 'title' => $sSectionTitle];
  1027. $aDataRv[] = [
  1028. 'section' => $sSection,
  1029. 'section_name' => $sSectionTitle,
  1030. 'data' => $aData,
  1031. 'is_profile' => bx_srv('system', 'is_module_profile', [$oSearchResult->aCurrent['module_name']])
  1032. ];
  1033. }
  1034. }
  1035. return [bx_api_get_block('search_sections', [
  1036. 'data' => $aDataRv,
  1037. 'params' => $aParamsBrowse
  1038. ])];
  1039. }
  1040. else{
  1041. $oSearch = new $sClass($aParamsBrowse['section']);
  1042. $oSearch->setLiveSearch(true);
  1043. $oSearch->setDataProcessing(true);
  1044. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1045. $oSearch->setCustomCurrentCondition([
  1046. 'paginate' => [
  1047. 'forceStart' => $aParamsBrowse['start'],
  1048. 'perPage' => $aParamsBrowse['per_page'],
  1049. ]
  1050. ]);
  1051. $aData = $oSearch->response();
  1052. if(count($aData) > $aParamsBrowse['per_page'])
  1053. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1054. return [
  1055. bx_api_get_block('browse', [
  1056. 'unit' => 'search-results',
  1057. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  1058. 'params' => $aParamsBrowse,
  1059. 'data' => $aData
  1060. ])
  1061. ];
  1062. }
  1063. }
  1064. /**
  1065. * @page service Service Calls
  1066. * @section bx_system_general System Services
  1067. * @subsection bx_system_general-general General
  1068. * @subsubsection bx_system_general-cmts cmts
  1069. *
  1070. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  1071. *
  1072. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  1073. *
  1074. * Comments block
  1075. * @param $sObject - comments object name
  1076. * @param $sId - content id assiciated tith the comments
  1077. *
  1078. * @see BxBaseServices::serviceCmts
  1079. */
  1080. /**
  1081. * @ref bx_system_general-cmts "cmts"
  1082. */
  1083. public function serviceCmts ($sObject, $sId)
  1084. {
  1085. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  1086. if (!$o || !$o->isEnabled())
  1087. return '';
  1088. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1089. }
  1090. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  1091. {
  1092. if (!$iContentId)
  1093. return false;
  1094. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  1095. return false;
  1096. return $oAccount->$sFunc(false, $aParams);
  1097. }
  1098. public function serviceAlertResponseProcessInstalled()
  1099. {
  1100. BxDolTranscoderImage::registerHandlersSystem();
  1101. }
  1102. public function serviceAlertResponseProcessStorageChange ($oAlert)
  1103. {
  1104. if ('sys_storage_default' != $oAlert->aExtras['option'])
  1105. return;
  1106. $aStorages = BxDolStorageQuery::getStorageObjects();
  1107. foreach ($aStorages as $r) {
  1108. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  1109. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  1110. }
  1111. }
  1112. public function serviceGetOptionsProfileBot()
  1113. {
  1114. $aResult = array(
  1115. array('key' => '', 'value' => _t('_Select_one'))
  1116. );
  1117. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1118. foreach($aAccountsIds as $iAccountId) {
  1119. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1120. foreach($aProfilesIds as $iProfileId) {
  1121. $oProfile = BxDolProfile::getInstance($iProfileId);
  1122. $aResult[] = array(
  1123. 'key' => $iProfileId,
  1124. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  1125. );
  1126. }
  1127. }
  1128. return $aResult;
  1129. }
  1130. public function serviceGetOptionsModuleListForPrivacySelector()
  1131. {
  1132. $aResult = array();
  1133. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  1134. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  1135. foreach($aModules as $aModule){
  1136. $oModule = BxDolModule::getInstance($aModule['name']);
  1137. if($oModule instanceof iBxDolContentInfoService){
  1138. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  1139. continue;
  1140. $aResult[$aModule['name']] = $aModule['title'];
  1141. }
  1142. }
  1143. return $aResult;
  1144. }
  1145. public function serviceGetOptionsCaptchaDefault()
  1146. {
  1147. $aResults = [];
  1148. $aObjects = BxDolCaptchaQuery::getObjects();
  1149. foreach($aObjects as $aObject)
  1150. $aResults[$aObject['object']] = $aObject['title'];
  1151. return $aResults;
  1152. }
  1153. public function serviceGetOptionsEmbedDefault()
  1154. {
  1155. $aResults = array(
  1156. '' => _t('_None')
  1157. );
  1158. $aObjects = BxDolEmbedQuery::getObjects();
  1159. foreach($aObjects as $aObject)
  1160. $aResults[$aObject['object']] = $aObject['title'];
  1161. return $aResults;
  1162. }
  1163. public function serviceGetOptionsLocationFieldDefault()
  1164. {
  1165. $aResults = array();
  1166. $aObjects = BxDolLocationFieldQuery::getObjects();
  1167. foreach($aObjects as $aObject)
  1168. $aResults[$aObject['object']] = _t($aObject['title']);
  1169. return $aResults;
  1170. }
  1171. public function serviceGetOptionsLocationMapDefault()
  1172. {
  1173. $aResults = array();
  1174. $aObjects = BxDolLocationMapQuery::getObjects();
  1175. foreach($aObjects as $aObject)
  1176. $aResults[$aObject['object']] = _t($aObject['title']);
  1177. return $aResults;
  1178. }
  1179. public function serviceGetOptionsPushDefault()
  1180. {
  1181. $aResults = [
  1182. '' => _t('_None')
  1183. ];
  1184. $aObjects = BxDolPushQuery::getObjects();
  1185. foreach($aObjects as $aObject)
  1186. $aResults[$aObject['object']] = $aObject['title'];
  1187. return $aResults;
  1188. }
  1189. public function serviceGetOptionsSmsDefault()
  1190. {
  1191. $aResults = [
  1192. '' => _t('_None')
  1193. ];
  1194. $aObjects = BxDolSmsQuery::getObjects();
  1195. foreach($aObjects as $aObject)
  1196. $aResults[$aObject['object']] = $aObject['title'];
  1197. return $aResults;
  1198. }
  1199. public function serviceGetOptionsSocketsFieldDefault()
  1200. {
  1201. $aResults = [];
  1202. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1203. foreach($aObjects as $sObject)
  1204. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1205. return $aResults;
  1206. }
  1207. public function serviceGetOptionsLocationLeafletGetProviders()
  1208. {
  1209. return BxDolLocationMapLeaflet::getProviders();
  1210. }
  1211. public function serviceGetOptionsRelations()
  1212. {
  1213. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1214. $aProfiles = array();
  1215. foreach($aModules as $aModule) {
  1216. $sMethod = 'act_as_profile';
  1217. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1218. continue;
  1219. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1220. }
  1221. $aResults = array();
  1222. foreach($aProfiles as $sName1 => $sTitle1)
  1223. foreach($aProfiles as $sName2 => $sTitle2)
  1224. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1225. return $aResults;
  1226. }
  1227. public function serviceGetOptionsCfProhibited()
  1228. {
  1229. return BxDolFormQuery::getDataItems('sys_content_filter');
  1230. }
  1231. public function serviceGetOptionsCfUnauthenticated()
  1232. {
  1233. return BxDolFormQuery::getDataItems('sys_content_filter');
  1234. }
  1235. public function serviceGetOptionsTaiwindDefault()
  1236. {
  1237. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1238. $aExcludes = ['.', '..', 'tailwind.css'];
  1239. $aResults = [];
  1240. if(($oHandle = opendir($sPath)) !== false) {
  1241. while(($sFile = readdir($oHandle)) !== false) {
  1242. if(in_array($sFile, $aExcludes))
  1243. continue;
  1244. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1245. continue;
  1246. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1247. $aResults[$sFile] = $sFile;
  1248. fclose($oHandlerFile);
  1249. }
  1250. closedir($oHandle);
  1251. }
  1252. return $aResults;
  1253. }
  1254. public function serviceGetOptionsIconsetDefault()
  1255. {
  1256. $aObjects = BxDolIconsetQuery::getObjects();
  1257. foreach($aObjects as $aObject)
  1258. $aResults[$aObject['object']] = $aObject['title'];
  1259. return $aResults;
  1260. }
  1261. public function serviceGetOptionsApiMenuTop()
  1262. {
  1263. $aMenus = BxDolMenuQuery::getMenuObjects();
  1264. $aResults = ['' => _t('_sys_please_select')];
  1265. foreach($aMenus as $aMenu)
  1266. if($aMenu['module'] == 'system')
  1267. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1268. return $aResults;
  1269. }
  1270. public function serviceGetOptionsApiContextSwitcher()
  1271. {
  1272. $aContexts = bx_srv('system', 'get_modules_by_type', ['context']);
  1273. $aResults = ['' => _t('_None')];
  1274. foreach($aContexts as $aContext)
  1275. $aResults[$aContext['name']] = _t('_' . $aContext['name']);
  1276. return $aResults;
  1277. }
  1278. public function serviceGetOptionsApiContextConnection()
  1279. {
  1280. $aConnections = ['subscriptions', 'fans', 'participants'];
  1281. $aResults = ['' => _t('_sys_please_select')];
  1282. foreach($aConnections as $sConnection)
  1283. $aResults[$sConnection] = _t('_adm_stg_cpt_option_sys_api_cnt_cnn_' . $sConnection);
  1284. return $aResults;
  1285. }
  1286. public function serviceGetOptionsAgentsModel()
  1287. {
  1288. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getModels(['active' => true, 'hidden' => false]);
  1289. }
  1290. public function serviceGetOptionsAgentsProfile($bSelectOne = true)
  1291. {
  1292. $aResult = [];
  1293. if($bSelectOne)
  1294. $aResult[] = ['key' => '', 'value' => _t('_Select_one')];
  1295. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1296. foreach($aAccountsIds as $iAccountId) {
  1297. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1298. foreach($aProfilesIds as $iProfileId)
  1299. if(($oProfile = BxDolProfile::getInstance($iProfileId)) !== false && ($sProfileModule = $oProfile->getModule()) != 'system')
  1300. $aResult[] = [
  1301. 'key' => $iProfileId,
  1302. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), _t('_' . $sProfileModule))
  1303. ];
  1304. }
  1305. return $aResult;
  1306. }
  1307. public function serviceGetOptionsStudioAssistant()
  1308. {
  1309. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1310. }
  1311. public function serviceGetOptionsLiveSearchAssistant()
  1312. {
  1313. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1314. }
  1315. public function serviceGetOptionsAskBlockAssistant()
  1316. {
  1317. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1318. }
  1319. public function serviceRedirect($sUrl = false)
  1320. {
  1321. if (!getParam('sys_confirmation_before_redirect')) {
  1322. BxDolTemplate::getInstance()->displayPageNotFound();
  1323. exit;
  1324. }
  1325. if (false === $sUrl)
  1326. $sUrl = bx_get('url');
  1327. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1328. http_response_code(500);
  1329. return MsgBox(_t('_error occured'));
  1330. }
  1331. else {
  1332. $bSpam = null;
  1333. /**
  1334. * @hooks
  1335. * @hookdef hook-system-check_spam_url 'system', 'check_spam_url' - hook to override sClass for search
  1336. * - $unit_name - equals `system`
  1337. * - $action - equals `check_spam_url`
  1338. * - $object_id - not used
  1339. * - $sender_id - logged account id
  1340. * - $extra_params - array of additional params with the following array keys:
  1341. * - `is_spam` - [bool] by ref, spam url or not, can be overridden in hook processing
  1342. * - `content` - [string] by ref, url of link, can be overridden in hook processing
  1343. * - `where` - [string] equal redirect
  1344. * @hook @ref hook-system-check_spam_url
  1345. */
  1346. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sUrl, 'where' => 'redirect'));
  1347. $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
  1348. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1349. 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
  1350. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1351. ]);
  1352. }
  1353. }
  1354. public function serviceSetBadges($iContentId, $sBadgesIds, $sModule)
  1355. {
  1356. $aSelectedBadges = explode(",", $sBadgesIds);
  1357. $iPerformerId = bx_get_logged_profile_id();
  1358. $aCheck = checkActionModule($iPerformerId, 'set badge', 'system', false);
  1359. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1360. return false;
  1361. $oBadges = BxDolBadges::getInstance();
  1362. $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => $iContentId, 'module' => $sModule));
  1363. foreach ($aBadges as $aBadge) {
  1364. if (isset($aBadge['badge_id'])){
  1365. $oBadges->delete($aBadge['badge_id']);
  1366. }
  1367. }
  1368. foreach ($aSelectedBadges as $iSelectedBadge) {
  1369. $oBadges->add($iSelectedBadge, $iContentId, $sModule);
  1370. }
  1371. checkActionModule($iPerformerId, 'set badge', 'system', true); // perform action
  1372. return true;
  1373. }
  1374. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1375. {
  1376. $sClass = '';
  1377. $sStyleFont = '';
  1378. $sStyleBg = '';
  1379. if ($aBadge['color'] == '')
  1380. $aBadge['color'] = 'purple-600';
  1381. if ($bIsCompact && $aBadge['icon'] != ''){
  1382. $aBadge['is_icon_only'] = 1;
  1383. }
  1384. if ($aBadge['is_icon_only'] == 1){
  1385. $sClass .= ' bx-badge-compact';
  1386. if (substr_count($aBadge['color'], 'rgb('))
  1387. $sStyleFont = 'color: ' . $aBadge['color'];
  1388. else
  1389. $sClass .= ' text-' . $aBadge['color'];
  1390. }
  1391. else{
  1392. if (substr_count($aBadge['color'], 'rgb('))
  1393. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1394. else
  1395. $sClass .= ' bg-' . $aBadge['color'];
  1396. }
  1397. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1398. 'bx_if:content' => array(
  1399. 'condition' => $aBadge['is_icon_only'] != '1',
  1400. 'content' => array('content' => _t($aBadge['text'])),
  1401. ),
  1402. 'bx_if:icon' => array(
  1403. 'condition' => $aBadge['icon'] != '',
  1404. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1405. ),
  1406. 'title' => $aBadge['text'],
  1407. 'style_font' => $sStyleFont,
  1408. 'style_bg' => $sStyleBg,
  1409. 'class' => $sClass,
  1410. )
  1411. );
  1412. }
  1413. public function serviceGetFooter()
  1414. {
  1415. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1416. }
  1417. private function _getSearchObject()
  1418. {
  1419. $sClass = 'BxTemplSearch';
  1420. $sElsName = 'bx_elasticsearch';
  1421. $sElsMethod = 'is_configured';
  1422. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1423. $oModule = BxDolModule::getInstance($sElsName);
  1424. bx_import('Search', $oModule->_aModule);
  1425. $sClass = 'BxElsSearch';
  1426. }
  1427. /**
  1428. * @hooks
  1429. * @hookdef hook-system-search_keyword 'system', 'search_keyword' - hook to override sClass for search
  1430. * - $unit_name - equals `system`
  1431. * - $action - equals `search_keyword`
  1432. * - $object_id - not used
  1433. * - $sender_id - not used
  1434. * - $extra_params - array of additional params with the following array keys:
  1435. * - `override_result` - [string] by ref, class name for search, can be overridden in hook processing
  1436. * @hook @ref hook-system-search_keyword
  1437. */
  1438. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  1439. $oSearch = new $sClass(bx_get('section'));
  1440. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1441. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1442. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1443. return $oSearch;
  1444. }
  1445. }
  1446. /** @} */