Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: captivat/LBCMail
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: AltisCorp/LBCMail
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
Loading
Showing with 797 additions and 172 deletions.
  1. +2 −1 .gitignore
  2. +30 −2 CHANGELOG.txt
  3. +94 −25 ConfigManager.php
  4. +3 −0 TODO
  5. +68 −0 bootstrap.php
  6. +76 −47 check.php
  7. +39 −0 config-dist.php
  8. +25 −36 index.php
  9. +157 −0 lib/Http/Client/Abstract.php
  10. +68 −0 lib/Http/Client/Curl.php
  11. +23 −8 lib/lbc.php
  12. +57 −0 styles.css
  13. +1 −1 version.php
  14. +5 −15 views/form-delete.phtml
  15. +85 −20 views/form.phtml
  16. +62 −15 views/list-alerts.phtml
  17. +2 −2 views/mail-ad.phtml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
configs/config.csv
configs/*.csv
config.php
.buildpath
.project
.settings
32 changes: 30 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
## Version 1.2 - 09/06/2012

## Version 1.3.2 - en cours

* ajout : trier les alertes par groupes (gestion basique).
* ajout : un peu de mise en forme avec un fichier style externe.
* ajout : fichier config.php pour gérer la configuration de l'application.
* ajout : possibilité de configurer un proxy.
* modification : passage à cURL pour les requêtes HTTP.
* correction : forcer le contrôle des alertes si ".lock" existe depuis plus de 10 minutes.

## Version 1.3.1 - 11/01/2013

* ajout : possibilité de suspendre les alertes sans les supprimer (merci s0x92 pour l'inspiration).
* correction : changement de classe CSS "ad-lbc" => "lbc" (crash parser).
* correction : mois de décembre non détecté ce qui exclu certaines anciennes annonces.

## Version 1.3 - 18/08/2012

* ajout : possbilité d'activer le multi utilisateur.
* correction : problème d'URL avec certaine recherche.

## Version 1.2.2 - 20/06/2012

* correction : prix max non pris en compte lors de l'enregistrement d'une alerte.
* correction : bug critique causant la perte des alertes.

## Version 1.2 - 16/06/2012

* ajout : système de filtre sur les prix et sur les villes.
* ajout : possibilité d'exclure les annonces sans prix d'indiqué.
* amélioration : création d'un objet "Alert" plus simple à gérer.
* correction : problème avec les dates (fuseau horaire notemment).
* correction : problème avec les dates (fuseau horaire notamment).
* correction : erreur lors de l'enregistrement d'une alerte avec données manquantes.


119 changes: 94 additions & 25 deletions ConfigManager.php
Original file line number Diff line number Diff line change
@@ -8,6 +8,12 @@ class Alert {
public $interval = 30;
public $time_last_ad = 0;
public $time_updated = 0;
public $price_min = -1;
public $price_max = -1;
public $price_strict = false;
public $cities;
public $suspend = 0;
public $group = "";

public function fromArray(array $values)
{
@@ -25,45 +31,63 @@ public function toArray()
"url" => $this->url,
"interval" => $this->interval,
"time_last_ad" => $this->time_last_ad,
"time_updated" => $this->time_updated
"time_updated" => $this->time_updated,
"price_min" => $this->price_min,
"price_max" => $this->price_max,
"price_strict" => $this->price_strict,
"cities" => $this->cities,
"suspend" => $this->suspend,
"group" => $this->group
);
}
}

class ConfigManager
{
protected static $_config;
protected static $_name = "config";

public static function getConfigFile()
{
return dirname(__FILE__)."/configs/config.csv";
return dirname(__FILE__)."/configs/".self::$_name.".csv";
}

public static function setConfigName($name)
{
self::$_name = $name;
self::load();
}

public static function load()
{
if (!is_file(self::getConfigFile())) {
return array();
}
$fp = fopen(self::getConfigFile(), "r");
if (!$header = fgetcsv($fp, 0, ",", '"')) {
return array();
}
$nb = count($header);
$config = array();
while (false !== $a = fgetcsv($fp, 0, ",", '"')) {
$alert = new Alert();
for ($i = 0; $i < $nb; $i++) {
if (isset($a[$i])) {
$alert->$header[$i] = $a[$i];
self::$_config = array();
if (is_file(self::getConfigFile())) {
$fp = fopen(self::getConfigFile(), "r");
if ($header = fgetcsv($fp, 0, ",", '"')) {
$nb = count($header);
$config = array();
while (false !== $a = fgetcsv($fp, 0, ",", '"')) {
$alert = new Alert();
for ($i = 0; $i < $nb; $i++) {
if (isset($a[$i])) {
$alert->$header[$i] = $a[$i];
}
}
$config[$alert->id] = $alert;
}
fclose($fp);
self::$_config = $config;
}
$config[] = $alert;
}
fclose($fp);
return $config;
}

public static function save(array $config)
public static function save()
{
if (!is_array(self::$_config)) {
self::load();
}
$filename = self::getConfigFile();
$setChmod = false;
if (!is_file($filename)) {
$dir = dirname($filename);
if ($dir == $filename) {
@@ -72,17 +96,62 @@ public static function save(array $config)
if (!is_writable($dir)) {
throw new Exception("Permission d'écrire sur le fichier de configuration non autorisée.");
}
} elseif (!is_writable(self::getConfigFile())) {
throw new Exception("Permission d'écrire sur le fichier de configuration non autorisée.");
$setChmod = true;
}
$fp = fopen($filename, "w");
if ($config && is_array($config)) {
$keys = array_keys($config[0]->toArray());
flock($fp, LOCK_EX);
if (self::$_config && is_array(self::$_config)) {
$alerts = array_values(self::$_config);
$keys = array_keys($alerts[0]->toArray());
fputcsv($fp, $keys, ",", '"');
foreach ($config AS $alert) {
foreach (self::$_config AS $alert) {
fputcsv($fp, array_values($alert->toArray()), ",", '"');
}
}
flock($fp, LOCK_UN);
fclose($fp);
if ($setChmod) {
chmod($filename, 0777);
}
}

public static function saveAlert(Alert $alert)
{
if (!is_array(self::$_config)) {
self::load();
}
if (empty($alert->id)) {
$alert->id = md5(uniqid());
}
self::$_config[$alert->id] = $alert;
self::save();
}

public static function deleteAlert(Alert $alert)
{
if (!is_array(self::$_config)) {
self::load();
}
unset(self::$_config[$alert->id]);
self::save();
}

public static function getAlerts()
{
if (!is_array(self::$_config)) {
self::load();
}
return self::$_config;
}

public static function getAlertById($id)
{
if (!is_array(self::$_config)) {
self::load();
}
if (isset(self::$_config[$id])) {
return self::$_config[$id];
}
return null;
}
}
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bug :
http://alerte.ilatumi.org/forum/viewtopic.php?id=45

68 changes: 68 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

ini_set("display_errors", true);

// définir un fuseau horaire
if (function_exists("date_default_timezone_set")) {
date_default_timezone_set("Europe/Paris");
}


$dirname = dirname(__FILE__);
$configFile = $dirname."/config.php";
if (is_file($configFile)) {
require $configFile;
}
require $dirname."/lib/lbc.php";
require $dirname."/lib/Http/Client/Curl.php";
require $dirname."/ConfigManager.php";

// initialisation des constantes.
if (!defined("MULTI_USER")) {
define("MULTI_USER", false);
}
if (!defined("PROXY_IP")) {
define("PROXY_IP", "");
}
if (!defined("PROXY_PORT")) {
define("PROXY_PORT", "");
}
if (!defined("CHECK_START")) {
define("CHECK_START", 7);
}
if (!defined("CHECK_END")) {
define("CHECK_END", 24);
}

// initialise le client HTTP.
$client = new HttpClientCurl();
if (defined("USER_AGENT")) {
$client->setUserAgent(USER_AGENT);
}
if (PROXY_IP) {
$client->setProxyIp(PROXY_IP);
if (PROXY_PORT) {
$client->setProxyPort(PROXY_PORT);
}
}

### Fonctions ###

/**
* Test la connexion HTTP.
* @param HttpClientAbstract $client
* @return string|boolean
*/
function testHTTPConnection(HttpClientAbstract $client) {
// teste la connexion
$client->setDownloadBody(false);
$client->request("http://www.google.fr");
if (200 == $client->getRespondCode()) {
// le proxy semble fonctionner.
$client->request("http://www.leboncoin.fr");
if (200 != $client->getRespondCode()) {
return false;
}
}
return true;
}
Loading