trunk, branches/version-0.7:
[scuttle] / populartags.php
1 <?php
2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
5 http://scuttle.org/
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 ***************************************************************************/
21
22 require_once('header.inc.php');
23 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
24 $tagservice =& ServiceFactory::getServiceInstance('TagService');
25 $userservice =& ServiceFactory::getServiceInstance('UserService');
26 $cacheservice =& ServiceFactory::getServiceInstance('CacheService');
27
28 list($url, $user) = explode('/', $_SERVER['PATH_INFO']);
29
30 if ($usecache) {
31     // Generate hash for caching on
32     $hashtext = $_SERVER['REQUEST_URI'];
33     if ($userservice->isLoggedOn()) {
34         $hashtext .= $userservice->getCurrentUserID();
35         $currentUser = $userservice->getCurrentUser();
36         $currentUsername = $currentUser[$userservice->getFieldName('username')];
37         if ($currentUsername == $user) {
38             $hashtext .= $user;
39         }
40     }
41     $hash = md5($hashtext);
42
43     // Cache for an hour
44     $cacheservice->Start($hash, 3600);
45 }
46
47 // Header variables
48 $tplvars = array();
49 $pagetitle = T_('Popular Tags');
50
51 if (isset($user) && $user != '') {
52     if (is_int($user)) {
53       $userid = intval($user);
54     } else {
55         if ($userinfo = $userservice->getUserByUsername($user)) {
56             $userid =& $userinfo[$userservice->getFieldName('primary')];
57         } else {
58             $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
59             $templateservice->loadTemplate('error.404.tpl', $tplVars);
60             //throw a 404 error
61             exit();
62         }
63     }
64     $pagetitle .= ': '. ucfirst($user);
65 } else {
66     $userid = NULL;
67 }
68
69 $tags = $tagservice->getPopularTags($userid, 150, $logged_on_userid);
70 $tplVars['tags'] =& $tagservice->tagCloud($tags, 5, 90, 225, getSortOrder('alphabet_asc')); 
71 $tplVars['user'] = $user;
72
73 if (isset($userid)) {
74     $tplVars['cat_url'] = createURL('bookmarks', '%s/%s');
75 } else {
76     $tplVars['cat_url'] = createURL('tags', '%2$s');
77 }
78
79 $tplVars['subtitle'] = $pagetitle;
80 $templateservice->loadTemplate('tags.tpl', $tplVars);
81
82 if ($usecache) {    
83     // Cache output if existing copy has expired
84     $cacheservice->End($hash);
85 }
86 ?>

Benjamin Mako Hill || Want to submit a patch?