Changeset 12778


Ignore:
Timestamp:
Dec 21, 2011, 10:01:26 PM (9 years ago)
Author:
rvelices
Message:

derivatives

  • better status codes + http headers on i.php
  • automatically switch to script mode, regenerate and reload derivatives on demand if their parameters change (without the need to clear the cache)
Location:
extensions/derivatives
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/derivatives/i.php

    r12775 r12778  
    11<?php
     2// +-----------------------------------------------------------------------+
     3// | Piwigo - a PHP based photo gallery                                    |
     4// +-----------------------------------------------------------------------+
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
     6// +-----------------------------------------------------------------------+
     7// | This program is free software; you can redistribute it and/or modify  |
     8// | it under the terms of the GNU General Public License as published by  |
     9// | the Free Software Foundation                                          |
     10// |                                                                       |
     11// | This program is distributed in the hope that it will be useful, but   |
     12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
     13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
     14// | General Public License for more details.                              |
     15// |                                                                       |
     16// | You should have received a copy of the GNU General Public License     |
     17// | along with this program; if not, write to the Free Software           |
     18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
     19// | USA.                                                                  |
     20// +-----------------------------------------------------------------------+
     21
    222defined('PHPWG_ROOT_PATH') || die('hacking');
    323
     
    5878    header('Content-Location: '.$url);
    5979    header('Location: '.$url);
    60     exit();
     80    exit;
     81  }
     82  if ($code>=400)
     83  {
     84    $protocol = $_SERVER["SERVER_PROTOCOL"];
     85    if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol) )
     86      $protocol = 'HTTP/1.0';
     87
     88    header( "$protocol $code $msg", true, $code );
    6189  }
    6290  //todo improve
     
    178206}
    179207
     208$src_mtime = @filemtime($page['src_path']);
     209if ($src_mtime === false)
     210{
     211  ierror('Source not found', 404);
     212}
     213
     214$need_generate = false;
     215$derivative_mtime = @filemtime($page['derivative_path']);
     216if ($derivative_mtime === false or
     217    $derivative_mtime < $src_mtime or
     218    $derivative_mtime < $params->last_mod_time)
     219{
     220  $need_generate = true;
     221}
     222
     223if (!$need_generate)
     224{
     225  if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )
     226    and strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $derivative_mtime)
     227  {// send the last mod time of the file back
     228    header('Last-Modified: '.gmdate('D, d M Y H:i:s', $derivative_mtime).' GMT', true, 304);
     229    header('Expires: '.gmdate('D, d M Y H:i:s', time()+10*24*3600).' GMT', true, 304);
     230    exit;
     231  }
     232  // todo send pass-through
     233}
     234
     235
    180236include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
    181237$image = new pwg_image($page['src_path']);
     
    217273
    218274$fstat = fstat($fp);
    219 $gmt_mtime = gmdate('D, d M Y H:i:s', $fstat['mtime']).' GMT';
    220 header('Last-Modified: '.$gmt_mtime);
     275header('Last-Modified: '.gmdate('D, d M Y H:i:s', $fstat['mtime']).' GMT');
     276header('Expires: '.gmdate('D, d M Y H:i:s', time()+10*24*3600).' GMT');
    221277header('Content-length: '.$fstat['size']);
    222278header('Connection: close');
  • extensions/derivatives/include/derivative.inc.php

    r12775 r12778  
    11<?php
     2// +-----------------------------------------------------------------------+
     3// | Piwigo - a PHP based photo gallery                                    |
     4// +-----------------------------------------------------------------------+
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
     6// +-----------------------------------------------------------------------+
     7// | This program is free software; you can redistribute it and/or modify  |
     8// | it under the terms of the GNU General Public License as published by  |
     9// | the Free Software Foundation                                          |
     10// |                                                                       |
     11// | This program is distributed in the hope that it will be useful, but   |
     12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
     13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
     14// | General Public License for more details.                              |
     15// |                                                                       |
     16// | You should have received a copy of the GNU General Public License     |
     17// | along with this program; if not, write to the Free Software           |
     18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
     19// | USA.                                                                  |
     20// +-----------------------------------------------------------------------+
    221
    322final class SrcImage
     
    150169    {
    151170      $mtime = @filemtime(PHPWG_ROOT_PATH.$rel_path);
    152       if ($mtime===false)
     171      if ($mtime===false or $mtime < $params->last_mod_time)
    153172      {
    154173        $url_style = 2;
  • extensions/derivatives/include/derivative_params.inc.php

    r12775 r12778  
    11<?php
     2// +-----------------------------------------------------------------------+
     3// | Piwigo - a PHP based photo gallery                                    |
     4// +-----------------------------------------------------------------------+
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
     6// +-----------------------------------------------------------------------+
     7// | This program is free software; you can redistribute it and/or modify  |
     8// | it under the terms of the GNU General Public License as published by  |
     9// | the Free Software Foundation                                          |
     10// |                                                                       |
     11// | This program is distributed in the hope that it will be useful, but   |
     12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
     13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
     14// | General Public License for more details.                              |
     15// |                                                                       |
     16// | You should have received a copy of the GNU General Public License     |
     17// | along with this program; if not, write to the Free Software           |
     18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
     19// | USA.                                                                  |
     20// +-----------------------------------------------------------------------+
    221
    322function size_to_url($s)
     
    258277{
    259278  public $type = IMG_CUSTOM;
     279  public $last_mod_time = 0; // used for non-custom images to regenerate the cached files
    260280  public $sizing;
    261281
Note: See TracChangeset for help on using the changeset viewer.