increased description size to 1000 characters
[scuttle] / history.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2006 Marcus Campbell
4 http://scuttle.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 ***************************************************************************/
20
21 require_once 'header.inc.php';
22
23 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
24 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
25 $userservice =& ServiceFactory::getServiceInstance('UserService');
26 $cacheservice =& ServiceFactory::getServiceInstance('CacheService');
27
28 $tplVars = array();
29
30 @list($url, $hash) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
31
32 $loggedon = false;
33 if ($userservice->isLoggedOn()) {
34     $loggedon = true;
35     $currentUser = $userservice->getCurrentUser();
36     $currentUsername = $currentUser[$userservice->getFieldName('username')];
37 }
38
39 if ($usecache) {
40     // Generate hash for caching on
41     $hashtext = $_SERVER['REQUEST_URI'];
42     if ($userservice->isLoggedOn()) {
43         $hashtext .= $currentUsername;
44     }
45     $cachehash = md5($hashtext);
46
47     // Cache for 30 minutes
48     $cacheservice->Start($cachehash, 1800);
49 }
50
51 // Pagination
52 $perpage = getPerPageCount();
53 if (isset($_GET['page']) && intval($_GET['page']) > 1) {
54     $page = $_GET['page'];
55     $start = ($page - 1) * $perpage;
56 } else {
57     $page = 0;
58     $start = 0;
59 }
60
61 if ($bookmark =& $bookmarkservice->getBookmarkByHash($hash)) {
62     // Template variables
63     $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, NULL, NULL, NULL, getSortOrder(), NULL, NULL, NULL, $hash);
64     $tplVars['pagetitle'] = T_('History') .': '. $bookmark['bAddress'];
65     $tplVars['subtitle'] = sprintf(T_('History for %s'), $bookmark['bAddress']);
66     $tplVars['loadjs'] = true;
67     $tplVars['page'] = $page;
68     $tplVars['start'] = $start;
69     $tplVars['bookmarkCount'] = $start + 1;
70     $tplVars['total'] = $bookmarks['total'];
71     $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
72     $tplVars['hash'] = $hash;
73     $tplVars['popCount'] = 50;
74     $tplVars['sidebar_blocks'] = array('common');
75     $tplVars['cat_url'] = createURL('tags', '%2$s');
76     $tplVars['nav_url'] = createURL('history', $hash .'/%3$s');
77     $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
78 } else {
79     // Throw a 404 error
80     $tplVars['error'] = T_('Address was not found');
81     $templateservice->loadTemplate('error.404.tpl', $tplVars);
82     exit();
83 }
84
85 if ($usecache) {
86     // Cache output if existing copy has expired
87     $cacheservice->End($cachehash);
88 }
89 ?>

Benjamin Mako Hill || Want to submit a patch?