[Tinhte] Image Attachment Optimization & CDN Support

[Tinhte] Image Attachment Optimization 2.3.0 20170315

No permission to download
I've got it installed and enabled, but forgot there was a TMS for it

Code:
<template_modifications>
    <modification title="Add hook to attached file" template_title="attached_files" execute_order="10" modification_type="str_replace" callback_class="" callback_method="" description="" version_id="20" version_string="2.0.0" active="1">
      <search_value><![CDATA[<div class="thumbnail">
                        <xen:if is="{$attachment.thumbnailUrl} AND {$canViewAttachments}">
                            <a href="{xen:link attachments, $attachment}" target="_blank" class="LbTrigger"
                                data-href="{xen:link misc/lightbox}"><img
                                src="{$attachment.thumbnailUrl}" alt="{$attachment.filename}" class="LbImage" /></a>
                        <xen:elseif is="{$attachment.thumbnailUrl}" />
                            <a href="{xen:link attachments, $attachment}" target="_blank"><img
                                src="{$attachment.thumbnailUrl}" alt="{$attachment.filename}" /></a>
                        <xen:else />
                            <a href="{xen:link attachments, $attachment}" target="_blank" class="genericAttachment"></a>
                        </xen:if>
                    </div>]]></search_value>
      <replace_value><![CDATA[<xen:hook name="attached_file_thumbnail" params="{xen:array 'attachment={$attachment}'}">
<div class="thumbnail">
                        <xen:if is="{$attachment.thumbnailUrl} AND {$canViewAttachments}">
                            <a href="{xen:link attachments, $attachment}" target="_blank" class="LbTrigger"
                                data-href="{xen:link misc/lightbox}"><img
                                src="{$attachment.thumbnailUrl}" alt="{$attachment.filename}" class="LbImage" /></a>
                        <xen:elseif is="{$attachment.thumbnailUrl}" />
                            <a href="{xen:link attachments, $attachment}" target="_blank"><img
                                src="{$attachment.thumbnailUrl}" alt="{$attachment.filename}" /></a>
                        <xen:else />
                            <a href="{xen:link attachments, $attachment}" target="_blank" class="genericAttachment"></a>
                        </xen:if>
                    </div>
</xen:hook>]]></replace_value>
    </modification>
  </template_modifications>
 
Finally tracked it down, for some reason the images are grabbing the cache control settings from the htaccess for php files

Code:
<filesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</filesMatch>

Removed the php from the filematch above from the htaccess and it is now giving the correct response headers. It is now caching on the CDN.

Why would the CDN be looking at the PHP cache controls in the htaccess and not the image controls ? I've confirmed it by removing just the PHP part from the filesmatch and it's working fine.

Is it something to do with View.php and View304.php being used to display the attachments ?
It is not because of the addon. As you know, XF serves attachment via PHP file (attachment.php). In your htaccess you have "no-cache", this option make addon useless since htaccess modified cache header.
 
With the new xenforo 1.2 hints you can speed up this plugin even more:

PHP:
 public static function load_class($class, array &$extend)
  {
  switch ($class)
  {
  case 'XenForo_ViewPublic_Attachment_View':
  $extend[] = 'Tinhte_AttachImageOptimization_ViewPublic_Attachment_View';
  break;
  case 'XenForo_ViewPublic_Attachment_View304':
  $extend[] = 'Tinhte_AttachImageOptimization_ViewPublic_Attachment_View304';
  break;
  case 'XenForo_ViewPublic_Post_Edit':
  $extend[] = 'Tinhte_AttachImageOptimization_ViewPublic_Post_Edit';
  break;
  case 'XenForo_ViewPublic_Post_EditInline':
  $extend[] = 'Tinhte_AttachImageOptimization_ViewPublic_Post_EditInline';
  break;
  case 'XenForo_ControllerPublic_Attachment':
  $extend[] = 'Tinhte_AttachImageOptimization_ControllerPublic_Attachment';
  break;
  case 'XenForo_BbCode_Formatter_Base':
  $extend[] = 'Tinhte_AttachImageOptimization_BbCode_Formatter_Base';
  break;
  }
  }

would be:
hint: XenForo_ViewPublic_Attachment_View_LoadClass
Class: Tinhte_AttachImageOptimization_Listener Funktion: viewPublicAttachmentViewLoadClass
PHP:
  public static function viewPublicAttachmentViewLoadClass($class, array &$extend)
  {
    $extend[] = 'Tinhte_AttachImageOptimization_ViewPublic_Attachment_View';
  }
...
 
_getValidUrl($url) could curl check against a 200 response.

OK, enough with the suggestions :D I want to put more photos on my community, then I will use your wonderful addon.
 
I just read this whole thread. I forgot I posted in it previously. I forgot I made a CDN resource. Which is funny cause I only made it because I knew I'd forget how to set it up. I'm glad I don't 'rage delete' my resources or I'd be screwed.
 
Top Bottom