diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/clienterroraction.php | 43 | ||||
-rw-r--r-- | lib/common.php | 5 | ||||
-rw-r--r-- | lib/error.php | 6 | ||||
-rw-r--r-- | lib/htmloutputter.php | 26 | ||||
-rw-r--r-- | lib/searchaction.php | 12 | ||||
-rw-r--r-- | lib/servererroraction.php | 19 | ||||
-rw-r--r-- | lib/twitterapi.php | 56 | ||||
-rw-r--r-- | lib/util.php | 4 |
8 files changed, 88 insertions, 83 deletions
diff --git a/lib/clienterroraction.php b/lib/clienterroraction.php index 7d007a756..1b98a1064 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/common.php b/lib/common.php index 88d77732f..0b4e03184 100644 --- a/lib/common.php +++ b/lib/common.php @@ -196,15 +196,14 @@ $config = array('enabled' => true), 'sms' => array('enabled' => true), - 'twitter' => - array('enabled' => true), 'twitterbridge' => array('enabled' => false), 'integration' => array('source' => 'StatusNet', # source attribute for Twitter 'taguri' => $_server.',2009'), # base for tag URIs 'twitter' => - array('consumer_key' => null, + array('enabled' => true, + 'consumer_key' => null, 'consumer_secret' => null), 'memcached' => array('enabled' => false, diff --git a/lib/error.php b/lib/error.php index 0c521db08..6a9b76be1 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/htmloutputter.php b/lib/htmloutputter.php index aa01f6b1d..2ff9380cc 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -106,14 +106,16 @@ class HTMLOutputter extends XMLOutputter } } - header('Content-Type: '.$type); + header('Content-Type: '.$type.'; charset=UTF-8'); $this->extraHeaders(); - if( ! substr($type,0,strlen('text/html'))=='text/html' ){ - // Browsers don't like it when <?xml it output for non-xhtml documents + if (preg_match("/.*\/.*xml/", $type)) { + // Required for XML documents $this->xw->startDocument('1.0', 'UTF-8'); } - $this->xw->writeDTD('html'); + $this->xw->writeDTD('html', + '-//W3C//DTD XHTML 1.0 Strict//EN', + 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); $language = $this->getLanguage(); @@ -425,16 +427,12 @@ class HTMLOutputter extends XMLOutputter function autofocus($id) { $this->elementStart('script', array('type' => 'text/javascript')); - $this->raw(' - <!-- - $(document).ready(function() { - var el = $("#' . $id . '"); - if (el.length) { - el.focus(); - } - }); - --> - '); + $this->raw('/*<![CDATA[*/'. + ' $(document).ready(function() {'. + ' var el = $("#' . $id . '");'. + ' if (el.length) { el.focus(); }'. + ' });'. + ' /*]]>*/'); $this->elementEnd('script'); } } diff --git a/lib/searchaction.php b/lib/searchaction.php index 0d9f85a8f..130b28ff5 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -135,16 +135,21 @@ class SearchAction extends Action } function searchSuggestions($q) { - $qe = urlencode($q); - $message = sprintf(_(<<<E_O_T + $message = _(<<<E_O_T * Make sure all words are spelled correctly. * Try different keywords. * Try more general keywords. * Try fewer keywords. +E_O_T +); + if (!common_config('site', 'private')) { + $qe = urlencode($q); + $message .= sprintf(_(<<<E_O_T + You can also try your search on other engines: -* [Twingly](http://www.twingly.com/search?q=%s&content=microblog&site=identi.ca) +* [Twingly](http://www.twingly.com/search?q=%s&content=microblog&site=%%%%site.server%%%%) * [Tweet scan](http://www.tweetscan.com/indexi.php?s=%s) * [Google](http://www.google.com/search?q=site%%3A%%%%site.server%%%%+%s) * [Yahoo](http://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s) @@ -152,6 +157,7 @@ You can also try your search on other engines: E_O_T ), $qe, $qe, $qe, $qe, $qe); + } $this->elementStart('dl', array('id' => 'help_search', 'class' => 'help')); $this->element('dt', null, _('Search help')); $this->elementStart('dd', 'instructions'); diff --git a/lib/servererroraction.php b/lib/servererroraction.php index c6400605e..0993a63bc 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]; - } } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 638efba24..3bac400e2 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(); diff --git a/lib/util.php b/lib/util.php index b831859e9..9b299cb14 100644 --- a/lib/util.php +++ b/lib/util.php @@ -981,7 +981,7 @@ function common_set_returnto($url) function common_get_returnto() { common_ensure_session(); - return $_SESSION['returnto']; + return (array_key_exists('returnto', $_SESSION)) ? $_SESSION['returnto'] : null; } function common_timestamp() @@ -1148,7 +1148,7 @@ function common_negotiate_type($cprefs, $sprefs) } if ('text/html' === $besttype) { - return "text/html; charset=utf-8"; + return "text/html"; } return $besttype; } |