mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-06 03:40:48 +02:00
Initial commit
Functional, without SSO
This commit is contained in:
45
sources/app/rss/scripts/index.php
Normal file
45
sources/app/rss/scripts/index.php
Normal 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));
|
||||
}
|
||||
}
|
98
sources/app/rss/scripts/refresh.php
Normal file
98
sources/app/rss/scripts/refresh.php
Normal 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;
|
||||
|
70
sources/app/rss/views/index.phtml
Normal file
70
sources/app/rss/views/index.phtml
Normal file
@ -0,0 +1,70 @@
|
||||
<form action="" method="post">
|
||||
<h2>Génération d'un flux RSS</h2>
|
||||
<dl>
|
||||
<dt><label for="url">
|
||||
Indiquer l'adresse de recherche</label></dt>
|
||||
<dd><input type="text" id="url" name="url" value="<?php
|
||||
echo $values["url"]; ?>" size="75" placeholder="Ex: <?php
|
||||
echo htmlspecialchars("https://www.leboncoin.fr/ventes_immobilieres/offres/champagne_ardenne/?f=a&th=1&pe=7&ret=1");
|
||||
?>" /></dd>
|
||||
</dl>
|
||||
<?php $isOpen = $values["price_min"] || $values["price_max"]
|
||||
|| $values["price_strict"] || !empty($values["cities"]); ?>
|
||||
<h2 id="morefilters" class="formbox">Filtres supplémentaires <span>(cliquez pour <?php
|
||||
echo $isOpen ? "fermer" : "ouvrir"
|
||||
?>)</span></h2>
|
||||
<dl id="morefilters-content" style="display: <?php
|
||||
echo $isOpen ? "block" : "none"
|
||||
?>;">
|
||||
<dt>
|
||||
<label>Filtre sur le prix</label>
|
||||
<dt>
|
||||
<dd>
|
||||
<label for="price_min">
|
||||
Prix min :
|
||||
<input type="text" id="price_min" name="price_min" value="<?php
|
||||
echo $values["price_min"]; ?>" size="6" />
|
||||
</label>
|
||||
<label for="price_max">
|
||||
Prix max :
|
||||
<input type="text" id="price_max" name="price_max" value="<?php
|
||||
echo $values["price_max"]; ?>" size="6" />
|
||||
</label>
|
||||
<?php if (isset($errors["price"])) : ?>
|
||||
<p class="error"><?php echo $errors["price"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt style="margin-bottom: 10px;">
|
||||
<input type="hidden" name="price_strict" value="0" />
|
||||
<label for="price_strict">
|
||||
<input type="checkbox" id="price_strict" name="price_strict" value="1"<?php
|
||||
echo $values["price_strict"]?' checked="checked"':''
|
||||
?> style="margin-left: 0;" />
|
||||
cochez cette case pour exclure les annonces sans prix d'indiqué de votre recherche.
|
||||
</label>
|
||||
</dt>
|
||||
<dt><label for="cities">Filtre sur les villes ou départements (un par ligne)</label></dt>
|
||||
<dd>
|
||||
<textarea id="cities" name="cities" cols="30" rows="10"><?php
|
||||
echo htmlspecialchars($values["cities"]) ?></textarea>
|
||||
</dd>
|
||||
<dt><label>Filtre multi-catégorie</label></dt>
|
||||
<dd class="categories">
|
||||
<p class="warning"><span>Attention : </span>
|
||||
ce filtre ne doit être utilisé que pour les recherches sur "toutes les catégories".</p>
|
||||
<?php $i = 1; ?>
|
||||
<?php foreach ($categoryCollection->fetchAll() AS $group => $categories) : ?>
|
||||
<div class="categories-list categories-list-<?php echo $i++; ?>">
|
||||
<h3><?php echo htmlspecialchars($group); ?></h3>
|
||||
<?php foreach ($categories AS $id => $category) : ?>
|
||||
<label for="category-<?php echo $id; ?>"><input id="category-<?php
|
||||
echo $id; ?>" type="checkbox" name="categories[]" value="<?php
|
||||
echo htmlspecialchars($category); ?>" /><?php
|
||||
echo htmlspecialchars($category); ?></label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</dd>
|
||||
</dl>
|
||||
<p><input type="submit" value="Générer le flux" /></p>
|
||||
</form>
|
45
sources/app/rss/views/rss-ad.phtml
Normal file
45
sources/app/rss/views/rss-ad.phtml
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
ob_start();
|
||||
?>
|
||||
<?php if ($ad->getDate()) : ?>
|
||||
Publié le <strong><?php echo date("d/m/Y H:i", $ad->getDate()); ?></strong>
|
||||
<br />
|
||||
<br />
|
||||
<?php endif; ?>
|
||||
|
||||
<strong>Nom</strong> : <?php echo $ad->getTitle(); ?>
|
||||
<?php if ($ad->getPrice()) : ?>
|
||||
<strong>Prix</strong> : <?php echo number_format($ad->getPrice(), 0, ',', ' '); ?> <?php echo $ad->getCurrency(); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if ($ad->getCategory()) : ?>
|
||||
<br />
|
||||
<strong>Catégorie</strong> : <?php echo $ad->getCategory(); ?>
|
||||
<?php endif; ?>
|
||||
<br />
|
||||
<?php if ($ad->getCountry()) : ?>
|
||||
<strong>Département</strong> : <?php echo $ad->getCountry(); ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php if ($ad->getCity()) : ?><strong>Ville</strong> : <a href="https://maps.google.fr/?z=9&q=<?php
|
||||
echo htmlspecialchars($ad->getCountry().' '.$ad->getCity());
|
||||
?>" title="Localiser sur Google Map" target="_blank"><?php echo $ad->getCity(); ?></a>
|
||||
<?php endif; ?>
|
||||
<?php if ($siteConfig->getOption("pro_visible")) : ?>
|
||||
<br />Annonce de <?php echo $ad->getProfessional()?'professionnel':'particulier.'; ?>
|
||||
<?php endif; ?>
|
||||
<br />
|
||||
<?php if ($ad->getUrgent()) : ?>
|
||||
<strong style="color: #FF8900;">urgent</strong>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if ($ad->getThumbnailLink()) : ?>
|
||||
<br /><img src="<?php echo str_replace('/thumbs/', '/images/', $ad->getThumbnailLink()); ?>"
|
||||
alt="" style="max-width: 600px; float: left; display: block;" />
|
||||
<?php else : ?>
|
||||
<br />Pas de photo disponible.
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
return ob_get_clean();
|
Reference in New Issue
Block a user