Ignore:
Timestamp:
Feb 2, 2012, 9:59:41 PM (12 years ago)
Author:
rvelices
Message:

feature 2548 multisize - custom sizes restricted to those requested by theme/plugin
code refacto

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/derivative_std_params.inc.php

    r12851 r13021  
    4747  private static $undefined_type_map = array();
    4848  private static $watermark;
     49  public static $custom = array();
    4950
    5051  static function get_all_types()
     
    7172  {
    7273    return self::$all_type_map[$type];
     74  }
     75 
     76  static function get_custom($w, $h, $crop=0, $minw=null, $minh=null)
     77  {
     78    $params = new DerivativeParams( new SizingParams( array($w,$h), $crop, array($minw,$minh)) );
     79    self::apply_global($params);
     80
     81    $key = array();
     82    $params->add_url_tokens($key);
     83    $key = implode('_',$key);
     84    if ( @self::$custom[$key] < time() - 24*3600)
     85    {
     86      self::$custom[$key] = time();
     87      self::save();
     88    }
     89    return $params;
    7390  }
    7491
     
    104121      self::$watermark = @$arr['w'];
    105122      if (!self::$watermark) self::$watermark = new WatermarkParams();
     123      self::$custom = @$arr['c'];
     124      if (!self::$custom) self::$custom = array();
    106125    }
    107126    else
     
    119138  static function set_and_save($map)
    120139  {
     140    self::$type_map = $map;
     141    self::save();
     142    self::build_maps();
     143  }
     144
     145  static function save()
     146  {
    121147    global $conf;
    122     self::$type_map = $map;
    123148
    124149    $ser = serialize( array(
    125150      'd' => self::$type_map,
    126151      'w' => self::$watermark,
     152      'c' => self::$custom,
    127153      ) );
    128154    conf_update_param('derivatives', addslashes($ser) );
    129155    file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat', $ser);
    130     self::build_maps();
    131156  }
    132157
     
    143168  }
    144169
    145   public static function apply_global($params)
     170  static function apply_global($params)
    146171  {
    147172    if (!empty(self::$watermark->file) &&
Note: See TracChangeset for help on using the changeset viewer.