<?php session_start(); require_once __DIR__ . '/autoload.php'; require_once __DIR__ . '/classes/simple_html_dom.php'; $ads_controller = new AdvertsController(); if (!empty($_POST['link'])) { $url = $_POST['link']; $get = @file_get_html($url); if (false == $get) { $_SESSION['errors'] = 'Invalid link!'; header('Location: /views/ads/importAds.php'); } else { $data = []; $data['title'] = $get->find('h1')[0]->innertext; $data['image'] = $get->find('img')[1]->src; if ($get->innertext != '' and count($get->find('.description-expanded div.item-params'))) { foreach ($get->find('.description-expanded div.item-params') as $div) { $data['text'] .= $div->innertext; } } if ($get->innertext != '' and count($get->find('.description-text div#desc_text p'))) { foreach ($get->find('.description-text div#desc_text') as $p) { $data['text'] .= $p->innertext; } } $ads_controller->addAdvert($data); header('Location: /index.php'); die; } }