public function callbackAction()
 {
     $oauth_token = $this->getRequest()->getParam('oauth_token');
     $oauth_verifier = $this->getRequest()->getParam('oauth_verifier');
     if (!$oauth_token || !$oauth_verifier) {
         return $this->_redirectUrl();
     }
     if ($oauth_token != Mage::getSingleton('core/session')->getData('oauth_token')) {
         return $this->_redirectUrl();
     }
     $connection = new TumblrOAuth(Mage::getStoreConfig('gomage_social/tumblr/id'), Mage::getStoreConfig('gomage_social/tumblr/secret'), Mage::getSingleton('core/session')->getData('oauth_token'), Mage::getSingleton('core/session')->getData('oauth_token_secret'));
     $access_token = $connection->getAccessToken($oauth_verifier);
     Mage::getSingleton('core/session')->unsetData('oauth_token');
     Mage::getSingleton('core/session')->unsetData('oauth_token_secret');
     $profile = null;
     switch ($connection->http_code) {
         case 200:
             $profile = $connection->get("http://api.tumblr.com/v2/user/info");
             break;
         default:
             $this->getSession()->addError($this->__('Could not connect to Tumblr. Refresh the page or try again later.'));
             return $this->_redirectUrl();
     }
     if ($profile) {
         $profile->name = $profile->response->user->name;
         $profile->id = $profile->name;
         if ($profile->id) {
             $social_collection = Mage::getModel('gomage_social/entity')->getCollection()->addFieldToFilter('social_id', $profile->id)->addFieldToFilter('type_id', GoMage_Social_Model_Type::TUMBLR);
             if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) {
                 $social_collection->addFieldToFilter('website_id', Mage::app()->getWebsite()->getId());
             }
             $social = $social_collection->getFirstItem();
             if ($social && $social->getId()) {
                 if ($social->social_id == $profile->id) {
                     $customer = Mage::getModel('customer/customer');
                     if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) {
                         $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
                     }
                     $customer->load($social->getData('customer_id'));
                     if ($customer && $customer->getId()) {
                         if (!$customer->getConfirmation()) {
                             $this->getSession()->loginById($customer->getId());
                         } else {
                             $this->getSession()->addError($this->__('This account is not confirmed.'));
                         }
                     }
                 }
             } else {
                 $profile->url = Mage::getUrl('gomage_social/tumblr/checkEmail', array('_secure' => true));
                 $profile->urlEmailClose = Mage::getUrl('gomage_social/twitter/emailClose', array('_secure' => true));
                 $profile->type_id = GoMage_Social_Model_Type::TUMBLR;
                 Mage::getSingleton('core/session')->setGsProfile($profile);
             }
         }
     }
     return $this->_redirectUrl();
 }
Пример #2
0
 /**
  * This method is used to process the second part of authentication workflow, after redirect
  *
  * @return array Array with status and user details
  */
 public function processAuth()
 {
     $ngConnectINI = eZINI::instance('ngconnect.ini');
     $http = eZHTTPTool::instance();
     $consumerKey = trim($ngConnectINI->variable('LoginMethod_tumblr', 'AppConsumerKey'));
     $consumerSecret = trim($ngConnectINI->variable('LoginMethod_tumblr', 'AppConsumerSecret'));
     if (empty($consumerKey) || empty($consumerSecret)) {
         return array('status' => 'error', 'message' => 'Consumer key or consumer secret undefined.');
     }
     $oAuthToken = trim($http->getVariable('oauth_token', ''));
     $oAuthVerifier = trim($http->getVariable('oauth_verifier', ''));
     $state = trim($http->getVariable('state', ''));
     if (empty($oAuthToken) || empty($oAuthVerifier) || empty($state)) {
         return array('status' => 'error', 'message' => 'oauth_token, oauth_verifier or state GET parameters undefined.');
     }
     if (!$http->hasSessionVariable('NGConnectOAuthState') || $state != $http->sessionVariable('NGConnectOAuthState')) {
         $http->removeSessionVariable('NGConnectOAuthState');
         return array('status' => 'error', 'message' => 'State parameter does not match stored value.');
     } else {
         $http->removeSessionVariable('NGConnectOAuthState');
     }
     if (!$http->hasSessionVariable('NGConnectOAuthToken') || !$http->hasSessionVariable('NGConnectOAuthTokenSecret') || $oAuthToken != $http->sessionVariable('NGConnectOAuthToken')) {
         $http->removeSessionVariable('NGConnectOAuthToken');
         $http->removeSessionVariable('NGConnectOAuthTokenSecret');
         return array('status' => 'error', 'message' => 'Token does not match stored value.');
     } else {
         $oAuthTokenSecret = $http->sessionVariable('NGConnectOAuthTokenSecret');
         $http->removeSessionVariable('NGConnectOAuthToken');
         $http->removeSessionVariable('NGConnectOAuthTokenSecret');
     }
     $connection = new TumblrOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthTokenSecret);
     $accessToken = $connection->getAccessToken($oAuthVerifier);
     if (!(isset($accessToken['oauth_token']) && isset($accessToken['oauth_token_secret']))) {
         return array('status' => 'error', 'message' => 'Error while retrieving access token.');
     }
     $connection = new TumblrOAuth($consumerKey, $consumerSecret, $accessToken['oauth_token'], $accessToken['oauth_token_secret']);
     $userData = $connection->get('http://api.tumblr.com/v2/user/info');
     $userData = json_decode($userData, true);
     if (!is_array($userData) || empty($userData['response']['user']['name'])) {
         return array('status' => 'error', 'message' => 'Invalid Tumblr user.');
     }
     $name = $userData['response']['user']['name'];
     $result = array('status' => 'success', 'login_method' => 'tumblr', 'id' => $name, 'first_name' => $name, 'last_name' => $name, 'email' => '', 'picture' => '');
     return $result;
 }
Пример #3
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_snapSetPgURL, $nxs_plurl, $nxs_gOptions;
            $ntInfo = $this->ntInfo;
            if (isset($_GET['auth']) && $_GET['auth'] == 'tr') {
                require_once 'apis/trOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $consumer_key = $options['trConsKey'];
                $consumer_secret = $options['trConsSec'];
                $callback_url = $nxs_snapSetPgURL . "&auth=tra&acc=" . $_GET['acc'];
                $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret);
                prr($tum_oauth);
                $request_token = $tum_oauth->getRequestToken($callback_url);
                echo "####";
                prr($request_token);
                $options['trOAuthToken'] = $request_token['oauth_token'];
                $options['trOAuthTokenSecret'] = $request_token['oauth_token_secret'];
                // prr($tum_oauth ); die();
                switch ($tum_oauth->http_code) {
                    case 200:
                        $url = $tum_oauth->getAuthorizeURL($options['trOAuthToken']);
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions['tr'][$_GET['acc']] = $options;
                            nxs_settings_save($nxs_gOptions);
                        }
                        echo '<script type="text/javascript">window.location = "' . $url . '"</script>';
                        break;
                    default:
                        echo '<br/><b style="color:red">Could not connect to Tumblr. Refresh the page or try again later.</b>';
                        die;
                }
                die;
            }
            if (isset($_GET['auth']) && $_GET['auth'] == 'tra') {
                require_once 'apis/trOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                prr($options);
                $consumer_key = $options['trConsKey'];
                $consumer_secret = $options['trConsSec'];
                $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trOAuthToken'], $options['trOAuthTokenSecret']);
                $options['trAccessTocken'] = $tum_oauth->getAccessToken($_REQUEST['oauth_verifier']);
                // prr($_GET);  prr($_REQUEST);   prr($options['trAccessTocken']);
                $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trAccessTocken']['oauth_token'], $options['trAccessTocken']['oauth_token_secret']);
                if (function_exists('get_option')) {
                    $nxs_gOptions = get_option('NS_SNAutoPoster');
                }
                if (!empty($nxs_gOptions)) {
                    $nxs_gOptions['tr'][$_GET['acc']] = $options;
                    nxs_settings_save($nxs_gOptions);
                }
                $userinfo = $tum_oauth->get('http://api.tumblr.com/v2/user/info');
                prr($userinfo);
                prr($tum_oauth);
                // prr($url); die();
                if (is_array($userinfo->response->user->blogs)) {
                    foreach ($userinfo->response->user->blogs as $blog) {
                        if (stripos($blog->url, $options['trPgID']) !== false) {
                            $gGet = $_GET;
                            unset($gGet['auth']);
                            unset($gGet['acc']);
                            unset($gGet['oauth_token']);
                            unset($gGet['oauth_verifier']);
                            unset($gGet['post_type']);
                            $sturl = explode('?', $nxs_snapSetPgURL);
                            $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : '');
                            echo '<script type="text/javascript">window.location = "' . $nxs_snapSetPgURL . '"</script>';
                            die;
                        }
                    }
                    prr($userinfo);
                    die("<span style='color:red;'>ERROR: Authorized USER don't have access to the specified blog: <span style='color:darkred; font-weight: bold;'>" . $options['trPgID'] . "</span></span>");
                }
            }
            ?>
    
    <div class="nxs_box">
      <div class="nxs_box_header"> 
        <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php 
            echo $nxs_plurl;
            ?>
img/<?php 
            echo $ntInfo['lcode'];
            ?>
16.png);"><?php 
            echo $ntInfo['name'];
            ?>
          <?php 
            $cbo = count($ntOpts);
            ?>
 
          <?php 
            if ($cbo > 1) {
                ?>
<div class="nsBigText"><?php 
                echo "(" . ($cbo == '0' ? 'No' : $cbo) . " ";
                _e('accounts', 'nxs_snap');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = str_ireplace('https://', '', str_ireplace('http://', '', $pbo['trURL']));
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['trOAuthTokenSecret']) && $pbo['trOAuthTokenSecret'] != '' ? '1' : '';
                }
                ?>
          <p style="margin:0px;margin-left:5px;"> <img id="<?php 
                echo $ntInfo['code'] . $indx;
                ?>
LoadingImg" style="display: none;" src='<?php 
                echo $nxs_plurl;
                ?>
img/ajax-loader-sm.gif' />
            <input value="0" name="<?php 
                echo $ntInfo['lcode'];
                ?>
[<?php 
                echo $indx;
                ?>
][apDo<?php 
                echo $ntInfo['code'];
                ?>
]" type="hidden" />             
            <?php 
                if ((int) $pbo['do' . $ntInfo['code']] == 1 && isset($pbo['catSel']) && (int) $pbo['catSel'] == 1) {
                    ?>
 <input type="radio" name="<?php 
                    echo $ntInfo['lcode'];
                    ?>
[<?php 
                    echo $indx;
                    ?>
][apDo<?php 
                    echo $ntInfo['code'];
                    ?>
]" id="rbtn<?php 
                    echo $ntInfo['lcode'] . $indx;
                    ?>
" value="1" checked="checked" onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);" /> <?php 
                } else {
                    ?>
            
            <input value="1" name="<?php 
                    echo $ntInfo['lcode'];
                    ?>
[<?php 
                    echo $indx;
                    ?>
][apDo<?php 
                    echo $ntInfo['code'];
                    ?>
]" type="checkbox" <?php 
                    if ((int) $pbo['do' . $ntInfo['code']] == 1 && $pbo['catSel'] != '1') {
                        echo "checked";
                    }
                    ?>
 />
           <?php 
                }
                ?>
            <?php 
                if (isset($pbo['catSel']) && (int) $pbo['catSel'] == 1) {
                    ?>
 <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php 
                    echo "*[" . (substr_count($pbo['catSelEd'], ",") + 1) . "]*";
                    ?>
</span><?php 
                }
                ?>
            <?php 
                if (isset($pbo['rpstOn']) && (int) $pbo['rpstOn'] == 1) {
                    ?>
 <span onmouseout="nxs_hidePopUpInfo('popReActive');" onmouseover="nxs_showPopUpInfo('popReActive', event);"><?php 
                    echo "*[R]*";
                    ?>
</span><?php 
                }
                ?>
            <strong><?php 
                _e('Auto-publish to', 'nxs_snap');
                ?>
 <?php 
                echo $ntInfo['name'];
                ?>
 <i style="color: #005800;"><?php 
                if ($pbo['nName'] != '') {
                    echo "(" . $pbo['nName'] . ")";
                }
                ?>
</i></strong>
          &nbsp;&nbsp;<?php 
                if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '')) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. Unfinished setup', 'nxs_snap');
                    ?>
 ==&gt;</b><?php 
                }
                ?>
<a id="do<?php 
                echo $ntInfo['code'] . $indx;
                ?>
AG" href="#" onclick="doGetHideNTBlock('<?php 
                echo $ntInfo['code'];
                ?>
' , '<?php 
                echo $indx;
                ?>
');return false;">[<?php 
                _e('Show Settings', 'nxs_snap');
                ?>
]</a>&nbsp;&nbsp;
          <a href="#" onclick="doDelAcct('<?php 
                echo $ntInfo['lcode'];
                ?>
', '<?php 
                echo $indx;
                ?>
', '<?php 
                if (isset($pbo['bgBlogID'])) {
                    echo $pbo['nName'];
                }
                ?>
');return false;">[<?php 
                _e('Remove Account', 'nxs_snap');
                ?>
]</a>
          </p><div id="nxsNTSetDiv<?php 
                echo $ntInfo['code'] . $indx;
                ?>
"></div><?php 
                //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }
Пример #4
0
echo '<br><br>';
echo '<table border="1" cellpadding="2" cellspacing="0">';
echo '<tr>';
echo '<th>API Method</th>';
echo '<th>HTTP Code</th>';
echo '<th>Response Length</th>';
echo '<th>Parameters</th>';
echo '</tr><tr>';
echo '<th colspan="4">Response Snippet</th>';
echo '</tr>';
/**
 * Timeline Methods.
 */
tumblroauth_header('Timeline Methods');
/* statuses/public_timeline */
tumblroauth_row('statuses/public_timeline', $connection->get('statuses/public_timeline'), $connection->http_code);
/* statuses/public_timeline */
tumblroauth_row('statuses/home_timeline', $connection->get('statuses/home_timeline'), $connection->http_code);
/* statuses/friends_timeline */
tumblroauth_row('statuses/friends_timeline', $connection->get('statuses/friends_timeline'), $connection->http_code);
/* statuses/user_timeline */
tumblroauth_row('statuses/user_timeline', $connection->get('statuses/user_timeline'), $connection->http_code);
/* statuses/mentions */
tumblroauth_row('statuses/mentions', $connection->get('statuses/mentions'), $connection->http_code);
/* statuses/retweeted_by_me */
tumblroauth_row('statuses/retweeted_by_me', $connection->get('statuses/retweeted_by_me'), $connection->http_code);
/* statuses/retweeted_to_me */
tumblroauth_row('statuses/retweeted_to_me', $connection->get('statuses/retweeted_to_me'), $connection->http_code);
/* statuses/retweets_of_me */
tumblroauth_row('statuses/retweets_of_me', $connection->get('statuses/retweets_of_me'), $connection->http_code);
/**
Пример #5
0
if (200 == $tum_oauth->http_code) {
    // good to go
} else {
    die('Unable to authenticate');
}
// What's next?  Now that we have an Access Token and Secret, we can make an API call.
// Any API call that requires OAuth authentiation will need the info we have now - (Consumer Key,
// Consumer Secret, Access Token, and Access Token secret).
// You should store the Access Token and Secret in a database, or if you must, a Cookie in the user's browser.
// Never expose your Consumer Secret.  It should stay on your server, avoid storing it in code viewable to the user.
// I'll make the /user/info API call to get some baisc information about the user
// Start a new instance of TumblrOAuth, overwriting the old one.
// This time it will need our Access Token and Secret instead of our Request Token and Secret
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $access_token['oauth_token'], $access_token['oauth_token_secret']);
// Make an API call with the TumblrOAuth instance.  There's also a post and delete method too.
$userinfo = $tum_oauth->get('http://api.tumblr.com/v2/user/info');
// You don't actuall have to pass a full URL,  TukmblrOAuth will complete the URL for you.
// This will also work: $userinfo = $tum_oauth->get('user/info');
// Check for an error.
if (200 == $tum_oauth->http_code) {
    // good to go
} else {
    die('Unable to get info');
}
// find primary blog.  Display its name.
$screen_name = $userinfo->response->user->name;
for ($fln = 0; $fln < count($userinfo->response->user->blogs); $fln = $fln + 1) {
    if ($userinfo->response->user->blogs[$fln]->primary == true) {
        echo "Your primary blog's name: " . $userinfo->response->user->blogs[$fln]->title;
        break;
    }
Пример #6
0
function tumblr_settings(&$a, &$s)
{
    if (!local_user()) {
        return;
    }
    /* Add our stylesheet to the page so we can make our settings look nice */
    $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/tumblr/tumblr.css' . '" media="all" />' . "\r\n";
    /* Get the current state of our config variables */
    $enabled = get_pconfig(local_user(), 'tumblr', 'post');
    $checked = $enabled ? ' checked="checked" ' : '';
    $css = $enabled ? '' : '-disabled';
    $def_enabled = get_pconfig(local_user(), 'tumblr', 'post_by_default');
    $def_checked = $def_enabled ? ' checked="checked" ' : '';
    /* Add some HTML to the existing form */
    $s .= '<span id="settings_tumblr_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_tumblr_expanded\'); openClose(\'settings_tumblr_inflated\');">';
    $s .= '<img class="connector' . $css . '" src="images/tumblr.png" /><h3 class="connector">' . t('Tumblr Export') . '</h3>';
    $s .= '</span>';
    $s .= '<div id="settings_tumblr_expanded" class="settings-block" style="display: none;">';
    $s .= '<span class="fakelink" onclick="openClose(\'settings_tumblr_expanded\'); openClose(\'settings_tumblr_inflated\');">';
    $s .= '<img class="connector' . $css . '" src="images/tumblr.png" /><h3 class="connector">' . t('Tumblr Export') . '</h3>';
    $s .= '</span>';
    $s .= '<div id="tumblr-username-wrapper">';
    $s .= '<a href="' . $a->get_baseurl() . '/tumblr/connect">' . t("(Re-)Authenticate your tumblr page") . '</a>';
    $s .= '</div><div class="clear"></div>';
    $s .= '<div id="tumblr-enable-wrapper">';
    $s .= '<label id="tumblr-enable-label" for="tumblr-checkbox">' . t('Enable Tumblr Post Plugin') . '</label>';
    $s .= '<input id="tumblr-checkbox" type="checkbox" name="tumblr" value="1" ' . $checked . '/>';
    $s .= '</div><div class="clear"></div>';
    $s .= '<div id="tumblr-bydefault-wrapper">';
    $s .= '<label id="tumblr-bydefault-label" for="tumblr-bydefault">' . t('Post to Tumblr by default') . '</label>';
    $s .= '<input id="tumblr-bydefault" type="checkbox" name="tumblr_bydefault" value="1" ' . $def_checked . '/>';
    $s .= '</div><div class="clear"></div>';
    $oauth_token = get_pconfig(local_user(), "tumblr", "oauth_token");
    $oauth_token_secret = get_pconfig(local_user(), "tumblr", "oauth_token_secret");
    $s .= '<div id="tumblr-page-wrapper">';
    if ($oauth_token != "" and $oauth_token_secret != "") {
        $page = get_pconfig(local_user(), 'tumblr', 'page');
        $consumer_key = get_config('tumblr', 'consumer_key');
        $consumer_secret = get_config('tumblr', 'consumer_secret');
        $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
        $userinfo = $tum_oauth->get('user/info');
        $blogs = array();
        $s .= '<label id="tumblr-page-label" for="tumblr-page">' . t('Post to page:') . '</label>';
        $s .= '<select name="tumblr_page" id="tumblr-page">';
        foreach ($userinfo->response->user->blogs as $blog) {
            $blogurl = substr(str_replace(array("http://", "https://"), array("", ""), $blog->url), 0, -1);
            if ($page == $blogurl) {
                $s .= "<option value='" . $blogurl . "' selected>" . $blogurl . "</option>";
            } else {
                $s .= "<option value='" . $blogurl . "'>" . $blogurl . "</option>";
            }
        }
        $s .= "</select>";
    } else {
        $s .= t("You are not authenticated to tumblr");
    }
    $s .= '</div><div class="clear"></div>';
    /* provide a submit button */
    $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="tumblr-submit" name="tumblr-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
}
Пример #7
0
 function fetch_count()
 {
     require_once dirname(__FILE__) . '/ext/tumblr_oauth.php';
     $settings = $this->get_settings();
     $tumblrConnection = new TumblrOAuth($settings['consumer_key']['value'], $settings['consumer_secret']['value'], $settings['access_token']['value'], $settings['access_token_secret']['value']);
     $tumblrData = $tumblrConnection->get('user/info');
     return isset($tumblrData->response) ? $tumblrData->response->user->likes : false;
 }