123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
- define('TAGS_PER_PAGE', 100);
- class PublictagcloudAction extends Action
- {
- function isReadOnly($args)
- {
- return true;
- }
- function title()
- {
-
- return _('Public tag cloud');
- }
- function showPageNotice()
- {
- $this->element('p', 'instructions',
-
-
- sprintf(_('These are most popular recent tags on %s'),
- common_config('site', 'name')));
- }
- function showEmptyList()
- {
-
-
-
- $message = _('No one has posted a notice with a [hashtag](%%doc.tags%%) yet.') . ' ';
- if (common_logged_in()) {
-
-
- $message .= _('Be the first to post one!');
- }
- else {
-
-
-
-
-
- $message .= _('Why not [register an account](%%action.register%%) and be the first to post one!');
- }
- $this->elementStart('div', 'guide');
- $this->raw(common_markup_to_html($message));
- $this->elementEnd('div');
- }
- function handle($args)
- {
- parent::handle($args);
- $this->showPage();
- }
- function showContent()
- {
-
- $tags = new Notice_tag();
-
-
-
- $tags->selectAdd();
- $tags->selectAdd('tag');
-
- $tags->selectAdd('max(notice_id) as last_notice_id');
- $calc = common_sql_weight('created', common_config('tag', 'dropoff'));
- $cutoff = sprintf("notice_tag.created > '%s'",
- common_sql_date(time() - common_config('tag', 'cutoff')));
- $tags->selectAdd($calc . ' as weight');
- $tags->whereAdd($cutoff);
- $tags->groupBy('tag');
- $tags->orderBy('weight DESC');
- $tags->limit(TAGS_PER_PAGE);
- $cnt = $tags->find();
- if ($cnt > 0) {
- $this->elementStart('div', array('id' => 'tagcloud',
- 'class' => 'section'));
- $tw = array();
- $sum = 0;
- while ($tags->fetch()) {
- $tw[$tags->tag] = $tags->weight;
- $sum += $tags->weight;
- }
- ksort($tw);
- $this->elementStart('ul', 'tags xoxo tag-cloud');
- foreach ($tw as $tag => $weight) {
- if ($sum) {
- $weightedSum = $weight/$sum;
- } else {
- $weightedSum = 0.5;
- }
- $this->showTag($tag, $weight, $weightedSum);
- }
- $this->elementEnd('ul');
- $this->elementEnd('div');
- } else {
- $this->showEmptyList();
- }
- }
- function showTag($tag, $weight, $relative)
- {
- if ($relative > 0.1) {
- $rel = 'tag-cloud-7';
- } else if ($relative > 0.05) {
- $rel = 'tag-cloud-6';
- } else if ($relative > 0.02) {
- $rel = 'tag-cloud-5';
- } else if ($relative > 0.01) {
- $rel = 'tag-cloud-4';
- } else if ($relative > 0.005) {
- $rel = 'tag-cloud-3';
- } else if ($relative > 0.002) {
- $rel = 'tag-cloud-2';
- } else {
- $rel = 'tag-cloud-1';
- }
- $this->elementStart('li', $rel);
- $this->element('a', array('href' => common_local_url('tag', array('tag' => $tag))),
- $tag);
- $this->elementEnd('li');
- }
- }
|