source: trunk/bookmarks/rss.php @ 103

Revision 103, 3.6 KB checked in by admin, 4 years ago (diff)

Merged 1.003 into Trunk

Line 
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
25require_once('header.inc.php');
26$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
27$cacheservice =& ServiceFactory::getServiceInstance('CacheService');
28$templateservice =& ServiceFactory::getServiceInstance('TemplateService');
29$userservice =& ServiceFactory::getServiceInstance('UserService');
30
31$tplVars = array();
32header('Content-Type: application/xml');
33list($url, $user, $cat) = explode('/', $_SERVER['PATH_INFO']);
34
35if ($usecache) {
36    // Generate hash for caching on
37    $hashtext = $_SERVER['REQUEST_URI'];
38    if ($userservice->isLoggedOn()) {
39        $hashtext .= $userservice->getCurrentUserID();
40        $currentUser = $userservice->getCurrentUser();
41        $currentUsername = $currentUser[$userservice->getFieldName('username')];
42        if ($currentUsername == $user) {
43            $hashtext .= $user;
44        }
45    }
46    $hash = md5($hashtext);
47
48    // Cache for an hour
49    $cacheservice->Start($hash, 3600);
50}
51
52$watchlist = null;
53if ($user && $user != 'all') {
54    if ($user == 'watchlist') {
55        $user = $cat;
56        $cat = null;
57        $watchlist = true;
58    }
59    if (is_int($user)) {
60        $userid = intval($user);
61    } else {
62        if ($userinfo = $userservice->getUserByUsername($user)) {
63            $userid =& $userinfo[$userservice->getFieldName('primary')];
64        } else {
65            $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
66            $templateservice->loadTemplate('error.404.tpl', $tplVars);
67            //throw a 404 error
68            exit();
69        }
70    }
71    $pagetitle .= ": ". $user;
72} else {
73    $userid = NULL;
74}
75
76if ($cat) {
77    $pagetitle .= ": ". str_replace('+', ' + ', $cat);
78}
79
80$tplVars['feedtitle'] = filter($GLOBALS['sitename'] . (isset($pagetitle) ? $pagetitle : ''));
81$tplVars['feedlink'] = $GLOBALS['root'];
82$tplVars['feeddescription'] = sprintf(T_('Recent bookmarks posted to %s'), $GLOBALS['sitename']);
83
84$bookmarks =& $bookmarkservice->getBookmarks(0, 15, $userid, $cat, NULL, getSortOrder(), $watchlist);
85$bookmarks_tmp =& filter($bookmarks['bookmarks']);
86
87$bookmarks_tpl = array();
88foreach(array_keys($bookmarks_tmp) as $key) {
89    $row =& $bookmarks_tmp[$key];
90
91    $_link = $row['bAddress'];
92    // Redirection option
93    if ($GLOBALS['useredir']) {
94        $_link = $GLOBALS['url_redir'] . $_link;
95    }
96    $_pubdate = gmdate("r", strtotime($row['bDatetime']));
97    // array_walk($row['tags'], 'filter');
98
99    $bookmarks_tpl[] = array(
100        'title' => $row['bTitle'],
101        'link'  => $_link,
102        'description' => $row['bDescription'],
103        'creator' => $row['username'],
104        'pubdate' => $_pubdate,
105        'tags' => $row['tags']
106    );
107}
108unset($bookmarks_tmp);
109unset($bookmarks);
110$tplVars['bookmarks'] =& $bookmarks_tpl;
111
112$templateservice->loadTemplate('rss.tpl', $tplVars);
113
114if ($usecache) {
115    // Cache output if existing copy has expired
116    $cacheservice->End($hash);
117}
118?>
Note: See TracBrowser for help on using the repository browser.