/** * 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(); } } }
/** * vkgroups * * @param string $selected The key that is selected * @param string $name The name for the field * @param array $attribs Additional HTML attributes for the <select> tag* * @param string $access_token Params * @param int $channel_id Params * * @return string HTML */ public static function vkgroups($selected = null, $name = 'xtform[vkgroup_id]', $attribs = array(), $access_token = null, $channel_id = null) { $options = array(); $attribs = array(); if (!empty($access_token) && !empty($channel_id)) { $options[] = JHTML::_('select.option', null, '-' . JText::_('JSELECT') . '-'); try { $ch = F0FTable::getAnInstance('Channel', 'AutoTweetTable'); $result = $ch->load($channel_id); if (!$result) { break; } $params = $ch->params; $registry = new JRegistry(); $registry->loadString($params); $registry->set('access_token', $access_token); $ch->bind(array('params' => (string) $registry)); $vkChannelHelper = new VkChannelHelper($ch); $result = $vkChannelHelper->getGroups(); if ($result['status']) { $groups = $result['items']; $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_VK_CHANNEL); foreach ($groups as $group) { $nm = $group['name']; if (empty($nm) || $nm == 'null') { $nm = $group['gid']; } $attr = 'social_url="' . $group['url'] . '" social_icon="' . $icon . '"'; $attrs = array('attr' => $attr, 'option.attr' => 'social_url', 'option.key' => 'value', 'option.text' => 'text', 'disable' => false); $opt = JHTML::_('select.option', $group['gid'], $nm, $attrs); $options[] = $opt; } } $attribs['id'] = $name; $attribs['list.attr'] = null; $attribs['list.translate'] = false; $attribs['option.key'] = 'value'; $attribs['option.text'] = 'text'; $attribs['option.attr'] = 'social_url'; $attribs['list.select'] = $selected; return EHtmlSelect::genericlist($options, $name, $attribs); } catch (Exception $e) { $error_message = $e->getMessage(); $options[] = JHTML::_('select.option', '', $error_message); } } else { $options[] = JHTML::_('select.option', null, '-' . JText::_('JSELECT') . '-'); } return EHtmlSelect::customGenericList($options, $name, $attribs, $selected, $name, array('option.attr' => 'access_token')); }
/** * getVkGroups. * * @return void */ public function getVkGroups() { @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'; $items = 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->getGroups(); $jselect = array('gid' => 0, 'name' => '-' . JText::_('JSELECT') . '-', 'screen_name' => '', 'is_closed' => 0, 'type' => 'page', 'photo' => '', 'photo_medium' => '', 'photo_big' => '', 'url' => ''); array_unshift($result['items'], $jselect); $status = $result['status']; $message = $result['error_message']; $items = $result['items']; $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, 'groups' => $items, 'social_icon' => $icon)); echo EJSON_START . $message . EJSON_END; flush(); JFactory::getApplication()->close(); }
</div> <?php $jsonAccessToken = null; $accessToken = null; $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';