git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit 36d61948 authored by Zach Copley's avatar Zach Copley

Rip out user, group and site design customization code

Squashed commit of the following:

commit 0bcfb6535115ec0a11669420f8689aeedc417bc8
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 15:51:47 2011 -0400

    Remove design-related stuff from the API

commit 88da010256fbcaee1ff01d9507ea47d3225f2825
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 15:40:16 2011 -0400

    Mop up misc design related code

commit 11958b064745b797b4c9f9f4b7e8f65e4c82ce83
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 15:21:00 2011 -0400

    Remove Design DB_DataObject class and references to it in schema

commit f8540594728ce6ba4697eb21657ccb897a9fc127
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 13:15:54 2011 -0400

    Remove design-related actions and widgets

commit ddf7b4d425b88b58956b8be06047d2a3e0560bd2
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 13:10:57 2011 -0400

    Remove navigation / routing to design settings actions

commit e3f280f8780d99168edf37ef766956f281e9c5da
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 13:03:09 2011 -0400

    CurrentUserDesignAction -> Action

commit 6780b1a07e1375a7fa0fd48c8bf3109d9a12e33e
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 12:54:22 2011 -0400

    * GroupDesignAction -> GroupAction (new base class for group actions)

commit 2136377e895db274709a1d486f377f13946ccfd6
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 9 12:36:40 2011 -0400

    OwnerDesignAction -> Action
parent c6d6749d
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Update the authenticating user's profile background image
*
* 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 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';
/**
* Update the authenticating user's profile background image
*
* @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 ApiAccountUpdateProfileBackgroundImageAction extends ApiAuthAction
{
var $tile = false;
/**
* 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->tile = $this->arg('tile');
return true;
}
/**
* Handle the request
*
* Check whether the credentials are valid and output the result
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
{
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400, $this->format
);
return;
}
if (!in_array($this->format, array('xml', 'json'))) {
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'),
404,
$this->format
);
return;
}
// Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
if (empty($_FILES)
&& empty($_POST)
&& ($_SERVER['CONTENT_LENGTH'] > 0)
) {
// TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
// TRANS: %s is the number of bytes of the CONTENT_LENGTH.
$msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.',
'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
}
if (empty($this->user)) {
// TRANS: Client error when user not found updating a profile background image.
$this->clientError(_('No such user.'), 404, $this->format);
return;
}
$design = $this->user->getDesign();
// XXX: This is kinda gross, but before we can add a background
// img we have to make sure there's a Design because design ID
// is part of the img filename.
if (empty($design)) {
$this->user->query('BEGIN');
// save new design
$design = new Design();
$id = $design->insert();
if (empty($id)) {
common_log_db_error($id, 'INSERT', __FILE__);
// TRANS: Client error displayed when saving design settings fails because of an empty id.
$this->clientError(_('Unable to save your design settings.'));
return;
}
$original = clone($this->user);
$this->user->design_id = $id;
$result = $this->user->update($original);
if (empty($result)) {
common_log_db_error($original, 'UPDATE', __FILE__);
// TRANS: Client error displayed when saving design settings fails because of an empty result.
$this->clientError(_('Unable to save your design settings.'));
$this->user->query('ROLLBACK');
return;
}
$this->user->query('COMMIT');
}
// Okay, now get the image and add it to the design
try {
$imagefile = ImageFile::fromUpload('image');
} catch (Exception $e) {
$this->clientError($e->getMessage(), 400, $this->format);
return;
}
$filename = Design::filename(
$design->id,
image_type_to_extension($imagefile->type),
common_timestamp()
);
$filepath = Design::path($filename);
move_uploaded_file($imagefile->filepath, $filepath);
// delete any old backround img laying around
if (isset($design->backgroundimage)) {
@unlink(Design::path($design->backgroundimage));
}
$original = clone($design);
$design->backgroundimage = $filename;
$design->setDisposition(true, false, ($this->tile == 'true'));
$result = $design->update($original);
if ($result === false) {
common_log_db_error($design, 'UPDATE', __FILE__);
// TRANS: Error displayed when updating design settings fails.
$this->showForm(_('Could not update your design.'));
return;
}
$profile = $this->user->getProfile();
if (empty($profile)) {
// TRANS: Error message displayed when referring to a user without a profile.
$this->clientError(_('User has no profile.'));
return;
}
$twitter_user = $this->twitterUserArray($profile, true);
if ($this->format == 'xml') {
$this->initDocument('xml');
$this->showTwitterXmlUser($twitter_user, 'user', true);
$this->endDocument('xml');
} elseif ($this->format == 'json') {
$this->initDocument('json');
$this->showJsonObjects($twitter_user);
$this->endDocument('json');
}
}
}
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Update a user's design colors
*
* 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 Zach Copley <zach@status.net>
* @copyright 2009-2010 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';
/**
* Sets one or more hex values that control the color scheme of the
* authenticating user's design
*
* @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 ApiAccountUpdateProfileColorsAction extends ApiAuthAction
{
var $profile_background_color = null;
var $profile_text_color = null;
var $profile_link_color = null;
var $profile_sidebar_fill_color = null;
var $profile_sidebar_border_color = 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->profile_background_color
= $this->trimmed('profile_background_color');
$this->profile_text_color
= $this->trimmed('profile_text_color');
$this->profile_link_color
= $this->trimmed('profile_link_color');
$this->profile_sidebar_fill_color
= $this->trimmed('profile_sidebar_fill_color');
// XXX: we don't support changing the sidebar border color
// in our designs.
$this->profile_sidebar_border_color
= $this->trimmed('profile_sidebar_border_color');
// XXX: Unlike Twitter, we do allow people to change the 'content color'
$this->profile_content_color = $this->trimmed('profile_content_color');
return true;
}
/**
* Handle the request
*
* Try to save the user's colors in her design. Create a new design
* if the user doesn't already have one.
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
{
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400, $this->format
);
return;
}
if (!in_array($this->format, array('xml', 'json'))) {
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'),
404,
$this->format
);
return;
}
$design = $this->user->getDesign();
if (!empty($design)) {
$original = clone($design);
try {
$this->setColors($design);
} catch (WebColorException $e) {
$this->clientError($e->getMessage(), 400, $this->format);
return false;
}
$result = $design->update($original);
if ($result === false) {
common_log_db_error($design, 'UPDATE', __FILE__);
// TRANS: Client error displayed when a database error occurs updating profile colours.
$this->clientError(_('Could not update your design.'));
return;
}
} else {
$this->user->query('BEGIN');
// save new design
$design = new Design();
try {
$this->setColors($design);
} catch (WebColorException $e) {
$this->clientError($e->getMessage(), 400, $this->format);
return false;
}
$id = $design->insert();
if (empty($id)) {
common_log_db_error($id, 'INSERT', __FILE__);
// TRANS: Client error displayed when a database error occurs inserting profile colours.
$this->clientError(_('Unable to save your design settings.'));
return;
}
$original = clone($this->user);
$this->user->design_id = $id;
$result = $this->user->update($original);
if (empty($result)) {
common_log_db_error($original, 'UPDATE', __FILE__);
// TRANS: Client error displayed when a database error occurs updating profile colours.
$this->clientError(_('Unable to save your design settings.'));
$this->user->query('ROLLBACK');
return;
}
$this->user->query('COMMIT');
}
$profile = $this->user->getProfile();
if (empty($profile)) {
// TRANS: Error message displayed when referring to a user without a profile.
$this->clientError(_('User has no profile.'));
return;
}
$twitter_user = $this->twitterUserArray($profile, true);
if ($this->format == 'xml') {
$this->initDocument('xml');
$this->showTwitterXmlUser($twitter_user, 'user', true);
$this->endDocument('xml');
} elseif ($this->format == 'json') {
$this->initDocument('json');
$this->showJsonObjects($twitter_user);
$this->endDocument('json');
}
}
/**
* Sets the user's design colors based on the request parameters
*
* @param Design $design the user's Design
*
* @return void
*/
function setColors($design)
{
$bgcolor = empty($this->profile_background_color) ?
null : new WebColor($this->profile_background_color);
$tcolor = empty($this->profile_text_color) ?
null : new WebColor($this->profile_text_color);
$sbcolor = empty($this->profile_sidebar_fill_color) ?
null : new WebColor($this->profile_sidebar_fill_color);
$lcolor = empty($this->profile_link_color) ?
null : new WebColor($this->profile_link_color);
$ccolor = empty($this->profile_content_color) ?
null : new WebColor($this->profile_content_color);
if (!empty($bgcolor)) {
$design->backgroundcolor = $bgcolor->intValue();
}
if (!empty($ccolor)) {
$design->contentcolor = $ccolor->intValue();
}
if (!empty($sbcolor)) {
$design->sidebarcolor = $sbcolor->intValue();
}
if (!empty($tcolor)) {
$design->textcolor = $tcolor->intValue();
}
if (!empty($lcolor)) {
$design->linkcolor = $lcolor->intValue();
}
return true;
}
}
......@@ -40,7 +40,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
class BlockedfromgroupAction extends GroupDesignAction
class BlockedfromgroupAction extends GroupAction
{
var $page = null;
......
This diff is collapsed.
......@@ -22,7 +22,7 @@
* @category Applications
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @copyright 2008-2011 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/
*/
......@@ -42,7 +42,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
class EditApplicationAction extends OwnerDesignAction
class EditApplicationAction extends Action
{
var $msg = null;
var $owner = null;
......
......@@ -23,8 +23,8 @@
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @author Zach Copley <zach@status.net>
* @copyright 2008-2011 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/
*/
......@@ -45,7 +45,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
class EditgroupAction extends GroupDesignAction
class EditgroupAction extends GroupAction
{
var $msg;
......
......@@ -40,7 +40,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @link http://status.net/
*/
class EditpeopletagAction extends OwnerDesignAction
class EditpeopletagAction extends Action
{
var $msg, $confirm, $confirm_args=array();
......
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Saves a design for a given group.
*
* 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 Settings
* @package StatusNet
* @author Sarven Capadisli <csarven@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR . '/lib/designsettings.php';
/**
* Set a group's design
*
* Saves a design for a given group
*
* @category Settings
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @author Sarven Capadisli <csarven@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 GroupDesignSettingsAction extends DesignSettingsAction
{
var $group = null;
/**
* Sets the right action for the form, and passes request args into
* the base action
*
* @param array $args misc. arguments
*
* @return boolean true
*/
function prepare($args)
{
parent::prepare($args);
if (!common_logged_in()) {
// TRANS: Client error displayed trying to change group design settings while not logged in.
$this->clientError(_('You must be logged in to edit a group.'));
return false;
}
$nickname_arg = $this->trimmed('nickname');
$nickname = common_canonical_nickname($nickname_arg);
// Permanent redirect on non-canonical nickname
if ($nickname_arg != $nickname) {
$args = array('nickname' => $nickname);
common_redirect(common_local_url('groupdesignsettings', $args), 301);
return false;
}
if (!$nickname) {
// TRANS: Client error displayed trying to change group design settings without providing a group nickname.
$this->clientError(_('No nickname.'), 404);
return false;
}
$groupid = $this->trimmed('groupid');
if ($groupid) {
$this->group = User_group::staticGet('id', $groupid);
} else {
$local = Local_group::staticGet('nickname', $nickname);
if ($local) {
$this->group = User_group::staticGet('id', $local->group_id);
}
}
if (!$this->group) {
// TRANS: Client error displayed trying to change group design settings while providing a nickname for a non-existing group.
$this->clientError(_('No such group.'), 404);
return false;
}
$cur = common_current_user();
if (!$cur->isAdmin($this->group)) {
// TRANS: Client error displayed trying to change group design settings without being a (group) admin.
$this->clientError(_('You must be an admin to edit the group.'), 403);
return false;
}
$this->submitaction = common_local_url('groupdesignsettings',
array('nickname' => $this->group->nickname));
return true;
}
/**
* A design for this action
*
* if the group attribute has been set, returns that group's
* design.
*
* @return Design a design object to use
*/
function getDesign()
{
if (empty($this->group)) {
return null;
}
return $this->group->getDesign();
}
/**
* Title of the page
*
* @return string Title of the page
*/
function title()
{
// TRANS: Title group design settings page.
return _('Group design');
}
/**
* Instructions for use
*
* @return instructions for use
*/
function getInstructions()
{
// TRANS: Instructions for group design settings page.
return _('Customize the way your group looks ' .
'with a background image and a colour palette of your choice.');
}
/**
* Override to show group nav stuff
*
* @return nothing
*/
function showObjectNav()
{
$nav = new GroupNav($this, $this->group);
$nav->show();
}
/**
* Override to show default nav stuff
*
* @return nothing
*/
function showLocalNav()
{
Action::showLocalNav();
}
/**
* Get the design we want to edit
*
* @return Design
*/
function getWorkingDesign()
{
$design = null;
if (isset($this->group)) {
$design = $this->group->getDesign();
}