| 1 | <?php |
|---|
| 2 | /*
|
|---|
| 3 |
|
|---|
| 4 | This file is part of omCollab.
|
|---|
| 5 |
|
|---|
| 6 | Copyright (c) 2008 omCollab (Openmethodology Project)
|
|---|
| 7 | http://www.openmethodology.org
|
|---|
| 8 | http://mike2.openmethodology.org/wiki/OmCollab
|
|---|
| 9 |
|
|---|
| 10 | And parts copyright of Scuttle project
|
|---|
| 11 | (http://sourceforge.net/projects/scuttle/, http://scuttle.org/)
|
|---|
| 12 |
|
|---|
| 13 | omCollab is free software: you can redistribute it and/or modify
|
|---|
| 14 | it under the terms of the GNU General Public License as published by
|
|---|
| 15 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 16 | (at your option) any later version.
|
|---|
| 17 |
|
|---|
| 18 | omCollab is distributed in the hope that it will be useful,
|
|---|
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 21 | GNU General Public License for more details.
|
|---|
| 22 |
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 | require_once('header.inc.php'); |
|---|
| 26 | |
|---|
| 27 | $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); |
|---|
| 28 | $templateservice =& ServiceFactory::getServiceInstance('TemplateService'); |
|---|
| 29 | $userservice =& ServiceFactory::getServiceInstance('UserService'); |
|---|
| 30 | $cacheservice =& ServiceFactory::getServiceInstance('CacheService'); |
|---|
| 31 | |
|---|
| 32 | $tplVars = array(); |
|---|
| 33 | |
|---|
| 34 | @list($url, $user, $page) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL; |
|---|
| 35 | |
|---|
| 36 | $loggedon = false; |
|---|
| 37 | if ($userservice->isLoggedOn()) { |
|---|
| 38 | $loggedon = true; |
|---|
| 39 | $currentUser = $userservice->getCurrentUser(); |
|---|
| 40 | $currentUsername = $currentUser[$userservice->getFieldName('username')]; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | if ($usecache) { |
|---|
| 44 | // Generate hash for caching on |
|---|
| 45 | if ($loggedon) { |
|---|
| 46 | if ($currentUsername != $user) { |
|---|
| 47 | $cachehash = md5($_SERVER['REQUEST_URI'] . $currentUsername); |
|---|
| 48 | |
|---|
| 49 | // Cache for 5 minutes |
|---|
| 50 | $cacheservice->Start($cachehash); |
|---|
| 51 | } |
|---|
| 52 | } else { |
|---|
| 53 | // Cache for 30 minutes |
|---|
| 54 | $cachehash = md5($_SERVER['REQUEST_URI']); |
|---|
| 55 | $cacheservice->Start($cachehash, 1800); |
|---|
| 56 | } |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | if ($user) { |
|---|
| 60 | if (is_int($user)) { |
|---|
| 61 | $userid = intval($user); |
|---|
| 62 | } else { |
|---|
| 63 | if (!($userinfo = $userservice->getUserByUsername($user) ) ) { |
|---|
| 64 | // Throw a 404 error |
|---|
| 65 | $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user); |
|---|
| 66 | $templateservice->loadTemplate('error.404.tpl', $tplVars); |
|---|
| 67 | exit(); |
|---|
| 68 | } else { |
|---|
| 69 | $userid =& $userinfo['uId']; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | // Header variables |
|---|
| 75 | $tplVars['loadjs'] = true; |
|---|
| 76 | |
|---|
| 77 | if ($user) { |
|---|
| 78 | $tplVars['user'] = $user; |
|---|
| 79 | $tplVars['userid'] = $userid; |
|---|
| 80 | $tplVars['userinfo'] =& $userinfo; |
|---|
| 81 | |
|---|
| 82 | // Pagination |
|---|
| 83 | $perpage = getPerPageCount(); |
|---|
| 84 | if (isset($_GET['page']) && intval($_GET['page']) > 1) { |
|---|
| 85 | $page = $_GET['page']; |
|---|
| 86 | $start = ($page - 1) * $perpage; |
|---|
| 87 | } else { |
|---|
| 88 | $page = 0; |
|---|
| 89 | $start = 0; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // Set template vars |
|---|
| 93 | $tplVars['page'] = $page; |
|---|
| 94 | $tplVars['start'] = $start; |
|---|
| 95 | $tplVars['bookmarkCount'] = $start + 1; |
|---|
| 96 | |
|---|
| 97 | $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $userid, NULL, NULL, getSortOrder(), true); |
|---|
| 98 | |
|---|
| 99 | $tplVars['sidebar_blocks'] = array('profile', 'watchlist', 'partners'); |
|---|
| 100 | $tplVars['watched'] = true; |
|---|
| 101 | $tplVars['total'] = $bookmarks['total']; |
|---|
| 102 | $tplVars['bookmarks'] =& $bookmarks['bookmarks']; |
|---|
| 103 | $tplVars['cat_url'] = createURL('tags', '%2$s'); |
|---|
| 104 | $tplVars['nav_url'] = createURL('watchlist', '%s/%s%s'); |
|---|
| 105 | |
|---|
| 106 | if ($user == $currentUsername) { |
|---|
| 107 | $title = T_('My Watchlist'); |
|---|
| 108 | } else { |
|---|
| 109 | $title = T_('Watchlist') .': '. $user; |
|---|
| 110 | } |
|---|
| 111 | $tplVars['pagetitle'] = $title; |
|---|
| 112 | $tplVars['subtitle'] = $title; |
|---|
| 113 | |
|---|
| 114 | $tplVars['rsschannels'] = array( |
|---|
| 115 | array(filter($sitename .': '. $title), createURL('rss', 'watchlist/'. filter($user, 'url'))) |
|---|
| 116 | ); |
|---|
| 117 | |
|---|
| 118 | $templateservice->loadTemplate('bookmarks.tpl', $tplVars); |
|---|
| 119 | } else { |
|---|
| 120 | $tplVars['error'] = T_('Username was not specified'); |
|---|
| 121 | $templateservice->loadTemplate('error.404.tpl', $tplVars); |
|---|
| 122 | exit(); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | if ($usecache) { |
|---|
| 126 | // Cache output if existing copy has expired |
|---|
| 127 | $cacheservice->End($hash); |
|---|
| 128 | } |
|---|
| 129 | ?> |
|---|