Exemple #1
0
 private function createThumbnails($imageName)
 {
     $targetFileName = $this->getConfig('root') . '/' . $imageName;
     $info = pathinfo($targetFileName);
     if (in_array($info['extension'], ['jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff', 'psd', 'pdf'])) {
         $targetContent = $this->filesystem->getAdapter()->read($imageName);
         $img = Thumbnail::generateThumbnail($targetContent, $info['extension'], $this->getSettings('thumbnail_size'), $this->getSettings('thumbnail_crop_enabled'));
         if ($img) {
             $thumbnailTempName = 'thumbs/THUMB_' . $imageName;
             $thumbImg = Thumbnail::writeImage($info['extension'], $thumbnailTempName, $img, $this->getSettings('thumbnail_quality'));
             $this->emitter->run('files.thumbnail.saving', ['name' => $imageName, 'size' => strlen($thumbImg)]);
             $this->filesystem->getAdapter()->write($thumbnailTempName, $thumbImg);
             $this->emitter->run('files.thumbnail.saving:after', ['name' => $imageName, 'size' => strlen($thumbImg)]);
         }
     }
 }
Exemple #2
0
 public function acceptLink($link)
 {
     $settings = $this->filesSettings;
     $fileData = array();
     if (strpos($link, 'youtube.com') !== false) {
         // Get ID from URL
         parse_str(parse_url($link, PHP_URL_QUERY), $array_of_vars);
         $video_id = $array_of_vars['v'];
         // Can't find the video ID
         if ($video_id === FALSE) {
             die("YouTube video ID not detected. Please paste the whole URL.");
         }
         $fileData['url'] = $video_id;
         $fileData['type'] = 'embed/youtube';
         $fileData['height'] = 340;
         $fileData['width'] = 560;
         // Get Data
         $url = "http://gdata.youtube.com/feeds/api/videos/" . $video_id;
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
         $content = curl_exec($ch);
         curl_close($ch);
         $filesAdapter = $this->storageAdaptersByRole['TEMP'];
         $fileData['name'] = "youtube_" . $video_id . ".jpg";
         $fileData['date_uploaded'] = gmdate('Y-m-d H:i:s');
         $fileData['storage_adapter'] = $filesAdapter['id'];
         $fileData['charset'] = '';
         $img = Thumbnail::generateThumbnail('http://img.youtube.com/vi/' . $video_id . '/0.jpg', 'jpeg', $settings['thumbnail_size'], $settings['thumbnail_crop_enabled']);
         $thumbnailTempName = tempnam(sys_get_temp_dir(), 'DirectusThumbnail');
         Thumbnail::writeImage('jpg', $thumbnailTempName, $img, $settings['thumbnail_quality']);
         if (!is_null($thumbnailTempName)) {
             $this->ThumbnailStorage->acceptFile($thumbnailTempName, 'THUMB_' . $fileData['name'], $filesAdapter['destination']);
         }
         if ($content !== false) {
             $fileData['title'] = $this->get_string_between($content, "<title type='text'>", "</title>");
             // Not pretty hack to get duration
             $pos_1 = strpos($content, "yt:duration seconds=") + 21;
             $fileData['size'] = substr($content, $pos_1, 10);
             $fileData['size'] = preg_replace("/[^0-9]/", "", $fileData['size']);
         } else {
             // an error happened
             $fileData['title'] = "Unable to Retrieve YouTube Title";
             $fileData['size'] = 0;
         }
     } else {
         if (strpos($link, 'vimeo.com') !== false) {
             // Get ID from URL
             preg_match('/vimeo\\.com\\/([0-9]{1,10})/', $link, $matches);
             $video_id = $matches[1];
             // Can't find the video ID
             if ($video_id === FALSE) {
                 die("Vimeo video ID not detected. Please paste the whole URL.");
             }
             $fileData['url'] = $video_id;
             $fileData['type'] = 'embed/vimeo';
             $filesAdapter = $this->storageAdaptersByRole['TEMP'];
             $fileData['name'] = "vimeo_" . $video_id . ".jpg";
             $fileData['date_uploaded'] = gmdate('Y-m-d H:i:s');
             $fileData['storage_adapter'] = $filesAdapter['id'];
             $fileData['charset'] = '';
             // Get Data
             $url = 'http://vimeo.com/api/v2/video/' . $video_id . '.php';
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
             $content = curl_exec($ch);
             curl_close($ch);
             $array = unserialize(trim($content));
             if ($content !== false) {
                 $fileData['title'] = $array[0]['title'];
                 $fileData['caption'] = strip_tags($array[0]['description']);
                 $fileData['size'] = $array[0]['duration'];
                 $fileData['height'] = $array[0]['height'];
                 $fileData['width'] = $array[0]['width'];
                 $fileData['tags'] = $array[0]['tags'];
                 $vimeo_thumb = $array[0]['thumbnail_large'];
                 $img = Thumbnail::generateThumbnail($vimeo_thumb, 'jpeg', $settings['thumbnail_size'], $settings['thumbnail_crop_enabled']);
                 $thumbnailTempName = tempnam(sys_get_temp_dir(), 'DirectusThumbnail');
                 Thumbnail::writeImage('jpg', $thumbnailTempName, $img, $settings['thumbnail_quality']);
                 if (!is_null($thumbnailTempName)) {
                     $this->ThumbnailStorage->acceptFile($thumbnailTempName, 'THUMB_' . $fileData['name'], $filesAdapter['destination']);
                 }
             } else {
                 // Unable to get Vimeo details
                 $fileData['title'] = "Unable to Retrieve Vimeo Title";
                 $fileData['height'] = 340;
                 $fileData['width'] = 560;
             }
         } else {
             //Arnt youtube or voimeo so try to curl photo and use uploadfile
             $content = file_get_contents($link);
             $tmpFile = tempnam(sys_get_temp_dir(), 'DirectusFile');
             file_put_contents($tmpFile, $content);
             $stripped_url = preg_replace('/\\?.*/', '', $link);
             $realfilename = basename($stripped_url);
             return self::acceptFile($tmpFile, $realfilename);
         }
     }
     return $fileData;
 }
foreach ($mediaRecords as $media) {
    $adapterSettings = $tempStorageAdapterSettings;
    if (!$tempStorageAdapter->fileExists($media['name'], $adapterSettings['destination'])) {
        out("Skipping media record #" . $media['id'] . " -- adapter can't locate original file.\n");
        $statistics['failure']++;
        continue;
    }
    $info = pathinfo($media['name']);
    if (!in_array($info['extension'], $supportedExtensions)) {
        out("Skipping media record #" . $media['id'] . " -- the following extension is unsupported: " . $info['extension'] . "\n");
        $statistics['failure']++;
        continue;
    }
    if ($thumbnailStorageAdapter->fileExists($media['id'], $thumbnailStorageAdapterSettings['destination'])) {
        $statistics['exists']++;
        continue;
    }
    // Generate thumbnail
    $localFile = $tempStorageAdapter->joinPaths($adapterSettings['destination'], $media['name']);
    $img = Thumbnail::generateThumbnail($localFile, $info['extension'], $filesSettings['thumbnail_size'], $filesSettings['thumbnail_crop_enabled']);
    $thumbnailTempName = tempnam(sys_get_temp_dir(), 'DirectusThumbnail');
    Thumbnail::writeImage($info['extension'], $thumbnailTempName, $img, $filesSettings['thumbnail_quality']);
    $fileData = $thumbnailStorageAdapter->acceptFile($thumbnailTempName, $media['id'] . "." . $info['extension'], $thumbnailStorageAdapterSettings['destination']);
    $statistics['success']++;
}
out('');
out('Statistics:');
out('-----------');
foreach ($statistics as $name => $value) {
    out("{$name}: {$value}");
}
Exemple #4
0
 private function createThumbnails($imageName)
 {
     $targetFileName = $this->getConfig('root') . '/' . $imageName;
     $info = pathinfo($targetFileName);
     if (in_array($info['extension'], array('jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff', 'psd', 'pdf'))) {
         $targetContent = $this->filesystem->getAdapter()->read($imageName);
         $img = Thumbnail::generateThumbnail($targetContent, $info['extension'], $this->getSettings('thumbnail_size'), $this->getSettings('thumbnail_crop_enabled'));
         if ($img) {
             //   $thumbnailTempName = $this->getConfig('root') . '/thumbs/THUMB_' . $imageName;
             $thumbnailTempName = 'thumbs/THUMB_' . $imageName;
             $thumbImg = Thumbnail::writeImage($info['extension'], $thumbnailTempName, $img, $this->getSettings('thumbnail_quality'));
             $this->filesystem->getAdapter()->write($thumbnailTempName, $thumbImg);
             //, new FlysystemConfig());
         }
     }
 }