Initial commit

Functional, without SSO
This commit is contained in:
Jimmy Monin
2016-09-18 11:03:26 +02:00
commit 57708e3169
253 changed files with 30787 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php
$values = array(
"url" => "", "price_min" => "", "price_max" => "", "price_strict" => false,
"cities" => "", "categories" => array()
);
$categoryCollection = new \Lbc\CategoryCollection();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
foreach ($_POST AS $name => $value) {
if (is_array($value)) {
$_POST[$name] = array_map("trim", $_POST[$name]);
} else {
$_POST[$name] = trim($_POST[$name]);
}
}
$values = array_merge($values, $_POST);
if (empty($values["url"])) {
$errors["url"] = "Ce champ est obligatoire.";
}
if ($values["price_min"] && $values["price_min"] != (int)$values["price_min"]) {
$errors["price"] = "Valeur de \"prix min\" non valide. ";
}
if ($values["price_max"] && $values["price_max"] != (int)$values["price_max"]) {
$errors["price"] .= "Valeur de \"prix max\" non valide.";
}
if (empty($errors)) {
$query = array("mod" => "rss", "a" => "refresh", "url" => $values["url"]);
if (!empty($values["price_min"])) {
$query["price_min"] = (int)$values["price_min"];
}
if (!empty($values["price_max"])) {
$query["price_max"] = (int)$values["price_max"];
}
if (!empty($values["cities"])) {
$query["cities"] = $values["cities"];
}
if (!empty($values["categories"]) && is_array($values["categories"])) {
$query["categories"] = $values["categories"];
}
$query["price_strict"] = isset($values["price_strict"])?
(int)(bool)$values["price_strict"]:0;
header("LOCATION: ./?".http_build_query($query));
}
}

View File

@ -0,0 +1,98 @@
<?php
if (!isset($_GET["url"])) {
return;
}
$disableLayout = true;
$logFile = DOCUMENT_ROOT."/var/logs/rss.log";
use \FeedWriter\RSS2;
try {
$parser = \AdService\ParserFactory::factory($_GET["url"]);
} catch (\AdService\Exception $e) {
echo "Cette adresse ne semble pas valide.";
exit;
}
if (false !== strpos($_GET["url"], "leboncoin.fr")) {
$_GET["url"] = rtrim(preg_replace("#(o|sp)=[0-9]*&?#", "", $_GET["url"]), "?&");
}
// nettoyage cache
$files = array_diff(scandir(DOCUMENT_ROOT."/var/feeds"), array(".", ".."));
foreach ($files AS $file) {
$file = DOCUMENT_ROOT."/var/feeds/".$file;
$mtime = filemtime($file);
if (($mtime + 20 * 60) < time()) {
unlink($file);
}
}
header("Content-Type: application/rss+xml", true);
$logger = Logger::getLogger("main");
$id = sha1($_SERVER["REQUEST_URI"]);
$cache_filename = DOCUMENT_ROOT."/var/feeds/".$id.".xml";
if (is_file($cache_filename)) {
readfile($cache_filename);
return;
}
$params = $_GET;
if (isset($params["cities"])) {
$params["cities"] = array_map("trim", explode("\n", mb_strtolower($params["cities"])));
}
$content = $client->request($_GET["url"]);
$filter = new \AdService\Filter($params);
$siteConfig = \AdService\SiteConfigFactory::factory($_GET["url"]);
$ads = $parser->process(
$content,
$filter,
parse_url($_GET["url"], PHP_URL_SCHEME)
);
$title = $siteConfig->getOption("site_name");
$urlParams = parse_url($_GET["url"]);
if (!empty($urlParams["query"])) {
parse_str($urlParams["query"], $aQuery);
if (!empty($aQuery["q"])) {
$title .= " - ".$aQuery["q"];
}
}
$feeds = new RSS2;
$feeds->setTitle($siteConfig->getOption("site_name"));
$feeds->setLink($siteConfig->getOption("site_url"));
$feeds->setSelfLink(
!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"?"https":"http".
"://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]
);
$feeds->setDescription("Flux RSS de la recherche : ".$_GET["url"]);
$feeds->setChannelElement("language", "fr-FR");
// The date when this feed was lastly updated. The publication date is also set.
$feeds->setDate(date(DATE_RSS, time()));
$feeds->setChannelElement("pubDate", date(\DATE_RSS, strtotime("2013-04-06")));
$feeds->addGenerator();
if (count($ads)) {
foreach ($ads AS $ad) {
$item = $feeds->createNewItem();
$item->setTitle($ad->getTitle());
$item->setLink($ad->getLink());
$item->setDescription(require DOCUMENT_ROOT."/app/rss/views/rss-ad.phtml");
if ($ad->getDate()) {
$item->setDate($ad->getDate());
}
$item->setId(md5($ad->getId()));
$feeds->addItem($item);
}
}
$content = $feeds->generateFeed();
file_put_contents($cache_filename, $content);
echo $content;