Changeset 12954 for trunk


Ignore:
Timestamp:
Jan 24, 2012, 8:24:47 PM (12 years ago)
Author:
rvelices
Message:

feature 2548 multisize

  • added define_derivative template functiion for themes and plugins
  • code cleanup, new events ...
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_modify.php

    r12922 r12954  
    2929include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
    3030
     31
     32// get_complete_dir returns the concatenation of get_site_url and
     33// get_local_dir
     34// Example : "pets > rex > 1_year_old" is on the the same site as the
     35// Piwigo files and this category has 22 for identifier
     36// get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/"
     37function get_complete_dir( $category_id )
     38{
     39  return get_site_url($category_id).get_local_dir($category_id);
     40}
     41
     42// get_local_dir returns an array with complete path without the site url
     43// Example : "pets > rex > 1_year_old" is on the the same site as the
     44// Piwigo files and this category has 22 for identifier
     45// get_local_dir(22) returns "pets/rex/1_year_old/"
     46function get_local_dir( $category_id )
     47{
     48  global $page;
     49
     50  $uppercats = '';
     51  $local_dir = '';
     52
     53  if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) )
     54  {
     55    $uppercats = $page['plain_structure'][$category_id]['uppercats'];
     56  }
     57  else
     58  {
     59    $query = 'SELECT uppercats';
     60    $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
     61    $query.= ';';
     62    $row = pwg_db_fetch_assoc( pwg_query( $query ) );
     63    $uppercats = $row['uppercats'];
     64  }
     65
     66  $upper_array = explode( ',', $uppercats );
     67
     68  $database_dirs = array();
     69  $query = 'SELECT id,dir';
     70  $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
     71  $query.= ';';
     72  $result = pwg_query( $query );
     73  while( $row = pwg_db_fetch_assoc( $result ) )
     74  {
     75    $database_dirs[$row['id']] = $row['dir'];
     76  }
     77  foreach ($upper_array as $id)
     78  {
     79    $local_dir.= $database_dirs[$id].'/';
     80  }
     81
     82  return $local_dir;
     83}
     84
     85// retrieving the site url : "http://domain.com/gallery/" or
     86// simply "./galleries/"
     87function get_site_url($category_id)
     88{
     89  global $page;
     90
     91  $query = '
     92SELECT galleries_url
     93  FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c
     94  WHERE s.id = c.site_id
     95    AND c.id = '.$category_id.'
     96;';
     97  $row = pwg_db_fetch_assoc(pwg_query($query));
     98  return $row['galleries_url'];
     99}
     100
    31101// +-----------------------------------------------------------------------+
    32102// | Check Access and exit when user status is not ok                      |
  • trunk/include/derivative.inc.php

    r12908 r12954  
    2525  const IS_MIMETYPE = 0x02;
    2626
     27  public $id;
    2728  public $rel_path;
    2829
     
    3435  {
    3536    global $conf;
    36 
     37   
     38    $this->id = $infos['id'];
    3739    $ext = get_extension($infos['path']);
    3840    if (in_array($ext, $conf['picture_ext']))
     
    7779  function get_url()
    7880  {
    79     return get_root_url().$this->rel_path;
     81    return embellish_url(get_root_url().$this->rel_path);
    8082  }
    8183
     
    9799final class DerivativeImage
    98100{
    99   const SAME_AS_SRC = 0x10;
    100 
    101101  public $src_image;
    102102
    103   private $flags = 0;
    104103  private $params;
    105104  private $rel_path, $rel_url;
     
    117116    }
    118117
    119     self::build($src_image, $this->params, $this->rel_path, $this->rel_url, $this->flags);
     118    self::build($src_image, $this->params, $this->rel_path, $this->rel_url);
    120119  }
    121120
     
    130129    $params = is_string($type) ? ImageStdParams::get_by_type($type) : $type;
    131130    self::build($src_image, $params, $rel_path, $rel_url);
    132     return get_root_url().$rel_url;
     131    if ($params == null)
     132    {
     133      return $src_image->get_url();
     134    }
     135    return embellish_url(
     136        trigger_event('get_derivative_url',
     137          get_root_url().$rel_url,
     138          $params, $src_image, $rel_url
     139          ) );
    133140  }
    134141
     
    149156  }
    150157
    151   private static function build($src, &$params, &$rel_path, &$rel_url, &$flags = null)
     158  private static function build($src, &$params, &$rel_path, &$rel_url)
    152159  {
    153160    if ( $src->has_size() && $params->is_identity( $src->get_size() ) )
    154161    {
    155162      // todo - what if we have a watermark maybe return a smaller size?
    156       $flags |= self::SAME_AS_SRC;
    157163      $params = null;
    158164      $rel_path = $rel_url = $src->rel_path;
     
    221227  function get_url()
    222228  {
    223     return get_root_url().$this->rel_url;
     229    if ($this->params == null)
     230    {
     231      return $this->src_image->get_url();
     232    }
     233    return embellish_url(
     234        trigger_event('get_derivative_url',
     235          get_root_url().$this->rel_url,
     236          $this->params, $this->src_image, $this->rel_url
     237          ) );
    224238  }
    225239
    226240  function same_as_source()
    227241  {
    228     return $this->flags & self::SAME_AS_SRC;
     242    return $this->params == null;
    229243  }
    230244
     
    232246  function get_type()
    233247  {
    234     if ($this->flags & self::SAME_AS_SRC)
     248    if ($this->params == null)
    235249      return 'original';
    236250    return $this->params->type;
     
    240254  function get_size()
    241255  {
    242     if ($this->flags & self::SAME_AS_SRC)
     256    if ($this->params == null)
    243257    {
    244258      return $this->src_image->get_size();
  • trunk/include/functions.inc.php

    r12920 r12954  
    779779function get_thumbnail_url($element_info)
    780780{
    781   $loc = $url = get_thumbnail_location($element_info);
    782   if ( !url_is_remote($loc) )
    783   {
    784     $url = (get_root_url().$loc);
    785   }
    786   // plugins want another url ?
    787   $url = trigger_event('get_thumbnail_url', $url, $element_info, $loc);
    788   return embellish_url($url);
     781  return DerivativeImage::thumb_url($element_info);
    789782}
    790783
  • trunk/include/functions_category.inc.php

    r12922 r12954  
    214214}
    215215
    216 // get_complete_dir returns the concatenation of get_site_url and
    217 // get_local_dir
    218 // Example : "pets > rex > 1_year_old" is on the the same site as the
    219 // Piwigo files and this category has 22 for identifier
    220 // get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/"
    221 function get_complete_dir( $category_id )
    222 {
    223   return get_site_url($category_id).get_local_dir($category_id);
    224 }
    225 
    226 // get_local_dir returns an array with complete path without the site url
    227 // Example : "pets > rex > 1_year_old" is on the the same site as the
    228 // Piwigo files and this category has 22 for identifier
    229 // get_local_dir(22) returns "pets/rex/1_year_old/"
    230 function get_local_dir( $category_id )
    231 {
    232   global $page;
    233 
    234   $uppercats = '';
    235   $local_dir = '';
    236 
    237   if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) )
    238   {
    239     $uppercats = $page['plain_structure'][$category_id]['uppercats'];
    240   }
    241   else
    242   {
    243     $query = 'SELECT uppercats';
    244     $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
    245     $query.= ';';
    246     $row = pwg_db_fetch_assoc( pwg_query( $query ) );
    247     $uppercats = $row['uppercats'];
    248   }
    249 
    250   $upper_array = explode( ',', $uppercats );
    251 
    252   $database_dirs = array();
    253   $query = 'SELECT id,dir';
    254   $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
    255   $query.= ';';
    256   $result = pwg_query( $query );
    257   while( $row = pwg_db_fetch_assoc( $result ) )
    258   {
    259     $database_dirs[$row['id']] = $row['dir'];
    260   }
    261   foreach ($upper_array as $id)
    262   {
    263     $local_dir.= $database_dirs[$id].'/';
    264   }
    265 
    266   return $local_dir;
    267 }
    268 
    269 // retrieving the site url : "http://domain.com/gallery/" or
    270 // simply "./galleries/"
    271 function get_site_url($category_id)
    272 {
    273   global $page;
    274 
    275   $query = '
    276 SELECT galleries_url
    277   FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c
    278   WHERE s.id = c.site_id
    279     AND c.id = '.$category_id.'
    280 ;';
    281   $row = pwg_db_fetch_assoc(pwg_query($query));
    282   return $row['galleries_url'];
    283 }
     216
    284217
    285218// returns an array of image orders available for users/visitors
  • trunk/include/template.class.php

    r12920 r12954  
    115115    $this->smarty->register_function('get_combined_scripts', array(&$this, 'func_get_combined_scripts') );
    116116    $this->smarty->register_function('combine_css', array(&$this, 'func_combine_css') );
     117    $this->smarty->register_function('define_derivative', array(&$this, 'func_define_derivative') );
    117118    $this->smarty->register_compiler_function('get_combined_css', array(&$this, 'func_get_combined_css') );
    118119    $this->smarty->register_block('footer_script', array(&$this, 'block_footer_script') );
     
    545546      $this->html_style .= $content;
    546547    }
     548  }
     549
     550  function func_define_derivative($params, &$smarty)
     551  {
     552    !empty($params['name']) or fatal_error('define_derviative missing name');
     553    if (isset($params['type']))
     554    {
     555      $derivative = ImageStdParams::get_by_type($params['type']);
     556      $smarty->assign( $params['name'], $derivative);
     557      return;
     558    }
     559    !empty($params['width']) or fatal_error('define_derviative missing width');
     560    !empty($params['height']) or fatal_error('define_derviative missing height');
     561
     562    $derivative = new DerivativeParams( SizingParams::classic( intval($params['width']), intval($params['height'])) );
     563    if (isset($params['crop']))
     564    {
     565      if (is_bool($params['crop']))
     566      {
     567        $derivative->sizing->max_crop = $params['crop'] ? 1:0;
     568      }
     569      else
     570      {
     571        $derivative->sizing->max_crop = round($params['crop']/100, 2);
     572      }
     573
     574      if ($derivative->sizing->max_crop)
     575      {
     576        $minw = empty($params['min_width']) ? $derivative->max_width() : intval($params['min_width']);
     577        $minw <= $derivative->max_width() or fatal_error('define_derviative invalid min_width');
     578        $minh = empty($params['min_height']) ? $derivative->max_height() : intval($params['min_height']);
     579        $minh <= $derivative->max_height() or fatal_error('define_derviative invalid min_height');
     580
     581        $derivative->sizing->min_size = array($minw, $minh);
     582      }
     583    }
     584
     585    ImageStdParams::apply_global($derivative);
     586    $smarty->assign( $params['name'], $derivative);
    547587  }
    548588
  • trunk/themes/default/template/thumbnails.tpl

    r12920 r12954  
    11{if !empty($thumbnails)}{strip}
     2{*define_derivative name='derivative_params' width=160 height=90 crop=true*}
    23{html_style}
    34{*Set some sizes according to maximum thumbnail width and height*}
Note: See TracChangeset for help on using the changeset viewer.