diff --git a/Globals.php b/Globals.php deleted file mode 100644 index 0e7307b..0000000 --- a/Globals.php +++ /dev/null @@ -1,30 +0,0 @@ -options()->tckImageAttachmentCacheControl_config['config']; - $cacheability = $config['cacheability']; - $maxAge = $config['max_age'] * 86400; - - $response->header('Expires', \gmdate('D, d M Y H:i:s', \XF::$time + $maxAge) . ' GMT'); - $response->header('Cache-Control', "{$cacheability}, max-age={$maxAge}"); - - Globals::setImageAttachment(null); - } -} \ No newline at end of file diff --git a/Pub/View/AttachmentTrait.php b/Pub/View/AttachmentTrait.php index c445520..d1b9502 100644 --- a/Pub/View/AttachmentTrait.php +++ b/Pub/View/AttachmentTrait.php @@ -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; - } -} \ No newline at end of file + return parent::renderRaw(); + } +} diff --git a/XF/Admin/View/Attachment/View.php b/XF/Admin/View/Attachment/View.php index 9b72ea4..4d9fbb9 100644 --- a/XF/Admin/View/Attachment/View.php +++ b/XF/Admin/View/Attachment/View.php @@ -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(); - } -} \ No newline at end of file + use AttachmentViewTrait; +} diff --git a/XF/Pub/View/Attachment/View.php b/XF/Pub/View/Attachment/View.php index 48432de..ef88bfe 100644 --- a/XF/Pub/View/Attachment/View.php +++ b/XF/Pub/View/Attachment/View.php @@ -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(); - } -} \ No newline at end of file + use AttachmentViewTrait; +} diff --git a/_output/code_event_listeners/app_complete_a6b26d818f85c93cb9b7076ada022678.json b/_output/code_event_listeners/app_complete_a6b26d818f85c93cb9b7076ada022678.json deleted file mode 100644 index 64c11c5..0000000 --- a/_output/code_event_listeners/app_complete_a6b26d818f85c93cb9b7076ada022678.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "event_id": "app_complete", - "execute_order": 10, - "callback_class": "TickTackk\\ImageAttachmentCacheControl\\Listener", - "callback_method": "appComplete", - "active": true, - "hint": "", - "description": "Called after the global \\XF\\App object has finished running, but before the response is filtered and returned." -} \ No newline at end of file