forked from SnorkY/LBCRss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
62 lines (51 loc) · 1.51 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
<?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";
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;
}
$content = file_get_contents($_GET["url"]);
$ads = Lbc_Parser::process($content, $_GET);
$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"]));
if (count($ads)) {
foreach ($ads 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();