❇️ Permet l'enregistrement de plusieurs images

This commit is contained in:
Clement Desmidt 2017-09-28 22:15:22 +02:00
parent 348ebfb170
commit 272ab042d7

View File

@ -2,6 +2,8 @@
namespace Shikiryu\LBCReposter; namespace Shikiryu\LBCReposter;
use Symfony\Component\DomCrawler\Crawler;
class Deal class Deal
{ {
const TYPE_OFFER = 's'; const TYPE_OFFER = 's';
@ -48,11 +50,22 @@ class Deal
$deal->setType(self::TYPE_OFFER); $deal->setType(self::TYPE_OFFER);
$deal->setBody($crawler->filter('.properties_description')->first()->filter('p')->eq(1)->text()); $deal->setBody($crawler->filter('.properties_description')->first()->filter('p')->eq(1)->text());
$deal->setPrice($crawler->filter('[itemprop=price]')->first()->attr('content')); $deal->setPrice($crawler->filter('[itemprop=price]')->first()->attr('content'));
$images = $crawler->filter('[data-popin-content]')->each( if ($crawler->filter('.item_photo')->count() > 0) {
function ($node, $i) { $script = $crawler ->filter('.item_photo')->first()->nextAll()
return [ sprintf('setImage%s', $i) => $node->attr('data-popin-content')]; ->filter('script')->first()->html();
preg_match_all("/\"(http.*ad-thumb.*)\"/m", $script, $urls);
$urls = $urls[1];
$images = [];
foreach ($urls as $i => $url) {
$images[] = [sprintf('setImage%s', $i) => str_replace('thumb','large', $url)];
} }
); } else {
$images = $crawler->filter('[data-popin-content]')->each(
function (Crawler $node, $i) {
return [ sprintf('setImage%s', $i) => $node->attr('data-popin-content')];
}
);
}
foreach ($images as $image) { foreach ($images as $image) {
foreach ($image as $method => $uri) { foreach ($image as $method => $uri) {
$deal->$method($uri); $deal->$method($uri);