3 * Laconica, 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@controlyourself.ca>
26 * @copyright 2008 Mike Cochrane
27 * @copyright 2008-2009 Control Yourself, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29 * @link http://laconi.ca/
32 if (!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@controlyourself.ca>
43 * @copyright 2008 Mike Cochrane
44 * @copyright 2008-2009 Control Yourself, Inc.
45 * @link http://laconi.ca/
48 class PublictagcloudAction extends Action
57 return _('Public tag cloud');
60 function showPageNotice()
62 $this->element('p', 'instructions',
63 sprintf(_('These are most popular recent tags on %s '),
64 common_config('site', 'name')));
67 function showLocalNav()
69 $nav = new PublicGroupNav($this);
73 function handle($args)
75 parent::handle($args);
79 function showContent()
81 # This should probably be cached rather than recalculated
82 $tags = new Notice_tag();
84 #Need to clear the selection and then only re-add the field
85 #we are grouping by, otherwise it's not a valid 'group by'
86 #even though MySQL seems to let it slide...
88 $tags->selectAdd('tag');
90 #Add the aggregated columns...
91 $tags->selectAdd('max(notice_id) as last_notice_id');
92 if(common_config('db','type')=='pgsql') {
93 $calc='sum(exp(-extract(epoch from (now()-created))/%s)) as weight';
95 $calc='sum(exp(-(now() - created)/%s)) as weight';
97 $tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff')));
98 $tags->groupBy('tag');
99 $tags->orderBy('weight DESC');
101 $tags->limit(TAGS_PER_PAGE);
103 $cnt = $tags->find();
106 $this->elementStart('p', 'tagcloud');
110 while ($tags->fetch()) {
111 $tw[$tags->tag] = $tags->weight;
112 $sum += $tags->weight;
117 foreach ($tw as $tag => $weight) {
118 $this->showTag($tag, $weight, $weight/$sum);
121 $this->elementEnd('p');
125 function showTag($tag, $weight, $relative)
127 # XXX: these should probably tune to the size of the site
128 if ($relative > 0.1) {
130 } else if ($relative > 0.05) {
132 } else if ($relative > 0.02) {
134 } else if ($relative > 0.01) {
136 } else if ($relative > 0.005) {
138 } else if ($relative > 0.002) {
144 $this->element('a', array('class' => "$cls weight-$weight relative-$relative",
145 'href' => common_local_url('tag', array('tag' => $tag))),