Upgrade LBCAlerte to version 3.3

Add upgrade script
This commit is contained in:
Jimmy Monin
2016-11-26 19:19:16 +01:00
parent a7c054b535
commit 58ffd500e6
89 changed files with 6436 additions and 758 deletions

View File

@ -6,4 +6,6 @@ if ($action != "check") {
} else {
$storage = new \App\Storage\File\Alert(DOCUMENT_ROOT."/var/configs/".$auth->getUsername().".csv");
}
}
}
require DOCUMENT_ROOT."/app/data/notifications.php";

View File

@ -138,24 +138,22 @@ class Main
// configuration des notifications.
$notifications = array();
$notifications_params = $user->getOption("notification");
if ($notifications_params && is_array($notifications_params)) {
foreach ($notifications_params AS $notification_name => $options) {
if (!is_array($options)) {
continue;
}
try {
$notifications[$notification_name] = \Message\AdapterFactory::factory($notification_name, $options);
$this->_logger->debug(
"[Pid ".getmypid()."] USER : ".$user->getUsername().
" -> Notification ".get_class($notifications[$notification_name])." activée"
);
} catch (\Exception $e) {
$this->_logger->warn(
"[Pid ".getmypid()."] USER : ".$user->getUsername().
" -> Notification ".$notification_name." invalide"
);
}
$notifications_enabled = $user->getNotificationsEnabled();
foreach ($notifications_enabled AS $notification_name => $options) {
if (!is_array($options)) {
continue;
}
try {
$notifications[$notification_name] = \Message\AdapterFactory::factory($notification_name, $options);
$this->_logger->debug(
"[Pid ".getmypid()."] USER : ".$user->getUsername().
" -> Notification ".get_class($notifications[$notification_name])." activée"
);
} catch (\Exception $e) {
$this->_logger->warn(
"[Pid ".getmypid()."] USER : ".$user->getUsername().
" -> Notification ".$notification_name." invalide"
);
}
}
@ -167,6 +165,7 @@ class Main
if (count($alerts) == 0) {
continue;
}
foreach ($alerts AS $i => $alert) {
$log_id = "[Pid ".getmypid()."] USER : ".$user->getUsername()." - ALERT ID : ".$alert->id." -> ";
@ -205,7 +204,7 @@ class Main
try {
$parser = \AdService\ParserFactory::factory($alert->url);
} catch (\AdService\Exception $e) {
$this->_logger->err($log_id." ".$e->getMessage());
$this->_logger->warn($log_id." ".$e->getMessage());
continue;
}
@ -310,15 +309,12 @@ class Main
$error = true;
}
if (!$error) {
if ($alert->group_ads) {
$newAdsCount = count($newAds);
$subject = "Alerte ".$siteConfig->getOption("site_name")." : ".$alert->title;
$message = '
$message_header = '
<h1 style="font-size: 16px;">Alerte : '.htmlspecialchars($alert->title, null, "UTF-8").'</h1>
<p style="font-size: 14px; margin: 0;"><strong><a href="'.htmlspecialchars($alert->url, null, "UTF-8").'"
style="text-decoration: none; color: #0B6CDA;">LIEN DE RECHERCHE</a>';
if ($baseurl) {
$message .= '
$message_header .= '
- <a href="'.$baseurl.'?mod=mail&amp;a=form&amp;id='. $alert->id .
'" style="text-decoration: none; color: #E77600;">MODIFIER</a>
- <a href="'.$baseurl.'?mod=mail&amp;a=toggle_status&amp;s=suspend&amp;id='. $alert->id .
@ -327,8 +323,13 @@ class Main
'" style="text-decoration: none; color: #FF0000;">SUPPRIMER</a>
';
}
$message .= '</strong></p>';
$message .= '<hr />';
$message_header .= '</strong></p>';
$message_header .= '<hr />';
if ($alert->group_ads) {
$newAdsCount = count($newAds);
$subject = "Alerte ".$siteConfig->getOption("site_name")." : ".$alert->title;
$message = $message_header;
$message .= '<p style="font-size: 16px; margin: 10px 0;"><strong>'.
$newAdsCount.' nouvelle'.($newAdsCount > 1?'s':'').
' annonce'.($newAdsCount > 1?'s':'').
@ -344,27 +345,12 @@ class Main
} catch (phpmailerException $e) {
$this->_logger->warn($log_id.$e->getMessage());
}
} else {
$newAds = array_reverse($newAds, true);
foreach ($newAds AS $id => $ad) {
$subject = ($alert->title?$alert->title." : ":"").$ads[$id]->getTitle();
$message = '
<h1 style="font-size: 16px;">Alerte : '.htmlspecialchars($alert->title, null, "UTF-8").'</h1>
<p style="font-size: 14px; margin: 0;"><strong><a href="'.htmlspecialchars($alert->url, null, "UTF-8").'"
style="text-decoration: none; color: #0B6CDA;">LIEN DE RECHERCHE</a>';
if ($baseurl) {
$message .= '
- <a href="'.$baseurl.'?mod=mail&amp;a=form&amp;id='. $alert->id .
'" style="text-decoration: none; color: #E77600;">MODIFIER</a>
- <a href="'.$baseurl.'?mod=mail&amp;a=toggle_status&amp;s=suspend&amp;id='. $alert->id .
'" style="text-decoration: none; color: #999999;">ACTIVER / DÉSACTIVER</a>
- <a href="'.$baseurl.'?mod=mail&amp;a=form-delete&amp;id='. $alert->id .
'" style="text-decoration: none; color: #FF0000;">SUPPRIMER</a>
';
}
$message .= '</strong></p>';
$message .= '<hr /><br />';
$message .= $ad;
$message = $message_header.$ad;
$this->_mailer->Subject = $subject;
$this->_mailer->Body = $message;
@ -377,13 +363,9 @@ class Main
}
}
}
if ($notifications && (
$alert->send_sms_free_mobile
|| $alert->send_sms_ovh
|| $alert->send_pushbullet
|| $alert->send_notifymyandroid
|| $alert->send_pushover
)) {
$params = array();
if ($notifications) {
if ($countAds < 5) { // limite à 5 SMS
foreach ($newAds AS $id => $ad) {
$ad = $ads[$id]; // récupère l'objet.
@ -411,30 +393,6 @@ class Main
"description" => "Nouvelle annonce".($alert->title ? " pour : ".$alert->title : ""),
"url" => $url,
);
foreach ($notifications AS $key => $notifier) {
switch ($key) {
case "freeMobile":
$key_test = "send_sms_free_mobile";
break;
case "ovh":
$key_test = "send_sms_ovh";
break;
default:
$key_test = "send_".$key;
}
if (isset($alert->$key_test) && $alert->$key_test) {
try {
$notifier->send($msg, $params);
} catch (Exception $e) {
$this->_logger->warn(
$log_id."Erreur sur envoi via ".
get_class($notifier).
": (".$e->getCode().") ".
$e->getMessage()
);
}
}
}
}
}
} else { // envoi un msg global
@ -448,28 +406,31 @@ class Main
($alert->title ? " pour : ".$alert->title : ""),
"url" => $url,
);
foreach ($notifications AS $key => $notifier) {
switch ($key) {
case "freeMobile":
$key_test = "send_sms_free_mobile";
break;
case "ovh":
$key_test = "send_sms_ovh";
break;
default:
$key_test = "send_".$key;
}
if (isset($alert->$key_test) && $alert->$key_test) {
try {
$notifier->send($msg, $params);
} catch (Exception $e) {
$this->_logger->warn(
$log_id."Erreur sur envoi via ".
get_class($notifier).
": (".$e->getCode().") ".
$e->getMessage()
);
}
}
}
if ($params) {
foreach ($notifications AS $key => $notifier) {
switch ($key) {
case "freeMobile":
$key_test = "send_sms_free_mobile";
break;
case "ovh":
$key_test = "send_sms_ovh";
break;
default:
$key_test = "send_".$key;
}
if (isset($alert->$key_test) && $alert->$key_test) {
try {
$notifier->send($msg, $params);
} catch (Exception $e) {
$this->_logger->warn(
$log_id."Erreur sur envoi via ".
get_class($notifier).
": (".$e->getCode().") ".
$e->getMessage()
);
}
}
}
@ -548,11 +509,7 @@ try {
return;
}
try {
$main->check();
} catch (\Exception $e) {
Logger::getLogger("main")->warn($e->getMessage());
}
$main->check();
$main->shutdown();

View File

@ -4,9 +4,17 @@ if (isset($_GET["id"])) {
}
if (empty($alert)) {
$alert = new App\Mail\Alert();
if ($emails = $userAuthed->getOption("addresses_mails")) {
$alert->email = $emails;
}
}
if (isset($_GET["preurl"])) {
$alert->url = $_GET["preurl"];
}
$categoryCollection = new \Lbc\CategoryCollection();
$errors = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
foreach ($_POST AS $name => $value) {
@ -17,15 +25,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
}
}
$alert->fromArray($_POST);
if (empty($alert->send_mail)
&& empty($alert->send_sms_free_mobile)
&& empty($alert->send_sms_ovh)
&& empty($alert->send_pushbullet)
&& empty($alert->send_notifymyandroid)
&& empty($alert->send_pushover)
) {
$errors["send_type"] = "Vous devez sélectionner au moins un moyen de communication.";
}
if (empty($alert->email)) {
$errors["email"] = "Ce champ est obligatoire.";
}

View File

@ -67,20 +67,3 @@ if (in_array("Sans groupe", $groups)) {
unset($groups[array_search("Sans groupe", $groups)]);
$groups[] = "Sans groupe";
}
$notification["freeMobile"] = $userAuthed->hasSMSFreeMobile();
$notification["ovh"] = $userAuthed->hasSMSOvh();
$notification["pushbullet"] = $userAuthed->hasPushbullet();
$notification["notifymyandroid"] = $userAuthed->hasNotifyMyAndroid();
$notification["pushover"] = $userAuthed->hasPushover();

View File

@ -1,12 +1,25 @@
<?php
if (isset($_GET["id"]) && $alert = $storage->fetchById($_GET["id"])) {
$status = isset($_GET["s"])?$_GET["s"]:"";
if (in_array($status, array("suspend", "send_mail", "send_sms_free_mobile",
"send_sms_ovh", "send_pushbullet", "send_notifymyandroid",
"send_pushover"))) {
$status = isset($_GET["s"]) ? $_GET["s"] : "";
$update = false;
if ($status == "suspend") {
$alert->$status = !$alert->$status;
$update = true;
} else {
foreach ($data_notifications AS $name => $notification) {
if ($status == $notification["form_name"]) {
$alert->$status = !$alert->$status;
$update = true;
break;
}
}
}
if ($update) {
$storage->save($alert);
}
}
header("LOCATION: ./?mod=mail"); exit;
header("LOCATION: ./?mod=mail");
exit;

View File

@ -29,63 +29,24 @@ $alertCategories = $alert->getCategories();
<p class="error"><?php echo $errors["title"]; ?></p>
<?php endif; ?>
</dd>
<?php if ($userAuthed->hasSMSFreeMobile() || $userAuthed->hasSMSOvh() || $userAuthed->hasPushbullet()) : ?>
<?php if ($userAuthed->hasNotification()) : ?>
<dt>
<label>Comment souhaitez-vous recevoir les alertes</label>
</dt>
<dd class="notification-list">
<input type="hidden" name="send_mail" value="0" />
<input type="hidden" name="send_sms_free_mobile" value="0" />
<input type="hidden" name="send_sms_ovh" value="0" />
<input type="hidden" name="send_pushbullet" value="0" />
<input type="hidden" name="send_notifymyandroid" value="0" />
<input type="hidden" name="send_pushover" value="0" />
<label for="alert_mail">
<input id="alert_mail" type="checkbox" name="send_mail" value="1"<?php
echo $alert->send_mail?' checked="checked"':''
?> />
par email
<?php foreach ($data_notifications AS $name => $notification) : ?>
<?php if (!$notification["enabled"]) continue; ?>
<input type="hidden" name="<?php echo $notification["form_name"]; ?>" value="0" />
<label for="<?php echo $notification["form_name"]; ?>">
<input id="<?php echo $notification["form_name"]; ?>"
type="checkbox"
name="<?php echo $notification["form_name"]; ?>"
value="1"
<?php echo $alert->{$notification["form_name"]} ? ' checked="checked"' : ''; ?>
/>
<?php echo $notification["form_label"]; ?>
</label>
<?php if ($userAuthed->hasSMSFreeMobile()) : ?>
<label for="alert_sms_free">
<input id="alert_sms_free" type="checkbox" name="send_sms_free_mobile" value="1"<?php
echo $alert->send_sms_free_mobile?' checked="checked"':''
?> />
par SMS Free Mobile
</label>
<?php endif; ?>
<?php if ($userAuthed->hasSMSOvh()) : ?>
<label for="alert_sms_ovh">
<input id="alert_sms_ovh" type="checkbox" name="send_sms_ovh" value="1"<?php
echo $alert->send_sms_ovh?' checked="checked"':''
?> />
par SMS OVH
</label>
<?php endif; ?>
<?php if ($userAuthed->hasPushbullet()) : ?>
<label for="alert_pushbullet">
<input id="alert_pushbullet" type="checkbox" name="send_pushbullet" value="1"<?php
echo $alert->send_pushbullet?' checked="checked"':''
?> />
par Pushbullet
</label>
<?php endif; ?>
<?php if ($userAuthed->hasNotifyMyAndroid()) : ?>
<label for="alert_notifymyandroid">
<input id="alert_notifymyandroid" type="checkbox" name="send_notifymyandroid" value="1"<?php
echo $alert->send_notifymyandroid?' checked="checked"':''
?> />
par NotityMyAndroid
</label>
<?php endif; ?>
<?php if ($userAuthed->hasPushover()) : ?>
<label for="alert_pushover">
<input id="alert_pushover" type="checkbox" name="send_pushover" value="1"<?php
echo $alert->send_pushover?' checked="checked"':''
?> />
par Pushover
</label>
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($errors["send_type"])) : ?>
<p class="error"><?php echo $errors["send_type"]; ?></p>
<?php endif; ?>

View File

@ -30,29 +30,12 @@
<?php if ($showCities) : ?>
<th style="width: 200px">Villes</th>
<?php endif; ?>
<?php if ($notification["freeMobile"]
|| $notification["ovh"]
|| $notification["pushbullet"]
|| $notification["notifymyandroid"]
|| $notification["pushover"]
) : ?>
<th style="width: 140px">Envoyer par email</th>
<?php if ($notification["freeMobile"]) : ?>
<th style="width: 140px">SMS Free Mobile</th>
<?php endif; ?>
<?php if ($notification["ovh"]) : ?>
<th style="width: 140px">SMS OVH</th>
<?php endif; ?>
<?php if ($notification["pushbullet"]) : ?>
<th style="width: 140px">Pushbullet</th>
<?php endif; ?>
<?php if ($notification["notifymyandroid"]) : ?>
<th style="width: 140px">NotityMyAndroid</th>
<?php endif; ?>
<?php if ($notification["pushover"]) : ?>
<th style="width: 140px">Pushover</th>
<?php endif; ?>
<?php endif; ?>
<?php foreach ($data_notifications AS $name => $notification) : ?>
<?php if (!$notification["enabled"]) continue; ?>
<th style="width: 140px"><?php echo $notification["list_label"]; ?></th>
<?php endforeach; ?>
<th style="width: 70px">Actif</th>
<th style="width: 170px">&nbsp;</th>
</tr>
@ -89,53 +72,17 @@
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($notification["freeMobile"]
|| $notification["ovh"]
|| $notification["pushbullet"]
|| $notification["notifymyandroid"]
|| $notification["pushover"]
) : ?>
<?php foreach ($data_notifications AS $name => $notification) : ?>
<?php if (!$notification["enabled"]) continue; ?>
<td>
<a href="?mod=mail&amp;a=toggle_status&amp;s=send_mail&amp;id=<?php echo $alert->id;
?>"><img src="static/images/<?php
echo !$alert->send_mail?"disable":"enable"; ?>.png" alt="" /></a>
<a href="?mod=mail&amp;a=toggle_status&amp;s=<?php
echo $notification["form_name"]; ?>&amp;id=<?php
echo $alert->id; ?>"><img src="static/images/<?php
echo !$alert->{$notification["form_name"]} ? "disable" : "enable";
?>.png" alt="" /></a>
</td>
<?php endif; ?>
<?php if ($notification["freeMobile"]) : ?>
<td>
<a href="?mod=mail&amp;a=toggle_status&amp;s=send_sms_free_mobile&amp;id=<?php echo $alert->id;
?>"><img src="static/images/<?php
echo !$alert->send_sms_free_mobile?"disable":"enable"; ?>.png" alt="" /></a>
</td>
<?php endif; ?>
<?php if ($notification["ovh"]) : ?>
<td>
<a href="?mod=mail&amp;a=toggle_status&amp;s=send_sms_ovh&amp;id=<?php echo $alert->id;
?>"><img src="static/images/<?php
echo !$alert->send_sms_ovh?"disable":"enable"; ?>.png" alt="" /></a>
</td>
<?php endif; ?>
<?php if ($notification["pushbullet"]) : ?>
<td>
<a href="?mod=mail&amp;a=toggle_status&amp;s=send_pushbullet&amp;id=<?php echo $alert->id;
?>"><img src="static/images/<?php
echo !$alert->send_pushbullet?"disable":"enable"; ?>.png" alt="" /></a>
</td>
<?php endif; ?>
<?php if ($notification["notifymyandroid"]) : ?>
<td>
<a href="?mod=mail&amp;a=toggle_status&amp;s=send_notifymyandroid&amp;id=<?php echo $alert->id;
?>"><img src="static/images/<?php
echo !$alert->send_notifymyandroid?"disable":"enable"; ?>.png" alt="" /></a>
</td>
<?php endif; ?>
<?php if ($notification["pushover"]) : ?>
<td>
<a href="?mod=mail&amp;a=toggle_status&amp;s=send_pushover&amp;id=<?php echo $alert->id;
?>"><img src="static/images/<?php
echo !$alert->send_pushover?"disable":"enable"; ?>.png" alt="" /></a>
</td>
<?php endif; ?>
<?php endforeach; ?>
<td>
<a href="?mod=mail&amp;a=toggle_status&amp;s=suspend&amp;id=<?php echo $alert->id;
?>"><img src="static/images/<?php

View File

@ -2,6 +2,10 @@
<div>
<?php if ($ad->getDate()) : ?>
<strong>Publié le <?php echo date("d/m/Y à H:i", $ad->getDate()); ?></strong>
<?php if (!empty($baseurl) && isset($config) && $config->getOption("allow_backup")) : ?>
- <a href="<?php echo $baseurl; ?>?mod=annonce&amp;a=backup&amp;aurl=<?php echo $ad->getLink(); ?>"
target="_blank">SAUVEGARDER L'ANNONCE</a>
<?php endif; ?>
<br />
<?php endif; ?>
@ -37,7 +41,7 @@
<?php endif; ?>
<?php if ($ad->getThumbnailLink()) : ?>
<br /><img src="<?php echo str_replace('/thumbs/', '/images/', $ad->getThumbnailLink()); ?>" alt=""
style="max-width: 100%; overflow:hidden;" />
style="max-width: 100%; max-height: 600px; overflow:hidden;" />
<?php else : ?>
<br />Pas de photo disponible.
<?php endif; ?>