public function insertImageInGallery($imgSource, $sourceId)
 {
     $imgUrl = $imgSource['image'];
     $ext = substr($imgUrl, -4);
     $time = time();
     $year = date('Y', $time);
     $month = date('m', $time);
     $imageDestinationName = $year . '/' . $month . '/' . 'image-' . $time . $ext;
     //check if structured folders exist and make them if they don't
     $this->checkIfMapExist($year, $month);
     //download image
     $ch = curl_init($imgUrl);
     $fp = fopen(CRAWLED_FOLDER . $imageDestinationName, 'wb');
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     $data = curl_exec($ch);
     curl_close($ch);
     fclose($fp);
     $model = new GalleryModel();
     $itemId = $model->insertFetchedImage(array('path' => $imageDestinationName, 'source_id' => $sourceId));
     $this->insertTag($imgSource['tag-list'], $itemId);
     return true;
 }
Example #2
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;
 }
Example #3
0
 public function getImageInfo()
 {
     $id = (int) $_POST['id'];
     if (!isset($id) || empty($id)) {
         echo json_encode(array('success' => false, 'message' => 'Invalid or empty ID'));
         exit;
     }
     //get image info
     $model = new GalleryModel();
     $imageInfo = $model->getTempById($id);
     if ($imageInfo) {
         $this->jsonResponseOutput(array('success' => true, 'image' => $imageInfo));
     } else {
         $this->jsonResponseOutput(array('success' => false, 'message' => 'Could not get the image info'));
     }
 }