-
Notifications
You must be signed in to change notification settings - Fork 15
/
feed-action.php
executable file
·155 lines (126 loc) · 3.93 KB
/
feed-action.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*
* This file is part of Feed On Feeds
*
* feed-action.php - performs various ajaxy actions on feeds
*
* Copyright (C) 2013 Justin Wind <justin.wind@gmail.com>
*
* Distributed under the GPL - see LICENSE
*
*/
include_once 'fof-main.php';
/* mark all items in feed as read, return updated sidebar entry */
if (!empty($_POST['read_feed'])) {
fof_db_mark_feed_read(fof_current_user(), $_POST['read_feed']);
$feed_row = fof_get_feed(fof_current_user(), $_POST['read_feed']);
echo fof_render_feed_row($feed_row);
exit();
}
/* update one feed, return replacement sidebar feed list content */
if (!empty($_POST['update_feedid'])) {
list($count, $error) = fof_update_feed($_POST['update_feedid']);
$feed_row = fof_get_feed(fof_current_user(), $_POST['update_feedid']);
if (!empty($error)) {
echo fof_render_feed_row($feed_row, $error);
} else {
echo fof_render_feed_row($feed_row);
}
exit();
}
/* returns a script block which updates a list of the subscribed sources for a tag */
if (!empty($_POST['update_tag_sources'])) {
fof_set_content_type('application/javascript');
$tag_id = fof_db_get_tag_by_name($_POST['update_tag_sources']);
$subs = fof_db_subscriptions_by_tags(fof_current_user());
/* FIXME: check timeouts, like below */
if (!empty($subs[$tag_id])) {
echo 'pendingUpdates(' . json_encode($subs[$tag_id]) . ');';
}
exit();
}
/* returns a script block which updates all updatable subscribed feeds */
if (!empty($_POST['update_subscribed_sources'])) {
fof_set_content_type('application/javascript');
$now = time();
$timeout = $fof_prefs_obj->admin_prefs['manualtimeout'] * 60;
$sources = array();
$statement = fof_db_get_subscriptions(fof_current_user(), true);
while (($feed = fof_db_get_row($statement)) !== false) {
if (($now - $feed['feed_cache_date']) < $timeout) {
continue;
}
if ($now < $feed['feed_cache_next_attempt']) {
continue;
}
$sources[] = $feed['feed_id'];
}
if (!empty($sources)) {
echo 'pendingUpdates(' . json_encode($sources) . ');';
}
exit();
}
/* returns a list of tags for a feed, with markup */
if (!empty($_POST['subscription_tag_list'])) {
fof_set_content_type();
$feed_id = $_POST['subscription_tag_list'];
$feed_row = fof_get_feed(fof_current_user(), $feed_id);
if (empty($feed_row)) {
header('Status: 404 Not Found');
echo 'No data for feed.';
exit();
}
echo "\n";
foreach ($feed_row['tags'] as $tag) {
echo ' <li>'
. $tag
. ' <a href="#" onclick="subscription_tag_modify(' . htmlentities(implode(',', array(json_encode($feed_id), json_encode($tag), json_encode('delete'))), ENT_QUOTES) . '); return false;">'
. '[x]'
. '</a>'
. '</li>'
. "\n";
}
echo " ";
exit();
}
/* modify a user's feed subscription */
if (!empty($_POST['subscription_tag'])) {
if (empty($_POST['feed'])) {
header('Status: 400 Bad Request');
echo 'Incomplete data.';
exit();
}
$tag = $_POST['subscription_tag'];
$feed_id = $_POST['feed'];
if (!empty($_POST['delete'])) {
fof_untag_feed(fof_current_user(), $feed_id, $tag);
} else {
fof_tag_feed(fof_current_user(), $feed_id, $tag);
}
exit();
}
/** Serve out an SVG image showing a feed's activity history.
*/
if (!empty($_GET['feed_history'])) {
include_once 'classes/svghistogram.php';
fof_set_content_type('image/svg+xml');
$history = fof_db_feed_history($_GET['feed_history']);
$options = array(
'title' => 'Feed History',
'description' => 'Items added to feed.',
'min_items' => max(31, $fof_prefs_obj->admin_prefs['purge'] + 7),
'max_items' => 366,
'label_zero' => '↑ today',
'label_x' => 'days ago →',
);
if (!empty($fof_prefs_obj->admin_prefs['purge'])) {
$options['shade_over'] = $fof_prefs_obj->admin_prefs['purge'];
$options['max_items'] = min($options['max_items'], ceil($fof_prefs_obj->admin_prefs['purge'] * SVGHistogram::PHI));
}
$graph = new SVGHistogram($options);
$graph->render($history);
exit();
}
header('Status: 400 Bad Request');
echo 'Unknown request.';
?>