-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfeed.php
108 lines (87 loc) · 3.99 KB
/
feed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
// We can't include this script as part of index.php?do= etc,
// as that would introduce html code into it. HTML != Valid XML
// So, include the headerfile to set up database access etc
define('IN_FS', true);
require dirname(__FILE__).'/header.php';
if (!$user->id && Get::val('user_id') && Get::val('auth')) {
$user = new User(Get::val('user_id'));
if (Get::val('auth') != md5($user->infos['user_pass'] . $user->infos['register_date'])) {
$user = new User;
}
}
$page = new FSTpl();
// Set up the basic XML head
header ('Content-type: text/html; charset=utf-8');
$max_items = (Get::num('num', 10) == 10) ? 10 : 20;
$sql_project = ' 1=1 ';
if ($proj->id) {
$sql_project = sprintf(' t.project_id = %d', $proj->id);
}
$feed_type = Get::enum('feed_type', array('rss1', 'rss2', 'atom'), 'rss2');
switch (Get::val('topic')) {
case 'clo': $orderby = 'date_closed'; $closed = 't.is_closed = 1';
$topic = 1;
$title = 'Recently closed tasks';
break;
case 'edit':$orderby = 'last_edited_time'; $closed = '1=1';
$topic = 2;
$title = 'Recently edited tasks';
break;
default: $orderby = 'date_opened'; $closed = '1=1';
$topic = 3;
$title = 'Recently opened tasks';
break;
}
$filename = md5(sprintf('%s-%s-%d-%d', $feed_type, $orderby, $proj->id, $max_items) . $conf['general']['cookiesalt']);
$cachefile = sprintf('%s/%s', FS_CACHE_DIR, $filename);
// Get the time when a task has been changed last
$db->setLimit($max_items);
$sql = $db->query("SELECT t.date_opened, t.date_closed, t.last_edited_time
FROM {tasks} t
WHERE $closed AND $sql_project
ORDER BY $orderby DESC");
$most_recent = 0;
while ($row = $sql->fetchRow()) {
$most_recent = max($most_recent, $row['date_opened'], $row['date_closed'], $row['last_edited_time']);
}
$content = $db->x->GetOne("SELECT content
FROM {cache} t
WHERE type = ? AND topic = ? AND $sql_project
AND max_items = ? AND last_updated >= ?", null,
array($feed_type, $topic . $user->id, $max_items, $most_recent));
if ($content) {
echo $content;
exit;
}
/* build a new feed if cache didn't work */
$db->setLimit($max_items);
$task_details = $db->x->getAll(
"SELECT t.task_id, t.item_summary, t.detailed_desc, t.date_opened, t.date_closed,
t.last_edited_time, t.opened_by, u.real_name, u.email_address, u.show_contact, t.*, p.project_prefix
FROM {tasks} t
INNER JOIN {users} u ON t.opened_by = u.user_id
INNER JOIN {projects} p ON t.project_id = p.project_id
WHERE $closed AND $sql_project
ORDER BY $orderby DESC");
$task_details = array_filter($task_details, array($user, 'can_view_task'));
$feed_description = $proj->prefs['feed_description'] ? $proj->prefs['feed_description'] : $fs->prefs['page_title'] . $proj->prefs['project_title'].': '.$title;
$feed_image = false;
if ($proj->prefs['feed_img_url']
&& !strncmp($proj->prefs['feed_img_url'], 'http://', 7))
{
$feed_image = $proj->prefs['feed_img_url'];
}
$page->uses('most_recent', 'feed_description', 'feed_image', 'task_details');
$content = $page->fetch('feed.'.$feed_type.'.tpl');
// cache feed
$fields = array('content'=> array('value' => $content),
'type'=> array('value' => $feed_type, 'key' => true),
'topic'=> array('value' => $topic . $user->id, 'key' => true),
'project_id'=> array('value' => $proj->id, 'key' => true),
'max_items'=> array('value' => $max_items, 'key' => true),
'last_updated'=> array('value' => time()));
$db->Replace('{cache}', $fields);
header('Content-Type: application/xml; charset=utf-8');
echo $content;
?>