foreach(pq('li.list-item') as $li) {
$el = pq($li);
$link = [];
$link['url'] = 'http:' . $el->find('a.product')->attr('href') . PHP_EOL;
$link['img'] = '';
$im_el = pq($el->find('img.picCore'));
if( $im_el->attr('src') ) {
$link['img'] = 'http:' . $im_el->attr('src');
}elseif( $im_el->attr('image-src') ) {
$link['img'] = 'http:' . $im_el->attr('image-src');
}else continue;
$link['text'] = $el->find('a.product')->text();
$link['id'] = $el->find('a.atwl-button')->attr('data-product-id');
$links []= $link;
}
foreach( $links as $link ) {
if( mb_strpos($done, $link['id'] . '-') !== FALSE ) {
echo $link['id'] . ' already done' . PHP_EOL;
continue;
}
if( $post = createPost($link) ) {
echo 'Post #' . $post . ' Created' . PHP_EOL;
file_put_contents(__DIR__ . '/complete.links', $link['id'] . '-' . PHP_EOL, FILE_APPEND);
break;
}
}
function createPost( $link ) {
global $settings;
$img = file_put_contents('photo.jpg', file_get_contents($link['img']));