http://piwigo.cumulodata.com define('DYN_NAME', 'Dynamic Resize'); define('DYN_PATH', dirname(__FILE__)); // /home/piwigo/webapp/web/plugin/dynamicResize define('DYN_ROOT' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__))); // ./plugin/dynamicResize define('ROOT_PATH','/home/piwigo/webapp/web/'); define('PATH', ROOT_URL.DYN_ROOT); //load_language('plugin.lang', DYN_ROOT); include_once DYN_ROOT.'/DynamicResize.class.php'; $obj = new DynamicResize(); $obj->load_config(); $debug_mode=0; $dyn_mode=1; //load in flow, with cookie setting //$dyn_mode=2; // load in XHR, wait for 2nd picture. //NOT_USED// add_event_handler('loc_begin_picture','dynamic_resize_picture_content',50,2); add_event_handler('render_element_content','dynamic_resize_picture_content',60 ,2); // this is the custom handler that generates the display for the element function dynamic_resize_picture_content($content, $element_info){ global $conf, $template,$debug_mode, $dyn_mode,$next_srcimg,$new_srcimg,$new_next_srcimg; $dyn_mode=1; $debug_mode=0; // $conf['dynamicResize'] = explode(',', $conf['dynamicResize']); // $debug_mode = $conf[0]; // echo 'debug Mode'.$debug_mode; //echo 'dyn_mode:'.$dyn_mode; //NOT_USED//$template->set_prefilter('picture', 'dynamicResizeXHR'); $srcimg = $template->get_template_vars('SRC_IMG'); $next = $template->get_template_vars('next'); $current = $template->get_template_vars('current'); $new_srcimg=''; //@todo:deal with alternative methods // $dynamic_srcimg = DYN_ROOT.'/resize.php?picture_url='.$srcimg; // $dynamic_srcimg= DYN_ROOT.'/slir/w801-h553/'.$srcimg; $template->set_filenames(array('dynamicresize' => DYN_PATH . '/dynamic_resize.tpl')); $template->assign(array( 'DYN_ROOT' => DYN_ROOT, 'ROOT_URL' => ROOT_URL, )); if($dyn_mode==1){ //FLOW MODE //autosize plugin if (isset($_COOKIE["dynamic_width"])) { $max_width=$_COOKIE["dynamic_width"];} if (isset($_COOKIE["dynamic_height"])) { $max_height=$_COOKIE["dynamic_height"];} //stripped plugin if (isset($_COOKIE["stripped_max_width"])) { $max_width=$_COOKIE["stripped_max_width"];} if (isset($_COOKIE["stripped_max_height"])) { $max_height=$_COOKIE["stripped_max_height"];} $img_W0=$current['width']; $img_H0=$current['height']; $img_ratio=$img_W0/$img_H0; if($debug_mode){ echo 'pic :'.$img_W0.'x'.$img_H0.'
'; } if(isset($max_width) && isset($max_height)){ if($debug_mode){ echo 'max size :'.$max_width.'x'.$max_height.'
'; } if ($img_H0 >= $max_height) { $dynamic_height=$max_height; }else{ $dynamic_height=$img_H0; } //TODO // if (img_H <= Hmin) img_H=Hmin; $dynamic_width = round($dynamic_height * $img_ratio); if ($dynamic_width > $max_width) { $dynamic_height = round($max_width / $img_ratio); //if (img_H <= Hmin) { // img_H = Hmin; // img_W = parseInt(img_H * img_ratio); //} else { $dynamic_width = $max_width; //} } if($debug_mode){ echo 'computed size pic :'.$dynamic_width.'x'.$dynamic_height.'
'; } //FOR PREFETCHING $isNext = isset($next) && isset($next['image_url']) && isset($next['width']) && isset($next['height']); if($isNext){ //NEXT PICTURE URL if(substr($next['image_url'],0,1)=='.') { $next_srcimg = substr($next['image_url'],1); }else{ $next_srcimg = $next['image_url']; } if($debug_mode){ echo 'next pic image url : '.$next_srcimg.'
'; } //NEXT PICTURE SIZE $next_W0=$next['width']; $next_H0=$next['height']; //print_r($next); $next_ratio = $next_W0/$next_H0; if($debug_mode){ echo 'next pic :'.$next_W0.'x'.$next_H0.'
'; } if ($next_H0 >= $max_height) { $next_dynamic_height=$max_height; }else{ $next_dynamic_height=$img_H0; } //TODO // if (img_H <= Hmin) img_H=Hmin; $next_dynamic_width = round($next_dynamic_height * $next_ratio); if ($next_dynamic_width > $max_width) { $next_dynamic_height = round($max_width / $next_ratio); //if (img_H <= Hmin) { // img_H = Hmin; //img_W = parseInt(img_H * img_ratio); //} else { $next_dynamic_width = $max_width; // } } if($debug_mode){ echo 'next pic computed size:'.$next_dynamic_width.'x'.$next_dynamic_height.'
'; } } //height could be wrong on chrome, see http://bugs.jquery.com/ticket/7427 }else{ if($debug_mode) echo 'no max_width or height info available, downloading original size
'; } //GETTING PICTURE URL if(isset($dynamic_width) && isset($dynamic_height)){ //@todo: deal with alternative methods if(substr($srcimg,0,1)=='.'){ $srcimg = substr($srcimg,1);} //remove leading '.' from path $new_srcimg = DYN_ROOT.'/slir/'.'w'.$dynamic_width.'-h'.$dynamic_height.$srcimg; if($isNext){ if(substr($next['image_url'],0,1)=='.') { $next_srcimg = substr($next['image_url'],1); }else{ $next_srcimg = $next['image_url']; } $new_next_srcimg = DYN_ROOT.'/slir/'.'w'.$next_dynamic_width.'-h'.$next_dynamic_height.$next_srcimg; } $template->assign('DYN_MODE', 'FLOW'); }else{ //get the original picture $new_srcimg = $srcimg; if(isset($next)) { $new_next_srcimg = $next_srcimg; } $template->assign('DYN_MODE', 'FLOW0'); } }else if ($dyn_mode==2){ //XHR MODE $new_srcimg = DYN_ROOT.'/images/spacer.gif'; $template->assign('DYN_MODE', 'XHR'); //@todo : deal with alternative methods //$template->assign('DYNAMIC_SRC_IMG', $dynamic_srcimg); $template->assign('DYNAMIC_SRC_IMG', $srcimg); }else{ $new_srcimg = $srcimg; $template->assign('DYN_MODE', 'STD'); if($debug_mode) echo 'Warning, mode should be 1 or 2. doing nothing'; } if(isset($next)){ $template->assign('NEXT',$next); $template->assign('NEXT_SRC_IMG',$new_next_srcimg); } $template->parse('dynamicresize',false); $template->assign('SRC_IMG', $new_srcimg); return $template->parse('default_content',true); } //Ajout du prefiltre /* add_event_handler('loc_begin_picture', 'dynamicResizePF', 65 ); function dynamicResizePF() { $path = get_root_url().'plugins/'. basename(dirname(__FILE__)).'/'; global $template; $srcimg = $template->get_template_vars('SRC_IMG'); $template->append('head_elements', ' ' ); } */ if($debug_mode==1 && $dyn_mode==2){ echo '
Clickme to fire ret_autosize
'; } ?>