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
 /**
  * Sends the message to the configured network
  *
  * @param string $pPostBody
  * @return mixed
  */
 protected function send($pPostBody)
 {
     $this->onlineIdentity->scheduleImportJob();
     $lToken = $this->getAuthToken();
     $lKey = sfConfig::get("app_" . $this->classToIdentifier() . "_oauth_token");
     $lSecret = sfConfig::get("app_" . $this->classToIdentifier() . "_oauth_secret");
     $lPostApi = sfConfig::get("app_" . $this->classToIdentifier() . "_post_api");
     $lPostApi = str_replace("{base-hostname}", $this->onlineIdentity->getName() . ".tumblr.com", $lPostApi);
     $oauth = new TumblrOAuth($lKey, $lSecret, $lToken->getTokenKey(), $lToken->getTokenSecret());
     return $oauth->post($lPostApi, $pPostBody);
 }
Пример #3
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;
 }
Пример #4
0
/**
 * @file
 * Take the user when they return from Tumblr. Get access tokens.
 * Verify credentials and redirect to based on response from Tumblr.
 */
/* Start session and load lib */
session_start();
require_once 'tumblroauth/tumblroauth.php';
require_once 'config.php';
/* If the oauth_token is old redirect to the connect page. */
if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
    $_SESSION['oauth_status'] = 'oldtoken';
    header('Location: ./clearsessions.php');
}
/* Create TumblroAuth object with app key/secret and token key/secret from default phase */
$connection = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
/* Request access tokens from tumblr */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
/* Save the access tokens. Normally these would be saved in a database for future use. */
$_SESSION['access_token'] = $access_token;
/* Remove no longer needed request tokens */
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
/* If HTTP response is 200 continue otherwise send to connect page to retry */
if (200 == $connection->http_code) {
    /* The user has been verified and the access tokens can be saved for future use */
    $_SESSION['status'] = 'verified';
    header('Location: ./index.php');
} else {
    /* Save HTTP status for error dialog on connnect page.*/
    header('Location: ./clearsessions.php');
Пример #5
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 
        }
Пример #6
0
 unset($_SESSION['request_token_secret']);
 // Make sure nothing went wrong.
 if (200 == $tum_oauth->http_code) {
     // good to go
 } else {
     die("Unable to authenticate. <a href=\"connect.php\">Try again?</a>");
 }
 // 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');
 // POST
 $url = "http://api.tumblr.com/v2/blog/{$blogname}.tumblr.com/post";
 $params = array("type" => "photo", "state" => "queue", "publish_on" => $pubdate, "source" => file_get_contents($pubimage), "data" => array(file_get_contents($pubimage)), "link" => $publink, "tags" => $tags, "caption" => $pubcaption);
 $post = $tum_oauth->post($url, $params);
 // Check for an error.
 if (201 == $tum_oauth->http_code) {
     $postid = (double) $post->response->id;
     echo "<br /><hr>{$pubcaption}<hr><br />\n\t<br />Sucessfully posted to <b>{$blogname}</b> queue! <a href=\"http://tumblr.com/blog/{$blogname}/queue\" target=\"_blank\">View queue</a> or <a href=\"connect.php\">Submit another post</a>";
 } else {
     die("Unable to post to tumblr. <a href=\"connect.php\">Try reconnecting...</a>");
 }
Пример #7
0
/* friends/ids */
$method = 'friends/ids';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/* friends/ids */
$method = 'friends/ids';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/**
 * Account Methods.
 */
tumblroauth_header('Account Methods');
/* account/verify_credentials */
$method = 'account/verify_credentials';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/* account/rate_limit_status */
$method = 'account/rate_limit_status';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/* account/update_profile_colors */
$parameters = array('profile_background_color' => 'fff');
$method = 'account/update_profile_colors';
tumblroauth_row($method, $connection->post($method, $parameters), $connection->http_code, $parameters);
/* account/update_profile */
$parameters = array('location' => 'Teh internets');
$method = 'account/update_profile';
tumblroauth_row($method, $connection->post($method, $parameters), $connection->http_code, $parameters);
/**
 * OAuth Methods.
 */
tumblroauth_header('OAuth Methods');
/* oauth/request_token */
$oauth = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET);
tumblroauth_row('oauth/reqeust_token', $oauth->getRequestToken(), $oauth->http_code);
Пример #8
0
unset($_SESSION['request_token_secret']);
// Make sure nothing went wrong.
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;
Пример #9
0
<?php

//Enable session.  We will store token information here later
session_start();
//echo 'hello';
//require 'vendor/autoload.php';
require_once 'vendor/tumblroauthnonnative/tumblroauth.php';
//Tumblr API urls
$req_url = 'http://www.tumblr.com/oauth/request_token';
$authurl = 'http://www.tumblr.com/oauth/authorize';
$acc_url = 'http://www.tumblr.com/oauth/access_token';
//Your Application key and secret
$consumer_key = 'vliXIm52B9BG2L1hfRAy6SvPbekkOk5JEsRITW5MeOH1Xnknl2';
$consumer_secret = '3Pqe75MjkrvqdrHAyKuZ9Z3nWMlCuLKjfMnT5E1H0rrz8WXVay';
$callback_url = 'callback.php';
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret);
$request_token = $tum_oauth->getRequestToken($callback_url);
$_SESSION['request_token'] = $token = $request_token['oauth_token'];
$_SESSION['request_token_secret'] = $request_token['oauth_token_secret'];
switch ($tum_oauth->http_code) {
    case 200:
        // Ask Tumblr to give us a special address to their login page
        $url = $tum_oauth->getAuthorizeURL($token);
        // Redirect the user to the login URL given to us by Tumblr
        header('Location: ' . $url);
        // That's it for our side.  The user is sent to a Tumblr Login page and
        // asked to authroize our app.  After that, Tumblr sends the user back to
        // our Callback URL (callback.php) along with some information we need to get
        // an access token.
        break;
    default:
Пример #10
0
function tumblr_send(&$a, &$b)
{
    if ($b['deleted'] || $b['private'] || $b['created'] !== $b['edited']) {
        return;
    }
    if (!strstr($b['postopts'], 'tumblr')) {
        return;
    }
    if ($b['parent'] != $b['id']) {
        return;
    }
    $oauth_token = get_pconfig($b['uid'], "tumblr", "oauth_token");
    $oauth_token_secret = get_pconfig($b['uid'], "tumblr", "oauth_token_secret");
    $page = get_pconfig($b['uid'], "tumblr", "page");
    $tmbl_blog = 'blog/' . $page . '/post';
    if ($oauth_token && $oauth_token_secret && $tmbl_blog) {
        require_once 'include/bbcode.php';
        $tag_arr = array();
        $tags = '';
        $x = preg_match_all('/\\#\\[(.*?)\\](.*?)\\[/', $b['tag'], $matches, PREG_SET_ORDER);
        if ($x) {
            foreach ($matches as $mtch) {
                $tag_arr[] = $mtch[2];
            }
        }
        if (count($tag_arr)) {
            $tags = implode(',', $tag_arr);
        }
        $title = trim($b['title']);
        require_once 'include/plaintext.php';
        $siteinfo = get_attached_data($b["body"]);
        $params = array('state' => 'published', 'tags' => $tags, 'tweet' => 'off', 'format' => 'html');
        if (!isset($siteinfo["type"])) {
            $siteinfo["type"] = "";
        }
        if ($title == "" and isset($siteinfo["title"])) {
            $title = $siteinfo["title"];
        }
        if (isset($siteinfo["text"])) {
            $body = $siteinfo["text"];
        } else {
            $body = bb_remove_share_information($b["body"]);
        }
        switch ($siteinfo["type"]) {
            case "photo":
                $params['type'] = "photo";
                $params['caption'] = bbcode($body, false, false, 4);
                if (isset($siteinfo["url"])) {
                    $params['link'] = $siteinfo["url"];
                }
                $params['source'] = $siteinfo["image"];
                break;
            case "link":
                $params['type'] = "link";
                $params['title'] = $title;
                $params['url'] = $siteinfo["url"];
                $params['description'] = bbcode($body, false, false, 4);
                break;
            case "audio":
                $params['type'] = "audio";
                $params['external_url'] = $siteinfo["url"];
                $params['caption'] = bbcode($body, false, false, 4);
                break;
            case "video":
                $params['type'] = "video";
                $params['embed'] = $siteinfo["url"];
                $params['caption'] = bbcode($body, false, false, 4);
                break;
            default:
                $params['type'] = "text";
                $params['title'] = $title;
                $params['body'] = bbcode($b['body'], false, false, 4);
                break;
        }
        if (isset($params['caption']) and trim($title) != "") {
            $params['caption'] = '<h1>' . $title . "</h1>" . "<p>" . $params['caption'] . "</p>";
        }
        if (trim($params['caption']) == "") {
            $params['caption'] = bbcode("[quote]" . $siteinfo["description"] . "[/quote]", false, false, 4);
        }
        $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);
        // Make an API call with the TumblrOAuth instance.
        $x = $tum_oauth->post($tmbl_blog, $params);
        $ret_code = $tum_oauth->http_code;
        //print_r($params);
        if ($ret_code == 201) {
            logger('tumblr_send: success');
        } elseif ($ret_code == 403) {
            logger('tumblr_send: authentication failure');
        } else {
            logger('tumblr_send: general error: ' . print_r($x, true));
        }
    }
}
Пример #11
0
<?php

// Include the TumblrOAuth library
include_once '../tumblr/config.php';
include_once '../tumblr/API/tumblroauth.php';
// Let's begin.  First we need a Request Token.  The request token is required to send the user to Tumblr's login page.
// Create a new instance of the TumblrOAuth library.
$ObjTumAuth = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET);
// Ask Tumblr for a Request Token.  Specify the Callback URL here too (although this should be optional)
$objArrRequest = $ObjTumAuth->getRequestToken(CALLBACK);
// Store the request token and Request Token Secret as out callback.php script will need this
$_SESSION['request_token'] = $strToken = $objArrRequest['oauth_token'];
$_SESSION['request_token_secret'] = $objArrRequest['oauth_token_secret'];
// Check the HTTP Code.  It should be a 200 (OK), if it's anything else then something didn't work.
switch ($ObjTumAuth->http_code) {
    case 200:
        // Ask Tumblr to give us a special address to their login page
        $strUrl = $ObjTumAuth->getAuthorizeURL($strToken);
        // Redirect the user to the login URL given to us by Tumblr
        header('Location: ' . $strUrl);
        // That's it for our side.  The user is sent to a Tumblr Login page and asked to authroize our app.  After that, Tumblr sends the user back to our
        // Callback URL (callback.php) along with some information we need to get an access token.
        break;
    default:
        // Give an error message
        echo 'Could not connect to Tumblr. Refresh the page or try again later.';
        exit;
}
$arrMessage = array('type' => 'regular', 'title' => 'Testing ', 'body' => 'Details', 'format' => 'html');
//API Call For Posting Blog update
$arrPost = $this->objTumblrOauth->post($strPostUrl, $arrMessage);
Пример #12
0
<?php

/* Start session and load library. */
session_start();
require_once 'tumblroauth/tumblroauth.php';
require_once 'config.php';
/* Build TumblrOAuth object with client credentials. */
$connection = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
    case 200:
        /* Build authorize URL and redirect user to Tumblr. */
        $url = $connection->getAuthorizeURL($token);
        header('Location: ' . $url);
        break;
    default:
        /* Show notification if something went wrong. */
        echo 'Could not connect to Tumblr. Refresh the page or try again later.';
}
Пример #13
0
unset($_SESSION['request_token_secret']);
// Make sure nothing went wrong.
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']);
// If WordPress post is a draft, true to upload as private, false to not upload it.
$publishDraftAsPrivate = true;
// A writeable logfile, to keep track of the new URLs.
$logFile = 'log.txt';
if (file_exists($xmlFile)) {
    $xml = simplexml_load_file($xmlFile);
} else {
    echo "ERROR: no such file\n\n";
    die;
}
if (isset($xml)) {
    $nodes = $xml->xpath('/rss/channel/item');
    $count = 0;
    while (list(, $node) = each($nodes)) {
        $post_type = 'regular';
Пример #14
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;
 }
Пример #15
0
/**
 * @file
 * User has successfully authenticated with Tumblr. Access tokens saved to session and DB.
 */
/* Load required lib files. */
session_start();
require_once 'tumblroauth/tumblroauth.php';
require_once 'config.php';
/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];
/* Create a TumblrOauth object with consumer/user tokens. */
$connection = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
/* Find User Info */
$user_info = $connection->post('user/info');
$content = $user_info;
/* Some example calls */
/* Find Primary Blog Hostname */
/*
foreach($user_info->response->user->blogs as $blog){
	if($blog->primary === true){
		break;
	}
}
$hostname = parse_url($blog->url,PHP_URL_HOST);
*/
// $connection->get("blog/$hostname/info"); /* Not Yet Working */
// $connection->post("blog/$hostname/post", array('type' => 'text', 'body' => 'Testing TumblrOAuth - ' . date(DATE_RFC822)));
Пример #16
0
<?php

// Start a session, load the library
session_start();
require 'vendor/autoload.php';
require_once 'vendor/tumblroauthnonnative/tumblroauth.php';
// Define the needed keys
$consumer_key = 'vliXIm52B9BG2L1hfRAy6SvPbekkOk5JEsRITW5MeOH1Xnknl2';
$consumer_secret = '3Pqe75MjkrvqdrHAyKuZ9Z3nWMlCuLKjfMnT5E1H0rrz8WXVay';
// Once the user approves your app at Tumblr, they are sent back to this script.
// This script is passed two parameters in the URL, oauth_token (our Request Token)
// and oauth_verifier (Key that we need to get Access Token).
// We'll also need out Request Token Secret, which we stored in a session.
// Create instance of TumblrOAuth.
// It'll need our Consumer Key and Secret as well as our Request Token and Secret
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $_SESSION['request_token'], $_SESSION['request_token_secret']);
$access_token = $tum_oauth->getAccessToken($_REQUEST['oauth_verifier']);
// We're done with the Request Token and Secret so let's remove those.
unset($_SESSION['request_token']);
unset($_SESSION['request_token_secret']);
// Make sure nothing went wrong.
if (200 == $tum_oauth->http_code) {
    // good to go
} else {
    die('Unable to authenticate');
}
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $access_token['oauth_token'], $access_token['oauth_token_secret']);
echo $access_token['oauth_token'];
echo $access_token['oauth_token_secret'];
Пример #17
0
 function doPostToNT($options, $message)
 {
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if (!isset($options['trConsKey']) || trim($options['trConsSec']) == '' || empty($options['trAccessTocken'])) {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     if (!isset($options['postType']) && isset($options['trPostType'])) {
         $options['postType'] = $options['trPostType'];
     }
     //## Compatibility with v <3.2
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     if (empty($message['postDate'])) {
         $message['postDate'] = '';
     }
     if (empty($options['trMsgTFormat'])) {
         $options['trMsgTFormat'] = '%TITLE%';
     }
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['trMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['trMsgTFormat'], $message);
     }
     //## Post
     $options['trURL'] = trim(str_ireplace('http://', '', $options['trURL']));
     if (substr($options['trURL'], -1) == '/') {
         $options['trURL'] = substr($options['trURL'], 0, -1);
     }
     require_once 'apis/trOAuth.php';
     $consumer_key = $options['trConsKey'];
     $consumer_secret = $options['trConsSec'];
     $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trAccessTocken']['oauth_token'], $options['trAccessTocken']['oauth_token_secret']);
     //prr($options);
     $postArr = array('tags' => $message['tags'], 'date' => $message['postDate']);
     if ($options['fillSrcURL'] == '1') {
         $postArr['source_url'] = $message['url'];
     }
     if (isset($message['imageURL'])) {
         $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
     } else {
         $imgURL = '';
     }
     // postType
     if ($options['postType'] == 'I') {
         $postArr['type'] = 'photo';
         $postArr['caption'] = $msg;
         $postArr['source'] = $imgURL;
         if (!isset($options['cImgURL']) || $options['cImgURL'] == '' || $options['cImgURL'] == 'R') {
             $postArr['link'] = $message['url'];
         } elseif ($options['cImgURL'] == 'S') {
             $postArr['link'] = $message['url'];
             $postArr['link'] = nxs_mkShortURL($postArr['link']);
         }
     } elseif ($options['postType'] == 'U') {
         $postArr['type'] = 'audio';
         $postArr['caption'] = $msg;
         $postArr['external_url'] = $aUrl;
     } elseif ($options['postType'] == 'V') {
         $postArr['type'] = 'video';
         $postArr['caption'] = $msg;
         $embedTxt = '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $message['videoURL'] . '" frameborder="0" allowfullscreen></iframe>';
         $postArr['embed'] = $embedTxt;
     } else {
         $postArr['title'] = $msgT;
         $postArr['type'] = 'text';
         $postArr['source'] = $message['url'];
         $postArr['body'] = $msg;
     }
     $postinfo = $tum_oauth->post("http://api.tumblr.com/v2/blog/" . $options['trURL'] . "/post", $postArr);
     // prr("http://api.tumblr.com/v2/blog/".$options['trURL']."/post");  prr($postinfo);  prr($postArr);
     $code = $postinfo->meta->status;
     // echo "XX".print_r($code);  prr($postinfo); // prr($msg); prr($postinfo); echo $code."VVVV"; die("|====");
     if ($code == 201) {
         return array('postID' => $postinfo->response->id, 'isPosted' => 1, 'postURL' => 'http://' . $options['trURL'] . "/post/" . $postinfo->response->id, 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= $code . " - " . $postinfo->meta->msg . (isset($postinfo->errmsg) ? $postinfo->errmsg : '') . " | " . print_r($postinfo, true);
     }
     return $badOut;
 }