Renders a JPEG preview of the given attachment. Will fall back to a file icon,
if a preview can not be generated.

@param string $attachmentId Attachment ID
@return void
325571
public function preview($attachmentId = null)
    {
        // FIXME cache previews
        $attachment = $this->Attachments->get($attachmentId);
        $this->_checkAuthorization($attachment);

        switch ($attachment->filetype) {
            case 'image/png':
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/gif':
                $image = new \Imagick($attachment->getAbsolutePath());
                if (Configure::read('Attachments.autorotate')) {
                    $this->_autorotate($image);
                }
                break;
            case 'application/pdf':
                // Will render a preview of the first page of this PDF
                $image = new \Imagick($attachment->getAbsolutePath() . '[0]');
                break;
            default:
                $image = new \Imagick(Plugin::path('Attachments') . '/webroot/img/file.png');
                break;
        }

        $image->setImageFormat('png');
        $image->thumbnailImage(80, 80, true, false);
        $image->setImageCompression(\Imagick::COMPRESSION_JPEG);
        $image->setImageCompressionQuality(75);
        $image->stripImage();

        header('Content-Type: image/' . $image->getImageFormat());
        echo $image;

        $image->destroy();
        exit;
    }
1309810
public function download($attachmentId = null)
    {
        $attachment = $this->Attachments->get($attachmentId);

        $this->_checkAuthorization($attachment);

        $this->response->file($attachment->getAbsolutePath(), [
            'download' => true,
            'name' => $attachment->filename
        ]);
        return $this->response;
    }
1285969
public function previewAction($emailId, $lang)
    {
        $class = $this->container->getParameter('lexik_mailer.email_entity.class');
        $email = $this->get('doctrine.orm.entity_manager')->find($class, $emailId);

        if (!$email) {
            throw $this->createNotFoundException(sprintf('No email found for id "%d"', $emailId));
        }

        $preview = $this->get('lexik_mailer.message_preview_generator');
        $preview->getTemplatesPreview($email, $lang);

        return $this->render('LexikMailerBundle:Email:preview.html.twig', array_merge(array(
            'content'  => $preview->get('content'),
            'subject'  => $preview->get('subject'),
            'fromName' => $preview->get('fromName'),
            'errors'   => $preview->getErrors(),
        ), $this->getAdditionalParameters()));
    }
712662
public URI attachmentUri(String documentId, String attachmentId) {
        String base_uri = String.format(
                "%s/%s/%s",
                this.rootUriString,
                this.encodeId(documentId),
                this.encodeId(attachmentId)
        );
        return uriFor(base_uri);
    }
737093
private function renderPasteNewFor($modelId)
    {
        $label = \sprintf($this->translate('pastenew.1'), ModelId::fromSerialized($modelId)->getId());
        return \sprintf(
            '<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>',
            $this->addToUrl('act=create&amp;after=' . $modelId),
            StringUtil::specialchars($label),
            $this->renderImageAsHtml('new.svg', $label)
        );
    }
671253
protected function sendSetPicture($jid, $filepath)
    {
        $nodeID = $this->createIqId();

        $data = preprocessProfilePicture($filepath);
        $preview = createIconGD($filepath, 96, true);

        $picture = new ProtocolNode('picture', ['type' => 'image'], null, $data);
        $preview = new ProtocolNode('picture', ['type' => 'preview'], null, $preview);

        $node = new ProtocolNode('iq', [
            'id'    => $nodeID,
            'to'    => $this->getJID($jid),
            'type'  => 'set',
            'xmlns' => 'w:profile:picture',
        ], [$picture, $preview], null);

        $this->sendNode($node);
    }
807767
public function view(? string $id = null): void
    {
        $calendar = null;

        $calendar = $this->Calendars->get($id);

        $this->set('calendar', $calendar);
        $this->set('_serialize', 'calendar');
    }
824767
public function actionShowFile(string $id): void
	{
		$response = $this->app->logs->getFile($id);
		if ($response) {
			$this->sendResponse($response);
		} else {
			$this->error();
		}
	}
279223
public function fileAction($storageId)
    {
        $fileManager = $this->get('beaast.core.manager.file');

        /**
         * @var File $file
         */
        $file = $fileManager->findOneBy(['storageId' => $storageId]);

        if (!$file) {
            return new Response('File not found.', 404);
        }

        $filePath = $fileManager->getFilePath($file);

        $headers = array();
        if ($file->getExtension() === 'png') {
            $headers = array(
                'Content-Type'     => 'image/png',
                'Content-Disposition' => 'inline; filename="'.$file->getFileName().'"',
            );
        } elseif ($file->getExtension() === 'jpg') {
            $headers = array(
                'Content-Type'     => 'image/jpg',
                'Content-Disposition' => 'inline; filename="'.$file->getFileName().'"',
            );
        } elseif ($file->getExtension() === 'pdf' || $file->getExtension() === 'xlsx') {
            $headers = array(
                'Cache-Control'     => 'private',
                'Content-Type'     => $file->getMimeType(),
                'Content-length'     => $file->getSize(),
                'Content-Disposition' => 'attachment; filename="'.$file->getFileName().'"',
            );
        }

        return new Response(file_get_contents($filePath), 200, $headers);
    }
1250053
public function image($mediaid = '')
    {
        $msg = array(
            'ToUserName'   => $this->getRevFrom(),
            'FromUserName' => $this->getRevTo(),
            'MsgType'      => self::MSGTYPE_IMAGE,
            'Image'        => array('MediaId' => $mediaid),
            'CreateTime'   => time(),
        );
        $this->Message($msg);
        return $this;
    }
387746
public function saveTags($attachmentId = null)
    {
        $this->request->allowMethod('post');
        $attachment = $this->Attachments->get($attachmentId);
        $this->_checkAuthorization($attachment);

        if (!TableRegistry::get($attachment->model)) {
            throw new \Cake\ORM\Exception\MissingTableClassException('Could not find Table ' . $attachment->model);
        }
        $inputArray = explode('&', $this->request->input('urldecode'));
        $tags = explode('$', explode('=', $inputArray[0])[1]);
        unset($inputArray[0]);

        // parse the attachments area options from the post data (comes in as a string)
        $options = [];
        foreach ($inputArray as $option) {
            $option = substr($option, 8);
            $optionParts = explode(']=', $option);
            $options[$optionParts[0]] = $optionParts[1];
        }
        // set so the first div of the attachments area element is skipped in the view, as it
        // serves as target for the Json Action
        $options['isAjax'] = true;

        $Model = TableRegistry::get($attachment->model);
        $Model->saveTags($attachment, $tags);

        $entity = $Model->get($attachment->foreign_key, ['contain' => 'Attachments']);
        $this->set(compact('entity', 'options'));
    }
1161293
public function actionPreview($id)
    {
        $emailTemplate = $this->loadModel($id);
        echo CHtml::tag('div', array('style' => 'font-family: Arial; font-weight: bold;'), $emailTemplate->subject) . '<hr/>';
        echo $emailTemplate->message;
    }
761541
private function renderAttachments(&$content, $boundary)
    {
        foreach($this->attachments as $file => $name) {
            if (!is_readable($file)) {
                throw new MailException('File could not be read: ' . $file); // @codeCoverageIgnore
            }
            $data = chunk_split(base64_encode(file_get_contents($file)));
            $type = mime_content_type($file);
            $content .= "\r\n";
            $content .= "--$boundary\r\n";
            $content .= "Content-Type: $type;\r\n\tname=\"$name\"\r\n";
            $content .= "Content-Transfer-Encoding: base64\r\n";
            $content .= "Content-Description: \"$name\"\r\n";
            $content .= "Content-Disposition: attachment;\r\n\tfilename=\"$name\"\r\n";
            $content .= "\r\n";
            $content .= "$data";
        }
    }
1081464
public function callbackAddImageToIndex($fileId)
    {
        $image = Yii::$app->storage->addImage($fileId);
        
        if (!$image) {
            return $this->sendError("Unable to create image from given file Id.");
        }

        Yii::$app->db->createCommand()->insert($this->refTableName, $this->prepareInsertFields([
            $this->imageIdFieldName => (int) $image->id,
            $this->refFieldName => (int) $this->itemId,
        ]))->execute();

        return $this->getImageArray($image->id);
    }
19208
public static function getAttachment($attachmentID,$options = [])
    {
        $result     = null;
        $downloader = new Priloha($attachmentID,$options);
        if ($downloader->lastResponseCode == 200) {

            $downloader->doCurlRequest(self::getDownloadURL($downloader), 'GET');
            if ($downloader->lastResponseCode == 200) {
                $result = $downloader->lastCurlResponse;
            }
        }
        return $result;
    }
467067
public function display() {

		// Compatibility with core WP's template parts.
		$this->templatePartCompat();

		if ( $this->template() ) {

			// Maybe remove core WP's `prepend_attachment`.
			$this->maybeShiftAttachment();

			// Make the `$data` variable available to the template.
			$data = $this->data;

			// Extract the data into individual variables. Each of
			// these variables will be available in the template.
			if ( $this->data instanceof Collection ) {
				extract( $this->data->all() );
			}

			// Load the template.
			include( $this->template() );
		}
	}
991798
public function saveOriginalImageToCache($fileID)
    {
        Storage::disk($this->cache_disk)->put($this->generateCacheFilePath($fileID), $this->getOriginalImageFile());
    }