/** * createFilePreview * * Return a file preview from Amazon S3. * * ### Example: * * $options * $options['filename'] * $options['title'] * $options['description'] * $options['originalFilename'] * * $path is the path of the image in the S3 bucket * * @param string $path * @param string $site * @param array $options * @return string */ public function createFilePreview($path, $site, array $options = []) { $html = ''; if ($path != null && $path != '') { try { $plainUrl = $this->getObjectUrl($site, $path); //$this->_s3Client->getObjectUrl($bucketName, $path, '+10 minutes'); $fileName = $options['filename']; if (WRUtils::guessKindOfFile($fileName) == 'image') { $html .= "<div class=\"file-selectable\" my-data-key=\"" . $options['id'] . "\" title=\"" . $options['title'] . "\">"; $html .= "<img style='height:120px' src='" . $plainUrl . "' class='file-preview-image' alt='" . $options['originalFilename'] . "' title='" . $options['originalFilename'] . "'>"; $html .= "</div>"; } else { $html .= "<div class=\"file-selectable\" my-data-key=\"" . $options['id'] . "\" title=\"" . $options['title'] . "\">"; $html .= WRUtils::getPreviewFileIcon($fileName); $html .= "</div>"; } } catch (\Exception $e) { $html .= "No preview!"; } } return $html; }
/** * imageWithDefault * * Return an image. If image isn't available return default image or default html placeholder * * ### Example: * * `$this->S3File->imageWithDefault($path, $options);` * * $options are the same as for HTML image, like ['class'=>'img-responsive'] * if you want to show an HTML piece of code when no image is retrieved pass, for example, in $options ['noimagehtml'=>'<span>no image</span>'] * * $path is the path of the image in the S3 bucket * * @param string $path * @param array $options * @return string */ public function imageWithDefault($path, array $options = []) { $html = ''; if ($path != null && $path != '' && WRUtils::guessKindOfFile($path) === 'image') { try { $html .= $this->Html->image($this->preparePath($path), $options); } catch (\Exception $e) { $html .= $this->getDefaultImage($options); } } else { $html .= $this->getDefaultImage($options); } return $html; }