2011-03-07 04:13:31 +09:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2011-03-07 04:13:31 +09:00
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/settingsaction.php';
|
|
|
|
require_once INSTALLDIR . '/lib/peopletags.php';
|
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
class TagprofileAction extends FormAction
|
2011-03-07 04:13:31 +09:00
|
|
|
{
|
|
|
|
var $error = null;
|
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
protected $target = null;
|
|
|
|
protected $form = 'TagProfile';
|
|
|
|
|
|
|
|
protected function prepare(array $args=array())
|
2011-03-07 04:13:31 +09:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$id = $this->trimmed('id');
|
|
|
|
if (!$id) {
|
2014-07-03 21:02:21 +09:00
|
|
|
$this->target = null;
|
2011-03-07 04:13:31 +09:00
|
|
|
} else {
|
2014-07-03 21:02:21 +09:00
|
|
|
$this->target = Profile::getKV('id', $id);
|
2011-03-07 04:13:31 +09:00
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if (!$this->target instanceof Profile) {
|
2011-04-11 02:59:55 +09:00
|
|
|
// TRANS: Client error displayed when referring to non-existing profile ID.
|
2011-03-07 04:13:31 +09:00
|
|
|
$this->clientError(_('No profile with that ID.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if ($this->target instanceof Profile && !$this->scoped->canTag($this->target)) {
|
2011-04-11 02:59:55 +09:00
|
|
|
// TRANS: Client error displayed when trying to tag a user that cannot be tagged.
|
2011-03-07 04:13:31 +09:00
|
|
|
$this->clientError(_('You cannot tag this user.'));
|
|
|
|
}
|
2014-07-03 21:02:21 +09:00
|
|
|
|
|
|
|
return true;
|
2011-03-07 04:13:31 +09:00
|
|
|
}
|
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
protected function handle()
|
2011-03-07 04:13:31 +09:00
|
|
|
{
|
2014-07-03 21:02:21 +09:00
|
|
|
if (Event::handle('StartTagProfileAction', array($this, $this->target))) {
|
|
|
|
parent::handle();
|
|
|
|
Event::handle('EndTagProfileAction', array($this, $this->target));
|
2011-03-07 04:13:31 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function title()
|
|
|
|
{
|
2014-07-03 21:02:21 +09:00
|
|
|
if (!$this->target instanceof Profile) {
|
2011-04-18 03:08:03 +09:00
|
|
|
// TRANS: Title for list form when not on a profile page.
|
|
|
|
return _('List a profile');
|
2011-03-07 04:13:31 +09:00
|
|
|
}
|
2011-04-18 03:08:03 +09:00
|
|
|
// TRANS: Title for list form when on a profile page.
|
2011-04-11 02:59:55 +09:00
|
|
|
// TRANS: %s is a profile nickname.
|
2014-07-03 21:02:21 +09:00
|
|
|
return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname());
|
2011-03-07 04:13:31 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function showContent()
|
|
|
|
{
|
2014-07-03 21:02:21 +09:00
|
|
|
$this->elementStart('div', 'entity_profile h-card');
|
|
|
|
// TRANS: Header in list form.
|
|
|
|
$this->element('h2', null, _('User profile'));
|
|
|
|
|
|
|
|
$avatarUrl = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
|
|
|
|
$this->element('img', array('src' => $avatarUrl,
|
|
|
|
'class' => 'u-photo avatar entity_depiction',
|
|
|
|
'width' => AVATAR_PROFILE_SIZE,
|
|
|
|
'height' => AVATAR_PROFILE_SIZE,
|
|
|
|
'alt' => $this->target->getBestName()));
|
|
|
|
|
|
|
|
$this->element('a', array('href' => $this->target->getUrl(),
|
|
|
|
'class' => 'entity_nickname p-nickname'),
|
|
|
|
$this->target->getNickname());
|
|
|
|
if ($this->target->fullname) {
|
|
|
|
$this->element('div', 'p-name entity_fn', $this->target->fullname);
|
|
|
|
}
|
2011-03-07 04:13:31 +09:00
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if ($this->target->location) {
|
|
|
|
$this->element('div', 'p-locality label entity_location', $this->target->location);
|
|
|
|
}
|
2011-03-07 04:13:31 +09:00
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if ($this->target->homepage) {
|
|
|
|
$this->element('a', array('href' => $this->target->homepage,
|
|
|
|
'rel' => 'me',
|
|
|
|
'class' => 'u-url entity_url'),
|
|
|
|
$this->target->homepage);
|
|
|
|
}
|
2011-03-07 04:13:31 +09:00
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if ($this->target->bio) {
|
|
|
|
$this->element('div', 'p-note entity_note', $this->target->bio);
|
|
|
|
}
|
2011-03-07 04:13:31 +09:00
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
$this->elementEnd('div');
|
2011-03-07 04:13:31 +09:00
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) {
|
|
|
|
parent::showContent();
|
|
|
|
Event::handle('EndShowTagProfileForm', array($this, $this->target));
|
2011-03-07 04:13:31 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
protected function getForm()
|
2011-03-07 04:13:31 +09:00
|
|
|
{
|
2014-07-03 21:02:21 +09:00
|
|
|
$class = $this->form.'Form';
|
|
|
|
$form = new $class($this, $this->target);
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function handlePost()
|
|
|
|
{
|
|
|
|
parent::handlePost(); // Does nothing for now
|
|
|
|
|
2011-03-07 04:13:31 +09:00
|
|
|
$tagstring = $this->trimmed('tags');
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
|
|
|
|
if (Event::handle('StartSavePeopletags', array($this, $tagstring))) {
|
|
|
|
$tags = array();
|
|
|
|
$tag_priv = array();
|
|
|
|
|
|
|
|
if (is_string($tagstring) && strlen($tagstring) > 0) {
|
|
|
|
|
|
|
|
$tags = preg_split('/[\s,]+/', $tagstring);
|
|
|
|
|
|
|
|
foreach ($tags as &$tag) {
|
|
|
|
$private = @$tag[0] === '.';
|
|
|
|
|
|
|
|
$tag = common_canonical_tag($tag);
|
|
|
|
if (!common_valid_profile_tag($tag)) {
|
2011-04-11 02:59:55 +09:00
|
|
|
// TRANS: Form validation error displayed if a given tag is invalid.
|
|
|
|
// TRANS: %s is the invalid tag.
|
|
|
|
$this->showForm(sprintf(_('Invalid tag: "%s".'), $tag));
|
2011-03-07 04:13:31 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tag_priv[$tag] = $private;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-07-03 21:02:21 +09:00
|
|
|
$result = Profile_tag::setTags($this->scoped->id, $this->target->id, $tags, $tag_priv);
|
2011-03-07 04:13:31 +09:00
|
|
|
if (!$result) {
|
|
|
|
throw new Exception('The tags could not be saved.');
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->showForm($e->getMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->boolean('ajax')) {
|
|
|
|
$this->startHTML('text/xml;charset=utf-8');
|
|
|
|
$this->elementStart('head');
|
2011-04-11 02:59:55 +09:00
|
|
|
$this->element('title', null, _m('TITLE','Tags'));
|
2011-03-07 04:13:31 +09:00
|
|
|
$this->elementEnd('head');
|
|
|
|
$this->elementStart('body');
|
|
|
|
|
2014-07-03 21:02:21 +09:00
|
|
|
if ($this->scoped->id == $this->target->id) {
|
|
|
|
$widget = new SelftagsWidget($this, $this->scoped, $this->target);
|
2011-03-07 04:13:31 +09:00
|
|
|
$widget->show();
|
|
|
|
} else {
|
2014-07-03 21:02:21 +09:00
|
|
|
$widget = new PeopletagsWidget($this, $this->scoped, $this->target);
|
2011-03-07 04:13:31 +09:00
|
|
|
$widget->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->elementEnd('body');
|
2013-09-24 09:32:17 +09:00
|
|
|
$this->endHTML();
|
2011-03-07 04:13:31 +09:00
|
|
|
} else {
|
2011-04-18 03:08:03 +09:00
|
|
|
// TRANS: Success message if lists are saved.
|
2014-07-03 21:02:21 +09:00
|
|
|
$this->msg = _('Lists saved.');
|
2011-03-07 04:13:31 +09:00
|
|
|
$this->showForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
Event::handle('EndSavePeopletags', array($this, $tagstring));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPageNotice()
|
|
|
|
{
|
|
|
|
if ($this->error) {
|
|
|
|
$this->element('p', 'error', $this->error);
|
|
|
|
} else {
|
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->element('p', null,
|
2011-04-11 02:59:55 +09:00
|
|
|
// TRANS: Page notice.
|
2011-04-18 03:08:03 +09:00
|
|
|
_('Use this form to add your subscribers or subscriptions to lists.'));
|
2011-03-07 04:13:31 +09:00
|
|
|
$this->elementEnd('div');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|