BxDolConModule.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Dolphin Connect
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxDolConModule 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_dolcon_profile_error_api_keys') );
  30. $this->_oTemplate->getPage(_t('_bx_dolcon'), $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. protected function _makeFriends($iProfileId)
  49. {
  50. return parent::__makeFriends($iProfileId);
  51. }
  52. /**
  53. * @param $aProfileInfo - remote profile info
  54. * @param $sAlternativeName - suffix to add to NickName to make it unique
  55. * @return profile array info, ready for the local database
  56. */
  57. protected function _convertRemoteFields($aProfileInfo, $sAlternativeName = '')
  58. {
  59. $aProfileFields = $aProfileInfo;
  60. $sFullname = $aProfileInfo['NickName'];
  61. if (!empty($aProfileInfo['FullName']))
  62. $sFullname = $aProfileInfo['FullName'];
  63. if (!empty($aProfileInfo['FirstName']))
  64. $sFullname = $aProfileInfo['FirstName'] . (!empty($aProfileInfo['LastName']) ? ' ' . $aProfileInfo['LastName'] : '');
  65. $aProfileFields['name'] = $aProfileInfo['NickName'];
  66. $aProfileFields['gender'] = isset($aProfileInfo['Sex']) && ('male' == $aProfileInfo['Sex'] || 'female' == $aProfileInfo['Sex']) ? ('male' == $aProfileInfo['Sex'] ? 1 : 2) : '';
  67. $aProfileFields['birthday'] = isset($aProfileInfo['DateOfBirth']) ? $aProfileInfo['DateOfBirth'] : '';
  68. $aProfileFields['fullname'] = $sFullname;
  69. $aProfileFields['picture'] = $aProfileInfo['picture'];
  70. $aProfileFields['description'] = $aProfileInfo['DescriptionMe'];
  71. $aProfileFields['allow_view_to'] = getParam('bx_dolcon_privacy');
  72. return $aProfileFields;
  73. }
  74. }
  75. /** @} */