示例#1
0
 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;
 }
示例#2
0
 public function approveTempItem()
 {
     $id = (int) $_POST['id'];
     $tags = explode(',', $_POST['tags']);
     $subtags = explode(',', $_POST['subtags']);
     if (!isset($id) || empty($id)) {
         echo json_encode(array('success' => false, 'message' => 'Invalid or empty ID'));
         exit;
     }
     $model = new GalleryModel();
     $imageInfo = $model->getTempById($id);
     $imagePath = '/' . trim(CRAWLED_FOLDER, '/') . $imageInfo['path'];
     $filename = str_replace('/temp/', '', $imageInfo['path']);
     if (file_exists($imagePath)) {
         // move file
         $time = $this->checkIfMapExist();
         $galleryImagePath = $time['year'] . '/' . $time['month'] . '/' . $filename;
         $moved = copy($imagePath, '/' . CRAWLED_FOLDER . $galleryImagePath);
         if ($moved) {
             $data = array('path' => $galleryImagePath, 'crawler_id' => $imageInfo['crawler_id'], 'url_source' => $imageInfo['url_source']);
             if ($itemId = $model->insertFetchedImage($data)) {
                 //@todo Move tags
                 $this->insertTag($tags, $itemId);
                 //remove temp image
                 unlink($imagePath);
                 $response = $model->deleteTempImage($id);
                 if ($response) {
                     $this->jsonResponseOutput(array('success' => $response));
                 } else {
                     $this->jsonResponseOutput(array('success' => $response, 'message' => 'Could not delete from database'));
                 }
                 exit;
             } else {
                 $this->jsonResponseOutput(array('success' => false, 'message' => 'Could not insert the image in the gallery table'));
             }
         } else {
             $this->jsonResponseOutput(array('success' => false, 'message' => 'File could not be moved'));
         }
     } else {
         $this->jsonResponseOutput(array('success' => false, 'message' => 'File does not exist. or incorrect path was set'));
     }
 }