BxBaseServices.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  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::serviceCheckAllowedModuleActionInProfile
  403. */
  404. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  405. {
  406. return _t('_Access denied');
  407. }
  408. /**
  409. * @see iBxDolProfileService::serviceGetSpaceTitle
  410. */
  411. public function serviceGetSpaceTitle()
  412. {
  413. return '';
  414. }
  415. /**
  416. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  417. */
  418. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  419. {
  420. return array();
  421. }
  422. /**
  423. * @page service Service Calls
  424. * @section bx_system_general System Services
  425. * @subsection bx_system_general-general General
  426. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  427. *
  428. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  429. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  430. *
  431. * Get United Create Post form.
  432. * @param $mixedContextId - context which the post will be created in:
  433. * - false = 'Public' post form;
  434. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  435. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  436. * @param $sDefault - tab selected by default.
  437. * @param $aCustom - an array with custom paramaters.
  438. * @return string with form content
  439. *
  440. * @see BxBaseServices::serviceGetCreatePostForm
  441. */
  442. /**
  443. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  444. */
  445. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  446. {
  447. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  448. return '';
  449. $oProfile = BxDolProfile::getInstance();
  450. if(!$oProfile)
  451. return '';
  452. if($mixedContextId !== false)
  453. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  454. $bContext = $mixedContextId !== false;
  455. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  456. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  457. return '';
  458. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  459. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  460. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  461. if(!$oMenu)
  462. return '';
  463. $aMenuItems = $oMenu->getMenuItems();
  464. if(empty($aMenuItems) || !is_array($aMenuItems))
  465. return '';
  466. if(empty($sDefault)) {
  467. $aDefault = array_shift($aMenuItems);
  468. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  469. }
  470. $oMenu->setSelected($sDefault, $sDefault);
  471. $oTemplate = BxDolTemplate::getInstance();
  472. $oTemplate->addJs(array('BxDolCreatePost.js'));
  473. $sJsObject = 'oBxDolCreatePost';
  474. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  475. 'sObjName' => $sJsObject,
  476. 'sRootUrl' => BX_DOL_URL_ROOT,
  477. 'sDefault' => $sDefault,
  478. 'iContextId' => $bContext ? $mixedContextId : 0,
  479. 'oCustom' => $aCustom
  480. )) . ");");
  481. return array(
  482. 'title' => $sTitle,
  483. 'content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  484. 'default' => $sDefault,
  485. 'placeholder' => $sPlaceholder,
  486. 'user_thumb' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  487. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
  488. 'js_object' => $sJsObject,
  489. 'js_content' => $sJsContent
  490. )),
  491. 'menu' => $oMenu
  492. );
  493. }
  494. /**
  495. * @page service Service Calls
  496. * @section bx_system_general System Services
  497. * @subsection bx_system_general-general General
  498. * @subsubsection bx_system_general-get_products_names get_products_names
  499. *
  500. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  501. *
  502. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  503. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  504. *
  505. * Get an array of products names from all modules with payments functionality.
  506. * @param $iVendorId filter products by vendor ID.
  507. * @param $iLimit limit number of records from one module.
  508. * @return array of products where key id product name and value is module name
  509. *
  510. * @see BxBaseServices::serviceGetProductsNames
  511. */
  512. /**
  513. * @ref bx_system_general-get_products_names "get_products_names"
  514. */
  515. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  516. {
  517. $o = BxDolPayments::getInstance();
  518. if (!$o)
  519. return array();
  520. return $o->getProductsNames($iVendorId, $iLimit);
  521. }
  522. /**
  523. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  524. */
  525. public function serviceCheckSpacePrivacy($iContentId)
  526. {
  527. return _t('_Access denied');
  528. }
  529. public function serviceFormsHelper ()
  530. {
  531. return new BxTemplAccountForms();
  532. }
  533. public function serviceActAsProfile ()
  534. {
  535. return false;
  536. }
  537. public function servicePrepareFields ($aFieldsProfile)
  538. {
  539. return $aFieldsProfile;
  540. }
  541. public function serviceProfilesSearch ($sTerm, $iLimit)
  542. {
  543. $oDb = BxDolAccountQuery::getInstance();
  544. $aRet = array();
  545. $a = $oDb->searchByTerm($sTerm, $iLimit);
  546. foreach ($a as $r)
  547. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  548. return $aRet;
  549. }
  550. /**
  551. * @page service Service Calls
  552. * @section bx_system_general System Services
  553. * @subsection bx_system_general-general General
  554. * @subsubsection bx_system_general-keyword_search keyword_search
  555. *
  556. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  557. *
  558. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  559. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  560. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  561. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  562. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  563. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  564. *
  565. * Search by keyword
  566. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  567. * @param $aCondition - condition for search, supported conditions:
  568. * - search by keyword: ["keyword" => "test"]
  569. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  570. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  571. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  572. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  573. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  574. * @param $sTemplate - template for displaying search results, for example: unit.html
  575. * @param $iStart - paginate, display records starting from this number
  576. * @param $iPerPage - paginate, display this number of records per page
  577. * @param $bLiveSearch - search results like in live search
  578. *
  579. * @see BxBaseServices::serviceKeywordSearch
  580. */
  581. /**
  582. * @ref bx_system_general-keyword_search "keyword_search"
  583. */
  584. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  585. {
  586. if (!$sSection || !isset($aCondition['keyword']))
  587. return '';
  588. $sClass = 'BxTemplSearch';
  589. $sElsName = 'bx_elasticsearch';
  590. $sElsMethod = 'is_configured';
  591. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  592. $oModule = BxDolModule::getInstance($sElsName);
  593. bx_import('Search', $oModule->_aModule);
  594. $sClass = 'BxElsSearch';
  595. }
  596. $oSearch = new $sClass(array($sSection));
  597. $oSearch->setLiveSearch($bLiveSearch);
  598. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  599. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  600. $oSearch->setCustomSearchCondition($aCondition);
  601. if (!$bPaginate)
  602. $oSearch->setRawProcessing(true);
  603. $oSearch->setCustomCurrentCondition(array(
  604. 'paginate' => array (
  605. 'start' => $iStart,
  606. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  607. )));
  608. if ($sTemplate)
  609. $oSearch->setUnitTemplate($sTemplate);
  610. return $oSearch->response();
  611. }
  612. /**
  613. * @page service Service Calls
  614. * @section bx_system_general System Services
  615. * @subsection bx_system_general-general General
  616. * @subsubsection bx_system_general-keyword_search keyword_search
  617. *
  618. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  619. *
  620. * Block with Search by Keywords Form
  621. *
  622. * @see BxBaseServices::serviceSearchKeywordForm
  623. */
  624. /**
  625. * @ref bx_system_general-keyword_search "keyword_search"
  626. */
  627. public function serviceSearchKeywordForm ()
  628. {
  629. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  630. }
  631. /**
  632. * @page service Service Calls
  633. * @section bx_system_general System Services
  634. * @subsection bx_system_general-general General
  635. * @subsubsection bx_system_general-keyword_search keyword_search
  636. *
  637. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  638. *
  639. * Block with Search by Keywords Results
  640. *
  641. * @see BxBaseServices::serviceSearchKeywordResult
  642. */
  643. /**
  644. * @ref bx_system_general-keyword_search "keyword_search"
  645. */
  646. public function serviceSearchKeywordResult ()
  647. {
  648. $oSearch = $this->_getSearchObject();
  649. $sCode = '';
  650. if (bx_get('keyword') !== false) {
  651. $sCode = $oSearch->response();
  652. if (!$sCode)
  653. $sCode = $oSearch->getEmptyResult();
  654. }
  655. return $sCode;
  656. }
  657. /**
  658. * @page service Service Calls
  659. * @section bx_system_general System Services
  660. * @subsection bx_system_general-general General
  661. * @subsubsection bx_system_general-cmts cmts
  662. *
  663. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  664. *
  665. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  666. *
  667. * Comments block
  668. * @param $sObject - comments object name
  669. * @param $sId - content id assiciated tith the comments
  670. *
  671. * @see BxBaseServices::serviceCmts
  672. */
  673. /**
  674. * @ref bx_system_general-cmts "cmts"
  675. */
  676. public function serviceCmts ($sObject, $sId)
  677. {
  678. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  679. if (!$o || !$o->isEnabled())
  680. return '';
  681. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  682. }
  683. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  684. {
  685. if (!$iContentId)
  686. return false;
  687. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  688. return false;
  689. return $oAccount->$sFunc(false, $aParams);
  690. }
  691. public function serviceAlertResponseProcessInstalled()
  692. {
  693. BxDolTranscoderImage::registerHandlersSystem();
  694. }
  695. public function serviceAlertResponseProcessStorageChange ($oAlert)
  696. {
  697. if ('sys_storage_default' != $oAlert->aExtras['option'])
  698. return;
  699. $aStorages = BxDolStorageQuery::getStorageObjects();
  700. foreach ($aStorages as $r) {
  701. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  702. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  703. }
  704. }
  705. public function serviceGetOptionsProfileBot()
  706. {
  707. $aResult = array(
  708. array('key' => '', 'value' => _t('_Select_one'))
  709. );
  710. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  711. foreach($aAccountsIds as $iAccountId) {
  712. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  713. foreach($aProfilesIds as $iProfileId) {
  714. $oProfile = BxDolProfile::getInstance($iProfileId);
  715. $aResult[] = array(
  716. 'key' => $iProfileId,
  717. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  718. );
  719. }
  720. }
  721. return $aResult;
  722. }
  723. public function serviceGetOptionsModuleListForPrivacySelector()
  724. {
  725. $aResult = array();
  726. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  727. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  728. foreach($aModules as $aModule){
  729. $oModule = BxDolModule::getInstance($aModule['name']);
  730. if($oModule instanceof iBxDolContentInfoService){
  731. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  732. continue;
  733. $aResult[$aModule['name']] = $aModule['title'];
  734. }
  735. }
  736. return $aResult;
  737. }
  738. public function serviceGetOptionsEmbedDefault()
  739. {
  740. $aResults = array(
  741. '' => _t('_None')
  742. );
  743. $aObjects = BxDolEmbedQuery::getObjects();
  744. foreach($aObjects as $aObject)
  745. $aResults[$aObject['object']] = $aObject['title'];
  746. return $aResults;
  747. }
  748. public function serviceGetOptionsLocationFieldDefault()
  749. {
  750. $aResults = array();
  751. $aObjects = BxDolLocationFieldQuery::getObjects();
  752. foreach($aObjects as $aObject)
  753. $aResults[$aObject['object']] = _t($aObject['title']);
  754. return $aResults;
  755. }
  756. public function serviceGetOptionsLocationMapDefault()
  757. {
  758. $aResults = array();
  759. $aObjects = BxDolLocationMapQuery::getObjects();
  760. foreach($aObjects as $aObject)
  761. $aResults[$aObject['object']] = _t($aObject['title']);
  762. return $aResults;
  763. }
  764. public function serviceGetOptionsLocationLeafletGetProviders()
  765. {
  766. return BxDolLocationMapLeaflet::getProviders();
  767. }
  768. public function serviceGetOptionsRelations()
  769. {
  770. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  771. $aProfiles = array();
  772. foreach($aModules as $aModule) {
  773. $sMethod = 'act_as_profile';
  774. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  775. continue;
  776. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  777. }
  778. $aResults = array();
  779. foreach($aProfiles as $sName1 => $sTitle1)
  780. foreach($aProfiles as $sName2 => $sTitle2)
  781. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  782. return $aResults;
  783. }
  784. public function serviceGetBadge($aBadge, $bIsCompact = false)
  785. {
  786. $sClass = '';
  787. $sStyleFont = '';
  788. $sStyleBg = '';
  789. if ($aBadge['color'] == '')
  790. $aBadge['color'] = '#ff0000';
  791. if ($aBadge['fontcolor'] == '')
  792. $aBadge['fontcolor'] = '#ffffff';
  793. if ($bIsCompact){
  794. $aBadge['is_icon_only'] = 1;
  795. $sClass .= ' bx-badge-compact-to';
  796. $sStyleFont = 'color: ' . $aBadge['color'];
  797. }
  798. else{
  799. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  800. }
  801. if ($aBadge['is_icon_only'] == 1){
  802. $sClass .= ' bx-badge-compact';
  803. }
  804. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  805. 'bx_if:content' => array(
  806. 'condition' => $aBadge['is_icon_only'] != '1',
  807. 'content' => array('content' => _t($aBadge['text'])),
  808. ),
  809. 'bx_if:icon' => array(
  810. 'condition' => $aBadge['icon'] != '',
  811. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  812. ),
  813. 'title' => $aBadge['text'],
  814. 'style_font' => $sStyleFont,
  815. 'style_bg' => $sStyleBg,
  816. 'class' => $sClass,
  817. )
  818. );
  819. }
  820. private function _getSearchObject()
  821. {
  822. $sClass = 'BxTemplSearch';
  823. $sElsName = 'bx_elasticsearch';
  824. $sElsMethod = 'is_configured';
  825. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  826. $oModule = BxDolModule::getInstance($sElsName);
  827. bx_import('Search', $oModule->_aModule);
  828. $sClass = 'BxElsSearch';
  829. }
  830. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  831. $oSearch = new $sClass(bx_get('section'));
  832. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  833. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  834. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  835. return $oSearch;
  836. }
  837. }
  838. /** @} */