- Timestamp:
- Jan 24, 2012, 8:24:47 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/cat_modify.php
r12922 r12954 29 29 include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 30 30 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/" 37 function 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/" 46 function 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/" 87 function get_site_url($category_id) 88 { 89 global $page; 90 91 $query = ' 92 SELECT 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 31 101 // +-----------------------------------------------------------------------+ 32 102 // | Check Access and exit when user status is not ok | -
trunk/include/derivative.inc.php
r12908 r12954 25 25 const IS_MIMETYPE = 0x02; 26 26 27 public $id; 27 28 public $rel_path; 28 29 … … 34 35 { 35 36 global $conf; 36 37 38 $this->id = $infos['id']; 37 39 $ext = get_extension($infos['path']); 38 40 if (in_array($ext, $conf['picture_ext'])) … … 77 79 function get_url() 78 80 { 79 return get_root_url().$this->rel_path;81 return embellish_url(get_root_url().$this->rel_path); 80 82 } 81 83 … … 97 99 final class DerivativeImage 98 100 { 99 const SAME_AS_SRC = 0x10;100 101 101 public $src_image; 102 102 103 private $flags = 0;104 103 private $params; 105 104 private $rel_path, $rel_url; … … 117 116 } 118 117 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); 120 119 } 121 120 … … 130 129 $params = is_string($type) ? ImageStdParams::get_by_type($type) : $type; 131 130 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 ) ); 133 140 } 134 141 … … 149 156 } 150 157 151 private static function build($src, &$params, &$rel_path, &$rel_url , &$flags = null)158 private static function build($src, &$params, &$rel_path, &$rel_url) 152 159 { 153 160 if ( $src->has_size() && $params->is_identity( $src->get_size() ) ) 154 161 { 155 162 // todo - what if we have a watermark maybe return a smaller size? 156 $flags |= self::SAME_AS_SRC;157 163 $params = null; 158 164 $rel_path = $rel_url = $src->rel_path; … … 221 227 function get_url() 222 228 { 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 ) ); 224 238 } 225 239 226 240 function same_as_source() 227 241 { 228 return $this-> flags & self::SAME_AS_SRC;242 return $this->params == null; 229 243 } 230 244 … … 232 246 function get_type() 233 247 { 234 if ($this-> flags & self::SAME_AS_SRC)248 if ($this->params == null) 235 249 return 'original'; 236 250 return $this->params->type; … … 240 254 function get_size() 241 255 { 242 if ($this-> flags & self::SAME_AS_SRC)256 if ($this->params == null) 243 257 { 244 258 return $this->src_image->get_size(); -
trunk/include/functions.inc.php
r12920 r12954 779 779 function get_thumbnail_url($element_info) 780 780 { 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); 789 782 } 790 783 -
trunk/include/functions_category.inc.php
r12922 r12954 214 214 } 215 215 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 284 217 285 218 // returns an array of image orders available for users/visitors -
trunk/include/template.class.php
r12920 r12954 115 115 $this->smarty->register_function('get_combined_scripts', array(&$this, 'func_get_combined_scripts') ); 116 116 $this->smarty->register_function('combine_css', array(&$this, 'func_combine_css') ); 117 $this->smarty->register_function('define_derivative', array(&$this, 'func_define_derivative') ); 117 118 $this->smarty->register_compiler_function('get_combined_css', array(&$this, 'func_get_combined_css') ); 118 119 $this->smarty->register_block('footer_script', array(&$this, 'block_footer_script') ); … … 545 546 $this->html_style .= $content; 546 547 } 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); 547 587 } 548 588 -
trunk/themes/default/template/thumbnails.tpl
r12920 r12954 1 1 {if !empty($thumbnails)}{strip} 2 {*define_derivative name='derivative_params' width=160 height=90 crop=true*} 2 3 {html_style} 3 4 {*Set some sizes according to maximum thumbnail width and height*}
Note: See TracChangeset
for help on using the changeset viewer.