diff options
author | Sarven Capadisli <csarven@status.net> | 2009-10-12 10:56:23 +0000 |
---|---|---|
committer | Sarven Capadisli <csarven@status.net> | 2009-10-12 10:56:23 +0000 |
commit | 8513ce94d29f03b18ccc06071144b0d50b3c6205 (patch) | |
tree | b7d91c68c7c8d121bddd10d47526c2e0f4de8be6 | |
parent | 5dc728a756b37f552480b72237f227a659f57928 (diff) | |
parent | f719720e8ad3b09d664e33172bafef2b0fb91eea (diff) |
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x-mobile
-rw-r--r-- | actions/groupsearch.php | 2 | ||||
-rw-r--r-- | actions/twitapigroups.php | 145 | ||||
-rw-r--r-- | actions/twitapistatuses.php | 4 | ||||
-rw-r--r-- | classes/Session.php | 13 | ||||
-rw-r--r-- | lib/default.php | 7 | ||||
-rw-r--r-- | lib/searchaction.php | 12 | ||||
-rw-r--r-- | lib/util.php | 2 | ||||
-rw-r--r-- | plugins/FBConnect/FBCLoginGroupNav.php | 20 | ||||
-rw-r--r-- | plugins/FBConnect/FBCSettingsNav.php | 42 | ||||
-rw-r--r-- | plugins/FBConnect/FBConnectPlugin.php | 43 |
10 files changed, 234 insertions, 56 deletions
diff --git a/actions/groupsearch.php b/actions/groupsearch.php index f0cca7156..55f4cee62 100644 --- a/actions/groupsearch.php +++ b/actions/groupsearch.php @@ -105,7 +105,7 @@ class GroupSearchResults extends GroupList function __construct($user_group, $terms, $action) { - parent::__construct($user_group, $terms, $action); + parent::__construct($user_group, null, $action); $this->terms = array_map('preg_quote', array_map('htmlspecialchars', $terms)); $this->pattern = '/('.implode('|',$terms).')/i'; diff --git a/actions/twitapigroups.php b/actions/twitapigroups.php index 493144e77..a29485883 100644 --- a/actions/twitapigroups.php +++ b/actions/twitapigroups.php @@ -428,7 +428,133 @@ require_once INSTALLDIR.'/lib/twitterapi.php'; function create($args, $apidata) { - die("todo"); + parent::handle($args); + + common_debug("in groups api action"); + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + $this->auth_user = $apidata['user']; + + $nickname = $args['nickname']; + $fullname = $args['full_name']; + $homepage = $args['homepage']; + $description = $args['description']; + $location = $args['location']; + $aliasstring = $args['aliases']; + + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->clientError(_('Nickname must have only lowercase letters '. + 'and numbers and no spaces.'), $code=403); + return; + } else if ($this->groupNicknameExists($nickname)) { + $this->clientError(_('Nickname already in use. Try another one.'), $code=403); + return; + } else if (!User_group::allowedNickname($nickname)) { + $this->clientError(_('Not a valid nickname.'), $code=403); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + $this->clientError(_('Homepage is not a valid URL.'), $code=403); + return; + } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + $this->clientError(_('Full name is too long (max 255 chars).'), $code=403); + return; + } else if (User_group::descriptionTooLong($description)) { + $this->clientError(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription()), $code=403); + return; + } else if (!is_null($location) && mb_strlen($location) > 255) { + $this->clientError(_('Location is too long (max 255 chars).'), $code=403); + return; + } + + if (!empty($aliasstring)) { + $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring))); + } else { + $aliases = array(); + } + + if (count($aliases) > common_config('group', 'maxaliases')) { + $this->clientError(sprintf(_('Too many aliases! Maximum %d.'), + common_config('group', 'maxaliases')), $code=403); + return; + } + + foreach ($aliases as $alias) { + if (!Validate::string($alias, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->clientError(sprintf(_('Invalid alias: "%s"'), $alias), $code=403); + return; + } + if ($this->groupNicknameExists($alias)) { + $this->clientError(sprintf(_('Alias "%s" already in use. Try another one.'), + $alias), $code=403); + return; + } + // XXX assumes alphanum nicknames + if (strcmp($alias, $nickname) == 0) { + $this->clientError(_('Alias can\'t be the same as nickname.'), $code=403); + return; + } + } + + $group = new User_group(); + + $group->query('BEGIN'); + + $group->nickname = $nickname; + $group->fullname = $fullname; + $group->homepage = $homepage; + $group->description = $description; + $group->location = $location; + $group->created = common_sql_now(); + + $result = $group->insert(); + + if (!$result) { + common_log_db_error($group, 'INSERT', __FILE__); + $this->serverError(_('Could not create group.')); + } + + $result = $group->setAliases($aliases); + + if (!$result) { + $this->serverError(_('Could not create aliases.')); + } + + $member = new Group_member(); + + $member->group_id = $group->id; + $member->profile_id = $this->auth_user->id; + $member->is_admin = 1; + $member->created = $group->created; + + $result = $member->insert(); + + if (!$result) { + common_log_db_error($member, 'INSERT', __FILE__); + $this->serverError(_('Could not set group membership.')); + } + + $group->query('COMMIT'); + + switch($apidata['content-type']) { + case 'xml': + $this->show_single_xml_group($group); + break; + case 'json': + $this->show_single_json_group($group); + break; + default: + $this->clientError(_('API method not found!'), $code = 404); + } } function update($args, $apidata) @@ -450,4 +576,21 @@ require_once INSTALLDIR.'/lib/twitterapi.php'; { die("todo"); } + + function groupNicknameExists($nickname) + { + $group = User_group::staticGet('nickname', $nickname); + + if (!empty($group)) { + return true; + } + + $alias = Group_alias::staticGet('alias', $nickname); + + if (!empty($alias)) { + return true; + } + + return false; + } } diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 87043b182..c589bd9b1 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -456,7 +456,7 @@ class TwitapistatusesAction extends TwitterapiAction function friends($args, $apidata) { parent::handle($args); - $includeStatuses=! (boolean) $args['lite']; + $includeStatuses= !(array_key_exists('lite', $args) and $args['lite']); return $this->subscriptions($apidata, 'subscribed', 'subscriber', false, $includeStatuses); } @@ -469,7 +469,7 @@ class TwitapistatusesAction extends TwitterapiAction function followers($args, $apidata) { parent::handle($args); - $includeStatuses=! (boolean) $args['lite']; + $includeStatuses= !(array_key_exists('lite', $args) and $args['lite']); return $this->subscriptions($apidata, 'subscriber', 'subscribed', false, $includeStatuses); } diff --git a/classes/Session.php b/classes/Session.php index d641edbbe..79a69a96e 100644 --- a/classes/Session.php +++ b/classes/Session.php @@ -85,9 +85,18 @@ class Session extends Memcached_DataObject return $session->insert(); } else { - $session->session_data = $session_data; + if (strcmp($session->session_data, $session_data) == 0) { + self::logdeb("Not writing session '$id'; unchanged"); + return true; + } else { + self::logdeb("Session '$id' data changed; updating"); + + $orig = clone($session); + + $session->session_data = $session_data; - return $session->update(); + return $session->update($orig); + } } } diff --git a/lib/default.php b/lib/default.php index f9670cb7f..329b041e9 100644 --- a/lib/default.php +++ b/lib/default.php @@ -140,16 +140,15 @@ $default = array('enabled' => true), 'sms' => array('enabled' => true), - 'twitter' => - array('enabled' => true), 'twitterbridge' => array('enabled' => false), 'integration' => array('source' => 'StatusNet', # source attribute for Twitter 'taguri' => $_server.',2009'), # base for tag URIs 'twitter' => - array('consumer_key' => null, - 'consumer_secret' => null), + array('enabled' => true, + 'consumer_key' => null, + 'consumer_secret' => null), 'memcached' => array('enabled' => false, 'server' => 'localhost', diff --git a/lib/searchaction.php b/lib/searchaction.php index 0d9f85a8f..130b28ff5 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -135,16 +135,21 @@ class SearchAction extends Action } function searchSuggestions($q) { - $qe = urlencode($q); - $message = sprintf(_(<<<E_O_T + $message = _(<<<E_O_T * Make sure all words are spelled correctly. * Try different keywords. * Try more general keywords. * Try fewer keywords. +E_O_T +); + if (!common_config('site', 'private')) { + $qe = urlencode($q); + $message .= sprintf(_(<<<E_O_T + You can also try your search on other engines: -* [Twingly](http://www.twingly.com/search?q=%s&content=microblog&site=identi.ca) +* [Twingly](http://www.twingly.com/search?q=%s&content=microblog&site=%%%%site.server%%%%) * [Tweet scan](http://www.tweetscan.com/indexi.php?s=%s) * [Google](http://www.google.com/search?q=site%%3A%%%%site.server%%%%+%s) * [Yahoo](http://search.yahoo.com/search?p=site%%3A%%%%site.server%%%%+%s) @@ -152,6 +157,7 @@ You can also try your search on other engines: E_O_T ), $qe, $qe, $qe, $qe, $qe); + } $this->elementStart('dl', array('id' => 'help_search', 'class' => 'help')); $this->element('dt', null, _('Search help')); $this->elementStart('dd', 'instructions'); diff --git a/lib/util.php b/lib/util.php index d249b154f..be10647fc 100644 --- a/lib/util.php +++ b/lib/util.php @@ -998,7 +998,7 @@ function common_set_returnto($url) function common_get_returnto() { common_ensure_session(); - return $_SESSION['returnto']; + return (array_key_exists('returnto', $_SESSION)) ? $_SESSION['returnto'] : null; } function common_timestamp() diff --git a/plugins/FBConnect/FBCLoginGroupNav.php b/plugins/FBConnect/FBCLoginGroupNav.php index 6e12c2040..81b2520a4 100644 --- a/plugins/FBConnect/FBCLoginGroupNav.php +++ b/plugins/FBConnect/FBCLoginGroupNav.php @@ -78,16 +78,20 @@ class FBCLoginGroupNav extends Widget // action => array('prompt', 'title') $menu = array(); - $menu['login'] = array(_('Login'), - _('Login with a username and password')); - - if (!(common_config('site','closed') || common_config('site','inviteonly'))) { - $menu['register'] = array(_('Register'), - _('Sign up for a new account')); + if (!common_config('site','openidonly')) { + $menu['login'] = array(_('Login'), + _('Login with a username and password')); + + if (!(common_config('site','closed') || common_config('site','inviteonly'))) { + $menu['register'] = array(_('Register'), + _('Sign up for a new account')); + } } - $menu['openidlogin'] = array(_('OpenID'), - _('Login or register with OpenID')); + if (common_config('openid', 'enabled')) { + $menu['openidlogin'] = array(_('OpenID'), + _('Login or register with OpenID')); + } $menu['FBConnectLogin'] = array(_('Facebook'), _('Login or register using Facebook')); diff --git a/plugins/FBConnect/FBCSettingsNav.php b/plugins/FBConnect/FBCSettingsNav.php index 29724d6bd..ed02371e2 100644 --- a/plugins/FBConnect/FBCSettingsNav.php +++ b/plugins/FBConnect/FBCSettingsNav.php @@ -77,32 +77,34 @@ class FBCSettingsNav extends Widget $this->action->elementStart('dd'); # action => array('prompt', 'title') - $menu = - array('imsettings' => - array(_('IM'), - _('Updates by instant messenger (IM)')), - 'smssettings' => - array(_('SMS'), - _('Updates by SMS')), - 'twittersettings' => - array(_('Twitter'), - _('Twitter integration options')), - 'FBConnectSettings' => - array(_('Facebook'), - _('Facebook Connect settings'))); + $menu = array(); + if (common_config('xmpp', 'enabled')) { + $menu['imsettings'] = + array(_('IM'), + _('Updates by instant messenger (IM)')); + } + if (common_config('sms', 'enabled')) { + $menu['smssettings'] = + array(_('SMS'), + _('Updates by SMS')); + } + if (common_config('twitter', 'enabled')) { + $menu['twittersettings'] = + array(_('Twitter'), + _('Twitter integration options')); + } + $menu['FBConnectSettings'] = + array(_('Facebook'), + _('Facebook Connect settings')); $action_name = $this->action->trimmed('action'); $this->action->elementStart('ul', array('class' => 'nav')); foreach ($menu as $menuaction => $menudesc) { - if ($menuaction == 'imsettings' && - !common_config('xmpp', 'enabled')) { - continue; - } $this->action->menuItem(common_local_url($menuaction), - $menudesc[0], - $menudesc[1], - $action_name === $menuaction); + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); } $this->action->elementEnd('ul'); diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 593b49b4e..ff74aade4 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -232,6 +232,14 @@ class FBConnectPlugin extends Plugin { $user = common_current_user(); + $connect = 'FBConnectSettings'; + if (common_config('xmpp', 'enabled')) { + $connect = 'imsettings'; + } else if (common_config('sms', 'enabled')) { + $connect = 'smssettings'; + } else if (common_config('twitter', 'enabled')) { + $connect = 'twittersettings'; + } if (!empty($user)) { @@ -266,13 +274,8 @@ class FBConnectPlugin extends Plugin _('Home'), _('Personal profile and friends timeline'), false, 'nav_home'); $action->menuItem(common_local_url('profilesettings'), _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account'); - if (common_config('xmpp', 'enabled')) { - $action->menuItem(common_local_url('imsettings'), - _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect'); - } else { - $action->menuItem(common_local_url('smssettings'), - _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect'); - } + $action->menuItem(common_local_url($connect), + _('Connect'), _('Connect to services'), false, 'nav_connect'); if (common_config('invite', 'enabled')) { $action->menuItem(common_local_url('invite'), _('Invite'), @@ -300,18 +303,30 @@ class FBConnectPlugin extends Plugin } } else { - if (!common_config('site', 'closed')) { - $action->menuItem(common_local_url('register'), - _('Register'), _('Create an account'), false, 'nav_register'); + if (!common_config('site', 'openidonly')) { + if (!common_config('site', 'closed')) { + $action->menuItem(common_local_url('register'), + _('Register'), _('Create an account'), false, 'nav_register'); + } + $action->menuItem(common_local_url('login'), + _('Login'), _('Login to the site'), false, 'nav_login'); + } else { + $this->menuItem(common_local_url('openidlogin'), + _('OpenID'), _('Login with OpenID'), false, 'nav_openid'); } - $action->menuItem(common_local_url('login'), - _('Login'), _('Login to the site'), false, 'nav_login'); } $action->menuItem(common_local_url('doc', array('title' => 'help')), _('Help'), _('Help me!'), false, 'nav_help'); - $action->menuItem(common_local_url('peoplesearch'), - _('Search'), _('Search for people or text'), false, 'nav_search'); + if ($user || !common_config('site', 'private')) { + $action->menuItem(common_local_url('peoplesearch'), + _('Search'), _('Search for people or text'), false, 'nav_search'); + } + + // We are replacing the primary nav entirely; give other + // plugins a chance to handle it here. + + Event::handle('EndPrimaryNav', array($action)); return false; } |