From 7f8dbb8e457d1e5534ebb569988d84ee3adaeef7 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 11 Nov 2009 10:38:11 -0800 Subject: Fix bug 1963: Web UI throws warnings during previously open login session after user account is deleted common_logged_in() returned bogus results because it checks against null specifically, but common_current_user() was sticking 'false' into $_cur because that's what User::staticGet() returned from a failed lookup. Now we skip over a failed lookup here, so we keep null and all is well. --- lib/util.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 81160d052..7aca4af8d 100644 --- a/lib/util.php +++ b/lib/util.php @@ -350,8 +350,11 @@ function common_current_user() common_ensure_session(); $id = isset($_SESSION['userid']) ? $_SESSION['userid'] : false; if ($id) { - $_cur = User::staticGet($id); - return $_cur; + $user = User::staticGet($id); + if ($user) { + $_cur = $user; + return $_cur; + } } } -- cgit v1.2.3-54-g00ecf From 014d6b1d19b6ae5de8d87f055397993f80579f74 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 11 Nov 2009 14:02:57 -0500 Subject: Redid how URL shorteners work. This way is much more like how Evan wants events to work (and more like how the rest of SN works). --- EVENTS.txt | 14 ++++ actions/othersettings.php | 17 ++--- lib/Shorturl_api.php | 67 ------------------ lib/common.php | 1 - lib/util.php | 25 +++---- plugins/BitlyUrl/BitlyUrlPlugin.php | 31 ++++----- plugins/LilUrl/LilUrlPlugin.php | 38 +++++----- plugins/PtitUrl/PtitUrlPlugin.php | 31 ++++----- plugins/SimpleUrl/SimpleUrlPlugin.php | 41 +++-------- plugins/TightUrl/TightUrlPlugin.php | 31 ++++----- plugins/UrlShortener/UrlShortenerPlugin.php | 103 ++++++++++++++++++++++++++++ 11 files changed, 197 insertions(+), 202 deletions(-) delete mode 100644 lib/Shorturl_api.php create mode 100644 plugins/UrlShortener/UrlShortenerPlugin.php (limited to 'lib') diff --git a/EVENTS.txt b/EVENTS.txt index f75dcebca..3acff277b 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -538,3 +538,17 @@ EndChangePassword: After changing a password UserDeleteRelated: Specify additional tables to delete entries from when deleting users - $user: User object - &$related: array of DB_DataObject class names to delete entries on matching user_id. + +GetUrlShorteners: Specify URL shorteners that are available for use +- &$shorteners: append your shortener to this array like so: $shorteners[shortenerName]=array('display'=>display, 'freeService'=>boolean) + +StartShortenUrl: About to shorten a URL +- $url: url to be shortened +- $shortenerName: name of the requested shortener +- &$shortenedUrl: short version of the url + +EndShortenUrl: After a URL has been shortened +- $url: url to be shortened +- $shortenerName: name of the requested shortener +- $shortenedUrl: short version of the url + diff --git a/actions/othersettings.php b/actions/othersettings.php index d32a2d651..d52a634ac 100644 --- a/actions/othersettings.php +++ b/actions/othersettings.php @@ -97,20 +97,15 @@ class OthersettingsAction extends AccountSettingsAction $this->elementStart('fieldset'); $this->hidden('token', common_session_token()); - $services=array(); - global $_shorteners; - if($_shorteners){ - foreach($_shorteners as $name=>$value) - { - $services[$name]=$name; - if(!empty($value['info']['freeService'])){ - // I18N - $services[$name].=' (free service)'; - } + Event::handle('GetUrlShorteners', array(&$shorteners)); + foreach($shorteners as $name=>$value) + { + $services[$name]=$name; + if($value['freeService']){ + $services[$name].=_(' (free service)'); } } asort($services); - $services['']='None'; $this->elementStart('ul', 'form_data'); $this->elementStart('li'); diff --git a/lib/Shorturl_api.php b/lib/Shorturl_api.php deleted file mode 100644 index de4d55012..000000000 --- a/lib/Shorturl_api.php +++ /dev/null @@ -1,67 +0,0 @@ -. - */ - -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } - -abstract class ShortUrlApi -{ - protected $service_url; - protected $long_limit = 27; - - function __construct($service_url) - { - $this->service_url = $service_url; - } - - function shorten($url) - { - if ($this->is_long($url)) return $this->shorten_imp($url); - return $url; - } - - protected abstract function shorten_imp($url); - - protected function is_long($url) { - return strlen($url) >= common_config('site', 'shorturllength'); - } - - protected function http_post($data) - { - $request = HTTPClient::start(); - $response = $request->post($this->service_url, null, $data); - return $response->getBody(); - } - - protected function http_get($url) - { - $request = HTTPClient::start(); - $response = $request->get($this->service_url . urlencode($url)); - return $response->getBody(); - } - - protected function tidy($response) { - $response = str_replace(' ', ' ', $response); - $config = array('output-xhtml' => true); - $tidy = new tidy; - $tidy->parseString($response, $config, 'utf8'); - $tidy->cleanRepair(); - return (string)$tidy; - } -} - diff --git a/lib/common.php b/lib/common.php index 6aac46807..4958866d0 100644 --- a/lib/common.php +++ b/lib/common.php @@ -229,7 +229,6 @@ require_once INSTALLDIR.'/lib/util.php'; require_once INSTALLDIR.'/lib/action.php'; require_once INSTALLDIR.'/lib/mail.php'; require_once INSTALLDIR.'/lib/subs.php'; -require_once INSTALLDIR.'/lib/Shorturl_api.php'; require_once INSTALLDIR.'/lib/clientexception.php'; require_once INSTALLDIR.'/lib/serverexception.php'; diff --git a/lib/util.php b/lib/util.php index 7aca4af8d..68f3520db 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1423,25 +1423,18 @@ function common_shorten_url($long_url) if (empty($user)) { // common current user does not find a user when called from the XMPP daemon // therefore we'll set one here fix, so that XMPP given URLs may be shortened - $svc = 'ur1.ca'; + $shortenerName = 'ur1.ca'; } else { - $svc = $user->urlshorteningservice; + $shortenerName = $user->urlshorteningservice; } - global $_shorteners; - if (!isset($_shorteners[$svc])) { - //the user selected service doesn't exist, so default to ur1.ca - $svc = 'ur1.ca'; - } - if (!isset($_shorteners[$svc])) { - // no shortener plugins installed. - return $long_url; - } - - $reflectionObj = new ReflectionClass($_shorteners[$svc]['callInfo'][0]); - $short_url_service = $reflectionObj->newInstanceArgs($_shorteners[$svc]['callInfo'][1]); - $short_url = $short_url_service->shorten($long_url); - return $short_url; + if(Event::handle('StartShortenUrl', array($long_url,$shortenerName,&$shortenedUrl))){ + //URL wasn't shortened, so return the long url + return $long_url; + }else{ + //URL was shortened, so return the result + return $shortenedUrl; + } } function common_client_ip() diff --git a/plugins/BitlyUrl/BitlyUrlPlugin.php b/plugins/BitlyUrl/BitlyUrlPlugin.php index 478ef99d2..65d0f70e6 100644 --- a/plugins/BitlyUrl/BitlyUrlPlugin.php +++ b/plugins/BitlyUrl/BitlyUrlPlugin.php @@ -31,31 +31,24 @@ if (!defined('STATUSNET')) { exit(1); } -class BitlyUrlPlugin extends Plugin +require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php'; + +class BitlyUrlPlugin extends UrlShortenerPlugin { - function __construct() - { - parent::__construct(); - } + public $serviceUrl; function onInitializePlugin(){ - $this->registerUrlShortener( - 'bit.ly', - array(), - array('BitlyUrl',array('http://bit.ly/api?method=shorten&long_url=')) - ); + parent::onInitializePlugin(); + if(!isset($this->serviceUrl)){ + throw new Exception("must specify a serviceUrl"); + } } -} -class BitlyUrl extends ShortUrlApi -{ - protected function shorten_imp($url) { + protected function shorten($url) { $response = $this->http_get($url); - if(!$response){ - return $url; - }else{ - return current(json_decode($response)->results)->hashUrl; - } + if(!$response) return; + return current(json_decode($response)->results)->hashUrl; } } + diff --git a/plugins/LilUrl/LilUrlPlugin.php b/plugins/LilUrl/LilUrlPlugin.php index 852253b02..e906751e8 100644 --- a/plugins/LilUrl/LilUrlPlugin.php +++ b/plugins/LilUrl/LilUrlPlugin.php @@ -31,37 +31,31 @@ if (!defined('STATUSNET')) { exit(1); } -require_once(INSTALLDIR.'/lib/Shorturl_api.php'); +require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php'; -class LilUrlPlugin extends Plugin +class LilUrlPlugin extends UrlShortenerPlugin { - function __construct() - { - parent::__construct(); - } + public $serviceUrl; function onInitializePlugin(){ - $this->registerUrlShortener( - 'ur1.ca', - array('freeService'=>true), - array('LilUrl',array('http://ur1.ca/')) - ); + parent::onInitializePlugin(); + if(!isset($this->serviceUrl)){ + throw new Exception("must specify a serviceUrl"); + } } -} -class LilUrl extends ShortUrlApi -{ - protected function shorten_imp($url) { - $data['longurl'] = $url; - $response = $this->http_post($data); - if (!$response) return $url; - $y = @simplexml_load_string($response); - if (!isset($y->body)) return $url; + protected function shorten($url) { + $data = array('longurl' => $url); + + $responseBody = $this->http_post($this->serviceUrl,$data); + + if (!$responseBody) return; + $y = @simplexml_load_string($responseBody); + if (!isset($y->body)) return; $x = $y->body->p[0]->a->attributes(); if (isset($x['href'])) { - common_log(LOG_INFO, __CLASS__ . ": shortened $url to $x[href]"); return $x['href']; } - return $url; } } + diff --git a/plugins/PtitUrl/PtitUrlPlugin.php b/plugins/PtitUrl/PtitUrlPlugin.php index f00d3e2f2..ef453e96d 100644 --- a/plugins/PtitUrl/PtitUrlPlugin.php +++ b/plugins/PtitUrl/PtitUrlPlugin.php @@ -30,33 +30,28 @@ if (!defined('STATUSNET')) { exit(1); } +require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php'; -class PtitUrlPlugin extends Plugin +class PtitUrlPlugin extends UrlShortenerPlugin { - function __construct() - { - parent::__construct(); - } + public $serviceUrl; function onInitializePlugin(){ - $this->registerUrlShortener( - 'ptiturl.com', - array(), - array('PtitUrl',array('http://ptiturl.com/?creer=oui&action=Reduire&url=')) - ); + parent::onInitializePlugin(); + if(!isset($this->serviceUrl)){ + throw new Exception("must specify a serviceUrl"); + } } -} -class PtitUrl extends ShortUrlApi -{ - protected function shorten_imp($url) { - $response = $this->http_get($url); - if (!$response) return $url; + protected function shorten($url) + { + $response = $this->http_get(sprintf($this->serviceUrl,urlencode($url))); + if (!$response) return; $response = $this->tidy($response); $y = @simplexml_load_string($response); - if (!isset($y->body)) return $url; + if (!isset($y->body)) return; $xml = $y->body->center->table->tr->td->pre->a->attributes(); if (isset($xml['href'])) return $xml['href']; - return $url; } } + diff --git a/plugins/SimpleUrl/SimpleUrlPlugin.php b/plugins/SimpleUrl/SimpleUrlPlugin.php index d59d63e47..45b745b07 100644 --- a/plugins/SimpleUrl/SimpleUrlPlugin.php +++ b/plugins/SimpleUrl/SimpleUrlPlugin.php @@ -31,40 +31,21 @@ if (!defined('STATUSNET')) { exit(1); } -class SimpleUrlPlugin extends Plugin +require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php'; + +class SimpleUrlPlugin extends UrlShortenerPlugin { - function __construct() - { - parent::__construct(); - } + public $serviceUrl; function onInitializePlugin(){ - $this->registerUrlShortener( - 'is.gd', - array(), - array('SimpleUrl',array('http://is.gd/api.php?longurl=')) - ); - $this->registerUrlShortener( - 'snipr.com', - array(), - array('SimpleUrl',array('http://snipr.com/site/snip?r=simple&link=')) - ); - $this->registerUrlShortener( - 'metamark.net', - array(), - array('SimpleUrl',array('http://metamark.net/api/rest/simple?long_url=')) - ); - $this->registerUrlShortener( - 'tinyurl.com', - array(), - array('SimpleUrl',array('http://tinyurl.com/api-create.php?url=')) - ); + parent::onInitializePlugin(); + if(!isset($this->serviceUrl)){ + throw new Exception("must specify a serviceUrl"); + } } -} -class SimpleUrl extends ShortUrlApi -{ - protected function shorten_imp($url) { - return $this->http_get($url); + protected function shorten($url) { + return $this->http_get(sprintf($this->serviceUrl,urlencode($url))); } } + diff --git a/plugins/TightUrl/TightUrlPlugin.php b/plugins/TightUrl/TightUrlPlugin.php index 48efb355f..56414c8c8 100644 --- a/plugins/TightUrl/TightUrlPlugin.php +++ b/plugins/TightUrl/TightUrlPlugin.php @@ -31,32 +31,27 @@ if (!defined('STATUSNET')) { exit(1); } -class TightUrlPlugin extends Plugin +require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php'; + +class TightUrlPlugin extends UrlShortenerPlugin { - function __construct() - { - parent::__construct(); - } + public $serviceUrl; function onInitializePlugin(){ - $this->registerUrlShortener( - '2tu.us', - array('freeService'=>true), - array('TightUrl',array('http://2tu.us/?save=y&url=')) - ); + parent::onInitializePlugin(); + if(!isset($this->serviceUrl)){ + throw new Exception("must specify a serviceUrl"); + } } -} -class TightUrl extends ShortUrlApi -{ - protected function shorten_imp($url) { - $response = $this->http_get($url); - if (!$response) return $url; + protected function shorten($url) + { + $response = $this->http_get(sprintf($this->serviceUrl,urlencode($url))); + if (!$response) return; $response = $this->tidy($response); $y = @simplexml_load_string($response); - if (!isset($y->body)) return $url; + if (!isset($y->body)) return; $xml = $y->body->p[0]->code[0]->a->attributes(); if (isset($xml['href'])) return $xml['href']; - return $url; } } diff --git a/plugins/UrlShortener/UrlShortenerPlugin.php b/plugins/UrlShortener/UrlShortenerPlugin.php new file mode 100644 index 000000000..37206aa89 --- /dev/null +++ b/plugins/UrlShortener/UrlShortenerPlugin.php @@ -0,0 +1,103 @@ +. + * + * @category Plugin + * @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/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +/** + * Superclass for plugins that do URL shortening + * + * @category Plugin + * @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/ + */ + +abstract class UrlShortenerPlugin extends Plugin +{ + public $shortenerName; + public $freeService=false; + //------------Url Shortener plugin should implement some (or all) of these methods------------\\ + + /** + * Short a URL + * @param url + * @return string shortened version of the url, or null if URL shortening failed + */ + protected abstract function shorten($url); + + //------------These methods may help you implement your plugin------------\\ + protected function http_get($url) + { + $request = HTTPClient::start(); + $response = $request->get($url); + return $response->getBody(); + } + + protected function http_post($url,$data) + { + $request = HTTPClient::start(); + $response = $request->post($url, null, $data); + return $response->getBody(); + } + + protected function tidy($response) { + $response = str_replace(' ', ' ', $response); + $config = array('output-xhtml' => true); + $tidy = new tidy; + $tidy->parseString($response, $config, 'utf8'); + $tidy->cleanRepair(); + return (string)$tidy; + } + //------------Below are the methods that connect StatusNet to the implementing Url Shortener plugin------------\\ + + function onInitializePlugin(){ + if(!isset($this->shortenerName)){ + throw new Exception("must specify a shortenerName"); + } + } + + function onGetUrlShorteners(&$shorteners) + { + $shorteners[$this->shortenerName]=array('freeService'=>$this->freeService); + } + + function onStartShortenUrl($url,$shortenerName,&$shortenedUrl) + { + if($shortenerName == $this->shortenerName && strlen($url) >= common_config('site', 'shorturllength')){ + $result = $this->shorten($url); + if(isset($result) && $result != null && $result !== false){ + $shortenedUrl=$result; + common_log(LOG_INFO, __CLASS__ . ": $this->shortenerName shortened $url to $shortenedUrl"); + return false; + } + } + } +} -- cgit v1.2.3-54-g00ecf From 1c4bacf7bcaad9b078ff1e7675371932bb76d0b3 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 11 Nov 2009 16:51:10 -0500 Subject: Remove registerUrlShortener() (no longer used) --- lib/plugin.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'lib') diff --git a/lib/plugin.php b/lib/plugin.php index 59bf3ba9d..87d7be5a7 100644 --- a/lib/plugin.php +++ b/lib/plugin.php @@ -76,18 +76,4 @@ class Plugin { return true; } - - /* - * the name of the shortener - * shortenerInfo associative array with additional information. One possible element is 'freeService' which can be true or false - * shortener array, first element is the name of the class, second element is an array to be passed as constructor parameters to the class - */ - function registerUrlShortener($name, $shortenerInfo, $shortener) - { - global $_shorteners; - if(!is_array($_shorteners)){ - $_shorteners=array(); - } - $_shorteners[$name]=array('info'=>$shortenerInfo, 'callInfo'=>$shortener); - } } -- cgit v1.2.3-54-g00ecf From 074b9faee0efafa2917e39257ab94f95fb6960b0 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 11 Nov 2009 18:00:58 -0500 Subject: Remove alt text on avatar url (so pidgin doesn't show it) surround notice_id with [], looks nicer --- lib/jabber.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/jabber.php b/lib/jabber.php index 73f2ec660..23c2e0d94 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -176,7 +176,7 @@ function jabber_format_entry($profile, $notice) $xs = new XMLStringer(); $xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im')); $xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml')); - $xs->element("img", array('src'=> $profile->avatarUrl(AVATAR_MINI_SIZE) , 'alt' => $profile->nickname)); + $xs->element("img", array('src'=> $profile->avatarUrl(AVATAR_MINI_SIZE))); $xs->element('a', array('href' => $profile->profileurl), $profile->nickname); $xs->text(": "); @@ -185,11 +185,11 @@ function jabber_format_entry($profile, $notice) } else { $xs->raw(common_render_content($notice->content, $notice)); } - $xs->raw(" "); + $xs->text(" "); $xs->element('a', array( 'href'=>common_local_url('conversation', array('id' => $notice->conversation)).'#notice-'.$notice->id - ),sprintf(_('notice id: %s'),$notice->id)); + ),sprintf(_('[%s]'),$notice->id)); $xs->elementEnd('body'); $xs->elementEnd('html'); -- cgit v1.2.3-54-g00ecf From 59e8896212a8d5e5ceed37162b8d38abc0de0e4b Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 11 Nov 2009 18:03:07 -0500 Subject: Add the [noticeid] to the end of text only jabber messages --- lib/jabber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/jabber.php b/lib/jabber.php index 23c2e0d94..a8e295ea5 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -481,5 +481,5 @@ function jabber_public_notice($notice) function jabber_format_notice(&$profile, &$notice) { - return $profile->nickname . ': ' . $notice->content; + return $profile->nickname . ': ' . $notice->content . ' [' . $notice->id . ']'; } -- cgit v1.2.3-54-g00ecf From 7efea1115f45b8880fe3161cc32b09510ddd2264 Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Wed, 11 Nov 2009 18:45:21 -0500 Subject: Ask users if they wish to send statistics to SNI, default is off. Users may not know about this setting and are unaware they are sending stats. This allows them to make that decision. --- install.php | 15 +++++++++++---- lib/default.php | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/install.php b/install.php index e7f7cf318..964d743f9 100644 --- a/install.php +++ b/install.php @@ -1,4 +1,3 @@ - * @author CiaranG * @author Craig Andrews - * @author Eric Helgeson + * @author Eric Helgeson * @author Evan Prodromou * @author Robin Millette * @author Sarven Capadisli @@ -500,6 +499,10 @@ function showForm()

Database password (optional)

+
  • + + +

    Periodically send information about your site to StatusNet Inc

    @@ -521,6 +524,7 @@ function handlePost() $username = $_POST['username']; $password = $_POST['password']; $sitename = $_POST['sitename']; + $snapshot = $_POST['snapshot']; $fancy = !empty($_POST['fancy']); $server = $_SERVER['HTTP_HOST']; $path = substr(dirname($_SERVER['PHP_SELF']), 1); @@ -567,7 +571,7 @@ STR; } updateStatus("Writing config file..."); - $res = writeConf($sitename, $server, $path, $fancy, $db); + $res = writeConf($sitename, $server, $path, $fancy, $db, $snapshot); if (!$res) { updateStatus("Can't write config file.", true); @@ -688,7 +692,7 @@ function Mysql_Db_installer($host, $database, $username, $password) return $db; } -function writeConf($sitename, $server, $path, $fancy, $db) +function writeConf($sitename, $server, $path, $fancy, $db, $snapshot) { // assemble configuration file in a string $cfg = " null, 'welcome' => null), 'snapshot' => - array('run' => 'web', + array('run' => 'never', 'frequency' => 10000, 'reporturl' => 'http://status.net/stats/report'), 'attachments' => -- cgit v1.2.3-54-g00ecf From d8fe5224cb5628f1a281c7498a516e89992f6474 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 12 Nov 2009 09:02:00 -0800 Subject: Fix for bug 1974: drop unnecessary define_syslog_variables() call from common.php The call was moved to this spot in commit 3ea1119e500c23ee918569e2a58cc5abaa1d8a5a (previously init'd later in another func) but doesn't seem to be needed anyway. None of our code uses the variables that this function defines, just the constants -- which are already predefined without the call. The function is deprecated in PHP 5.3 and gone in 6, so we may as well toss it now. --- lib/common.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index 4958866d0..fbe4216e3 100644 --- a/lib/common.php +++ b/lib/common.php @@ -38,8 +38,6 @@ define('FOREIGN_NOTICE_SEND_REPLY', 4); define('FOREIGN_FRIEND_SEND', 1); define('FOREIGN_FRIEND_RECV', 2); -define_syslog_variables(); - # append our extlib dir as the last-resort place to find libs set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/'); -- cgit v1.2.3-54-g00ecf From ed690615de8f6433a1a4d9a8fc7c28385af47d8a Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 12 Nov 2009 20:12:00 -0500 Subject: Added a User_username table that links the external username with a StatusNet user_id Added EmailAuthenticationPlugin Added ReverseUsernameAuthenticationPlugin Changed the StartChangePassword and EndChangePassword events to take a user, instead of a nickname User::allowed_nickname was declared non-static, but used as if it was static, so I made the declaration static --- EVENTS.txt | 4 +- actions/passwordsettings.php | 4 +- classes/User.php | 16 +- classes/statusnet.ini | 10 ++ index.php | 1 - lib/util.php | 1 + plugins/Authentication/AuthenticationPlugin.php | 177 ++++++++++++++------- plugins/Authentication/User_username.php | 25 +++ .../EmailAuthenticationPlugin.php | 54 +++++++ plugins/EmailAuthentication/README | 7 + .../LdapAuthenticationPlugin.php | 56 +++---- plugins/LdapAuthentication/README | 5 +- plugins/ReverseUsernameAuthentication/README | 26 +++ .../ReverseUsernameAuthenticationPlugin.php | 58 +++++++ 14 files changed, 349 insertions(+), 95 deletions(-) create mode 100644 plugins/Authentication/User_username.php create mode 100644 plugins/EmailAuthentication/EmailAuthenticationPlugin.php create mode 100644 plugins/EmailAuthentication/README create mode 100644 plugins/ReverseUsernameAuthentication/README create mode 100644 plugins/ReverseUsernameAuthentication/ReverseUsernameAuthenticationPlugin.php (limited to 'lib') diff --git a/EVENTS.txt b/EVENTS.txt index 3acff277b..c788a9215 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -528,12 +528,12 @@ EndCheckPassword: After checking a username/password pair - $authenticatedUser: User object if credentials match a user, else null. StartChangePassword: Before changing a password -- $nickname: user's nickname +- $user: user - $oldpassword: the user's old password - $newpassword: the desired new password EndChangePassword: After changing a password -- $nickname: user's nickname +- $user: user UserDeleteRelated: Specify additional tables to delete entries from when deleting users - $user: User object diff --git a/actions/passwordsettings.php b/actions/passwordsettings.php index 9e79501e2..11d7bf785 100644 --- a/actions/passwordsettings.php +++ b/actions/passwordsettings.php @@ -170,7 +170,7 @@ class PasswordsettingsAction extends AccountSettingsAction } $success = false; - if(! Event::handle('StartChangePassword', array($user->nickname, $oldpassword, $newpassword))){ + if(! Event::handle('StartChangePassword', array($user, $oldpassword, $newpassword))){ //no handler changed the password, so change the password internally $original = clone($user); @@ -186,7 +186,7 @@ class PasswordsettingsAction extends AccountSettingsAction $this->serverError(_('Can\'t save new password.')); return; } - Event::handle('EndChangePassword', array($nickname)); + Event::handle('EndChangePassword', array($user)); } $this->showForm(_('Password saved.'), true); diff --git a/classes/User.php b/classes/User.php index 9b90ce61b..9f1ee53f4 100644 --- a/classes/User.php +++ b/classes/User.php @@ -114,7 +114,7 @@ class User extends Memcached_DataObject return $result; } - function allowed_nickname($nickname) + static function allowed_nickname($nickname) { // XXX: should already be validated for size, content, etc. $blacklist = common_config('nickname', 'blacklist'); @@ -190,7 +190,17 @@ class User extends Memcached_DataObject $profile->query('BEGIN'); + if(!empty($email)) + { + $email = common_canonical_email($email); + } + + $nickname = common_canonical_nickname($nickname); $profile->nickname = $nickname; + if(! User::allowed_nickname($nickname)){ + common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname), + __FILE__); + } $profile->profileurl = common_profile_url($nickname); if (!empty($fullname)) { @@ -242,6 +252,10 @@ class User extends Memcached_DataObject } } + if(isset($email_confirmed) && $email_confirmed) { + $user->email = $email; + } + // This flag is ignored but still set to 1 $user->inboxed = 1; diff --git a/classes/statusnet.ini b/classes/statusnet.ini index 912d05cdf..19ab7bf97 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -566,3 +566,13 @@ modified = 384 user_id = K token = K +[user_username] +user_id = 129 +provider_name = 130 +username = 130 +created = 142 +modified = 384 + +[user_username__keys] +provider_name = K +username = K diff --git a/index.php b/index.php index b1e4f651e..577b491ed 100644 --- a/index.php +++ b/index.php @@ -68,7 +68,6 @@ function getPath($req) */ function handleError($error) { -//error_log(print_r($error,1)); if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) { return; } diff --git a/lib/util.php b/lib/util.php index 68f3520db..4b2a25ead 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1058,6 +1058,7 @@ function common_log($priority, $msg, $filename=null) } } else { common_ensure_syslog(); + error_log($msg); syslog($priority, $msg); } } diff --git a/plugins/Authentication/AuthenticationPlugin.php b/plugins/Authentication/AuthenticationPlugin.php index e3e55fea6..99b61b808 100644 --- a/plugins/Authentication/AuthenticationPlugin.php +++ b/plugins/Authentication/AuthenticationPlugin.php @@ -48,20 +48,20 @@ abstract class AuthenticationPlugin extends Plugin //should accounts be automatically created after a successful login attempt? public $autoregistration = false; - //can the user change their email address - public $email_changeable=true; - //can the user change their email address public $password_changeable=true; + //unique name for this authentication provider + public $provider_name; + //------------Auth plugin should implement some (or all) of these methods------------\\ /** * Check if a nickname/password combination is valid - * @param nickname + * @param username * @param password * @return boolean true if the credentials are valid, false if they are invalid. */ - function checkPassword($nickname, $password) + function checkPassword($username, $password) { return false; } @@ -69,88 +69,116 @@ abstract class AuthenticationPlugin extends Plugin /** * Automatically register a user when they attempt to login with valid credentials. * User::register($data) is a very useful method for this implementation - * @param nickname - * @return boolean true if the user was created, false if autoregistration is not allowed, null if this plugin is not responsible for this nickname + * @param username + * @return boolean true if the user was created, false if not */ - function autoRegister($nickname) + function autoRegister($username) { - return null; + $registration_data = array(); + $registration_data['nickname'] = $username ; + return User::register($registration_data); } /** * Change a user's password * The old password has been verified to be valid by this plugin before this call is made - * @param nickname + * @param username * @param oldpassword * @param newpassword - * @return boolean true if the password was changed, false if password changing failed for some reason, null if this plugin is not responsible for this nickname + * @return boolean true if the password was changed, false if password changing failed for some reason */ - function changePassword($nickname,$oldpassword,$newpassword) + function changePassword($username,$oldpassword,$newpassword) { - return null; - } - - /** - * Can a user change this field in his own profile? - * @param nickname - * @param field - * @return boolean true if the field can be changed, false if not allowed to change it, null if this plugin is not responsible for this nickname - */ - function canUserChangeField($nickname, $field) - { - return null; + return false; } //------------Below are the methods that connect StatusNet to the implementing Auth plugin------------\\ - function __construct() - { - parent::__construct(); + function onInitializePlugin(){ + if(!isset($this->provider_name)){ + throw new Exception("must specify a provider_name for this authentication provider"); + } } - + function onStartCheckPassword($nickname, $password, &$authenticatedUser){ - if($this->password_changeable){ - $authenticated = $this->checkPassword($nickname, $password); + //map the nickname to a username + $user_username = new User_username(); + $user_username->username=$nickname; + $user_username->provider_name=$this->provider_name; + if($user_username->find() && $user_username->fetch()){ + $username = $user_username->username; + $authenticated = $this->checkPassword($username, $password); if($authenticated){ - $authenticatedUser = User::staticGet('nickname', $nickname); - if(!$authenticatedUser && $this->autoregistration){ - if($this->autoregister($nickname)){ + $authenticatedUser = User::staticGet('id', $user_username->user_id); + return false; + } + }else{ + $user = User::staticGet('nickname', $nickname); + if($user){ + //make sure a different provider isn't handling this nickname + $user_username = new User_username(); + $user_username->username=$nickname; + if(!$user_username->find()){ + //no other provider claims this username, so it's safe for us to handle it + $authenticated = $this->checkPassword($nickname, $password); + if($authenticated){ $authenticatedUser = User::staticGet('nickname', $nickname); + $user_username = new User_username(); + $user_username->user_id = $authenticatedUser->id; + $user_username->provider_name = $this->provider_name; + $user_username->username = $nickname; + $user_username->created = DB_DataObject_Cast::dateTime(); + $user_username->insert(); + return false; } } - return false; }else{ - if($this->authoritative){ - return false; + if($this->autoregistration){ + $authenticated = $this->checkPassword($nickname, $password); + if($authenticated && $this->autoregister($nickname)){ + $authenticatedUser = User::staticGet('nickname', $nickname); + $user_username = new User_username(); + $user_username->user_id = $authenticatedUser->id; + $user_username->provider_name = $this->provider_name; + $user_username->username = $nickname; + $user_username->created = DB_DataObject_Cast::dateTime(); + $user_username->insert(); + return false; + } } } - //we're not authoritative, so let other handlers try + } + if($this->authoritative){ + return false; }else{ - if($this->authoritative){ - //since we're authoritative, no other plugin could do this - throw new Exception(_('Password changing is not allowed')); - } + //we're not authoritative, so let other handlers try + return; } } - function onStartChangePassword($nickname,$oldpassword,$newpassword) + function onStartChangePassword($user,$oldpassword,$newpassword) { if($this->password_changeable){ - $authenticated = $this->checkPassword($nickname, $oldpassword); - if($authenticated){ - $result = $this->changePassword($nickname,$oldpassword,$newpassword); - if($result){ - //stop handling of other handlers, because what was requested was done - return false; - }else{ - throw new Exception(_('Password changing failed')); - } - }else{ - if($this->authoritative){ - //since we're authoritative, no other plugin could do this - throw new Exception(_('Password changing failed')); + $user_username = new User_username(); + $user_username->user_id=$user->id; + $user_username->provider_name=$this->provider_name; + if($user_username->find() && $user_username->fetch()){ + $authenticated = $this->checkPassword($user_username->username, $oldpassword); + if($authenticated){ + $result = $this->changePassword($user_username->username,$oldpassword,$newpassword); + if($result){ + //stop handling of other handlers, because what was requested was done + return false; + }else{ + throw new Exception(_('Password changing failed')); + } }else{ - //let another handler try - return null; + if($this->authoritative){ + //since we're authoritative, no other plugin could do this + throw new Exception(_('Password changing failed')); + }else{ + //let another handler try + return null; + } } } }else{ @@ -164,9 +192,42 @@ abstract class AuthenticationPlugin extends Plugin function onStartAccountSettingsPasswordMenuItem($widget) { if($this->authoritative && !$this->password_changeable){ - //since we're authoritative, no other plugin could change passwords, so do render the menu item + //since we're authoritative, no other plugin could change passwords, so do not render the menu item + return false; + } + } + + function onAutoload($cls) + { + switch ($cls) + { + case 'User_username': + require_once(INSTALLDIR.'/plugins/Authentication/User_username.php'); return false; + default: + return true; } } + + function onCheckSchema() { + $schema = Schema::get(); + $schema->ensureTable('user_username', + array(new ColumnDef('provider_name', 'varchar', + '255', false, 'PRI'), + new ColumnDef('username', 'varchar', + '255', false, 'PRI'), + new ColumnDef('user_id', 'integer', + null, false), + new ColumnDef('created', 'datetime', + null, false), + new ColumnDef('modified', 'timestamp'))); + return true; + } + + function onUserDeleteRelated($user, &$tables) + { + $tables[] = 'User_username'; + return true; + } } diff --git a/plugins/Authentication/User_username.php b/plugins/Authentication/User_username.php new file mode 100644 index 000000000..79adeb189 --- /dev/null +++ b/plugins/Authentication/User_username.php @@ -0,0 +1,25 @@ +. + * + * @category Plugin + * @package StatusNet + * @author Craig Andrews + * @copyright 2009 Craig Andrews http://candrews.integralblue.com + * @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); +} + +class EmailAuthenticationPlugin extends Plugin +{ + //---interface implementation---// + + function onStartCheckPassword($nickname, $password, &$authenticatedUser) + { + if(strpos($nickname, '@')) + { + $user = User::staticGet('email',$nickname); + if($user && isset($user->email)) + { + if(common_check_user($user->nickname,$password)) + { + $authenticatedUser = $user; + return false; + } + } + } + } +} + diff --git a/plugins/EmailAuthentication/README b/plugins/EmailAuthentication/README new file mode 100644 index 000000000..320815689 --- /dev/null +++ b/plugins/EmailAuthentication/README @@ -0,0 +1,7 @@ +The Email Authentication plugin allows users to login using their email address. + +The provided email address is used to lookup the user's nickname, then that nickname and the provided password is checked. + +Installation +============ +add "addPlugin('emailAuthentication');" to the bottom of your config.php diff --git a/plugins/LdapAuthentication/LdapAuthenticationPlugin.php b/plugins/LdapAuthentication/LdapAuthenticationPlugin.php index ded5cf299..865154730 100644 --- a/plugins/LdapAuthentication/LdapAuthenticationPlugin.php +++ b/plugins/LdapAuthentication/LdapAuthenticationPlugin.php @@ -48,20 +48,31 @@ class LdapAuthenticationPlugin extends AuthenticationPlugin public $scope=null; public $attributes=array(); - function __construct() - { - parent::__construct(); + function onInitializePlugin(){ + parent::onInitializePlugin(); + if(!isset($this->host)){ + throw new Exception("must specify a host"); + } + if(!isset($this->basedn)){ + throw new Exception("must specify a basedn"); + } + if(!isset($this->attributes['nickname'])){ + throw new Exception("must specify a nickname attribute"); + } + if(!isset($this->attributes['username'])){ + throw new Exception("must specify a username attribute"); + } } //---interface implementation---// - function checkPassword($nickname, $password) + function checkPassword($username, $password) { $ldap = $this->ldap_get_connection(); if(!$ldap){ return false; } - $entry = $this->ldap_get_user($nickname); + $entry = $this->ldap_get_user($username); if(!$entry){ return false; }else{ @@ -76,48 +87,33 @@ class LdapAuthenticationPlugin extends AuthenticationPlugin } } - function autoRegister($nickname) + function autoRegister($username) { - $entry = $this->ldap_get_user($nickname,$this->attributes); + $entry = $this->ldap_get_user($username,$this->attributes); if($entry){ $registration_data = array(); foreach($this->attributes as $sn_attribute=>$ldap_attribute){ - if($sn_attribute=='email'){ - $registration_data[$sn_attribute]=common_canonical_email($entry->getValue($ldap_attribute,'single')); - }else if($sn_attribute=='nickname'){ - $registration_data[$sn_attribute]=common_canonical_nickname($entry->getValue($ldap_attribute,'single')); - }else{ - $registration_data[$sn_attribute]=$entry->getValue($ldap_attribute,'single'); - } + $registration_data[$sn_attribute]=$entry->getValue($ldap_attribute,'single'); + } + if(isset($registration_data['email']) && !empty($registration_data['email'])){ + $registration_data['email_confirmed']=true; } //set the database saved password to a random string. $registration_data['password']=common_good_rand(16); - $user = User::register($registration_data); - return true; + return User::register($registration_data); }else{ //user isn't in ldap, so we cannot register him - return null; + return false; } } - function changePassword($nickname,$oldpassword,$newpassword) + function changePassword($username,$oldpassword,$newpassword) { //TODO implement this throw new Exception(_('Sorry, changing LDAP passwords is not supported at this time')); return false; } - - function canUserChangeField($nickname, $field) - { - switch($field) - { - case 'password': - case 'nickname': - case 'email': - return false; - } - } //---utility functions---// function ldap_get_config(){ @@ -159,7 +155,7 @@ class LdapAuthenticationPlugin extends AuthenticationPlugin */ function ldap_get_user($username,$attributes=array()){ $ldap = $this->ldap_get_connection(); - $filter = Net_LDAP2_Filter::create($this->attributes['nickname'], 'equals', $username); + $filter = Net_LDAP2_Filter::create($this->attributes['username'], 'equals', $username); $options = array( 'scope' => 'sub', 'attributes' => $attributes diff --git a/plugins/LdapAuthentication/README b/plugins/LdapAuthentication/README index 03647e7c7..b10a1eb93 100644 --- a/plugins/LdapAuthentication/README +++ b/plugins/LdapAuthentication/README @@ -6,7 +6,8 @@ add "addPlugin('ldapAuthentication', array('setting'=>'value', 'setting2'=>'valu Settings ======== -authoritative (false): Set to true if LDAP's responses are authoritative (meaning if LDAP fails, do check the any other plugins or the internal password database). +provider_name*: a unique name for this authentication provider. +authoritative (false): Set to true if LDAP's responses are authoritative (meaning if LDAP fails, do check any other plugins or the internal password database). autoregistration (false): Set to true if users should be automatically created when they attempt to login. email_changeable (true): Are users allowed to change their email address? (true or false) password_changeable (true): Are users allowed to change their passwords? (true or false) @@ -23,6 +24,7 @@ filter: Default search filter. See http://pear.php.net/manual/en/package.network scope: Default search scope. See http://pear.php.net/manual/en/package.networking.net-ldap2.connecting.php attributes: an array with the key being the StatusNet user attribute name, and the value the LDAP attribute name + username* nickname* email fullname @@ -37,6 +39,7 @@ Example Here's an example of an LDAP plugin configuration that connects to Microsoft Active Directory. addPlugin('ldapAuthentication', array( + 'provider_name'=>'Example', 'authoritative'=>true, 'autoregistration'=>true, 'binddn'=>'username', diff --git a/plugins/ReverseUsernameAuthentication/README b/plugins/ReverseUsernameAuthentication/README new file mode 100644 index 000000000..e9160ed9b --- /dev/null +++ b/plugins/ReverseUsernameAuthentication/README @@ -0,0 +1,26 @@ +The Reverse Username Authentication plugin allows for StatusNet to handle authentication by checking if the provided password is the same as the reverse of the username. + +THIS PLUGIN IS FOR TESTING PURPOSES ONLY + +Installation +============ +add "addPlugin('reverseUsernameAuthentication', array('setting'=>'value', 'setting2'=>'value2', ...);" to the bottom of your config.php + +Settings +======== +provider_name*: a unique name for this authentication provider. +password_changeable*: must be set to false. This plugin does not support changing passwords. +authoritative (false): Set to true if this plugin's responses are authoritative (meaning if this fails, do check any other plugins or the internal password database). +autoregistration (false): Set to true if users should be automatically created when they attempt to login. + +* required +default values are in (parenthesis) + +Example +======= +addPlugin('reverseUsernameAuthentication', array( + 'provider_name'=>'Example', + 'password_changeable'=>false, + 'authoritative'=>true, + 'autoregistration'=>true +)); diff --git a/plugins/ReverseUsernameAuthentication/ReverseUsernameAuthenticationPlugin.php b/plugins/ReverseUsernameAuthentication/ReverseUsernameAuthenticationPlugin.php new file mode 100644 index 000000000..d48283b2e --- /dev/null +++ b/plugins/ReverseUsernameAuthentication/ReverseUsernameAuthenticationPlugin.php @@ -0,0 +1,58 @@ +. + * + * @category Plugin + * @package StatusNet + * @author Craig Andrews + * @copyright 2009 Craig Andrews http://candrews.integralblue.com + * @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/Authentication/AuthenticationPlugin.php'; + +class ReverseUsernameAuthenticationPlugin extends AuthenticationPlugin +{ + //---interface implementation---// + + function onInitializePlugin(){ + parent::onInitializePlugin(); + if(!isset($this->password_changeable) && $this->password_changeable){ + throw new Exception("password_changeable cannot be set to true. This plugin does not support changing passwords."); + } + } + + function checkPassword($username, $password) + { + return $username == strrev($password); + } + + function autoRegister($username) + { + $registration_data = array(); + $registration_data['nickname'] = $username ; + return User::register($registration_data); + } +} -- cgit v1.2.3-54-g00ecf From f60a55d9ec08019c7e1a9b60bc5d34fad61fb088 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 12 Nov 2009 20:15:10 -0500 Subject: blasted, that should not be there --- lib/util.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 4b2a25ead..68f3520db 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1058,7 +1058,6 @@ function common_log($priority, $msg, $filename=null) } } else { common_ensure_syslog(); - error_log($msg); syslog($priority, $msg); } } -- cgit v1.2.3-54-g00ecf From 21603f02258346aa516db77c1691ee32f180fcbc Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 13 Nov 2009 11:28:54 +0100 Subject: Fix typo (!. -> !) --- lib/subs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/subs.php b/lib/subs.php index 934380b76..2f0f97049 100644 --- a/lib/subs.php +++ b/lib/subs.php @@ -121,7 +121,7 @@ function subs_unsubscribe_user($user, $other_nickname) function subs_unsubscribe_to($user, $other) { if (!$user->isSubscribed($other)) - return _('Not subscribed!.'); + return _('Not subscribed!'); $sub = DB_DataObject::factory('subscription'); -- cgit v1.2.3-54-g00ecf From 12d3c44480465b494010f6f1e56d831cf3567f06 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 13 Nov 2009 12:13:38 +0000 Subject: Added hAtom for profile and group lists --- lib/grouplist.php | 6 +++--- lib/profilelist.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/grouplist.php b/lib/grouplist.php index cc734bdd0..99bff9cdc 100644 --- a/lib/grouplist.php +++ b/lib/grouplist.php @@ -85,18 +85,18 @@ class GroupList extends Widget function showGroup() { - $this->out->elementStart('li', array('class' => 'profile', + $this->out->elementStart('li', array('class' => 'profile hentry', 'id' => 'group-' . $this->group->id)); $user = common_current_user(); - $this->out->elementStart('div', 'entity_profile vcard'); + $this->out->elementStart('div', 'entity_profile vcard entry-content'); $logo = ($this->group->stream_logo) ? $this->group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE); $this->out->elementStart('a', array('href' => $this->group->homeUrl(), - 'class' => 'url', + 'class' => 'url entry-title', 'rel' => 'contact group')); $this->out->element('img', array('src' => $logo, 'class' => 'photo avatar', diff --git a/lib/profilelist.php b/lib/profilelist.php index bbb722701..3412d41d1 100644 --- a/lib/profilelist.php +++ b/lib/profilelist.php @@ -76,7 +76,7 @@ class ProfileList extends Widget function startList() { - $this->out->elementStart('ul', 'profiles'); + $this->out->elementStart('ul', 'profiles xoxo'); } function endList() @@ -140,7 +140,7 @@ class ProfileListItem extends Widget function startItem() { - $this->out->elementStart('li', array('class' => 'profile', + $this->out->elementStart('li', array('class' => 'profile hentry', 'id' => 'profile-' . $this->profile->id)); } @@ -175,14 +175,14 @@ class ProfileListItem extends Widget function startProfile() { - $this->out->elementStart('div', 'entity_profile vcard'); + $this->out->elementStart('div', 'entity_profile vcard entry-content'); } function showAvatar() { $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE); $this->out->elementStart('a', array('href' => $this->profile->profileurl, - 'class' => 'url', + 'class' => 'url entry-title', 'rel' => 'contact')); $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE), 'class' => 'photo avatar', -- cgit v1.2.3-54-g00ecf From 1bac324072a2d8d53b7e8c038d781b0af21eb99e Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 13 Nov 2009 12:26:24 +0000 Subject: Moved class="pagination" to child element and removed element --- lib/action.php | 4 +--- plugins/Facebook/facebookaction.php | 4 +--- plugins/Facebook/facebookhome.php | 4 +--- plugins/InfiniteScroll/infinitescroll.js | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/action.php b/lib/action.php index 80f398fbd..b5cf3240c 100644 --- a/lib/action.php +++ b/lib/action.php @@ -1048,8 +1048,7 @@ class Action extends HTMLOutputter // lawsuit { // Does a little before-after block for next/prev page if ($have_before || $have_after) { - $this->elementStart('div', array('class' => 'pagination')); - $this->elementStart('dl', null); + $this->elementStart('dl', 'pagination'); $this->element('dt', null, _('Pagination')); $this->elementStart('dd', null); $this->elementStart('ul', array('class' => 'nav')); @@ -1074,7 +1073,6 @@ class Action extends HTMLOutputter // lawsuit $this->elementEnd('ul'); $this->elementEnd('dd'); $this->elementEnd('dl'); - $this->elementEnd('div'); } } diff --git a/plugins/Facebook/facebookaction.php b/plugins/Facebook/facebookaction.php index a10fdf90d..c852bbf5e 100644 --- a/plugins/Facebook/facebookaction.php +++ b/plugins/Facebook/facebookaction.php @@ -382,8 +382,7 @@ class FacebookAction extends Action { // Does a little before-after block for next/prev page if ($have_before || $have_after) { - $this->elementStart('div', array('class' => 'pagination')); - $this->elementStart('dl', null); + $this->elementStart('dl', 'pagination'); $this->element('dt', null, _('Pagination')); $this->elementStart('dd', null); $this->elementStart('ul', array('class' => 'nav')); @@ -408,7 +407,6 @@ class FacebookAction extends Action $this->elementEnd('ul'); $this->elementEnd('dd'); $this->elementEnd('dl'); - $this->elementEnd('div'); } } diff --git a/plugins/Facebook/facebookhome.php b/plugins/Facebook/facebookhome.php index 91c0cc6b8..ea141c2c2 100644 --- a/plugins/Facebook/facebookhome.php +++ b/plugins/Facebook/facebookhome.php @@ -244,8 +244,7 @@ class FacebookhomeAction extends FacebookAction // XXX: Fix so this uses common_local_url() if possible. if ($have_before || $have_after) { - $this->elementStart('div', array('class' => 'pagination')); - $this->elementStart('dl', null); + $this->elementStart('dl', 'pagination'); $this->element('dt', null, _('Pagination')); $this->elementStart('dd', null); $this->elementStart('ul', array('class' => 'nav')); @@ -270,7 +269,6 @@ class FacebookhomeAction extends FacebookAction $this->elementEnd('ul'); $this->elementEnd('dd'); $this->elementEnd('dl'); - $this->elementEnd('div'); } } diff --git a/plugins/InfiniteScroll/infinitescroll.js b/plugins/InfiniteScroll/infinitescroll.js index ae4d53d09..09b2d4f72 100644 --- a/plugins/InfiniteScroll/infinitescroll.js +++ b/plugins/InfiniteScroll/infinitescroll.js @@ -6,7 +6,7 @@ jQuery(document).ready(function($){ loadingImg : $('address .url')[0].href+'plugins/InfiniteScroll/ajax-loader.gif', text : "Loading the next set of posts...", donetext : "Congratulations, you\'ve reached the end of the Internet.", - navSelector : "div.pagination", + navSelector : ".pagination", contentSelector : "#notices_primary ol.notices", itemSelector : "#notices_primary ol.notices li" },function(){ -- cgit v1.2.3-54-g00ecf From 2147ac510f5489c860a4bebf3ab48a069b89ecfb Mon Sep 17 00:00:00 2001 From: brenda Date: Sat, 14 Nov 2009 16:52:39 +1300 Subject: don't offer install.php on check-fancy requests this time, E_STRICT compliant --- lib/common.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index fbe4216e3..4524d50fa 100644 --- a/lib/common.php +++ b/lib/common.php @@ -19,6 +19,9 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +//exit with 200 response, if this is checking fancy from the installer +if (isset($_REQUEST['p']) && $_REQUEST['p'] == 'check-fancy') { exit; } + define('STATUSNET_VERSION', '0.9.0dev'); define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility -- cgit v1.2.3-54-g00ecf From fe18063bd2bb00ac67d4afc038850cd3a7a63189 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 14 Nov 2009 17:38:10 +0100 Subject: Revert "Ask users if they wish to send statistics to SNI, default is off." This reverts commit 7efea1115f45b8880fe3161cc32b09510ddd2264. Conflicts: install.php --- install.php | 16 ++++------------ lib/default.php | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/install.php b/install.php index 8e76f6198..e7f7cf318 100644 --- a/install.php +++ b/install.php @@ -1,3 +1,4 @@ + * @author CiaranG * @author Craig Andrews - * @author Eric Helgeson + * @author Eric Helgeson * @author Evan Prodromou * @author Robin Millette * @author Sarven Capadisli @@ -499,11 +500,6 @@ function showForm()

    Database password (optional)

  • -
  • - - -

    Periodically send information about your site to StatusNet Inc

    -
  • @@ -525,7 +521,6 @@ function handlePost() $username = $_POST['username']; $password = $_POST['password']; $sitename = $_POST['sitename']; - $snapshot = $_POST['snapshot']; $fancy = !empty($_POST['fancy']); $server = $_SERVER['HTTP_HOST']; $path = substr(dirname($_SERVER['PHP_SELF']), 1); @@ -572,7 +567,7 @@ STR; } updateStatus("Writing config file..."); - $res = writeConf($sitename, $server, $path, $fancy, $db, $snapshot); + $res = writeConf($sitename, $server, $path, $fancy, $db); if (!$res) { updateStatus("Can't write config file.", true); @@ -693,7 +688,7 @@ function Mysql_Db_installer($host, $database, $username, $password) return $db; } -function writeConf($sitename, $server, $path, $fancy, $db, $snapshot) +function writeConf($sitename, $server, $path, $fancy, $db) { // assemble configuration file in a string $cfg = " null, 'welcome' => null), 'snapshot' => - array('run' => 'never', + array('run' => 'web', 'frequency' => 10000, 'reporturl' => 'http://status.net/stats/report'), 'attachments' => -- cgit v1.2.3-54-g00ecf From 133ca0ef6b13d4d693c2e03b831cc75517f89227 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 14 Nov 2009 13:10:47 -0800 Subject: Fix regression from 9f372da3da4bd445175eda9155fa7fdd13d3c85e: typo in refactoring caused fatal error on unrecognized message source --- lib/mailbox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mailbox.php b/lib/mailbox.php index e1d384a06..90a58b4c4 100644 --- a/lib/mailbox.php +++ b/lib/mailbox.php @@ -282,7 +282,7 @@ class MailboxAction extends CurrentUserDesignAction $ns->name); $this->elementEnd('span'); } else { - $this->out->element('span', 'device', $source_name); + $this->element('span', 'device', $source_name); } break; } -- cgit v1.2.3-54-g00ecf From e9225fabddb4c7dc2fef2c66b4ba3ecfd8c2f07d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 15 Nov 2009 15:57:37 +0100 Subject: common superclass for forms that operate on a profile --- lib/profileactionform.php | 187 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 lib/profileactionform.php (limited to 'lib') diff --git a/lib/profileactionform.php b/lib/profileactionform.php new file mode 100644 index 000000000..fb183b6b6 --- /dev/null +++ b/lib/profileactionform.php @@ -0,0 +1,187 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Superclass for forms that operate on a profile + * + * Certain forms (block, silence, userflag, sandbox, delete) work on + * a single profile and work almost the same. So, this form extracts + * a lot of the common code to simplify those forms. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class ProfileActionForm extends Form +{ + /** + * Profile of user to act on + */ + + var $profile = null; + + /** + * Return-to args + */ + + var $args = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to act on + * @param array $args return-to args + */ + + function __construct($out=null, $profile=null, $args=null) + { + parent::__construct($out); + + $this->profile = $profile; + $this->args = $args; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return $this->target() . '-' . $this->profile->id; + } + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_user_'.$this->target(); + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url($this->target()); + } + + /** + * Legend of the Form + * + * @return void + */ + + function formLegend() + { + $this->out->element('legend', null, $this->description()); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $action = $this->target(); + + $this->out->hidden($action.'to-' . $this->profile->id, + $this->profile->id, + $action.'to'); + + if ($this->args) { + foreach ($this->args as $k => $v) { + $this->out->hidden('returnto-' . $k, $v); + } + } + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', $this->title(), 'submit', + null, $this->description()); + } + + /** + * Action this form targets + * + * @return string Name of the action, lowercased. + */ + + function target() + { + return null; + } + + /** + * Title of the form + * + * @return string Title of the form, internationalized + */ + + function title() + { + return null; + } + + /** + * Description of the form + * + * @return string description of the form, internationalized + */ + + function description() + { + return null; + } +} -- cgit v1.2.3-54-g00ecf From d5032fc3a31b2c31f3c90112a0c5519ba7ec7f11 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 15 Nov 2009 15:57:52 +0100 Subject: blockform uses profileactionform --- lib/blockform.php | 99 ++++++++----------------------------------------------- 1 file changed, 13 insertions(+), 86 deletions(-) (limited to 'lib') diff --git a/lib/blockform.php b/lib/blockform.php index 4820d09af..b6652b1f6 100644 --- a/lib/blockform.php +++ b/lib/blockform.php @@ -32,8 +32,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/form.php'; - /** * Form for blocking a user * @@ -47,109 +45,38 @@ require_once INSTALLDIR.'/lib/form.php'; * @see UnblockForm */ -class BlockForm extends Form +class BlockForm extends ProfileActionForm { /** - * Profile of user to block - */ - - var $profile = null; - - /** - * Return-to args - */ - - var $args = null; - - /** - * Constructor + * Action this form provides * - * @param HTMLOutputter $out output channel - * @param Profile $profile profile of user to block - * @param array $args return-to args + * @return string Name of the action, lowercased. */ - function __construct($out=null, $profile=null, $args=null) + function target() { - parent::__construct($out); - - $this->profile = $profile; - $this->args = $args; + return 'block'; } /** - * ID of the form - * - * @return int ID of the form - */ - - function id() - { - return 'block-' . $this->profile->id; - } - - - /** - * class of the form - * - * @return string class of the form - */ - - function formClass() - { - return 'form_user_block'; - } - - - /** - * Action of the form - * - * @return string URL of the action - */ - - function action() - { - return common_local_url('block'); - } - - - /** - * Legend of the Form - * - * @return void - */ - function formLegend() - { - $this->out->element('legend', null, _('Block this user')); - } - - - /** - * Data elements of the form + * Title of the form * - * @return void + * @return string Title of the form, internationalized */ - function formData() + function title() { - $this->out->hidden('blockto-' . $this->profile->id, - $this->profile->id, - 'blockto'); - if ($this->args) { - foreach ($this->args as $k => $v) { - $this->out->hidden('returnto-' . $k, $v); - } - } + return _('Block'); } /** - * Action elements + * Description of the form * - * @return void + * @return string description of the form, internationalized */ - function formActions() + function description() { - $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user')); + return _('Block this user'); } } -- cgit v1.2.3-54-g00ecf From e3b53565bb5744116811cd88dbe67ae8df7547fd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 15 Nov 2009 15:57:59 +0100 Subject: unblockform uses profileactionform --- lib/unblockform.php | 98 ++++++++--------------------------------------------- 1 file changed, 14 insertions(+), 84 deletions(-) (limited to 'lib') diff --git a/lib/unblockform.php b/lib/unblockform.php index f1343757c..4fe28b21a 100644 --- a/lib/unblockform.php +++ b/lib/unblockform.php @@ -28,12 +28,10 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { +if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR.'/lib/form.php'; - /** * Form for unblocking a user * @@ -47,106 +45,38 @@ require_once INSTALLDIR.'/lib/form.php'; * @see BlockForm */ -class UnblockForm extends Form +class UnblockForm extends ProfileActionForm { /** - * Profile of user to unblock - */ - - var $profile = null; - - /** - * Return-to args - */ - - var $args = null; - - /** - * Constructor - * - * @param HTMLOutputter $out output channel - * @param Profile $profile profile of user to unblock - * @param array $args return-to args - */ - - function __construct($out=null, $profile=null, $args=null) - { - parent::__construct($out); - - $this->profile = $profile; - $this->args = $args; - } - - /** - * ID of the form - * - * @return int ID of the form - */ - - function id() - { - return 'unblock-' . $this->profile->id; - } - - /** - * class of the form + * Action this form provides * - * @return string class of the form + * @return string Name of the action, lowercased. */ - function formClass() + function target() { - return 'form_user_unblock'; + return 'unblock'; } /** - * Action of the form - * - * @return string URL of the action - */ - - function action() - { - return common_local_url('unblock'); - } - - /** - * Legend of the Form - * - * @return void - */ - function formLegend() - { - $this->out->element('legend', null, _('Unblock this user')); - } - - - /** - * Data elements of the form + * Title of the form * - * @return void + * @return string Title of the form, internationalized */ - function formData() + function title() { - $this->out->hidden('unblockto-' . $this->profile->id, - $this->profile->id, - 'unblockto'); - if ($this->args) { - foreach ($this->args as $k => $v) { - $this->out->hidden('returnto-' . $k, $v); - } - } + return _('Unblock'); } /** - * Action elements + * Description of the form * - * @return void + * @return string description of the form, internationalized */ - function formActions() + function description() { - $this->out->submit('submit', _('Unblock'), 'submit', null, _('Unblock this user')); + return _('Unlock this user'); } } -- cgit v1.2.3-54-g00ecf From c9475c76a8b4c2bf32d1d3293b03b646e7e7a91e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 15 Nov 2009 15:59:10 +0100 Subject: define rights around how to silence, sandbox, and delete a user --- classes/User.php | 14 ++++++++++++++ classes/User_role.php | 2 ++ lib/right.php | 3 +++ 3 files changed, 19 insertions(+) (limited to 'lib') diff --git a/classes/User.php b/classes/User.php index 9f1ee53f4..0e8404377 100644 --- a/classes/User.php +++ b/classes/User.php @@ -720,10 +720,14 @@ class User extends Memcached_DataObject switch ($right) { case Right::DELETEOTHERSNOTICE: + case Right::SANDBOXUSER: + case Right::SILENCEUSER: + case Right::DELETEUSER: $result = $this->hasRole(User_role::MODERATOR); break; case Right::CONFIGURESITE: $result = $this->hasRole(User_role::ADMINISTRATOR); + break; default: $result = false; break; @@ -774,4 +778,14 @@ class User extends Memcached_DataObject $block->delete(); // XXX delete group block? Reset blocker? } + + function isSandboxed() + { + return $this->hasRole(User_role::SANDBOXED); + } + + function isSilenced() + { + return $this->hasRole(User_role::SILENCED); + } } diff --git a/classes/User_role.php b/classes/User_role.php index fc3806897..b415642fc 100644 --- a/classes/User_role.php +++ b/classes/User_role.php @@ -48,4 +48,6 @@ class User_role extends Memcached_DataObject const MODERATOR = 'moderator'; const ADMINISTRATOR = 'administrator'; + const SANDBOXED = 'sandboxed'; + const SILENCED = 'silenced'; } diff --git a/lib/right.php b/lib/right.php index 4fc981af0..88abdf780 100644 --- a/lib/right.php +++ b/lib/right.php @@ -47,5 +47,8 @@ class Right { const DELETEOTHERSNOTICE = 'deleteothersnotice'; const CONFIGURESITE = 'configuresite'; + const DELETEUSER = 'deleteuser'; + const SILENCEUSER = 'silenceuser'; + const SANDBOXUSER = 'sandboxuser'; } -- cgit v1.2.3-54-g00ecf From d24ed193e7b19b50f7304790820c945e46ac2c95 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 15 Nov 2009 16:00:29 +0100 Subject: add forms for silence, sandbox, delete user --- lib/deleteuserform.php | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/sandboxform.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/silenceform.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/unsandboxform.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/unsilenceform.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/userprofile.php | 44 +++++++++++++++++++++++---- 6 files changed, 439 insertions(+), 6 deletions(-) create mode 100644 lib/deleteuserform.php create mode 100644 lib/sandboxform.php create mode 100644 lib/silenceform.php create mode 100644 lib/unsandboxform.php create mode 100644 lib/unsilenceform.php (limited to 'lib') diff --git a/lib/deleteuserform.php b/lib/deleteuserform.php new file mode 100644 index 000000000..09ea8f68d --- /dev/null +++ b/lib/deleteuserform.php @@ -0,0 +1,79 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Form for deleting a user + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + */ + +class DeleteUserForm extends ProfileActionForm +{ + /** + * Action this form provides + * + * @return string Name of the action, lowercased. + */ + + function target() + { + return 'deleteuser'; + } + + /** + * Title of the form + * + * @return string Title of the form, internationalized + */ + + function title() + { + return _('Delete'); + } + + /** + * Description of the form + * + * @return string description of the form, internationalized + */ + + function description() + { + return _('Delete this user'); + } +} diff --git a/lib/sandboxform.php b/lib/sandboxform.php new file mode 100644 index 000000000..7a98e0a5f --- /dev/null +++ b/lib/sandboxform.php @@ -0,0 +1,80 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Form for sandboxing a user + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see UnSandboxForm + */ + +class SandboxForm extends ProfileActionForm +{ + /** + * Action this form provides + * + * @return string Name of the action, lowercased. + */ + + function target() + { + return 'sandbox'; + } + + /** + * Title of the form + * + * @return string Title of the form, internationalized + */ + + function title() + { + return _('Sandbox'); + } + + /** + * Description of the form + * + * @return string description of the form, internationalized + */ + + function description() + { + return _('Sandbox this user'); + } +} diff --git a/lib/silenceform.php b/lib/silenceform.php new file mode 100644 index 000000000..c9cf4b057 --- /dev/null +++ b/lib/silenceform.php @@ -0,0 +1,80 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Form for silencing a user + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see UnSilenceForm + */ + +class SilenceForm extends Form +{ + /** + * Action this form provides + * + * @return string Name of the action, lowercased. + */ + + function target() + { + return 'silence'; + } + + /** + * Title of the form + * + * @return string Title of the form, internationalized + */ + + function title() + { + return _('Silence'); + } + + /** + * Description of the form + * + * @return string description of the form, internationalized + */ + + function description() + { + return _('Silence this user'); + } +} diff --git a/lib/unsandboxform.php b/lib/unsandboxform.php new file mode 100644 index 000000000..559d1462d --- /dev/null +++ b/lib/unsandboxform.php @@ -0,0 +1,82 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Form for unsandboxing a user + * + * Removes the "sandboxed" role for a user. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see UnSandboxForm + */ + +class UnsandboxForm extends Form +{ + /** + * Action this form provides + * + * @return string Name of the action, lowercased. + */ + + function target() + { + return 'unsandbox'; + } + + /** + * Title of the form + * + * @return string Title of the form, internationalized + */ + + function title() + { + return _('Unsandbox'); + } + + /** + * Description of the form + * + * @return string description of the form, internationalized + */ + + function description() + { + return _('Unsandbox this user'); + } +} diff --git a/lib/unsilenceform.php b/lib/unsilenceform.php new file mode 100644 index 000000000..324d278b9 --- /dev/null +++ b/lib/unsilenceform.php @@ -0,0 +1,80 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Form for unsilencing a user + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see UnSilenceForm + */ + +class UnSilenceForm extends Form +{ + /** + * Action this form provides + * + * @return string Name of the action, lowercased. + */ + + function target() + { + return 'unsilence'; + } + + /** + * Title of the form + * + * @return string Title of the form, internationalized + */ + + function title() + { + return _('Unsilence'); + } + + /** + * Description of the form + * + * @return string description of the form, internationalized + */ + + function description() + { + return _('Unsilence this user'); + } +} diff --git a/lib/userprofile.php b/lib/userprofile.php index 4f9d4984f..4321a2f93 100644 --- a/lib/userprofile.php +++ b/lib/userprofile.php @@ -283,22 +283,54 @@ class UserProfile extends Widget } } + // return-to args, so we don't have to keep re-writing them + + $r2args = array('action' => 'showstream', + 'nickname' => $this->profile->nickname); + // block/unblock $blocked = $cur->hasBlocked($this->profile); $this->out->elementStart('li', 'entity_block'); if ($blocked) { - $ubf = new UnblockForm($this->out, $this->profile, - array('action' => 'showstream', - 'nickname' => $this->profile->nickname)); + $ubf = new UnblockForm($this->out, $this->profile, $r2args); $ubf->show(); } else { - $bf = new BlockForm($this->out, $this->profile, - array('action' => 'showstream', - 'nickname' => $this->profile->nickname)); + $bf = new BlockForm($this->out, $this->profile, $r2args); $bf->show(); } $this->out->elementEnd('li'); + + if ($cur->hasRight(Right::SANDBOXUSER)) { + $this->out->elementStart('li', 'entity_sandbox'); + if ($this->user->isSandboxed()) { + $usf = new UnSandboxForm($this->out, $this->profile, $r2args); + $usf->show(); + } else { + $sf = new SandboxForm($this->out, $this->profile, $r2args); + $sf->show(); + } + $this->out->elementEnd('li'); + } + + if ($cur->hasRight(Right::SILENCEUSER)) { + $this->out->elementStart('li', 'entity_silence'); + if ($this->user->isSilenced()) { + $usf = new UnSilenceForm($this->out, $this->profile, $r2args); + $usf->show(); + } else { + $sf = new SilenceForm($this->out, $this->profile, $r2args); + $sf->show(); + } + $this->out->elementEnd('li'); + } + + if ($cur->hasRight(Right::DELETEUSER)) { + $this->out->elementStart('li', 'entity_delete'); + $df = DeleteUserForm($this->out, $this->profile, $r2args); + $df->show(); + $this->out->elementEnd('li'); + } } } -- cgit v1.2.3-54-g00ecf From f04dbc8fa21d86bae5c34ece2637c3c345e29927 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Mon, 16 Nov 2009 00:19:47 -0500 Subject: Add "followers" and "following" commands --- lib/command.php | 40 ++++++++++++++++++++++++++++++++++++++++ lib/commandinterpreter.php | 12 ++++++++++++ 2 files changed, 52 insertions(+) (limited to 'lib') diff --git a/lib/command.php b/lib/command.php index 2ec3320de..c4a4f7cf4 100644 --- a/lib/command.php +++ b/lib/command.php @@ -605,6 +605,44 @@ class LoginCommand extends Command } } +class FollowingCommand extends Command +{ + function execute($channel) + { + $profile = $this->user->getSubscriptions(0); + $nicknames=array(); + while ($profile->fetch()) { + $nicknames[]=$profile->nickname; + } + if(count($nicknames)==0){ + $out=_('You are not subscribed to anyone.'); + }else{ + $out=_('You are subscribed to these people: '); + $out.=implode(', ',$nicknames); + } + $channel->output($this->user,$out); + } +} + +class FollowersCommand extends Command +{ + function execute($channel) + { + $profile = $this->user->getSubscribers(); + $nicknames=array(); + while ($profile->fetch()) { + $nicknames[]=$profile->nickname; + } + if(count($nicknames)==0){ + $out=_('No one is subscribed to you.'); + }else{ + $out=_('These people are subscribed to you: '); + $out.=implode(', ',$nicknames); + } + $channel->output($this->user,$out); + } +} + class HelpCommand extends Command { function execute($channel) @@ -615,6 +653,8 @@ class HelpCommand extends Command "off - turn off notifications\n". "help - show this help\n". "follow - subscribe to user\n". + "following - list the people you follow\n". + "followers - list the people that follow you\n". "leave - unsubscribe from user\n". "d - direct message to user\n". "get - get last notice from user\n". diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index d878fe268..ecc08f101 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -47,6 +47,18 @@ class CommandInterpreter } else { return new LoginCommand($user); } + case 'followers': + if ($arg) { + return null; + } else { + return new FollowersCommand($user); + } + case 'following': + if ($arg) { + return null; + } else { + return new FollowingCommand($user); + } case 'on': if ($arg) { list($other, $extra) = $this->split_arg($arg); -- cgit v1.2.3-54-g00ecf From 64677fc09a54546274a001ce9bec0fa4bc8132f7 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 14:28:58 +0100 Subject: common superclass for actions that operate on a profile and return --- lib/profileactionform.php | 2 +- lib/profileformaction.php | 139 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 lib/profileformaction.php (limited to 'lib') diff --git a/lib/profileactionform.php b/lib/profileactionform.php index fb183b6b6..24d4595c0 100644 --- a/lib/profileactionform.php +++ b/lib/profileactionform.php @@ -131,7 +131,7 @@ class ProfileActionForm extends Form $this->out->hidden($action.'to-' . $this->profile->id, $this->profile->id, - $action.'to'); + 'profileid'); if ($this->args) { foreach ($this->args as $k => $v) { diff --git a/lib/profileformaction.php b/lib/profileformaction.php new file mode 100644 index 000000000..92e8611b9 --- /dev/null +++ b/lib/profileformaction.php @@ -0,0 +1,139 @@ +. + * + * @category Action + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +/** + * Superclass for actions that operate on a user + * + * @category Action + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ + +class ProfileFormAction extends Action +{ + var $profile = null; + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + + $this->checkSessionToken(); + + if (!common_logged_in()) { + $this->clientError(_('Not logged in.')); + return false; + } + + $id = $this->trimmed('profileid'); + + if (!$id) { + $this->clientError(_('No profile specified.')); + return false; + } + + $this->profile = Profile::staticGet('id', $id); + + if (!$this->profile) { + $this->clientError(_('No profile with that ID.')); + return false; + } + + return true; + } + + /** + * Handle request + * + * Shows a page with list of favorite notices + * + * @param array $args $_REQUEST args; handled in prepare() + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->handlePost(); + $this->returnToArgs(); + } + } + + /** + * Return to the calling page based on hidden arguments + * + * @return void + */ + + function returnToArgs() + { + foreach ($this->args as $k => $v) { + if ($k == 'returnto-action') { + $action = $v; + } else if (substr($k, 0, 9) == 'returnto-') { + $args[substr($k, 9)] = $v; + } + } + + if ($action) { + common_redirect(common_local_url($action, $args), 303); + } else { + $this->clientError(_("No return-to arguments")); + } + } + + /** + * handle a POST request + * + * sub-classes should overload this request + * + * @return void + */ + + function handlePost() + { + return; + } +} -- cgit v1.2.3-54-g00ecf From ff88ef407a344749c02d9d1d0dc104b4b720d7ae Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 14:40:04 +0100 Subject: make block actions use profileformaction superclass --- actions/block.php | 6 ++-- actions/unblock.php | 72 +++++++++-------------------------------------- lib/profileformaction.php | 2 +- 3 files changed, 17 insertions(+), 63 deletions(-) (limited to 'lib') diff --git a/actions/block.php b/actions/block.php index b125d2d8b..2443b3010 100644 --- a/actions/block.php +++ b/actions/block.php @@ -64,7 +64,7 @@ class BlockAction extends Action $this->clientError(_('There was a problem with your session token. Try again, please.')); return; } - $id = $this->trimmed('blockto'); + $id = $this->trimmed('profileid'); if (!$id) { $this->clientError(_('No profile specified.')); return false; @@ -97,7 +97,7 @@ class BlockAction extends Action 303); } elseif ($this->arg('yes')) { $this->blockProfile(); - } elseif ($this->arg('blockto')) { + } else { $this->showPage(); } } @@ -138,7 +138,7 @@ class BlockAction extends Action 'unable to subscribe to you in the future, and '. 'you will not be notified of any @-replies from them.')); $this->element('input', array('id' => 'blockto-' . $id, - 'name' => 'blockto', + 'name' => 'profileid', 'type' => 'hidden', 'value' => $id)); foreach ($this->args as $k => $v) { diff --git a/actions/unblock.php b/actions/unblock.php index dc28d5d54..c60458cd3 100644 --- a/actions/unblock.php +++ b/actions/unblock.php @@ -42,57 +42,25 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://status.net/ */ -class UnblockAction extends Action -{ - var $profile = null; - /** - * Take arguments for running - * - * @param array $args $_REQUEST args - * - * @return boolean success flag - */ +class UnblockAction extends ProfileFormAction +{ function prepare($args) { - parent::prepare($args); - if (!common_logged_in()) { - $this->clientError(_('Not logged in.')); - return false; - } - $token = $this->trimmed('token'); - if (!$token || $token != common_session_token()) { - $this->clientError(_('There was a problem with your session token. Try again, please.')); - return; - } - $id = $this->trimmed('unblockto'); - if (!$id) { - $this->clientError(_('No profile specified.')); + if (!parent::prepare($args)) { return false; } - $this->profile = Profile::staticGet('id', $id); - if (!$this->profile) { - $this->clientError(_('No profile with that ID.')); + + $cur = common_current_user(); + + assert(!empty($cur)); // checked by parent + + if (!$cur->hasBlocked($this->profile)) { + $this->clientError(_("You haven't blocked that user.")); return false; } - return true; - } - /** - * Handle request - * - * Shows a page with list of favorite notices - * - * @param array $args $_REQUEST args; handled in prepare() - * - * @return void - */ - function handle($args) - { - parent::handle($args); - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $this->unblockProfile(); - } + return true; } /** @@ -100,7 +68,8 @@ class UnblockAction extends Action * * @return void */ - function unblockProfile() + + function handlePost() { $cur = common_current_user(); $result = $cur->unblock($this->profile); @@ -108,20 +77,5 @@ class UnblockAction extends Action $this->serverError(_('Error removing the block.')); return; } - foreach ($this->args as $k => $v) { - if ($k == 'returnto-action') { - $action = $v; - } else if (substr($k, 0, 9) == 'returnto-') { - $args[substr($k, 9)] = $v; - } - } - if ($action) { - common_redirect(common_local_url($action, $args), 303); - } else { - common_redirect(common_local_url('subscribers', - array('nickname' => $cur->nickname)), - 303); - } } } - diff --git a/lib/profileformaction.php b/lib/profileformaction.php index 92e8611b9..8cb5f6a93 100644 --- a/lib/profileformaction.php +++ b/lib/profileformaction.php @@ -134,6 +134,6 @@ class ProfileFormAction extends Action function handlePost() { - return; + $this->serverError(_("unimplemented method")); } } -- cgit v1.2.3-54-g00ecf From d968b5b4f1db223c7fc8c105526e08ca64877c21 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 17:05:03 +0100 Subject: give SilenceForm proper superclass --- lib/silenceform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/silenceform.php b/lib/silenceform.php index c9cf4b057..9673fa120 100644 --- a/lib/silenceform.php +++ b/lib/silenceform.php @@ -43,7 +43,7 @@ if (!defined('STATUSNET')) { * @see UnSilenceForm */ -class SilenceForm extends Form +class SilenceForm extends ProfileActionForm { /** * Action this form provides -- cgit v1.2.3-54-g00ecf From 9cc0d6524073b0a997289c0998443d25130730f2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 17:05:31 +0100 Subject: give UnsandboxForm correct superclass --- lib/unsandboxform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/unsandboxform.php b/lib/unsandboxform.php index 559d1462d..a77634244 100644 --- a/lib/unsandboxform.php +++ b/lib/unsandboxform.php @@ -45,7 +45,7 @@ if (!defined('STATUSNET')) { * @see UnSandboxForm */ -class UnsandboxForm extends Form +class UnsandboxForm extends ProfileActionForm { /** * Action this form provides -- cgit v1.2.3-54-g00ecf From ee5c9a5c9084a4ebf16e1aef7bb073bbf7c629da Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 17:05:39 +0100 Subject: give UnsilenceForm correct superclass --- lib/unsilenceform.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/unsilenceform.php b/lib/unsilenceform.php index 324d278b9..ac02b8b6c 100644 --- a/lib/unsilenceform.php +++ b/lib/unsilenceform.php @@ -40,10 +40,10 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ * - * @see UnSilenceForm + * @see SilenceForm */ -class UnSilenceForm extends Form +class UnSilenceForm extends ProfileActionForm { /** * Action this form provides -- cgit v1.2.3-54-g00ecf From a723cc979b5f93d6b688c5d19522cb27fa6c17eb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 17:06:12 +0100 Subject: correct constructor for DeleteUserForm --- lib/userprofile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/userprofile.php b/lib/userprofile.php index 4321a2f93..dedac5bf1 100644 --- a/lib/userprofile.php +++ b/lib/userprofile.php @@ -327,7 +327,7 @@ class UserProfile extends Widget if ($cur->hasRight(Right::DELETEUSER)) { $this->out->elementStart('li', 'entity_delete'); - $df = DeleteUserForm($this->out, $this->profile, $r2args); + $df = new DeleteUserForm($this->out, $this->profile, $r2args); $df->show(); $this->out->elementEnd('li'); } -- cgit v1.2.3-54-g00ecf From 4f9f3665f7958a6c56279e70de8f987728554d8d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 17:06:35 +0100 Subject: add routes for silence, sandbox, delete user --- lib/router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/router.php b/lib/router.php index bad3decad..53f30dd3e 100644 --- a/lib/router.php +++ b/lib/router.php @@ -96,7 +96,10 @@ class Router 'unsubscribe', 'confirmaddress', 'recoverpassword', 'invite', 'favor', 'disfavor', 'sup', 'block', 'unblock', 'subedit', - 'groupblock', 'groupunblock'); + 'groupblock', 'groupunblock', + 'sandbox', 'unsandbox', + 'silence', 'unsilence', + 'deleteuser'); foreach ($main as $a) { $m->connect('main/'.$a, array('action' => $a)); -- cgit v1.2.3-54-g00ecf From 73b4d770a2551018ea17d115d980972dc5f0865a Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Mon, 16 Nov 2009 11:17:14 -0500 Subject: Changed to StatusNet consistent terminology --- lib/command.php | 8 ++++---- lib/commandinterpreter.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/command.php b/lib/command.php index c4a4f7cf4..247ea4475 100644 --- a/lib/command.php +++ b/lib/command.php @@ -605,7 +605,7 @@ class LoginCommand extends Command } } -class FollowingCommand extends Command +class SubscriptionsCommand extends Command { function execute($channel) { @@ -624,7 +624,7 @@ class FollowingCommand extends Command } } -class FollowersCommand extends Command +class SubscribersCommand extends Command { function execute($channel) { @@ -653,8 +653,8 @@ class HelpCommand extends Command "off - turn off notifications\n". "help - show this help\n". "follow - subscribe to user\n". - "following - list the people you follow\n". - "followers - list the people that follow you\n". + "subscriptions - list the people you follow\n". + "subscribers - list the people that follow you\n". "leave - unsubscribe from user\n". "d - direct message to user\n". "get - get last notice from user\n". diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index ecc08f101..c39fafb62 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -47,17 +47,17 @@ class CommandInterpreter } else { return new LoginCommand($user); } - case 'followers': + case 'subscribers': if ($arg) { return null; } else { - return new FollowersCommand($user); + return new SubscribersCommand($user); } - case 'following': + case 'subscriptions': if ($arg) { return null; } else { - return new FollowingCommand($user); + return new SubscriptionsCommand($user); } case 'on': if ($arg) { -- cgit v1.2.3-54-g00ecf From 0e7dd81a6cf38c879f24f476411104d67b9eb177 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Mon, 16 Nov 2009 11:23:00 -0500 Subject: Added a "groups" command --- lib/command.php | 20 ++++++++++++++++++++ lib/commandinterpreter.php | 6 ++++++ 2 files changed, 26 insertions(+) (limited to 'lib') diff --git a/lib/command.php b/lib/command.php index 247ea4475..0c98c94ac 100644 --- a/lib/command.php +++ b/lib/command.php @@ -643,6 +643,25 @@ class SubscribersCommand extends Command } } +class GroupsCommand extends Command +{ + function execute($channel) + { + $group = $this->user->getGroups(); + $groups=array(); + while ($group->fetch()) { + $groups[]=$group->nickname; + } + if(count($groups)==0){ + $out=_('You are not a member of any groups.'); + }else{ + $out=_('You are a member of these groups: '); + $out.=implode(', ',$groups); + } + $channel->output($this->user,$out); + } +} + class HelpCommand extends Command { function execute($channel) @@ -653,6 +672,7 @@ class HelpCommand extends Command "off - turn off notifications\n". "help - show this help\n". "follow - subscribe to user\n". + "groups - lists the groups you have joined\n". "subscriptions - list the people you follow\n". "subscribers - list the people that follow you\n". "leave - unsubscribe from user\n". diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index c39fafb62..665015afc 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -59,6 +59,12 @@ class CommandInterpreter } else { return new SubscriptionsCommand($user); } + case 'groups': + if ($arg) { + return null; + } else { + return new GroupsCommand($user); + } case 'on': if ($arg) { list($other, $extra) = $this->split_arg($arg); -- cgit v1.2.3-54-g00ecf From 968058c68b0d23e3dccc85301d78dccf8bcc0ba1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 17:54:34 +0100 Subject: getting arguments for return-to processing --- lib/action.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/action.php b/lib/action.php index b5cf3240c..4c1e73564 100644 --- a/lib/action.php +++ b/lib/action.php @@ -985,6 +985,18 @@ class Action extends HTMLOutputter // lawsuit */ function selfUrl() + { + list($action, $args) = $this->returnToArgs(); + return common_local_url($action, $args); + } + + /** + * Returns arguments sufficient for re-constructing URL + * + * @return array two elements: action, other args + */ + + function returnToArgs() { $action = $this->trimmed('action'); $args = $this->args; @@ -998,8 +1010,7 @@ class Action extends HTMLOutputter // lawsuit foreach (array_keys($_COOKIE) as $cookie) { unset($args[$cookie]); } - - return common_local_url($action, $args); + return array($action, $args); } /** -- cgit v1.2.3-54-g00ecf From 0580e824f0d650d9f9091be131916945951faba5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 17:54:50 +0100 Subject: use return-to method for UserProfile widget --- lib/userprofile.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/userprofile.php b/lib/userprofile.php index dedac5bf1..ee205af85 100644 --- a/lib/userprofile.php +++ b/lib/userprofile.php @@ -285,8 +285,11 @@ class UserProfile extends Widget // return-to args, so we don't have to keep re-writing them - $r2args = array('action' => 'showstream', - 'nickname' => $this->profile->nickname); + list($action, $r2args) = $this->out->returnToArgs(); + + // push the action into the list + + $r2args['action'] = $action; // block/unblock -- cgit v1.2.3-54-g00ecf From d2145a5b7f3a95dcfa90edb4bcd5e5b3bf66c116 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 19:03:59 +0100 Subject: Move rights check to profile and add right for new notices Added a right for new notices, realized that the hasRight() method should be on the profile, and moved it. Makes this a less atomic commit but that's the way it goes sometimes. --- classes/Notice.php | 6 ++---- classes/Profile.php | 38 ++++++++++++++++++++++++++++++++++++++ classes/User.php | 33 ++------------------------------- lib/right.php | 1 + 4 files changed, 43 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/classes/Notice.php b/classes/Notice.php index 291e6202b..fde40240f 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -195,10 +195,8 @@ class Notice extends Memcached_DataObject ' take a breather and post again in a few minutes.')); } - $banned = common_config('profile', 'banned'); - - if ( in_array($profile_id, $banned) || in_array($profile->nickname, $banned)) { - common_log(LOG_WARNING, "Attempted post from banned user: $profile->nickname (user id = $profile_id)."); + if (!$profile->hasRight(Right::NEWNOTICE)) { + common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname); throw new ClientException(_('You are banned from posting notices on this site.')); } diff --git a/classes/Profile.php b/classes/Profile.php index 5b4394d3b..e3b35533a 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -661,4 +661,42 @@ class Profile extends Memcached_DataObject { $this->revokeRole(Profile_role::SILENCED); } + + /** + * Does this user have the right to do X? + * + * With our role-based authorization, this is merely a lookup for whether the user + * has a particular role. The implementation currently uses a switch statement + * to determine if the user has the pre-defined role to exercise the right. Future + * implementations may allow per-site roles, and different mappings of roles to rights. + * + * @param $right string Name of the right, usually a constant in class Right + * @return boolean whether the user has the right in question + */ + + function hasRight($right) + { + $result = false; + if (Event::handle('UserRightsCheck', array($this, $right, &$result))) { + switch ($right) + { + case Right::DELETEOTHERSNOTICE: + case Right::SANDBOXUSER: + case Right::SILENCEUSER: + case Right::DELETEUSER: + $result = $this->hasRole(Profile_role::MODERATOR); + break; + case Right::CONFIGURESITE: + $result = $this->hasRole(Profile_role::ADMINISTRATOR); + break; + case Right::NEWNOTICE: + $result = !$this->isSilenced(); + break; + default: + $result = false; + break; + } + } + return $result; + } } diff --git a/classes/User.php b/classes/User.php index 82d3bd59a..a466369a1 100644 --- a/classes/User.php +++ b/classes/User.php @@ -657,39 +657,10 @@ class User extends Memcached_DataObject return Design::staticGet('id', $this->design_id); } - /** - * Does this user have the right to do X? - * - * With our role-based authorization, this is merely a lookup for whether the user - * has a particular role. The implementation currently uses a switch statement - * to determine if the user has the pre-defined role to exercise the right. Future - * implementations may allow per-site roles, and different mappings of roles to rights. - * - * @param $right string Name of the right, usually a constant in class Right - * @return boolean whether the user has the right in question - */ - function hasRight($right) { - $result = false; - if (Event::handle('UserRightsCheck', array($this, $right, &$result))) { - switch ($right) - { - case Right::DELETEOTHERSNOTICE: - case Right::SANDBOXUSER: - case Right::SILENCEUSER: - case Right::DELETEUSER: - $result = $this->hasRole(Profile_role::MODERATOR); - break; - case Right::CONFIGURESITE: - $result = $this->hasRole(Profile_role::ADMINISTRATOR); - break; - default: - $result = false; - break; - } - } - return $result; + $profile = $this->getProfile(); + return $profile->hasRight($right); } function delete() diff --git a/lib/right.php b/lib/right.php index 88abdf780..ae8516602 100644 --- a/lib/right.php +++ b/lib/right.php @@ -50,5 +50,6 @@ class Right const DELETEUSER = 'deleteuser'; const SILENCEUSER = 'silenceuser'; const SANDBOXUSER = 'sandboxuser'; + const NEWNOTICE = 'newnotice'; } -- cgit v1.2.3-54-g00ecf From f1efb845e4955f398be3a7e36499474dc67bdade Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 19:22:22 +0100 Subject: don't allow sandboxed users to post public notices --- classes/Notice.php | 5 ++--- classes/Profile.php | 3 +++ lib/right.php | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/classes/Notice.php b/classes/Notice.php index fde40240f..1db431f2a 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -203,12 +203,11 @@ class Notice extends Memcached_DataObject $notice = new Notice(); $notice->profile_id = $profile_id; - $blacklist = common_config('public', 'blacklist'); $autosource = common_config('public', 'autosource'); - # Blacklisted are non-false, but not 1, either + # Sandboxed are non-false, but not 1, either - if (($blacklist && in_array($profile_id, $blacklist)) || + if (!$user->hasRight(Right::PUBLICNOTICE) || ($source && $autosource && in_array($source, $autosource))) { $notice->is_local = Notice::LOCAL_NONPUBLIC; } else { diff --git a/classes/Profile.php b/classes/Profile.php index e3b35533a..291e3f064 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -692,6 +692,9 @@ class Profile extends Memcached_DataObject case Right::NEWNOTICE: $result = !$this->isSilenced(); break; + case Right::PUBLICNOTICE: + $result = !$this->isSandboxed(); + break; default: $result = false; break; diff --git a/lib/right.php b/lib/right.php index ae8516602..1a3a7d49a 100644 --- a/lib/right.php +++ b/lib/right.php @@ -51,5 +51,6 @@ class Right const SILENCEUSER = 'silenceuser'; const SANDBOXUSER = 'sandboxuser'; const NEWNOTICE = 'newnotice'; + const PUBLICNOTICE = 'publicnotice'; } -- cgit v1.2.3-54-g00ecf From e9321a18063911f28bb55e355298ce65b36b5b71 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 19:46:08 +0100 Subject: more rights denied to silenced and sandboxed --- classes/Profile.php | 4 ++++ lib/right.php | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'lib') diff --git a/classes/Profile.php b/classes/Profile.php index 291e3f064..8754c506c 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -690,9 +690,13 @@ class Profile extends Memcached_DataObject $result = $this->hasRole(Profile_role::ADMINISTRATOR); break; case Right::NEWNOTICE: + case Right::NEWMESSAGE: + case Right::SUBSCRIBE: $result = !$this->isSilenced(); break; case Right::PUBLICNOTICE: + case Right::EMAILONREPLY: + case Right::EMAILONSUBSCRIBE: $result = !$this->isSandboxed(); break; default: diff --git a/lib/right.php b/lib/right.php index 1a3a7d49a..90ca75fd5 100644 --- a/lib/right.php +++ b/lib/right.php @@ -52,5 +52,9 @@ class Right const SANDBOXUSER = 'sandboxuser'; const NEWNOTICE = 'newnotice'; const PUBLICNOTICE = 'publicnotice'; + const NEWMESSAGE = 'newmessage'; + const SUBSCRIBE = 'subscribe'; + const EMAILONREPLY = 'emailonreply'; + const EMAILONSUBSCRIBE = 'emailonsubscribe'; } -- cgit v1.2.3-54-g00ecf From e150d920a53cbafaf6ff3f6397fa40f8cc0e526e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 14:11:14 -0500 Subject: silently skip email for subs from sandboxed user --- lib/mail.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/mail.php b/lib/mail.php index 5218059e9..94d5dcb12 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -216,7 +216,8 @@ function mail_subscribe_notify($listenee, $listener) function mail_subscribe_notify_profile($listenee, $other) { - if ($listenee->email && $listenee->emailnotifysub) { + if ($other->hasRight(Right::EMAILONSUBSCRIBE) && + $listenee->email && $listenee->emailnotifysub) { // use the recipient's localization common_init_locale($listenee->language); @@ -597,7 +598,7 @@ function mail_notify_attn($user, $notice) $bestname = $sender->getBestName(); common_init_locale($user->language); - + if ($notice->conversation != $notice->id) { $conversationEmailText = "The full conversation can be read here:\n\n". "\t%5\$s\n\n "; @@ -607,9 +608,9 @@ function mail_notify_attn($user, $notice) $conversationEmailText = "%5\$s"; $conversationUrl = null; } - + $subject = sprintf(_('%s (@%s) sent a notice to your attention'), $bestname, $sender->nickname); - + $body = sprintf(_("%1\$s (@%9\$s) just sent a notice to your attention (an '@-reply') on %2\$s.\n\n". "The notice is here:\n\n". "\t%3\$s\n\n" . @@ -635,7 +636,7 @@ function mail_notify_attn($user, $notice) array('nickname' => $user->nickname)),//%7 common_local_url('emailsettings'), //%8 $sender->nickname); //%9 - + common_init_locale(); mail_to_user($user, $subject, $body); } -- cgit v1.2.3-54-g00ecf From 2ad4de45e6b0f7edc629fb08346d978039f1c8a3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 14:12:35 -0500 Subject: block subscribes by silenced users --- lib/oauthstore.php | 4 ++++ lib/subs.php | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/oauthstore.php b/lib/oauthstore.php index a4ea5ad4d..b04bcbb8b 100644 --- a/lib/oauthstore.php +++ b/lib/oauthstore.php @@ -462,6 +462,10 @@ class StatusNetOAuthDataStore extends OAuthDataStore $subscribed = $this->_getAnyProfile($subscribed_user_uri); $subscriber = $this->_getAnyProfile($subscriber_uri); + if (!$subscriber->hasRight(Right::SUBSCRIBE)) { + return _('You have been banned from subscribing.'); + } + $sub->subscribed = $subscribed->id; $sub->subscriber = $subscriber->id; diff --git a/lib/subs.php b/lib/subs.php index 2f0f97049..2fc3160de 100644 --- a/lib/subs.php +++ b/lib/subs.php @@ -44,6 +44,10 @@ function subs_subscribe_user($user, $other_nickname) function subs_subscribe_to($user, $other) { + if (!$user->hasRight(Right::SUBSCRIBE)) { + return _('You have been banned from subscribing.'); + } + if ($user->isSubscribed($other)) { return _('Already subscribed!'); } -- cgit v1.2.3-54-g00ecf From 05ff8925bf2d115bf2c249d6901f7f67b7ac7ba8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 14:18:51 -0500 Subject: prevent email notification on replies by sandboxed users --- lib/mail.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/mail.php b/lib/mail.php index 94d5dcb12..6e74d1806 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -595,6 +595,10 @@ function mail_notify_attn($user, $notice) $sender = $notice->getProfile(); + if (!$sender->hasRight(Right::EMAILONREPLY)) { + return; + } + $bestname = $sender->getBestName(); common_init_locale($user->language); -- cgit v1.2.3-54-g00ecf From d59af0296070cd868855564a0280e4be2c16410d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 16 Nov 2009 14:28:55 -0500 Subject: disallow email on faves from sandboxed users --- classes/Profile.php | 1 + lib/mail.php | 4 ++++ lib/right.php | 1 + 3 files changed, 6 insertions(+) (limited to 'lib') diff --git a/classes/Profile.php b/classes/Profile.php index 8754c506c..d52dff5af 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -697,6 +697,7 @@ class Profile extends Memcached_DataObject case Right::PUBLICNOTICE: case Right::EMAILONREPLY: case Right::EMAILONSUBSCRIBE: + case Right::EMAILONFAVE: $result = !$this->isSandboxed(); break; default: diff --git a/lib/mail.php b/lib/mail.php index 6e74d1806..dffac3262 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -546,6 +546,10 @@ function mail_notify_message($message, $from=null, $to=null) function mail_notify_fave($other, $user, $notice) { + if (!$user->hasRight(Right::EMAILONFAVE)) { + return; + } + $profile = $user->getProfile(); $bestname = $profile->getBestName(); diff --git a/lib/right.php b/lib/right.php index 90ca75fd5..5e66eae0e 100644 --- a/lib/right.php +++ b/lib/right.php @@ -56,5 +56,6 @@ class Right const SUBSCRIBE = 'subscribe'; const EMAILONREPLY = 'emailonreply'; const EMAILONSUBSCRIBE = 'emailonsubscribe'; + const EMAILONFAVE = 'emailonfave'; } -- cgit v1.2.3-54-g00ecf From a373d07ae00b878f47970f2e4a7d86c6ec3a65cf Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Mon, 16 Nov 2009 15:24:25 -0500 Subject: Allow plugin DB_DataObject classes to not have to use the .ini file by overriding keys(), table(), and sequenceKey() for them --- classes/Plugin_DataObject.php | 195 ++++++++++++++++++++++++ classes/statusnet.ini | 31 ---- lib/schema.php | 41 ++++- plugins/Authentication/AuthenticationPlugin.php | 11 +- plugins/Authentication/User_username.php | 22 ++- plugins/OpenID/OpenIDPlugin.php | 23 +-- plugins/OpenID/User_openid.php | 22 ++- plugins/OpenID/User_openid_trustroot.php | 20 ++- plugins/UserFlag/UserFlagPlugin.php | 11 +- plugins/UserFlag/User_flag_profile.php | 21 ++- 10 files changed, 318 insertions(+), 79 deletions(-) create mode 100644 classes/Plugin_DataObject.php (limited to 'lib') diff --git a/classes/Plugin_DataObject.php b/classes/Plugin_DataObject.php new file mode 100644 index 000000000..d5cecf0f7 --- /dev/null +++ b/classes/Plugin_DataObject.php @@ -0,0 +1,195 @@ +. + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +abstract class Plugin_DataObject extends Memcached_DataObject +{ + function table() { + static $table = null; + if($table == null) { + $table = array(); + $DB = $this->getDatabaseConnection(); + $dbtype = $DB->phptype; + $tableDef = $this->tableDef(); + foreach($tableDef->columns as $columnDef){ + switch(strtoupper($columnDef->type)) { + /*shamelessly copied from DB_DataObject_Generator*/ + case 'INT': + case 'INT2': // postgres + case 'INT4': // postgres + case 'INT8': // postgres + case 'SERIAL4': // postgres + case 'SERIAL8': // postgres + case 'INTEGER': + case 'TINYINT': + case 'SMALLINT': + case 'MEDIUMINT': + case 'BIGINT': + $type = DB_DATAOBJECT_INT; + if ($columnDef->size == 1) { + $type += DB_DATAOBJECT_BOOL; + } + break; + + case 'REAL': + case 'DOUBLE': + case 'DOUBLE PRECISION': // double precision (firebird) + case 'FLOAT': + case 'FLOAT4': // real (postgres) + case 'FLOAT8': // double precision (postgres) + case 'DECIMAL': + case 'MONEY': // mssql and maybe others + case 'NUMERIC': + case 'NUMBER': // oci8 + $type = DB_DATAOBJECT_INT; // should really by FLOAT!!! / MONEY... + break; + + case 'YEAR': + $type = DB_DATAOBJECT_INT; + break; + + case 'BIT': + case 'BOOL': + case 'BOOLEAN': + + $type = DB_DATAOBJECT_BOOL; + // postgres needs to quote '0' + if ($dbtype == 'pgsql') { + $type += DB_DATAOBJECT_STR; + } + break; + + case 'STRING': + case 'CHAR': + case 'VARCHAR': + case 'VARCHAR2': + case 'TINYTEXT': + + case 'ENUM': + case 'SET': // not really but oh well + + case 'POINT': // mysql geometry stuff - not really string - but will do.. + + case 'TIMESTAMPTZ': // postgres + case 'BPCHAR': // postgres + case 'INTERVAL': // postgres (eg. '12 days') + + case 'CIDR': // postgres IP net spec + case 'INET': // postgres IP + case 'MACADDR': // postgress network Mac address. + + case 'INTEGER[]': // postgres type + case 'BOOLEAN[]': // postgres type + + $type = DB_DATAOBJECT_STR; + break; + + case 'TEXT': + case 'MEDIUMTEXT': + case 'LONGTEXT': + + $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_TXT; + break; + + + case 'DATE': + $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE; + break; + + case 'TIME': + $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_TIME; + break; + + + case 'DATETIME': + + $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME; + break; + + case 'TIMESTAMP': // do other databases use this??? + + $type = ($dbtype == 'mysql') ? + DB_DATAOBJECT_MYSQLTIMESTAMP : + DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME; + break; + + + case 'BLOB': /// these should really be ignored!!!??? + case 'TINYBLOB': + case 'MEDIUMBLOB': + case 'LONGBLOB': + + case 'CLOB': // oracle character lob support + + case 'BYTEA': // postgres blob support.. + $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_BLOB; + break; + + default: + throw new Exception("Cannot handle datatype: $columnDef->type"); + } + if(! $columnDef->nullable) { + $type+=DB_DATAOBJECT_NOTNULL; + } + $table[$columnDef->name]=$type; + } + } + return $table; + } + + function keys() { + static $keys = null; + if($keys == null) { + $keys = array(); + $tableDef = $this->tableDef(); + foreach($tableDef->columns as $columnDef){ + if($columnDef->key != null){ + $keys[] = $columnDef->name; + } + } + } + return $keys; + } + + function sequenceKey() { + static $sequenceKey = null; + if($sequenceKey == null) { + $sequenceKey = array(false,false); + $tableDef = $this->tableDef(); + foreach($tableDef->columns as $columnDef){ + if($columnDef->key == 'PRI' && $columnDef->auto_increment){ + $sequenceKey=array($columnDef->name,true); + } + } + } + return $sequenceKey; + } + + /** + * Get the TableDef object that represents the table backing this class + * Ideally, this function would a static function, but PHP doesn't allow + * abstract static functions + * @return TableDef TableDef instance + */ + abstract function tableDef(); +} + diff --git a/classes/statusnet.ini b/classes/statusnet.ini index 19ab7bf97..8572ea8ac 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -526,27 +526,6 @@ modified = 384 [user_group__keys] id = N -[user_openid] -canonical = 130 -display = 130 -user_id = 129 -created = 142 -modified = 384 - -[user_openid__keys] -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 @@ -566,13 +545,3 @@ modified = 384 user_id = K token = K -[user_username] -user_id = 129 -provider_name = 130 -username = 130 -created = 142 -modified = 384 - -[user_username__keys] -provider_name = K -username = K diff --git a/lib/schema.php b/lib/schema.php index 1e0c1f3e9..560884d9f 100644 --- a/lib/schema.php +++ b/lib/schema.php @@ -372,6 +372,26 @@ class Schema return true; } + /** + * Ensures that the table that backs a given + * Plugin_DataObject class exists. + * + * If the table does not yet exist, it will + * create the table. If it does exist, it will + * alter the table to match the column definitions. + * + * @param Plugin_DataObject $dataObjectClass + * + * @return boolean success flag + */ + + public function ensureDataObject($dataObjectClass) + { + $obj = new $dataObjectClass(); + $tableDef = $obj->tableDef(); + return $this->ensureTable($tableDef->name,$tableDef->columns); + } + /** * Ensures that a table exists with the given * name and the given column definitions. @@ -544,6 +564,19 @@ class TableDef public $name; /** array of ColumnDef objects for the columns. */ public $columns; + + /** + * Constructor. + * + * @param string $name name of the table + * @param array $columns columns in the table + */ + + function __construct($name=null,$columns=null) + { + $this->name = $name; + $this->columns = $columns; + } } /** @@ -576,6 +609,8 @@ class ColumnDef /** 'extra' stuff. Returned by MySQL, largely * unused. */ public $extra; + /** auto increment this field if no value is specific for it during an insert **/ + public $auto_increment; /** * Constructor. @@ -591,7 +626,7 @@ class ColumnDef function __construct($name=null, $type=null, $size=null, $nullable=true, $key=null, $default=null, - $extra=null) + $extra=null, $auto_increment=false) { $this->name = strtolower($name); $this->type = strtolower($type); @@ -600,6 +635,7 @@ class ColumnDef $this->key = $key; $this->default = $default; $this->extra = $extra; + $this->auto_increment = $auto_increment; } /** @@ -617,7 +653,8 @@ class ColumnDef $this->_typeMatch($other) && $this->_defaultMatch($other) && $this->_nullMatch($other) && - $this->key == $other->key); + $this->key == $other->key && + $this->auto_increment == $other->auto_increment); } /** diff --git a/plugins/Authentication/AuthenticationPlugin.php b/plugins/Authentication/AuthenticationPlugin.php index a76848b04..a80da901c 100644 --- a/plugins/Authentication/AuthenticationPlugin.php +++ b/plugins/Authentication/AuthenticationPlugin.php @@ -204,16 +204,7 @@ abstract class AuthenticationPlugin extends Plugin function onCheckSchema() { $schema = Schema::get(); - $schema->ensureTable('user_username', - array(new ColumnDef('provider_name', 'varchar', - '255', false, 'PRI'), - new ColumnDef('username', 'varchar', - '255', false, 'PRI'), - new ColumnDef('user_id', 'integer', - null, false), - new ColumnDef('created', 'datetime', - null, false), - new ColumnDef('modified', 'timestamp'))); + $schema->ensureDataObject(User_username); return true; } diff --git a/plugins/Authentication/User_username.php b/plugins/Authentication/User_username.php index f30f60d83..6826f2681 100644 --- a/plugins/Authentication/User_username.php +++ b/plugins/Authentication/User_username.php @@ -2,9 +2,9 @@ /** * Table Definition for user_username */ -require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; +require_once INSTALLDIR.'/classes/Plugin_DataObject.php'; -class User_username extends Memcached_DataObject +class User_username extends Plugin_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -43,4 +43,22 @@ class User_username extends Memcached_DataObject return false; } } + + /** + * Get the TableDef object that represents the table backing this class + * @return TableDef TableDef instance + */ + function tableDef() + { + return new TableDef($this->__table, + array(new ColumnDef('provider_name', 'varchar', + '255', false, 'PRI'), + new ColumnDef('username', 'varchar', + '255', false, 'PRI'), + new ColumnDef('user_id', 'integer', + null, false), + new ColumnDef('created', 'datetime', + null, false), + new ColumnDef('modified', 'timestamp'))); + } } diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index 55c0eadaf..88e23ea3e 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -156,6 +156,9 @@ class OpenIDPlugin extends Plugin case 'User_openid': require_once(INSTALLDIR.'/plugins/OpenID/User_openid.php'); return false; + case 'User_openid_trustroot': + require_once(INSTALLDIR.'/plugins/OpenID/User_openid_trustroot.php'); + return false; default: return true; } @@ -278,24 +281,8 @@ class OpenIDPlugin extends Plugin function onCheckSchema() { $schema = Schema::get(); - $schema->ensureTable('user_openid', - array(new ColumnDef('canonical', 'varchar', - '255', false, 'PRI'), - new ColumnDef('display', 'varchar', - '255', false), - new ColumnDef('user_id', 'integer', - null, false, 'MUL'), - 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'))); + $schema->ensureDataObject(User_openid); + $schema->ensureDataObject(User_openid_trustroot); return true; } diff --git a/plugins/OpenID/User_openid.php b/plugins/OpenID/User_openid.php index 338e0f6e9..c3624118e 100644 --- a/plugins/OpenID/User_openid.php +++ b/plugins/OpenID/User_openid.php @@ -2,9 +2,9 @@ /** * Table Definition for user_openid */ -require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; +require_once INSTALLDIR.'/classes/Plugin_DataObject.php'; -class User_openid extends Memcached_DataObject +class User_openid extends Plugin_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -33,4 +33,22 @@ class User_openid extends Memcached_DataObject return ($cnt > 0); } + + /** + * Get the TableDef object that represents the table backing this class + * @return TableDef TableDef instance + */ + function tableDef() + { + return new TableDef($this->__table, + array(new ColumnDef('canonical', 'varchar', + '255', false, 'PRI'), + new ColumnDef('display', 'varchar', + '255', false), + new ColumnDef('user_id', 'integer', + null, false, 'MUL'), + new ColumnDef('created', 'datetime', + null, false), + new ColumnDef('modified', 'timestamp'))); + } } diff --git a/plugins/OpenID/User_openid_trustroot.php b/plugins/OpenID/User_openid_trustroot.php index 4654b72df..b208dddfd 100644 --- a/plugins/OpenID/User_openid_trustroot.php +++ b/plugins/OpenID/User_openid_trustroot.php @@ -2,9 +2,9 @@ /** * Table Definition for user_openid_trustroot */ -require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; +require_once INSTALLDIR.'/classes/Plugin_DataObject.php'; -class User_openid_trustroot extends Memcached_DataObject +class User_openid_trustroot extends Plugin_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -26,4 +26,20 @@ class User_openid_trustroot extends Memcached_DataObject { return Memcached_DataObject::pkeyGet('User_openid_trustroot', $kv); } + + /** + * Get the TableDef object that represents the table backing this class + * @return TableDef TableDef instance + */ + function tableDef() + { + return new TableDef($this->__table, + 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'))); + } } diff --git a/plugins/UserFlag/UserFlagPlugin.php b/plugins/UserFlag/UserFlagPlugin.php index 6410ee1ce..df7eac7a2 100644 --- a/plugins/UserFlag/UserFlagPlugin.php +++ b/plugins/UserFlag/UserFlagPlugin.php @@ -48,16 +48,7 @@ class UserFlagPlugin extends Plugin $schema = Schema::get(); // For storing user-submitted flags on profiles - - $schema->ensureTable('user_flag_profile', - array(new ColumnDef('profile_id', 'integer', null, - false, 'PRI'), - new ColumnDef('user_id', 'integer', null, - false, 'PRI'), - new ColumnDef('created', 'datetime', null, - false, 'MUL'), - new ColumnDef('cleared', 'datetime', null, - true, 'MUL'))); + $schema->ensureDataObject(User_flag_profile); return true; } diff --git a/plugins/UserFlag/User_flag_profile.php b/plugins/UserFlag/User_flag_profile.php index 30bd4ae68..2fb27912d 100644 --- a/plugins/UserFlag/User_flag_profile.php +++ b/plugins/UserFlag/User_flag_profile.php @@ -21,9 +21,9 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; +require_once INSTALLDIR.'/classes/Plugin_DataObject.php'; -class User_flag_profile extends Memcached_DataObject +class User_flag_profile extends Plugin_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -65,4 +65,21 @@ class User_flag_profile extends Memcached_DataObject return !empty($ufp); } + + /** + * Get the TableDef object that represents the table backing this class + * @return TableDef TableDef instance + */ + function tableDef() + { + return new TableDef($this->__table, + array(new ColumnDef('profile_id', 'integer', null, + false, 'PRI'), + new ColumnDef('user_id', 'integer', null, + false, 'PRI'), + new ColumnDef('created', 'datetime', null, + false, 'MUL'), + new ColumnDef('cleared', 'datetime', null, + true, 'MUL'))); + } } -- cgit v1.2.3-54-g00ecf From a99198ba94766dcfb58d4cc16358dc1438df422a Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Mon, 16 Nov 2009 15:57:57 -0500 Subject: Do proper translations for plurals --- lib/command.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/command.php b/lib/command.php index 0c98c94ac..7e98156b6 100644 --- a/lib/command.php +++ b/lib/command.php @@ -617,8 +617,11 @@ class SubscriptionsCommand extends Command if(count($nicknames)==0){ $out=_('You are not subscribed to anyone.'); }else{ - $out=_('You are subscribed to these people: '); - $out.=implode(', ',$nicknames); + $out = ngettext('You are subscribed to this person:', + 'You are subscribed to these people:', + count($nicknames)); + $out .= ' '; + $out .= implode(', ',$nicknames); } $channel->output($this->user,$out); } @@ -636,8 +639,11 @@ class SubscribersCommand extends Command if(count($nicknames)==0){ $out=_('No one is subscribed to you.'); }else{ - $out=_('These people are subscribed to you: '); - $out.=implode(', ',$nicknames); + $out = ngettext('This person is subscribed to you:', + 'These people are subscribed to you:', + count($nicknames)); + $out .= ' '; + $out .= implode(', ',$nicknames); } $channel->output($this->user,$out); } @@ -655,7 +661,9 @@ class GroupsCommand extends Command if(count($groups)==0){ $out=_('You are not a member of any groups.'); }else{ - $out=_('You are a member of these groups: '); + $out = ngettext('You are a member of this group:', + 'You are a member of these groups:', + count($nicknames)); $out.=implode(', ',$groups); } $channel->output($this->user,$out); -- cgit v1.2.3-54-g00ecf From 8ab40e70518402071f50263ebae8cf9633500405 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 16 Nov 2009 15:35:16 -0800 Subject: Cleanup for bug 1813: workaround sometimes-missing dl() in PHP 5.3 by defining our own bogus function rather than attempting to patch upstream libs. This keeps our fix across upstream versions (or when loading upstream library from outside extlib) Note that fixes to OpenID libraries in commit fe9473ac7810d317e001a0fec19cbacaafc0c909 were lost in just such an update. --- extlib/PEAR.php | 2 +- lib/common.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/extlib/PEAR.php b/extlib/PEAR.php index fcefa964a..4c24c6006 100644 --- a/extlib/PEAR.php +++ b/extlib/PEAR.php @@ -746,7 +746,7 @@ class PEAR { if (!extension_loaded($ext)) { // if either returns true dl() will produce a FATAL error, stop that - if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1) || !function_exists('dl')) { + if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) { return false; } if (OS_WINDOWS) { diff --git a/lib/common.php b/lib/common.php index 4524d50fa..063d7d9d9 100644 --- a/lib/common.php +++ b/lib/common.php @@ -45,6 +45,14 @@ define('FOREIGN_FRIEND_RECV', 2); set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/'); +# To protect against upstream libraries which haven't updated +# for PHP 5.3 where dl() function may not be present... +if (!function_exists('dl')) { + function dl($library) { + return false; + } +} + # global configuration object require_once('PEAR.php'); -- cgit v1.2.3-54-g00ecf