Moved group create API into its own action

Merge branch '0.9.x' into refactor-api

* 0.9.x:
  Implemented create group api
  fix FBConnect so it doesn't muffle EndPrimaryNav
  don't write session if it's unchanged
  Fixed facebook connect primary nav to hide search option when site is private and user is not logged in
  Fixed facebook connect primary nav to obey sms/twitter/openid settings
  Fixed facebook connect login nav to obey openid settings
  Fixed facebook connect nav to obey sms/twitter disabled
  Fixed twitter defaulting to disabled
  Revert "Open tags should have closing tags"
  Don't show search suggestions for private sites
  Fixed E_NOTICE when returnto isn't set
  Fixed E_NOTICE when the "lite" parameter isn't included in the request
  Fixed E_NOTICE - GroupList expects an owner object in the constructor, not an array of search terms
  Returning false seems to fix IE from reclaiming window focus. I think
  Aligning notice attach label from right instead of left
  Fixed IE background image alignment for attach, favour and disfavour
  Fixed nudge and direct message background image alignment
  Using 'CSS sprites' for common icons for the identica theme. Default
  Open tags should have closing tags

Conflicts:
	actions/twitapigroups.php
	actions/twitapistatuses.php
This commit is contained in:
Zach Copley 2009-10-12 12:31:14 -07:00
commit e071a8cbff
16 changed files with 490 additions and 78 deletions

360
actions/apigroupcreate.php Normal file
View File

@ -0,0 +1,360 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Create a group via the API
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category API
* @package StatusNet
* @author Craig Andrews <candrews@integralblue.com>
* @author Zach Copley <zach@status.net>
* @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);
}
require_once INSTALLDIR . '/lib/apiauth.php';
/**
* Make a new group. Sets the authenticated user as the administrator of the group.
*
* @category API
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
class ApiGroupCreateAction extends ApiAuthAction
{
var $group = null;
var $nickname = null;
var $fullname = null;
var $homepage = null;
var $description = null;
var $location = null;
var $aliasstring = null;
var $aliases = null;
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*
*/
function prepare($args)
{
parent::prepare($args);
$this->user = $this->auth_user;
$this->nickname = $this->arg('nickname');
$this->fullname = $this->arg('full_name');
$this->homepage = $this->arg('homepage');
$this->description = $this->arg('description');
$this->location = $this->arg('location');
$this->aliasstring = $this->arg('aliases');
return true;
}
/**
* Handle the request
*
* Save the new group
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
{
parent::handle($args);
if (!common_config('inboxes','enabled')) {
$this->serverError(
_('Inboxes must be enabled for groups to work'),
400,
$this->format
);
return false;
}
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (empty($this->user)) {
$this->clientError(_('No such user!'), 404, $this->format);
return;
}
if ($this->validateParams() == false) {
return;
}
$group = new User_group();
$group->query('BEGIN');
$group->nickname = $this->nickname;
$group->fullname = $this->fullname;
$group->homepage = $this->homepage;
$group->description = $this->description;
$group->location = $this->location;
$group->created = common_sql_now();
$result = $group->insert();
if (!$result) {
common_log_db_error($group, 'INSERT', __FILE__);
$this->serverError(
_('Could not create group.'),
500,
$this->format
);
return;
}
$result = $group->setAliases($this->aliases);
if (!$result) {
$this->serverError(
_('Could not create aliases.'),
500,
$this->format
);
return;
}
$member = new Group_member();
$member->group_id = $group->id;
$member->profile_id = $this->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.'),
500,
$this->format
);
return;
}
$group->query('COMMIT');
switch($this->format) {
case 'xml':
$this->showSingleXmlGroup($group);
break;
case 'json':
$this->showSingleJsonGroup($group);
break;
default:
$this->clientError(
_('API method not found!'),
404,
$this->format
);
break;
}
}
/**
* Validate params for the new group
*
* @return void
*/
function validateParams()
{
if (!Validate::string(
$this->nickname, array(
'min_length' => 1,
'max_length' => 64,
'format' => NICKNAME_FMT)
)
)
{
$this->clientError(
_(
'Nickname must have only lowercase letters ' .
'and numbers and no spaces.'
),
403,
$this->format
);
return false;
} elseif ($this->groupNicknameExists($this->nickname)) {
$this->clientError(
_('Nickname already in use. Try another one.'),
403,
$this->format
);
return false;
} else if (!User_group::allowedNickname($this->nickname)) {
$this->clientError(
_('Not a valid nickname.'),
403,
$this->format
);
return false;
} elseif (!is_null($this->homepage)
&& strlen($this->homepage) > 0
&& !Validate::uri(
$this->homepage, array(
'allowed_schemes' =>
array('http', 'https')
)
))
{
$this->clientError(
_('Homepage is not a valid URL.'),
403,
$this->format
);
return false;
} elseif (!is_null($this->fullname)
&& mb_strlen($this->fullname) > 255)
{
$this->clientError(
_('Full name is too long (max 255 chars).'),
403,
$this->format
);
return false;
} elseif (User_group::descriptionTooLong($this->description)) {
$this->clientError(sprintf(
_('Description is too long (max %d chars).'),
User_group::maxDescription()),
403,
$this->format
);
return false;
} elseif (!is_null($this->location)
&& mb_strlen($this->location) > 255)
{
$this->clientError(
_('Location is too long (max 255 chars).'),
403,
$this->format
);
return false;
}
if (!empty($this->aliasstring)) {
$this->aliases = array_map(
'common_canonical_nickname',
array_unique(preg_split('/[\s,]+/',
$this->aliasstring)
)
);
} else {
$this->aliases = array();
}
if (count($this->aliases) > common_config('group', 'maxaliases')) {
$this->clientError(
sprintf(_('Too many aliases! Maximum %d.'),
common_config('group', 'maxaliases')),
403,
$this->format
);
return false;
}
foreach ($this->aliases as $alias) {
if (!Validate::string($alias, array(
'min_length' => 1,
'max_length' => 64,
'format' => NICKNAME_FMT
)
))
{
$this->clientError(
sprintf(_('Invalid alias: "%s"'), $alias),
403,
$this->format
);
return false;
}
if ($this->groupNicknameExists($alias)) {
$this->clientError(
sprintf(_('Alias "%s" already in use. Try another one.'),
$alias),
403,
$this->format
);
return false;
}
// XXX assumes alphanum nicknames
if (strcmp($alias, $this->nickname) == 0) {
$this->clientError(
_('Alias can\'t be the same as nickname.'),
403,
$this->format
);
return false;
}
}
// Evarything looks OK
return true;
}
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;
}
}

View File

@ -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';

View File

@ -85,9 +85,18 @@ class Session extends Memcached_DataObject
return $session->insert();
} else {
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);
}
}
}

View File

@ -894,7 +894,7 @@ class ApiAction extends Action
$this->endDocument('json');
}
function show_single_xml_group($group)
function showSingleXmlGroup($group)
{
$this->initDocument('xml');
$twitter_group = $this->twitterGroupArray($group);

View File

@ -140,15 +140,14 @@ $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,
array('enabled' => true,
'consumer_key' => null,
'consumer_secret' => null),
'memcached' =>
array('enabled' => false,

View File

@ -572,6 +572,10 @@ class Router
array('action' => 'ApiGroupMembership',
'id' => '[a-zA-Z0-9]+',
'format' => '(xml|json)'));
$m->connect('api/statusnet/groups/create.:format',
array('action' => 'ApiGroupCreate',
'format' => '(xml|json)'));
// Tags
$m->connect('api/statusnet/tags/timeline/:tag.:format',
array('action' => 'ApiTimelineTag',

View File

@ -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');

View File

@ -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()

View File

@ -78,6 +78,7 @@ class FBCLoginGroupNav extends Widget
// action => array('prompt', 'title')
$menu = array();
if (!common_config('site','openidonly')) {
$menu['login'] = array(_('Login'),
_('Login with a username and password'));
@ -85,9 +86,12 @@ class FBCLoginGroupNav extends Widget
$menu['register'] = array(_('Register'),
_('Sign up for a new account'));
}
}
if (common_config('openid', 'enabled')) {
$menu['openidlogin'] = array(_('OpenID'),
_('Login or register with OpenID'));
}
$menu['FBConnectLogin'] = array(_('Facebook'),
_('Login or register using Facebook'));

View File

@ -77,28 +77,30 @@ class FBCSettingsNav extends Widget
$this->action->elementStart('dd');
# action => array('prompt', 'title')
$menu =
array('imsettings' =>
$menu = array();
if (common_config('xmpp', 'enabled')) {
$menu['imsettings'] =
array(_('IM'),
_('Updates by instant messenger (IM)')),
'smssettings' =>
_('Updates by instant messenger (IM)'));
}
if (common_config('sms', 'enabled')) {
$menu['smssettings'] =
array(_('SMS'),
_('Updates by SMS')),
'twittersettings' =>
_('Updates by SMS'));
}
if (common_config('twitter', 'enabled')) {
$menu['twittersettings'] =
array(_('Twitter'),
_('Twitter integration options')),
'FBConnectSettings' =>
_('Twitter integration options'));
}
$menu['FBConnectSettings'] =
array(_('Facebook'),
_('Facebook Connect settings')));
_('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],

View File

@ -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', '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('doc', array('title' => 'help')),
_('Help'), _('Help me!'), false, 'nav_help');
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;
}

View File

@ -25,6 +25,8 @@ RealtimeUpdate = {
'border-top-color':'#AAAAAA',
'border-top-style':'solid'
});
return false;
});
},

View File

@ -468,16 +468,15 @@ margin-bottom:7px;
#form_notice #notice_data-attach {
position:absolute;
top:25px;
right:10.5%;
cursor:pointer;
}
#form_notice label[for=notice_data-attach] {
text-indent:-9999px;
left:86%;
width:16px;
height:16px;
}
#form_notice #notice_data-attach {
left:40.6%;
padding:0;
height:16px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -88,7 +88,7 @@ color:#333333;
color:#000000;
}
#form_notice label[for=notice_data-attach] {
background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -328px;
}
#form_notice #notice_data-attach {
opacity:0;
@ -150,16 +150,18 @@ background-color:#9BB43E;
#export_data li a {
background-repeat:no-repeat;
background-position:0 45%;
}
#export_data li a.rss {
background-image:url(../../base/images/icons/icon_rss.png);
background-image:url(../../base/images/icons/icons-01.png);
background-position:0 -130px;
}
#export_data li a.atom {
background-image:url(../../base/images/icons/icon_atom.png);
background-image:url(../../base/images/icons/icons-01.png);
background-position:0 -64px;
}
#export_data li a.foaf {
background-image:url(../../base/images/icons/icon_foaf.gif);
background-image:url(../../base/images/icons/icons-01.png);
background-position:0 1px;
}
.entity_edit a,
@ -171,7 +173,6 @@ background-image:url(../../base/images/icons/icon_foaf.gif);
.form_group_unblock input.submit,
.entity_nudge p,
.form_make_admin input.submit {
background-position: 0 40%;
background-repeat: no-repeat;
background-color:transparent;
}
@ -189,43 +190,48 @@ background-color:#87B4C8;
}
.entity_edit a {
background-image:url(../../base/images/icons/twotone/green/edit.gif);
background-image:url(../../base/images/icons/icons-01.png);
background-position: 0 -718px;
}
.entity_send-a-message a {
background-image:url(../../base/images/icons/twotone/green/quote.gif);
background-image:url(../../base/images/icons/icons-01.png);
background-position: 0 -849px;
}
.entity_nudge p,
.form_user_nudge input.submit {
background-image:url(../../base/images/icons/twotone/green/mail.gif);
background-image:url(../../base/images/icons/icons-01.png);
background-position: 0 -785px;
}
.form_user_block input.submit,
.form_user_unblock input.submit,
.form_group_block input.submit,
.form_group_unblock input.submit {
background-image:url(../../base/images/icons/twotone/green/shield.gif);
background-image:url(../../base/images/icons/icons-01.png);
background-position: 0 -918px;
}
.form_make_admin input.submit {
background-image:url(../../base/images/icons/twotone/green/admin.gif);
background-image:url(../../base/images/icons/icons-01.png);
background-position: 0 -983px;
}
/* NOTICES */
.notice .attachment {
background:transparent url(../../base/images/icons/twotone/green/clip-02.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -394px;
}
#attachments .attachment {
background:none;
}
.notice-options .notice_reply {
background:transparent url(../../base/images/icons/twotone/green/reply.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -589px;
}
.notice-options form.form_favor input.submit {
background:transparent url(../../base/images/icons/twotone/green/favourite.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -457px;
}
.notice-options form.form_disfavor input.submit {
background:transparent url(../../base/images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -523px;
}
.notice-options .notice_delete {
background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -655px;
}
.notices div.entry-content,
@ -262,7 +268,7 @@ background-color:rgba(200, 200, 200, 0.300);
/*END: NOTICES */
#new_group a {
background:transparent url(../../base/images/icons/twotone/green/news.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -1054px;
}
.pagination .nav_prev a,
@ -271,10 +277,10 @@ background-repeat:no-repeat;
border-color:#CEE1E9;
}
.pagination .nav_prev a {
background-image:url(../../base/images/icons/twotone/green/arrow-left.gif);
background-position:10% 45%;
background-image:url(../../base/images/icons/icons-01.png);
background-position:10% -187px;
}
.pagination .nav_next a {
background-image:url(../../base/images/icons/twotone/green/arrow-right.gif);
background-position:90% 45%;
background-image:url(../../base/images/icons/icons-01.png);
background-position:105% -252px;
}

View File

@ -7,8 +7,14 @@ color:#FFFFFF;
background-color:#D9DADB;
}
#form_notice .form_note + label {
background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%;
background:transparent url(../../base/images/icons/icons-01.png) no-repeat 0 -328px;
}
#form_notice #notice_data-attach {
filter: alpha(opacity=0);
}
.notice-options form.form_favor input.submit {
background-position:0 -460px;
}
.notice-options form.form_disfavor input.submit {
background-position:0 -526px;
}