forked from RomanSixty/Feed-on-Feeds
-
Notifications
You must be signed in to change notification settings - Fork 3
/
feed-detail.php
executable file
·321 lines (287 loc) · 9.31 KB
/
feed-detail.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
/*
* This file is part of FEED ON FEEDS - http://feedonfeeds.com/
*
* feed-detail.php - display and control all information about a feed
*
*
* Copyright (C) 2013 Justin Wind <[email protected]>
*
* Distributed under the GPL - see LICENSE
*
*/
/*
FIXME:
add form fallbacks for ajax actions
*/
require_once 'fof-main.php';
include 'header.php';
function pretty_time($t) {
return strftime('%c', $t);
}
$p = &FoF_Prefs::instance();
$fof_admin_prefs = $p->admin_prefs;
if (empty($_GET['feed'])) {
echo '<div class="error"><h1>No Feed</h1>Nothing to detail.</div>' . "\n";
die();
}
$feed_id = $_GET['feed'];
/* handle updates */
$messages = array();
if (isset($_POST['alt_title'])) {
if (fof_db_subscription_title_set(fof_current_user(), $feed_id, $_POST['alt_title'])) {
if (empty($_POST['alt_title'])) {
$messages[] = 'Cleared custom title.';
} else {
$messages[] = 'Set custom title to "' . $_POST['alt_title'] . '"';
}
} else {
$messages[] = '<span class="error">Failed to set custom title!</span>';
}
}
if (isset($_POST['alt_image'])) {
if (fof_db_subscription_image_set(fof_current_user(), $feed_id, $_POST['alt_image'])) {
if (empty($_POST['alt_image'])) {
$messages[] = 'Cleared custom image.';
} else {
$messages[] = 'Set custom image to "' . $_POST['alt_image'] . '"';
}
} else {
$messages[] = '<span class="error">Failed to set custom image!</span>';
}
}
if (isset($_POST['new_tag'])) {
if (fof_tag_feed(fof_current_user(), $feed_id, $_POST['new_tag'])) {
$messages[] = 'Feed will now be tagged with "' . $_POST['new_tag'] . '"';
} else {
$messages[] = '<span class="error">Failed to set tag on feed!</span>';
}
}
if (!empty($messages)) {
echo '<div class="notice">';
foreach ($messages as $msg) {
echo '<div>' . $msg . '</div>' . "\n";
}
echo '</div>' . "\n";
/* sidebar will be wrong until refreshed */
echo '<script>document.observe("dom:loaded", function() { refreshlist(); });</script>';
}
/* let admin see any feed */
if (fof_is_admin()) {
echo '<h1>Admin Feed Details</h1>' . "\n";
echo '<div class="subscribers">' . "\n";
echo '<h2>Subscribers</h2>' . "\n";
echo '<ul>' . "\n";
$sub_statement = fof_db_get_subscribed_users($feed_id);
$users = fof_db_get_users();
while (($subscriber = fof_db_get_row($sub_statement, 'user_id')) !== false) {
echo '<li>' . $users[$subscriber]['user_name'] . ' (' . $subscriber . ')</li>' . "\n";
}
echo '</ul>' . "\n";
echo '</div>' . "\n";
} elseif (fof_db_is_subscribed_id(fof_current_user(), $feed_id)) {
echo '<h1>Feed Details</h1>' . "\n";
} else {
echo '<div class="error"><h1>Not Subscribed</h1>You don\'t know anything about that feed.</div>' . "\n";
die();
}
if (fof_is_admin() && !fof_db_is_subscribed_id(fof_current_user(), $feed_id)) {
/* fof_get_feed expects a subscription, so shirk that and just populate overall stats */
$feed_row = fof_db_get_feed_by_id($feed_id);
fof_db_subscription_feed_fix($feed_row);
list($feed_row['feed_items'], $feed_row['feed_tagged'], $counts) = fof_db_feed_counts(fof_current_user(), $feed_id);
$feed_row = array_merge(array('tags' => array(), 'feed_unread' => 0, 'feed_read' => 0, 'feed_starred' => 0, 'feed_age' => $feed_row['feed_cache_date']), $feed_row);
list($feed_row['agestr'], $feed_row['agestrabbr']) = fof_nice_time_stamp($feed_row['feed_cache_date']);
$max_stmt = fof_db_get_latest_item_age(fof_current_user(), $feed_id);
$feed_row['max_date'] = fof_db_get_row($max_stmt, 'max_date', TRUE);
list($feed_row['lateststr'], $feed_row['lateststrabbr']) = fof_nice_time_stamp($feed_row['max_date']);
/* not subscribed, so no subscription preferences to change.. */
$admin_view = true;
} else {
$feed_row = fof_get_feed(fof_current_user(), $feed_id);
$admin_view = false;
}
/* only include the update scripts if subscribed */
if (!$admin_view || fof_db_is_subscribed_id(fof_current_user(), $feed_id)) {
$feed_id_js = json_encode($feed_id);
?>
<script>
function subscription_tags_refresh(feed) {
fetch('feed-action.php', {
'method': 'post',
'headers': {'Content-Type': 'application/x-www-form-urlencoded'},
'body': 'subscription_tag_list='+feed
}).then(function(response) {
response.text().then(data => document.querySelector('#feedtags ul').innerHTML = data);
});
}
function subscription_tag_modify(feed, tag, action) {
let params = 'feed='+feed+'&subscription_tag='+tag;
if (action === "delete") {
params += '&'+action+'=true';
}
fetch('feed-action.php', {
'method': 'post',
'headers': {'Content-Type': 'application/x-www-form-urlencoded'},
'body': params
}).then(function() {
subscription_tags_refresh(feed);
refreshlist();
});
}
window.onload = function() {
subscription_tags_refresh(<?php echo $feed_id_js; ?>);
document.getElementById('new_tag').addEventListener("keypress", function(event) {
if (event.key === 'Enter') {
subscription_tag_modify(<?php echo $feed_id_js; ?>, this.value, "add");
document.getElementById('new_tag').value = '';
return false;
}
});
document.querySelector('#new_tag + input[type="button"]').addEventListener("click", function(event) {
subscription_tag_modify(<?php echo $feed_id_js; ?>, document.getElementById('new_tag').value, "add");
document.getElementById('new_tag').value = '';
return false;
});
};
</script>
<?php
}
?>
<form method="post" action="">
<div id="general">
<h2>General</h2>
<ul>
<li>
Source URL: '<?php echo $feed_row['feed_url']; ?>'
</li>
<li>
Site URL: '<?php echo $feed_row['feed_link']; ?>'
</li>
<li>
Description: '<?php echo $feed_row['feed_description']; ?>'
</li>
<li>
Title: '<?php echo $feed_row['feed_title']; ?>'
</li>
<?php
if (!$admin_view) {
?>
<li>
Custom Title:
<input type="text" name="alt_title" value="<?php echo htmlentities($feed_row['alt_title'], ENT_QUOTES); ?>" size="50" />
</li>
<?php
}
?>
<li>
Image:
<img class="feed-icon" src="<?php echo htmlentities($feed_row['feed_image'], ENT_QUOTES); ?>" />
</li>
<?php
if (!$admin_view) {
?>
<li>
Custom Image:
<input type="text" name="alt_image" value="<?php echo htmlentities($feed_row['alt_image'], ENT_QUOTES); ?>" size="50" />
<img class="feed-icon" src="<?php echo htmlentities($feed_row['alt_image'], ENT_QUOTES); ?>" />
</li>
<?php
}
?>
</ul>
<span>
<?php
if (!$admin_view) {
?>
<input type="submit" value="Update" />
<?php
}
?>
</span>
</div>
</form>
<div id="counts">
<h2>Item Counts</h2>
<ul>
<li>Items: <?php echo $feed_row['feed_items']; ?></li>
<li>Read: <?php echo $feed_row['feed_read']; ?></li>
<li>Unread: <?php echo $feed_row['feed_unread']; ?></li>
<li>Starred: <?php echo $feed_row['feed_starred']; ?></li>
<li>Tagged: <?php echo $feed_row['feed_tagged']; ?></li>
</ul>
</div>
<div id="history">
<h2>Item History</h2>
<div>New items per day (today at left)</div>
<div>
<img src="feed-action.php?feed_history=<?php echo $feed_id; ?>" />
</div>
</div>
<?php
if (!empty($fof_admin_prefs['purge'])) {
echo '<div id="purge">' . "\n";
echo '<h2>Purge Potential</h2>' . "\n";
/* NOTE: not accurate, don't know how many items were listed in latest feed fetch */
$purge_statement = fof_db_items_purge_list($feed_id, $fof_admin_prefs['purge'], $fof_admin_prefs['purge_grace'], array('folded'));
$purge_items = $purge_statement->fetchAll();
$purge_count = count($purge_items);
echo '<div>' . ($purge_count ? $purge_count : 'No') . ' item' . ($purge_count == 1 ? '' : 's') . ' likely to be purged on next update.</div>' . "\n";
echo '</div>' . "\n";
}
?>
<div id="times">
<h2>Dates</h2>
<ul>
<li>Last updated: <?php echo pretty_time($feed_row['feed_age']) . ' (' . $feed_row['agestr'] . ')'; ?></li>
<li>Most recent item: <?php echo pretty_time($feed_row['max_date']) . ' (' . $feed_row['lateststr'] . ')'; ?></li>
<li>Image cached: <?php echo pretty_time($feed_row['feed_image_cache_date']); ?>
</li>
<li>Last update attempt: <?php echo pretty_time($feed_row['feed_cache_attempt_date']); ?></li>
<?php
if (!empty($feed_row['feed_cache_last_attempt_status'])) {
echo '<li><img class="feed-icon" src="' . $fof_asset['alert_icon'] . '" /> Last update attempt was not successful: <span>' . $feed_row['feed_cache_last_attempt_status'] . '</span></li>' . "\n";
}
?>
<li>Next attempt:
<?php
$now = time();
if ($now >= $feed_row['feed_cache_next_attempt']) {
echo "due";
if ($now - $feed_row['feed_cache_date'] <= $fof_admin_prefs['autotimeout'] * 60) {
echo ", but is delayed by the system rate-limit until " . pretty_time($feed_row['feed_cache_date'] + ($fof_admin_prefs['autotimeout'] * 60));
}
} else {
echo pretty_time($feed_row['feed_cache_next_attempt']);
}
?>
</li>
</ul>
</div>
<?php
if (!$admin_view) {
?>
<form method="post" action="">
<div id="feedtags">
<h2>Tags Automatically Applied to Items from this Feed</h2>
<ul>
<li><img class="feed-icon" src="<?php echo $fof_asset['busy_icon']; ?>" /> Tags loading...</li>
</ul>
<span>
<?php
/*
* As far as I can tell, the observe event attached on domload (above) ought to handle this, but without the inline keyCode check here, it seems to still try to submit the form on carriage-return.
* Perhaps someone better-versed in clientside js can iron this out.
*/
?>
<input type="text" size="10" id="new_tag" onkeypress="if (event.key == 'Enter') return false;" /><input type="button" value="Tag Feed" />
</span>
</div>
</form>
<?php
}
?>
<?php
include 'footer.php';
?>