public function fetchElement($name, $value, &$node, $control_name) { $lang =& JFactory::getLanguage(); $lang->load('com_community', JPATH_ROOT); if (!JPluginHelper::importPlugin('community', 'twitter')) { return JText::sprintf('COM_COMMUNITY_PLUGIN_FAIL_LOAD', 'Twitter'); } $my = CFactory::getUser(); $consumer = plgCommunityTwitter::getConsumer(); $oauth =& JTable::getInstance('Oauth', 'CTable'); ob_start(); if (!$oauth->load($my->id, 'twitter') || empty($oauth->accesstoken)) { $oauth->userid = $my->id; $oauth->app = 'twitter'; $oauth->requesttoken = serialize($consumer->getRequestToken()); $oauth->store(); ?> <div><?php echo JText::_('COM_COMMUNITY_TWITTER_LOGIN'); ?> </div> <a href="<?php echo $consumer->getRedirectUrl(); ?> "><img src="<?php echo JURI::root(); ?> components/com_community/assets/twitter.png" border="0" alt="here" /></a> <?php } else { //User is already authenticated and we have the proper tokens to fetch data. $url = CRoute::_('index.php?option=com_community&view=oauth&task=remove&app=twitter'); ?> <div><?php echo JText::sprintf('COM_COMMUNITY_TWITTER_REMOVE_ACCESS', $url); ?> </div> <?php } $html = ob_get_contents(); ob_end_clean(); return $html; }
public function callback() { $mainframe =& JFactory::getApplication(); $my = CFactory::getUser(); $denied = JRequest::getVar('denied', ''); $app = JRequest::getVar('app', ''); $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id, false); if (empty($app)) { echo JText::_('CC INVALID APPLICATION'); return; } if ($my->id == 0) { echo JText::_('CC INVALID ACCESS'); return; } if (!empty($denied)) { $mainframe->redirect($url, JText::_('You have denied access to the application')); } $oauth =& JTable::getInstance('Oauth', 'CTable'); if ($oauth->load($my->id, $app)) { $consumer = plgCommunityTwitter::getConsumer(); $oauth->userid = $my->id; $oauth->app = $app; $getData = JRequest::get('get'); try { $oauth->accesstoken = serialize($consumer->getAccessToken($getData, unserialize($oauth->requesttoken))); } catch (Exception $error) { $mainframe->redirect($url, $error->getMessage()); } if (!empty($oauth->accesstoken)) { $oauth->store(); } $msg = JText::_('Successful authentication'); $mainframe->redirect($url, $msg); } }
public function callback() { $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $my = CFactory::getUser(); $denied = $jinput->get('denied', '', 'NONE'); //JRequest::getVar( 'denied' , '' ); $app = $jinput->get('app', '', 'STRING'); //JRequest::getVar( 'app' , '' ); $oauth_verifier = $jinput->get('oauth_verifier', '', 'STRING'); //JRequest::getVar( 'oauth_verifier' , '' ); $verify = $jinput->get('verify', '', 'NONE'); //JRequest::getVar( 'verify' , '' ); $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id, false); $consumer = plgCommunityTwitter::getConsumer(); if ($oauth_verifier && empty($verify)) { $consumer->config['user_token'] = $_SESSION['oauth']['oauth_token']; $consumer->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret']; $code = $consumer->request('POST', $consumer->url('oauth/access_token', ''), array('oauth_verifier' => $_REQUEST['oauth_verifier'])); if ($code == 200) { $_SESSION['access_token'] = $consumer->extract_params($consumer->response['response']); unset($_SESSION['oauth']); $instance = JURI::getInstance(); $url = JURI::getInstance()->toString(); $mainframe->redirect($url . '&verify=true'); } else { echo JText::_('COM_COMMUNITY_INVALID_APPLICATION'); return; } } if (empty($app)) { echo JText::_('COM_COMMUNITY_INVALID_APPLICATION'); return; } if ($my->id == 0) { echo JText::_('COM_COMMUNITY_INVALID_ACCESS'); return; } if (!empty($denied)) { $mainframe->redirect($url, JText::_('COM_COMMUNITY_OAUTH_APPLICATION_ACCESS_DENIED_WARNING')); } $oauth = JTable::getInstance('Oauth', 'CTable'); if ($oauth->load($my->id, $app) && $verify) { $consumer->config['user_token'] = $_SESSION['access_token']['oauth_token']; $consumer->config['user_secret'] = $_SESSION['access_token']['oauth_token_secret']; /* The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview. */ $code = $consumer->request('GET', $consumer->url('1.1/account/verify_credentials')); if ($code == 200) { $resp = json_decode($consumer->response['response']); $consumer->config['screen_name'] = $resp->screen_name; } else { /** * @todo Should we display response / error of message */ echo JText::_('COM_COMMUNITY_INVALID_ACCESS'); return; } $oauth->userid = $my->id; $oauth->app = $app; $getData = JRequest::get('get'); try { $oauth->accesstoken = serialize($consumer->config); } catch (Exception $error) { $mainframe->redirect($url, $error->getMessage()); } if (!empty($oauth->accesstoken)) { $oauth->store(); } $msg = JText::_('COM_COMMUNITY_OAUTH_AUTHENTICATION_SUCCESS'); $mainframe->redirect($url, $msg); } }
public static function getOAuthRequest() { if (!JPluginHelper::importPlugin('community', 'twitter')) { return JText::sprintf('COM_COMMUNITY_PLUGIN_FAIL_LOAD', 'Twitter'); } $my = CFactory::getUser(); $consumer = plgCommunityTwitter::getConsumer(); $oauth = JTable::getInstance('Oauth', 'CTable'); ob_start(); if (!$oauth->load($my->id, 'twitter') || empty($oauth->accesstoken)) { $callback = JURI::root() . 'index.php?option=com_community&view=oauth&task=callback&app=twitter'; $oauth->userid = $my->id; $oauth->app = 'twitter'; $code = $consumer->request('POST', $consumer->url('oauth/request_token', ''), array('oauth_callback' => $callback)); if ($code == 200) { $_SESSION['oauth'] = $consumer->extract_params($consumer->response['response']); $temp_credentials = $_SESSION['oauth']['oauth_token']; $authurl = $consumer->url("oauth/authorize", '') . "?oauth_token={$_SESSION['oauth']['oauth_token']}"; } else { $temp_credentials = null; $authurl = null; //echo 'false;';//outputError($tmhOAuth); } //$temp_credentials = $consumer->getRequestToken($callback); $oauth->requesttoken = serialize($temp_credentials); $oauth->store(); ?> <?php if ($code == 200) { ?> <div><?php echo JText::_('COM_COMMUNITY_TWITTER_LOGIN'); ?> </div> <a href="<?php echo $authurl; ?> "><img src="<?php echo JURI::root(true); ?> /components/com_community/assets/twitter.png" border="0" alt="here" /></a> <?php } else { ?> <div><?php echo JText::_('COM_COMMUNITY_TWITTER_FAILED_REQUEST_TOKEN'); ?> </div> <?php } ?> <?php } else { //User is already authenticated and we have the proper tokens to fetch data. $url = CRoute::_('index.php?option=com_community&view=oauth&task=remove&app=twitter'); ?> <div><?php echo JText::sprintf('COM_COMMUNITY_TWITTER_REMOVE_ACCESS', $url); ?> </div> <?php } $html = ob_get_contents(); ob_end_clean(); return $html; }