]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/publicpeopletagcloud.php
Update/add translator documentation.
[quix0rs-gnu-social.git] / actions / publicpeopletagcloud.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Public tag cloud for notices
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Public
23  * @package   StatusNet
24  * @author    Mike Cochrane <mikec@mikenz.geek.nz>
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2008 Mike Cochrane
27  * @copyright 2008-2009 StatusNet, Inc.
28  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29  * @link      http://status.net/
30  */
31
32 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
33
34 define('TAGS_PER_PAGE', 100);
35
36 /**
37  * Public tag cloud for notices
38  *
39  * @category Personal
40  * @package  StatusNet
41  * @author    Mike Cochrane <mikec@mikenz.geek.nz>
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2008 Mike Cochrane
44  * @copyright 2008-2009 StatusNet, Inc.
45  * @link     http://status.net/
46  */
47 class PublicpeopletagcloudAction extends Action
48 {
49     function isReadOnly($args)
50     {
51         return true;
52     }
53
54     function title()
55     {
56         // TRANS: Title for page with public people tag cloud.
57         return _('Public people tag cloud');
58     }
59
60     function showPageNotice()
61     {
62         $this->element('p', 'instructions',
63                        // TRANS: Page notice for page with public people tag cloud.
64                        // TRANS: %s is a StatusNet sitename.
65                        sprintf(_('These are most used people tags on %s'),
66                                common_config('site', 'name')));
67     }
68
69     function showEmptyList()
70     {
71         // TRANS: Empty list message on page with public people tag cloud.
72         // TRANS: This message contains Markdown links in the form [description](link).
73         $message = _('No one has [tagged](%%doc.tags%%) anyone yet.') . ' ';
74
75         if (common_logged_in()) {
76             // TRANS: Additional empty list message on page with public people tag cloud for logged in users.
77             $message .= _('Be the first to tag someone!');
78         }
79         else {
80             // TRANS: Additional empty list message on page with public people tag cloud for anonymous users.
81         // TRANS: This message contains Markdown links in the form [description](link).
82             $message .= _('Why not [register an account](%%action.register%%) and be the first to tag someone!');
83         }
84
85         $this->elementStart('div', 'guide');
86         $this->raw(common_markup_to_html($message));
87         $this->elementEnd('div');
88     }
89
90     function showLocalNav()
91     {
92         $nav = new PublicGroupNav($this);
93         $nav->show();
94     }
95
96     function handle($args)
97     {
98         parent::handle($args);
99         $this->showPage();
100     }
101
102     function showContent()
103     {
104         // XXX: cache this
105
106         $tags = new Profile_tag();
107         $plist = new Profile_list();
108         $plist->private = false;
109
110         $tags->joinAdd($plist);
111         $tags->selectAdd();
112         $tags->selectAdd('profile_tag.tag');
113         $tags->selectAdd('count(profile_tag.tag) as weight');
114         $tags->groupBy('profile_tag.tag');
115         $tags->orderBy('weight DESC');
116
117         $tags->limit(TAGS_PER_PAGE);
118
119         $cnt = $tags->find();
120
121         if ($cnt > 0) {
122             $this->elementStart('div', array('id' => 'tagcloud',
123                                              'class' => 'section'));
124
125             $tw = array();
126             $sum = 0;
127             while ($tags->fetch()) {
128                 $tw[$tags->tag] = $tags->weight;
129                 $sum += $tags->weight;
130             }
131
132             ksort($tw);
133
134             $this->elementStart('dl');
135             // TRANS: DT element on on page with public people tag cloud.
136             $this->element('dt', null, _('People tag cloud'));
137             $this->elementStart('dd');
138             $this->elementStart('ul', 'tags xoxo tag-cloud');
139             foreach ($tw as $tag => $weight) {
140                 if ($sum) {
141                     $weightedSum = $weight/$sum;
142                 } else {
143                     $weightedSum = 0.5;
144                 }
145                 $this->showTag($tag, $weight, $weightedSum);
146             }
147             $this->elementEnd('ul');
148             $this->elementEnd('dd');
149             $this->elementEnd('dl');
150             $this->elementEnd('div');
151         } else {
152             $this->showEmptyList();
153         }
154     }
155
156     function showTag($tag, $weight, $relative)
157     {
158         if ($relative > 0.1) {
159             $rel =  'tag-cloud-7';
160         } else if ($relative > 0.05) {
161             $rel = 'tag-cloud-6';
162         } else if ($relative > 0.02) {
163             $rel = 'tag-cloud-5';
164         } else if ($relative > 0.01) {
165             $rel = 'tag-cloud-4';
166         } else if ($relative > 0.005) {
167             $rel = 'tag-cloud-3';
168         } else if ($relative > 0.002) {
169             $rel = 'tag-cloud-2';
170         } else {
171             $rel = 'tag-cloud-1';
172         }
173
174         $this->elementStart('li', $rel);
175
176         // TRANS: Link title for number of people tagged. %d is the number of people tagged.
177         $title = sprintf(_m('1 person tagged','%d people tagged',$weight),$weight);
178         $this->element('a', array('href'  => common_local_url('peopletag', array('tag' => $tag)),
179                                   'title' => $title), $tag);
180         $this->elementEnd('li');
181     }
182 }