From 7f5fbee2e36889fae1d1c5043d76625e197e39ea Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 30 Oct 2009 09:17:19 +1300 Subject: [PATCH 01/41] give some suggestions back to the user when no config file found, and a link to the installer --- lib/common.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/common.php b/lib/common.php index e29456ed4e..667826f395 100644 --- a/lib/common.php +++ b/lib/common.php @@ -185,7 +185,14 @@ function _have_config() } // XXX: Throw a conniption if database not installed - +// XXX: Find a way to use htmlwriter for this instead of handcoded markup +if (!_have_config()) { + echo '

'. _('No configuation file found. ') .'

'; + echo '

'. _('I looked for configuration files in the following places: ') .'
'. implode($_config_files, '
'); + echo '

'. _('You make wish run the installer to fix this.') .'

'; + echo ''. _('Go to the installer.') .''; + exit; +} // Fixup for statusnet.ini $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1); From 54696f7c46684234bbeb48747b37f934ffd0d393 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 29 Oct 2009 16:01:25 -0400 Subject: [PATCH 02/41] Moved the public XRDS from the OpenID plugin to core Added 4 new events involved in XRDS: StartUserXRDS, EndUserXRDS, StartPublicXRDS, EndPublicXRDS Added OpenID provider functionality (no delegation support [yet]) --- EVENTS.txt | 16 +++ actions/public.php | 7 ++ actions/publicxrds.php | 81 +++++++++++++ actions/xrds.php | 108 +++++++++++------- lib/router.php | 3 + .../publicxrds.php => lib/xrdsoutputter.php | 77 +++++-------- plugins/OpenID/OpenIDPlugin.php | 63 ++++++++-- plugins/OpenID/openid.php | 8 ++ plugins/OpenID/openidserver.php | 96 ++++++++++++++++ 9 files changed, 361 insertions(+), 98 deletions(-) create mode 100644 actions/publicxrds.php rename plugins/OpenID/publicxrds.php => lib/xrdsoutputter.php (52%) create mode 100644 plugins/OpenID/openidserver.php diff --git a/EVENTS.txt b/EVENTS.txt index d989557e64..a8a77390f6 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -458,3 +458,19 @@ StartProfileListItemActionElements: Showing the profile list actions (prepend a EndProfileListItemActionElements: Showing profile list actions (append a button here) - $item: ProfileListItem widget + +StartUserXRDS: Start XRDS output (right after the opening XRDS tag) +- $action: the current action +- &$xrdsoutputter - XRDSOutputter object to write to + +EndUserXRDS: End XRDS output (right before the closing XRDS tag) +- $action: the current action +- &$xrdsoutputter - XRDSOutputter object to write to + +StartPublicXRDS: Start XRDS output (right after the opening XRDS tag) +- $action: the current action +- &$xrdsoutputter - XRDSOutputter object to write to + +EndPublicXRDS: End XRDS output (right before the closing XRDS tag) +- $action: the current action +- &$xrdsoutputter - XRDSOutputter object to write to diff --git a/actions/public.php b/actions/public.php index 73fad182a3..4b71e58532 100644 --- a/actions/public.php +++ b/actions/public.php @@ -131,6 +131,13 @@ class PublicAction extends Action return _('Public timeline'); } } + + function extraHead() + { + parent::extraHead(); + $this->element('meta', array('http-equiv' => 'X-XRDS-Location', + 'content' => common_local_url('publicxrds'))); + } /** * Output elements for RSS and Atom feeds diff --git a/actions/publicxrds.php b/actions/publicxrds.php new file mode 100644 index 0000000000..5fd4eead7d --- /dev/null +++ b/actions/publicxrds.php @@ -0,0 +1,81 @@ + + * @author Robin Millette + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + * + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2008, 2009, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/plugins/OpenID/openid.php'; +require_once INSTALLDIR.'/lib/xrdsoutputter.php'; + +/** + * Public XRDS + * + * @category Action + * @package StatusNet + * @author Evan Prodromou + * @author Robin Millette + * @author Craig Andrews + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + * + * @todo factor out similarities with XrdsAction + */ +class PublicxrdsAction extends Action +{ + /** + * Is read only? + * + * @return boolean true + */ + function isReadOnly($args) + { + return true; + } + + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return nothing + */ + function handle($args) + { + parent::handle($args); + $xrdsOutputter = new XRDSOutputter(); + $xrdsOutputter->startXRDS(); + Event::handle('StartPublicXRDS', array($this,&$xrdsOutputter)); + Event::handle('EndPublicXRDS', array($this,&$xrdsOutputter)); + $xrdsOutputter->endXRDS(); + } +} + diff --git a/actions/xrds.php b/actions/xrds.php index 8ba89fec0f..8f09557d18 100644 --- a/actions/xrds.php +++ b/actions/xrds.php @@ -36,6 +36,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { require_once INSTALLDIR.'/lib/omb.php'; require_once INSTALLDIR.'/extlib/libomb/service_provider.php'; require_once INSTALLDIR.'/extlib/libomb/xrds_mapper.php'; +require_once INSTALLDIR.'/lib/xrdsoutputter.php'; /** * XRDS for OpenMicroBlogging @@ -49,6 +50,8 @@ require_once INSTALLDIR.'/extlib/libomb/xrds_mapper.php'; */ class XrdsAction extends Action { + var $user; + /** * Is read only? * @@ -58,6 +61,18 @@ class XrdsAction extends Action { return true; } + + function prepare($args) + { + parent::prepare($args); + $nickname = $this->trimmed('nickname'); + $this->user = User::staticGet('nickname', $nickname); + if (!$this->user) { + $this->clientError(_('No such user.')); + return; + } + return true; + } /** * Class handler. @@ -69,49 +84,64 @@ class XrdsAction extends Action function handle($args) { parent::handle($args); - $nickname = $this->trimmed('nickname'); - $user = User::staticGet('nickname', $nickname); - if (!$user) { - $this->clientError(_('No such user.')); - return; - } - $this->showXrds($user); - } + $xrdsOutputter = new XRDSOutputter(); + $xrdsOutputter->startXRDS(); - /** - * Show XRDS for a user. - * - * @param class $user XRDS for this user. - * - * @return void - */ - function showXrds($user) - { - $srv = new OMB_Service_Provider(profile_to_omb_profile($user->uri, - $user->getProfile())); - /* Use libomb’s default XRDS Writer. */ - $xrds_writer = null; - $srv->writeXRDS(new Laconica_XRDS_Mapper(), $xrds_writer); - } -} + Event::handle('StartUserXRDS', array($this,&$xrdsOutputter)); -class Laconica_XRDS_Mapper implements OMB_XRDS_Mapper -{ - protected $urls; + //oauth + $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xml:id' => 'oauth', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $xrdsOutputter->element('Type', null, 'xri://$xrds*simple'); + $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_REQUEST, + common_local_url('requesttoken'), + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1)); + $xrdsOutputter->showXrdsService( OAUTH_ENDPOINT_AUTHORIZE, + common_local_url('userauthorization'), + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1), + null, + $this->user->getIdentifierURI()); + $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_ACCESS, + common_local_url('accesstoken'), + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1), + null, + $this->user->getIdentifierURI()); + $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_RESOURCE, + null, + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1), + null, + $this->user->getIdentifierURI()); + $xrdsOutputter->elementEnd('XRD'); + + //omb + $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xml:id' => 'oauth', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $xrdsOutputter->element('Type', null, 'xri://$xrds*simple'); + $xrdsOutputter->showXrdsService(OMB_ENDPOINT_POSTNOTICE, + common_local_url('postnotice')); + $xrdsOutputter->showXrdsService(OMB_ENDPOINT_UPDATEPROFILE, + common_local_url('updateprofile')); + $xrdsOutputter->elementEnd('XRD'); + + //misc + $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xml:id' => 'oauth', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $xrdsOutputter->showXrdsService(OAUTH_DISCOVERY, + '#oauth'); + $xrdsOutputter->showXrdsService(OMB_VERSION, + '#omb'); + $xrdsOutputter->elementEnd('XRD'); - public function __construct() - { - $this->urls = array( - OAUTH_ENDPOINT_REQUEST => 'requesttoken', - OAUTH_ENDPOINT_AUTHORIZE => 'userauthorization', - OAUTH_ENDPOINT_ACCESS => 'accesstoken', - OMB_ENDPOINT_POSTNOTICE => 'postnotice', - OMB_ENDPOINT_UPDATEPROFILE => 'updateprofile'); - } + Event::handle('EndUserXRDS', array($this,&$xrdsOutputter)); - public function getURL($action) - { - return common_local_url($this->urls[$action]); + $xrdsOutputter->endXRDS(); + } } ?> diff --git a/lib/router.php b/lib/router.php index 2fd255fe6f..0dd130ab07 100644 --- a/lib/router.php +++ b/lib/router.php @@ -108,6 +108,9 @@ class Router $m->connect('main/oembed', array('action' => 'oembed')); + $m->connect('main/xrds', + array('action' => 'publicxrds')); + // these take a code foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) { diff --git a/plugins/OpenID/publicxrds.php b/lib/xrdsoutputter.php similarity index 52% rename from plugins/OpenID/publicxrds.php rename to lib/xrdsoutputter.php index 1b2b359caa..0e228e2937 100644 --- a/plugins/OpenID/publicxrds.php +++ b/lib/xrdsoutputter.php @@ -1,21 +1,12 @@ - * @author Robin Millette - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 - * @link http://status.net/ - * - * StatusNet - the distributed open-source microblogging tool - * Copyright (C) 2008, 2009, StatusNet, Inc. - * - * This program is free software: you can redistribute it and/or modify + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -27,60 +18,45 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . + * + * @category Output + * @package StatusNet + * @author Craig Andrews + * @copyright 2008 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ */ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/plugins/OpenID/openid.php'; +require_once INSTALLDIR.'/lib/xmloutputter.php'; /** - * Public XRDS for OpenID + * Low-level generator for XRDS XML * - * @category Action + * @category Output * @package StatusNet - * @author Evan Prodromou - * @author Robin Millette - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @author Craig Andrews + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ * - * @todo factor out similarities with XrdsAction + * @see Action + * @see XMLOutputter */ -class PublicxrdsAction extends Action -{ - /** - * Is read only? - * - * @return boolean true - */ - function isReadOnly($args) - { - return true; - } - /** - * Class handler. - * - * @param array $args array of arguments - * - * @return nothing - */ - function handle($args) +class XRDSOutputter extends XMLOutputter +{ + public function startXRDS() { - parent::handle($args); header('Content-Type: application/xrds+xml'); $this->startXML(); $this->elementStart('XRDS', array('xmlns' => 'xri://$xrds')); - $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', - 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', - 'version' => '2.0')); - $this->element('Type', null, 'xri://$xrds*simple'); - foreach (array('finishopenidlogin', 'finishaddopenid') as $finish) { - $this->showService(Auth_OpenID_RP_RETURN_TO_URL_TYPE, - common_local_url($finish)); - } - $this->elementEnd('XRD'); + } + + public function endXRDS() + { $this->elementEnd('XRDS'); $this->endXML(); } @@ -96,7 +72,7 @@ class PublicxrdsAction extends Action * * @return void */ - function showService($type, $uri, $params=null, $sigs=null, $localId=null) + function showXrdsService($type, $uri, $params=null, $sigs=null, $localId=null) { $this->elementStart('Service'); if ($uri) { @@ -119,4 +95,3 @@ class PublicxrdsAction extends Action $this->elementEnd('Service'); } } - diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index 81e3ed9c4c..5ebee2cbe4 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -62,17 +62,59 @@ class OpenIDPlugin extends Plugin * @return boolean hook return */ - function onRouterInitialized($m) + function onStartInitializeRouter($m) { $m->connect('main/openid', array('action' => 'openidlogin')); + $m->connect('main/openidtrust', array('action' => 'openidtrust')); $m->connect('settings/openid', array('action' => 'openidsettings')); - $m->connect('xrds', array('action' => 'publicxrds')); $m->connect('index.php?action=finishopenidlogin', array('action' => 'finishopenidlogin')); $m->connect('index.php?action=finishaddopenid', array('action' => 'finishaddopenid')); - + $m->connect('main/openidserver', array('action' => 'openidserver')); + return true; } + function onEndPublicXRDS($action, &$xrdsOutputter) + { + $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $xrdsOutputter->element('Type', null, 'xri://$xrds*simple'); + //consumer + foreach (array('finishopenidlogin', 'finishaddopenid') as $finish) { + $xrdsOutputter->showXrdsService(Auth_OpenID_RP_RETURN_TO_URL_TYPE, + common_local_url($finish)); + } + //provider + $xrdsOutputter->showXrdsService('http://specs.openid.net/auth/2.0/server', + common_local_url('openidserver'), + null, + null, + 'http://specs.openid.net/auth/2.0/identifier_select'); + $xrdsOutputter->elementEnd('XRD'); + } + + function onEndUserXRDS($action, &$xrdsOutputter) + { + $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xml:id' => 'openid', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $xrdsOutputter->element('Type', null, 'xri://$xrds*simple'); + + //consumer + $xrdsOutputter->showXrdsService('http://specs.openid.net/auth/2.0/return_to', + common_local_url('finishopenidlogin')); + + //provider + $xrdsOutputter->showXrdsService('http://specs.openid.net/auth/2.0/signon', + common_local_url('openidserver'), + null, + null, + common_profile_url($action->user->nickname)); + $xrdsOutputter->elementEnd('XRD'); + } + function onEndLoginGroupNav(&$action) { $action_name = $action->trimmed('action'); @@ -107,6 +149,7 @@ class OpenIDPlugin extends Plugin case 'XrdsAction': case 'PublicxrdsAction': case 'OpenidsettingsAction': + case 'OpenidserverAction': require_once(INSTALLDIR.'/plugins/OpenID/' . strtolower(mb_substr($cls, 0, -6)) . '.php'); return false; case 'User_openid': @@ -152,12 +195,16 @@ class OpenIDPlugin extends Plugin function onEndShowHeadElements($action) { - if ($action->trimmed('action') == 'public') { - // for client side of OpenID authentication - $action->element('meta', array('http-equiv' => 'X-XRDS-Location', - 'content' => common_local_url('publicxrds'))); + if($action instanceof ShowstreamAction){ + $action->element('link', array('rel' => 'openid2.provider', + 'href' => common_local_url('openidserver'))); + $action->element('link', array('rel' => 'openid2.local_id', + 'href' => $action->profile->profileurl)); + $action->element('link', array('rel' => 'openid.server', + 'href' => common_local_url('openidserver'))); + $action->element('link', array('rel' => 'openid.delegate', + 'href' => $action->profile->profileurl)); } - return true; } diff --git a/plugins/OpenID/openid.php b/plugins/OpenID/openid.php index b76497c28a..ff7a938994 100644 --- a/plugins/OpenID/openid.php +++ b/plugins/OpenID/openid.php @@ -23,6 +23,7 @@ require_once(INSTALLDIR.'/plugins/OpenID/User_openid.php'); require_once('Auth/OpenID.php'); require_once('Auth/OpenID/Consumer.php'); +require_once('Auth/OpenID/Server.php'); require_once('Auth/OpenID/SReg.php'); require_once('Auth/OpenID/MySQLStore.php'); @@ -50,6 +51,13 @@ function oid_consumer() return $consumer; } +function oid_server() +{ + $store = oid_store(); + $server = new Auth_OpenID_Server($store, common_local_url('openidserver')); + return $server; +} + function oid_clear_last() { oid_set_last(''); diff --git a/plugins/OpenID/openidserver.php b/plugins/OpenID/openidserver.php new file mode 100644 index 0000000000..198a1a3280 --- /dev/null +++ b/plugins/OpenID/openidserver.php @@ -0,0 +1,96 @@ +. + * + * @category Settings + * @package StatusNet + * @author Craig Andrews + * @copyright 2008-2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/action.php'; +require_once INSTALLDIR.'/plugins/OpenID/openid.php'; + +/** + * Settings for OpenID + * + * Lets users add, edit and delete OpenIDs from their account + * + * @category Settings + * @package StatusNet + * @author Craig Andrews + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class OpenidserverAction extends Action +{ + + function handle($args) + { + parent::handle($args); + $oserver = oid_server(); + $request = $oserver->decodeRequest(); + if (in_array($request->mode, array('checkid_immediate', + 'checkid_setup'))) { + $cur = common_current_user(); + error_log("Request identity: " . $request->identity); + if(!$cur){ + /* Go log in, and then come back. */ + common_set_returnto($_SERVER['REQUEST_URI']); + common_redirect(common_local_url('login')); + return; + }else if(common_profile_url($cur->nickname) == $request->identity || $request->idSelect()){ + $response = &$request->answer(true, null, common_profile_url($cur->nickname)); + } else if ($request->immediate) { + $response = &$request->answer(false); + } else { + //invalid + $this->clientError(sprintf(_('You are not authorized to use the identity %s'),$request->identity),$code=403); + } + } else { + $response = &$oserver->handleRequest($request); + } + + if($response){ + $webresponse = $oserver->encodeResponse($response); + + if ($webresponse->code != AUTH_OPENID_HTTP_OK) { + header(sprintf("HTTP/1.1 %d ", $webresponse->code), + true, $webresponse->code); + } + + if($webresponse->headers){ + foreach ($webresponse->headers as $k => $v) { + header("$k: $v"); + } + } + $this->raw($webresponse->body); + }else{ + $this->clientError(_('Just an OpenID provider. Nothing to see here, move along...'),$code=500); + } + } +} From c49564647a081ff5a82defa197b796306a7a064e Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 29 Oct 2009 16:26:56 -0400 Subject: [PATCH 03/41] whitespace adjustments for doxygen --- lib/xrdsoutputter.php | 1 - plugins/OpenID/openidserver.php | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/xrdsoutputter.php b/lib/xrdsoutputter.php index 0e228e2937..4b77ed5a3a 100644 --- a/lib/xrdsoutputter.php +++ b/lib/xrdsoutputter.php @@ -45,7 +45,6 @@ require_once INSTALLDIR.'/lib/xmloutputter.php'; * @see Action * @see XMLOutputter */ - class XRDSOutputter extends XMLOutputter { public function startXRDS() diff --git a/plugins/OpenID/openidserver.php b/plugins/OpenID/openidserver.php index 198a1a3280..a6b18608d7 100644 --- a/plugins/OpenID/openidserver.php +++ b/plugins/OpenID/openidserver.php @@ -45,7 +45,6 @@ require_once INSTALLDIR.'/plugins/OpenID/openid.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ - class OpenidserverAction extends Action { From d5951ebce69b9b98d0425b7c7aabc2061d6b9ea8 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 30 Oct 2009 10:02:37 +1300 Subject: [PATCH 04/41] Revert "give some suggestions back to the user when no config file found, and a link to the installer" This reverts commit 7f5fbee2e36889fae1d1c5043d76625e197e39ea. --- lib/common.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/common.php b/lib/common.php index 667826f395..e29456ed4e 100644 --- a/lib/common.php +++ b/lib/common.php @@ -185,14 +185,7 @@ function _have_config() } // XXX: Throw a conniption if database not installed -// XXX: Find a way to use htmlwriter for this instead of handcoded markup -if (!_have_config()) { - echo '

'. _('No configuation file found. ') .'

'; - echo '

'. _('I looked for configuration files in the following places: ') .'
'. implode($_config_files, '
'); - echo '

'. _('You make wish run the installer to fix this.') .'

'; - echo ''. _('Go to the installer.') .''; - exit; -} + // Fixup for statusnet.ini $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1); From f1daca16e2f34cce7d25cb1dbe144fc027fcc1fd Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 30 Oct 2009 10:03:25 +1300 Subject: [PATCH 05/41] give some suggestions back to the user when no config file found, and a link to the installer --- lib/common.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/common.php b/lib/common.php index e29456ed4e..2c2f6869ee 100644 --- a/lib/common.php +++ b/lib/common.php @@ -185,7 +185,14 @@ function _have_config() } // XXX: Throw a conniption if database not installed - +// XXX: Find a way to use htmlwriter for this instead of handcoded markup +if (!_have_config()) { + echo '

'. _('No configuation file found. ') .'

'; + echo '

'. _('I looked for configuration files in the following places: ') .'
'. implode($_config_files, '
'); + echo '

'. _('You may wish to run the installer to fix this.') .'

'; + echo ''. _('Go to the installer.') .''; + exit; +} // Fixup for statusnet.ini $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1); From 35ace5562d999532d799f4d5153b7b3c347042a0 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 29 Oct 2009 19:09:42 -0400 Subject: [PATCH 06/41] Fix feed links which were broken when the API was restructured --- actions/all.php | 14 ++++++-------- actions/public.php | 10 ++++------ actions/replies.php | 24 +++++++++++++++++++----- actions/showfavorites.php | 26 +++++++++++++++++++------- actions/showgroup.php | 14 ++++++-------- actions/showstream.php | 16 ++++++++-------- actions/tag.php | 16 +++++++--------- 7 files changed, 69 insertions(+), 51 deletions(-) diff --git a/actions/all.php b/actions/all.php index f1786462e1..61cedce749 100644 --- a/actions/all.php +++ b/actions/all.php @@ -99,19 +99,17 @@ class AllAction extends ProfileAction sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)), new Feed(Feed::RSS2, common_local_url( - 'api', array( - 'apiaction' => 'statuses', - 'method' => 'friends_timeline', - 'argument' => $this->user->nickname.'.rss' + 'ApiTimelineFriends', array( + 'format' => 'rss', + 'id' => $this->user->nickname ) ), sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)), new Feed(Feed::ATOM, common_local_url( - 'api', array( - 'apiaction' => 'statuses', - 'method' => 'friends_timeline', - 'argument' => $this->user->nickname.'.atom' + 'ApiTimelineFriends', array( + 'format' => 'atom', + 'id' => $this->user->nickname ) ), sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname)) diff --git a/actions/public.php b/actions/public.php index 4b71e58532..982dfde157 100644 --- a/actions/public.php +++ b/actions/public.php @@ -150,14 +150,12 @@ class PublicAction extends Action return array(new Feed(Feed::RSS1, common_local_url('publicrss'), _('Public Stream Feed (RSS 1.0)')), new Feed(Feed::RSS2, - common_local_url('api', - array('apiaction' => 'statuses', - 'method' => 'public_timeline.rss')), + common_local_url('ApiTimelinePublic', + array('format' => 'rss')), _('Public Stream Feed (RSS 2.0)')), new Feed(Feed::ATOM, - common_local_url('api', - array('apiaction' => 'statuses', - 'method' => 'public_timeline.atom')), + common_local_url('ApiTimelinePublic', + array('format' => 'atom')), _('Public Stream Feed (Atom)'))); } diff --git a/actions/replies.php b/actions/replies.php index 6003ad30bd..a13b5a2273 100644 --- a/actions/replies.php +++ b/actions/replies.php @@ -138,11 +138,25 @@ class RepliesAction extends OwnerDesignAction function getFeeds() { - $rssurl = common_local_url('repliesrss', - array('nickname' => $this->user->nickname)); - $rsstitle = sprintf(_('Feed for replies to %s'), $this->user->nickname); - - return array(new Feed(Feed::RSS1, $rssurl, $rsstitle)); + return array(new Feed(Feed::RSS1, + common_local_url('repliesrss', + array('nickname' => $this->user->nickname)), + sprintf(_('Replies feed for %s (RSS 1.0)'), + $this->user->nickname)), + new Feed(Feed::RSS2, + common_local_url('ApiTimelineMentions', + array( + 'id' => $this->user->nickname, + 'format' => 'rss')), + sprintf(_('Replies feed for %s (RSS 2.0)'), + $this->user->nickname)), + new Feed(Feed::ATOM, + common_local_url('ApiTimelineMentions', + array( + 'id' => $this->user->nickname, + 'format' => 'atom')), + sprintf(_('Replies feed for %s (Atom)'), + $this->user->nickname))); } /** diff --git a/actions/showfavorites.php b/actions/showfavorites.php index b96d2af37f..b12fcdd9a0 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -164,13 +164,25 @@ class ShowfavoritesAction extends OwnerDesignAction function getFeeds() { - $feedurl = common_local_url('favoritesrss', - array('nickname' => - $this->user->nickname)); - $feedtitle = sprintf(_('Feed for favorites of %s'), - $this->user->nickname); - - return array(new Feed(Feed::RSS1, $feedurl, $feedtitle)); + return array(new Feed(Feed::RSS1, + common_local_url('favoritesrss', + array('nickname' => $this->user->nickname)), + sprintf(_('Feed for favorites of %s (RSS 1.0)'), + $this->user->nickname)), + new Feed(Feed::RSS2, + common_local_url('ApiTimelineFavorites', + array( + 'id' => $this->user->nickname, + 'format' => 'rss')), + sprintf(_('Feed for favorites of %s (RSS 2.0)'), + $this->user->nickname)), + new Feed(Feed::ATOM, + common_local_url('ApiTimelineFavorites', + array( + 'id' => $this->user->nickname, + 'format' => 'atom')), + sprintf(_('Feed for favorites of %s (Atom)'), + $this->user->nickname))); } /** diff --git a/actions/showgroup.php b/actions/showgroup.php index bfe45ddad7..a4af29391d 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -328,17 +328,15 @@ class ShowgroupAction extends GroupDesignAction sprintf(_('Notice feed for %s group (RSS 1.0)'), $this->group->nickname)), new Feed(Feed::RSS2, - common_local_url('api', - array('apiaction' => 'groups', - 'method' => 'timeline', - 'argument' => $this->group->nickname.'.rss')), + common_local_url('ApiTimelineGroup', + array('format' => 'rss', + 'id' => $this->group->nickname)), sprintf(_('Notice feed for %s group (RSS 2.0)'), $this->group->nickname)), new Feed(Feed::ATOM, - common_local_url('api', - array('apiaction' => 'groups', - 'method' => 'timeline', - 'argument' => $this->group->nickname.'.atom')), + common_local_url('ApiTimelineGroup', + array('format' => 'atom', + 'id' => $this->group->nickname)), sprintf(_('Notice feed for %s group (Atom)'), $this->group->nickname)), new Feed(Feed::FOAF, diff --git a/actions/showstream.php b/actions/showstream.php index de7100b1dc..4f48060378 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -128,17 +128,17 @@ class ShowstreamAction extends ProfileAction sprintf(_('Notice feed for %s (RSS 1.0)'), $this->user->nickname)), new Feed(Feed::RSS2, - common_local_url('api', - array('apiaction' => 'statuses', - 'method' => 'user_timeline', - 'argument' => $this->user->nickname.'.rss')), + common_local_url('ApiTimelineUser', + array( + 'id' => $this->user->nickname, + 'format' => 'rss')), sprintf(_('Notice feed for %s (RSS 2.0)'), $this->user->nickname)), new Feed(Feed::ATOM, - common_local_url('api', - array('apiaction' => 'statuses', - 'method' => 'user_timeline', - 'argument' => $this->user->nickname.'.atom')), + common_local_url('ApiTimelineUser', + array( + 'id' => $this->user->nickname, + 'format' => 'atom')), sprintf(_('Notice feed for %s (Atom)'), $this->user->nickname)), new Feed(Feed::FOAF, diff --git a/actions/tag.php b/actions/tag.php index f0ab30308c..3a88c1229d 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -86,17 +86,15 @@ class TagAction extends Action sprintf(_('Notice feed for tag %s (RSS 1.0)'), $this->tag)), new Feed(Feed::RSS2, - common_local_url('api', - array('apiaction' => 'tags', - 'method' => 'timeline', - 'argument' => $this->tag.'.rss')), - sprintf(_('Notice feed for %s group (RSS 2.0)'), + common_local_url('ApiTimelineTag', + array('format' => 'rss', + 'tag' => $this->tag)), + sprintf(_('Notice feed for tag %s (RSS 2.0)'), $this->tag)), new Feed(Feed::ATOM, - common_local_url('api', - array('apiaction' => 'tags', - 'method' => 'timeline', - 'argument' => $this->tag.'.atom')), + common_local_url('ApiTimelineTag', + array('format' => 'atom', + 'tag' => $this->tag)), sprintf(_('Notice feed for tag %s (Atom)'), $this->tag))); } From 656eef6e6abb1eb89a0cf2f0adf81057c017ee50 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 01:20:47 -0400 Subject: [PATCH 07/41] Fixed PubSubHubBub plugin to reflect new api --- plugins/PubSubHubBub/PubSubHubBubPlugin.php | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/plugins/PubSubHubBub/PubSubHubBubPlugin.php b/plugins/PubSubHubBub/PubSubHubBubPlugin.php index e1e82e352c..d15a869cba 100644 --- a/plugins/PubSubHubBub/PubSubHubBubPlugin.php +++ b/plugins/PubSubHubBub/PubSubHubBubPlugin.php @@ -65,21 +65,21 @@ class PubSubHubBubPlugin extends Plugin $feeds = array(); //public timeline feeds - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'public_timeline.rss')); - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'public_timeline.atom')); + $feeds[]=common_local_url('ApiTimelinePublic',array('format' => 'rss')); + $feeds[]=common_local_url('ApiTimelinePublic',array('format' => 'atom')); //author's own feeds $user = User::staticGet('id',$notice->profile_id); - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.rss')); - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.atom')); + $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'rss')); + $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'atom')); //tag feeds $tag = new Notice_tag(); $tag->notice_id = $notice->id; if ($tag->find()) { while ($tag->fetch()) { - $feeds[]=common_local_url('api',array('apiaction' => 'tags','method' => 'timeline', 'argument'=>$tag->tag.'.atom')); - $feeds[]=common_local_url('api',array('apiaction' => 'tags','method' => 'timeline', 'argument'=>$tag->tag.'.rss')); + $feeds[]=common_local_url('ApiTimelineTag',array('tag'=>$tag->tag, 'format'=>'rss')); + $feeds[]=common_local_url('ApiTimelineTag',array('tag'=>$tag->tag, 'format'=>'atom')); } } @@ -89,8 +89,8 @@ class PubSubHubBubPlugin extends Plugin if ($group_inbox->find()) { while ($group_inbox->fetch()) { $group = User_group::staticGet('id',$group_inbox->group_id); - $feeds[]=common_local_url('api',array('apiaction' => 'groups','method' => 'timeline','argument' => $group->nickname.'.rss')); - $feeds[]=common_local_url('api',array('apiaction' => 'groups','method' => 'timeline','argument' => $group->nickname.'.atom')); + $feeds[]=common_local_url('ApiTimelineGroup',array('id' => $group->nickname,'format'=>'rss')); + $feeds[]=common_local_url('ApiTimelineGroup',array('id' => $group->nickname,'format'=>'atom')); } } @@ -100,18 +100,17 @@ class PubSubHubBubPlugin extends Plugin if ($notice_inbox->find()) { while ($notice_inbox->fetch()) { $user = User::staticGet('id',$notice_inbox->user_id); - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.rss')); - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.atom')); + $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'rss')); + $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'atom')); } } - /* TODO: when the reply page gets RSS and ATOM feeds, implement this //feed of user replied to if($notice->reply_to){ $user = User::staticGet('id',$notice->reply_to); - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.rss')); - $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.atom')); - }*/ + $feeds[]=common_local_url('ApiTimelineMentions',array('id' => $user->nickname,'format'=>'rss')); + $feeds[]=common_local_url('ApiTimelineMentions',array('id' => $user->nickname,'format'=>'atom')); + } foreach(array_unique($feeds) as $feed){ if(! $publisher->publish_update($feed)){ From 005f85b5eaace14a1303eb51fb216e6d77696244 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 01:25:52 -0400 Subject: [PATCH 08/41] Removed reference to 'api' action which no longer exists since api refactor --- classes/Notice.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index c08a66790f..a9dbaa461b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1181,10 +1181,9 @@ class Notice extends Memcached_DataObject $xs->element('link', array('href' => $profile->profileurl)); $user = User::staticGet('id', $profile->id); if (!empty($user)) { - $atom_feed = common_local_url('api', - array('apiaction' => 'statuses', - 'method' => 'user_timeline', - 'argument' => $profile->nickname.'.atom')); + $atom_feed = common_local_url('ApiTimelineUser', + array('format' => 'atom', + 'id' => $profile->nickname)); $xs->element('link', array('rel' => 'self', 'type' => 'application/atom+xml', 'href' => $profile->profileurl)); From 02131db1c976831241b61e205ccda9e3232c4fe2 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 01:30:42 -0400 Subject: [PATCH 09/41] Bump to Auth_OpenID 2.1.3 --- extlib/Auth/OpenID.php | 2 +- extlib/Auth/OpenID/BigMath.php | 2 +- extlib/Auth/OpenID/Consumer.php | 3 ++- extlib/Auth/OpenID/Message.php | 5 +++++ extlib/Auth/Yadis/HTTPFetcher.php | 2 +- extlib/Auth/Yadis/ParanoidHTTPFetcher.php | 2 -- extlib/Auth/Yadis/PlainHTTPFetcher.php | 2 -- extlib/Auth/Yadis/XML.php | 4 ++-- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/extlib/Auth/OpenID.php b/extlib/Auth/OpenID.php index 6556b5b01e..db6164256f 100644 --- a/extlib/Auth/OpenID.php +++ b/extlib/Auth/OpenID.php @@ -20,7 +20,7 @@ /** * The library version string */ -define('Auth_OpenID_VERSION', '2.1.2'); +define('Auth_OpenID_VERSION', '2.1.3'); /** * Require the fetcher code. diff --git a/extlib/Auth/OpenID/BigMath.php b/extlib/Auth/OpenID/BigMath.php index b5fc627a09..45104947d6 100644 --- a/extlib/Auth/OpenID/BigMath.php +++ b/extlib/Auth/OpenID/BigMath.php @@ -376,7 +376,7 @@ function Auth_OpenID_detectMathLibrary($exts) // Try to load dynamic modules. if (!$loaded) { foreach ($extension['modules'] as $module) { - if (function_exists('dl') && ini_get('enable_dl') && !ini_get('safe_mode') && @dl($module . "." . PHP_SHLIB_SUFFIX)) { + if (@dl($module . "." . PHP_SHLIB_SUFFIX)) { $loaded = true; break; } diff --git a/extlib/Auth/OpenID/Consumer.php b/extlib/Auth/OpenID/Consumer.php index a72684c6b8..500890b656 100644 --- a/extlib/Auth/OpenID/Consumer.php +++ b/extlib/Auth/OpenID/Consumer.php @@ -1295,7 +1295,8 @@ class Auth_OpenID_GenericConsumer { Auth_OpenID_OPENID2_NS => array_merge($basic_sig_fields, array('response_nonce', 'claimed_id', - 'assoc_handle')), + 'assoc_handle', + 'op_endpoint')), Auth_OpenID_OPENID1_NS => array_merge($basic_sig_fields, array('nonce')) ); diff --git a/extlib/Auth/OpenID/Message.php b/extlib/Auth/OpenID/Message.php index fd23e67a3c..5ab115a86e 100644 --- a/extlib/Auth/OpenID/Message.php +++ b/extlib/Auth/OpenID/Message.php @@ -887,6 +887,11 @@ class Auth_OpenID_Message { function getAliasedArg($aliased_key, $default = null) { + if ($aliased_key == 'ns') { + // Return the namespace URI for the OpenID namespace + return $this->getOpenIDNamespace(); + } + $parts = explode('.', $aliased_key, 2); if (count($parts) != 2) { diff --git a/extlib/Auth/Yadis/HTTPFetcher.php b/extlib/Auth/Yadis/HTTPFetcher.php index a1825403d6..963b9a49a4 100644 --- a/extlib/Auth/Yadis/HTTPFetcher.php +++ b/extlib/Auth/Yadis/HTTPFetcher.php @@ -138,7 +138,7 @@ class Auth_Yadis_HTTPFetcher { * pass the URLHasAllowedScheme check or if the server's response * is malformed. */ - function get($url, $headers) + function get($url, $headers = null) { trigger_error("not implemented", E_USER_ERROR); } diff --git a/extlib/Auth/Yadis/ParanoidHTTPFetcher.php b/extlib/Auth/Yadis/ParanoidHTTPFetcher.php index 8975d7f89e..6a418260ee 100644 --- a/extlib/Auth/Yadis/ParanoidHTTPFetcher.php +++ b/extlib/Auth/Yadis/ParanoidHTTPFetcher.php @@ -127,8 +127,6 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { Auth_OpenID_USER_AGENT.' '.$curl_user_agent); curl_setopt($c, CURLOPT_TIMEOUT, $off); curl_setopt($c, CURLOPT_URL, $url); - curl_setopt($c, CURLOPT_RANGE, - "0-".(1024 * Auth_OpenID_FETCHER_MAX_RESPONSE_KB)); curl_exec($c); diff --git a/extlib/Auth/Yadis/PlainHTTPFetcher.php b/extlib/Auth/Yadis/PlainHTTPFetcher.php index 8882e3cef7..3e0ca2bb0c 100644 --- a/extlib/Auth/Yadis/PlainHTTPFetcher.php +++ b/extlib/Auth/Yadis/PlainHTTPFetcher.php @@ -83,8 +83,6 @@ class Auth_Yadis_PlainHTTPFetcher extends Auth_Yadis_HTTPFetcher { "User-Agent: $user_agent", "Host: ".$parts['host']. ($specify_port ? ":".$parts['port'] : ""), - "Range: 0-". - (1024*Auth_OpenID_FETCHER_MAX_RESPONSE_KB), "Port: ".$parts['port']); $errno = 0; diff --git a/extlib/Auth/Yadis/XML.php b/extlib/Auth/Yadis/XML.php index 7232d6cbdd..81b2ce2210 100644 --- a/extlib/Auth/Yadis/XML.php +++ b/extlib/Auth/Yadis/XML.php @@ -91,7 +91,7 @@ class Auth_Yadis_XMLParser { * @return array $node_list An array of matching opaque node * objects to be used with other methods of this parser class. */ - function evalXPath($xpath, $node = null) + function &evalXPath($xpath, $node = null) { // Not implemented. } @@ -349,7 +349,7 @@ function &Auth_Yadis_getXMLParser() foreach ($extensions as $name => $params) { if (!extension_loaded($name)) { foreach ($params['libname'] as $libname) { - if (function_exists('dl') && ini_get('enable_dl') && !ini_get('safe_mode') && @dl($libname)) { + if (@dl($libname)) { $classname = $params['classname']; } } From 54c64a0cf1160db174934799750d7eec83f4f433 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 30 Oct 2009 18:53:45 +1300 Subject: [PATCH 10/41] don't write the closing ?> to the config.php --- install.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/install.php b/install.php index 319c261e41..6bfc4c2e21 100644 --- a/install.php +++ b/install.php @@ -692,9 +692,7 @@ function writeConf($sitename, $server, $path, $fancy, $db) // database "\$config['db']['database'] = '{$db['database']}';\n\n". ($db['type'] == 'pgsql' ? "\$config['db']['quote_identifiers'] = true;\n\n":''). - "\$config['db']['type'] = '{$db['type']}';\n\n". - - "?>"; + "\$config['db']['type'] = '{$db['type']}';\n\n"; // write configuration file out to install directory $res = file_put_contents(INSTALLDIR.'/config.php', $cfg); From a12133258ad685523e2ce793e6599861c64ee225 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 12:40:08 +0100 Subject: [PATCH 11/41] Refactored XHR forms: .form_user_subscribe .form_user_unsubscribe .form_favor .form_disfavor .form_group_join .form_group_leave .form_user_nudge Using FormXHR() --- js/util.js | 152 ++++++++++++++++++----------------------------------- 1 file changed, 50 insertions(+), 102 deletions(-) diff --git a/js/util.js b/js/util.js index b079388e47..0605100271 100644 --- a/js/util.js +++ b/js/util.js @@ -89,52 +89,6 @@ $(document).ready(function(){ } } - // XXX: refactor this code - - var favoptions = { dataType: 'xml', - beforeSubmit: function(data, target, options) { - $(target).addClass('processing'); - return true; - }, - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var dis = new_form.id; - var fav = dis.replace('disfavor', 'favor'); - $('form#'+fav).replaceWith(new_form); - $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden); - } - }; - - var disoptions = { dataType: 'xml', - beforeSubmit: function(data, target, options) { - $(target).addClass('processing'); - return true; - }, - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var fav = new_form.id; - var dis = fav.replace('favor', 'disfavor'); - $('form#'+dis).replaceWith(new_form); - $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden); - } - }; - - var joinoptions = { dataType: 'xml', - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var leave = new_form.id; - var join = leave.replace('leave', 'join'); - $('form#'+join).replaceWith(new_form); - $('form#'+leave).ajaxForm(leaveoptions).each(addAjaxHidden); - } - }; - - var leaveoptions = { dataType: 'xml', - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var join = new_form.id; - var leave = join.replace('join', 'leave'); - $('form#'+leave).replaceWith(new_form); - $('form#'+join).ajaxForm(joinoptions).each(addAjaxHidden); - } - }; - function addAjaxHidden() { var ajax = document.createElement('input'); ajax.setAttribute('type', 'hidden'); @@ -143,62 +97,13 @@ $(document).ready(function(){ this.appendChild(ajax); } - $("form.form_favor").ajaxForm(favoptions); - $("form.form_disfavor").ajaxForm(disoptions); - $("form.form_group_join").ajaxForm(joinoptions); - $("form.form_group_leave").ajaxForm(leaveoptions); - $("form.form_favor").each(addAjaxHidden); - $("form.form_disfavor").each(addAjaxHidden); - $("form.form_group_join").each(addAjaxHidden); - $("form.form_group_leave").each(addAjaxHidden); - - $("#form_user_nudge").ajaxForm ({ dataType: 'xml', - beforeSubmit: function(xml) { $("#form_user_nudge input[type=submit]").attr("disabled", "disabled"); - $("#form_user_nudge input[type=submit]").addClass("disabled"); - }, - success: function(xml) { $("#form_user_nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true)); - $("#form_user_nudge input[type=submit]").removeAttr("disabled"); - $("#form_user_nudge input[type=submit]").removeClass("disabled"); - } - }); - $("#form_user_nudge").each(addAjaxHidden); - - var Subscribe = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { $(".form_user_subscribe input[type=submit]").attr("disabled", "disabled"); - $(".form_user_subscribe input[type=submit]").addClass("disabled"); - }, - success: function(xml) { var form_unsubscribe = document._importNode($('form', xml).get(0), true); - var form_unsubscribe_id = form_unsubscribe.id; - var form_subscribe_id = form_unsubscribe_id.replace('unsubscribe', 'subscribe'); - $("form#"+form_subscribe_id).replaceWith(form_unsubscribe); - $("form#"+form_unsubscribe_id).ajaxForm(UnSubscribe).each(addAjaxHidden); - $("dd.subscribers").text(parseInt($("dd.subscribers").text())+1); - $(".form_user_subscribe input[type=submit]").removeAttr("disabled"); - $(".form_user_subscribe input[type=submit]").removeClass("disabled"); - } - }; - - var UnSubscribe = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { $(".form_user_unsubscribe input[type=submit]").attr("disabled", "disabled"); - $(".form_user_unsubscribe input[type=submit]").addClass("disabled"); - }, - success: function(xml) { var form_subscribe = document._importNode($('form', xml).get(0), true); - var form_subscribe_id = form_subscribe.id; - var form_unsubscribe_id = form_subscribe_id.replace('subscribe', 'unsubscribe'); - $("form#"+form_unsubscribe_id).replaceWith(form_subscribe); - $("form#"+form_subscribe_id).ajaxForm(Subscribe).each(addAjaxHidden); - $("#profile_send_a_new_message").remove(); - $("#profile_nudge").remove(); - $("dd.subscribers").text(parseInt($("dd.subscribers").text())-1); - $(".form_user_unsubscribe input[type=submit]").removeAttr("disabled"); - $(".form_user_unsubscribe input[type=submit]").removeClass("disabled"); - } - }; - - $(".form_user_subscribe").ajaxForm(Subscribe); - $(".form_user_unsubscribe").ajaxForm(UnSubscribe); - $(".form_user_subscribe").each(addAjaxHidden); - $(".form_user_unsubscribe").each(addAjaxHidden); + $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_join').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); var PostNotice = { dataType: 'xml', beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) { @@ -384,3 +289,46 @@ function NoticeDataAttach() { }); }); } + +var SN = { // StatusNet + C: { // Config + S: { // Selector + Disabled: 'disabled', + Warning: 'warning', + Error: 'error', + Processing: 'processing' + } + }, + + U: { // Utils + FormXHR: function(f) { + f.bind('submit', function(e) { + form_id = $(this)[0].id; + $.ajax({ + type: 'POST', + url: $(this)[0].action, + data: $(this).serialize() + '&ajax=1', + beforeSend: function(xhr) { + $('#'+form_id).addClass(SN.C.S.Processing); + $('#'+form_id+' .submit').addClass(SN.C.S.Disabled); + $('#'+form_id+' .submit').attr(SN.C.S.Disabled, SN.C.S.Disabled); + }, + error: function (xhr, textStatus, errorThrown) { + alert(errorThrown || textStatus); + }, + success: function(data, textStatus) { + if ($('form', data)[0].length > 0) { + form_new = $('form', data)[0]; + $('#'+form_id).replaceWith(document._importNode(form_new, true)); + $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); + } + else { + $('#'+form_id).replaceWith(document._importNode($('p', data)[0], true)); + } + } + }); + return false; + }); + } + } +} From 5a48a387fc20c5fbc1fb930e39fdbc5cf0862fbd Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 13:15:11 +0100 Subject: [PATCH 12/41] Updated form_notice --- js/util.js | 191 +++++++++++++++++++++++++++-------------------------- 1 file changed, 98 insertions(+), 93 deletions(-) diff --git a/js/util.js b/js/util.js index 0605100271..77fbc1ee9f 100644 --- a/js/util.js +++ b/js/util.js @@ -89,14 +89,6 @@ $(document).ready(function(){ } } - function addAjaxHidden() { - var ajax = document.createElement('input'); - ajax.setAttribute('type', 'hidden'); - ajax.setAttribute('name', 'ajax'); - ajax.setAttribute('value', 1); - this.appendChild(ajax); - } - $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); @@ -105,90 +97,8 @@ $(document).ready(function(){ $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - var PostNotice = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) { - $("#form_notice").addClass("warning"); - return false; - } - $("#form_notice").addClass("processing"); - $("#notice_action-submit").attr("disabled", "disabled"); - $("#notice_action-submit").addClass("disabled"); - return true; - }, - timeout: '60000', - error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing"); - $("#notice_action-submit").removeAttr("disabled"); - $("#notice_action-submit").removeClass("disabled"); - if (textStatus == "timeout") { - alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists"); - } - else { - if ($(".error", xhr.responseXML).length > 0) { - $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true)); - } - else { - var HTTP20x30x = [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]; - if(jQuery.inArray(parseInt(xhr.status), HTTP20x30x) < 0) { - alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again."); - } - else { - $("#notice_data-text").val(""); - if (maxLength > 0) { - counter(); - } - } - } - } - }, - success: function(xml) { if ($("#error", xml).length > 0) { - var result = document._importNode($("p", xml).get(0), true); - result = result.textContent || result.innerHTML; - alert(result); - } - else { - if($('body')[0].id == 'bookmarklet') { - self.close(); - } - if ($("#command_result", xml).length > 0) { - var result = document._importNode($("p", xml).get(0), true); - result = result.textContent || result.innerHTML; - alert(result); - } - else { - li = $("li", xml).get(0); - if ($("#"+li.id).length == 0) { - var notice_irt_value = $('#notice_in-reply-to').val(); - var notice_irt = '#notices_primary #notice-'+notice_irt_value; - if($('body')[0].id == 'conversation') { - if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) { - $(notice_irt).append('
    '); - } - $($(notice_irt+' .notices')[0]).append(document._importNode(li, true)); - } - else { - $("#notices_primary .notices").prepend(document._importNode(li, true)); - } - $('#'+li.id).css({display:'none'}); - $('#'+li.id).fadeIn(2500); - NoticeReply(); - NoticeAttachments(); - } - } - $("#notice_data-text").val(""); - $("#notice_data-attach").val(""); - $("#notice_in-reply-to").val(""); - $('#notice_data-attach_selected').remove(); - if (maxLength > 0) { - counter(); - } - } - $("#form_notice").removeClass("processing"); - $("#notice_action-submit").removeAttr("disabled"); - $("#notice_action-submit").removeClass("disabled"); - } - }; - $("#form_notice").ajaxForm(PostNotice); - $("#form_notice").each(addAjaxHidden); + SN.U.FormNoticeXHR(); + NoticeReply(); NoticeAttachments(); NoticeDataAttach(); @@ -292,11 +202,23 @@ function NoticeDataAttach() { var SN = { // StatusNet C: { // Config + I: { + NoticeTextCharMax: 140, + PatternUsername: /^[0-9a-zA-Z\-_.]*$/, + HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307] + }, S: { // Selector Disabled: 'disabled', Warning: 'warning', Error: 'error', - Processing: 'processing' + Processing: 'processing', + CommendResult: 'command_result', + FormNotice: 'form_notice', + NoticeDataText: 'notice_data-text', + NoticeTextCount: 'notice_text-count', + NoticeInReplyTo: 'notice_in-reply-to', + NoticeDataAttach: 'notice_data-attach', + NoticeActionSubmit: 'notice_action-submit' } }, @@ -329,6 +251,89 @@ var SN = { // StatusNet }); return false; }); + }, + + FormNoticeXHR: function() { + $('#'+SN.C.S.FormNotice).append(''); + $('#'+SN.C.S.FormNotice).ajaxForm({ + timeout: '60000', + beforeSend: function(xhr) { + if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { + $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + return false; + } + $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Processing); + $('#'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled); + $('#'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled); + return true; + }, + error: function (xhr, textStatus, errorThrown) { + $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); + $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled); + if (textStatus == 'timeout') { + alert ('Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists'); + } + else { + if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) { + $('#'+SN.C.S.FormNotice).append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true)); + } + else { + if(jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) < 0) { + alert('Sorry! We had trouble sending your notice ('+xhr.status+' '+xhr.statusText+'). Please report the problem to the site administrator if this happens again.'); + } + else { + SN.C.I.NoticeDataText.val(''); +// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + } + } + } + }, + success: function(data, textStatus) { + if ($('#'+SN.C.S.Error, data).length > 0) { + var result = document._importNode($('p', data)[0], true); + alert(result.textContent || result.innerHTML); + } + else { + if($('body')[0].id == 'bookmarklet') { + self.close(); + } + if ($('#'+SN.C.S.CommandResult, data).length > 0) { + var result = document._importNode($('p', data)[0], true); + alert(result.textContent || result.innerHTML); + } + else { + notice = $('li', data)[0]; + if ($('#'+notice.id).length === 0) { + var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val(); + var notice_irt = '#notices_primary #notice-'+notice_irt_value; + if($('body')[0].id == 'conversation') { + if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) { + $(notice_irt).append('
      '); + } + $($(notice_irt+' .notices')[0]).append(document._importNode(notice, true)); + } + else { + $("#notices_primary .notices").prepend(document._importNode(notice, true)); + } + $('#'+notice.id).css({display:'none'}); + $('#'+notice.id).fadeIn(2500); +// SN.U.NoticeAttachments(); +// SN.U.NoticeReply(); + } + } + $('#'+SN.C.S.NoticeDataText).val(''); + $('#'+SN.C.S.NoticeDataAttach).val(''); + $('#'+SN.C.S.NoticeInReplyTo).val(''); +// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + } + }, + complete: function(xhr, textStatus) { + $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); + $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled); + $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + } + }); } } } From ad759b2bc81e3676cec61257c6080821b7569559 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 13:56:01 +0100 Subject: [PATCH 13/41] Updated NoticeReply and NoticeReplySet --- js/util.js | 65 +++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/js/util.js b/js/util.js index 77fbc1ee9f..9874d614cd 100644 --- a/js/util.js +++ b/js/util.js @@ -99,42 +99,12 @@ $(document).ready(function(){ SN.U.FormNoticeXHR(); - NoticeReply(); + SN.U.NoticeReply(); NoticeAttachments(); NoticeDataAttach(); }); -function NoticeReply() { - if ($('#notice_data-text').length > 0 && $('#content .notice_reply').length > 0) { - $('#content .notice').each(function() { - var notice = $(this)[0]; - $($('.notice_reply', notice)[0]).click(function() { - var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid'); - NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text()); - return false; - }); - }); - } -} -function NoticeReplySet(nick,id) { - rgx_username = /^[0-9a-zA-Z\-_.]*$/; - if (nick.match(rgx_username)) { - var text = $("#notice_data-text"); - if (text.length) { - replyto = "@" + nick + " "; - text.val(replyto + text.val().replace(RegExp(replyto, 'i'), '')); - $("#form_notice input#notice_in-reply-to").val(id); - if (text.get(0).setSelectionRange) { - var len = text.val().length; - text.get(0).setSelectionRange(len,len); - text.get(0).focus(); - } - return false; - } - } - return true; -} function NoticeAttachments() { $.fn.jOverlay.options = { @@ -319,7 +289,7 @@ var SN = { // StatusNet $('#'+notice.id).css({display:'none'}); $('#'+notice.id).fadeIn(2500); // SN.U.NoticeAttachments(); -// SN.U.NoticeReply(); + SN.U.NoticeReply(); } } $('#'+SN.C.S.NoticeDataText).val(''); @@ -334,6 +304,37 @@ var SN = { // StatusNet $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); } }); + }, + + NoticeReply: function() { + if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) { + $('#content .notice').each(function() { + var notice = $(this)[0]; + $($('.notice_reply', notice)[0]).click(function() { + var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid'); + SN.U.NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text()); + return false; + }); + }); + } + }, + + NoticeReplySet function(nick,id) { + if (nick.match(SN.C.I.PatternUsername)) { + var text = $('#'+SN.C.S.NoticeDataText); + if (text.length) { + replyto = '@' + nick + ' '; + text.val(replyto + text.val().replace(RegExp(replyto, 'i'), '')); + $('#'+SN.C.S.FormNotice+' input#'+SN.C.S.NoticeInReplyTo).val(id); + if (text.get(0).setSelectionRange) { + var len = text.val().length; + text.get(0).setSelectionRange(len,len); + text.get(0).focus(); + } + return false; + } + } + return true; } } } From 0e5cf9b3b4002d4da092633150e0faf35b166dcf Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 13:56:53 +0100 Subject: [PATCH 14/41] Missing : --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 9874d614cd..9182cb9f16 100644 --- a/js/util.js +++ b/js/util.js @@ -319,7 +319,7 @@ var SN = { // StatusNet } }, - NoticeReplySet function(nick,id) { + NoticeReplySet: function(nick,id) { if (nick.match(SN.C.I.PatternUsername)) { var text = $('#'+SN.C.S.NoticeDataText); if (text.length) { From b55b2fa7d0667a635fad06af793ed00683f188b1 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 14:02:51 +0100 Subject: [PATCH 15/41] Updated NoticeAttachments --- js/util.js | 103 +++++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/js/util.js b/js/util.js index 9182cb9f16..fcfc0b95ab 100644 --- a/js/util.js +++ b/js/util.js @@ -100,62 +100,12 @@ $(document).ready(function(){ SN.U.FormNoticeXHR(); SN.U.NoticeReply(); - NoticeAttachments(); + SN.U.NoticeAttachments(); NoticeDataAttach(); }); -function NoticeAttachments() { - $.fn.jOverlay.options = { - method : 'GET', - data : '', - url : '', - color : '#000', - opacity : '0.6', - zIndex : 99, - center : false, - imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif', - bgClickToClose : true, - success : function() { - $('#jOverlayContent').append(''); - $('#jOverlayContent button').click($.closeOverlay); - }, - timeout : 0, - autoHide : true, - css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'} - }; - - $('#content .notice a.attachment').click(function() { - $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); - return false; - }); - - var t; - $("body:not(#shownotice) #content .notice a.thumbnail").hover( - function() { - var anchor = $(this); - $("a.thumbnail").children('img').hide(); - anchor.closest(".entry-title").addClass('ov'); - - if (anchor.children('img').length == 0) { - t = setTimeout(function() { - $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { - anchor.append(data); - }); - }, 500); - } - else { - anchor.children('img').show(); - } - }, - function() { - clearTimeout(t); - $("a.thumbnail").children('img').hide(); - $(this).closest(".entry-title").removeClass('ov'); - } - ); -} function NoticeDataAttach() { NDA = $('#notice_data-attach'); @@ -335,6 +285,57 @@ var SN = { // StatusNet } } return true; + }, + + NoticeAttachments: function() { + $.fn.jOverlay.options = { + method : 'GET', + data : '', + url : '', + color : '#000', + opacity : '0.6', + zIndex : 99, + center : false, + imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif', + bgClickToClose : true, + success : function() { + $('#jOverlayContent').append(''); + $('#jOverlayContent button').click($.closeOverlay); + }, + timeout : 0, + autoHide : true, + css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'} + }; + + $('#content .notice a.attachment').click(function() { + $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); + return false; + }); + + var t; + $("body:not(#shownotice) #content .notice a.thumbnail").hover( + function() { + var anchor = $(this); + $("a.thumbnail").children('img').hide(); + anchor.closest(".entry-title").addClass('ov'); + + if (anchor.children('img').length == 0) { + t = setTimeout(function() { + $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { + anchor.append(data); + }); + }, 500); + } + else { + anchor.children('img').show(); + } + }, + function() { + clearTimeout(t); + $("a.thumbnail").children('img').hide(); + $(this).closest(".entry-title").removeClass('ov'); + } + ); } } } From 53e91f22d231772199e11d29357a0c8d897a1c40 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 14:16:38 +0100 Subject: [PATCH 16/41] Updated NoticeDataAttach --- js/util.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/js/util.js b/js/util.js index fcfc0b95ab..203dca28e3 100644 --- a/js/util.js +++ b/js/util.js @@ -101,25 +101,10 @@ $(document).ready(function(){ SN.U.NoticeReply(); SN.U.NoticeAttachments(); - NoticeDataAttach(); + SN.U.NoticeDataAttach(); }); - - -function NoticeDataAttach() { - NDA = $('#notice_data-attach'); - NDA.change(function() { - S = '
      '+$(this).val()+'
      '; - NDAS = $('#notice_data-attach_selected'); - (NDAS.length > 0) ? NDAS.replaceWith(S) : $('#form_notice').append(S); - $('#notice_data-attach_selected button').click(function(){ - $('#notice_data-attach_selected').remove(); - NDA.val(''); - }); - }); -} - var SN = { // StatusNet C: { // Config I: { @@ -131,6 +116,7 @@ var SN = { // StatusNet Disabled: 'disabled', Warning: 'warning', Error: 'error', + Success: 'success', Processing: 'processing', CommendResult: 'command_result', FormNotice: 'form_notice', @@ -138,6 +124,7 @@ var SN = { // StatusNet NoticeTextCount: 'notice_text-count', NoticeInReplyTo: 'notice_in-reply-to', NoticeDataAttach: 'notice_data-attach', + NoticeDataAttachSelected: 'notice_data-attach_selected', NoticeActionSubmit: 'notice_action-submit' } }, @@ -238,7 +225,7 @@ var SN = { // StatusNet } $('#'+notice.id).css({display:'none'}); $('#'+notice.id).fadeIn(2500); -// SN.U.NoticeAttachments(); + SN.U.NoticeAttachments(); SN.U.NoticeReply(); } } @@ -336,6 +323,19 @@ var SN = { // StatusNet $(this).closest(".entry-title").removeClass('ov'); } ); + }, + + NoticeDataAttach: function() { + NDA = $('#'+SN.C.S.NoticeDataAttach); + NDA.change(function() { + S = '
      '+$(this).val()+'
      '; + NDAS = $('#'+SN.C.S.NoticeDataAttachSelected); + (NDAS.length > 0) ? NDAS.replaceWith(S) : $('#'+SN.C.S.FormNotice).append(S); + $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){ + $('#'+SN.C.S.NoticeDataAttachSelected).remove(); + NDA.val(''); + }); + }); } } } From 1ddf69f30ef576e3090d43be9e3aca9ee24f6119 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 14:31:57 +0100 Subject: [PATCH 17/41] Updated SubmitOnReturn --- js/util.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/js/util.js b/js/util.js index 203dca28e3..4ba1bcfba5 100644 --- a/js/util.js +++ b/js/util.js @@ -56,18 +56,7 @@ $(document).ready(function(){ counter(null); } - function submitonreturn(event) { - if (event.keyCode == 13 || event.keyCode == 10) { - // iPhone sends \n not \r for 'return' - $("#form_notice").submit(); - event.preventDefault(); - event.stopPropagation(); - $("#notice_data-text").blur(); - $("body").focus(); - return false; - } - return true; - } + // define maxLength if it wasn't defined already @@ -82,7 +71,9 @@ $(document).ready(function(){ counter(); } - $("#notice_data-text").bind("keydown", submitonreturn); + $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { + SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); + }); if($('body')[0].id != 'conversation') { $("#notice_data-text").focus(); @@ -130,6 +121,18 @@ var SN = { // StatusNet }, U: { // Utils + SubmitOnReturn: function(event, el) { + if (event.keyCode == 13 || event.keyCode == 10) { + el.submit(); + event.preventDefault(); + event.stopPropagation(); + $('#'+SN.U.NoticeDataText).blur(); + $('body').focus(); + return false; + } + return true; + }, + FormXHR: function(f) { f.bind('submit', function(e) { form_id = $(this)[0].id; From 4024a5ee65839d79d788d58b4fdd96893fe96360 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:43:41 +0100 Subject: [PATCH 18/41] Updated notice form counter --- js/util.js | 109 +++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 57 deletions(-) diff --git a/js/util.js b/js/util.js index 4ba1bcfba5..10c7bb18e0 100644 --- a/js/util.js +++ b/js/util.js @@ -17,68 +17,23 @@ */ $(document).ready(function(){ - var counterBlackout = false; - - // count character on keyup - function counter(event){ - if (maxLength <= 0) { - return; - } - var currentLength = $("#notice_data-text").val().length; - var remaining = maxLength - currentLength; - var counter = $("#notice_text-count"); - - if (remaining.toString() != counter.text()) { - if (!counterBlackout || remaining == 0) { - if (counter.text() != String(remaining)) { - counter.text(remaining); - } - - if (remaining < 0) { - $("#form_notice").addClass("warning"); - } else { - $("#form_notice").removeClass("warning"); - } - // Skip updates for the next 500ms. - // On slower hardware, updating on every keypress is unpleasant. - if (!counterBlackout) { - counterBlackout = true; - window.setTimeout(clearCounterBlackout, 500); - } - } - } - } - - function clearCounterBlackout() { - // Allow keyup events to poke the counter again - counterBlackout = false; - // Check if the string changed since we last looked - counter(null); - } - - - - // define maxLength if it wasn't defined already - - if (typeof(maxLength) == "undefined") { - maxLength = 140; - } - - if ($("#notice_data-text").length) { - if (maxLength > 0) { - $("#notice_data-text").bind("keyup", counter); - // run once in case there's something in there - counter(); - } + if ($('#'+SN.C.S.NoticeDataText).length) { + if (maxLength > 0) { + $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + SN.U.Counter(); + }); + // run once in case there's something in there + SN.U.Counter(); + } $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); }); if($('body')[0].id != 'conversation') { - $("#notice_data-text").focus(); + $('#'+SN.C.S.NoticeDataText).focus(); } - } + } $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); @@ -99,7 +54,8 @@ $(document).ready(function(){ var SN = { // StatusNet C: { // Config I: { - NoticeTextCharMax: 140, + CounterBlackout: false, + MaxLength: 140, PatternUsername: /^[0-9a-zA-Z\-_.]*$/, HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307] }, @@ -116,7 +72,7 @@ var SN = { // StatusNet NoticeInReplyTo: 'notice_in-reply-to', NoticeDataAttach: 'notice_data-attach', NoticeDataAttachSelected: 'notice_data-attach_selected', - NoticeActionSubmit: 'notice_action-submit' + NoticeActionSubmit: 'notice_action-submit', } }, @@ -133,6 +89,45 @@ var SN = { // StatusNet return true; }, + Counter: function() { + if (typeof(maxLength) == "undefined") { + maxLength = SN.C.I.MaxLength; + } + + if (maxLength <= 0) { + return; + } + + var remaining = maxLength - $('#'+SN.C.S.NoticeDataText).val().length; + var counter = $('#'+SN.C.S.NoticeTextCount); + + if (remaining.toString() != counter.text()) { + if (!SN.C.I.CounterBlackout || remaining == 0) { + if (counter.text() != String(remaining)) { + counter.text(remaining); + } + if (remaining < 0) { + $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + } else { + $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Warning); + } + // Skip updates for the next 500ms. + // On slower hardware, updating on every keypress is unpleasant. + if (!SN.C.I.CounterBlackout) { + SN.C.I.CounterBlackout = true; + window.setTimeout(SN.U.ClearCounterBlackout, 500); + } + } + } + }, + + ClearCounterBlackout: function() { + // Allow keyup events to poke the counter again + SN.C.I.CounterBlackout = false; + // Check if the string changed since we last looked + SN.U.Counter(null); + }, + FormXHR: function(f) { f.bind('submit', function(e) { form_id = $(this)[0].id; From 02240a890ff804bcbca33568cfc73a827265256c Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:48:35 +0100 Subject: [PATCH 19/41] Only run the scripts if the user is logged in --- js/util.js | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/js/util.js b/js/util.js index 10c7bb18e0..3e8d244b72 100644 --- a/js/util.js +++ b/js/util.js @@ -17,37 +17,41 @@ */ $(document).ready(function(){ - if ($('#'+SN.C.S.NoticeDataText).length) { - if (maxLength > 0) { - $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + if ($('body.user_in').length > 0) { + if ($('#'+SN.C.S.NoticeDataText).length) { + if (maxLength > 0) { + $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + SN.U.Counter(); + }); + // run once in case there's something in there SN.U.Counter(); + } + + $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { + SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); }); - // run once in case there's something in there - SN.U.Counter(); + + if($('body')[0].id != 'conversation') { + $('#'+SN.C.S.NoticeDataText).focus(); + } } - $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { - SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); - }); + $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_join').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - if($('body')[0].id != 'conversation') { - $('#'+SN.C.S.NoticeDataText).focus(); - } + SN.U.FormNoticeXHR(); + + SN.U.NoticeReply(); + + SN.U.NoticeDataAttach(); } - $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); - $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); - $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); - $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); }); - $('.form_group_join').each(function() { SN.U.FormXHR($(this)); }); - $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); - $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - - SN.U.FormNoticeXHR(); - - SN.U.NoticeReply(); SN.U.NoticeAttachments(); - SN.U.NoticeDataAttach(); }); From d16a989f49266b9f9790a13e5967cd9d580d9f54 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:49:47 +0100 Subject: [PATCH 20/41] Updated author documentation --- js/util.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/util.js b/js/util.js index 3e8d244b72..1519df252e 100644 --- a/js/util.js +++ b/js/util.js @@ -14,6 +14,14 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . + * + * @category UI interaction + * @package StatusNet + * @author Sarven Capadisli + * @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://status.net/ */ $(document).ready(function(){ From 728ead799273d5665e211899874576f05de23329 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:51:52 +0100 Subject: [PATCH 21/41] Resetting counter after a notice submit --- js/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/util.js b/js/util.js index 1519df252e..1b855caaf2 100644 --- a/js/util.js +++ b/js/util.js @@ -201,7 +201,7 @@ var SN = { // StatusNet } else { SN.C.I.NoticeDataText.val(''); -// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + SN.U.Counter(); } } } @@ -242,7 +242,7 @@ var SN = { // StatusNet $('#'+SN.C.S.NoticeDataText).val(''); $('#'+SN.C.S.NoticeDataAttach).val(''); $('#'+SN.C.S.NoticeInReplyTo).val(''); -// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + SN.U.Counter(); } }, complete: function(xhr, textStatus) { From 4c94eda3c8ce2f52c9979245bea13e9e44485b0a Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:59:17 +0100 Subject: [PATCH 22/41] Added Init comment --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 1b855caaf2..28e4fac8cd 100644 --- a/js/util.js +++ b/js/util.js @@ -65,7 +65,7 @@ $(document).ready(function(){ var SN = { // StatusNet C: { // Config - I: { + I: { // Init CounterBlackout: false, MaxLength: 140, PatternUsername: /^[0-9a-zA-Z\-_.]*$/, From cb8160dd8c7dc3ecfa0df3da1f6d5e9f3a6abcd0 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 16:21:03 +0100 Subject: [PATCH 23/41] Added missing dataType line for ajaxForm --- js/util.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/util.js b/js/util.js index 28e4fac8cd..3d33b18f9b 100644 --- a/js/util.js +++ b/js/util.js @@ -71,6 +71,7 @@ var SN = { // StatusNet PatternUsername: /^[0-9a-zA-Z\-_.]*$/, HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307] }, + S: { // Selector Disabled: 'disabled', Warning: 'warning', @@ -174,6 +175,7 @@ var SN = { // StatusNet $('#'+SN.C.S.FormNotice).append(''); $('#'+SN.C.S.FormNotice).ajaxForm({ timeout: '60000', + dataType: 'xml', beforeSend: function(xhr) { if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); From 873ecb81e8e147ccf05c351de795798ec4d3ed58 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:41:52 +0000 Subject: [PATCH 24/41] Remove attachment view after XHR notice submit --- js/util.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 3d33b18f9b..638f8e6d13 100644 --- a/js/util.js +++ b/js/util.js @@ -223,7 +223,7 @@ var SN = { // StatusNet } else { notice = $('li', data)[0]; - if ($('#'+notice.id).length === 0) { + if ($('#'+notice.id).length == 0) { var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val(); var notice_irt = '#notices_primary #notice-'+notice_irt_value; if($('body')[0].id == 'conversation') { @@ -244,6 +244,7 @@ var SN = { // StatusNet $('#'+SN.C.S.NoticeDataText).val(''); $('#'+SN.C.S.NoticeDataAttach).val(''); $('#'+SN.C.S.NoticeInReplyTo).val(''); + $('#'+SN.C.S.NoticeDataAttachSelected).remove(); SN.U.Counter(); } }, From 73e8c442409b5dcdb5d0affe364fb8fe50a90c37 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:47:32 +0000 Subject: [PATCH 25/41] IE doesn't like last comma. I understand. --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 638f8e6d13..10f962fd01 100644 --- a/js/util.js +++ b/js/util.js @@ -85,7 +85,7 @@ var SN = { // StatusNet NoticeInReplyTo: 'notice_in-reply-to', NoticeDataAttach: 'notice_data-attach', NoticeDataAttachSelected: 'notice_data-attach_selected', - NoticeActionSubmit: 'notice_action-submit', + NoticeActionSubmit: 'notice_action-submit' } }, From e134f7ceb15435aaaeff65269a51c15a9a3552df Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:59:24 +0000 Subject: [PATCH 26/41] Using document importNode otherwise IE pukes --- js/util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js/util.js b/js/util.js index 10f962fd01..d1b34542e2 100644 --- a/js/util.js +++ b/js/util.js @@ -146,6 +146,7 @@ var SN = { // StatusNet form_id = $(this)[0].id; $.ajax({ type: 'POST', + dataType: 'xml', url: $(this)[0].action, data: $(this).serialize() + '&ajax=1', beforeSend: function(xhr) { @@ -157,9 +158,9 @@ var SN = { // StatusNet alert(errorThrown || textStatus); }, success: function(data, textStatus) { - if ($('form', data)[0].length > 0) { - form_new = $('form', data)[0]; - $('#'+form_id).replaceWith(document._importNode(form_new, true)); + form_new = document._importNode($('form', data).get(0), true); + if (form_new.length > 0) { + $('#'+form_id).replaceWith(form_new); $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); } else { From 93506faaa608efbcf264bb3f1f0ed363d81bb390 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 16:02:22 +0000 Subject: [PATCH 27/41] Minor --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index d1b34542e2..f8e71d440d 100644 --- a/js/util.js +++ b/js/util.js @@ -158,7 +158,7 @@ var SN = { // StatusNet alert(errorThrown || textStatus); }, success: function(data, textStatus) { - form_new = document._importNode($('form', data).get(0), true); + form_new = document._importNode($('form', data)[0], true); if (form_new.length > 0) { $('#'+form_id).replaceWith(form_new); $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); From 87781b85c4eb0925f04bfb9f1468d8b4a26af39a Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 16:06:11 +0000 Subject: [PATCH 28/41] Fixed Nudge XHR --- js/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/util.js b/js/util.js index f8e71d440d..75b9addb2c 100644 --- a/js/util.js +++ b/js/util.js @@ -158,8 +158,8 @@ var SN = { // StatusNet alert(errorThrown || textStatus); }, success: function(data, textStatus) { - form_new = document._importNode($('form', data)[0], true); - if (form_new.length > 0) { + if (typeof($('form', data)[0]) != 'undefined') { + form_new = document._importNode($('form', data)[0], true); $('#'+form_id).replaceWith(form_new); $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); } From acaf07f6e8c873e0069e84dac74bac3c7da98a97 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 13:21:11 -0400 Subject: [PATCH 29/41] Added an "Verify Your Identity" page to the OpenID provider --- classes/statusnet.ini | 10 ++ plugins/OpenID/OpenIDPlugin.php | 9 ++ plugins/OpenID/User_openid_trustroot.php | 29 +++++ plugins/OpenID/openidserver.php | 24 +++- plugins/OpenID/openidtrust.php | 142 +++++++++++++++++++++++ 5 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 plugins/OpenID/User_openid_trustroot.php create mode 100644 plugins/OpenID/openidtrust.php diff --git a/classes/statusnet.ini b/classes/statusnet.ini index 7931c7bcdf..623790b100 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -537,6 +537,16 @@ modified = 384 canonical = K display = U +[user_openid_trustroot] +trustroot = 130 +user_id = 129 +created = 142 +modified = 384 + +[user_openid__keys] +trustroot = K +user_id = K + [user_role] user_id = 129 role = 130 diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index 5ebee2cbe4..02fc79b040 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -150,6 +150,7 @@ class OpenIDPlugin extends Plugin case 'PublicxrdsAction': case 'OpenidsettingsAction': case 'OpenidserverAction': + case 'OpenidtrustAction': require_once(INSTALLDIR.'/plugins/OpenID/' . strtolower(mb_substr($cls, 0, -6)) . '.php'); return false; case 'User_openid': @@ -286,6 +287,14 @@ class OpenIDPlugin extends Plugin new ColumnDef('created', 'datetime', null, false), new ColumnDef('modified', 'timestamp'))); + $schema->ensureTable('user_openid_trustroot', + array(new ColumnDef('trustroot', 'varchar', + '255', false, 'PRI'), + new ColumnDef('user_id', 'integer', + null, false, 'PRI'), + new ColumnDef('created', 'datetime', + null, false), + new ColumnDef('modified', 'timestamp'))); return true; } } diff --git a/plugins/OpenID/User_openid_trustroot.php b/plugins/OpenID/User_openid_trustroot.php new file mode 100644 index 0000000000..4654b72df7 --- /dev/null +++ b/plugins/OpenID/User_openid_trustroot.php @@ -0,0 +1,29 @@ +mode, array('checkid_immediate', 'checkid_setup'))) { $cur = common_current_user(); - error_log("Request identity: " . $request->identity); if(!$cur){ /* Go log in, and then come back. */ common_set_returnto($_SERVER['REQUEST_URI']); common_redirect(common_local_url('login')); return; }else if(common_profile_url($cur->nickname) == $request->identity || $request->idSelect()){ - $response = &$request->answer(true, null, common_profile_url($cur->nickname)); + $user_openid_trustroot = User_openid_trustroot::pkeyGet( + array('user_id'=>$cur->id, 'trustroot'=>$request->trustroot)); + if(empty($user_openid_trustroot)){ + if($request->immediate){ + //cannot prompt the user to trust this trust root in immediate mode, so answer false + $response = &$request->answer(false); + }else{ + //ask the user to trust this trust root + $_SESSION['openid_trust_root'] = $request->trust_root; + $allowResponse = $request->answer(true, null, common_profile_url($cur->nickname)); + $denyResponse = $request->answer(false); + common_ensure_session(); + $_SESSION['openid_allow_url'] = $allowResponse->encodeToUrl(); + $_SESSION['openid_deny_url'] = $denyResponse->encodeToUrl(); + common_redirect(common_local_url('openidtrust')); + return; + } + }else{ + //user has previously authorized this trust root + $response = &$request->answer(true, null, common_profile_url($cur->nickname)); + } } else if ($request->immediate) { $response = &$request->answer(false); } else { diff --git a/plugins/OpenID/openidtrust.php b/plugins/OpenID/openidtrust.php new file mode 100644 index 0000000000..29c7bdc23c --- /dev/null +++ b/plugins/OpenID/openidtrust.php @@ -0,0 +1,142 @@ +. + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } + +require_once INSTALLDIR.'/plugins/OpenID/openid.php'; +require_once(INSTALLDIR.'/plugins/OpenID/User_openid_trustroot.php'); + +class OpenidtrustAction extends Action +{ + var $trust_root; + var $allowUrl; + var $denyUrl; + var $user; + + /** + * Is this a read-only action? + * + * @return boolean false + */ + + function isReadOnly($args) + { + return false; + } + + /** + * Title of the page + * + * @return string title of the page + */ + + function title() + { + return _('OpenID Identity Verification'); + } + + function prepare($args) + { + parent::prepare($args); + common_ensure_session(); + $this->user = common_current_user(); + if(empty($this->user)){ + /* Go log in, and then come back. */ + common_set_returnto($_SERVER['REQUEST_URI']); + common_redirect(common_local_url('login')); + return; + } + $this->trust_root = $_SESSION['openid_trust_root']; + $this->allowUrl = $_SESSION['openid_allow_url']; + $this->denyUrl = $_SESSION['openid_deny_url']; + if(empty($this->trust_root) || empty($this->allowUrl) || empty($this->denyUrl)){ + $this->clientError(_('This page should only be reached during OpenID processing, not directly.')); + return; + } + return true; + } + + function handle($args) + { + parent::handle($args); + if($_SERVER['REQUEST_METHOD'] == 'POST'){ + $this->handleSubmit(); + }else{ + $this->showPage(); + } + } + + function handleSubmit() + { + unset($_SESSION['openid_trust_root']); + unset($_SESSION['openid_allow_url']); + unset($_SESSION['openid_deny_url']); + if($this->arg('allow')) + { + //save to database + $user_openid_trustroot = new User_openid_trustroot(); + $user_openid_trustroot->user_id = $this->user->id; + $user_openid_trustroot->trustroot = $this->trust_root; + $user_openid_trustroot->created = DB_DataObject_Cast::dateTime(); + if (!$user_openid_trustroot->insert()) { + $err = PEAR::getStaticProperty('DB_DataObject','lastError'); + common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__); + } + common_redirect($this->allowUrl, $code=302); + }else{ + common_redirect($this->denyUrl, $code=302); + } + } + + /** + * Show page notice + * + * Display a notice for how to use the page, or the + * error if it exists. + * + * @return void + */ + + function showPageNotice() + { + $this->element('p',null,sprintf(_('%s has asked to verify your identity. Click Continue to verify your identity and login without creating a new password.'),$this->trust_root)); + } + + /** + * Core of the display code + * + * Shows the login form. + * + * @return void + */ + + function showContent() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_openidtrust', + 'class' => 'form_settings', + 'action' => common_local_url('openidtrust'))); + $this->elementStart('fieldset'); + $this->submit('allow', _('Continue')); + $this->submit('deny', _('Cancel')); + + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } +} From 204eb5b0c42e5e90f8f03e89953239b4d2fc738c Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 13:42:54 -0400 Subject: [PATCH 30/41] made openidserver a login action so it can be seen when the site is in "private" mode --- plugins/OpenID/OpenIDPlugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index 02fc79b040..2309eea9df 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -180,6 +180,7 @@ class OpenIDPlugin extends Plugin { case 'openidlogin': case 'finishopenidlogin': + case 'openidserver': $login = true; return false; default: From cdbf7b1da522ea42c0cdc62b59e07a8499bf7972 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 13:48:18 -0400 Subject: [PATCH 31/41] Allow non-users to view the site's xrds when the site is private. Getting to closer to allow OpenID login on private sites. --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 644812bd55..3acdba3754 100644 --- a/index.php +++ b/index.php @@ -143,7 +143,7 @@ function checkMirror($action_obj, $args) function isLoginAction($action) { - static $loginActions = array('login', 'recoverpassword', 'api', 'doc', 'register'); + static $loginActions = array('login', 'recoverpassword', 'api', 'doc', 'register', 'publicxrds'); $login = null; From 982850c9c75eb2eb9821ae1e3ce76594ffdf4b7e Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 15:33:04 -0400 Subject: [PATCH 32/41] Added simple registration (sreg) support to the OpenID provider --- plugins/OpenID/openidserver.php | 88 +++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/plugins/OpenID/openidserver.php b/plugins/OpenID/openidserver.php index 8ffe979b08..dab97c93ed 100644 --- a/plugins/OpenID/openidserver.php +++ b/plugins/OpenID/openidserver.php @@ -48,68 +48,104 @@ require_once(INSTALLDIR.'/plugins/OpenID/User_openid_trustroot.php'); */ class OpenidserverAction extends Action { + var $oserver; + + function prepare($args) + { + parent::prepare($args); + $this->oserver = oid_server(); + return true; + } function handle($args) { parent::handle($args); - $oserver = oid_server(); - $request = $oserver->decodeRequest(); + $request = $this->oserver->decodeRequest(); if (in_array($request->mode, array('checkid_immediate', 'checkid_setup'))) { - $cur = common_current_user(); - if(!$cur){ - /* Go log in, and then come back. */ - common_set_returnto($_SERVER['REQUEST_URI']); - common_redirect(common_local_url('login')); - return; - }else if(common_profile_url($cur->nickname) == $request->identity || $request->idSelect()){ + $user = common_current_user(); + if(!$user){ + if($request->immediate){ + //cannot prompt the user to login in immediate mode, so answer false + $response = $this->generateDenyResponse($request); + }else{ + /* Go log in, and then come back. */ + common_set_returnto($_SERVER['REQUEST_URI']); + common_redirect(common_local_url('login')); + return; + } + }else if(common_profile_url($user->nickname) == $request->identity || $request->idSelect()){ $user_openid_trustroot = User_openid_trustroot::pkeyGet( - array('user_id'=>$cur->id, 'trustroot'=>$request->trustroot)); + array('user_id'=>$user->id, 'trustroot'=>$request->trust_root)); if(empty($user_openid_trustroot)){ if($request->immediate){ //cannot prompt the user to trust this trust root in immediate mode, so answer false - $response = &$request->answer(false); + $response = $this->generateDenyResponse($request); }else{ - //ask the user to trust this trust root - $_SESSION['openid_trust_root'] = $request->trust_root; - $allowResponse = $request->answer(true, null, common_profile_url($cur->nickname)); - $denyResponse = $request->answer(false); common_ensure_session(); + $_SESSION['openid_trust_root'] = $request->trust_root; + $allowResponse = $this->generateAllowResponse($request, $user); + $this->oserver->encodeResponse($allowResponse); //sign the response + $denyResponse = $this->generateDenyResponse($request); + $this->oserver->encodeResponse($denyResponse); //sign the response $_SESSION['openid_allow_url'] = $allowResponse->encodeToUrl(); $_SESSION['openid_deny_url'] = $denyResponse->encodeToUrl(); + //ask the user to trust this trust root common_redirect(common_local_url('openidtrust')); return; } }else{ //user has previously authorized this trust root - $response = &$request->answer(true, null, common_profile_url($cur->nickname)); + $response = $this->generateAllowResponse($request, $user); + //$response = $request->answer(true, null, common_profile_url($user->nickname)); } } else if ($request->immediate) { - $response = &$request->answer(false); + $response = $this->generateDenyResponse($request); } else { //invalid $this->clientError(sprintf(_('You are not authorized to use the identity %s'),$request->identity),$code=403); } } else { - $response = &$oserver->handleRequest($request); + $response = $this->oserver->handleRequest($request); } if($response){ - $webresponse = $oserver->encodeResponse($response); - - if ($webresponse->code != AUTH_OPENID_HTTP_OK) { - header(sprintf("HTTP/1.1 %d ", $webresponse->code), - true, $webresponse->code); + $response = $this->oserver->encodeResponse($response); + if ($response->code != AUTH_OPENID_HTTP_OK) { + header(sprintf("HTTP/1.1 %d ", $response->code), + true, $response->code); } - if($webresponse->headers){ - foreach ($webresponse->headers as $k => $v) { + if($response->headers){ + foreach ($response->headers as $k => $v) { header("$k: $v"); } } - $this->raw($webresponse->body); + $this->raw($response->body); }else{ $this->clientError(_('Just an OpenID provider. Nothing to see here, move along...'),$code=500); } } + + function generateAllowResponse($request, $user){ + $response = $request->answer(true, null, common_profile_url($user->nickname)); + + $profile = $user->getProfile(); + $sreg_data = array( + 'fullname' => $profile->fullname, + 'nickname' => $user->nickname, + 'email' => $user->email, + 'language' => $user->language, + 'timezone' => $user->timezone); + $sreg_request = Auth_OpenID_SRegRequest::fromOpenIDRequest($request); + $sreg_response = Auth_OpenID_SRegResponse::extractResponse( + $sreg_request, $sreg_data); + $sreg_response->toMessage($response->fields); + return $response; + } + + function generateDenyResponse($request){ + $response = $request->answer(false); + return $response; + } } From fc22bde67cd9a92ffb27bd8ce9258035fb25e582 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 30 Oct 2009 16:01:20 -0400 Subject: [PATCH 33/41] Redirect to login when trying to send a direct message while not logged in. http://status.net/trac/ticket/1359 --- actions/newmessage.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/actions/newmessage.php b/actions/newmessage.php index a0b17fc18a..eac4ab2104 100644 --- a/actions/newmessage.php +++ b/actions/newmessage.php @@ -99,7 +99,9 @@ class NewmessageAction extends Action $user = common_current_user(); if (!$user) { - $this->clientError(_('Only logged-in users can send direct messages.'), 403); + /* Go log in, and then come back. */ + common_set_returnto($_SERVER['REQUEST_URI']); + common_redirect(common_local_url('login')); return false; } From b7ed31c27bc883b7b7b6a9af6391aacd8d897d78 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 30 Oct 2009 16:53:23 -0400 Subject: [PATCH 34/41] Use nickname from profile, not user object, to avoid barfing warnings on Twitter messages imported into the timeline. --- actions/shownotice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/shownotice.php b/actions/shownotice.php index 41408c23cc..5d16fdad9e 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -172,9 +172,9 @@ class ShownoticeAction extends OwnerDesignAction function title() { if (!empty($this->profile->fullname)) { - $base = $this->profile->fullname . ' (' . $this->user->nickname . ') '; + $base = $this->profile->fullname . ' (' . $this->profile->nickname . ') '; } else { - $base = $this->user->nickname; + $base = $this->profile->nickname; } return sprintf(_('%1$s\'s status on %2$s'), From 900a0e2838e0c84649c3e09e683d0ad37dab9552 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 21:11:56 +0000 Subject: [PATCH 35/41] Running through importNode before checking for id --- js/util.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/util.js b/js/util.js index 75b9addb2c..11b06298d1 100644 --- a/js/util.js +++ b/js/util.js @@ -175,8 +175,8 @@ var SN = { // StatusNet FormNoticeXHR: function() { $('#'+SN.C.S.FormNotice).append(''); $('#'+SN.C.S.FormNotice).ajaxForm({ - timeout: '60000', dataType: 'xml', + timeout: '60000', beforeSend: function(xhr) { if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); @@ -223,7 +223,7 @@ var SN = { // StatusNet alert(result.textContent || result.innerHTML); } else { - notice = $('li', data)[0]; + notice = document._importNode($('li', data)[0], true); if ($('#'+notice.id).length == 0) { var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val(); var notice_irt = '#notices_primary #notice-'+notice_irt_value; @@ -231,10 +231,10 @@ var SN = { // StatusNet if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) { $(notice_irt).append('
        '); } - $($(notice_irt+' .notices')[0]).append(document._importNode(notice, true)); + $($(notice_irt+' .notices')[0]).append(notice); } else { - $("#notices_primary .notices").prepend(document._importNode(notice, true)); + $("#notices_primary .notices").prepend(notice); } $('#'+notice.id).css({display:'none'}); $('#'+notice.id).fadeIn(2500); From db9aef9f67a9448e73f6ee3463329045e41084f3 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 21:31:11 +0000 Subject: [PATCH 36/41] IE has some issue with notices that are sent with file attachments. It doesn't like the XHR response with XHTML DTD. New notices without the file attachment work fine. The rendered content (the anchor for the file attachment link) doesn't appear to be the issue. To fix this problem, I removed the XHTML DTD line from newnotice's XHR response. This is unnecessary for text/xml outputs that's intended for XHR responses any way. It just happens to fix an IE issue. Still a mystery to me as to why it is particular to notices with file attachments. --- actions/newnotice.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/actions/newnotice.php b/actions/newnotice.php index f677c49a96..fbd7ab6bce 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -192,7 +192,9 @@ class NewnoticeAction extends Action common_broadcast_notice($notice); if ($this->boolean('ajax')) { - $this->startHTML('text/xml;charset=utf-8'); + header('Content-Type: text/xml;charset=utf-8'); + $this->xw->startDocument('1.0', 'UTF-8'); + $this->elementStart('html'); $this->elementStart('head'); $this->element('title', null, _('Notice posted')); $this->elementEnd('head'); From f9bb95174b93de4ce28167eea21535a01394f71f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 16:14:38 +0100 Subject: [PATCH 37/41] Added XHR for direct messages. --- actions/newmessage.php | 17 ++++++++++++++++- js/util.js | 28 ++++++++++++++++++++++++++++ theme/base/css/display.css | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/actions/newmessage.php b/actions/newmessage.php index eac4ab2104..37fca1ca2b 100644 --- a/actions/newmessage.php +++ b/actions/newmessage.php @@ -223,7 +223,22 @@ class NewmessageAction extends Action } $this->msg = $msg; - $this->showPage(); + if ($this->trimmed('ajax')) { + $this->startHTML('text/xml;charset=UTF-8'); + $this->elementStart('head'); + $this->element('title', null, _('New message')); + $this->elementEnd('head'); + $this->elementStart('body'); + if (common_logged_in()) { + $this->showNoticeForm(); + } + $this->elementEnd('div'); + $this->elementEnd('body'); + $this->endHTML(); + } + else { + $this->showPage(); + } } function showPageNotice() diff --git a/js/util.js b/js/util.js index 11b06298d1..c7a3e8f889 100644 --- a/js/util.js +++ b/js/util.js @@ -57,6 +57,8 @@ $(document).ready(function(){ SN.U.NoticeReply(); SN.U.NoticeDataAttach(); + + SN.U.NewDirectMessage(); } SN.U.NoticeAttachments(); @@ -350,6 +352,32 @@ var SN = { // StatusNet NDA.val(''); }); }); + }, + + NewDirectMessage: function() { + NDM = $('.entity_send-a-message a'); + NDM.attr({'href':NDM.attr('href')+'&ajax=1'}); + NDM.click(function() { + var NDMF = $('.entity_send-a-message form'); + if (NDMF.length == 0) { + $.get(NDM.attr('href'), null, function(data) { + $('.entity_send-a-message').append(document._importNode($('form', data).get(0), true)); + $('.entity_send-a-message textarea').focus(); + + NDMF = $('.entity_send-a-message form'); + NDMF.append(''); + $('.entity_send-a-message button').click(function(){ + NDMF.hide(); + return false; + }); + }); + } + else { + NDMF.show(); + $('.entity_send-a-message textarea').focus(); + } + return false; + }); } } } diff --git a/theme/base/css/display.css b/theme/base/css/display.css index c8aafe4893..db6b08e632 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -670,6 +670,40 @@ border-radius:4px; margin-bottom:18px; } + +.entity_send-a-message button { +position:absolute; +top:0; +right:0; +} + +.entity_send-a-message #form_notice { +position:absolute; +top:34px; +right:-1px; +padding:1.795%; +width:65%; +z-index:1; + +background-color:#FFFFFF; +border:1px solid #CCCCCC; +-moz-box-shadow:3px 7px 5px rgba(194, 194, 194, 0.7); +-moz-border-radius:7px; +} +.entity_send-a-message #form_notice legend { +display:block; +margin-bottom:11px; +} + +.entity_send-a-message #form_notice label, +.entity_send-a-message #form_notice select { +display:none; +} +.entity_send-a-message input.submit { +text-align:center; +} + + .entity_tags ul { list-style-type:none; display:inline; From 48f33f781a91db7178a4f5046885a74dc484e629 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 17:16:37 +0100 Subject: [PATCH 38/41] Using 'form_notice' class instead of 'form' to group both forms --- lib/messageform.php | 13 ++++++++++++- lib/noticeform.php | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/messageform.php b/lib/messageform.php index e25ebfa08f..b034be3122 100644 --- a/lib/messageform.php +++ b/lib/messageform.php @@ -80,10 +80,21 @@ class MessageForm extends Form /** * ID of the form * - * @return int ID of the form + * @return string ID of the form */ function id() + { + return 'form_notice-direct'; + } + + /** + * Class of the form + * + * @return string class of the form + */ + + function formClass() { return 'form_notice'; } diff --git a/lib/noticeform.php b/lib/noticeform.php index 9864d15eb0..1be011c182 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -105,7 +105,7 @@ class NoticeForm extends Form /** * ID of the form * - * @return int ID of the form + * @return string ID of the form */ function id() @@ -113,6 +113,17 @@ class NoticeForm extends Form return 'form_notice'; } + /** + * Class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_notice'; + } + /** * Action of the form * From d42ef1112338be06d0549adbc0b8f2ad42dcba2f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 17:25:41 +0100 Subject: [PATCH 39/41] Updated form_notice styles. .form_notice applies to both noticeform (form_notice) and messageform (form_notice-direct) --- theme/base/css/display.css | 50 +++++++++++++++++----------------- theme/base/css/ie.css | 10 +++---- theme/default/css/display.css | 10 +++---- theme/default/css/ie.css | 4 +-- theme/identica/css/display.css | 10 +++---- theme/identica/css/ie.css | 4 +-- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index db6b08e632..8355a0a5cc 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -432,21 +432,21 @@ border-width:1px; border-style:solid; } -#form_notice { +.form_notice { width:45%; float:left; position:relative; line-height:1; } -#form_notice fieldset { +.form_notice fieldset { border:0; padding:0; position:relative; } -#form_notice legend { +.form_notice legend { display:none; } -#form_notice textarea { +.form_notice textarea { float:left; border-radius:7px; -moz-border-radius:7px; @@ -458,44 +458,44 @@ padding:7px 7px 16px 7px; position:relative; z-index:2; } -#form_notice label { +.form_notice label { display:block; float:left; font-size:1.3em; margin-bottom:7px; } -#form_notice label[for=notice_data-attach], -#form_notice #notice_data-attach { +.form_notice label[for=notice_data-attach], +.form_notice #notice_data-attach { position:absolute; top:25px; right:10.5%; cursor:pointer; } -#form_notice label[for=notice_data-attach] { +.form_notice label[for=notice_data-attach] { text-indent:-9999px; width:16px; height:16px; } -#form_notice #notice_data-attach { +.form_notice #notice_data-attach { padding:0; height:16px; } -#form_notice .form_note { +.form_notice .form_note { position:absolute; bottom:2px; right:21.715%; z-index:9; } -#form_notice .form_note dt { +.form_notice .form_note dt { font-weight:bold; display:none; } -#notice_text-count { +.form_notice #notice_text-count { font-weight:bold; line-height:1.15; padding:1px 2px; } -#form_notice #notice_action-submit { +.form_notice #notice_action-submit { width:14%; height:47px; padding:0; @@ -503,24 +503,24 @@ position:absolute; bottom:0; right:0; } -#form_notice label[for=to] { +.form_notice label[for=to] { margin-top:7px; } -#form_notice select[id=to] { +.form_notice select[id=to] { margin-bottom:7px; margin-left:18px; float:left; max-width:322px; } -#form_notice .error, -#form_notice .success { +.form_notice .error, +.form_notice .success { float:left; clear:both; width:81.5%; margin-bottom:0; line-height:1.618; } -#form_notice #notice_data-attach_selected code { +.form_notice #notice_data-attach_selected code { float:left; width:90%; display:block; @@ -528,7 +528,7 @@ font-size:1.1em; line-height:1.8; overflow:auto; } -#form_notice #notice_data-attach_selected button { +.form_notice #notice_data-attach_selected button { float:right; font-size:0.8em; } @@ -677,7 +677,7 @@ top:0; right:0; } -.entity_send-a-message #form_notice { +.entity_send-a-message .form_notice { position:absolute; top:34px; right:-1px; @@ -690,16 +690,16 @@ border:1px solid #CCCCCC; -moz-box-shadow:3px 7px 5px rgba(194, 194, 194, 0.7); -moz-border-radius:7px; } -.entity_send-a-message #form_notice legend { +.entity_send-a-message .form_notice legend { display:block; margin-bottom:11px; } -.entity_send-a-message #form_notice label, -.entity_send-a-message #form_notice select { +.entity_send-a-message .form_notice label, +.entity_send-a-message .form_notice select { display:none; } -.entity_send-a-message input.submit { +.entity_send-a-message .form_notice input.submit { text-align:center; } @@ -1333,7 +1333,7 @@ clear:both; #bookmarklet address { display:none; } -#bookmarklet #form_notice { +#bookmarklet .form_notice { width:auto; } #bookmarklet #wrap { diff --git a/theme/base/css/ie.css b/theme/base/css/ie.css index 3e128b84ed..84bc1b1d64 100644 --- a/theme/base/css/ie.css +++ b/theme/base/css/ie.css @@ -3,10 +3,10 @@ input.checkbox, input.radio { top:0; } -#form_notice textarea { +.form_notice textarea { width:78%; } -#form_notice .form_note + label { +.form_notice .form_note + label { position:absolute; top:25px; left:83%; @@ -15,14 +15,14 @@ height:16px; width:16px; display:block; } -#form_notice #notice_action-submit { +.form_notice #notice_action-submit { width:17%; max-width:17%; } -#form_notice #notice_data-attach_selected { +.form_notice #notice_data-attach_selected { width:78.5%; } -#form_notice #notice_data-attach_selected button { +.form_notice #notice_data-attach_selected button { padding:0 4px; } .notice-options input.submit { diff --git a/theme/default/css/display.css b/theme/default/css/display.css index a5f1fd6e47..5eff5842a7 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -37,14 +37,14 @@ background:none; } input.submit, -#form_notice.warning #notice_text-count, +.form_notice.warning #notice_text-count, .form_settings .form_note, .entity_remote_subscribe { background-color:#9BB43E; } input:focus, textarea:focus, select:focus, -#form_notice.warning #notice_data-text { +.form_notice.warning #notice_data-text { border-color:#9BB43E; box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3); -moz-box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3); @@ -84,13 +84,13 @@ background-color:#C8D1D5; #notice_text-count { color:#333333; } -#form_notice.warning #notice_text-count { +.form_notice.warning #notice_text-count { color:#000000; } -#form_notice label[for=notice_data-attach] { +.form_notice label[for=notice_data-attach] { background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -328px; } -#form_notice #notice_data-attach { +.form_notice #notice_data-attach { opacity:0; } diff --git a/theme/default/css/ie.css b/theme/default/css/ie.css index cbbd49ce6c..a0d3cd6825 100644 --- a/theme/default/css/ie.css +++ b/theme/default/css/ie.css @@ -6,9 +6,9 @@ color:#FFFFFF; #site_nav_local_views a { background-color:#C8D1D5; } -#form_notice .form_note + label { +.form_notice .form_note + label { background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%; } -#form_notice #notice_data-attach { +.form_notice #notice_data-attach { filter: alpha(opacity=0); } diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index 6339c9314e..8aedd5144d 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -37,14 +37,14 @@ background:none; } input.submit, -#form_notice.warning #notice_text-count, +.form_notice.warning #notice_text-count, .form_settings .form_note, .entity_remote_subscribe { background-color:#9BB43E; } input:focus, textarea:focus, select:focus, -#form_notice.warning #notice_data-text { +.form_notice.warning #notice_data-text { border-color:#9BB43E; box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3); -moz-box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3); @@ -84,13 +84,13 @@ background-color:#CEE1E9; #notice_text-count { color:#333333; } -#form_notice.warning #notice_text-count { +.form_notice.warning #notice_text-count { color:#000000; } -#form_notice label[for=notice_data-attach] { +.form_notice label[for=notice_data-attach] { background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -328px; } -#form_notice #notice_data-attach { +.form_notice #notice_data-attach { opacity:0; } diff --git a/theme/identica/css/ie.css b/theme/identica/css/ie.css index 044c32ff16..9ede1e324b 100644 --- a/theme/identica/css/ie.css +++ b/theme/identica/css/ie.css @@ -6,10 +6,10 @@ color:#FFFFFF; #site_nav_local_views a { background-color:#D9DADB; } -#form_notice .form_note + label { +.form_notice .form_note + label { background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -328px; } -#form_notice #notice_data-attach { +.form_notice #notice_data-attach { filter: alpha(opacity=0); } .notice-options form.form_favor input.submit { From dd50368cb23a3dd4a05c720d1f6b37c02d529ef4 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 18:01:19 +0100 Subject: [PATCH 40/41] Updated FormNoticeXHR to allow any form_notice as input (e.g., reused in XHR direct message) --- js/util.js | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/js/util.js b/js/util.js index c7a3e8f889..a2950fcb31 100644 --- a/js/util.js +++ b/js/util.js @@ -40,7 +40,7 @@ $(document).ready(function(){ }); if($('body')[0].id != 'conversation') { - $('#'+SN.C.S.NoticeDataText).focus(); + $('.'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeDataText).focus(); } } @@ -52,7 +52,7 @@ $(document).ready(function(){ $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - SN.U.FormNoticeXHR(); + SN.U.FormNoticeXHR($('.'+SN.C.S.FormNotice)); SN.U.NoticeReply(); @@ -80,7 +80,7 @@ var SN = { // StatusNet Error: 'error', Success: 'success', Processing: 'processing', - CommendResult: 'command_result', + CommandResult: 'command_result', FormNotice: 'form_notice', NoticeDataText: 'notice_data-text', NoticeTextCount: 'notice_text-count', @@ -174,38 +174,40 @@ var SN = { // StatusNet }); }, - FormNoticeXHR: function() { - $('#'+SN.C.S.FormNotice).append(''); - $('#'+SN.C.S.FormNotice).ajaxForm({ + FormNoticeXHR: function(form) { + form_id = form.attr('id'); + console.log(form_id); + form.append(''); + form.ajaxForm({ dataType: 'xml', timeout: '60000', beforeSend: function(xhr) { - if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { - $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + if ($('#'+form_id+' #'+SN.C.S.NoticeDataText)[0].value.length === 0) { + form.addClass(SN.C.S.Warning); return false; } - $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Processing); - $('#'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled); - $('#'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled); + form.addClass(SN.C.S.Processing); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled); return true; }, error: function (xhr, textStatus, errorThrown) { - $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); - $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); - $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled); + form.removeClass(SN.C.S.Processing); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled); if (textStatus == 'timeout') { alert ('Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists'); } else { if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) { - $('#'+SN.C.S.FormNotice).append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true)); + form.append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true)); } else { if(jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) < 0) { alert('Sorry! We had trouble sending your notice ('+xhr.status+' '+xhr.statusText+'). Please report the problem to the site administrator if this happens again.'); } else { - SN.C.I.NoticeDataText.val(''); + $('#'+form_id+' #'+SN.C.S.NoticeDataText).val(''); SN.U.Counter(); } } @@ -220,6 +222,7 @@ var SN = { // StatusNet if($('body')[0].id == 'bookmarklet') { self.close(); } + if ($('#'+SN.C.S.CommandResult, data).length > 0) { var result = document._importNode($('p', data)[0], true); alert(result.textContent || result.innerHTML); @@ -244,17 +247,17 @@ var SN = { // StatusNet SN.U.NoticeReply(); } } - $('#'+SN.C.S.NoticeDataText).val(''); - $('#'+SN.C.S.NoticeDataAttach).val(''); - $('#'+SN.C.S.NoticeInReplyTo).val(''); - $('#'+SN.C.S.NoticeDataAttachSelected).remove(); + $('#'+form_id+' #'+SN.C.S.NoticeDataText).val(''); + $('#'+form_id+' #'+SN.C.S.NoticeDataAttach).val(''); + $('#'+form_id+' #'+SN.C.S.NoticeInReplyTo).val(''); + $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove(); SN.U.Counter(); } }, complete: function(xhr, textStatus) { - $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); - $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled); - $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + form.removeClass(SN.C.S.Processing); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); } }); }, @@ -362,14 +365,15 @@ var SN = { // StatusNet if (NDMF.length == 0) { $.get(NDM.attr('href'), null, function(data) { $('.entity_send-a-message').append(document._importNode($('form', data).get(0), true)); - $('.entity_send-a-message textarea').focus(); + NDMF = $('.entity_send-a-message .form_notice'); + SN.U.FormNoticeXHR(NDMF); - NDMF = $('.entity_send-a-message form'); NDMF.append(''); $('.entity_send-a-message button').click(function(){ NDMF.hide(); return false; }); + $('.entity_send-a-message textarea').focus(); }); } else { From 8a333805df5fc3786ef8abe1d71421fb9270ff7f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 18:55:13 +0100 Subject: [PATCH 41/41] Updated counter, submitonreturn to be reused by any form. Created FormNoticeEnhancements to call those at one go for any form. --- js/util.js | 71 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/js/util.js b/js/util.js index a2950fcb31..663ec89863 100644 --- a/js/util.js +++ b/js/util.js @@ -26,23 +26,7 @@ $(document).ready(function(){ if ($('body.user_in').length > 0) { - if ($('#'+SN.C.S.NoticeDataText).length) { - if (maxLength > 0) { - $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { - SN.U.Counter(); - }); - // run once in case there's something in there - SN.U.Counter(); - } - - $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { - SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); - }); - - if($('body')[0].id != 'conversation') { - $('.'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeDataText).focus(); - } - } + $('.'+SN.C.S.FormNotice).each(function() { SN.U.FormNoticeEnhancements($(this)); }); $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); @@ -52,8 +36,6 @@ $(document).ready(function(){ $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - SN.U.FormNoticeXHR($('.'+SN.C.S.FormNotice)); - SN.U.NoticeReply(); SN.U.NoticeDataAttach(); @@ -92,19 +74,42 @@ var SN = { // StatusNet }, U: { // Utils + FormNoticeEnhancements: function(form) { + form_id = form.attr('id'); + if (maxLength > 0) { + $('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + SN.U.Counter(form); + }); + // run once in case there's something in there + SN.U.Counter(form); + } + + $('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keydown', function(e) { + SN.U.SubmitOnReturn(e, form); + }); + + if($('body')[0].id != 'conversation') { + $('#'+form_id+' textarea').focus(); + } + + SN.U.FormNoticeXHR(form); + }, + SubmitOnReturn: function(event, el) { if (event.keyCode == 13 || event.keyCode == 10) { el.submit(); event.preventDefault(); event.stopPropagation(); - $('#'+SN.U.NoticeDataText).blur(); + $('#'+el[0].id+' #'+SN.U.NoticeDataText).blur(); $('body').focus(); return false; } return true; }, - Counter: function() { + Counter: function(form) { + SN.C.I.FormNoticeCurrent = form; + form_id = form.attr('id'); if (typeof(maxLength) == "undefined") { maxLength = SN.C.I.MaxLength; } @@ -113,8 +118,8 @@ var SN = { // StatusNet return; } - var remaining = maxLength - $('#'+SN.C.S.NoticeDataText).val().length; - var counter = $('#'+SN.C.S.NoticeTextCount); + var remaining = maxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length; + var counter = $('#'+form_id+' #'+SN.C.S.NoticeTextCount); if (remaining.toString() != counter.text()) { if (!SN.C.I.CounterBlackout || remaining == 0) { @@ -122,25 +127,26 @@ var SN = { // StatusNet counter.text(remaining); } if (remaining < 0) { - $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + form.addClass(SN.C.S.Warning); } else { - $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Warning); + form.removeClass(SN.C.S.Warning); } // Skip updates for the next 500ms. // On slower hardware, updating on every keypress is unpleasant. if (!SN.C.I.CounterBlackout) { SN.C.I.CounterBlackout = true; - window.setTimeout(SN.U.ClearCounterBlackout, 500); + SN.C.I.FormNoticeCurrent = form; + window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);", 500); } } } }, - ClearCounterBlackout: function() { + ClearCounterBlackout: function(form) { // Allow keyup events to poke the counter again SN.C.I.CounterBlackout = false; // Check if the string changed since we last looked - SN.U.Counter(null); + SN.U.Counter(form); }, FormXHR: function(f) { @@ -176,7 +182,6 @@ var SN = { // StatusNet FormNoticeXHR: function(form) { form_id = form.attr('id'); - console.log(form_id); form.append(''); form.ajaxForm({ dataType: 'xml', @@ -208,7 +213,7 @@ var SN = { // StatusNet } else { $('#'+form_id+' #'+SN.C.S.NoticeDataText).val(''); - SN.U.Counter(); + SN.U.Counter($('#'+SN.C.S.FormNotice)); } } } @@ -251,7 +256,7 @@ var SN = { // StatusNet $('#'+form_id+' #'+SN.C.S.NoticeDataAttach).val(''); $('#'+form_id+' #'+SN.C.S.NoticeInReplyTo).val(''); $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove(); - SN.U.Counter(); + SN.U.Counter($('#'+SN.C.S.FormNotice)); } }, complete: function(xhr, textStatus) { @@ -366,14 +371,12 @@ var SN = { // StatusNet $.get(NDM.attr('href'), null, function(data) { $('.entity_send-a-message').append(document._importNode($('form', data).get(0), true)); NDMF = $('.entity_send-a-message .form_notice'); - SN.U.FormNoticeXHR(NDMF); - + SN.U.FormNoticeEnhancements(NDMF); NDMF.append(''); $('.entity_send-a-message button').click(function(){ NDMF.hide(); return false; }); - $('.entity_send-a-message textarea').focus(); }); } else {