-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaggregate.php
208 lines (199 loc) · 7.78 KB
/
aggregate.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
<?php
$path = "./";
require_once($path."autoloader.php");
require_once($path."functions.php");
require_once($path."db/SQLiteManager.php");
$id = $_REQUEST["id"];
if(!$id) {
die("no id");
}
$db = SQLiteManager\SQLiteManager::getInstance();
$result = $db->select("aggregateFeeds", null, ["ID"=>$id]);
$feedInfo = $db->fetchArray($result)[0];
if(!$feedInfo) {
die("bad id ".$id);
}
$threshold = $_REQUEST["threshold"];
if(!$threshold) {
die("no threshold (0 - 100)");
}
$grouping = (int)$_REQUEST["grouping"];
if(!isset($_REQUEST["grouping"])) {
$grouping = 1;
}
$minThreshold = $_REQUEST["minThreshold"];
if(!isset($_REQUEST["minThreshold"])) {
$minThreshold = true;
}
$urls = explode("\n", $feedInfo["feeds"]);
$articles = [];
$feeds = [];
$i = 0;
foreach($urls as $url) {
$feed = new SimplePie();
$feed->enable_cache(false);
$feed->set_feed_url($url);
$feed->init();
foreach($feed->get_items() as $item) {
$title = $item->get_title();
$summary = $item->get_description();
$articles[$i][$title] = $item;
}
$i++;
$feeds[] = $feed;
}
$output = [];
$feedArticles = array_shift($articles);
foreach($feedArticles as $title=>$article) {
$title = strtolower($title); //similar_text takes case into account
$avg = 0;
$hits = 0;
$maxes = [];
foreach($articles as $feedArticles2) {
$max = 0;
foreach($feedArticles2 as $title2=>$article2) {
$title2 = strtolower($title2);
$similarity1;
$similarity2;
similar_text($title, $title2, $similarity1);
similar_text($title2, $title, $similarity2);
$max = max($max, $similarity1, $similarity2);
}
if(($minThreshold && $max >= $threshold) || (!$minThreshold && $max <= $threshold)) {
$maxes[] = round($max, 1)."%";
$hits++;
}
if($grouping > 0 && $grouping === $hits) {
$output[] = [implode(", ", $maxes), $article];
break;
}
$avg += $max;
}
if($grouping == 0) {
$avg /= count($articles) - 1;
if(($minThreshold && $avg >= $threshold) || (!$minThreshold && $avg <= $threshold)) {
$output[] = [round($avg, 1), $article];
}
}
}
?>
<?php
header('Content-type: application/atom+xml');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
?>
<feed xmlns="http://www.w3.org/2005/Atom">
<?php $feed = $feeds[0]; ?>
<title><?= $feed->get_title(); ?></title>
<?php
$protocol = 'http';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$protocol = 'https';
}
?>
<link href="<?= $protocol.'://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI] ?>" rel="self"/>
<link href="<?= $feed->get_base(); ?>" />
<id><?= $feed->get_permalink(); ?></id>
<?php if($feed->get_authors()) { ?>
<?php foreach($feed->get_authors() as $author) { ?>
<author>
<?php if($author->get_name()) { ?>
<name><?= $author->get_name(); ?></name>
<?php } ?>
<?php if($author->get_email()) { ?>
<email><?= $author->get_email(); ?></email>
<?php } ?>
<?php if($author->get_link()) { ?>
<uri><?= $author->get_link(); ?></uri>
<?php } ?>
</author>
<?php } ?>
<?php } ?>
<?php if($feed->get_contributors()) { ?>
<?php foreach($feed->get_contributors() as $acontributor) { ?>
<contributor>
<?php if($contributor->get_name()) { ?>
<name><?= $contributor->get_name(); ?></name>
<?php } ?>
<?php if($contributor->get_email()) { ?>
<email><?= $contributor->get_email(); ?></email>
<?php } ?>
<?php if($contributor->get_link()) { ?>
<uri><?= $contributor->get_link(); ?></uri>
<?php } ?>
</contributor>
<?php } ?>
<?php } ?>
<?php if($feed->get_categories()) { ?>
<?php foreach($feed->get_categories() as $category) { ?>
<category term="<?= $category; ?>"/>
<?php } ?>
<?php } ?>
<?php if($feed->get_copyright()) { ?>
<rights><?= $feed->get_copyright(); ?></rights>
<?php } ?>
<?php if($feed->get_image_url()) { ?>
<logo><?= $feed->get_image_url(); ?></logo>
<?php } ?>
<updated><?= date("c"); ?></updated> <?php /* WARNING: simplepie doesn't provide ANY feed-level date */ ?>
<?php $i = 0; ?>
<?php foreach($output as $temp) {
$item = $temp[1];
/*if(!filter($item, $feedInfo["patterns"])) {
continue;
}*/
?>
<entry>
<title><?= $item->get_title()." - ".$temp[0]."%"; ?></title>
<link href="<?= $item->get_permalink(); ?>"/>
<id><?= $item->get_id(); ?></id>
<?php if($item->get_date()) { ?>
<published><?= $item->get_date("c"); ?></published>
<?php } ?>
<?php if($item->get_updated_date()) { ?>
<updated><?= $item->get_updated_date("c"); ?></updated>
<?php } ?>
<summary type="html"><![CDATA[<?= $item->get_description(); ?>]]></summary>
<?php if($item->get_content(true)) { ?>
<content type="html"><![CDATA[<?= $item->get_content(true); ?>]]></content>
<?php } ?>
<?php if($item->get_authors()) { ?>
<?php foreach($item->get_authors() as $author) { ?>
<author>
<?php if($author->get_name()) { ?>
<name><?= $author->get_name(); ?></name>
<?php } ?>
<?php if($author->get_email()) { ?>
<email><?= $author->get_email(); ?></email>
<?php } ?>
<?php if($author->get_link()) { ?>
<uri><?= $author->get_link(); ?></uri>
<?php } ?>
</author>
<?php } ?>
<?php } ?>
<?php if($item->get_contributors()) { ?>
<?php foreach($item->get_contributors() as $acontributor) { ?>
<contributor>
<?php if($contributor->get_name()) { ?>
<name><?= $contributor->get_name(); ?></name>
<?php } ?>
<?php if($contributor->get_email()) { ?>
<email><?= $contributor->get_email(); ?></email>
<?php } ?>
<?php if($contributor->get_link()) { ?>
<uri><?= $contributor->get_link(); ?></uri>
<?php } ?>
</contributor>
<?php } ?>
<?php } ?>
<?php if($item->get_categories()) { ?>
<?php foreach($item->get_categories() as $category) { ?>
<category<?php if($category->get_scheme()) { ?> scheme="<?= $category->get_scheme(); ?>"<?php } ?><?php if($category->get_term()) { ?> term="<?= $category->get_term(); ?>"<?php } ?><?php if($category->get_label()) { ?> label="<?= $category->get_label(); ?>"<?php } ?>/>
<?php } ?>
<?php } ?>
<?php if($item->get_copyright()) { ?>
<rights><?= $item->get_copyright(); ?></rights>
<?php } ?>
</entry>
<?php } ?>
</feed>