Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions Globals.php

This file was deleted.

34 changes: 0 additions & 34 deletions Listener.php

This file was deleted.

65 changes: 27 additions & 38 deletions Pub/View/AttachmentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,38 @@

namespace TickTackk\ImageAttachmentCacheControl\Pub\View;

use TickTackk\ImageAttachmentCacheControl\Globals;
use XF\Entity\Attachment as AttachmentEntity;
use XF\Entity\User as UserEntity;
use XF\Repository\User as UserRepo;

trait AttachmentTrait
{
/**
* @throws \Exception
*/
public function setupForTckImageAttachmentCacheControl() : void
{
if (!\XF::options()->tckImageAttachmentCacheControl_config['enabled'])
/**
* @return string|HttpResponseStream
*
* @throws \Exception
*/
public function renderRaw()
{
$params = $this->getParams();

$config = \XF::options()->tckImageAttachmentCacheControl_config;

if (
$config['enabled']
&& isset($params['attachment'])
&& ($attachment = $params['attachment'])
&& ($attachment instanceof AttachmentEntity)
&& $attachment->Data
&& $attachment->Data->width
&& $attachment->Data->height
)
{
return;
}

Globals::setImageAttachment($this->getImageAttachmentFromParamsForTckImageAttachmentCacheControl());
}

/**
* @throws \Exception
*/
protected function getImageAttachmentFromParamsForTckImageAttachmentCacheControl() :? AttachmentEntity
{
$params = $this->getParams();
if (!\array_key_exists('attachment', $params))
{
return null;
}
$cacheability = $config['config']['cacheability'];
$maxAge = $config['config']['max_age'] * 86400;

$attachment = $params['attachment'];
if (!$attachment instanceof AttachmentEntity || !$attachment->Data)
{
return null;
}

/** @var AttachmentEntity $attachment */
if (!$attachment->Data->width || !$attachment->Data->height)
{
return null;
$this->response->header('Expires', \gmdate('D, d M Y H:i:s', \XF::$time + $maxAge) . ' GMT');
$this->response->header('Cache-Control', "{$cacheability}, max-age={$maxAge}");
}

return $attachment;
}
}
return parent::renderRaw();
}
}
17 changes: 2 additions & 15 deletions XF/Admin/View/Attachment/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,8 @@
namespace TickTackk\ImageAttachmentCacheControl\XF\Admin\View\Attachment;

use TickTackk\ImageAttachmentCacheControl\Pub\View\AttachmentTrait as AttachmentViewTrait;
use XF\Http\ResponseStream as HttpResponseStream;

class View extends XFCP_View
{
use AttachmentViewTrait;

/**
* @return string|HttpResponseStream
*
* @throws \Exception
*/
public function renderRaw()
{
$this->setupForTckImageAttachmentCacheControl();

return parent::renderRaw();
}
}
use AttachmentViewTrait;
}
17 changes: 2 additions & 15 deletions XF/Pub/View/Attachment/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,8 @@
namespace TickTackk\ImageAttachmentCacheControl\XF\Pub\View\Attachment;

use TickTackk\ImageAttachmentCacheControl\Pub\View\AttachmentTrait as AttachmentViewTrait;
use XF\Http\ResponseStream as HttpResponseStream;

class View extends XFCP_View
{
use AttachmentViewTrait;

/**
* @return string|HttpResponseStream
*
* @throws \Exception
*/
public function renderRaw()
{
$this->setupForTckImageAttachmentCacheControl();

return parent::renderRaw();
}
}
use AttachmentViewTrait;
}

This file was deleted.