Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*------------------------------------------------------------------------
- # twitterconnect.php - Content - Embedding Tweet With Shortcode
- # ------------------------------------------------------------------------
- # author Sabuj Kundu of Codeboxr Team
- # copyright Copyright (C) 2010-2012 codeboxr.com. All Rights Reserved.
- # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
- # Websites: http://codeboxr.com
- # Technical Support: Forum - http://codeboxr.com/product/tweet-embed-using-shortcode-in-joomla
- # Plugin type: content
- -------------------------------------------------------------------------*/
- // Check to ensure this file is included in Joomla!
- defined('_JEXEC') or die( 'Restricted access' );
- require_once( JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_cbsocialappsoauth' . DS . 'tables' . DS . 'cbsocialappsoauthadmin.php' );
- //require_once( JPATH_ROOT .DS.'components' .DS.'com_community' .DS.'tables' .DS.'oauth.php');
- require_once( JPATH_ROOT . DS . 'components' . DS . 'com_mysocialtimeline' . DS . 'includes'.DS.'twitteroauth'.DS.'twitteroauth.php'); // must have
- //jimport('joomla.form.formfield');
- /**
- * Form Field class for the Joomla Framework.
- *
- */
- //class JFormFieldTwitterconnect extends JFormField
- class JElementTwitterconnect extends JElement
- {
- /**
- * Color picker form field type compatible with Joomla 1.6. Displays an Adobe type color picker panel, and returns a six-digit hex value, eg #cc99ff
- */
- //protected $type = 'twitterconnect';
- var $_name = 'twitterconnect';
- /**
- */
- //protected function getInput()
- function fetchElement( $name, $value, &$node, $control_name )
- {
- $baseurl = JURI::base();
- $baseurl = str_replace('administrator/','',$baseurl);
- /*
- // Initialize some field attributes.
- $size = $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';
- $maxLength = $this->element['maxlength'] ? ' maxlength="'.(int) $this->element['maxlength'].'"' : '';
- $class = $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';
- $readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
- $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
- $scriptname = $baseurl.'plugins/content/contentscrollpane/contentscrollpane/jscolor/color-picker.js';
- $doc =& JFactory::getDocument();
- $doc->addScript($scriptname);
- $options = array();
- if( $this->element['cellwidth']){ $options[] = "cellWidth:". (int) $this->element['cellwidth'];}
- if( $this->element['cellheight']){ $options[] = "cellHeight:".(int) $this->element['cellheight'];}
- if( $this->element['top']){ $options[] = "top:". (int) $this->element['top'];}
- if( $this->element['left']){ $options[] = "left:". (int) $this->element['left'];}
- $optionString = implode(',',$options);
- $js = 'window.addEvent(\'domready\', function(){
- var colorInput = $(\''.$this->id.'\');
- var cpicker = new ColorPicker(colorInput,{'.$optionString.'});
- });
- ';
- $doc->addScriptDeclaration($js);
- // Initialize JavaScript field attributes.
- $onchange = $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';
- return '<input type="text" name="'.$this->name.'" id="'.$this->id.'"' .
- ' value="'.htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8').'"' .
- $class.$size.$disabled.$readonly.$onchange.$maxLength.'/>';
- *
- */
- //$extid = (int) JRequest::getInt('cid');
- $extid = JRequest::getVar('cid', 0, '', 'array');
- $extid = (int)$extid[0];
- //var_dump($extid);
- $oauth = & JTable::getInstance( 'Oauth' , 'CBSocialappsadmin' );
- $productionmode = true; // true = production version false = development version(for local testing)
- if($productionmode){
- $callback = JURI::root() .'administrator/index.php?option=com_menus&menutype=mainmenu&task=edit&cid[]='.$extid;
- }
- else{
- $callback = 'http://127.0.0.1/jtest5/administrator/index.php?option=com_menus&menutype=mainmenu&task=edit&cid[]='.$extid;
- }
- //$callback = JURI::root() .'administrator/index.php?option=com_modules&view=module&layout=edit&id='.$extid;
- $callbackurl = $callback.'&tokenmode=1';
- //var_dump($callbackurl);
- // Get Plugin info
- /*
- $db =& JFactory::getDbo();
- $query = $db->getQuery(true);
- //$query->select('element, client_id');
- $query->from('#__extensions');
- $query->where('extension_id = '.$extid);
- $query->where('type = '.$db->quote('module'));
- $db->setQuery($query);
- */
- //var_dump($moduletbale->params);
- //$plugin =& JPluginHelper::getPlugin('content', 'mysocialtimelinecom');
- $plugin = JTable::getInstance('menu', 'JTable', array());
- $plugin->id = $extid;
- $plugin->load();
- //var_dump($plugin);
- // Get the plugin parameters
- //$extid = JRequest::getInt('extension_id','');
- $removeapp = JRequest::getInt('removeapp',0);
- $oauth =& JTable::getInstance( 'Oauth' , 'CBSocialappsadmin' );
- $oauth->extid = $extid;
- $oauth->app = 'mysocialtimelinecom';
- if($removeapp){
- //var_dump($extid);
- //var_dump($oauth);
- $oauth->delete();
- //exit(1);
- }
- //var_dump($extid);
- //define('CONSUMER_KEY', $consumerKey);
- //define('CONSUMER_SECRET', $consumerSecret);
- //define('OAUTH_CALLBACK', $callbackurl);
- /* Build TwitterOAuth object with client credentials. */
- ob_start();
- $consumerKey = '';
- $consumerSecret = '';
- $plgdisabled = true;
- if(is_object($plugin)){
- //$pluginParams = new JRegistry( $plugin->params );
- $pluginParams = new JParameter( $plugin->params );
- //var_dump($pluginParams);
- $consumerKey = $pluginParams->get('consumerKey','3ca7EalPxMh5uJFFC9dgdw');
- $consumerSecret = $pluginParams->get('consumerSecret','hKLPw1nOpzJXOn8fVYju1dAeGSOdhoIuRngFyAkU9Ts');
- $plgdisabled = false;
- }
- if(empty($consumerKey) || empty($consumerSecret)):
- if($plgdisabled){
- echo '<span style="float:left; display:inline;">Please enable the plugin.</span>';
- }
- else{
- echo '<span style="float:left; display:inline;">Please add Consumer Key and Consumer Secret</span>';
- }
- else:
- $oauth->extid = $extid;
- $oauth->app = 'mysocialtimelinecom';
- $tokenmode = JRequest::getInt('tokenmode',0);
- if($oauth->load( $extid , 'mysocialtimelinecom') && $tokenmode)
- {
- $oauth_token = JRequest::getString('oauth_token','');
- $oauth_verifier = JRequest::getString('oauth_verifier','');
- //
- $requesttoken = unserialize($oauth->requesttoken); // we again convert to array
- if(!empty($oauth_token ) && !empty ($oauth_verifier) && ($oauth_token == $requesttoken['oauth_token']) && !empty($_SESSION['mysocialtimelinecom_oauth_token_secret'])){
- /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
- $consumer = new TwitterOAuth($consumerKey, $consumerSecret, $oauth_token, $_SESSION['mysocialtimelinecom_oauth_token_secret']);
- /* Request access tokens from twitter */
- $access_token = $consumer->getAccessToken($oauth_verifier);
- //var_dump($access_token);
- $oauth->app = 'mysocialtimelinecom';
- $oauth->extid = $extid;
- $oauth->accesstoken = serialize($access_token);
- //$oauth->requesttoken = $oauth_token;
- if( !empty($oauth->accesstoken) )
- {
- if (200 == $consumer->http_code) {
- $storeval = $oauth->store();
- echo '<a style="float:left; display:inline;" href="'.$callback.'&removeapp=1"><img src="'.$baseurl.'components/com_mysocialtimeline/images/twitterconnect/twitter_revoke.png" alt="Remove Twitter/Unauthorize Twitter" title="Remove Twitter/Unauthorize Twitter" /></a>';
- } else {
- /* Save HTTP status for error dialog on connnect page.*/
- echo '<a style="float:left; display:inline;" href="'.$callback.'">Something wrong, please click here to refresh1!</a>';
- }
- //var_dump($storeval);
- //User is already authenticated and we have the proper tokens to fetch data.
- //$url = $callback;
- //$removeappurl = JURI::root() .'index.php?option=com_community'.rawurlencode('&view=profile&task=callback&app=advanceinstagramforjom');
- }
- else{
- echo '<a style="float:left; display:inline;" href="'.$callback.'">Something wrong, please click here to refresh1!</a>';
- }
- }
- else{
- echo '<a style="float:left; display:inline;" href="'.$callback.'">Something wrong, please click here to refresh2!</a>';
- }
- }
- else{
- $consumer = new TwitterOAuth($consumerKey, $consumerSecret);
- if( !$oauth->load( $extid , 'mysocialtimelinecom') || empty($oauth->accesstoken) ){
- $request_token = $consumer->getRequestToken($callbackurl); //original was array
- //var_dump($request_token);
- /* If last connection failed don't display authorization link. */
- switch ($consumer->http_code) {
- case 200:
- // 200 means ok
- //$oauth->extid = $extid;
- //$oauth->accesstoken = $extid;
- //$request_token = $consumer->getRequestToken($callbackurl); //original was array
- $_SESSION['mysocialtimelinecom_oauth_token'] = $token = $request_token['oauth_token'];
- $_SESSION['mysocialtimelinecom_oauth_token_secret'] = $request_token['oauth_token_secret'];
- $oauth->requesttoken = serialize($request_token);
- $storeval = $oauth->store();
- $url = $consumer->getAuthorizeURL($token);
- //header('Location: ' . $url);
- echo '<a style="float:left; display:inline;" href="'.$url.'"><img src="'.$baseurl.'components/com_mysocialtimeline/images/twitterconnect/darker.png" alt="Sign in with Twitter"/></a>';
- break;
- default:
- /* Show notification if something went wrong. */
- echo '<a style="float:left; display:inline;" href="'.$callback.'">Something wrong, please click here to refresh3!</a>';
- }
- }
- else{
- echo '<a style="float:left; display:inline;" href="'.$callback.'&removeapp=1"><img src="'.$baseurl.'components/com_mysocialtimeline/images/twitterconnect/twitter_revoke.png" alt="Remove Twitter/Unauthorize Twitter" title="Remove Twitter/Unauthorize Twitter" /></a>';
- }
- }//end no token mode
- endif;
- $html = ob_get_contents();
- ob_end_clean();
- return $html;
- //$content = '<a href="#"><img src="'.$baseurl.'plugins/content/mysocialtimelinecom/mysocialtimelinecom/images/darker.png" alt="Sign in with Twitter"/></a>';
- //return $content;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement