TagprofileAction fiddled with, now doesn't require OStatus override

But it still doesn't quite work properly, so a lot of work is necessary for this.
This commit is contained in:
Mikael Nordfeldth 2014-07-03 14:02:21 +02:00
parent 7f0c7e8e80
commit 4b40d6bb2a
2 changed files with 64 additions and 152 deletions

View File

@ -17,175 +17,119 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } if (!defined('GNUSOCIAL')) { exit(1); }
require_once INSTALLDIR . '/lib/settingsaction.php'; require_once INSTALLDIR . '/lib/settingsaction.php';
require_once INSTALLDIR . '/lib/peopletags.php'; require_once INSTALLDIR . '/lib/peopletags.php';
class TagprofileAction extends Action class TagprofileAction extends FormAction
{ {
var $profile = null;
var $error = null; var $error = null;
function prepare($args) protected $target = null;
protected $form = 'TagProfile';
protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);
if (!common_logged_in()) {
common_set_returnto($_SERVER['REQUEST_URI']);
if (Event::handle('RedirectToLogin', array($this, null))) {
common_redirect(common_local_url('login'), 303);
}
}
$id = $this->trimmed('id'); $id = $this->trimmed('id');
if (!$id) { if (!$id) {
$this->profile = false; $this->target = null;
} else { } else {
$this->profile = Profile::getKV('id', $id); $this->target = Profile::getKV('id', $id);
if (!$this->profile) { if (!$this->target instanceof Profile) {
// TRANS: Client error displayed when referring to non-existing profile ID. // TRANS: Client error displayed when referring to non-existing profile ID.
$this->clientError(_('No profile with that ID.')); $this->clientError(_('No profile with that ID.'));
} }
} }
$current = common_current_user()->getProfile(); if ($this->target instanceof Profile && !$this->scoped->canTag($this->target)) {
if ($this->profile && !$current->canTag($this->profile)) {
// TRANS: Client error displayed when trying to tag a user that cannot be tagged. // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
$this->clientError(_('You cannot tag this user.')); $this->clientError(_('You cannot tag this user.'));
} }
return true;
} }
function handle($args) protected function handle()
{ {
parent::handle($args); if (Event::handle('StartTagProfileAction', array($this, $this->target))) {
if (Event::handle('StartTagProfileAction', array($this, $this->profile))) { parent::handle();
if ($_SERVER['REQUEST_METHOD'] == 'POST') { Event::handle('EndTagProfileAction', array($this, $this->target));
$this->saveTags();
} else {
$this->showForm();
}
Event::handle('EndTagProfileAction', array($this, $this->profile));
} }
} }
function title() function title()
{ {
if (!$this->profile) { if (!$this->target instanceof Profile) {
// TRANS: Title for list form when not on a profile page. // TRANS: Title for list form when not on a profile page.
return _('List a profile'); return _('List a profile');
} }
// TRANS: Title for list form when on a profile page. // TRANS: Title for list form when on a profile page.
// TRANS: %s is a profile nickname. // TRANS: %s is a profile nickname.
return sprintf(_m('ADDTOLIST','List %s'), $this->profile->nickname); return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname());
}
function showForm($error=null)
{
$this->error = $error;
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Title for list form when an error has occurred.
$this->element('title', null, _m('TITLE','Error'));
$this->elementEnd('head');
$this->elementStart('body');
$this->element('p', 'error', $error);
$this->elementEnd('body');
$this->endHTML();
} else {
$this->showPage();
}
} }
function showContent() function showContent()
{ {
if (Event::handle('StartShowTagProfileForm', array($this, $this->profile)) && $this->profile) { $this->elementStart('div', 'entity_profile h-card');
$this->elementStart('div', 'entity_profile h-card p-author'); // TRANS: Header in list form.
// TRANS: Header in list form. $this->element('h2', null, _('User profile'));
$this->element('h2', null, _('User profile'));
$avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE); $avatarUrl = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$this->element('img', array('src' => $avatarUrl, $this->element('img', array('src' => $avatarUrl,
'class' => 'photo avatar entity_depiction', 'class' => 'u-photo avatar entity_depiction',
'width' => AVATAR_PROFILE_SIZE, 'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE,
'alt' => 'alt' => $this->target->getBestName()));
($this->profile->fullname) ? $this->profile->fullname :
$this->profile->nickname));
$this->element('a', array('href' => $this->profile->profileurl, $this->element('a', array('href' => $this->target->getUrl(),
'class' => 'entity_nickname nickname'), 'class' => 'entity_nickname p-nickname'),
$this->profile->nickname); $this->target->getNickname());
if ($this->profile->fullname) { if ($this->target->fullname) {
$this->element('div', 'p-name entity_fn', $this->profile->fullname); $this->element('div', 'p-name entity_fn', $this->target->fullname);
} }
if ($this->profile->location) { if ($this->target->location) {
$this->element('div', 'label entity_location', $this->profile->location); $this->element('div', 'p-locality label entity_location', $this->target->location);
} }
if ($this->profile->homepage) { if ($this->target->homepage) {
$this->element('a', array('href' => $this->profile->homepage, $this->element('a', array('href' => $this->target->homepage,
'rel' => 'me', 'rel' => 'me',
'class' => 'u-url entity_url'), 'class' => 'u-url entity_url'),
$this->profile->homepage); $this->target->homepage);
} }
if ($this->profile->bio) { if ($this->target->bio) {
$this->element('div', 'note entity_note', $this->profile->bio); $this->element('div', 'p-note entity_note', $this->target->bio);
} }
$this->elementEnd('div'); $this->elementEnd('div');
$this->elementStart('form', array('method' => 'post', if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) {
'id' => 'form_tag_user', parent::showContent();
'class' => 'form_settings', Event::handle('EndShowTagProfileForm', array($this, $this->target));
'name' => 'tagprofile',
'action' => common_local_url('tagprofile', array('id' => $this->profile->id))));
$this->elementStart('fieldset');
// TRANS: Fieldset legend for list form.
$this->element('legend', null, _('List user'));
$this->hidden('token', common_session_token());
$this->hidden('id', $this->profile->id);
$user = common_current_user();
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$tags = Profile_tag::getTagsArray($user->id, $this->profile->id, $user->id);
// TRANS: Field label on list form.
$this->input('tags', _m('LABEL','Lists'),
($this->arg('tags')) ? $this->arg('tags') : implode(' ', $tags),
// TRANS: Field title on list form.
_('Lists for this user (letters, numbers, -, ., and _), comma- or space- separated.'));
$this->elementEnd('li');
$this->elementEnd('ul');
// TRANS: Button text to save lists.
$this->submit('save', _m('BUTTON','Save'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
Event::handle('EndShowTagProfileForm', array($this, $this->profile));
} }
} }
function saveTags() protected function getForm()
{ {
$id = $this->trimmed('id'); $class = $this->form.'Form';
$form = new $class($this, $this->target);
return $form;
}
protected function handlePost()
{
parent::handlePost(); // Does nothing for now
$tagstring = $this->trimmed('tags'); $tagstring = $this->trimmed('tags');
$token = $this->trimmed('token'); $token = $this->trimmed('token');
if (Event::handle('StartSavePeopletags', array($this, $tagstring))) { if (Event::handle('StartSavePeopletags', array($this, $tagstring))) {
if (!$token || $token != common_session_token()) {
// TRANS: Client error displayed when the session token does not match or is not given.
$this->showForm(_('There was a problem with your session token. '.
'Try again, please.'));
return;
}
$tags = array(); $tags = array();
$tag_priv = array(); $tag_priv = array();
@ -208,10 +152,8 @@ class TagprofileAction extends Action
} }
} }
$user = common_current_user();
try { try {
$result = Profile_tag::setTags($user->id, $this->profile->id, $tags, $tag_priv); $result = Profile_tag::setTags($this->scoped->id, $this->target->id, $tags, $tag_priv);
if (!$result) { if (!$result) {
throw new Exception('The tags could not be saved.'); throw new Exception('The tags could not be saved.');
} }
@ -227,11 +169,11 @@ class TagprofileAction extends Action
$this->elementEnd('head'); $this->elementEnd('head');
$this->elementStart('body'); $this->elementStart('body');
if ($user->id == $this->profile->id) { if ($this->scoped->id == $this->target->id) {
$widget = new SelftagsWidget($this, $user, $this->profile); $widget = new SelftagsWidget($this, $this->scoped, $this->target);
$widget->show(); $widget->show();
} else { } else {
$widget = new PeopletagsWidget($this, $user, $this->profile); $widget = new PeopletagsWidget($this, $this->scoped, $this->target);
$widget->show(); $widget->show();
} }
@ -239,7 +181,7 @@ class TagprofileAction extends Action
$this->endHTML(); $this->endHTML();
} else { } else {
// TRANS: Success message if lists are saved. // TRANS: Success message if lists are saved.
$this->error = _('Lists saved.'); $this->msg = _('Lists saved.');
$this->showForm(); $this->showForm();
} }

View File

@ -233,36 +233,6 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
function onStartShowTagProfileForm($action, $profile)
{
$action->elementStart('form', array('method' => 'post',
'id' => 'form_tag_user',
'class' => 'form_settings',
'name' => 'tagprofile',
'action' => common_local_url('tagprofile', array('id' => @$profile->id))));
$action->elementStart('fieldset');
// TRANS: Fieldset legend.
$action->element('legend', null, _m('List remote profile'));
$action->hidden('token', common_session_token());
$user = common_current_user();
$action->elementStart('ul', 'form_data');
$action->elementStart('li');
// TRANS: Field label.
$action->input('uri', _m('LABEL','Remote profile'), $action->trimmed('uri'),
// TRANS: Field title.
_m('OStatus user\'s address, like nickname@example.com or http://example.net/nickname.'));
$action->elementEnd('li');
$action->elementEnd('ul');
// TRANS: Button text to fetch remote profile.
$action->submit('fetch', _m('BUTTON','Fetch'));
$action->elementEnd('fieldset');
$action->elementEnd('form');
}
function onStartTagProfileAction($action, $profile) function onStartTagProfileAction($action, $profile)
{ {
$err = null; $err = null;