]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/publicpeopletagcloud.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[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
48 class PublicpeopletagcloudAction extends Action
49 {
50     function isReadOnly($args)
51     {
52         return true;
53     }
54
55     function title()
56     {
57         return _('Public people tag cloud');
58     }
59
60     function showPageNotice()
61     {
62         $this->element('p', 'instructions',
63                        sprintf(_('These are most used people tags on %s '),
64                                common_config('site', 'name')));
65     }
66
67     function showEmptyList()
68     {
69         $message = _('No one has [tagged](%%doc.tags%%) anyone yet.') . ' ';
70
71         if (common_logged_in()) {
72             $message .= _('Be the first to tag someone!');
73         }
74         else {
75             $message .= _('Why not [register an account](%%action.register%%) and be the first to tag someone!');
76         }
77
78         $this->elementStart('div', 'guide');
79         $this->raw(common_markup_to_html($message));
80         $this->elementEnd('div');
81     }
82
83     function showLocalNav()
84     {
85         $nav = new PublicGroupNav($this);
86         $nav->show();
87     }
88
89     function handle($args)
90     {
91         parent::handle($args);
92         $this->showPage();
93     }
94
95     function showContent()
96     {
97         // XXX: cache this
98
99         $tags = new Profile_tag();
100         $plist = new Profile_list();
101         $plist->private = false;
102
103         $tags->joinAdd($plist);
104         $tags->selectAdd();
105         $tags->selectAdd('profile_tag.tag');
106         $tags->selectAdd('count(profile_tag.tag) as weight');
107         $tags->groupBy('profile_tag.tag');
108         $tags->orderBy('weight DESC');
109
110         $tags->limit(TAGS_PER_PAGE);
111
112         $cnt = $tags->find();
113
114         if ($cnt > 0) {
115             $this->elementStart('div', array('id' => 'tagcloud',
116                                              'class' => 'section'));
117
118             $tw = array();
119             $sum = 0;
120             while ($tags->fetch()) {
121                 $tw[$tags->tag] = $tags->weight;
122                 $sum += $tags->weight;
123             }
124
125             ksort($tw);
126
127             $this->elementStart('dl');
128             $this->element('dt', null, _('People tag cloud'));
129             $this->elementStart('dd');
130             $this->elementStart('ul', 'tags xoxo tag-cloud');
131             foreach ($tw as $tag => $weight) {
132                 if ($sum) {
133                     $weightedSum = $weight/$sum;
134                 } else {
135                     $weightedSum = 0.5;
136                 }
137                 $this->showTag($tag, $weight, $weightedSum);
138             }
139             $this->elementEnd('ul');
140             $this->elementEnd('dd');
141             $this->elementEnd('dl');
142             $this->elementEnd('div');
143         } else {
144             $this->showEmptyList();
145         }
146     }
147
148     function showTag($tag, $weight, $relative)
149     {
150         if ($relative > 0.1) {
151             $rel =  'tag-cloud-7';
152         } else if ($relative > 0.05) {
153             $rel = 'tag-cloud-6';
154         } else if ($relative > 0.02) {
155             $rel = 'tag-cloud-5';
156         } else if ($relative > 0.01) {
157             $rel = 'tag-cloud-4';
158         } else if ($relative > 0.005) {
159             $rel = 'tag-cloud-3';
160         } else if ($relative > 0.002) {
161             $rel = 'tag-cloud-2';
162         } else {
163             $rel = 'tag-cloud-1';
164         }
165
166         $this->elementStart('li', $rel);
167
168         $count = ($weight == 1) ? '1 person tagged' : '%d people tagged';
169         $this->element('a', array('href'  => common_local_url('peopletag', array('tag' => $tag)),
170                                   'title' => sprintf(_($count), $weight)), $tag);
171         $this->elementEnd('li');
172     }
173 }