BxBaseServices.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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. );
  29. }
  30. public function serviceIsSafeService($s)
  31. {
  32. $sService = bx_gen_method_name($s);
  33. $aSafeServices = $this->serviceGetSafeServices();
  34. return isset($aSafeServices[$sService]);
  35. }
  36. public function serviceGetSafeServices()
  37. {
  38. return array(
  39. 'GetCreatePostForm' => 'BxBaseServices',
  40. 'GetProductsNames' => 'BxBaseServices',
  41. 'KeywordSearch' => 'BxBaseServices',
  42. 'Cmts' => 'BxBaseServices',
  43. 'CreateAccountForm' => 'BxBaseServiceAccount',
  44. 'ForgotPassword' => 'BxBaseServiceAccount',
  45. 'SwitchProfile' => 'BxBaseServiceAccount',
  46. 'CategoriesList' => 'BxBaseServiceCategory',
  47. 'Test' => 'BxBaseServiceLogin',
  48. 'MemberAuthCode' => 'BxBaseServiceLogin',
  49. 'LoginForm' => 'BxBaseServiceLogin',
  50. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  51. 'ProfileMembership' => 'BxBaseServiceProfiles',
  52. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  53. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  54. 'GetChartGrowth' => 'BxBaseChartServices',
  55. 'GetChartStats' => 'BxBaseChartServices',
  56. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  57. 'GetOrdersCount' => 'BxBasePaymentsServices',
  58. );
  59. }
  60. /**
  61. * @page service Service Calls
  62. * @section bx_system_general System Services
  63. * @subsection bx_system_general-general General
  64. * @subsubsection bx_system_general-module_check_for_update module_check_for_update
  65. *
  66. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
  67. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
  68. * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
  69. *
  70. * Checks whether an update is available for requested module or not.
  71. * @param $mixedModule - module ID/name to check the updates for.
  72. * @return array with information about the update, false if nothing was found
  73. *
  74. * @see BxBaseServices::serviceModuleCheckForUpdate
  75. */
  76. /**
  77. * @ref bx_system_general-module_check_for_update "module_check_for_update"
  78. */
  79. public function serviceModuleCheckForUpdate($mixedModule)
  80. {
  81. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  82. if(empty($aModule) || !is_array($aModule))
  83. return false;
  84. $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
  85. if(empty($aUpdates) || !is_array($aUpdates))
  86. return false;
  87. $aUpdate = array_shift($aUpdates);
  88. return array(
  89. 'version_from' => $aUpdate['file_version'],
  90. 'version_to' => $aUpdate['file_version_to'],
  91. 'file_id' => $aUpdate['file_id']
  92. );
  93. }
  94. /**
  95. * @page service Service Calls
  96. * @section bx_system_general System Services
  97. * @subsection bx_system_general-general General
  98. * @subsubsection bx_system_general-module_update module_update
  99. *
  100. * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
  101. * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
  102. * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
  103. *
  104. * Download and install an update for requested module. The operation may be performed
  105. * immediately or by Transient Cron task. The second way is more common.
  106. * @param $mixedModule - module ID/name to check the updates for.
  107. * @return integer value determining the result of the operation. It can be one of the following values:
  108. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  109. *
  110. * @see BxBaseServices::serviceModuleUpdate
  111. */
  112. /**
  113. * @ref bx_system_general-module_update "module_update"
  114. */
  115. public function serviceModuleUpdate($mixedModule)
  116. {
  117. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  118. if(empty($aModule) || !is_array($aModule))
  119. return BX_DOL_STUDIO_IU_RC_FAILED;
  120. $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
  121. return $aResult['code'];
  122. }
  123. /**
  124. * @page service Service Calls
  125. * @section bx_system_general System Services
  126. * @subsection bx_system_general-general General
  127. * @subsubsection bx_system_general-module_delete module_delete
  128. *
  129. * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
  130. * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
  131. * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
  132. *
  133. * Delete the requested module. By default only uninstalled module can be deleted.
  134. * The operation may be performed immediately or by Transient Cron task. The second way is more common.
  135. * @param $sModule - module name to delete.
  136. * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
  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::serviceModuleDelete
  141. */
  142. /**
  143. * @ref bx_system_general-module_delete "module_delete"
  144. */
  145. public function serviceModuleDelete($sModule, $bForceUninstall = false)
  146. {
  147. $sModulePath = '';
  148. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  149. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
  150. if(!empty($aModule) && is_array($aModule)) {
  151. if(!$bForceUninstall)
  152. return BX_DOL_STUDIO_IU_RC_FAILED;
  153. $sModulePath = $aModule['path'];
  154. $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
  155. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  156. return BX_DOL_STUDIO_IU_RC_FAILED;
  157. }
  158. else {
  159. $aModules = $oInstallerUtils->getModules(false);
  160. if(!isset($aModules[$sModule]))
  161. return BX_DOL_STUDIO_IU_RC_FAILED;
  162. $sModulePath = $aModules[$sModule]['dir'];
  163. }
  164. $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
  165. return $aResult['code'];
  166. }
  167. /**
  168. * @page service Service Calls
  169. * @section bx_system_general System Services
  170. * @subsection bx_system_general-general General
  171. * @subsubsection bx_system_general-module_install module_install
  172. *
  173. * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
  174. * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
  175. * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
  176. *
  177. * Install the requested module. By default the module will be installed only.
  178. * @param $sModule - module name to install.
  179. * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
  180. * @return boolean value determining the result of the operation.
  181. *
  182. * @see BxBaseServices::serviceModuleInstall
  183. */
  184. /**
  185. * @ref bx_system_general-module_install "module_install"
  186. */
  187. public function serviceModuleInstall($sModule, $bForceEnable = false)
  188. {
  189. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  190. $aModules = $oInstallerUtils->getModules(false);
  191. if(!isset($aModules[$sModule]))
  192. return false;
  193. $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
  194. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  195. return false;
  196. return true;
  197. }
  198. /**
  199. * @page service Service Calls
  200. * @section bx_system_general System Services
  201. * @subsection bx_system_general-general General
  202. * @subsubsection bx_system_general-module_uninstall module_uninstall
  203. *
  204. * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
  205. * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
  206. * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
  207. *
  208. * Uninstall the requested module. By default only disabled module can be uninstalled.
  209. * @param $mixedModule - module ID/name to uninstall.
  210. * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
  211. * @return boolean value determining the result of the operation.
  212. *
  213. * @see BxBaseServices::serviceModuleUninstall
  214. */
  215. /**
  216. * @ref bx_system_general-module_uninstall "module_uninstall"
  217. */
  218. public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
  219. {
  220. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  221. if(empty($aModule) || !is_array($aModule))
  222. return false;
  223. if((int)$aModule['enabled'] != 0 && !$bForceDisable)
  224. return false;
  225. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
  226. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  227. return false;
  228. return true;
  229. }
  230. /**
  231. * @page service Service Calls
  232. * @section bx_system_general System Services
  233. * @subsection bx_system_general-general General
  234. * @subsubsection bx_system_general-module_enable module_enable
  235. *
  236. * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
  237. * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
  238. * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
  239. *
  240. * Enable the requested module.
  241. * @param $mixedModule - module ID/name to enable.
  242. * @return boolean value determining the result of the operation.
  243. *
  244. * @see BxBaseServices::serviceModuleEnable
  245. */
  246. /**
  247. * @ref bx_system_general-module_enable "module_enable"
  248. */
  249. public function serviceModuleEnable($mixedModule)
  250. {
  251. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  252. if(empty($aModule) || !is_array($aModule))
  253. return false;
  254. if((int)$aModule['enabled'] != 0)
  255. return false;
  256. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
  257. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  258. return false;
  259. return true;
  260. }
  261. /**
  262. * @page service Service Calls
  263. * @section bx_system_general System Services
  264. * @subsection bx_system_general-general General
  265. * @subsubsection bx_system_general-module_disable module_disable
  266. *
  267. * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
  268. * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
  269. * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
  270. *
  271. * Disable the requested module.
  272. * @param $mixedModule - module ID/name to disable.
  273. * @return boolean value determining the result of the operation.
  274. *
  275. * @see BxBaseServices::serviceModuleDisable
  276. */
  277. /**
  278. * @ref bx_system_general-module_disable "module_disable"
  279. */
  280. public function serviceModuleDisable($mixedModule)
  281. {
  282. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  283. if(empty($aModule) || !is_array($aModule))
  284. return false;
  285. if((int)$aModule['enabled'] == 0)
  286. return false;
  287. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
  288. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  289. return false;
  290. return true;
  291. }
  292. /**
  293. * @page service Service Calls
  294. * @section bx_system_general System Services
  295. * @subsection bx_system_general-general General
  296. * @subsubsection bx_system_general-is_module_installed is_module_installed
  297. *
  298. * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
  299. * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
  300. * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
  301. *
  302. * Checks whether the requested module is installed or not.
  303. * @param $mixedModule - module ID/name to check.
  304. * @return boolean value determining the result of the operation.
  305. *
  306. * @see BxBaseServices::serviceIsModuleInstalled
  307. */
  308. /**
  309. * @ref bx_system_general-is_module_installed "is_module_installed"
  310. */
  311. public function serviceIsModuleInstalled($mixedModule)
  312. {
  313. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  314. return !empty($aModule) && is_array($aModule);
  315. }
  316. /**
  317. * @page service Service Calls
  318. * @section bx_system_general System Services
  319. * @subsection bx_system_general-general General
  320. * @subsubsection bx_system_general-is_module_enabled is_module_enabled
  321. *
  322. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
  323. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
  324. * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
  325. *
  326. * Checks whether the requested module is enabled or not.
  327. * @param $mixedModule - module ID/name to check.
  328. * @return boolean value determining the result of the operation.
  329. *
  330. * @see BxBaseServices::serviceIsModuleEnabled
  331. */
  332. /**
  333. * @ref bx_system_general-is_module_enabled "is_module_enabled"
  334. */
  335. public function serviceIsModuleEnabled($mixedModule)
  336. {
  337. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  338. return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
  339. }
  340. public function serviceProfileUnit ($iContentId, $aParams = array())
  341. {
  342. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  343. }
  344. public function serviceHasImage ($iContentId)
  345. {
  346. return false;
  347. }
  348. public function serviceProfilePicture ($iContentId)
  349. {
  350. return BxDolTemplate::getInstance()->getImageUrl('account-picture.png');
  351. }
  352. public function serviceProfileAvatar ($iContentId)
  353. {
  354. return BxDolTemplate::getInstance()->getImageUrl('account-avatar.png');
  355. }
  356. public function serviceProfileCover ($iContentId)
  357. {
  358. return '';
  359. }
  360. public function serviceProfileEditUrl ($iContentId)
  361. {
  362. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  363. }
  364. public function serviceProfileThumb ($iContentId)
  365. {
  366. return $this->_serviceProfileFunc('getThumb', $iContentId);
  367. }
  368. public function serviceProfileIcon ($iContentId)
  369. {
  370. return $this->_serviceProfileFunc('getIcon', $iContentId);
  371. }
  372. public function serviceProfileName ($iContentId)
  373. {
  374. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  375. }
  376. public function serviceProfileUrl ($iContentId)
  377. {
  378. return $this->_serviceProfileFunc('getUrl', $iContentId);
  379. }
  380. /**
  381. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  382. */
  383. public function serviceCheckAllowedProfileView($iContentId)
  384. {
  385. return _t('_Access denied');
  386. }
  387. /**
  388. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  389. */
  390. public function serviceCheckAllowedProfileContact($iContentId)
  391. {
  392. return _t('_Access denied');
  393. }
  394. /**
  395. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  396. */
  397. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  398. {
  399. return _t('_Access denied');
  400. }
  401. /**
  402. * @see iBxDolProfileService::serviceGetSpaceTitle
  403. */
  404. public function serviceGetSpaceTitle()
  405. {
  406. return '';
  407. }
  408. /**
  409. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  410. */
  411. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  412. {
  413. return array();
  414. }
  415. /**
  416. * @page service Service Calls
  417. * @section bx_system_general System Services
  418. * @subsection bx_system_general-general General
  419. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  420. *
  421. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  422. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  423. *
  424. * Get United Create Post form.
  425. * @param $mixedContextId - context which the post will be created in:
  426. * - false = 'Public' post form;
  427. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  428. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  429. * @param $sDefault - tab selected by default.
  430. * @param $aCustom - an array with custom paramaters.
  431. * @return string with form content
  432. *
  433. * @see BxBaseServices::serviceGetCreatePostForm
  434. */
  435. /**
  436. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  437. */
  438. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  439. {
  440. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  441. return '';
  442. $oProfile = BxDolProfile::getInstance();
  443. if(!$oProfile)
  444. return '';
  445. if($mixedContextId !== false)
  446. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  447. $bContext = $mixedContextId !== false;
  448. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  449. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  450. return '';
  451. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  452. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  453. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  454. if(!$oMenu)
  455. return '';
  456. $aMenuItems = $oMenu->getMenuItems();
  457. if(empty($aMenuItems) || !is_array($aMenuItems))
  458. return '';
  459. if(empty($sDefault)) {
  460. $aDefault = array_shift($aMenuItems);
  461. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  462. }
  463. $oMenu->setSelected($sDefault, $sDefault);
  464. $oTemplate = BxDolTemplate::getInstance();
  465. $oTemplate->addJs(array('BxDolCreatePost.js'));
  466. $sJsObject = 'oBxDolCreatePost';
  467. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  468. 'sObjName' => $sJsObject,
  469. 'sRootUrl' => BX_DOL_URL_ROOT,
  470. 'sDefault' => $sDefault,
  471. 'iContextId' => $bContext ? $mixedContextId : 0,
  472. 'oCustom' => $aCustom
  473. )) . ");");
  474. return array(
  475. 'title' => $sTitle,
  476. 'content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  477. 'default' => $sDefault,
  478. 'placeholder' => $sPlaceholder,
  479. 'user_thumb' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  480. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
  481. 'js_object' => $sJsObject,
  482. 'js_content' => $sJsContent
  483. )),
  484. 'menu' => $oMenu
  485. );
  486. }
  487. /**
  488. * @page service Service Calls
  489. * @section bx_system_general System Services
  490. * @subsection bx_system_general-general General
  491. * @subsubsection bx_system_general-get_products_names get_products_names
  492. *
  493. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  494. *
  495. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  496. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  497. *
  498. * Get an array of products names from all modules with payments functionality.
  499. * @param $iVendorId filter products by vendor ID.
  500. * @param $iLimit limit number of records from one module.
  501. * @return array of products where key id product name and value is module name
  502. *
  503. * @see BxBaseServices::serviceGetProductsNames
  504. */
  505. /**
  506. * @ref bx_system_general-get_products_names "get_products_names"
  507. */
  508. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  509. {
  510. $o = BxDolPayments::getInstance();
  511. if (!$o)
  512. return array();
  513. return $o->getProductsNames($iVendorId, $iLimit);
  514. }
  515. /**
  516. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  517. */
  518. public function serviceCheckSpacePrivacy($iContentId)
  519. {
  520. return _t('_Access denied');
  521. }
  522. public function serviceFormsHelper ()
  523. {
  524. return new BxTemplAccountForms();
  525. }
  526. public function serviceActAsProfile ()
  527. {
  528. return false;
  529. }
  530. public function servicePrepareFields ($aFieldsProfile)
  531. {
  532. return $aFieldsProfile;
  533. }
  534. public function serviceProfilesSearch ($sTerm, $iLimit)
  535. {
  536. $oDb = BxDolAccountQuery::getInstance();
  537. $aRet = array();
  538. $a = $oDb->searchByTerm($sTerm, $iLimit);
  539. foreach ($a as $r)
  540. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  541. return $aRet;
  542. }
  543. /**
  544. * @page service Service Calls
  545. * @section bx_system_general System Services
  546. * @subsection bx_system_general-general General
  547. * @subsubsection bx_system_general-keyword_search keyword_search
  548. *
  549. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  550. *
  551. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  552. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  553. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  554. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  555. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  556. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  557. *
  558. * Search by keyword
  559. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  560. * @param $aCondition - condition for search, supported conditions:
  561. * - search by keyword: ["keyword" => "test"]
  562. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  563. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  564. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  565. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  566. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  567. * @param $sTemplate - template for displaying search results, for example: unit.html
  568. * @param $iStart - paginate, display records starting from this number
  569. * @param $iPerPage - paginate, display this number of records per page
  570. * @param $bLiveSearch - search results like in live search
  571. *
  572. * @see BxBaseServices::serviceKeywordSearch
  573. */
  574. /**
  575. * @ref bx_system_general-keyword_search "keyword_search"
  576. */
  577. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  578. {
  579. if (!$sSection || !isset($aCondition['keyword']))
  580. return '';
  581. $sClass = 'BxTemplSearch';
  582. $sElsName = 'bx_elasticsearch';
  583. $sElsMethod = 'is_configured';
  584. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  585. $oModule = BxDolModule::getInstance($sElsName);
  586. bx_import('Search', $oModule->_aModule);
  587. $sClass = 'BxElsSearch';
  588. }
  589. $oSearch = new $sClass(array($sSection));
  590. $oSearch->setLiveSearch($bLiveSearch);
  591. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  592. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  593. $oSearch->setCustomSearchCondition($aCondition);
  594. if (!$bPaginate)
  595. $oSearch->setRawProcessing(true);
  596. $oSearch->setCustomCurrentCondition(array(
  597. 'paginate' => array (
  598. 'start' => $iStart,
  599. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  600. )));
  601. if ($sTemplate)
  602. $oSearch->setUnitTemplate($sTemplate);
  603. return $oSearch->response();
  604. }
  605. /**
  606. * @page service Service Calls
  607. * @section bx_system_general System Services
  608. * @subsection bx_system_general-general General
  609. * @subsubsection bx_system_general-keyword_search keyword_search
  610. *
  611. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  612. *
  613. * Block with Search by Keywords Form
  614. *
  615. * @see BxBaseServices::serviceSearchKeywordForm
  616. */
  617. /**
  618. * @ref bx_system_general-keyword_search "keyword_search"
  619. */
  620. public function serviceSearchKeywordForm ()
  621. {
  622. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  623. }
  624. /**
  625. * @page service Service Calls
  626. * @section bx_system_general System Services
  627. * @subsection bx_system_general-general General
  628. * @subsubsection bx_system_general-keyword_search keyword_search
  629. *
  630. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  631. *
  632. * Block with Search by Keywords Results
  633. *
  634. * @see BxBaseServices::serviceSearchKeywordResult
  635. */
  636. /**
  637. * @ref bx_system_general-keyword_search "keyword_search"
  638. */
  639. public function serviceSearchKeywordResult ()
  640. {
  641. $oSearch = $this->_getSearchObject();
  642. $sCode = '';
  643. if (bx_get('keyword') !== false) {
  644. $sCode = $oSearch->response();
  645. if (!$sCode)
  646. $sCode = $oSearch->getEmptyResult();
  647. }
  648. return $sCode;
  649. }
  650. /**
  651. * @page service Service Calls
  652. * @section bx_system_general System Services
  653. * @subsection bx_system_general-general General
  654. * @subsubsection bx_system_general-cmts cmts
  655. *
  656. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  657. *
  658. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  659. *
  660. * Comments block
  661. * @param $sObject - comments object name
  662. * @param $sId - content id assiciated tith the comments
  663. *
  664. * @see BxBaseServices::serviceCmts
  665. */
  666. /**
  667. * @ref bx_system_general-cmts "cmts"
  668. */
  669. public function serviceCmts ($sObject, $sId)
  670. {
  671. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  672. if (!$o || !$o->isEnabled())
  673. return '';
  674. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  675. }
  676. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  677. {
  678. if (!$iContentId)
  679. return false;
  680. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  681. return false;
  682. return $oAccount->$sFunc(false, $aParams);
  683. }
  684. public function serviceAlertResponseProcessInstalled()
  685. {
  686. BxDolTranscoderImage::registerHandlersSystem();
  687. }
  688. public function serviceAlertResponseProcessStorageChange ($oAlert)
  689. {
  690. if ('sys_storage_default' != $oAlert->aExtras['option'])
  691. return;
  692. $aStorages = BxDolStorageQuery::getStorageObjects();
  693. foreach ($aStorages as $r) {
  694. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  695. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  696. }
  697. }
  698. public function serviceGetOptionsProfileBot()
  699. {
  700. $aResult = array(
  701. array('key' => '', 'value' => _t('_Select_one'))
  702. );
  703. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  704. foreach($aAccountsIds as $iAccountId) {
  705. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  706. foreach($aProfilesIds as $iProfileId) {
  707. $oProfile = BxDolProfile::getInstance($iProfileId);
  708. $aResult[] = array(
  709. 'key' => $iProfileId,
  710. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  711. );
  712. }
  713. }
  714. return $aResult;
  715. }
  716. public function serviceGetOptionsModuleListForPrivacySelector()
  717. {
  718. $aResult = array();
  719. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  720. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  721. foreach($aModules as $aModule){
  722. $oModule = BxDolModule::getInstance($aModule['name']);
  723. if($oModule instanceof iBxDolContentInfoService){
  724. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  725. continue;
  726. $aResult[$aModule['name']] = $aModule['title'];
  727. }
  728. }
  729. return $aResult;
  730. }
  731. public function serviceGetOptionsEmbedDefault()
  732. {
  733. $aResults = array(
  734. '' => _t('_None')
  735. );
  736. $aObjects = BxDolEmbedQuery::getObjects();
  737. foreach($aObjects as $aObject)
  738. $aResults[$aObject['object']] = $aObject['title'];
  739. return $aResults;
  740. }
  741. public function serviceGetOptionsLocationFieldDefault()
  742. {
  743. $aResults = array();
  744. $aObjects = BxDolLocationFieldQuery::getObjects();
  745. foreach($aObjects as $aObject)
  746. $aResults[$aObject['object']] = _t($aObject['title']);
  747. return $aResults;
  748. }
  749. public function serviceGetOptionsLocationMapDefault()
  750. {
  751. $aResults = array();
  752. $aObjects = BxDolLocationMapQuery::getObjects();
  753. foreach($aObjects as $aObject)
  754. $aResults[$aObject['object']] = _t($aObject['title']);
  755. return $aResults;
  756. }
  757. public function serviceGetOptionsLocationLeafletGetProviders()
  758. {
  759. return BxDolLocationMapLeaflet::getProviders();
  760. }
  761. public function serviceGetOptionsRelations()
  762. {
  763. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  764. $aProfiles = array();
  765. foreach($aModules as $aModule) {
  766. $sMethod = 'act_as_profile';
  767. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  768. continue;
  769. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  770. }
  771. $aResults = array();
  772. foreach($aProfiles as $sName1 => $sTitle1)
  773. foreach($aProfiles as $sName2 => $sTitle2)
  774. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  775. return $aResults;
  776. }
  777. public function serviceGetBadge($aBadge, $bIsCompact = false)
  778. {
  779. $sClass = '';
  780. $sStyleFont = '';
  781. $sStyleBg = '';
  782. if ($aBadge['color'] == '')
  783. $aBadge['color'] = '#ff0000';
  784. if ($aBadge['fontcolor'] == '')
  785. $aBadge['fontcolor'] = '#ffffff';
  786. if ($bIsCompact){
  787. $aBadge['is_icon_only'] = 1;
  788. $sClass .= ' bx-badge-compact-to';
  789. $sStyleFont = 'color: ' . $aBadge['color'];
  790. }
  791. else{
  792. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  793. }
  794. if ($aBadge['is_icon_only'] == 1){
  795. $sClass .= ' bx-badge-compact';
  796. }
  797. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  798. 'bx_if:content' => array(
  799. 'condition' => $aBadge['is_icon_only'] != '1',
  800. 'content' => array('content' => _t($aBadge['text'])),
  801. ),
  802. 'bx_if:icon' => array(
  803. 'condition' => $aBadge['icon'] != '',
  804. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  805. ),
  806. 'title' => $aBadge['text'],
  807. 'style_font' => $sStyleFont,
  808. 'style_bg' => $sStyleBg,
  809. 'class' => $sClass,
  810. )
  811. );
  812. }
  813. private function _getSearchObject()
  814. {
  815. $sClass = 'BxTemplSearch';
  816. $sElsName = 'bx_elasticsearch';
  817. $sElsMethod = 'is_configured';
  818. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  819. $oModule = BxDolModule::getInstance($sElsName);
  820. bx_import('Search', $oModule->_aModule);
  821. $sClass = 'BxElsSearch';
  822. }
  823. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  824. $oSearch = new $sClass(bx_get('section'));
  825. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  826. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  827. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  828. return $oSearch;
  829. }
  830. }
  831. /** @} */