1
0
Эх сурвалжийг харах

#794 UNA Connect: auto-friend feature, option for default privacy

Alex Trofimov 9 жил өмнө
parent
commit
43a35e866f

+ 1 - 1
modules/boonex/una_connect/classes/BxUnaConConfig.php

@@ -39,7 +39,7 @@ class BxUnaConConfig extends BxBaseModConnectConfig
         $this -> isAlwaysConfirmEmail = (bool)getParam('bx_unacon_confirm_email'); 
         $this -> isAlwaysAutoApprove = (bool)getParam('bx_unacon_approve');
 
-        $this -> bAutoFriends = 'on' == getParam('bx_unacon_auto_friends');
+        $this -> bAutoFriends = (bool)getParam('bx_unacon_auto_friends');
 
         $this -> sPageStart = BX_DOL_URL_ROOT . $this -> getBaseUri() . 'start';
         $this -> sPageHandle = BX_DOL_URL_ROOT . $this -> getBaseUri() . 'handle';

+ 44 - 0
modules/boonex/una_connect/classes/BxUnaConModule.php

@@ -86,6 +86,9 @@ class BxUnaConModule extends BxBaseModConnectModule
         $sExpiresAt = new \DateTime('+' . $sExpiresIn . ' seconds');
         $sRefreshToken = $aResponse['refresh_token'];
 
+        $oSession = BxDolSession::getInstance();
+        $oSession->setValue($this->getName() . '_access_token', $sAccessToken);
+        
         // request info about profile
         $s = bx_file_get_contents($this->_oConfig->sApiUrl . 'api/me', array(), 'get', array(
             'Authorization: Bearer ' . $sAccessToken,
@@ -119,6 +122,46 @@ class BxUnaConModule extends BxBaseModConnectModule
         }
     }
 
+    /**
+     * Make friends
+     *
+     * @param $iProfileId integer
+     * @return void
+     */
+    protected function _makeFriends($iProfileId)
+    {
+        if (!$this->_oConfig->bAutoFriends)
+            return;
+
+        $oConnFrinds = BxDolConnection::getObjectInstance('sys_profiles_friends');
+        if (!$oConnFrinds)
+            return;
+
+        // request info about profile
+        if (!($iRemoteProfileId = $this->_oDb->getRemoteProfileId($iProfileId)))
+            return;
+        $oSession = BxDolSession::getInstance();
+        if (!($sAccessToken = $oSession->getValue($this->getName() . '_access_token')))
+            return;
+        $s = bx_file_get_contents($this->_oConfig->sApiUrl . 'api/friends?id=' . $iRemoteProfileId, array(), 'get', array(
+            'Authorization: Bearer ' . $sAccessToken,
+        ));
+
+        // handle error
+        if (!$s || NULL === ($aResponse = json_decode($s, true)) || !$aResponse || isset($aResponse['error']) || !isset($aResponse['friends'])) {
+            $sErrorDescription = isset($aResponse['error_description']) ? $aResponse['error_description'] : _t('_error occured');
+            return;
+        }
+
+        // add friends & followers
+        foreach ($aResponse['friends'] as $iRemoteProfileId) {
+            if (!($iLocalProfileId = $this->_oDb->getProfileId($iRemoteProfileId)))
+                continue;
+            $oConnFrinds->actionAdd($iProfileId, $iLocalProfileId);
+            $oConnFrinds->actionAdd($iLocalProfileId, $iProfileId);
+        }
+    }
+
     /**
      * @param $aProfileInfo - remote profile info
      * @param $sAlternativeName - suffix to add to NickName to make it unique
@@ -131,6 +174,7 @@ class BxUnaConModule extends BxBaseModConnectModule
         $aProfileFields['name'] = $aProfileInfo['profile_display_name'];
         $aProfileFields['fullname'] = $aProfileInfo['profile_display_name'];
         $aProfileFields['picture'] = $aProfileInfo['picture'];
+        $aProfileFields['allow_view_to'] = getParam('bx_unacon_privacy');
         
         return $aProfileFields;
     }

+ 1 - 0
modules/boonex/una_connect/install/sql/enable.sql

@@ -37,6 +37,7 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_unacon_url', '', @iCategId, '_bx_unacon_option_app_url', 'digit', '', '', 30, ''),
 ('bx_unacon_redirect_page', 'dashboard', @iCategId, '_sys_connect_option_redirect', 'select', '', '', 40, 'join,settings,dashboard,index'),
 ('bx_unacon_module', 'bx_persons', @iCategId, '_sys_connect_option_module', 'select', '', '', 50, 'a:2:{s:6:"module";s:9:"bx_unacon";s:6:"method";s:20:"get_profiles_modules";}'),
+('bx_unacon_privacy', '3', @iCategId, '_sys_connect_option_privacy', 'select', '', '', 54, 'a:2:{s:6:"module";s:9:"bx_unacon";s:6:"method";s:18:"get_privacy_groups";}'),
 ('bx_unacon_auto_friends', 'on', @iCategId, '_bx_unacon_option_auto_friends', 'checkbox', '', '', 60, ''),
 ('bx_unacon_confirm_email', 'on', @iCategId, '_sys_connect_option_confirm_email', 'checkbox', '', '', 70, ''),
 ('bx_unacon_approve', '', @iCategId, '_sys_connect_option_approve', 'checkbox', '', '', 80, ''),