forked from SnorkY/LBCRss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
88 lines (72 loc) · 2.24 KB
/
index.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
<?php
/**
* Code minimalisme de génération de flux RSS pour Leboncoin.fr
* @version 1.0
*/
$dirname = dirname(__FILE__);
require $dirname."/lib/feedgenerator/FeedGenerator.php";
require $dirname."/lib/lbc.php";
require $dirname."/lib/proxyWrapper.php";
$getC = new proxyWrapper();
date_default_timezone_set("Europe/Paris");
if (empty($_GET["url"])) {
require $dirname."/form.php";
return;
}
try {
$_GET["url"] = Lbc::formatUrl($_GET["url"]);
} catch (Exception $e) {
echo "Cette adresse ne semble pas valide.";
exit;
}
if (!empty($_GET["queryname"])) {
$title = "LeBonCoin"." - ".$_GET["queryname"];
} else {
$title = "LeBonCoin";
$urlParams = parse_url($_GET["url"]);
if (!empty($urlParams["query"])) {
parse_str($urlParams["query"], $aQuery);
if (!empty($aQuery["q"])) {
$title .= " - ".$aQuery["q"];
}
}
}
$feeds = new FeedGenerator();
$feeds->setGenerator(new RSSGenerator);
$feeds->setTitle($title);
$feeds->setChannelLink(
!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"?"https":"http".
"://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]
);
$feeds->setLink("http://www.leboncoin.fr");
$feeds->setDescription("Flux RSS de la recherche : ".htmlspecialchars($_GET["url"]));
$content = $getC->file_get_contents($_GET["url"]);
$ads = Lbc_Parser::process($content, $_GET);
if (!empty($_GET["multipleURLs"]))
{
$additionnalURLs = array(explode("\n", $_GET["multipleURLs"]));
if (trim($_GET["multipleURLs"])) {
$additionnalURLs = array_map("trim", explode("\n", $_GET["multipleURLs"]));
}
foreach ($additionnalURLs AS $newURL) {
$newcontent = $getC->file_get_contents($newURL);
$newads = Lbc_Parser::process($newcontent, $_GET);
if (count($newads)) {
$ads = array_merge($ads, $newads);
}
}
}
$sortedads = Lbc::sortAds($ads);
if (count($sortedads)) {
foreach ($sortedads AS $ad) {
$item = new FeedItem(
md5($ad->getId().$ad->getDate()),
$ad->getTitle(),
$ad->getLink(),
require $dirname."/view.phtml"
);
$item->pubDate = gmdate("D, d M Y H:i:s O", $ad->getDate())." GMT";
$feeds->addItem($item);
}
}
$feeds->display();