3 * StatusNet, the distributed open-source microblogging tool
5 * Public tag cloud for notices
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.
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.
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/>.
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/
32 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
34 define('TAGS_PER_PAGE', 100);
37 * Public tag cloud for notices
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/
47 class PublictagcloudAction extends Action
49 function isReadOnly($args)
56 // TRANS: Title for public tag cloud.
57 return _('Public tag cloud');
60 function showPageNotice()
62 $this->element('p', 'instructions',
63 // TRANS: Instructions (more used like an explanation/header).
64 // TRANS: %s is the StatusNet sitename.
65 sprintf(_('These are most popular recent tags on %s'),
66 common_config('site', 'name')));
69 function showEmptyList()
71 // TRANS: This message contains a Markdown URL. The link description is between
72 // TRANS: square brackets, and the link between parentheses. Do not separate "]("
73 // TRANS: and do not change the URL part.
74 $message = _('No one has posted a notice with a [hashtag](%%doc.tags%%) yet.') . ' ';
76 if (common_logged_in()) {
77 // TRANS: Message shown to a logged in user for the public tag cloud
78 // TRANS: while no tags exist yet. "One" refers to the non-existing hashtag.
79 $message .= _('Be the first to post one!');
82 // TRANS: Message shown to a anonymous user for the public tag cloud
83 // TRANS: while no tags exist yet. "One" refers to the non-existing hashtag.
84 // TRANS: This message contains a Markdown URL. The link description is between
85 // TRANS: square brackets, and the link between parentheses. Do not separate "]("
86 // TRANS: and do not change the URL part.
87 $message .= _('Why not [register an account](%%action.register%%) and be the first to post one!');
90 $this->elementStart('div', 'guide');
91 $this->raw(common_markup_to_html($message));
92 $this->elementEnd('div');
95 function handle($args)
97 parent::handle($args);
101 function showContent()
103 // This should probably be cached rather than recalculated
104 $tags = new Notice_tag();
106 #Need to clear the selection and then only re-add the field
107 #we are grouping by, otherwise it's not a valid 'group by'
108 #even though MySQL seems to let it slide...
110 $tags->selectAdd('tag');
112 #Add the aggregated columns...
113 $tags->selectAdd('max(notice_id) as last_notice_id');
114 $calc = common_sql_weight('created', common_config('tag', 'dropoff'));
115 $cutoff = sprintf("notice_tag.created > '%s'",
116 common_sql_date(time() - common_config('tag', 'cutoff')));
117 $tags->selectAdd($calc . ' as weight');
118 $tags->whereAdd($cutoff);
119 $tags->groupBy('tag');
120 $tags->orderBy('weight DESC');
122 $tags->limit(TAGS_PER_PAGE);
124 $cnt = $tags->find();
127 $this->elementStart('div', array('id' => 'tagcloud',
128 'class' => 'section'));
132 while ($tags->fetch()) {
133 $tw[$tags->tag] = $tags->weight;
134 $sum += $tags->weight;
139 $this->elementStart('ul', 'tags xoxo tag-cloud');
140 foreach ($tw as $tag => $weight) {
142 $weightedSum = $weight/$sum;
146 $this->showTag($tag, $weight, $weightedSum);
148 $this->elementEnd('ul');
150 $this->elementEnd('div');
152 $this->showEmptyList();
156 function showTag($tag, $weight, $relative)
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';
171 $rel = 'tag-cloud-1';
174 $this->elementStart('li', $rel);
175 $this->element('a', array('href' => common_local_url('tag', array('tag' => $tag))),
177 $this->elementEnd('li');