From d59284d42d3735e393e5e99d027136d96778600d Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 16:52:15 -0800 Subject: No need to pass in $this->limit and $this-tag --- actions/userrss.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/userrss.php b/actions/userrss.php index 77bd316b2..e03eb9356 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -41,9 +41,9 @@ class UserrssAction extends Rss10Action return false; } else { if (!empty($this->tag)) { - $this->notices = $this->getTaggedNotices($this->tag, $this->limit); + $this->notices = $this->getTaggedNotices(); } else { - $this->notices = $this->getNotices($this->limit); + $this->notices = $this->getNotices(); } return true; } -- cgit v1.2.3-54-g00ecf From 7faf6ec75592764b829b1954352dfaf0329cdbf0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 7 Mar 2010 23:41:55 -0500 Subject: add a script to import Twitter atom feed as notices --- scripts/importtwitteratom.php | 192 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 scripts/importtwitteratom.php diff --git a/scripts/importtwitteratom.php b/scripts/importtwitteratom.php new file mode 100644 index 000000000..7316f2108 --- /dev/null +++ b/scripts/importtwitteratom.php @@ -0,0 +1,192 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'i:n:f:'; +$longoptions = array('id=', 'nickname=', 'file='); + +$helptext = <<documentElement->namespaceURI != Activity::ATOM || + $dom->documentElement->localName != 'feed') { + throw new Exception("'$filename' is not an Atom feed."); + } + + return $dom; +} + +function importActivityStream($user, $doc) +{ + $feed = $doc->documentElement; + + $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); + + for ($i = $entries->length - 1; $i >= 0; $i--) { + $entry = $entries->item($i); + $activity = new Activity($entry, $feed); + $object = $activity->object; + if (!have_option('q', 'quiet')) { + print $activity->content . "\n"; + } + $html = getTweetHtml($object->link); + + $config = array('safe' => 1, + 'deny_attribute' => 'class,rel,id,style,on*'); + + $html = htmLawed($html, $config); + + $content = html_entity_decode(strip_tags($html)); + + $notice = Notice::saveNew($user->id, + $content, + 'importtwitter', + array('uri' => $object->id, + 'url' => $object->link, + 'rendered' => $html, + 'created' => common_sql_date($activity->time), + 'replies' => array(), + 'groups' => array())); + } +} + +function getTweetHtml($url) +{ + try { + $client = new HTTPClient(); + $response = $client->get($url); + } catch (HTTP_Request2_Exception $e) { + print "ERROR: HTTP response " . $e->getMessage() . "\n"; + return false; + } + + if (!$response->isOk()) { + print "ERROR: HTTP response " . $response->getCode() . "\n"; + return false; + } + + $body = $response->getBody(); + + return tweetHtmlFromBody($body); +} + +function tweetHtmlFromBody($body) +{ + $doc = DOMDocument::loadHTML($body); + $xpath = new DOMXPath($doc); + + $spans = $xpath->query('//span[@class="entry-content"]'); + + if ($spans->length == 0) { + print "ERROR: No content in tweet page.\n"; + return ''; + } + + $span = $spans->item(0); + + $children = $span->childNodes; + + $text = ''; + + for ($i = 0; $i < $children->length; $i++) { + $child = $children->item($i); + if ($child instanceof DOMElement && + $child->tagName == 'a' && + !preg_match('#^https?://#', $child->getAttribute('href'))) { + $child->setAttribute('href', 'http://twitter.com' . $child->getAttribute('href')); + } + $text .= $doc->saveXML($child); + } + + return $text; +} + +try { + + $doc = getAtomFeedDocument(); + $user = getUser(); + + importActivityStream($user, $doc); + +} catch (Exception $e) { + print $e->getMessage()."\n"; + exit(1); +} + -- cgit v1.2.3-54-g00ecf From 5f7aa6f2e3c82b9598e3405885eb455bed9b0edc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 8 Mar 2010 12:36:03 -0500 Subject: make API realm configurable --- lib/apiauth.php | 6 +++++- lib/default.php | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/apiauth.php b/lib/apiauth.php index 5090871cf..f63c84d8f 100644 --- a/lib/apiauth.php +++ b/lib/apiauth.php @@ -235,7 +235,11 @@ class ApiAuthAction extends ApiAction { $this->basicAuthProcessHeader(); - $realm = common_config('site', 'name') . ' API'; + $realm = common_config('api', 'realm'); + + if (empty($realm)) { + $realm = common_config('site', 'name') . ' API'; + } if (!isset($this->auth_user_nickname) && $required) { header('WWW-Authenticate: Basic realm="' . $realm . '"'); diff --git a/lib/default.php b/lib/default.php index bdd78d4d8..46d3d4774 100644 --- a/lib/default.php +++ b/lib/default.php @@ -293,4 +293,6 @@ $default = array('crawldelay' => 0, 'disallow' => array('main', 'settings', 'admin', 'search', 'message') ), + 'api' => + array('realm' => null), ); -- cgit v1.2.3-54-g00ecf From 49722f65502b9730f1c1434851e21d02b8b2fd41 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 8 Mar 2010 22:53:43 +0000 Subject: Only allow RSSCloud subs to canonical RSS2 profile feeds --- plugins/RSSCloud/RSSCloudRequestNotify.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/RSSCloud/RSSCloudRequestNotify.php b/plugins/RSSCloud/RSSCloudRequestNotify.php index d76c08d37..030529534 100644 --- a/plugins/RSSCloud/RSSCloudRequestNotify.php +++ b/plugins/RSSCloud/RSSCloudRequestNotify.php @@ -270,13 +270,14 @@ class RSSCloudRequestNotifyAction extends Action function userFromFeed($feed) { - // We only do profile feeds + // We only do canonical RSS2 profile feeds (specified by ID), e.g.: + // http://www.example.com/api/statuses/user_timeline/2.rss $path = common_path('api/statuses/user_timeline/'); - $valid = '%^' . $path . '(?.*)\.rss$%'; + $valid = '%^' . $path . '(?.*)\.rss$%'; if (preg_match($valid, $feed, $matches)) { - $user = User::staticGet('nickname', $matches['nickname']); + $user = User::staticGet('id', $matches['id']); if (!empty($user)) { return $user; } -- cgit v1.2.3-54-g00ecf From 0d66dc543d368092de08b49857c67248210d8d84 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 8 Mar 2010 18:06:21 -0500 Subject: an otp is a real login --- actions/otp.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actions/otp.php b/actions/otp.php index acf84aee8..1e06603d4 100644 --- a/actions/otp.php +++ b/actions/otp.php @@ -126,6 +126,8 @@ class OtpAction extends Action $this->lt->delete(); $this->lt = null; + common_real_login(true); + if ($this->rememberme) { common_rememberme($this->user); } -- cgit v1.2.3-54-g00ecf From 691c88bce8fa37d1d371988857645b6cdd9994d9 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 8 Mar 2010 22:53:43 +0000 Subject: Only allow RSSCloud subs to canonical RSS2 profile feeds --- plugins/RSSCloud/RSSCloudRequestNotify.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/RSSCloud/RSSCloudRequestNotify.php b/plugins/RSSCloud/RSSCloudRequestNotify.php index d76c08d37..030529534 100644 --- a/plugins/RSSCloud/RSSCloudRequestNotify.php +++ b/plugins/RSSCloud/RSSCloudRequestNotify.php @@ -270,13 +270,14 @@ class RSSCloudRequestNotifyAction extends Action function userFromFeed($feed) { - // We only do profile feeds + // We only do canonical RSS2 profile feeds (specified by ID), e.g.: + // http://www.example.com/api/statuses/user_timeline/2.rss $path = common_path('api/statuses/user_timeline/'); - $valid = '%^' . $path . '(?.*)\.rss$%'; + $valid = '%^' . $path . '(?.*)\.rss$%'; if (preg_match($valid, $feed, $matches)) { - $user = User::staticGet('nickname', $matches['nickname']); + $user = User::staticGet('id', $matches['id']); if (!empty($user)) { return $user; } -- cgit v1.2.3-54-g00ecf From 7214db14fe37798623acab2e6f5755d05bacbc8f Mon Sep 17 00:00:00 2001 From: James Walker Date: Tue, 9 Mar 2010 01:24:21 -0500 Subject: wrong param order to strpos() --- plugins/OStatus/classes/HubSub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/OStatus/classes/HubSub.php b/plugins/OStatus/classes/HubSub.php index 3120a70f9..c420b3eef 100644 --- a/plugins/OStatus/classes/HubSub.php +++ b/plugins/OStatus/classes/HubSub.php @@ -192,7 +192,7 @@ class HubSub extends Memcached_DataObject // Any existing query string parameters must be preserved $url = $this->callback; - if (strpos('?', $url) !== false) { + if (strpos($url, '?') !== false) { $url .= '&'; } else { $url .= '?'; -- cgit v1.2.3-54-g00ecf From 72e4c733735ac590599bef392611314370135b37 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 9 Mar 2010 11:06:08 +0000 Subject: Use canonical URL for notification in RSSCloud plugin --- plugins/RSSCloud/RSSCloudNotifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/RSSCloud/RSSCloudNotifier.php b/plugins/RSSCloud/RSSCloudNotifier.php index d454691c8..9e7b53680 100644 --- a/plugins/RSSCloud/RSSCloudNotifier.php +++ b/plugins/RSSCloud/RSSCloudNotifier.php @@ -152,7 +152,7 @@ class RSSCloudNotifier function notify($profile) { $feed = common_path('api/statuses/user_timeline/') . - $profile->nickname . '.rss'; + $profile->id . '.rss'; $cloudSub = new RSSCloudSubscription(); -- cgit v1.2.3-54-g00ecf From 7afad469c200d9d57af75fc667f05041bec137b6 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 9 Mar 2010 11:06:08 +0000 Subject: Use canonical URL for notification in RSSCloud plugin --- plugins/RSSCloud/RSSCloudNotifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/RSSCloud/RSSCloudNotifier.php b/plugins/RSSCloud/RSSCloudNotifier.php index d454691c8..9e7b53680 100644 --- a/plugins/RSSCloud/RSSCloudNotifier.php +++ b/plugins/RSSCloud/RSSCloudNotifier.php @@ -152,7 +152,7 @@ class RSSCloudNotifier function notify($profile) { $feed = common_path('api/statuses/user_timeline/') . - $profile->nickname . '.rss'; + $profile->id . '.rss'; $cloudSub = new RSSCloudSubscription(); -- cgit v1.2.3-54-g00ecf From 61434ebaa291ebd11cd1423ec36bb66073d55a74 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 9 Mar 2010 10:55:48 -0500 Subject: a script to flush site --- scripts/flushsite.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/flushsite.php diff --git a/scripts/flushsite.php b/scripts/flushsite.php new file mode 100644 index 000000000..b7f385ac4 --- /dev/null +++ b/scripts/flushsite.php @@ -0,0 +1,45 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'd'; +$longoptions = array('delete'); + +$helptext = << +Flush the site with the given name from memcached. + +END_OF_FLUSHSITE_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$nickname = common_config('site', 'nickname'); + +$sn = Status_network::memGet('nickname', $nickname); + +if (empty($sn)) { + print "No such site.\n"; + exit(-1); +} + +print "Flushing cache for {$nickname}..."; +$sn->decache(); +print "OK.\n"; \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 58192ad68758437a37d8af19d6676d35699ed070 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 9 Mar 2010 10:56:33 -0800 Subject: OStatus: fix exception thrown on HTTP error during feed discovery --- plugins/OStatus/lib/feeddiscovery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/OStatus/lib/feeddiscovery.php b/plugins/OStatus/lib/feeddiscovery.php index 7afb71bdc..ff76b229e 100644 --- a/plugins/OStatus/lib/feeddiscovery.php +++ b/plugins/OStatus/lib/feeddiscovery.php @@ -129,7 +129,7 @@ class FeedDiscovery function initFromResponse($response) { if (!$response->isOk()) { - throw new FeedSubBadResponseException($response->getCode()); + throw new FeedSubBadResponseException($response->getStatus()); } $sourceurl = $response->getUrl(); -- cgit v1.2.3-54-g00ecf