forked from RomanSixty/Feed-on-Feeds
-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.php
executable file
·103 lines (90 loc) · 2.71 KB
/
update.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
<?php
/*
* This file is part of FEED ON FEEDS - http://feedonfeeds.com/
*
* update.php - updates feeds with feedback
*
*
* Copyright (C) 2004-2007 Stephen Minutillo
* [email protected] - http://minutillo.com/steve/
*
* Distributed under the GPL - see LICENSE
*
*/
include 'header.php';
echo "<br>\n";
$p = &FoF_Prefs::instance();
$admin_prefs = $p->admin_prefs;
$feeds = array();
if (!empty($_GET['feed'])) {
$feed = fof_db_get_feed_by_id($_GET['feed']);
if (empty($feed)) {
$feed_status = "<span class=\"error\">Error: unknown feed '" . $_GET['feed'] . "'</span>";
} else {
$feeds[] = $feed;
$feed_status = " is waiting to update...";
}
echo '<div id="feed_id_' . $feed['feed_id'] . '">'
. fof_render_feed_link($feed) . ' ' . $feed_status
. "</div>\n";
} else {
if ($fof_user_id == 1) {
$result = fof_db_get_feeds_needing_attempt();
} else {
$result = fof_db_get_subscriptions(fof_current_user(), true);
}
while (($feed = fof_db_get_row($result)) !== false) {
if ((time() - $feed['feed_cache_attempt_date']) < ($admin_prefs['manualtimeout'] * 60)) {
list($timestamp) = fof_nice_time_stamp($feed['feed_cache_date']);
$feed_status = " was just updated $timestamp!";
} else if (time() < $feed['feed_cache_next_attempt']) {
list($timestamp) = fof_nice_time_stamp($feed['feed_cache_next_attempt']);
$feed_status = " isn't due for an update for $timestamp.";
} else {
$feeds[] = $feed;
$feed_status = " is waiting to update...";
}
echo '<div id="feed_id_' . $feed['feed_id'] . '">'
. fof_render_feed_link($feed) . ' ' . $feed_status
. "</div>\n";
}
}
$feeds = fof_multi_sort($feeds, 'feed_cache_attempt_date', false);
$feedjson = array();
foreach ($feeds as $feed) {
$feedjson[] = json_encode(array('id' => $feed['feed_id'], 'title' => $feed['feed_title']));
}
?>
<script>
let feedslist = [ <?php echo implode(', ', $feedjson); ?> ];
let feedi;
window.onload = function() {
throb();
feedi = iterate(feedslist);
for (let i = 0; i < Math.min(feedslist.length, 5); i++)
setTimeout(continueupdate, 50);
};
function continueupdate() {
if (feed = feedi()) {
const f = feed();
const update_feed_id = 'feed_id_' + f['id'];
window.scrollTo(0, document.getElementById(update_feed_id).offsetTop);
fetch('update-single.php', {
'method': 'post',
'headers': {'Content-Type': 'application/x-www-form-urlencoded'},
'body': 'feed='+f['id']
}).then(function(response) {
response.text().then(data => {
document.getElementById(update_feed_id).innerHTML = data;
});
continueupdate();
});
} else {
document.getElementById('items').insertAdjacentHTML('beforeend', '<br>Update complete!');
refreshlist();
}
}
</script>
<?php
include 'footer.php';
?>