Changeset 12820


Ignore:
Timestamp:
01/01/12 22:10:43 (8 years ago)
Author:
rvelices
Message:

feature 2541 multisize

  • admin GUI for choosing derivative parameters + persistence
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin.php

    r12102 r12820  
    166166    'U_NOTIFICATION_BY_MAIL'=> $link_start.'notification_by_mail', 
    167167    'U_CONFIG_GENERAL'=> $link_start.'configuration', 
     168    'U_CONFIG_DERIVATIVES'=> $link_start.'derivatives', 
    168169    'U_CONFIG_DISPLAY'=> $conf_link.'default', 
    169170    'U_CONFIG_EXTENTS'=> $link_start.'extend_for_templates', 
  • trunk/admin/include/functions.php

    r12797 r12820  
    20552055 
    20562056    case 'configuration': 
     2057    case 'derivatives': 
    20572058    case 'extend_for_templates': 
    20582059    case 'menubar': 
     
    22482249} 
    22492250 
    2250 function clear_derivative_cache($type='all') 
     2251/** delete all derivative files for one or several types */ 
     2252function clear_derivative_cache($types='all') 
    22512253{ 
    22522254  $pattern='#.*-'; 
    2253   if ($type == 'all') 
     2255  if ($types == 'all') 
     2256  { 
     2257    $types = ImageStdParams::get_all_types(); 
     2258    $types[] = IMG_CUSTOM; 
     2259  } 
     2260  elseif (!is_array($types)) 
     2261  { 
     2262    $types = array($types); 
     2263  } 
     2264 
     2265  if (count($types)>1) 
    22542266  { 
    22552267    $type_urls = array(); 
    2256     foreach(ImageStdParams::get_all_types() as $dtype) 
     2268    foreach($types as $dtype) 
    22572269    { 
    22582270      $type_urls[] = derivative_to_url($dtype); 
    22592271    } 
    2260     $type_urls[] = derivative_to_url(IMG_CUSTOM); 
    22612272    $pattern .= '(' . implode('|',$type_urls) . ')'; 
    22622273  } 
    22632274  else 
    22642275  { 
    2265     $pattern .= derivative_to_url($type); 
    2266   } 
     2276    $pattern .= derivative_to_url($types[0]); 
     2277  } 
     2278   
    22672279  $pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#'; 
    22682280  if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR)) 
     
    23212333      } 
    23222334      clearstatcache(); 
    2323       rmdir($path); 
     2335      @rmdir($path); 
    23242336    } 
    23252337    return $rmdir; 
  • trunk/admin/themes/default/template/admin.tpl

    r12482 r12820  
    8585      <ul> 
    8686        <li><a href="{$U_CONFIG_GENERAL}">{'Options'|@translate}</a></li> 
     87                                <li><a href="{$U_CONFIG_DERIVATIVES}">{'Derivatives'|@translate}</a></li> 
    8788        <li><a href="{$U_CONFIG_MENUBAR}">{'Menu Management'|@translate}</a></li> 
    8889        <li><a href="{$U_CONFIG_EXTENTS}">{'Templates'|@translate}</a></li> 
  • trunk/i.php

    r12802 r12820  
    168168    try 
    169169    { 
    170       $page['derivative_params'] = ImageParams::from_url_tokens($deriv); 
     170      $page['derivative_params'] = DerivativeParams::from_url_tokens($deriv); 
    171171    } 
    172172    catch (Exception $e) 
     
    184184} 
    185185 
     186 
     187function send_derivative($expires) 
     188{ 
     189  global $page; 
     190  $fp = fopen($page['derivative_path'], 'rb'); 
     191 
     192  $fstat = fstat($fp); 
     193  header('Last-Modified: '.gmdate('D, d M Y H:i:s', $fstat['mtime']).' GMT'); 
     194  if ($expires!==false) 
     195  { 
     196    header('Expires: '.gmdate('D, d M Y H:i:s', $expires).' GMT'); 
     197  } 
     198  header('Content-length: '.$fstat['size']); 
     199  header('Connection: close'); 
     200 
     201  $ctype="application/octet-stream"; 
     202  switch (strtolower($page['derivative_ext'])) 
     203  { 
     204    case ".jpe": case ".jpeg": case ".jpg": $ctype="image/jpeg"; break; 
     205    case ".png": $ctype="image/png"; break; 
     206    case ".gif": $ctype="image/gif"; break; 
     207  } 
     208  header("Content-Type: $ctype"); 
     209 
     210  fpassthru($fp); 
     211  fclose($fp); 
     212} 
    186213 
    187214 
     
    220247{ 
    221248  $need_generate = true; 
     249} 
     250 
     251$expires=false; 
     252$now = time(); 
     253if ( $now > (max($src_mtime, $params->last_mod_time) + 24*3600) ) 
     254{// somehow arbitrary - if derivative params or src didn't change for the last 24 hours, we send an expire header for several days 
     255  $expires = $now + 10*24*3600; 
    222256} 
    223257 
     
    231265    exit; 
    232266  } 
    233   // todo send pass-through 
     267  send_derivative($expires); 
    234268} 
    235269 
     
    271305$image->destroy(); 
    272306 
    273 $fp = fopen($page['derivative_path'], 'rb'); 
    274  
    275 $fstat = fstat($fp); 
    276 header('Last-Modified: '.gmdate('D, d M Y H:i:s', $fstat['mtime']).' GMT'); 
    277 header('Expires: '.gmdate('D, d M Y H:i:s', time()+10*24*3600).' GMT'); 
    278 header('Content-length: '.$fstat['size']); 
    279 header('Connection: close'); 
    280  
    281 $ctype="application/octet-stream"; 
    282 switch (strtolower($page['derivative_ext'])) 
    283 { 
    284   case ".jpe": case ".jpeg": case ".jpg": $ctype="image/jpeg"; break; 
    285   case ".png": $ctype="image/png"; break; 
    286   case ".gif": $ctype="image/gif"; break; 
    287 } 
    288 header("Content-Type: $ctype"); 
    289  
    290 fpassthru($fp); 
    291 fclose($fp); 
     307send_derivative($expires); 
    292308?> 
  • trunk/include/derivative_params.inc.php

    r12797 r12820  
    279279 
    280280/*how we generate a derivative image*/ 
    281 final class ImageParams 
     281final class DerivativeParams 
    282282{ 
    283283  public $type = IMG_CUSTOM; 
     
    290290  } 
    291291 
     292  public function __sleep() 
     293  { 
     294      return array('last_mod_time', 'sizing'); 
     295  } 
     296     
    292297  function add_url_tokens(&$tokens) 
    293298  { 
     
    298303  { 
    299304    $sizing = SizingParams::from_url_tokens($tokens); 
    300     $ret = new ImageParams($sizing); 
     305    $ret = new DerivativeParams($sizing); 
    301306    return $ret; 
    302307  } 
  • trunk/include/derivative_std_params.inc.php

    r12796 r12820  
    3535  private static $type_map = array(); 
    3636  private static $undefined_type_map = array(); 
    37    
     37 
    3838  static function get_all_types() 
    3939  { 
    4040    return self::$all_types; 
    4141  } 
    42    
     42 
    4343  static function get_all_type_map() 
    4444  { 
     
    5555    return self::$undefined_type_map; 
    5656  } 
    57    
     57 
    5858  static function get_by_type($type) 
    5959  { 
    6060    return self::$all_type_map[$type]; 
    6161  } 
    62    
     62 
    6363  static function load_from_db() 
    6464  { 
    65     self::make_default(); 
     65    global $conf; 
     66    $arr = @unserialize($conf['derivatives']); 
     67    if (false!==$arr) 
     68    { 
     69      self::$type_map = $arr['d']; 
     70    } 
     71    else 
     72    { 
     73      self::make_default(); 
     74    } 
    6675    self::build_maps(); 
    6776  } 
     
    6978  static function load_from_file() 
    7079  { 
    71     self::make_default(); 
     80    global $conf; 
     81    $arr = @unserialize(@file_get_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat')); 
     82    if (false!==$arr) 
     83    { 
     84      self::$type_map = $arr['d']; 
     85    } 
     86    else 
     87    { 
     88      self::make_default(); 
     89    } 
     90    self::build_maps(); 
     91  } 
     92 
     93  static function set_and_save($map) 
     94  { 
     95    global $conf; 
     96    self::$type_map = $map; 
     97 
     98    $ser = serialize( array( 
     99      'd' => self::$type_map 
     100      ) ); 
     101    conf_update_param('derivatives', addslashes($ser) ); 
     102    file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat', $ser); 
    72103    self::build_maps(); 
    73104  } 
     
    75106  static function make_default() 
    76107  { 
    77     //todo 
    78     self::$type_map[IMG_SQUARE] = new ImageParams( SizingParams::square(100,100) ); 
    79     self::$type_map[IMG_THUMB] = new ImageParams( SizingParams::classic(144,144) ); 
    80     self::$type_map[IMG_SMALL] = new ImageParams( SizingParams::classic(240,240) ); 
    81     self::$type_map[IMG_MEDIUM] = new ImageParams( SizingParams::classic(432,432) ); 
    82     self::$type_map[IMG_LARGE] = new ImageParams( SizingParams::classic(648,576) ); 
    83     self::$type_map[IMG_XLARGE] = new ImageParams( SizingParams::classic(864,648) ); 
    84     self::$type_map[IMG_XXLARGE] = new ImageParams( SizingParams::classic(1200,900) ); 
     108    self::$type_map[IMG_SQUARE] = new DerivativeParams( SizingParams::square(100,100) ); 
     109    self::$type_map[IMG_THUMB] = new DerivativeParams( SizingParams::classic(144,144) ); 
     110    self::$type_map[IMG_SMALL] = new DerivativeParams( SizingParams::classic(240,240) ); 
     111    self::$type_map[IMG_MEDIUM] = new DerivativeParams( SizingParams::classic(432,432) ); 
     112    self::$type_map[IMG_LARGE] = new DerivativeParams( SizingParams::classic(648,576) ); 
     113    self::$type_map[IMG_XLARGE] = new DerivativeParams( SizingParams::classic(864,648) ); 
     114    self::$type_map[IMG_XXLARGE] = new DerivativeParams( SizingParams::classic(1200,900) ); 
    85115  } 
    86    
     116 
    87117  private static function build_maps() 
    88118  { 
     
    111141    } 
    112142  } 
    113    
     143 
    114144} 
    115145 
  • trunk/language/en_UK/common.lang.php

    r12693 r12820  
    363363$lang['Your Gallery Customization'] = "Your gallery customization"; 
    364364$lang['Your password has been reset'] = 'Your password has been reset'; 
    365  
     365$lang['square'] = "Square"; 
     366$lang['thumb'] = "Thumb"; 
     367$lang['small'] = "Small"; 
     368$lang['medium'] = "Medium"; 
     369$lang['large'] = "Large"; 
     370$lang['xlarge'] = "XLarge"; 
     371$lang['xxlarge'] = "XXLarge"; 
     372$lang['original'] = "Original"; 
    366373?> 
Note: See TracChangeset for help on using the changeset viewer.