forked from RomanSixty/Feed-on-Feeds
-
Notifications
You must be signed in to change notification settings - Fork 3
/
add.php
executable file
·182 lines (148 loc) · 5.35 KB
/
add.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
<?php
/*
* This file is part of FEED ON FEEDS - http://feedonfeeds.com/
*
* add.php - displays form to add a feed
*
*
* Copyright (C) 2004-2007 Stephen Minutillo
* [email protected] - http://minutillo.com/steve/
*
* Distributed under the GPL - see LICENSE
*
*/
include 'header.php';
$url = isset($_POST['rss_url']) ? $_POST['rss_url'] : NULL;
if (!isset($url)) {
$url = isset($_GET['rss_url']) ? $_GET['rss_url'] : NULL;
}
$youtube = isset($_POST['youtube_channel']) ? $_POST['youtube_channel'] : NULL;
$opml = isset($_POST['opml_url']) ? $_POST['opml_url'] : NULL;
$file = isset($_POST['opml_file']) ? $_POST['opml_file'] : NULL;
$unread = isset($_POST['unread']) ? $_POST['unread'] : NULL;
$feeds = array();
if ($youtube) {
// okay, we may have different kinds of URLs here, depending if the channel owner got a vanity user name
//
// https://www.youtube.com/user/<vanity_title>...
// https://www.youtube.com/channel/<channel_id>...
//
// what we need however is the channel's id, so let's try to find that out
$channel_id = null;
$matches = array();
if (preg_match('~youtube\.com/channel/([^/]+)~', $youtube, $matches)) {
$channel_id = $matches[1];
} elseif (preg_match('~youtube\.com/c/([^/]+)~', $youtube, $matches)
|| preg_match('~youtube\.com/user/([^/]+)~', $youtube, $matches)
|| preg_match('~youtube\.com/@([^/]+)~', $youtube, $matches)) {
$file = file_get_contents($youtube);
if (preg_match('~"externalId":"([^"]+)"~m', $file, $matches)) {
$channel_id = $matches[1];
}
}
if (!empty($channel_id)) {
$feeds[] = 'https://www.youtube.com/feeds/videos.xml?channel_id=' . $channel_id;
}
}
if ($url) {
// maybe we have a reddit url? try to guess the corresponding rss feed
$url = preg_replace('~^(https://www\.reddit\.com/(?:u|r)/[^/]+).*$~i', '$1.rss', $url);
$feeds[] = $url;
}
if ($opml) {
$sfile = new SimplePie_File($opml);
if (!$sfile->success) {
echo "Cannot open " . htmlentities($opml) . "<br>";
return false;
}
$content = $sfile->body;
$feeds = fof_opml_to_array($content);
}
if (!empty($_FILES['opml_file']) && !empty($_FILES['opml_file']['tmp_name'])) {
if (($content = file_get_contents($_FILES['opml_file']['tmp_name'])) === false) {
echo "Cannot open uploaded file '" . htmlentities($_FILES['opml_file']['name']) . "'<br>";
} else {
$feeds = fof_opml_to_array($content);
}
}
$add_feed_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$add_feed_url .= "://" . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"];
?>
<div style="background: #eee; border: 1px solid black; padding: 1.5em; margin: 1.5em;">
<span id="add_bookmarklet">
You can use the <a href="javascript:void(location.href='<?php echo $add_feed_url; ?>?rss_url='+escape(location))">FoF subscribe</a> bookmarklet to subscribe to any page with a feed. Just add it as a bookmark and then click on it when you are at a page you'd like to subscribe to!
</span>
</div>
<div style="padding: 1.5em;">
<form method="post" action="opml.php">
<input type="submit" value="Export subscriptions as OPML">
</form>
<br>
<form method="post" name="addform" action="add.php" enctype="multipart/form-data">
When adding feeds, mark <select name="unread">
<option value=all<?php if ($unread == "all") {
echo " selected";
}
?>>all</option>
<option value=today<?php if ($unread == "today") {
echo " selected";
}
?>>today's</option>
<option value=no<?php if ($unread == "no") {
echo " selected";
}
?>>no</option>
</select> items as unread<br><br>
RSS or reddit or weblog URL: <input type="text" name="rss_url" size="40" value="<?php echo htmlentities($url??"") ?>"><input type="Submit" value="Add a feed"><br><br>
YouTube channel page: <input type="text" name="youtube_channel" size="40" value="<?php echo htmlentities($youtube??"") ?>"><input type="Submit" value="Subscribe to channel"><br><br>
OPML URL: <input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="text" name="opml_url" size="40" value="<?php echo htmlentities($opml??"") ?>"><input type="Submit" value="Add feeds from OPML file on the Internet"><br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
OPML filename: <input type="file" name="opml_file" size="40" value="<?php echo htmlentities($file??"") ?>"><input type="Submit" value="Upload an OPML file">
</form>
<hr>
<?php
if (count($feeds)) {
$idx = 0;
$feedjson = array();
foreach ($feeds as $feed) {
$feedjson[] = json_encode(array('url' => urlencode($feed), 'idx' => $idx));
echo '<div id="feed_index_' . $idx . '">'
. $feed . ' is waiting to add...'
. "</div>\n";
$idx++;
}
?>
<script>
let feedslist = [ <?php echo implode(', ', $feedjson); ?> ];
let feedi;
window.onload = function() {
throb();
feedi = iterate(feedslist);
continueadd();
};
function continueadd() {
if (feed = feedi()) {
const f = feed();
const new_feed_id = 'feed_index_' + f['idx'];
fetch('add-single.php', {
'method': 'post',
'headers': {'Content-Type': 'application/x-www-form-urlencoded'},
'body': 'url='+f['url']+'&unread='+document.addform.unread.value
}).then(function(response) {
response.text().then(data => {
document.getElementById(new_feed_id).innerHTML = data;
});
continueadd();
});
} else {
document.getElementById('items').insertAdjacentHTML('beforeend', '<br>Done!');
refreshlist();
}
}
</script>
<?php
}
echo '</div><br>';
include 'footer.php';
?>