BxUnaConModule.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 UnaConnect UNA Connect
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxUnaConModule extends BxBaseModConnectModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. /**
  18. * Redirect to remote site login form
  19. *
  20. * @return n/a/ - redirect or HTML page in case of error
  21. */
  22. function actionStart()
  23. {
  24. if (isLogged())
  25. $this->_redirect ($this -> _oConfig -> sDefaultRedirectUrl);
  26. if (!$this->_oConfig->sApiID || !$this->_oConfig->sApiSecret || !$this->_oConfig->sApiUrl) {
  27. require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
  28. bx_import('BxDolLanguages');
  29. $sCode = MsgBox( _t('_bx_unacon_profile_error_api_keys') );
  30. $this->_oTemplate->getPage(_t('_bx_unacon'), $sCode);
  31. }
  32. else {
  33. // define redirect URL to the remote site
  34. $sUrl = bx_append_url_params($this->_oConfig->sApiUrl . 'auth', array(
  35. 'response_type' => 'code',
  36. 'client_id' => $this->_oConfig->sApiID,
  37. 'redirect_uri' => $this->_oConfig->sPageHandle,
  38. 'scope' => $this->_oConfig->sScope,
  39. 'state' => $this->_genToken(),
  40. ));
  41. $this->_redirect($sUrl);
  42. }
  43. }
  44. function actionHandle()
  45. {
  46. return $this->_actionHandle();
  47. }
  48. public function serviceGetActions($aWidget)
  49. {
  50. $oInformer = BxDolInformer::getInstance(BxDolStudioTemplate::getInstance());
  51. $oInformer->add('sys-module-discontinued', _t('_adm_txt_modules_discontinued', BX_DOL_URL_STUDIO . 'design.php?name=bx_unacon', _t('_bx_unacon_settings')), BX_INFORMER_ALERT);
  52. return bx_srv('system', 'get_actions', [$aWidget], 'TemplStudioDesigns');
  53. }
  54. protected function _makeFriends($iProfileId)
  55. {
  56. return parent::__makeFriends($iProfileId);
  57. }
  58. /**
  59. * @param $aProfileInfo - remote profile info
  60. * @param $sAlternativeName - suffix to add to NickName to make it unique
  61. * @return profile array info, ready for the local database
  62. */
  63. protected function _convertRemoteFields($aProfileInfo, $sAlternativeName = '')
  64. {
  65. $aProfileFields = $aProfileInfo;
  66. $aProfileFields['name'] = $aProfileInfo['profile_display_name'];
  67. $aProfileFields['gender'] = isset($aProfileInfo['gender']) ? $aProfileInfo['gender'] : '';
  68. $aProfileFields['birthday'] = isset($aProfileInfo['birthday']) ? $aProfileInfo['birthday'] : '';
  69. $aProfileFields['fullname'] = $aProfileInfo['profile_display_name'];
  70. $aProfileFields['picture'] = $aProfileInfo['picture'];
  71. $aProfileFields['allow_view_to'] = getParam('bx_unacon_privacy');
  72. return $aProfileFields;
  73. }
  74. }
  75. /** @} */