summaryrefslogtreecommitdiff
path: root/functions.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-03-06 12:05:58 +0300
committerAndrew Dolgov <[email protected]>2011-03-06 12:05:58 +0300
commit54a3dd8d1019cbeba2d312e61378ced7c670038a (patch)
tree118721274de5d0d070ca55222745fd7185f577a3 /functions.php
parentba083651fa57c7bd19358701b0da17c354bcd564 (diff)
switch twitter support from twitteroauth to tmhOAuth
Diffstat (limited to 'functions.php')
-rw-r--r--functions.php44
1 files changed, 33 insertions, 11 deletions
diff --git a/functions.php b/functions.php
index 33ac51d22..a0608ded5 100644
--- a/functions.php
+++ b/functions.php
@@ -108,7 +108,7 @@
require_once 'lib/phpmailer/class.phpmailer.php';
require_once 'lib/sphinxapi.php';
- require_once 'lib/twitteroauth/twitteroauth.php';
+ require_once 'lib/tmhoauth/tmhOAuth.php';
//define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
@@ -2933,7 +2933,7 @@
$has_oauth = db_fetch_result($result, 0, 'twitter_oauth');
- if (!$has_oauth || strpos($url, '://twitter.com') === false) {
+ if (!$has_oauth || strpos($url, '://api.twitter.com') === false) {
if (!fetch_file_contents($url)) return 5;
if (url_is_html($url)) {
@@ -7056,25 +7056,47 @@
return $obj;
}
+
function fetch_twitter_rss($link, $url, $owner_uid) {
$result = db_query($link, "SELECT twitter_oauth FROM ttrss_users
WHERE id = $owner_uid");
$access_token = json_decode(db_fetch_result($result, 0, 'twitter_oauth'), true);
+ $url_escaped = db_escape_string($url);
if ($access_token) {
-
- /* Create a TwitterOauth object with consumer/user tokens. */
- $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
-
- /* If method is set change API call made. Test is called by default. */
- $content = $connection->get($url);
- $rss = new MagpieRSS($content, MAGPIE_OUTPUT_ENCODING,
- MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING );
+ $tmhOAuth = new tmhOAuth(array(
+ 'consumer_key' => CONSUMER_KEY,
+ 'consumer_secret' => CONSUMER_SECRET,
+ 'user_token' => $access_token['oauth_token'],
+ 'user_secret' => $access_token['oauth_token_secret'],
+ ));
+
+ $code = $tmhOAuth->request('GET', $url);
+
+ if ($code == 200) {
+
+ $content = $tmhOAuth->response['response'];
+
+ $rss = new MagpieRSS($content, MAGPIE_OUTPUT_ENCODING,
+ MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING );
+
+ return $rss;
+
+ } else {
+
+ db_query($link, "UPDATE ttrss_feeds
+ SET last_error = 'OAuth authorization failed ($code).'
+ WHERE feed_url = '$url_escaped' AND owner_uid = $owner_uid");
+ }
- return $rss;
} else {
+
+ db_query($link, "UPDATE ttrss_feeds
+ SET last_error = 'OAuth information not found.'
+ WHERE feed_url = '$url_escaped' AND owner_uid = " . $_SESSION['uid']);
+
return false;
}
}