We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 4b9df58c authored by Evan Prodromou's avatar Evan Prodromou

Merge branch 'master' into groups

Conflicts:

	.gitignore
parents bd056218 65bfda33
......@@ -5,3 +5,7 @@ config.php
.htaccess
*.tmproj
dataobject.ini
*~
*.bak
*.orig
*.rej
......@@ -817,6 +817,10 @@ private: If set to 'true', anonymous users will be redirected to the
authentication will require it. Note that this does not turn
off registration; use 'closed' or 'inviteonly' for the
behaviour you want.
notice: A plain string that will appear on every page. A good place
to put introductory information about your service, or info about
upgrades and outages, or other community info. Any HTML will
be escaped.
db
--
......
......@@ -38,7 +38,7 @@ class AccesstokenAction extends Action
common_debug('printing the access token', __FILE__);
print $token;
} catch (OAuthException $e) {
common_server_error($e->getMessage());
$this->serverError($e->getMessage());
}
}
}
......@@ -19,80 +19,86 @@
if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/actions/showstream.php');
require_once INSTALLDIR.'/lib/personalgroupnav.php';
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR.'/lib/feedlist.php';
class AllAction extends StreamAction
class AllAction extends Action
{
var $user = null;
var $page = null;
function handle($args)
function isReadOnly()
{
return true;
}
parent::handle($args);
function prepare($args)
{
parent::prepare($args);
$nickname = common_canonical_nickname($this->arg('nickname'));
$user = User::staticGet('nickname', $nickname);
if (!$user) {
$this->client_error(_('No such user.'));
return;
$this->user = User::staticGet('nickname', $nickname);
$this->page = $this->trimmed('page');
if (!$this->page) {
$this->page = 1;
}
return true;
}
$profile = $user->getProfile();
function handle($args)
{
parent::handle($args);
if (!$profile) {
common_server_error(_('User has no profile.'));
if (!$this->user) {
$this->clientError(_('No such user.'));
return;
}
# Looks like we're good; show the header
common_show_header(sprintf(_("%s and friends"), $profile->nickname),
array($this, 'show_header'), $user,
array($this, 'show_top'));
$this->show_notices($user);
$this->showPage();
}
common_show_footer();
function title()
{
if ($this->page > 1) {
return sprintf(_("%s and friends, page %d"), $this->user->nickname, $this->page);
} else {
return sprintf(_("%s and friends"), $this->user->nickname);
}
}
function show_header($user)
function showFeeds()
{
common_element('link', array('rel' => 'alternate',
$this->element('link', array('rel' => 'alternate',
'href' => common_local_url('allrss', array('nickname' =>
$user->nickname)),
$this->user->nickname)),
'type' => 'application/rss+xml',
'title' => sprintf(_('Feed for friends of %s'), $user->nickname)));
'title' => sprintf(_('Feed for friends of %s'), $this->user->nickname)));
}
function show_top($user)
function showLocalNav()
{
$cur = common_current_user();
if ($cur && $cur->id == $user->id) {
common_notice_form('all');
}
$this->views_menu();
$this->show_feeds_list(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $user->nickname)),
'type' => 'rss',
'version' => 'RSS 1.0',
'item' => 'allrss')));
$nav = new PersonalGroupNav($this);
$nav->show();
}
function show_notices($user)
function showExportData()
{
$fl = new FeedList($this);
$fl->show(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $this->user->nickname)),
'type' => 'rss',
'version' => 'RSS 1.0',
'item' => 'allrss')));
}
$page = $this->trimmed('page');
if (!$page) {
$page = 1;
}
function showContent()
{
$notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$nl = new NoticeList($notice, $this);
$cnt = $this->show_notice_list($notice);
$cnt = $nl->show();
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'all', array('nickname' => $user->nickname));
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'all', array('nickname' => $this->user->nickname));
}
}
......@@ -34,7 +34,7 @@ class AllrssAction extends Rss10Action
$this->user = User::staticGet('nickname', $nickname);
if (!$this->user) {
common_user_error(_('No such user.'));
$this->clientError(_('No such user.'));
return false;
} else {
return true;
......
......@@ -103,10 +103,10 @@ class ApiAction extends Action
call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata);
} else {
common_user_error("API method not found!", $code=404);
$this->clientError("API method not found!", $code=404);
}
} else {
common_user_error("API method not found!", $code=404);
$this->clientError("API method not found!", $code=404);
}
}
......@@ -159,10 +159,10 @@ class ApiAction extends Action
if ($this->content_type == 'xml') {
header('Content-Type: application/xml; charset=utf-8');
common_start_xml();
common_element_start('hash');
common_element('error', null, $msg);
common_element('request', null, $_SERVER['REQUEST_URI']);
common_element_end('hash');
$this->elementStart('hash');
$this->element('error', null, $msg);
$this->element('request', null, $_SERVER['REQUEST_URI']);
$this->elementEnd('hash');
common_end_xml();
} else if ($this->content_type == 'json') {
header('Content-Type: application/json; charset=utf-8');
......@@ -174,7 +174,7 @@ class ApiAction extends Action
}
}
function is_readonly()
function isReadOnly()
{
# NOTE: before handle(), can't use $this->arg
$apiaction = $_REQUEST['apiaction'];
......
......@@ -26,28 +26,28 @@ class AvatarbynicknameAction extends Action
parent::handle($args);
$nickname = $this->trimmed('nickname');
if (!$nickname) {
$this->client_error(_('No nickname.'));
$this->clientError(_('No nickname.'));
return;
}
$size = $this->trimmed('size');
if (!$size) {
$this->client_error(_('No size.'));
$this->clientError(_('No size.'));
return;
}
$size = strtolower($size);
if (!in_array($size, array('original', '96', '48', '24'))) {
$this->client_error(_('Invalid size.'));
$this->clientError(_('Invalid size.'));
return;
}
$user = User::staticGet('nickname', $nickname);
if (!$user) {
$this->client_error(_('No such user.'));
$this->clientError(_('No such user.'));
return;
}
$profile = $user->getProfile();
if (!$profile) {
$this->client_error(_('User has no profile.'));
$this->clientError(_('User has no profile.'));
return;
}
if ($size == 'original') {
......
<?php
/**
* Laconica, the distributed open-source microblogging tool
*
* Upload an avatar
*
* 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 Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Zach Copley <zach@controlyourself.ca>
* @copyright 2008-2009 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/
if (!defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/accountsettingsaction.php';
/**
* Upload an avatar
*
* We use jQuery to crop the image after upload.
*
* @category Settings
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Zach Copley <zach@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/
class AvatarsettingsAction extends AccountSettingsAction
{
/**
* Title of the page
*
* @return string Title of the page
*/
function title()
{
return _('Avatar');
}
/**
* Instructions for use
*
* @return instructions for use
*/
function getInstructions()
{
return _('Set your personal avatar.');
}
/**
* Content area of the page
*
* Shows a form for uploading an avatar.
*
* @return void
*/
function showContent()
{
$user = common_current_user();
$profile = $user->getProfile();
if (!$profile) {
common_log_db_error($user, 'SELECT', __FILE__);
$this->serverError(_('User without matching profile'));
return;
}
$original = $profile->getOriginalAvatar();
$this->elementStart('form', array('enctype' => 'multipart/form-data',
'method' => 'POST',
'id' => 'avatar',
'action' =>
common_local_url('avatarsettings')));
$this->hidden('token', common_session_token());
if ($original) {
$this->elementStart('div',
array('id' => 'avatar_original',
'class' => 'avatar_view'));
$this->element('h3', null, _("Original:"));
$this->elementStart('div', array('id'=>'avatar_original_view'));
$this->element('img', array('src' => $original->url,
'class' => 'avatar original',
'width' => $original->width,
'height' => $original->height,
'alt' => $user->nickname));
$this->elementEnd('div');
$this->elementEnd('div');
}
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
if ($avatar) {
$this->elementStart('div',
array('id' => 'avatar_preview',
'class' => 'avatar_view'));
$this->element('h3', null, _("Preview:"));
$this->elementStart('div', array('id'=>'avatar_preview_view'));
$this->element('img', array('src' => $original->url,//$avatar->url,
'class' => 'avatar profile',
'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE,
'alt' => $user->nickname));
$this->elementEnd('div');
$this->elementEnd('div');
foreach (array('avatar_crop_x', 'avatar_crop_y',
'avatar_crop_w', 'avatar_crop_h') as $crop_info) {
$this->element('input', array('name' => $crop_info,
'type' => 'hidden',
'id' => $crop_info));
}
$this->submit('crop', _('Crop'));
}
$this->element('input', array('name' => 'MAX_FILE_SIZE',
'type' => 'hidden',
'id' => 'MAX_FILE_SIZE',
'value' => MAX_AVATAR_SIZE));
$this->elementStart('p');
$this->element('input', array('name' => 'avatarfile',
'type' => 'file',
'id' => 'avatarfile'));
$this->elementEnd('p');
$this->submit('upload', _('Upload'));
$this->elementEnd('form');
}
/**
* Handle a post
*
* We mux on the button name to figure out what the user actually wanted.
*
* @return void
*/
function handlePost()
{
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->show_form(_('There was a problem with your session token. '.
'Try again, please.'));
return;
}
if ($this->arg('upload')) {
$this->uploadAvatar();
} else if ($this->arg('crop')) {
$this->cropAvatar();
} else {
$this->showForm(_('Unexpected form submission.'));
}
}
/**
* Handle an image upload
*
* Does all the magic for handling an image upload, and crops the
* image by default.
*
* @return void
*/
function uploadAvatar()
{
switch ($_FILES['avatarfile']['error']) {
case UPLOAD_ERR_OK: // success, jump out
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$this->showForm(_('That file is too big.'));
return;
case UPLOAD_ERR_PARTIAL:
@unlink($_FILES['avatarfile']['tmp_name']);
$this->showForm(_('Partial upload.'));
return;
default:
$this->showForm(_('System error uploading file.'));
return;
}
$info = @getimagesize($_FILES['avatarfile']['tmp_name']);
if (!$info) {
@unlink($_FILES['avatarfile']['tmp_name']);
$this->showForm(_('Not an image or corrupt file.'));
return;
}
switch ($info[2]) {
case IMAGETYPE_GIF:
case IMAGETYPE_JPEG:
case IMAGETYPE_PNG:
break;
default:
$this->showForm(_('Unsupported image file format.'));
return;
}
$user = common_current_user();
$profile = $user->getProfile();
if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) {
$this->showForm(_('Avatar updated.'), true);
} else {
$this->showForm(_('Failed updating avatar.'));
}
@unlink($_FILES['avatarfile']['tmp_name']);
}
/**
* Handle the results of jcrop.
*
* @return void
*/
function cropAvatar()
{
$user = common_current_user();
$profile = $user->getProfile();
$x = $this->arg('avatar_crop_x');
$y = $this->arg('avatar_crop_y');
$w = $this->arg('avatar_crop_w');
$h = $this->arg('avatar_crop_h');
if ($profile->crop_avatars($x, $y, $w, $h)) {
$this->showForm(_('Avatar updated.'), true);
} else {
$this->showForm(_('Failed updating avatar.'));