mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-26 13:17:34 +02:00
Upgrade LBCAlerte to version 3.3
Add upgrade script
This commit is contained in:
9
sources/app/annonce/init.php
Normal file
9
sources/app/annonce/init.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$storageType = $config->get("storage", "type", "files");
|
||||
if ($storageType == "db") {
|
||||
$storage = new \App\Storage\Db\Ad($dbConnection, $userAuthed);
|
||||
} else {
|
||||
$storage = new \App\Storage\File\Ad(DOCUMENT_ROOT."/var/configs/backup-ads-".$auth->getUsername().".csv");
|
||||
}
|
||||
|
||||
$adPhoto = new App\Storage\AdPhoto($userAuthed);
|
40
sources/app/annonce/scripts/backup.php
Normal file
40
sources/app/annonce/scripts/backup.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
$url = !empty($_GET["aurl"]) ? $_GET["aurl"] : null;
|
||||
|
||||
$logger = Logger::getLogger("main");
|
||||
|
||||
$content = $client->request($url);
|
||||
|
||||
try {
|
||||
$parser = \AdService\ParserFactory::factory($url);
|
||||
} catch (\AdService\Exception $e) {
|
||||
$logger->err($e->getMessage());
|
||||
}
|
||||
|
||||
$ad = $parser->processAd(
|
||||
$content,
|
||||
parse_url($url, PHP_URL_SCHEME)
|
||||
);
|
||||
|
||||
$ad_stored = $storage->fetchById($ad->getId());
|
||||
if ($ad_stored) {
|
||||
if ($_SERVER["REQUEST_METHOD"] != "POST") {
|
||||
return;
|
||||
}
|
||||
|
||||
// Supprime les photos
|
||||
$adPhoto->delete($ad);
|
||||
}
|
||||
|
||||
|
||||
if (!$ad_stored) {
|
||||
$ad_stored = new \App\Ad\Ad();
|
||||
}
|
||||
|
||||
$ad_stored->setFromArray($ad->toArray());
|
||||
$storage->save($ad_stored);
|
||||
|
||||
$adPhoto->import($ad_stored);
|
||||
|
||||
header("LOCATION: ./?mod=annonce&a=view&id=".$ad->getId()); exit;
|
27
sources/app/annonce/scripts/form-comment.php
Normal file
27
sources/app/annonce/scripts/form-comment.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use AdService\SiteConfigFactory;
|
||||
|
||||
if (!isset($_GET["id"])) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$ad = $storage->fetchById($_GET["id"]);
|
||||
if (!$ad) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$comment = isset($_POST["comment"]) ? trim($_POST["comment"]) : "";
|
||||
$ad->setComment($comment);
|
||||
$storage->save($ad);
|
||||
|
||||
header("LOCATION: ./?mod=annonce&a=view&id=".$ad->getId()."&update=1");
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$ad_config = SiteConfigFactory::factory($ad->getLink());
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
17
sources/app/annonce/scripts/form-delete.php
Normal file
17
sources/app/annonce/scripts/form-delete.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
if (!isset($_GET["id"])) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
$ad = $storage->fetchById($_GET["id"]);
|
||||
if (!$ad) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (isset($_POST["id"]) && $_POST["id"] == $_GET["id"]) {
|
||||
$storage->delete($ad);
|
||||
$adPhoto->delete($ad);
|
||||
}
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$referer = isset($_GET["r"]) ? $_GET["r"] : "";
|
46
sources/app/annonce/scripts/form.php
Normal file
46
sources/app/annonce/scripts/form.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
$ad = new App\Ad\Ad();
|
||||
|
||||
$link = "";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (empty($_POST["link"])) {
|
||||
$errors["link"] = "Ce champ est obligatoire.";
|
||||
} else {
|
||||
$link = $_POST["link"];
|
||||
try {
|
||||
$siteConfig = \AdService\SiteConfigFactory::factory($link);
|
||||
$parser = \AdService\ParserFactory::factory($link);
|
||||
} catch (\Exception $e) {
|
||||
$errors["link"] = "Cette adresse ne semble pas valide.";
|
||||
}
|
||||
}
|
||||
if (empty($errors)) {
|
||||
$ad = $parser->processAd(
|
||||
$client->request($link),
|
||||
parse_url($link, PHP_URL_SCHEME)
|
||||
);
|
||||
if (!$ad) {
|
||||
$errors["link"] = "Impossible de sauvegarder l'annonce (annonce hors ligne ou format des données invalides).";
|
||||
}
|
||||
}
|
||||
if (empty($errors) && !empty($ad)) {
|
||||
$ad = $parser->processAd(
|
||||
$client->request($link),
|
||||
parse_url($link, PHP_URL_SCHEME)
|
||||
);
|
||||
|
||||
$ad_stored = $storage->fetchById($ad->getId());
|
||||
if (!$ad_stored) {
|
||||
$ad_stored = new \App\Ad\Ad();
|
||||
}
|
||||
|
||||
$ad_stored->setFromArray($ad->toArray());
|
||||
$storage->save($ad_stored);
|
||||
|
||||
$adPhoto->import($ad_stored);
|
||||
|
||||
header("LOCATION: ./?mod=annonce");
|
||||
exit;
|
||||
}
|
||||
}
|
28
sources/app/annonce/scripts/index.php
Normal file
28
sources/app/annonce/scripts/index.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
if (isset($_GET["sort"])) {
|
||||
if (in_array($_GET["sort"], array("title", "price", "city", "category", "author", "date", "zip_code", "date_created"))) {
|
||||
if (!isset($_SESSION["backupad"]["sort"]) || $_SESSION["backupad"]["sort"] != $_GET["sort"]) {
|
||||
$_SESSION["backupad"]["sort"] = $_GET["sort"];
|
||||
$_SESSION["backupad"]["order"] = "asc";
|
||||
} elseif (!isset($_SESSION["backupad"]["order"]) || $_SESSION["backupad"]["order"] == "desc") {
|
||||
$_SESSION["backupad"]["order"] = "asc";
|
||||
} else {
|
||||
$_SESSION["backupad"]["order"] = "desc";
|
||||
}
|
||||
}
|
||||
header("LOCATION: ?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$sort = "date_created";
|
||||
$order = "desc";
|
||||
if (isset($_SESSION["backupad"]["sort"])) {
|
||||
$sort = $_SESSION["backupad"]["sort"];
|
||||
}
|
||||
if (isset($_SESSION["backupad"]["order"])) {
|
||||
$order = $_SESSION["backupad"]["order"];
|
||||
}
|
||||
|
||||
$ads = $storage->fetchAll($sort." ".$order);
|
||||
|
||||
|
18
sources/app/annonce/scripts/view.php
Normal file
18
sources/app/annonce/scripts/view.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use AdService\SiteConfigFactory;
|
||||
|
||||
if (!isset($_GET["id"])) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
$ad = $storage->fetchById($_GET["id"]);
|
||||
if (!$ad) {
|
||||
header("LOCATION: ./?mod=annonce"); exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$ad_config = SiteConfigFactory::factory($ad->getLink());
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
20
sources/app/annonce/views/backup.phtml
Normal file
20
sources/app/annonce/views/backup.phtml
Normal file
@ -0,0 +1,20 @@
|
||||
<form action="" method="post">
|
||||
<fieldset>
|
||||
<legend>Annonce déjà sauvegardée</legend>
|
||||
|
||||
<p>
|
||||
Vous avez déjà sauvegardé cette annonce.
|
||||
Souhaitez vous écraser la sauvegarde ?
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>Titre : <?php echo htmlspecialchars($ad_stored->getTitle()); ?></li>
|
||||
<li>Url : <?php echo htmlspecialchars($ad_stored->getLink()); ?></li>
|
||||
</ul>
|
||||
<p>
|
||||
<input type="hidden" name="id" value="<?php echo $ad_stored->getId(); ?>" />
|
||||
<input type="submit" value="Oui" style="font-weight: bold;" />
|
||||
| <a href="?mod=annonce">Non</a>
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
17
sources/app/annonce/views/form-comment.phtml
Normal file
17
sources/app/annonce/views/form-comment.phtml
Normal file
@ -0,0 +1,17 @@
|
||||
<h2>
|
||||
<?php echo htmlspecialchars($ad->getTitle()); ?>
|
||||
</h2>
|
||||
|
||||
<form action="" method="post">
|
||||
<p><label for="comment">Votre note :</label></p>
|
||||
<p>
|
||||
<textarea name="comment" cols="75" rows="5"><?php
|
||||
echo htmlspecialchars($ad->getComment()); ?></textarea>
|
||||
<br />
|
||||
<p>
|
||||
<input type="submit" value="Enregistrer" />
|
||||
| <a href="?mod=annonce&a=view&id=<?php
|
||||
echo $ad->getId(); ?>">annuler</a>
|
||||
</p>
|
||||
</p>
|
||||
</form>
|
15
sources/app/annonce/views/form-delete.phtml
Normal file
15
sources/app/annonce/views/form-delete.phtml
Normal file
@ -0,0 +1,15 @@
|
||||
<form action="" method="post">
|
||||
<fieldset>
|
||||
<legend>Supprimer cette annonce ?</legend>
|
||||
<ul>
|
||||
<li>Titre : <?php echo htmlspecialchars($ad->getTitle()); ?></li>
|
||||
<li>Url : <?php echo htmlspecialchars($ad->getLink()); ?></li>
|
||||
</ul>
|
||||
<p>
|
||||
<input type="hidden" name="id" value="<?php echo $_GET["id"]; ?>" />
|
||||
<input type="submit" value="Oui" style="font-weight: bold;" />
|
||||
| <a href="?mod=annonce<?php
|
||||
echo $referer == "view" ? '&a=view&id='.$ad->getId() : ''; ?>">Non</a>
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
28
sources/app/annonce/views/form.phtml
Normal file
28
sources/app/annonce/views/form.phtml
Normal file
@ -0,0 +1,28 @@
|
||||
<form action="" method="post">
|
||||
<h2>Sauvegarder une annonce</h2>
|
||||
<dl>
|
||||
<dt>
|
||||
<label for="url">URL de l'annonce</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="link" name="link" value="<?php
|
||||
echo htmlspecialchars($link);
|
||||
?>" size="75" />
|
||||
<?php if (isset($errors["link"])) : ?>
|
||||
<p class="error"><?php echo $errors["link"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
</dl>
|
||||
<p><input type="submit" value="Enregistrer" />
|
||||
| <a href="?mod=annonce">annuler</a></p>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
103
sources/app/annonce/views/index.phtml
Normal file
103
sources/app/annonce/views/index.phtml
Normal file
@ -0,0 +1,103 @@
|
||||
<p>
|
||||
<?php if (0 < $nbAds = count($ads)) : ?>
|
||||
<strong><?php echo $nbAds ?> <?php
|
||||
echo $nbAds > 1?"annonces sauvegardées":"annonce sauvegardée"; ?></strong> |
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&a=form" class="link-create-ad">Sauvegarder une annonce</a>
|
||||
</p>
|
||||
|
||||
<table style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20px"></th>
|
||||
<th style="width: 20px"></th>
|
||||
<th>
|
||||
<?php if ($sort == "title") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=title">Titre</a>
|
||||
</th>
|
||||
<th style="width: 200px">
|
||||
<?php if ($sort == "author") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=author">Auteur</a>
|
||||
</th>
|
||||
<th style="width: 200px">
|
||||
<?php if ($sort == "date_created") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=date_created">Date de sauvegarde</a>
|
||||
</th>
|
||||
<th style="width: 200px">
|
||||
<?php if ($sort == "date") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=date">Date de publication</a>
|
||||
</th>
|
||||
<th style="width: 200px">
|
||||
<?php if ($sort == "category") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=category">Catégorie</a>
|
||||
</th>
|
||||
<th style="width: 100px">
|
||||
<?php if ($sort == "price") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=price">Prix</a>
|
||||
</th>
|
||||
<th style="width: 200px">
|
||||
<?php if ($sort == "zip_code") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=zip_code">Code postal</a>
|
||||
</th>
|
||||
<th style="width: 200px">
|
||||
<?php if ($sort == "city") : ?>
|
||||
<img src="static/images/sort-<?php echo $order; ?>.png" alt="" />
|
||||
<?php endif; ?>
|
||||
<a href="?mod=annonce&sort=city">Villes</a>
|
||||
</th>
|
||||
<th style="width: 20px"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (0 == $nbAds) : ?>
|
||||
<tr><td colspan="11">Aucune annonce sauvegardée</td></tr>
|
||||
<?php else: ?>
|
||||
<?php $i = 1; foreach ($ads AS $ad) : ?>
|
||||
<?php
|
||||
$date = implode("/", array_reverse(explode("-", $ad->getDate())));
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $i++; ?></td>
|
||||
<td>
|
||||
<?php if ($photos = $ad->getPhotos()) : ?>
|
||||
<img src="<?php echo $adPhoto->getPublicDestination($photos[0]["local"]); ?>" alt=""
|
||||
style="max-width: 100px; max-height: 100px;" />
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="title"><a href="?mod=annonce&a=view&id=<?php echo $ad->getId(); ?>"><?php
|
||||
echo $ad->getTitle()?htmlspecialchars($ad->getTitle()):"-"; ?></a></td>
|
||||
<td><?php echo htmlspecialchars($ad->getAuthor()); ?></td>
|
||||
<td><?php echo date("d/m/Y à H:i", strtotime($ad->getDateCreated())); ?></td>
|
||||
<td><?php echo htmlspecialchars($date); ?></td>
|
||||
<td><?php echo htmlspecialchars($ad->getCategory()); ?></td>
|
||||
<td style="text-align: right;">
|
||||
<?php if ($price = $ad->getPrice()) : ?>
|
||||
<?php echo number_format($price, 0, ",", " ")." ";
|
||||
echo htmlspecialchars($ad->getCurrency()); ?>
|
||||
<?php else: ?>
|
||||
-
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($ad->getZipCode()); ?></td>
|
||||
<td><?php echo htmlspecialchars($ad->getCity()); ?></td>
|
||||
<td><a href="?mod=annonce&a=form-delete&id=<?php echo $ad->getId(); ?>"
|
||||
title="Supprimer l'annonce"><span class="fa fa-times"></span></a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
95
sources/app/annonce/views/view.phtml
Normal file
95
sources/app/annonce/views/view.phtml
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
$date = implode("/", array_reverse(explode("-", $ad->getDate())));
|
||||
?>
|
||||
<p>
|
||||
<a href="?mod=annonce">< retour à la liste des annonces sauvegardées</a> |
|
||||
<a href="?mod=annonce&a=form-delete&id=<?php echo $ad->getId(); ?>&r=view"
|
||||
title="Supprimer l'annonce"><span class="fa fa-times"></span> supprimer l'annonce</a>
|
||||
</p>
|
||||
|
||||
<h2>
|
||||
<?php echo htmlspecialchars($ad->getTitle()); ?>
|
||||
<a href="<?php echo $ad->getLink(); ?>"
|
||||
target="_blank"
|
||||
title="Ouvrir sur <?php echo $ad_config->getOption("site_name");
|
||||
?>"><span class="fa fa-external-link"></span></a>
|
||||
</h2>
|
||||
<div class="annonce">
|
||||
<div class="annonce-data">
|
||||
<ul>
|
||||
<li class="annonce-data-line">
|
||||
<span class="annonce-label">Auteur</span><span
|
||||
class="annonce-value"><?php echo $ad->getAuthor(); ?></span>
|
||||
</li>
|
||||
<?php if ($value = $ad->getPrice()) : ?>
|
||||
<li class="annonce-data-line">
|
||||
<span class="annonce-label">Prix</span><span
|
||||
class="annonce-value"><?php
|
||||
echo number_format($value, 0, ",", " ")." ";
|
||||
echo htmlspecialchars($ad->getCurrency());
|
||||
?></span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li class="annonce-data-line">
|
||||
<span class="annonce-label">Date</span><span
|
||||
class="annonce-value"><?php
|
||||
echo $date; ?></span>
|
||||
</li>
|
||||
<li class="annonce-data-line">
|
||||
<span class="annonce-label">Catégorie</span><span
|
||||
class="annonce-value"><?php
|
||||
echo htmlspecialchars($ad->getCategory()); ?></span>
|
||||
</li>
|
||||
<?php if ($value = $ad->getCity()) : ?>
|
||||
<li class="annonce-data-line">
|
||||
<span class="annonce-label">Ville</span><span
|
||||
class="annonce-value">
|
||||
<?php echo htmlspecialchars($ad->getZipCode()); ?>
|
||||
<?php echo htmlspecialchars($value); ?>
|
||||
</span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($ad->getProperties() AS $name => $value) : ?>
|
||||
<?php if ($value) : ?>
|
||||
<li class="annonce-data-line">
|
||||
<span class="annonce-label"><?php echo htmlspecialchars($name); ?></span><span
|
||||
class="annonce-value">
|
||||
<?php echo htmlspecialchars($value); ?>
|
||||
</span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<div class="annonce-description">
|
||||
<span class="annonce-label">Description</span>
|
||||
<p><?php
|
||||
echo nl2br(htmlspecialchars($ad->getDescription())); ?></p>
|
||||
</div>
|
||||
<div class="annonce-comment">
|
||||
<span class="annonce-label">Note</span>
|
||||
<div>
|
||||
<p><?php echo nl2br(htmlspecialchars($note = $ad->getComment())); ?></p>
|
||||
<p><a href="?mod=annonce&a=form-comment&id=<?php echo $ad->getId(); ?>"
|
||||
class="button">
|
||||
<?php if (!$note) : ?>
|
||||
Ajouter une note
|
||||
<?php else: ?>
|
||||
Modifier la note
|
||||
<?php endif; ?>
|
||||
</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php $photos = $ad->getPhotos(); ?>
|
||||
<div class="annonce-photos">
|
||||
<?php foreach ($photos AS $photo) : ?>
|
||||
<div class="annonce-photo">
|
||||
<a href="<?php echo $adPhoto->getPublicDestination($photo["local"]);
|
||||
?>" target="_blank"><img
|
||||
src="<?php echo $adPhoto->getPublicDestination($photo["local"]); ?>"
|
||||
alt="" class="annonce-photo-img" /></a>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user