From 277b464054b24f8d680ddbe762c9e438f6679592 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 3 Sep 2009 19:42:50 +0000 Subject: Created autofocus method to give focus to an element (primarily a form control) on page onload. Updated some of the pages to use autofocus. --- lib/designsettings.php | 2 ++ lib/htmloutputter.php | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'lib') diff --git a/lib/designsettings.php b/lib/designsettings.php index fe4222597..fdc05562e 100644 --- a/lib/designsettings.php +++ b/lib/designsettings.php @@ -327,6 +327,8 @@ class DesignSettingsAction extends AccountSettingsAction $this->script('js/farbtastic/farbtastic.js'); $this->script('js/farbtastic/farbtastic.go.js'); $this->script('js/userdesign.go.js'); + + $this->autofocus('design_background-image_file'); } /** diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php index 8ad7dc20f..aa01f6b1d 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -412,4 +412,29 @@ class HTMLOutputter extends XMLOutputter $this->element('p', 'form_guide', $instructions); } } + + + /** + * Internal script to autofocus the given element on page onload. + * + * @param string $id element ID, must refer to an existing element + * + * @return void + * + */ + function autofocus($id) + { + $this->elementStart('script', array('type' => 'text/javascript')); + $this->raw(' + + '); + $this->elementEnd('script'); + } } -- cgit v1.2.3-54-g00ecf From 80b7e54ca2cebcfd7c2c5e63b4ef604106a42aca Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 4 Sep 2009 11:30:29 -0400 Subject: Added additional characters as allowed in URLs. --- lib/util.php | 6 +++--- tests/URLDetectionTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index f4ba3a6c2..79611af2c 100644 --- a/lib/util.php +++ b/lib/util.php @@ -442,9 +442,9 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { ')'. '(?:'. '(?:\:\d+)?'. //:port - '(?:/[\pN\pL$\[\]\,\!\(\)\.\:\-\_\+\/\=\&\;\%\~]*)?'. // /path - '(?:\?[\pN\pL\$\[\]\,\!\(\)\.\:\-\_\+\/\=\&\;\%\~\/]*)?'. // ?query string - '(?:\#[\pN\pL$\[\]\,\!\(\)\.\:\-\_\+\/\=\&\;\%\~\/\?\#]*)?'. // #fragment + '(?:/[\pN\pL$\[\]\,\!\(\)\.\:\-\_\+\/\=\&\;\%\~\*\$\+\'\"]*)?'. // /path + '(?:\?[\pN\pL\$\[\]\,\!\(\)\.\:\-\_\+\/\=\&\;\%\~\*\$\+\'\"\/]*)?'. // ?query string + '(?:\#[\pN\pL$\[\]\,\!\(\)\.\:\-\_\+\/\=\&\;\%\~\*\$\+\'\"\/\?\#]*)?'. // #fragment ')(?127.0.0.1/Name:test.php'), array('127.0.0.1/~test', '127.0.0.1/~test'), + array('127.0.0.1/+test', + '127.0.0.1/+test'), + array('127.0.0.1/$test', + '127.0.0.1/$test'), + array('127.0.0.1/\'test', + '127.0.0.1/\'test'), + array('127.0.0.1/"test', + '127.0.0.1/"test'), + array('127.0.0.1/-test', + '127.0.0.1/-test'), + array('127.0.0.1/_test', + '127.0.0.1/_test'), + array('127.0.0.1/!test', + '127.0.0.1/!test'), + array('127.0.0.1/*test', + '127.0.0.1/*test'), array('127.0.0.1/test%20stuff', '127.0.0.1/test%20stuff'), array('http://[::1]:99/test.php', -- cgit v1.2.3-54-g00ecf From b237dc21ba672957d38daeb0ce1ddf501a3ede3f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 4 Sep 2009 15:59:27 +0000 Subject: Updated layout for filter by tag form --- lib/galleryaction.php | 5 ++++- theme/base/css/display.css | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/galleryaction.php b/lib/galleryaction.php index 18cc7b929..31e36803a 100644 --- a/lib/galleryaction.php +++ b/lib/galleryaction.php @@ -132,13 +132,16 @@ class GalleryAction extends OwnerDesignAction $this->elementEnd('li'); $this->elementStart('li', array('id'=>'filter_tags_item')); $this->elementStart('form', array('name' => 'bytag', - 'id' => 'bytag', + 'id' => 'form_filter_bytag', 'action' => common_path('?action=' . $this->trimmed('action')), 'method' => 'post')); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Select tag to filter')); $this->dropdown('tag', _('Tag'), $content, _('Choose a tag to narrow list'), false, $tag); $this->hidden('nickname', $this->user->nickname); $this->submit('submit', _('Go')); + $this->elementEnd('fieldset'); $this->elementEnd('form'); $this->elementEnd('li'); $this->elementEnd('ul'); diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 6f1a29f4a..d770f3868 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -156,7 +156,8 @@ font-weight:bold; #form_notice_delete legend, #form_password_recover legend, #form_password_change legend, -.form_entity_block legend { +.form_entity_block legend, +#form_filter_bytag legend { display:none; } @@ -1049,36 +1050,37 @@ display:none; #filter_tags ul { list-style-type:none; } -#filter_tags ul li { +#filter_tags li { float:left; margin-left:7px; padding-left:7px; border-left-width:1px; border-left-style:solid; } -#filter_tags ul li.child_1 { +#filter_tags #filter_tags_all { margin-left:0; border-left:0; padding-left:0; } -#filter_tags ul li#filter_tags_all a { +#filter_tags_all a { font-weight:bold; margin-top:7px; float:left; } -#filter_tags ul li#filter_tags_item label { +#filter_tags_item label { margin-right:7px; } -#filter_tags ul li#filter_tags_item label, -#filter_tags ul li#filter_tags_item select { -display:inline; +#filter_tags_item label, +#filter_tags_item select { +float:left; } -#filter_tags ul li#filter_tags_item p { +#filter_tags_item p { float:left; +clear:both; margin-left:38px; } -#filter_tags ul li#filter_tags_item input { +#filter_tags_item .submit { position:relative; top:3px; left:3px; -- cgit v1.2.3-54-g00ecf From f218d7fd588660fb6d4def782c64abd8b991e4a7 Mon Sep 17 00:00:00 2001 From: brenda Date: Sat, 5 Sep 2009 16:11:38 +1200 Subject: more info in error message, to help next person who has to debug locales --- lib/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 79611af2c..3dcd077a7 100644 --- a/lib/util.php +++ b/lib/util.php @@ -59,7 +59,7 @@ function common_init_language() textdomain("statusnet"); setlocale(LC_CTYPE, 'C'); if(!$locale_set) { - common_log(LOG_INFO,'Language requested:'.$language.' - locale could not be set:',__FILE__); + common_log(LOG_INFO, 'Language requested:' . $language . ' - locale could not be set. Perhaps that system locale is not installed.', __FILE__); } } -- cgit v1.2.3-54-g00ecf From afe1b8ec3df8d231ae9c6699da3a3947da285c00 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Tue, 8 Sep 2009 11:27:37 +0100 Subject: Use a non-error-generating array key check to a) improve performance and b) not fill the log file with crud --- lib/omb.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/omb.php b/lib/omb.php index 0d6244599..7dca760c6 100644 --- a/lib/omb.php +++ b/lib/omb.php @@ -135,7 +135,7 @@ function omb_broadcast_remote_subscribers($notice) $posted = array(); while ($rp->fetch()) { - if (!$posted[$rp->postnoticeurl]) { + if (!array_key_exists($rp->postnoticeurl, $posted)) { common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl); if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) { common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl); -- cgit v1.2.3-54-g00ecf From aecdba1ded89b45f32d0b7615ce6b103478403dd Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 9 Sep 2009 16:57:11 -0400 Subject: :: isn't a valid IPv6 address for our purposes --- lib/util.php | 4 ++-- tests/URLDetectionTest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 3dcd077a7..256acf199 100644 --- a/lib/util.php +++ b/lib/util.php @@ -432,7 +432,7 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { ')'. '|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]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:(?:[0-9A-Fa-f]{1,4}:)(?::[0-9A-Fa-f]{1,4}){0,4}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?::(?::[0-9A-Fa-f]{1,4}){0,5}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?:(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})))\]?(?http://127.0.0.1'), array('127.0.0.1', -- cgit v1.2.3-54-g00ecf From e2848eb8621dd645fa68cb1641c0af1df5530408 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 9 Sep 2009 22:57:15 -0400 Subject: If a shortened URL begins with http://, don't include it in the shortened url. Saves 7 characters, which is pretty awesome for 140 character max length notices. --- lib/util.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 256acf199..3e95d2bea 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1414,6 +1414,9 @@ function common_shorten_url($long_url) curl_close($curlh); + if(substr($short_url,0,7)=='http://'){ + $short_url = substr($short_url,7); + } return $short_url; } -- cgit v1.2.3-54-g00ecf From 5bad7040b14bf61d84cc33c8b4cf2af3b5861d3b Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 14 Sep 2009 22:08:17 +0200 Subject: Fix bad merge d7ae0ed4fd755ebad0788a17d0f2fb6a6ca9d63b --- lib/omb.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/omb.php b/lib/omb.php index 9133af7a0..0566701ff 100644 --- a/lib/omb.php +++ b/lib/omb.php @@ -80,14 +80,9 @@ function omb_broadcast_notice($notice) $posted = array(); while ($rp->fetch()) { - if (!array_key_exists($rp->postnoticeurl, $posted)) { - common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl); - if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) { - common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl); - $posted[$rp->postnoticeurl] = true; - } else { - common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl); - } + if (isset($posted[$rp->postnoticeurl])) { + /* We already posted to this url. */ + continue; } common_debug('Posting to ' . $rp->postnoticeurl, __FILE__); -- cgit v1.2.3-54-g00ecf From d44bc16ee989af7f5ebbd6a40edcc7a4d90902a0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 26 Mar 2009 15:26:19 -0400 Subject: Start a common library for HTTP client stuff --- lib/httputil.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/httputil.php (limited to 'lib') diff --git a/lib/httputil.php b/lib/httputil.php new file mode 100644 index 000000000..5c1f4f3e1 --- /dev/null +++ b/lib/httputil.php @@ -0,0 +1,80 @@ +. + * + * @category Action + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Utility class for doing HTTP-related stuff + * + * We make HTTP calls in several places, and we have several different + * ways of doing them. This class hides the specifics of what underlying + * library (curl or PHP-HTTP or whatever) that's used. + * + * @category HTTP + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class HTTPResponse +{ + var $code = null; + var $headers = null; + var $body = null; +} + +class HTTPClientUtil +{ + function __construct() + { + } + + function head($url, $headers) + { + } + + function get($url, $headers) + { + } + + function post($url, $headers, $body) + { + } + + function put($url, $headers, $body) + { + } + + function delete($url, $headers) + { + } +} -- cgit v1.2.3-54-g00ecf From 20dd0db7049209a5f43697d8bba8eadb63736bce Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 20:29:41 -0400 Subject: move httputil to httpclient --- lib/httpclient.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/httputil.php | 80 ------------------------------------------------------ 2 files changed, 80 insertions(+), 80 deletions(-) create mode 100644 lib/httpclient.php delete mode 100644 lib/httputil.php (limited to 'lib') diff --git a/lib/httpclient.php b/lib/httpclient.php new file mode 100644 index 000000000..5c1f4f3e1 --- /dev/null +++ b/lib/httpclient.php @@ -0,0 +1,80 @@ +. + * + * @category Action + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Utility class for doing HTTP-related stuff + * + * We make HTTP calls in several places, and we have several different + * ways of doing them. This class hides the specifics of what underlying + * library (curl or PHP-HTTP or whatever) that's used. + * + * @category HTTP + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class HTTPResponse +{ + var $code = null; + var $headers = null; + var $body = null; +} + +class HTTPClientUtil +{ + function __construct() + { + } + + function head($url, $headers) + { + } + + function get($url, $headers) + { + } + + function post($url, $headers, $body) + { + } + + function put($url, $headers, $body) + { + } + + function delete($url, $headers) + { + } +} diff --git a/lib/httputil.php b/lib/httputil.php deleted file mode 100644 index 5c1f4f3e1..000000000 --- a/lib/httputil.php +++ /dev/null @@ -1,80 +0,0 @@ -. - * - * @category Action - * @package Laconica - * @author Evan Prodromou - * @copyright 2009 Control Yourself, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -if (!defined('LACONICA')) { - exit(1); -} - -/** - * Utility class for doing HTTP-related stuff - * - * We make HTTP calls in several places, and we have several different - * ways of doing them. This class hides the specifics of what underlying - * library (curl or PHP-HTTP or whatever) that's used. - * - * @category HTTP - * @package Laconica - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -class HTTPResponse -{ - var $code = null; - var $headers = null; - var $body = null; -} - -class HTTPClientUtil -{ - function __construct() - { - } - - function head($url, $headers) - { - } - - function get($url, $headers) - { - } - - function post($url, $headers, $body) - { - } - - function put($url, $headers, $body) - { - } - - function delete($url, $headers) - { - } -} -- cgit v1.2.3-54-g00ecf From ae20d073ce8cb393417be6f05cdf54289ecd5bad Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 20:40:03 -0400 Subject: update httpclient class --- lib/httpclient.php | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/httpclient.php b/lib/httpclient.php index 5c1f4f3e1..145409f50 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -32,7 +32,7 @@ if (!defined('LACONICA')) { } /** - * Utility class for doing HTTP-related stuff + * Useful structure for HTTP responses * * We make HTTP calls in several places, and we have several different * ways of doing them. This class hides the specifics of what underlying @@ -52,29 +52,66 @@ class HTTPResponse var $body = null; } -class HTTPClientUtil +/** + * Utility class for doing HTTP client stuff + * + * We make HTTP calls in several places, and we have several different + * ways of doing them. This class hides the specifics of what underlying + * library (curl or PHP-HTTP or whatever) that's used. + * + * @category HTTP + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class HTTPClient { - function __construct() + static $_client = null; + + static function start() { + if (!is_null(self::$_client)) { + return self::$_client; + } + + $type = common_config('http', 'client'); + + switch ($type) { + case 'curl': + self::$_client = new CurlClient(); + break; + default: + throw new Exception("Unknown HTTP client type '$type'"); + break; + } + + return self::$_client; } function head($url, $headers) { + throw new Exception("HEAD method unimplemented"); } function get($url, $headers) { + throw new Exception("GET method unimplemented"); } function post($url, $headers, $body) { + throw new Exception("POST method unimplemented"); } function put($url, $headers, $body) { + throw new Exception("PUT method unimplemented"); } function delete($url, $headers) { + throw new Exception("DELETE method unimplemented"); } } -- cgit v1.2.3-54-g00ecf From 3380b49aecb773ebadfe4a8e563f75ce4855e1a2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 20:40:18 -0400 Subject: add http client config value --- lib/common.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index 3b21b548c..194eb568f 100644 --- a/lib/common.php +++ b/lib/common.php @@ -284,6 +284,8 @@ $config = array('contentlimit' => null), 'message' => array('contentlimit' => null), + 'http' => + array('client' => 'curl'), // XXX: should this be the default? ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); -- cgit v1.2.3-54-g00ecf From 8ceb4196f323295742fd1113ff014ebee9ad7ae3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 21:22:47 -0400 Subject: add user agent and correct version check to httpclient --- lib/httpclient.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/httpclient.php b/lib/httpclient.php index 145409f50..d606f5a6e 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -27,7 +27,7 @@ * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET')) { exit(1); } @@ -114,4 +114,9 @@ class HTTPClient { throw new Exception("DELETE method unimplemented"); } + + function userAgent() + { + return "StatusNet/".STATUSNET_VERSION." (".STATUSNET_CODENAME.")"; + } } -- cgit v1.2.3-54-g00ecf From 9a9a0ae56f5ae65144e6da5014859b1e30044f8b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 21:50:19 -0400 Subject: add cURL client with HEAD method --- lib/curlclient.php | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/httpclient.php | 6 +-- 2 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 lib/curlclient.php (limited to 'lib') diff --git a/lib/curlclient.php b/lib/curlclient.php new file mode 100644 index 000000000..e027102e3 --- /dev/null +++ b/lib/curlclient.php @@ -0,0 +1,134 @@ +n. + * + * @category HTTP + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +define(CURLCLIENT_VERSION, "0.1"); + +/** + * Wrapper for Curl + * + * Makes Curl HTTP client calls within our HTTPClient framework + * + * @category HTTP + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class CurlClient extends HTTPClient +{ + function __construct() + { + } + + function head($url, $headers=null) + { + $ch = curl_init($url); + + $this->setup($ch); + + curl_setopt_array($ch, + array(CURLOPT_NOBODY => true)); + + $result = curl_exec($ch); + + return $this->parseResults($result); + } + + function setup($ch) + { + curl_setopt_array($ch, + array(CURLOPT_USERAGENT, $this->userAgent(), + CURLOPT_HEADER => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => $headers)); + } + + function userAgent() + { + $version = curl_version(); + return parent::userAgent() . " CurlClient/".CURLCLIENT_VERSION . " cURL/" . $version['version']; + } + + function parseResults($results) + { + $resp = new HTTPResponse(); + + $lines = explode("\r\n", $results); + + if (preg_match("#^HTTP/1.[01] (\d\d\d) .+$#", $lines[0], $match)) { + $resp->code = $match[1]; + } else { + throw Exception("Bad format: initial line is not HTTP status line"); + } + + $lastk = null; + + for ($i = 1; $i < count($lines); $i++) { + $l =& $lines[$i]; + if (mb_strlen($l) == 0) { + $resp->body = implode("\r\n", array_slice($lines, $i + 1)); + break; + } + if (preg_match("#^(\S+):\s+(.*)$#", $l, $match)) { + $k = $match[1]; + $v = $match[2]; + + if (array_key_exists($k, $resp->headers)) { + if (is_array($resp->headers[$k])) { + $resp->headers[$k][] = $v; + } else { + $resp->headers[$k] = array($resp->headers[$k], $v); + } + } else { + $resp->headers[$k] = $v; + } + $lastk = $k; + } else if (preg_match("#^\s+(.*)$#", $l, $match)) { + // continuation line + if (is_null($lastk)) { + throw Exception("Bad format: initial whitespace in headers"); + } + $h =& $resp->headers[$lastk]; + if (is_array($h)) { + $n = count($h); + $h[$n-1] .= $match[1]; + } else { + $h .= $match[1]; + } + } + } + + return $resp; + } +} diff --git a/lib/httpclient.php b/lib/httpclient.php index d606f5a6e..9b0bb6f3a 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -47,9 +47,9 @@ if (!defined('STATUSNET')) { class HTTPResponse { - var $code = null; - var $headers = null; - var $body = null; + public $code = null; + public $headers = null; + public $body = null; } /** -- cgit v1.2.3-54-g00ecf From 6b7f09eba675679d5ea84ed33e85fa9d5c62a30d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 21:55:36 -0400 Subject: add get to curl client --- lib/curlclient.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/curlclient.php b/lib/curlclient.php index e027102e3..f45c3c2f4 100644 --- a/lib/curlclient.php +++ b/lib/curlclient.php @@ -60,8 +60,31 @@ class CurlClient extends HTTPClient curl_setopt_array($ch, array(CURLOPT_NOBODY => true)); + if (!is_null($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + + $result = curl_exec($ch); + + curl_close($ch); + + return $this->parseResults($result); + } + + function get($url, $headers=null) + { + $ch = curl_init($url); + + $this->setup($ch); + + if (!is_null($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + $result = curl_exec($ch); + curl_close($ch); + return $this->parseResults($result); } @@ -70,8 +93,7 @@ class CurlClient extends HTTPClient curl_setopt_array($ch, array(CURLOPT_USERAGENT, $this->userAgent(), CURLOPT_HEADER => true, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HTTPHEADER => $headers)); + CURLOPT_RETURNTRANSFER => true)); } function userAgent() -- cgit v1.2.3-54-g00ecf From f8a8c14b550a3ac3a4b3a17c53559056f70409b2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 22:05:57 -0400 Subject: fix user-agent for curlclient --- lib/curlclient.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/curlclient.php b/lib/curlclient.php index f45c3c2f4..99c3b6aa4 100644 --- a/lib/curlclient.php +++ b/lib/curlclient.php @@ -88,10 +88,14 @@ class CurlClient extends HTTPClient return $this->parseResults($result); } + function post($url, $headers=null) + { + } + function setup($ch) { curl_setopt_array($ch, - array(CURLOPT_USERAGENT, $this->userAgent(), + array(CURLOPT_USERAGENT => $this->userAgent(), CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true)); } -- cgit v1.2.3-54-g00ecf From 2f97531a49c042a0a900edb31f067a3c9f32967f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 22:14:15 -0400 Subject: add post to curlclient --- lib/curlclient.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/curlclient.php b/lib/curlclient.php index 99c3b6aa4..c43bfb57f 100644 --- a/lib/curlclient.php +++ b/lib/curlclient.php @@ -88,8 +88,27 @@ class CurlClient extends HTTPClient return $this->parseResults($result); } - function post($url, $headers=null) + function post($url, $headers=null, $body=null) { + $ch = curl_init($url); + + $this->setup($ch); + + curl_setopt($ch, CURLOPT_POST, true); + + if (!is_null($body)) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + } + + if (!is_null($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + + $result = curl_exec($ch); + + curl_close($ch); + + return $this->parseResults($result); } function setup($ch) -- cgit v1.2.3-54-g00ecf From 6f531745ca21e7b5460be90890c55b1934a45f15 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 22:28:59 -0400 Subject: change all evans to evan@status.net --- actions/all.php | 6 +++--- actions/api.php | 6 +++--- actions/finishremotesubscribe.php | 2 +- actions/updateprofile.php | 2 +- index.php | 6 +++--- install.php | 2 +- lib/httpclient.php | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/actions/all.php b/actions/all.php index e56e10c21..5ffc7e9bd 100644 --- a/actions/all.php +++ b/actions/all.php @@ -18,15 +18,15 @@ * * @category Actions * @package Actions - * @author Evan Prodromou - * @author Evan Prodromou + * @author Evan Prodromou + * @author Evan Prodromou * @author Mike Cochrane * @author Robin Millette * @author Adrian Lang * @author Meitar Moscovitz * @author Sarven Capadisli * @author Craig Andrews - * @author Evan Prodromou + * @author Evan Prodromou * @author Evan Prodromou * @author Jeffery To * @author Zach Copley diff --git a/actions/api.php b/actions/api.php index 9b5f54807..06fdbfb44 100644 --- a/actions/api.php +++ b/actions/api.php @@ -18,8 +18,8 @@ * * @category Actions * @package Actions - * @author Evan Prodromou - * @author Evan Prodromou + * @author Evan Prodromou + * @author Evan Prodromou * @author Brenda Wallace * @author Jeffery To * @author Robin Millette @@ -27,7 +27,7 @@ * @author Christopher Vollick * @author CiaranG * @author Craig Andrews - * @author Evan Prodromou + * @author Evan Prodromou * @author Evan Prodromou * @author Gina Haeussge * @author Mike Cochrane diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php index 44abbfceb..5f6807d10 100644 --- a/actions/finishremotesubscribe.php +++ b/actions/finishremotesubscribe.php @@ -41,7 +41,7 @@ require_once INSTALLDIR.'/lib/omb.php'; * * @category Action * @package Laconica - * @author Evan Prodromou + * @author Evan Prodromou * @author Robin Millette * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://laconi.ca/ diff --git a/actions/updateprofile.php b/actions/updateprofile.php index 7f7dd75fe..d9cc7f7f3 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -38,7 +38,7 @@ require_once INSTALLDIR.'/extlib/libomb/service_provider.php'; * * @category Action * @package Laconica - * @author Evan Prodromou + * @author Evan Prodromou * @author Robin Millette * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://laconi.ca/ diff --git a/index.php b/index.php index a1d983dce..4e6c09379 100644 --- a/index.php +++ b/index.php @@ -23,9 +23,9 @@ * @author Christopher Vollick * @author CiaranG * @author Craig Andrews - * @author Evan Prodromou - * @author Evan Prodromou - * @author Evan Prodromou + * @author Evan Prodromou + * @author Evan Prodromou + * @author Evan Prodromou * @author Evan Prodromou * @author Gina Haeussge * @author Jeffery To diff --git a/install.php b/install.php index 54ae0cd5e..24ad3eb24 100644 --- a/install.php +++ b/install.php @@ -26,7 +26,7 @@ * @author CiaranG * @author Craig Andrews * @author Eric Helgeson - * @author Evan Prodromou + * @author Evan Prodromou * @author Evan Prodromou * @author Robin Millette * @author Sarven Capadisli diff --git a/lib/httpclient.php b/lib/httpclient.php index 9b0bb6f3a..005971153 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -21,7 +21,7 @@ * * @category Action * @package Laconica - * @author Evan Prodromou + * @author Evan Prodromou * @copyright 2009 Control Yourself, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/ @@ -40,7 +40,7 @@ if (!defined('STATUSNET')) { * * @category HTTP * @package Laconica - * @author Evan Prodromou + * @author Evan Prodromou * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/ */ @@ -61,7 +61,7 @@ class HTTPResponse * * @category HTTP * @package Laconica - * @author Evan Prodromou + * @author Evan Prodromou * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/ */ -- cgit v1.2.3-54-g00ecf From 15a2b69777479f1544a681ed1bff76aa066cf95c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Sep 2009 22:31:52 -0400 Subject: statusize new HTTP classes --- lib/curlclient.php | 10 +++++----- lib/httpclient.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/curlclient.php b/lib/curlclient.php index c43bfb57f..36fc7d157 100644 --- a/lib/curlclient.php +++ b/lib/curlclient.php @@ -1,6 +1,6 @@ n. * * @category HTTP - * @package Laconica + * @package StatusNet * @author Evan Prodromou * @copyright 2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ if (!defined('STATUSNET')) { @@ -39,10 +39,10 @@ define(CURLCLIENT_VERSION, "0.1"); * Makes Curl HTTP client calls within our HTTPClient framework * * @category HTTP - * @package Laconica + * @package StatusNet * @author Evan Prodromou * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ class CurlClient extends HTTPClient diff --git a/lib/httpclient.php b/lib/httpclient.php index 005971153..c8c8ae5b2 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -1,6 +1,6 @@ . * * @category Action - * @package Laconica + * @package StatusNet * @author Evan Prodromou - * @copyright 2009 Control Yourself, Inc. + * @copyright 2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ if (!defined('STATUSNET')) { @@ -39,10 +39,10 @@ if (!defined('STATUSNET')) { * library (curl or PHP-HTTP or whatever) that's used. * * @category HTTP - * @package Laconica + * @package StatusNet * @author Evan Prodromou * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ class HTTPResponse @@ -60,10 +60,10 @@ class HTTPResponse * library (curl or PHP-HTTP or whatever) that's used. * * @category HTTP - * @package Laconica + * @package StatusNet * @author Evan Prodromou * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ class HTTPClient -- cgit v1.2.3-54-g00ecf