X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=actions%2Ftagprofile.php;h=79a401c6a93dccfb7d584ddb088d4cb33f1fdd7d;hb=c85e78ac3c03bd584a6da3a0a7b5cb9160cc9324;hp=4305f4bc885f45643b13941d4fb79b1463601a2c;hpb=25198a8d4cee5b2182f1ecb99192a4108a01afa4;p=quix0rs-gnu-social.git diff --git a/actions/tagprofile.php b/actions/tagprofile.php index 4305f4bc88..79a401c6a9 100644 --- a/actions/tagprofile.php +++ b/actions/tagprofile.php @@ -17,177 +17,105 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +if (!defined('GNUSOCIAL')) { exit(1); } -require_once INSTALLDIR . '/lib/settingsaction.php'; require_once INSTALLDIR . '/lib/peopletags.php'; -class TagprofileAction extends Action +class TagprofileAction extends FormAction { - var $profile = null; var $error = null; - function 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); - } - } + protected $target = null; + protected $form = 'TagProfile'; + protected function doPreparation() + { $id = $this->trimmed('id'); - if (!$id) { - $this->profile = false; - } else { - $this->profile = Profile::staticGet('id', $id); + $uri = $this->trimmed('uri'); + if (!empty($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. $this->clientError(_('No profile with that ID.')); - return false; } + } elseif (!empty($uri)) { + $this->target = Profile::fromUri($uri); + } else { + // TRANS: Client error displayed when trying to tag a user but no ID or profile is provided. + $this->clientError(_('No profile identifier provided.')); } - $current = common_current_user()->getProfile(); - if ($this->profile && !$current->canTag($this->profile)) { + if (!$this->scoped->canTag($this->target)) { // TRANS: Client error displayed when trying to tag a user that cannot be tagged. $this->clientError(_('You cannot tag this user.')); } - return true; - } - function handle($args) - { - parent::handle($args); - if (Event::handle('StartTagProfileAction', array($this, $this->profile))) { - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $this->saveTags(); - } else { - $this->showForm(); - } - Event::handle('EndTagProfileAction', array($this, $this->profile)); - } + $this->formOpts = $this->target; + + return true; } function title() { - if (!$this->profile) { + if (!$this->target instanceof Profile) { // TRANS: Title for list form when not on a profile page. return _('List a profile'); } // TRANS: Title for list form when on a profile page. // TRANS: %s is a profile nickname. - return sprintf(_m('ADDTOLIST','List %s'), $this->profile->nickname); - } - - 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->elementEnd('html'); - } else { - $this->showPage(); - } + return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname()); } function showContent() { - if (Event::handle('StartShowTagProfileForm', array($this, $this->profile)) && $this->profile) { - $this->elementStart('div', 'entity_profile vcard author'); - // TRANS: Header in list form. - $this->element('h2', null, _('User profile')); - - $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); - $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE), - 'class' => 'photo avatar entity_depiction', - 'width' => AVATAR_PROFILE_SIZE, - 'height' => AVATAR_PROFILE_SIZE, - 'alt' => - ($this->profile->fullname) ? $this->profile->fullname : - $this->profile->nickname)); - - $this->element('a', array('href' => $this->profile->profileurl, - 'class' => 'entity_nickname nickname'), - $this->profile->nickname); - if ($this->profile->fullname) { - $this->element('div', 'fn entity_fn', $this->profile->fullname); - } - - if ($this->profile->location) { - $this->element('div', 'label entity_location', $this->profile->location); - } - - if ($this->profile->homepage) { - $this->element('a', array('href' => $this->profile->homepage, - 'rel' => 'me', - 'class' => 'url entity_url'), - $this->profile->homepage); - } - - if ($this->profile->bio) { - $this->element('div', 'note entity_note', $this->profile->bio); - } - - $this->elementEnd('div'); - - $this->elementStart('form', array('method' => 'post', - 'id' => 'form_tag_user', - 'class' => 'form_settings', - 'name' => 'tagprofile', - 'action' => common_local_url('tagprofile', array('id' => $this->profile->id)))); + $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); + } - $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); + if ($this->target->location) { + $this->element('div', 'p-locality label entity_location', $this->target->location); + } - $user = common_current_user(); + if ($this->target->homepage) { + $this->element('a', array('href' => $this->target->homepage, + 'rel' => 'me', + 'class' => 'u-url entity_url'), + $this->target->homepage); + } - $this->elementStart('ul', 'form_data'); - $this->elementStart('li'); + if ($this->target->bio) { + $this->element('div', 'p-note entity_note', $this->target->bio); + } - $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'); + $this->elementEnd('div'); - Event::handle('EndShowTagProfileForm', array($this, $this->profile)); + if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) { + parent::showContent(); + Event::handle('EndShowTagProfileForm', array($this, $this->target)); } } - function saveTags() + protected function doPost() { - $id = $this->trimmed('id'); $tagstring = $this->trimmed('tags'); $token = $this->trimmed('token'); 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(); $tag_priv = array(); @@ -202,24 +130,16 @@ class TagprofileAction extends Action if (!common_valid_profile_tag($tag)) { // TRANS: Form validation error displayed if a given tag is invalid. // TRANS: %s is the invalid tag. - $this->showForm(sprintf(_('Invalid tag: "%s".'), $tag)); - return; + throw new ClientException(sprintf(_('Invalid tag: "%s".'), $tag)); } $tag_priv[$tag] = $private; } } - $user = common_current_user(); - - try { - $result = Profile_tag::setTags($user->id, $this->profile->id, $tags, $tag_priv); - if (!$result) { - throw new Exception('The tags could not be saved.'); - } - } catch (Exception $e) { - $this->showForm($e->getMessage()); - return false; + $result = Profile_tag::setTags($this->scoped->getID(), $this->target->getID(), $tags, $tag_priv); + if (!$result) { + throw new ServerException('The tags could not be saved.'); } if ($this->boolean('ajax')) { @@ -229,36 +149,23 @@ class TagprofileAction extends Action $this->elementEnd('head'); $this->elementStart('body'); - if ($user->id == $this->profile->id) { - $widget = new SelftagsWidget($this, $user, $this->profile); + if ($this->scoped->id == $this->target->id) { + $widget = new SelftagsWidget($this, $this->scoped, $this->target); $widget->show(); } else { - $widget = new PeopletagsWidget($this, $user, $this->profile); + $widget = new PeopletagsWidget($this, $this->scoped, $this->target); $widget->show(); } $this->elementEnd('body'); - $this->elementEnd('html'); + $this->endHTML(); } else { // TRANS: Success message if lists are saved. - $this->error = _('Lists saved.'); + $this->msg = _('Lists saved.'); $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, - // TRANS: Page notice. - _('Use this form to add your subscribers or subscriptions to lists.')); - $this->elementEnd('div'); - } - } }