/** * callback. * * @return void */ public function callbackStandalone() { // CSRF prevention if ($this->csrfProtection) { $this->_csrfProtection(); } $channelId = $this->input->getUint('channelId'); $access_token = $this->input->getCmd('access_token'); $expires_in = $this->input->getCmd('expires_in'); $user_id = $this->input->getCmd('user_id'); // Error throw if (!empty($access_token)) { $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable'); $result = $channel->load($channelId); if (!$result) { throw new Exception('Channel failed to load!'); } $vkChannelHelper = new VkChannelHelper($channel); $oAccessToken = new StdClass(); $oAccessToken->access_token = $access_token; $oAccessToken->expires_in = $expires_in; $oAccessToken->user_id = $user_id; $jsonAccessToken = json_encode($oAccessToken); $vkChannelHelper->setJsonAccessToken($jsonAccessToken); $userSettings = $vkChannelHelper->getUserSettings(); if (is_array($userSettings) && ($userSettings['response'] = 65536)) { $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(); } } }
/** * getVkValidation. * * @return void */ public function getVkValidation() { @ob_end_clean(); header('Content-type: text/plain'); // No JInputJSON in J2.5 $raw = file_get_contents('php://input'); $data = json_decode($raw, true); $safeHtmlFilter = JFilterInput::getInstance(); $token = $data['token']; $token = $safeHtmlFilter->clean($token, 'ALNUM'); $this->input->set($token, 1); // CSRF prevention if ($this->csrfProtection) { $this->_csrfProtection(); } $channel_id = $data['channel_id']; $channel_id = $safeHtmlFilter->clean($channel_id, 'ALNUM'); $access_token = $data['access_token']; $access_token = $safeHtmlFilter->clean($access_token, 'STRING'); $status = false; $error_message = 'Unknown'; $user = null; $url = null; $icon = null; $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable'); $result = $channel->load($channel_id); if (!$result) { $error_message = 'Channel failed to load!'; } else { try { $params = $channel->params; $registry = new JRegistry(); $registry->loadString($params); $registry->set('access_token', $access_token); $channel->bind(array('params' => (string) $registry)); $vkChannelHelper = new VkChannelHelper($channel); $result = $vkChannelHelper->getUserSettings(); $status = $result['status']; $message = $result['error_message']; $user = $result['user']; $url = $result['url']; $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_VK_CHANNEL); } catch (Exception $e) { $error_message = $e->getMessage(); } } $message = json_encode(array('status' => $status, 'error_message' => $error_message, 'user' => $user, 'social_icon' => $icon, 'social_url' => $url)); echo EJSON_START . $message . EJSON_END; flush(); JFactory::getApplication()->close(); }