function updateImageNouvelle(Nouvelle $n, $RSS_id) { $imageUrl = $n->getImage(); if (!($imageUrl == 'default')) { $nouvelleUrl = $this->getIdNouvelle($n); $imageUrlLocal = '../model/images/' . $RSS_id . '_' . $nouvelleUrl . '.jpg'; if (!file_exists($imageUrlLocal)) { file_put_contents($imageUrlLocal, file_get_contents($imageUrl)); } } else { $imageUrlLocal = '../model/images/default.jpg'; $imageUrl = 'http://image-link-archive.meteor.com/images/placeholder-640x480.png'; // URL d'une image à mettre en default if (!file_exists($imageUrlLocal)) { file_put_contents($imageUrlLocal, file_get_contents($imageUrl)); } } }
function createNouvelle(Nouvelle $n, $RSS_id) { $o = $this->readNouvellefromTitre($n->getTitre(), $RSS_id); if ($o == NULL) { $q = "INSERT INTO nouvelle (date, titre, description, url, image, RSS_id) VALUES (\"" . htmlspecialchars($n->getPubDate()) . "\", \"" . htmlspecialchars($n->getTitre()) . "\", \"" . htmlspecialchars($n->getDescription()) . "\", \"" . htmlspecialchars($n->getLink()) . "\", \"" . htmlspecialchars($n->getImage()) . "\", " . $RSS_id . ")"; try { $r = $this->db->exec($q); if ($r == 0) { echo "createRSS error: no rss inserted\n"; } return $this->readRSSfromURL($n->getLink()); } catch (PDOException $e) { echo "PDO Error :" . $e->getMessage(); } } else { return $n; } }