'; protected $sync_fields = array( 'description' => array( 'label' => 'Bio', 'node' => 'me' ), 'lang' => array( 'label' => 'Language', 'node' => 'me' ), 'location' => array( 'label' => 'Location', 'node' => 'me' ), 'created_at' => array( 'label' => 'Register date', 'node' => 'me' ), 'profile_url' => array( 'label' => 'Profile URL', 'node' => 'me' ), 'screen_name' => array( 'label' => 'Screen name', 'node' => 'me' ), 'url' => array( 'label' => 'Owned website', 'node' => 'me' ) ); public function __construct() { $this->id = 'twitter'; $this->label = 'Twitter'; $this->path = dirname(__FILE__); $this->requiredFields = array( 'consumer_key' => 'Consumer Key', 'consumer_secret' => 'Consumer Secret' ); $this->oauthRedirectBehavior = 'default_redirect_but_app_has_restriction'; parent::__construct(array( 'consumer_key' => '', 'consumer_secret' => '', 'login_label' => 'Continue with Twitter', 'register_label' => 'Sign up with Twitter', 'link_label' => 'Link account with Twitter', 'unlink_label' => 'Unlink account from Twitter', 'profile_image_size' => 'normal' )); } protected function forTranslation() { __('Continue with Twitter', 'nextend-facebook-connect'); __('Sign up with Twitter', 'nextend-facebook-connect'); __('Link account with Twitter', 'nextend-facebook-connect'); __('Unlink account from Twitter', 'nextend-facebook-connect'); } public function validateSettings($newData, $postedData) { $newData = parent::validateSettings($newData, $postedData); foreach ($postedData AS $key => $value) { switch ($key) { case 'tested': if ($postedData[$key] == '1' && (!isset($newData['tested']) || $newData['tested'] != '0')) { $newData['tested'] = 1; } else { $newData['tested'] = 0; } break; case 'consumer_key': case 'consumer_secret': $newData[$key] = trim(sanitize_text_field($value)); if ($this->settings->get($key) !== $newData[$key]) { $newData['tested'] = 0; } if (empty($newData[$key])) { Notices::addError(sprintf(__('The %1$s entered did not appear to be a valid. Please enter a valid %2$s.', 'nextend-facebook-connect'), $this->requiredFields[$key], $this->requiredFields[$key])); } break; case 'profile_image_size': $newData[$key] = trim(sanitize_text_field($value)); break; } } return $newData; } /** * @return NextendSocialProviderTwitterClient */ public function getClient() { if ($this->client === null) { require_once dirname(__FILE__) . '/twitter-client.php'; $this->client = new NextendSocialProviderTwitterClient($this->id, $this->settings->get('consumer_key'), $this->settings->get('consumer_secret')); $this->client->setRedirectUri($this->getRedirectUriForOAuthFlow()); } return $this->client; } /** * @return array|mixed|object * @throws Exception */ protected function getCurrentUserInfo() { $response = $this->getClient() ->get('account/verify_credentials', array( 'include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true' )); if (isset($response['id']) && isset($response['id_str'])) { // On 32bit and Windows server, we must copy id_str to id as the id int representation won't be OK $response['id'] = $response['id_str']; } return $response; } public function getMe() { return $this->authUserData; } /** * @param $key * * @return string */ public function getAuthUserData($key) { switch ($key) { case 'id': return $this->authUserData['id']; case 'email': return !empty($this->authUserData['email']) ? $this->authUserData['email'] : ''; case 'name': return $this->authUserData['name']; case 'username': return $this->authUserData['screen_name']; case 'first_name': $name = explode(' ', $this->getAuthUserData('name'), 2); return isset($name[0]) ? $name[0] : ''; case 'last_name': $name = explode(' ', $this->getAuthUserData('name'), 2); return isset($name[1]) ? $name[1] : ''; case 'picture': $profile_image_size = $this->settings->get('profile_image_size'); $profile_image = $this->authUserData['profile_image_url_https']; $avatar_url = ''; if (!empty($profile_image)) { switch ($profile_image_size) { case 'mini': $avatar_url = str_replace('_normal.', '_' . $profile_image_size . '.', $profile_image); break; case 'normal': $avatar_url = $profile_image; break; case 'bigger': $avatar_url = str_replace('_normal.', '_' . $profile_image_size . '.', $profile_image); break; case 'original': $avatar_url = str_replace('_normal.', '.', $profile_image); break; } } return $avatar_url; } return parent::getAuthUserData($key); } public function syncProfile($user_id, $provider, $access_token) { if ($this->needUpdateAvatar($user_id)) { if ($this->getAuthUserData('picture')) { $this->updateAvatar($user_id, $this->getAuthUserData('picture')); } } $this->storeAccessToken($user_id, $access_token); } public function deleteLoginPersistentData() { parent::deleteLoginPersistentData(); if ($this->client !== null) { $this->client->deleteLoginPersistentData(); } } public function getAvatar($user_id) { if (!$this->isUserConnected($user_id)) { return false; } $picture = $this->getUserData($user_id, 'profile_picture'); if (!$picture || $picture == '') { return false; } return $picture; } } NextendSocialLogin::addProvider(new NextendSocialProviderTwitter);