Changeset 13021
- Timestamp:
- Feb 2, 2012, 9:59:41 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/derivatives.php
r12922 r13021 215 215 if (isset($enabled[$type])) 216 216 {// now disabled, before was enabled 217 $changed_types[] = $type; 217 218 $disabled[$type] = $enabled[$type]; 218 219 unset($enabled[$type]); -
trunk/admin/include/functions.php
r13013 r13021 203 203 204 204 $ok = true; 205 foreach ($files as $path) 206 { 207 if (is_file($path) and !unlink($path)) 208 { 209 $ok = false; 210 trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING); 211 break; 212 } 213 } 205 if (!isset($conf['never_delete_originals'])) 206 { 207 foreach ($files as $path) 208 { 209 if (is_file($path) and !unlink($path)) 210 { 211 $ok = false; 212 trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING); 213 break; 214 } 215 } 216 } 214 217 215 218 if ($ok) -
trunk/admin/themes/default/template/derivatives_build.tpl
r12865 r13021 45 45 {footer_script require='jquery.effects.slide'}{literal} 46 46 47 var loader = new ImageLoader( {onChanged: loaderChanged } )47 var loader = new ImageLoader( {onChanged: loaderChanged, maxRequests:1 } ) 48 48 , pending_next_page = null 49 49 , last_image_show_time = 0 -
trunk/i.php
r12958 r13021 66 66 function ilog() 67 67 { 68 global $conf , $ilogfh;68 global $conf; 69 69 if (!$conf['enable_i_log']) return; 70 if(!$ilogfh) 71 { 72 $dir=PHPWG_ROOT_PATH.$conf['data_location'].'tmp/'; 73 if (!mkgetdir($dir) or ! ($ilogfh=fopen($dir.'i.log', 'a')) ) 74 return; 75 } 70 76 71 $line = date("c"); 77 72 foreach( func_get_args() as $arg) … … 87 82 } 88 83 } 89 fwrite($ilogfh, $line."\n"); 84 $file=PHPWG_ROOT_PATH.$conf['data_location'].'tmp/i.log'; 85 if (false == file_put_contents($file, $line."\n", FILE_APPEND)) 86 { 87 mkgetdir(dirname($file)); 88 } 90 89 } 91 90 … … 125 124 } 126 125 126 function url_to_size($s) 127 { 128 $pos = strpos($s, 'x'); 129 if ($pos===false) 130 { 131 return array((int)$s, (int)$s); 132 } 133 return array((int)substr($s,0,$pos), (int)substr($s,$pos+1)); 134 } 135 136 function parse_custom_params($tokens) 137 { 138 if (count($tokens)<1) 139 ierror('Empty array while parsing Sizing', 400); 140 141 $crop = 0; 142 $min_size = null; 143 144 $token = array_shift($tokens); 145 if ($token[0]=='s') 146 { 147 $size = url_to_size( substr($token,1) ); 148 } 149 elseif ($token[0]=='e') 150 { 151 $crop = 1; 152 $size = $min_size = url_to_size( substr($token,1) ); 153 } 154 else 155 { 156 $size = url_to_size( $token ); 157 if (count($tokens)<2) 158 ierror('Sizing arr', 400); 159 160 $token = array_shift($tokens); 161 $crop = char_to_fraction($token); 162 163 $token = array_shift($tokens); 164 $min_size = url_to_size( $token ); 165 } 166 return new DerivativeParams( new SizingParams($size, $crop, $min_size) ); 167 } 168 127 169 function parse_request() 128 170 { … … 200 242 if ($page['derivative_type'] == IMG_CUSTOM) 201 243 { 202 try 203 { 204 $params = $page['derivative_params'] = DerivativeParams::from_url_tokens($deriv); 205 } 206 catch (Exception $e) 207 { 208 ierror($e->getMessage(), 400); 209 } 244 $params = $page['derivative_params'] = parse_custom_params($deriv); 245 210 246 if ($params->sizing->ideal_size[0] < 20 or $params->sizing->ideal_size[1] < 20) 211 247 { … … 215 251 { 216 252 ierror('Invalid crop', 400); 253 } 254 $greatest = ImageStdParams::get_by_type(IMG_XXLARGE); 255 if ($params->max_width() > $greatest->max_width() || $params->max_height() > $greatest->max_height()) 256 { 257 ierror('Too big', 403); 258 } 259 260 $key = array(); 261 $params->add_url_tokens($key); 262 $key = implode('_', $key); 263 if (!isset(ImageStdParams::$custom[$key])) 264 { 265 ierror('Size not allowed', 403); 217 266 } 218 267 } -
trunk/include/derivative_params.inc.php
r12908 r13021 34 34 } 35 35 36 function url_to_size($s)37 {38 $pos = strpos($s, 'x');39 if ($pos===false)40 {41 return array((int)$s, (int)$s);42 }43 return array((int)substr($s,0,$pos), (int)substr($s,$pos+1));44 }45 46 36 function size_equals($s1, $s2) 47 37 { … … 49 39 } 50 40 41 function char_to_fraction($c) 42 { 43 return (ord($c) - ord('a'))/25; 44 } 45 46 function fraction_to_char($f) 47 { 48 return ord('a') + round($f*25); 49 } 51 50 52 51 /** small utility to manipulate a 'rectangle'*/ … … 80 79 if (!empty($coi)) 81 80 { 82 $coil = floor($this->r * (ord($coi[0]) - ord('a'))/25);83 $coir = ceil($this->r * (ord($coi[2]) - ord('a'))/25);81 $coil = floor($this->r * char_to_fraction($coi[0])); 82 $coir = ceil($this->r * char_to_fraction($coi[2])); 84 83 $availableL = $coil > $this->l ? $coil - $this->l : 0; 85 84 $availableR = $coir < $this->r ? $this->r - $coir : 0; … … 116 115 if (!empty($coi)) 117 116 { 118 $coit = floor($this->b * (ord($coi[1]) - ord('a'))/25);119 $coib = ceil($this->b * (ord($coi[3]) - ord('a'))/25);117 $coit = floor($this->b * char_to_fraction($coi[1])); 118 $coib = ceil($this->b * char_to_fraction($coi[3])); 120 119 $availableT = $coit > $this->t ? $coit - $this->t : 0; 121 120 $availableB = $coib < $this->b ? $this->b - $coib : 0; … … 180 179 { 181 180 $tokens[] = size_to_url($this->ideal_size); 182 $tokens[] = sprintf('%02x', round(100*$this->max_crop));181 $tokens[] = fraction_to_char($this->max_crop); 183 182 $tokens[] = size_to_url($this->min_size); 184 183 } 185 184 } 186 187 static function from_url_tokens($tokens)188 {189 if (count($tokens)<1)190 throw new Exception('Empty array while parsing Sizing');191 $token = array_shift($tokens);192 if ($token[0]=='s')193 {194 return new SizingParams( url_to_size( substr($token,1) ) );195 }196 if ($token[0]=='e')197 {198 $s = url_to_size( substr($token,1) );199 return new SizingParams($s, 1, $s);200 }201 202 $ideal_size = url_to_size( $token );203 if (count($tokens)<2)204 throw new Exception('Sizing arr');205 206 $token = array_shift($tokens);207 $crop = hexdec($token) / 100;208 209 $token = array_shift($tokens);210 $min_size = url_to_size( $token );211 return new SizingParams($ideal_size, $crop, $min_size);212 }213 214 185 215 186 function compute($in_size, $coi, &$crop_rect, &$scale_size) … … 303 274 } 304 275 305 static function from_url_tokens($tokens)306 {307 $sizing = SizingParams::from_url_tokens($tokens);308 $ret = new DerivativeParams($sizing);309 return $ret;310 }311 312 276 function compute_final_size($in_size, $coi) 313 277 { -
trunk/include/derivative_std_params.inc.php
r12851 r13021 47 47 private static $undefined_type_map = array(); 48 48 private static $watermark; 49 public static $custom = array(); 49 50 50 51 static function get_all_types() … … 71 72 { 72 73 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; 73 90 } 74 91 … … 104 121 self::$watermark = @$arr['w']; 105 122 if (!self::$watermark) self::$watermark = new WatermarkParams(); 123 self::$custom = @$arr['c']; 124 if (!self::$custom) self::$custom = array(); 106 125 } 107 126 else … … 119 138 static function set_and_save($map) 120 139 { 140 self::$type_map = $map; 141 self::save(); 142 self::build_maps(); 143 } 144 145 static function save() 146 { 121 147 global $conf; 122 self::$type_map = $map;123 148 124 149 $ser = serialize( array( 125 150 'd' => self::$type_map, 126 151 'w' => self::$watermark, 152 'c' => self::$custom, 127 153 ) ); 128 154 conf_update_param('derivatives', addslashes($ser) ); 129 155 file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat', $ser); 130 self::build_maps();131 156 } 132 157 … … 143 168 } 144 169 145 publicstatic function apply_global($params)170 static function apply_global($params) 146 171 { 147 172 if (!empty(self::$watermark->file) && -
trunk/include/picture_comment.inc.php
r12922 r13021 127 127 { 128 128 // comments order (get, session, conf) 129 if (!empty($_GET['comments_order']) )129 if (!empty($_GET['comments_order']) && in_array(strtoupper($_GET['comments_order']), array('ASC', 'DESC'))) 130 130 { 131 if (in_array(strtoupper($_GET['comments_order']), array('ASC', 'DESC'))) 132 { 133 $comments_order = $_GET['comments_order']; 134 pwg_set_session_var('comments_order', $comments_order); 135 } 136 else 137 { 138 $comments_order = $conf['comments_order']; 139 } 131 pwg_set_session_var('comments_order', $_GET['comments_order']); 140 132 } 141 else if (pwg_get_session_var('comments_order') !== null) 142 { 143 $comments_order = pwg_get_session_var('comments_order'); 144 } 145 else 146 { 147 $comments_order = $conf['comments_order']; 148 } 133 $comments_order = pwg_get_session_var('comments_order', $conf['comments_order']); 134 149 135 $template->assign(array( 150 136 'COMMENTS_ORDER_URL' => duplicate_picture_url().'&comments_order='.($comments_order == 'ASC' ? 'DESC' : 'ASC'), -
trunk/include/template.class.php
r12955 r13021 560 560 !empty($params['height']) or fatal_error('define_derviative missing height'); 561 561 562 $derivative = new DerivativeParams( SizingParams::classic( intval($params['width']), intval($params['height'])) ); 562 $w = intval($params['width']); 563 $h = intval($params['height']); 564 $crop = 0; 565 $minw=null; 566 $minh=null; 567 563 568 if (isset($params['crop'])) 564 569 { 565 570 if (is_bool($params['crop'])) 566 571 { 567 $ derivative->sizing->max_crop = $params['crop'] ? 1:0;572 $crop = $params['crop'] ? 1:0; 568 573 } 569 574 else 570 575 { 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); 576 $crop = round($params['crop']/100, 2); 577 } 578 579 if ($crop) 580 { 581 $minw = empty($params['min_width']) ? $w : intval($params['min_width']); 582 $minw <= $w or fatal_error('define_derviative invalid min_width'); 583 $minh = empty($params['min_height']) ? $h : intval($params['min_height']); 584 $minh <= $h or fatal_error('define_derviative invalid min_height'); 585 } 586 } 587 588 $smarty->assign( $params['name'], ImageStdParams::get_custom($w, $h, $crop, $minw, $minh) ); 587 589 } 588 590 -
trunk/themes/default/template/picture.tpl
r12894 r13021 279 279 {if $COMMENT_COUNT > 0} 280 280 <h3>{$pwg->l10n_dec('%d comment', '%d comments',$COMMENT_COUNT)}</h3> 281 { /if}282 {if $COMMENT_COUNT > 2} 283 {'Sort order'|@translate} : <a href="{$COMMENTS_ORDER_URL}#comments">{$COMMENTS_ORDER_TITLE}</a> 284 281 {if $COMMENT_COUNT > 2} 282 {'Sort order'|@translate}: <a href="{$COMMENTS_ORDER_URL}#comments" rel="nofollow">{$COMMENTS_ORDER_TITLE}</a> 283 {/if} 284 {/if} 285 285 {if !empty($navbar)}{include file='navigation_bar.tpl'|@get_extent:'navbar'}{/if} 286 286
Note: See TracChangeset
for help on using the changeset viewer.