예제 #1
0
 public function downloadImage()
 {
     $urlSource = $_POST['url'];
     $crawlerId = $_POST['crawler'];
     if (empty($urlSource)) {
         return false;
     }
     if (empty($crawlerId)) {
         return false;
     }
     $crawlerModel = new CrawlerModel();
     $crawlerInfo = $crawlerModel->getCrawlerInfo($crawlerId);
     $source = $crawlerModel->getSourceById($crawlerInfo['source_type']);
     if (!$source) {
         echo 'Crawler source not found';
         header("HTTP/1.0 404 Not Found");
         exit;
     }
     $class = '\\Krikke\\Crawler\\Controller\\Crawlers\\' . ucfirst($source['source']);
     $controller = new $class();
     $imgSrc = $controller->getImage(false);
     $imagePath = $controller->downloadImage($imgSrc, $crawlerId);
     $model = new GalleryModel();
     $itemId = $model->insertTempFetchedImage(array('path' => $imagePath, 'crawler_id' => $crawlerId, 'url_source' => $urlSource));
     if (isset($imgSrc['more-sources']) && !empty($imgSrc['more-sources'])) {
         $this->saveSources($imgSrc['more-sources'], $crawlerId, $source['id']);
     }
     exit;
 }
예제 #2
0
 public function getImage($returnJson = true)
 {
     $url = $_POST['url'];
     $crawlerId = $_POST['crawler'];
     $crawlerModel = new CrawlerModel();
     $crawlerInfo = $crawlerModel->getCrawlerInfo($crawlerId);
     if (empty($url)) {
         return false;
     }
     if (empty($crawlerId)) {
         return false;
     }
     $crawlerModel = new CrawlerModel();
     $source = $crawlerModel->getSourceById($crawlerInfo['source_type']);
     $dom = HtmlDomParser::file_get_html($url);
     $images = $dom->find($source['main_image']);
     $imgSrc = $images[0]->src;
     /**
      * find more sources
      */
     $moreSources = array();
     $moreFromBlock = $dom->find('.domainLinkWrapper');
     if (isset($moreFromBlock[0])) {
         $moreSources[] = $moreFromBlock[0]->href;
     }
     //paged Collection (suggested boards under pin
     $pagedCollection = $dom->find('.PagedCollection');
     if (isset($pagedCollection[0]) && !empty($pagedCollection[0])) {
         $boardLinkWrapper = $pagedCollection[0]->find('.boardLinkWrapper');
         foreach ($boardLinkWrapper as $blw) {
             $moreSources[] = $blw->href;
         }
     }
     $imgData = array('image' => $imgSrc, 'more-sources' => $moreSources);
     if ($returnJson) {
         echo json_encode($imgData);
         exit;
     } else {
         return $imgData;
     }
 }