Exemplo n.º 1
0
 public function run()
 {
     header('Content-Type: text/html; charset=utf-8');
     $url = $this->getUrl();
     $kategoria = $this->getKategoria();
     $dir = opendir('uploads/');
     $doc = new \DOMDocument();
     @$doc->loadHTMLFile($url);
     $xpath = new \DOMXPath($doc);
     $links = $xpath->query('//td[@class="main_table"]//td[@class="right"]//table[@class="tekst"]//td[@class="product_list_foto"]//a/@href');
     $titles = $xpath->query('//td[@class="main_table"]//td[@class="right"]//table[@class="tekst"]//td[@class="product_list_data"]//span[@class="product_list_name"]');
     $desc = $xpath->query('//td[@class="main_table"]//td[@class="right"]//table[@class="tekst"]//td[@class="product_list_data"]//td[@class="product_list_desc"]');
     for ($i = 0, $j = 0; $i < $links->length; $i++, $j = $j + 2) {
         $description = $doc->saveHTML($desc->item($j));
         $description = strip_tags($description, '<p><div><br>');
         $title = $titles->item($i)->nodeValue;
         $src = self::PREFIX_TO_IMAGES . $links->item($i)->value;
         $ext = pathinfo($src, PATHINFO_EXTENSION);
         $permalink = $this->createPermalink($title);
         \DB\base\Manager::connection()->exec("\n                INSERT INTO element \n                    (label, permalink, opis, extension, kategoria_id)\n                    VALUES\n                    ('" . $title . "','" . $permalink . "','" . $description . "', '" . $ext . "'," . $kategoria . ")\n            ");
         $lastId = \DB\base\Manager::connection()->query("\n                SELECT id FROM element ORDER BY id DESC LIMIT 1\n            ")->fetchColumn();
         $imgCt = file_get_contents($src);
         $folder = 'uploads/' . $lastId;
         mkdir($folder);
         $fp = fopen($folder . "/image." . $ext, "w");
         fwrite($fp, $imgCt);
         fclose($fp);
     }
 }
Exemplo n.º 2
0
 public function run()
 {
     header('Content-Type: text/html; charset=UTF-8');
     $url = $this->getUrl();
     $kategoria = $this->getKategoria();
     $dir = opendir('uploads/');
     $doc = new \DOMDocument();
     @$doc->loadHTMLFile($url);
     $xpath = new \DOMXPath($doc);
     $titles = $xpath->query('//div[@class="rendslide-box"]//div[@class="product-box"]//td[@class="label"]//p[@class="font-fitter"]');
     $links = $xpath->query('//div[@class="rendslide-box"]//div[@class="slide page"]/@onclick');
     for ($i = 0; $i < $links->length; $i++) {
         $title = iconv('UTF8', 'LATIN1', $titles->item($i)->nodeValue);
         $link = str_replace("'", "", str_replace('window.location.href=', '', $links->item($i)->value));
         $subDoc = new \DOMDocument();
         @$subDoc->loadHTMLFile($link);
         $subXpath = new \DOMXPath($subDoc);
         $src = $subXpath->query('//div[@id="product"]//div[@class="left"]//a[@class="box"]/@href')->item(0)->value;
         $ext = pathinfo($src, PATHINFO_EXTENSION);
         $description = $subDoc->saveHTML($subXpath->query('//div[@id="product"]//div[@class="right"]//div[@class="left-margin"]')->item(0));
         $permalink = $this->createPermalink($title);
         $description = iconv('UTF8', 'LATIN1', $description);
         $description = preg_replace('/<p>.<\\/p>/', '', $description);
         \DB\base\Manager::connection()->exec("\n                INSERT INTO element \n                    (label, permalink, opis, extension, kategoria_id)\n                    VALUES\n                    ('" . $title . "','" . $permalink . "','" . $description . "', '" . $ext . "'," . $kategoria . ")\n            ");
         $lastId = \DB\base\Manager::connection()->query("\n                SELECT id FROM element ORDER BY id DESC LIMIT 1\n            ")->fetchColumn();
         $imgCt = file_get_contents($src);
         $folder = 'uploads/' . $lastId;
         mkdir($folder);
         $fp = fopen($folder . "/image." . $ext, "w");
         fwrite($fp, $imgCt);
         fclose($fp);
     }
 }
Exemplo n.º 3
0
 protected function createPermalink($label)
 {
     $connection = \DB\base\Manager::connection();
     $blk = false;
     $i = 0;
     $pl = $this->generatePermalink($label);
     $count = (int) $connection->query("SELECT count(*) as count FROM element WHERE permalink = '" . $pl . "'")->fetchObject()->count;
     if ($count == 0) {
         return $pl;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 public static function create($name, \Symfony\Component\HttpFoundation\File\UploadedFile $zdjecie)
 {
     $permalink = self::generatePermalink($name);
     $ext = pathinfo($zdjecie->getClientOriginalName(), PATHINFO_EXTENSION);
     $connection = \DB\base\Manager::connection();
     $count = (int) $connection->query("SELECT count(*) as count FROM kategorie WHERE permalink = '" . $permalink . "'")->fetchObject()->count;
     if ($count == 0) {
         $connection->exec("INSERT INTO kategorie (label, permalink, extension) VALUES ('" . $name . "', '" . $permalink . "', '" . $ext . "')");
         $lastId = \DB\base\Manager::connection()->query("\r\n                SELECT id FROM kategorie ORDER BY id DESC LIMIT 1\r\n            ")->fetchColumn();
         mkdir('uploads/kategorie/' . $lastId);
         $zdjecie->move('uploads/kategorie/' . $lastId, 'image.' . $ext);
         return true;
     }
     return false;
 }
Exemplo n.º 5
0
 public function run()
 {
     header('Content-Type: text/html; charset=utf-8');
     $url = $this->getUrl();
     $kategoria = $this->getKategoria();
     $dir = opendir('uploads/');
     $doc = new \DOMDocument();
     @$doc->loadHTMLFile($url);
     $xpath = new \DOMXPath($doc);
     $links = $xpath->query('//tr[@class="fewperrow"]//div[@class="product"]//a/@href');
     for ($i = 0; $i < $links->length; $i++) {
         $subDoc = new \DOMDocument();
         $href = $links->item($i)->value;
         @$subDoc->loadHTMLFile('http://jawo2008.pl/' . $href);
         $subXpath = new \DOMXPath($subDoc);
         $label = $subXpath->query('//div[@id="box_productfull"]//div[@class="boxhead"]')->item(0)->nodeValue;
         $src = 'http://jawo2008.pl/' . $subXpath->query('//div[@id="box_productfull"]//div[@class="innerbox"]//td[@class="productimg"]//a/@href')->item(0)->nodeValue;
         $permalink = $this->createPermalink($label);
         if ($permalink === false) {
             continue;
         }
         //description
         $opis = $subXpath->query('//div[@id="box_productfull"]//div[@class="innerbox"]//div[@class="description"]');
         if ($opis->length > 0) {
             $opis = $subDoc->saveHTML($opis->item(0));
         } else {
             $opis = '';
         }
         $ext = pathinfo($src, PATHINFO_EXTENSION);
         \DB\base\Manager::connection()->exec("\r\n                INSERT INTO element \r\n                    (label, permalink, opis, extension, kategoria_id)\r\n                    VALUES\r\n                    ('" . $label . "','" . $permalink . "','" . $opis . "', '" . $ext . "'," . $kategoria . ")\r\n            ");
         $lastId = \DB\base\Manager::connection()->query("\r\n                SELECT id FROM element ORDER BY id DESC LIMIT 1\r\n            ")->fetchColumn();
         $imgCt = file_get_contents($src);
         $folder = 'uploads/' . $lastId;
         mkdir($folder);
         $fp = fopen($folder . "/image." . $ext, "w");
         fwrite($fp, $imgCt);
         fclose($fp);
     }
 }
Exemplo n.º 6
0
 public function run()
 {
     $url = $this->getUrl();
     $kategoria = $this->getKategoria();
     $dir = opendir('uploads/');
     $doc = new \DOMDocument();
     @$doc->loadHTMLFile($url);
     $xpath = new \DOMXPath($doc);
     $links = $xpath->query('//a[@class="product_img_link"]/@href');
     for ($i = 0; $i < $links->length; $i++) {
         $subDoc = new \DOMDocument();
         $href = $links->item($i)->value;
         @$subDoc->loadHTMLFile($href);
         $subXpath = new \DOMXPath($subDoc);
         $img = $subXpath->query('//span[@id="view_full_size"]/img/@src');
         $label = $subXpath->query('//h1[@itemprop="name"]')->item(0)->nodeValue;
         $permalink = $this->createPermalink($label);
         if ($permalink === false) {
             continue;
         }
         $opis = $subXpath->query('//div[@id="idTab1"]');
         if ($opis->length > 0) {
             $opis = $subXpath->query('//div[@id="idTab1"]')->item(0)->nodeValue;
         } else {
             $opis = '';
         }
         $src = $img->item(0)->value;
         $ext = pathinfo($src, PATHINFO_EXTENSION);
         \DB\base\Manager::connection()->exec("\r\n                INSERT INTO element \r\n                    (label, permalink, opis, extension, kategoria_id)\r\n                    VALUES\r\n                    ('" . $label . "','" . $permalink . "','" . $opis . "', '" . $ext . "'," . $kategoria . ")\r\n            ");
         $lastId = \DB\base\Manager::connection()->query("\r\n                SELECT id FROM element ORDER BY id DESC LIMIT 1\r\n            ")->fetchColumn();
         $imgCt = file_get_contents($src);
         $folder = 'uploads/' . $lastId;
         mkdir($folder);
         $fp = fopen($folder . "/image." . $ext, "w");
         fwrite($fp, $imgCt);
         fclose($fp);
     }
 }
Exemplo n.º 7
0
//            if(!is_dir($folder)) {
//                mkdir($folder);
//            }
//            $fp = fopen($folder . "/image.".$ext, "w");
//            fwrite($fp, $imgCt);
//            fclose($fp);
//            die;
//        });
$app->get('/lista-produktow/{kategoria}', function ($kategoria) use($app) {
    $objKategoria = Manager::connection()->query("SELECT * FROM kategorie WHERE permalink = '" . $kategoria . "'")->fetchObject();
    $arrElementy = Manager::connection()->query("SELECT * FROM element WHERE kategoria_id = " . $objKategoria->id)->fetchAll();
    return $app['twig']->render('listaElementow.html.twig', array('kategoria' => $objKategoria, 'elementy' => $arrElementy));
});
$app->get('/lista-produktow/{kategoria}/{element}', function ($kategoria, $element) use($app) {
    $objElement = Manager::connection()->query("SELECT * FROM element WHERE permalink = '" . $element . "'")->fetchObject();
    $objKategoria = Manager::connection()->query("SELECT * FROM kategorie WHERE id = '" . $objElement->kategoria_id . "'")->fetchObject();
    return $app['twig']->render('showElement.html.twig', array('element' => $objElement, 'kategoria' => $objKategoria));
});
//$app->get('/dodaj-logo/{id}/{h}', function($id, $h) use ($app) {
//            $objElement = Manager::connection()->query("SELECT * FROM element WHERE id = " . $id)->fetchObject();
//            if($objElement === false){ die; }
//            $logoPath = getcwd() . '/web/img/logo_wb.png';
//            $imgPath = getcwd() . '/uploads/' . $id . '/image.' . $objElement->extension;
//            $znak = imagecreatefrompng($logoPath);
//            $toMethod = $objElement->extension == 'jpg' ? 'jpeg' : $objElement->extension;
//            $method = 'imagecreatefrom' . $toMethod;
//            $img = $method($imgPath);
//            $plik_w = imagesx($img);
//            $plik_h = imagesy($img);
//            $znaczek_w = imagesx($znak);
//            $znaczek_h = imagesy($znak);