/** * callback. * * @return void */ public function callback() { // CSRF prevention if ($this->csrfProtection) { $this->_csrfProtection(); } $channelId = $this->input->getUint('channelId'); $vkcode = $this->input->getCmd('code'); // Error throw if (!empty($vkcode)) { $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable'); $result = $channel->load($channelId); if (!$result) { throw new Exception('Channel failed to load!'); } $vkChannelHelper = new VkChannelHelper($channel); $redirect_uri = self::getCallbackUrl($channelId); $jsonAccessToken = $vkChannelHelper->getJsonAccessToken($vkcode, $redirect_uri); $registry = new JRegistry(); $registry->loadString($channel->params); $registry->set('access_token', $jsonAccessToken); $channel->bind(array('params' => (string) $registry)); $channel->store(); // Redirect $url = 'index.php?option=com_autotweet&view=channels&task=edit&id=' . $channelId; $this->setRedirect($url); $this->redirect(); } }
$userId = null; $expiresIn = null; $authUrl = '#'; $authUrlButtonStyle = 'disabled'; $validationGroupStyle = 'hide'; // New channel, not even saved if ($this->item->id == 0) { $message = JText::_('COM_AUTOTWEET_CHANNEL_VK_NEWCHANNEL_NOAUTHORIZATION'); include_once 'auth_button.php'; } else { $vkChannelHelper = new VkChannelHelper($this->item); $isAuth = $vkChannelHelper->isAuth(); // New channel, but saved if ($isAuth) { // We have an access Token! $jsonAccessToken = $vkChannelHelper->getJsonAccessToken(); $accessToken = $vkChannelHelper->getAccessToken(); $userId = $vkChannelHelper->getUserId(); $expiresIn = $vkChannelHelper->getExpiresIn(); // $this->item->xtform->set('social_url', '#'); $validationGroupStyle = null; include_once 'validation_button.php'; } else { $message = JText::_('COM_AUTOTWEET_CHANNEL_VK_NEWCHANNEL_AUTHORIZATION'); $application_id = $this->item->xtform->get('application_id'); $thisUrl = 'http://api.vkontakte.ru/blank.html'; $authUrl = $vkChannelHelper->getAuthorizeUrlDesktopStandalone($application_id, $thisUrl); $authUrlButtonStyle = null; include_once 'auth_button.php'; include_once 'validation_button.php'; }