X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ftagprofile.php;h=871d0e30b09012f1b809cf9e68829ef52a5dafc2;hb=b596391fcd05dddc8c37495b663d3be074eac05d;hp=871626ef1925f4a208bcdf44384e601010f72af9;hpb=4b40d6bb2ad6540fe114eebe74b2330902382a81;p=quix0rs-gnu-social.git diff --git a/actions/tagprofile.php b/actions/tagprofile.php index 871626ef19..871d0e30b0 100644 --- a/actions/tagprofile.php +++ b/actions/tagprofile.php @@ -19,9 +19,6 @@ if (!defined('GNUSOCIAL')) { exit(1); } -require_once INSTALLDIR . '/lib/settingsaction.php'; -require_once INSTALLDIR . '/lib/peopletags.php'; - class TagprofileAction extends FormAction { var $error = null; @@ -29,36 +26,32 @@ class TagprofileAction extends FormAction protected $target = null; protected $form = 'TagProfile'; - protected function prepare(array $args=array()) + protected function doPreparation() { - parent::prepare($args); - $id = $this->trimmed('id'); - if (!$id) { - $this->target = null; - } else { + $uri = $this->trimmed('uri'); + if (!empty($id)) { $this->target = Profile::getKV('id', $id); if (!$this->target instanceof Profile) { // TRANS: Client error displayed when referring to non-existing profile ID. $this->clientError(_('No profile with that ID.')); } + } 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.')); } - if ($this->target instanceof Profile && !$this->scoped->canTag($this->target)) { + 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; - } + $this->formOpts = $this->target; - protected function handle() - { - if (Event::handle('StartTagProfileAction', array($this, $this->target))) { - parent::handle(); - Event::handle('EndTagProfileAction', array($this, $this->target)); - } + return true; } function title() @@ -72,6 +65,15 @@ class TagprofileAction extends FormAction return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname()); } + function showPage() + { + // Only serve page content if we aren't POSTing via ajax + // otherwise, we serve XML content from doPost() + if (!$this->isPost() || !$this->boolean('ajax')) { + parent::showPage(); + } + } + function showContent() { $this->elementStart('div', 'entity_profile h-card'); @@ -115,17 +117,8 @@ class TagprofileAction extends FormAction } } - protected function getForm() - { - $class = $this->form.'Form'; - $form = new $class($this, $this->target); - return $form; - } - - protected function handlePost() + protected function doPost() { - parent::handlePost(); // Does nothing for now - $tagstring = $this->trimmed('tags'); $token = $this->trimmed('token'); @@ -144,22 +137,16 @@ class TagprofileAction extends FormAction 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; } } - try { - $result = Profile_tag::setTags($this->scoped->id, $this->target->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')) { @@ -188,17 +175,4 @@ class TagprofileAction extends FormAction 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'); - } - } }