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

tagprofile.php 6.16 KB
Newer Older
Shashi Gowda's avatar
Shashi Gowda committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?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/>.
 */

20
if (!defined('GNUSOCIAL')) { exit(1); }
Shashi Gowda's avatar
Shashi Gowda committed
21

22
class TagprofileAction extends FormAction
Shashi Gowda's avatar
Shashi Gowda committed
23 24 25
{
    var $error = null;

26 27 28
    protected $target = null;
    protected $form = 'TagProfile';

29
    protected function doPreparation()
Shashi Gowda's avatar
Shashi Gowda committed
30 31
    {
        $id = $this->trimmed('id');
32 33
        $uri = $this->trimmed('uri');
        if (!empty($id))  {
34
            $this->target = Profile::getKV('id', $id);
Shashi Gowda's avatar
Shashi Gowda committed
35

36
            if (!$this->target instanceof Profile) {
37
                // TRANS: Client error displayed when referring to non-existing profile ID.
Shashi Gowda's avatar
Shashi Gowda committed
38 39
                $this->clientError(_('No profile with that ID.'));
            }
40 41 42 43 44
        } 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.'));
Shashi Gowda's avatar
Shashi Gowda committed
45 46
        }

47
        if (!$this->scoped->canTag($this->target)) {
48
            // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
Shashi Gowda's avatar
Shashi Gowda committed
49 50
            $this->clientError(_('You cannot tag this user.'));
        }
51

52
        $this->formOpts = $this->target;
Shashi Gowda's avatar
Shashi Gowda committed
53

54
        return true;
Shashi Gowda's avatar
Shashi Gowda committed
55 56 57 58
    }

    function title()
    {
59
        if (!$this->target instanceof Profile) {
60 61
            // TRANS: Title for list form when not on a profile page.
            return _('List a profile');
Shashi Gowda's avatar
Shashi Gowda committed
62
        }
63
        // TRANS: Title for list form when on a profile page.
64
        // TRANS: %s is a profile nickname.
65
        return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname());
Shashi Gowda's avatar
Shashi Gowda committed
66 67 68 69
    }

    function showContent()
    {
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        $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);
        }
Shashi Gowda's avatar
Shashi Gowda committed
87

88 89 90
        if ($this->target->location) {
            $this->element('div', 'p-locality label entity_location', $this->target->location);
        }
Shashi Gowda's avatar
Shashi Gowda committed
91

92 93 94 95 96 97
        if ($this->target->homepage) {
            $this->element('a', array('href' => $this->target->homepage,
                                      'rel' => 'me',
                                      'class' => 'u-url entity_url'),
                           $this->target->homepage);
        }
Shashi Gowda's avatar
Shashi Gowda committed
98

99 100 101
        if ($this->target->bio) {
            $this->element('div', 'p-note entity_note', $this->target->bio);
        }
Shashi Gowda's avatar
Shashi Gowda committed
102

103
        $this->elementEnd('div');
Shashi Gowda's avatar
Shashi Gowda committed
104

105 106 107
        if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) {
            parent::showContent();
            Event::handle('EndShowTagProfileForm', array($this, $this->target));
Shashi Gowda's avatar
Shashi Gowda committed
108 109 110
        }
    }

111
    protected function doPost()
112
    {
Shashi Gowda's avatar
Shashi Gowda committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        $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)) {
129 130
                        // TRANS: Form validation error displayed if a given tag is invalid.
                        // TRANS: %s is the invalid tag.
131
                        throw new ClientException(sprintf(_('Invalid tag: "%s".'), $tag));
Shashi Gowda's avatar
Shashi Gowda committed
132 133 134 135 136 137
                    }

                    $tag_priv[$tag] = $private;
                }
            }

138 139 140
            $result = Profile_tag::setTags($this->scoped->getID(), $this->target->getID(), $tags, $tag_priv);
            if (!$result) {
                throw new ServerException('The tags could not be saved.');
Shashi Gowda's avatar
Shashi Gowda committed
141 142 143 144 145
            }

            if ($this->boolean('ajax')) {
                $this->startHTML('text/xml;charset=utf-8');
                $this->elementStart('head');
146
                $this->element('title', null, _m('TITLE','Tags'));
Shashi Gowda's avatar
Shashi Gowda committed
147 148 149
                $this->elementEnd('head');
                $this->elementStart('body');

150 151
                if ($this->scoped->id == $this->target->id) {
                    $widget = new SelftagsWidget($this, $this->scoped, $this->target);
Shashi Gowda's avatar
Shashi Gowda committed
152 153
                    $widget->show();
                } else {
154
                    $widget = new PeopletagsWidget($this, $this->scoped, $this->target);
Shashi Gowda's avatar
Shashi Gowda committed
155 156 157 158
                    $widget->show();
                }

                $this->elementEnd('body');
159
                $this->endHTML();
Shashi Gowda's avatar
Shashi Gowda committed
160
            } else {
161
                // TRANS: Success message if lists are saved.
162
                $this->msg = _('Lists saved.');
Shashi Gowda's avatar
Shashi Gowda committed
163 164 165 166 167 168 169
                $this->showForm();
            }

            Event::handle('EndSavePeopletags', array($this, $tagstring));
        }
    }
}