summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-07-28 11:59:42 -0700
committerBrion Vibber <brion@pobox.com>2010-07-28 11:59:42 -0700
commitab2c3686b7711f3d0e727093b487fcb54448cc39 (patch)
treeb42bbd7ca1be71f3b5f72e8461096f6e3c95b2c3 /lib
parentd645b342ac4a678b9f7932ee38858e25cd611f35 (diff)
parent189d34173311828ccfe0aec5f381ad26887384ce (diff)
Merge branch 'testing' into 0.9.x
Diffstat (limited to 'lib')
-rw-r--r--lib/activityutils.php6
-rw-r--r--lib/apiaction.php76
-rw-r--r--lib/apiauth.php38
-rw-r--r--lib/atomnoticefeed.php13
-rw-r--r--lib/noticelist.php10
-rw-r--r--lib/rssaction.php10
6 files changed, 80 insertions, 73 deletions
diff --git a/lib/activityutils.php b/lib/activityutils.php
index 401fd7fc2..dd38d4e14 100644
--- a/lib/activityutils.php
+++ b/lib/activityutils.php
@@ -257,6 +257,12 @@ class ActivityUtils
*/
static function validateUri($uri)
{
+ // Check mailto: URIs first
+
+ if (preg_match('/^mailto:(.*)$/', $uri, $match)) {
+ return Validate::email($match[1], common_config('email', 'check_domain'));
+ }
+
if (Validate::uri($uri)) {
return true;
}
diff --git a/lib/apiaction.php b/lib/apiaction.php
index 8de13a62d..7868ecab1 100644
--- a/lib/apiaction.php
+++ b/lib/apiaction.php
@@ -126,6 +126,7 @@ class ApiAction extends Action
var $max_id = null;
var $since_id = null;
var $source = null;
+ var $callback = null;
var $access = self::READ_ONLY; // read (default) or read-write
@@ -145,6 +146,7 @@ class ApiAction extends Action
parent::prepare($args);
$this->format = $this->arg('format');
+ $this->callback = $this->arg('callback');
$this->page = (int)$this->arg('page', 1);
$this->count = (int)$this->arg('count', 20);
$this->max_id = (int)$this->arg('max_id', 0);
@@ -461,6 +463,7 @@ class ApiAction extends Action
function twitterRssEntryArray($notice)
{
$profile = $notice->getProfile();
+
$entry = array();
// We trim() to avoid extraneous whitespace in the output
@@ -733,14 +736,16 @@ class ApiAction extends Action
'xmlns:statusnet' => 'http://status.net/schema/api/1/'));
if (is_array($notice)) {
- foreach ($notice as $n) {
- $twitter_status = $this->twitterStatusArray($n);
- $this->showTwitterXmlStatus($twitter_status);
- }
- } else {
- while ($notice->fetch()) {
+ $notice = new ArrayWrapper($notice);
+ }
+
+ while ($notice->fetch()) {
+ try {
$twitter_status = $this->twitterStatusArray($notice);
$this->showTwitterXmlStatus($twitter_status);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
}
}
@@ -788,14 +793,16 @@ class ApiAction extends Action
$this->element('ttl', null, '40');
if (is_array($notice)) {
- foreach ($notice as $n) {
- $entry = $this->twitterRssEntryArray($n);
- $this->showTwitterRssItem($entry);
- }
- } else {
- while ($notice->fetch()) {
+ $notice = new ArrayWrapper($notice);
+ }
+
+ while ($notice->fetch()) {
+ try {
$entry = $this->twitterRssEntryArray($notice);
$this->showTwitterRssItem($entry);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ // continue on exceptions
}
}
@@ -831,12 +838,15 @@ class ApiAction extends Action
$this->element('subtitle', null, $subtitle);
if (is_array($notice)) {
- foreach ($notice as $n) {
- $this->raw($n->asAtomEntry());
- }
- } else {
- while ($notice->fetch()) {
+ $notice = new ArrayWrapper($notice);
+ }
+
+ while ($notice->fetch()) {
+ try {
$this->raw($notice->asAtomEntry());
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
}
}
@@ -1031,14 +1041,16 @@ class ApiAction extends Action
$statuses = array();
if (is_array($notice)) {
- foreach ($notice as $n) {
- $twitter_status = $this->twitterStatusArray($n);
- array_push($statuses, $twitter_status);
- }
- } else {
- while ($notice->fetch()) {
+ $notice = new ArrayWrapper($notice);
+ }
+
+ while ($notice->fetch()) {
+ try {
$twitter_status = $this->twitterStatusArray($notice);
array_push($statuses, $twitter_status);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
}
}
@@ -1175,9 +1187,8 @@ class ApiAction extends Action
header('Content-Type: application/json; charset=utf-8');
// Check for JSONP callback
- $callback = $this->arg('callback');
- if ($callback) {
- print $callback . '(';
+ if (isset($this->callback)) {
+ print $this->callback . '(';
}
break;
case 'rss':
@@ -1206,8 +1217,7 @@ class ApiAction extends Action
case 'json':
// Check for JSONP callback
- $callback = $this->arg('callback');
- if ($callback) {
+ if (isset($this->callback)) {
print ')';
}
break;
@@ -1237,7 +1247,10 @@ class ApiAction extends Action
$status_string = ClientErrorAction::$status[$code];
- header('HTTP/1.1 '.$code.' '.$status_string);
+ // Do not emit error header for JSONP
+ if (!isset($this->callback)) {
+ header('HTTP/1.1 '.$code.' '.$status_string);
+ }
if ($format == 'xml') {
$this->initDocument('xml');
@@ -1270,7 +1283,10 @@ class ApiAction extends Action
$status_string = ServerErrorAction::$status[$code];
- header('HTTP/1.1 '.$code.' '.$status_string);
+ // Do not emit error header for JSONP
+ if (!isset($this->callback)) {
+ header('HTTP/1.1 '.$code.' '.$status_string);
+ }
if ($content_type == 'xml') {
$this->initDocument('xml');
diff --git a/lib/apiauth.php b/lib/apiauth.php
index 91cb64262..cf7a2692c 100644
--- a/lib/apiauth.php
+++ b/lib/apiauth.php
@@ -227,7 +227,7 @@ class ApiAuthAction extends ApiAction
} catch (OAuthException $e) {
common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
- $this->showAuthError();
+ $this->clientError($e->getMessage(), 401, $this->format);
exit;
}
}
@@ -265,7 +265,7 @@ class ApiAuthAction extends ApiAction
// show error if the user clicks 'cancel'
- $this->showAuthError();
+ $this->clientError("Could not authenticate you.", 401, $this->format);
exit;
} else {
@@ -298,7 +298,7 @@ class ApiAuthAction extends ApiAction
$proxy,
$ip);
common_log(LOG_WARNING, $msg);
- $this->showAuthError();
+ $this->clientError("Could not authenticate you.", 401, $this->format);
exit;
}
}
@@ -345,36 +345,4 @@ class ApiAuthAction extends ApiAction
}
}
}
-
- /**
- * Output an authentication error message. Use XML or JSON if one
- * of those formats is specified, otherwise output plain text
- *
- * @return void
- */
-
- function showAuthError()
- {
- header('HTTP/1.1 401 Unauthorized');
- $msg = 'Could not authenticate you.';
-
- if ($this->format == 'xml') {
- header('Content-Type: application/xml; charset=utf-8');
- $this->startXML();
- $this->elementStart('hash');
- $this->element('error', null, $msg);
- $this->element('request', null, $_SERVER['REQUEST_URI']);
- $this->elementEnd('hash');
- $this->endXML();
- } elseif ($this->format == 'json') {
- header('Content-Type: application/json; charset=utf-8');
- $error_array = array('error' => $msg,
- 'request' => $_SERVER['REQUEST_URI']);
- print(json_encode($error_array));
- } else {
- header('Content-type: text/plain');
- print "$msg\n";
- }
- }
-
}
diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php
index 6ed803ce4..b88217291 100644
--- a/lib/atomnoticefeed.php
+++ b/lib/atomnoticefeed.php
@@ -125,12 +125,17 @@ class AtomNoticeFeed extends Atom10Feed
*/
function addEntryFromNotice($notice)
{
- $source = $this->showSource();
- $author = $this->showAuthor();
+ try {
+ $source = $this->showSource();
+ $author = $this->showAuthor();
- $cur = empty($this->cur) ? common_current_user() : $this->cur;
+ $cur = empty($this->cur) ? common_current_user() : $this->cur;
- $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur));
+ $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur));
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ // we continue on exceptions
+ }
}
function showSource()
diff --git a/lib/noticelist.php b/lib/noticelist.php
index e23cf3b6d..17adf3a49 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -96,8 +96,14 @@ class NoticeList extends Widget
break;
}
- $item = $this->newListItem($this->notice);
- $item->show();
+ try {
+ $item = $this->newListItem($this->notice);
+ $item->show();
+ } catch (Exception $e) {
+ // we log exceptions and continue
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
+ }
}
$this->out->elementEnd('ol');
diff --git a/lib/rssaction.php b/lib/rssaction.php
index 62e3f21b6..f366db972 100644
--- a/lib/rssaction.php
+++ b/lib/rssaction.php
@@ -178,7 +178,13 @@ class Rss10Action extends Action
if (count($this->notices)) {
foreach ($this->notices as $n) {
- $this->showItem($n);
+ try {
+ $this->showItem($n);
+ } catch (Exception $e) {
+ // log exceptions and continue
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
+ }
}
}
@@ -232,7 +238,7 @@ class Rss10Action extends Action
function showItem($notice)
{
- $profile = Profile::staticGet($notice->profile_id);
+ $profile = $notice->getProfile();
$nurl = common_local_url('shownotice', array('notice' => $notice->id));
$creator_uri = common_profile_uri($profile);
$this->elementStart('item', array('rdf:about' => $notice->uri,