From 155ba6c103b3672656937ad36bec02cb9c7834e5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Sep 2009 09:12:44 -0400 Subject: [PATCH 1/3] stop overwriting created timestamp on group edit --- actions/editgroup.php | 1 - 1 file changed, 1 deletion(-) diff --git a/actions/editgroup.php b/actions/editgroup.php index e7ba836a01..b8dac31cb1 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -250,7 +250,6 @@ class EditgroupAction extends GroupDesignAction $this->group->homepage = $homepage; $this->group->description = $description; $this->group->location = $location; - $this->group->created = common_sql_now(); $result = $this->group->update($orig); From 5252c438040f071e0c61a9c93152dcf1aa382504 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Sep 2009 17:43:45 -0400 Subject: [PATCH 2/3] move HTTP error code strings to class variables --- lib/clienterroraction.php | 43 +++++++++++++++++---------------------- lib/error.php | 6 ++++-- lib/servererroraction.php | 19 +++++++---------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/lib/clienterroraction.php b/lib/clienterroraction.php index 7d007a7567..1b98a10645 100644 --- a/lib/clienterroraction.php +++ b/lib/clienterroraction.php @@ -46,28 +46,28 @@ require_once INSTALLDIR.'/lib/error.php'; */ class ClientErrorAction extends ErrorAction { + static $status = array(400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed'); + function __construct($message='Error', $code=400) { parent::__construct($message, $code); - - $this->status = array(400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Requested Range Not Satisfiable', - 417 => 'Expectation Failed'); $this->default = 400; } @@ -91,9 +91,4 @@ class ClientErrorAction extends ErrorAction $this->showPage(); } - - function title() - { - return $this->status[$this->code]; - } } diff --git a/lib/error.php b/lib/error.php index 0c521db081..6a9b76be11 100644 --- a/lib/error.php +++ b/lib/error.php @@ -44,9 +44,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { */ class ErrorAction extends Action { + static $status = array(); + var $code = null; var $message = null; - var $status = null; var $default = null; function __construct($message, $code, $output='php://output', $indent=true) @@ -88,9 +89,10 @@ class ErrorAction extends Action * * @return page title */ + function title() { - return $this->message; + return self::$status[$this->code]; } function isReadOnly($args) diff --git a/lib/servererroraction.php b/lib/servererroraction.php index c6400605ea..0993a63bca 100644 --- a/lib/servererroraction.php +++ b/lib/servererroraction.php @@ -55,17 +55,17 @@ require_once INSTALLDIR.'/lib/error.php'; class ServerErrorAction extends ErrorAction { + static $status = array(500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported'); + function __construct($message='Error', $code=500) { parent::__construct($message, $code); - $this->status = array(500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported'); - $this->default = 500; // Server errors must be logged. @@ -93,9 +93,4 @@ class ServerErrorAction extends ErrorAction $this->showPage(); } - - function title() - { - return $this->status[$this->code]; - } } From 5309910b9b4dd2533ff5b2190f90bf415fd20113 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Sep 2009 17:57:31 -0400 Subject: [PATCH 3/3] Twitter API returns server errors in preferred format --- actions/twitapistatuses.php | 2 +- lib/twitterapi.php | 56 ++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 5e2867ea81..41887a68f4 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -297,7 +297,7 @@ class TwitapistatusesAction extends TwitterapiAction $source, 1, $reply_to); if (is_string($notice)) { - $this->serverError($notice); + $this->serverError($notice, 500, $apidata['content-type']); return; } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 638efba241..3bac400e2f 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -501,7 +501,7 @@ class TwitterapiAction extends Action $enclosure = $entry['enclosures'][0]; $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null); } - + if(array_key_exists('tags', $entry)){ foreach($entry['tags'] as $tag){ $this->element('category', null,$tag); @@ -939,35 +939,16 @@ class TwitterapiAction extends Action function clientError($msg, $code = 400, $content_type = 'json') { - - static $status = array(400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Requested Range Not Satisfiable', - 417 => 'Expectation Failed'); - $action = $this->trimmed('action'); common_debug("User error '$code' on '$action': $msg", __FILE__); - if (!array_key_exists($code, $status)) { + if (!array_key_exists($code, ClientErrorAction::$status)) { $code = 400; } - $status_string = $status[$code]; + $status_string = ClientErrorAction::$status[$code]; + header('HTTP/1.1 '.$code.' '.$status_string); if ($content_type == 'xml') { @@ -986,6 +967,35 @@ class TwitterapiAction extends Action } + function serverError($msg, $code = 500, $content_type = 'json') + { + $action = $this->trimmed('action'); + + common_debug("Server error '$code' on '$action': $msg", __FILE__); + + if (!array_key_exists($code, ServerErrorAction::$status)) { + $code = 400; + } + + $status_string = ServerErrorAction::$status[$code]; + + header('HTTP/1.1 '.$code.' '.$status_string); + + if ($content_type == 'xml') { + $this->init_document('xml'); + $this->elementStart('hash'); + $this->element('error', null, $msg); + $this->element('request', null, $_SERVER['REQUEST_URI']); + $this->elementEnd('hash'); + $this->end_document('xml'); + } else { + $this->init_document('json'); + $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); + print(json_encode($error_array)); + $this->end_document('json'); + } + } + function init_twitter_rss() { $this->startXML();