source: extensions/Autosize/autosize.inc.php @ 22116

Last change on this file since 22116 was 22116, checked in by cljosse, 11 years ago

[extensions] Autosize update to piwigo 2.5

File size: 56.1 KB
RevLine 
[7375]1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// | Autosize                                                              |
5// +-----------------------------------------------------------------------+
6// | Copyright(C) 2010      cljosse                                        |
7// +-----------------------------------------------------------------------+
8// | This program is free software; you can redistribute it and/or modify  |
9// | it under the terms of the GNU General Public License as published by  |
10// | the Free Software Foundation                                          |
11// |                                                                       |
12// | This program is distributed in the hope that it will be useful, but   |
13// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
14// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
15// | General Public License for more details.                              |
16// |                                                                       |
17// | You should have received a copy of the GNU General Public License     |
18// | along with this program; if not, write to the Free Software           |
19// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
20// | USA.                                                                  |
21// +-----------------------------------------------------------------------+
[18823]22class autosize_ctrl {
[17503]23        /*********************************
24        * cl_autosize_admin
25        **********************************/
26        static public function cl_autosize_admin($menu)         {
27                global  $lang ;
28                array_push($menu, array('NAME' => 'Autosize',
29                'URL' => get_admin_plugin_menu_link(AUTOSIZE_PATH . 'admin/admin_autosize.php')));
30                return $menu;
31        } //function cl_autosize_admin
[18716]32
33
34/**************************
35*  autosize_calcContent   *
36**************************/
37 static public function autosize_calcContent($content,$element_info){
[19003]38   global $conf,$page, $template,$picture,$user; 
[19707]39  global $defined_types,$pictureSelType,$pictureMap ,$pictureDeriv ,$liste_type,$SRC_IMG;
[18716]40  global $autosize_parametres,$user_status;
41  global $infos_message,$error_message;
42    //==============================================================================
43  global $DEBUG_autosize;
[18823]44  if( isset($_GET['cl_debug']) && $_GET['cl_debug'] =='false') {
45      $DEBUG_autosize="";
46  }else{
[18735]47    $DEBUG_autosize = isset($_POST['cl_debug']) ? $_POST['cl_debug'] : "" ;
[18716]48    $DEBUG_autosize = isset($_GET['cl_debug']) ? $_GET['cl_debug'] :  $DEBUG_autosize ;
[18735]49    $DEBUG_autosize = isset($conf['cl_debug']) ? $conf['cl_debug']."," . $DEBUG_autosize : $DEBUG_autosize ;
[18716]50 //===============================================================
[18823]51}
52 if(preg_match("|event|", $DEBUG_autosize, $val))  $infos_message =  "autosize_calcContent, " ; 
[18716]53    $ma_page=isset($page['body_id'])?$page['body_id']:"" ; 
54   if ($ma_page !='thePicturePage') return ; 
[19744]55    $default_size =  $conf['derivative_default_size'];
56//============================================================
57self::get_cookies();
[19003]58    $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), array("Autosize","SelMaxi"));
[18716]59    if (count($types)==0){ 
60        include_once (AUTOSIZE_PATH.'maintain.inc.php');
61        if (isset($conf['cl_derivatives_sav']))  {   
62            plugin_deactivate() ;             
63        }   
64          plugin_activate(); 
65          unset (  $_COOKIE['autosize_reload']) ;
66    }
[19156]67    if(preg_match("|test|", $DEBUG_autosize, $val)) { 
[19844]68        $infos_message .= "#65 autosize_calcContent: <br>";
69        if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
[19156]70        $infos_message .=  "SESSION:"  . cl_print_var($_SESSION) ;
71        $infos_message .=  "COOKIE:"  . cl_print_var($_COOKIE) ;
72        $infos_message .=  "GET:"  . cl_print_var($_GET) ;
73        $infos_message .= "POST:"  . cl_print_var($_POST) ;
74        $infos_message .= "$pictureDeriv $pictureSelType $pictureMap ";
[19746]75      //  self::Fin_php ("#75: ".$DEBUG_autosize);
[19156]76 }
[19003]77    if(!isset($_COOKIE['picture_deriv'] )){
[19156]78        if(preg_match("|test_1|", $DEBUG_autosize, $val)) { 
[19746]79          $infos_message .= "not COOKIE['picture_deriv'] -> reload(): <br>";         
80          self::Fin_php("#80 autosize_calcContent:" . $DEBUG_autosize );
[19156]81        }
[19844]82        unset($_COOKIE['autosize_reload']);
83    } 
84    if (!isset($_COOKIE['autosize_reload'])  ){ 
85        if(preg_match("|test_2|", $DEBUG_autosize, $val)) { 
86          $infos_message .= "not COOKIE['autosize_reload'] -> reload(): <br>";           
87          self::Fin_php("#87 autosize_calcContent:" . $DEBUG_autosize);
[19156]88        }
[19844]89          self::reload("#89");
90      //  self::Fin_php("#90 autosize_calcContent:" + $DEBUG_autosize);
[18823]91
[18716]92    } 
93//===================================================================
94  $current = $template->get_template_vars('current'); 
95  if (!isset($current)) return ; 
96//===============================================================
97    global $imgSizeWH;
98    $derivative = $current['src_image'] ;
99    $imgSizeWH = $derivative->get_size();
100    $SRC_IMG    = $derivative->get_url(); 
[18949]101
[18716]102    $picture['current']['scaled_width']=$imgSizeWH[0];
103    $picture['current']['scaled_height']= $imgSizeWH[1];
104    $picture['current']['high_url']= $SRC_IMG;   
105    $picture['current']['image_url']=$SRC_IMG; 
[18949]106    $picture['current']['thumbnail']=$SRC_IMG;
107
[18716]108//==============================================================
109    $autosize_parametres = cl_autosize_Get_Options();
110   return false ;
111 }//calc_content ;
112
113
114
[17503]115/*********************
116* INIT
117*********************/
[19844]118static public function init_3(){
119 
120}
[19764]121static public function init_1($content, $image)
122                {
123                  global $conf, $template, $page;   
124       if(!isset($conf['AS_panorama'])) return $content; 
[22116]125                if(  !is_array($conf['AS_panorama']) ){
126                return $content;
127        }
128         $asp = & $conf['AS_panorama'];                   
129      if(!isset($asp['in_mode_360'])) $asp['in_mode_360']="";
130      if(!isset($asp['in_mode_180'])) $asp['in_mode_180']="";
131     
[19764]132       if ( !stristr($image['name'], $asp['in_mode_360']) and !stristr($image['name'], $asp['in_mode_180']) ) return $content;
133
[19844]134      $asp['min_viewport_width']=$_COOKIE['windowWidth'] -$_COOKIE['theImageLeft']-$_COOKIE['theImageRight'];
135          $asp['viewport_height']=$_COOKIE['windowHeight']-130 ;
[19764]136
137      $asp['start_position']= 10;     
[19844]138 
[19764]139      }
[19844]140/*********************/
[18716]141static public function init($content,$element_info){
142  global  $template,$version,$icon_path,$page,$picture,$conf;
143  global $user,$Css,$css_slideshow,$css_display,$liste_type;
[19003]144  global  $has_pamoorama,$pictureSelType,$pictureDeriv,$pictureMap;
[18716]145  global $infos_message,$warnings_message;
[18735]146
147  global $set_miniature,$imgSizeWH,$DEBUG_autosize; 
148  global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
[18716]149//======================================================= 
150global $has_pamoorama ;
[18823]151
152  if( isset($_GET['cl_debug']) && $_GET['cl_debug'] =='false') {
153      $DEBUG_autosize="";
154  }else{
155    $DEBUG_autosize = isset($_POST['cl_debug']) ? $_POST['cl_debug'] : "" ;
156    $DEBUG_autosize = isset($_GET['cl_debug']) ? $_GET['cl_debug'] :  $DEBUG_autosize ;
157    $DEBUG_autosize = isset($conf['cl_debug']) ? $conf['cl_debug']."," . $DEBUG_autosize : $DEBUG_autosize ;
158 //===============================================================
159}
160if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .=  "init, ";} ;
161
[18716]162  $has_pamoorama = isset($template->files['pamooramics_content'])?"true":"false"; 
[18325]163  $theme=$user['theme']; 
[18716]164 
[18823]165  $Css = self::css($theme."-rules.css"); 
[18716]166  $css_slideshow=isset($Css['.Autosize']['slideshow'])?$Css['.Autosize']['slideshow']:"yes"; 
167  $css_display= isset($Css['.Autosize']['display'])?$Css['.Autosize']['display']:"block"; 
[19003]168  $default_size =  $conf['derivative_default_size'];
169//============================================================
170self::get_cookies();
[18716]171 //==============================================================
[18823]172 if(preg_match("|test|", $DEBUG_autosize, $val)) { 
[19156]173    $infos_message .= "#133 <br>Init:SESSION:"  . cl_print_var($_SESSION) ;
[19003]174       if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
[19156]175        $infos_message .=  "GET:"  . cl_print_var($_GET) ;
176        $infos_message .= "POST:"  . cl_print_var($_POST) ;
177        $infos_message .= "$pictureDeriv $pictureSelType $pictureMap ";
[19744]178      //  self::Fin_php("#138: ".$DEBUG_autosize);
[18823]179 }
[19003]180  $autosize_parametres = cl_autosize_Get_Options();
[18823]181
[18234]182//=====================================================================
[18716]183  $current = $template->get_template_vars('current'); 
[18823]184   //=== Zone affichage ==       
185      $windowWidth=$_COOKIE['windowWidth'] ;
186      $windowHeight=$_COOKIE['windowHeight'] ;
[18115]187
[18716]188      $theImageTop= isset($_COOKIE['theImageTop'])?$_COOKIE['theImageTop']:0;
189      $theImageLeft=isset($_COOKIE['theImageLeft'])?$_COOKIE['theImageLeft']:0;
[18325]190
[18716]191       $theImageRight=isset($_COOKIE['theImageRight'])?$_COOKIE['theImageRight']:0;
192       $theImageBottom=isset($_COOKIE['theImageBottom'])?$_COOKIE['theImageBottom']:0;
[18325]193
[18823]194
[18716]195       $theImageMargeWidth=isset($_COOKIE['theImageMargeWidth']) ? $_COOKIE['theImageMargeWidth']:0;
196       $theImageMargeHeight=isset($_COOKIE['theImageMargeHeight'])?$_COOKIE['theImageMargeHeight']:0;
[18234]197
[18736]198      $theImageMargeHeight -= 2;
199if(isset($_COOKIE['theImageWidth'])){
200       $theImageWidth=    $_COOKIE['theImageWidth'];
201       $theImageHeight=  $_COOKIE['theImageHeight'] ;
202}
203       $theImageWidth=    $windowWidth -  $theImageLeft - $theImageMargeWidth;
204       $theImageHeight=   $windowHeight - $theImageTop  - $theImageMargeHeight ;
205 
[18925]206   if (isset($element_info['is_gvideo']) && $element_info['is_gvideo'] ){
[18823]207    $pictureDeriv=$default_size;
[18736]208
[18823]209   }else{
210
211
212    $retour = self::get_min_max() ; 
213
[18735]214    $theMainImageSize = $retour->get_size();
[18823]215    $theMainImageWidth=   isset($_COOKIE['theMainImageWidth'])?$_COOKIE['theMainImageWidth']:$theMainImageSize[0];
216    $theMainImageHeight=   isset($_COOKIE['theMainImageHeight'])?$_COOKIE['theMainImageHeight']:$theMainImageSize[1] ;
217
[18716]218  if($theImageHeight!=0 && $theImageWidth!=0){
219      $pictureDeriv=$retour->type ;
220   }else{
221      $pictureDeriv=$default_size;
222   }
[18823]223}
[19003]224 
225 if(preg_match("|test|", $DEBUG_autosize, $val)) { 
[19746]226    $infos_message .=  "#208 <br>Init:SESSION:"  . cl_print_var($_SESSION) ;
[19156]227   
[19003]228    if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
[19156]229        $infos_message .=  "Init: COOKIE:"  . cl_print_var($_COOKIE) ;
230        $infos_message .=  "GET:"  . cl_print_var($_GET) ;
231        $infos_message .=  "POST:"  . cl_print_var($_POST) ;     
232        $infos_message .=("#193: ".$DEBUG_autosize);
[19003]233 }
[18716]234 $pattern = array();
235  if($has_pamoorama=="true"){ 
[18735]236  if(preg_match("|c1|", $DEBUG_autosize, $val)) echo  $theImageWidth . "x" . $theImageHeight ;
[18725]237      $pattern[0] = '/width\:(.*)(\d+),/';$replacement[0] = 'width:  '.$theImageWidth.' ,'; 
[18716]238      if(($theImageWidth!=0)){     
239            $content=  preg_replace($pattern, $replacement, $content);
240        }
[18735]241         if(preg_match("|c1|", $DEBUG_autosize, $val)) {
[18716]242         echo "<!-- " . $theImageWidth . "x" . $theImageHeight . " " .cl_print_var($content) ." -->";
[19746]243         self::Fin_php("#225: " . $DEBUG_autosize);
[18716]244    }
245      return  $content;
246  }
[18725]247if(isset($_GET['map'])){
248return  $content;
249}
[18716]250 $pattern[0] = '/width\:(.*)(\d+)px/';$replacement[0] = 'width:100% '; 
251 $pattern[1] = '/height\:(.*)(\d+)px/';$replacement[1] = 'height:100% '; 
252 $pattern[2] = '/width=\"(\d+)\"/';$replacement[2] = ' ';
253 $pattern[3] = '/height=\"(\d+)\"/';$replacement[3] = ' ';
[17503]254
[18949]255if ( strstr( $content,"iframe")||strstr($content,"charlie" )){ 
256 
257$pictureSelType="Autosize";
258$pictureDeriv=$conf['derivative_default_size'];
259
260$_COOKIE['picture_sel_type']=$pictureSelType;
261$_COOKIE['picture_deriv']=$pictureDeriv;
262
[18716]263  $ncount=1;   
[18949]264  if (strstr($content,"charlie" )){   
265      $content=str_replace( "<object" , "<object id='theMainImage_obj' name='theMainImage' "  ,$content,$ncount);
266      $content=str_replace( "<embed" ,  "<embed id='theMainImage_emb' name='theMainImage' "  ,$content,$ncount);
[19003]267      $content=str_replace( 'id="video"',"id='theMainImage_vid'  name='theMainImage' " ,$content,$ncount);
268  $content=str_replace( '<video"',"<video id='theMainImage_vid'  name='theMainImage' " ,$content,$ncount);
[18949]269  }else{
270      $content=str_replace( "<iframe" ,  "<iframe id='iframe' name='theMainImage' "  ,$content,$ncount);
271  }
[18716]272  $content=  preg_replace($pattern, "", $content);
[18949]273
[19003]274  $content= "<div id='theMainImage' style='height:".$theImageHeight."px  ;width:".$theImageWidth."px '>". $content . "</div>";
[18726]275 $content= "<style>#theImageAndInfos{height:auto;width:auto;position:relative}
[19003]276  #theImage{height:auto;align:center;text-align:center;position:relative}
[18949]277  #theMainImage{height:auto;align:center;text-align:center;position:static} 
278  #charlie{display:none }
279  #iframe{display:none }
[18716]280 </style>".$content;
281return  $content;
282 }
[19003]283 
284   $content=  preg_replace($pattern, "", $content);
[18234]285
[18725]286  return  $content;
[18716]287}//INIT
[17503]288
[18716]289/************************
290*  INIT 2
291*************************/
292static public function init2($content,$element_info){
[17503]293
[18234]294
[18716]295global  $template,$version,$icon_path,$page,$picture,$conf;
296global $user,$Css,$css_slideshow,$css_display,$liste_type;
297global $infos_message;
298//content = photo
[18234]299
[18716]300//=====================================================================
301  global  $has_pamoorama,$pictureSelType,$pictureDeriv;
[18735]302  global $DEBUG_autosize;
[18823]303  if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "init2, ";} ;
[18735]304   global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
[18716]305  //-- si Autosize correction redim ---------------
306  $current = $template->get_template_vars('current'); 
307  if (!isset($current)) return ;
[19003]308  if($pictureSelType!="Autosize") return $content ; 
309    $pattern =Array('/width=\"(\d+)\"/','/height=\"(\d+)\"/');
310    $replacement = Array('',"style='height:".$theImageHeight."px'");
311      $replacement = Array('',"");
312    $content= preg_replace($pattern, $replacement, $content);
[18716]313if( $has_pamoorama=="true") return $content ;
[17503]314
[18735]315if( !preg_match("|c1|", $DEBUG_autosize, $val) ) return $content ;
[18823]316//************************  c1 ***************************************
317   echo "theMainImageWidth :" . $theMainImageSize[0] . " X " . $theMainImageSize[1]  . "<br >";
318   echo "theImageWidth :" . $theImageWidth . " X " . $theImageHeight . "<br >";
319   echo $infos_message."<br />";
[18735]320   $Ratio = $theMainImageSize[0]/$theMainImageSize[1];
321
322   $nh = intval($theImageWidth / $Ratio)  ;
323   $nw = intval($theImageHeight * $Ratio) ;
324
325   echo $nw . "x " . $nh ."<br />";
326
327if($theMainImageSize[0] < $nw){
328     echo "HEIGHT " .$theImageHeight . "  WIDTH " .  $nw."<br />";
329}
330if($theMainImageSize[1] <  $nh ){
331 echo "HEIGHT " . $nh  . "  WIDTH " .  ($theImageWidth)."<br />";
332}
333
334 $content=  $content . $pictureDeriv . " " .$pictureSelType;
335        echo "<div style='color:white;position:absolute;left:0;top:0;width:".$windowWidth ."px;height:" .$windowHeight."px;background-color:blue'>";
336         echo "left:".$theImageLeft."px;top:".$theImageTop."px;width:".$theImageWidth ."px;height:" .$theImageHeight."px;";
337        echo "<div style='position:absolute;left:".$theImageLeft."px;top:".$theImageTop."px;width:".$theImageWidth ."px;height:" .  $theImageHeight."px;background-color:green;'>";
[19746]338 self::Fin_php("#320 : " . $content + $DEBUG_autosize);
[18325]339   
[18716]340} //INIT2
341/***************************
342*
343***************************/
[19744]344static public  function reload($id_ret){
[19003]345//=========================================
346include_once ( "include/functions_cookie.inc.php");   
347global $ma_page,$user,$element_info,$infos_message,$DEBUG_autosize;
348global $pictureDeriv,$pictureSelType,$pictureMap;
349      global $conf;
350
[18716]351  $set_miniature = "<!DOCTYPE html><html><head>
352   <meta http-equiv='content-type' content='text/html; charset=UTF-8'/>
[19744]353    <script type='text/javascript' src='themes/default/js/jquery.min.js'></script>
354    <script type='text/javascript' src='plugins/Autosize/js/autosizeDetect.js'></script>
[18716]355    <script type='text/javascript' src='plugins/Autosize/js/autosize.cookie.js'></script>
356    <script type='text/javascript' src='".PHPWG_ROOT_PATH."themes/default/js/plugins/jquery.ajaxmanager.js'></script>";     
[19744]357   
[18716]358    $set_miniature .= "<script type='text/javascript' src='".PHPWG_ROOT_PATH."plugins/Autosize/js/autosize_ajax.js' id='autosize_ajax' >  </script >";
[17503]359
[18716]360   $set_var = "<script type='text/javascript'>\n var COOKIE_PATH =  '".cookie_path()."';\n"; 
[19744]361   if(preg_match("|noreload|", $DEBUG_autosize, $val)) { 
362   $set_var .= " var reload =  'false';\n"; 
363   } else {
364    $set_var .= " var reload =  'true';\n"; 
365   }
366   $set_var .= " var ret_id =  '". $id_ret . "';\n"; 
[18716]367   $set_var .= " var mapage =  '". $ma_page . "';\n"; 
368   $set_var .= " var theme =  '" .$user['theme']. "';\n"; 
369   $set_var .= " var  theMainImageWidth = '" .$element_info['width'] . "';\n"; 
370   $set_var .= " var   theMainImageHeight = '" .$element_info['height'] . "';\n";   
371   $set_var .= " var  theMainImageSrc = '" .$element_info['path']. "';\n"; 
[17503]372
[18716]373   $set_var .= " </script >";
374   
375$autoscript="
376      </head>
377      <body onload=on_load() style='background-color:black;color :white;font-size:30px '  > 
[19744]378     please wait, loading($id_ret)...
[18716]379     <div></div>
380      </body></html>";   
[19744]381     
[19003]382 
383  $default_size =  $conf['derivative_default_size'];
384//=======================================================================
385$pictureSelType = pwg_get_session_var('picture_sel_type',$default_size); 
386$pictureDeriv = pwg_get_session_var('picture_deriv',$default_size); 
387$pictureMap = pwg_get_session_var('picture_map',$default_size); 
388//=======================================================================
389   $autosize_parametres = cl_autosize_Get_Options();
390   $userst= $user['status']."_enabled" ;
391 $userst=$autosize_parametres-> $userst;
392 $usertype= $user['status']."_type" ;
393 $usertype = $autosize_parametres->$usertype;
394if($userst=='off'){
395 
396}else{ 
397      if($usertype!="Autosize" && $usertype!="SelMaxi" ){
398          $pictureSelType = $usertype;
399          $pictureDeriv = $usertype;
400      }else if($autosize_parametres->defaut_type=="off"){
401          $pictureSelType = pwg_get_session_var('picture_sel_type',"SelMaxi"); 
402      }else {
403          $pictureSelType = pwg_get_session_var('picture_sel_type',"Autosize"); 
404      }
405}       
406//============================================================
407  self::save_cookies();
408if( !isset($_COOKIE['picture_deriv'])  ){
409  echo "INIT <pre>";
410  print_r($_COOKIE);
[19746]411  self::Fin_php("#393: ".$DEBUG_autosize);
[19003]412}
413
[19744]414if(preg_match("|vue_init|", $DEBUG_autosize, $val)) {   
415  $infos_message.="Reload: $userst <br> $usertype <br> autosize_parametres:"  . cl_print_var($autosize_parametres) ; 
416        if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
[19003]417        echo "Reload: SESSION:"  . cl_print_var($_SESSION) ;
418        echo "Reload: COOKIE:"  . cl_print_var($_COOKIE) ;
419        echo "GET:"  . cl_print_var($_GET) ;
420        echo "POST:"  . cl_print_var($_POST) ;
[19746]421        self::Fin_php("#403: ".$DEBUG_autosize);
[19744]422    }
423
424     $infos_message.="Reload: $userst <br> $usertype <br> autosize_parametres:"  . cl_print_var($autosize_parametres) ; 
[19746]425     if(!preg_match("|aff_init|", $DEBUG_autosize, $val)) { $infos_message=""; }
[18716]426        echo $set_miniature ;
[19746]427        echo $set_var ;       
[19744]428        echo $autoscript;       
[19859]429        if (!isset($_COOKIE['autosize_reload'])  ){ 
430            self::Fin_php("#424: ".$DEBUG_autosize);
431    } 
432  //     
[19744]433       
[18716]434}
435
436 /************************
[17503]437 *  cl_autosize_script_1
438 *************************/
439 static public function cl_autosize_script_1(){
[18735]440  global $user,$page,$template,$cl_plugin,$cl_version;
[18325]441    global  $has_pamoorama,$css_slideshow; 
[18716]442    global $pictureSelType,$pictureDeriv,$infos_message,$conf;
443    global $DEBUG_autosize;
[18823]444 if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "cl_autosize_script_1, " ;} ;
[18716]445    $ma_page=isset($page['body_id'])?$page['body_id']:"" ; 
446    if ($ma_page !='thePicturePage') return ; 
447    if ( $has_pamoorama=="false" ) return ; 
[18325]448 if ($page['slideshow']){
[18716]449 //==== mise à l'échelle ===
[18325]450    $current = $template->get_template_vars('current'); 
[19003]451    $default_size =  $conf['derivative_default_size'];
[18716]452
453    if(isset($current['selected_derivative'])) {
454        $model=$current['selected_derivative']->get_type() ;
455    }else{
456        $model=$default_size;
457    }
458   
[18325]459    $selected_derivative =  $current['derivatives'][$model]; 
460    $template->append('current', array(
461                                'selected_derivative' => $selected_derivative
462                                    ), 
463                      true);
464
465 }
[18716]466 
467
468
[10845]469    $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
[10347]470    $autosize_parametres =       cl_autosize_Get_Options() ;                   
471    $theme=$user['theme'];
[17503]472    //==============================================================================
[10347]473    $template->assign(
474      array(   
[17308]475          'autosize_parametres' => $autosize_parametres ,
476          'cl_plugins' => $cl_plugin ,
[18735]477          'cl_version' => $cl_version ,
[17308]478          'name' => $cl_plugin['name'] ,
[18716]479          'has_pamoorama' => $has_pamoorama,                                                             
[17503]480          'theme' => $theme  , 
481          'DEBUG_autosize' => $DEBUG_autosize,
[17308]482          'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
483          'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
[18325]484          'Version_pwg' => PHPWG_VERSION ,
[19003]485          'slide_show' => $page['slideshow']
[18325]486         )
[10347]487    );
[18735]488   if( preg_match("|c2|", $DEBUG_autosize, $val) ){ 
[19744]489   self::Fin_php( "446: " . $DEBUG_autosize);
[18735]490   return $content ;
491
492   }
[18716]493 
[17503]494    return $template->parse( 'autosize_init', false);
[18325]495
[18716]496
[8627]497        }// function cl_autosize_script_1
[16931]498
499 /*************************************
500 * cl_autosize_script_2()
501 **************************************/
[8627]502 static public function cl_autosize_script_2()
[18716]503 {  global $css_slideshow;
504   global $pictureSelType,$pictureDeriv,$infos_message;
[18735]505           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$cl_version,$known_script ;
506 
[18716]507     global  $has_pamoorama; 
508     global $DEBUG_autosize;
[18823]509  if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "cl_autosize_script_2, ";} ;
[18716]510    $ma_page=isset($page['body_id'])?$page['body_id']:"" ;   
511    if ($ma_page !='thePicturePage') return ; 
[18325]512 
[18716]513    $theme=$user['theme'];
514    if ($has_pamoorama=="false" ) return ; 
[19003]515    if ($css_slideshow == "no" and isset($_GET['slideshow'])) return ;   
[11429]516                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
[16931]517//=====================================================================
[8627]518                        $template->assign(
519                                        array(
[18735]520                                        'cl_version' => $cl_version ,
[8627]521                                        'name' => $cl_plugin['name'] ,
522                                        'ma_page' =>    $ma_page,
523                                        'theme' => $theme  ,
[10845]524                                        'DEBUG_autosize' => $DEBUG_autosize   ,
[19003]525                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH         
[8627]526                                        )
527                                                );
528                        $autoscript="<script type='text/javascript'>
529                        /* cl_autosize_script_2 */
530                        if (typeof (save_framework) == 'function')
[16124]531                           save_framework('".$ma_page."'); 
[18716]532     
[8627]533                        </script>";
534                $template->append('footer_elements',$autoscript); 
[18716]535     
[8627]536                return ; 
537 }// function cl_autosize_script_2
[18716]538
[17308]539  /*************************************
540 * cl_autosize_script_3()
541 **************************************/
[17503]542 static public function cl_autosize_script_3() {
[18716]543    global  $has_pamoorama,$template,$page,$infos_message;
[18735]544     global $DEBUG_autosize;
[18823]545      if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "cl_autosize_script_3, ";} ;
[18716]546$ma_page=isset($page['body_id'])?$page['body_id']:"" ;
547if ($ma_page !='thePicturePage') return ; 
[8627]548
[18716]549   
550    $template->func_combine_script(array('id'=>'my_script_2',
551                                    'path'=> AUTOSIZE_PATH.'js/JScript.js',
552                                    'require' => 'jquery'),
553                                $template->smarty);
554
555$template->func_combine_css(array('id'=>'autosize.css',
556                                    'path'=> AUTOSIZE_PATH.'css/autosize.css'
557                            ));
558
559
560                        $autoscript="<script type='text/javascript'>   
561                         var COOKIE_PATH = '".cookie_path()."' ;
562                        </script>"; 
563                    $template->append('footer_elements',$autoscript); 
564        if ($has_pamoorama=="false" ) return ; 
565
566                        $autoscript="<script type='text/javascript'>   
[17308]567                        if (typeof (Ajout_Ajax) == 'function')
568                           Ajout_Ajax(); 
569                        </script>";
570                $template->append('footer_elements',$autoscript); 
[18716]571
572     
[17308]573                return ; 
574 }// function cl_autosize_script_3
575
[18716]576/************************
577* cl_autosize_affiche
578*************************/     
579        static public function cl_autosize_affiche(){
580  if (!defined('AUTOSIZE_PATH')) {
581      define(  'AUTOSIZE_PATH',   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/' );
582      if (!defined('AUTOSIZE_PATH_ABS')) 
583        define(  'AUTOSIZE_PATH_ABS',  realpath(AUTOSIZE_PATH)."/");
584}
585
586    global $user, $picture, $template,$page,$known_script;
587    global $content, $element_info;   
588    global $infos_message,$error_message,$warnings_message;
589    global  $conf,$lang ,$user,$userdata;
590    global $defined_types,  $liste_type,$SRC_IMG;
591    global $set_miniature;
592    global $autosize_parametres,$user_status;   
593    global  $has_pamoorama,$pictureSelType,$pictureDeriv;
[19003]594    global $DEBUG_autosize;
595      global $css_slideshow,$css_display; 
[18823]596      if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .=  "cl_autosize_affiche, " ;} ;
[18716]597$ma_page=isset($page['body_id'])?$page['body_id']:"" ;
598if ($ma_page !='thePicturePage') return ; 
[19003]599//============================================================
600 self::save_cookies();
601
[18975]602    if(isset($set_miniature)){
[18823]603          $set_miniature = self::cl_autosize_nofile($set_miniature) ;
[18975]604          $set_miniatures= explode("script",$set_miniature);
605          if(preg_match("|noGen|", $DEBUG_autosize, $val)) { 
606          if(count($set_miniatures)> 1 )
607                $infos_message .= "PictureDeriv:" . $pictureDeriv. ' miniature:' . cl_print_var( $set_miniature); 
608                 
609            }else { 
610               
611               
612          } ; 
613          $template->append('footer_elements',$set_miniature); 
[18716]614      }
[19003]615 if ($css_slideshow == "no" and isset($_GET['slideshow'])) return ;   
616 
617  $AUTOSIZE_PATH = dirname(__FILE__).'/';
618  $theme=$user['theme']; 
619  load_language('plugin.lang', AUTOSIZE_PATH);
[18735]620
[19003]621 include_once (AUTOSIZE_PATH."include/affiche.php");   
622
[18735]623     $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
624     if ($css_display=="none"  &&  $has_pamoorama=="true" ) {   
[18716]625            $css_display="block" ;
626         }
627         $file_css=AUTOSIZE_PATH."css/".$theme.".css";
628         if (!file_exists($file_css))  $file_css="no";     
[18735]629     if ($css_display=="none" ) {       
630        return ;
631      } 
632     if($pictureSelType == $pictureDeriv ) {
[18925]633         if(preg_match("|event|", $DEBUG_autosize, $val)) {  cl_aff_infos_plus();} ;
[19003]634   
[18735]635     } 
[19003]636     
637    if (defined('GMAPS_VERSION')) $gmaps_function="true";
[18949]638          else $gmaps_function="false" ;
639
[19003]640
641
[18716]642        $template->set_filenames(array('autosize_content_header'=> $file )); 
643        $template->assign(      array( AUTOSIZE_PATH,$AUTOSIZE_PATH,
644                                  'file_css' =>$file_css,
645                                  'css_display' => $css_display,                                 
[18949]646                                  'theme' =>$theme,
647                                   'gmaps_function' => $gmaps_function
[18716]648                          ));
649        $template->concat('autosize_content', $template->parse('autosize_content_header', true)); 
[18735]650
[18716]651        $file =AUTOSIZE_PATH_ABS.'template/header.tpl' ;
652        $template->set_filenames(array('autosize_init_header'=> $file ));
653        $template->parse( 'autosize_init_header', false); 
654        $theme=$user['theme']; 
655                               
656                                if($autosize_parametres->check_icon_v == 'on'){                         
657                                                $template->assign('cl_autosize_button', 
658                                                array(  'cl_autosize_info' => 'cl_autosize_info' ,
659                    'cl_autosize_info_1' => 'cl_autosize_info_' , 
660                                                                    'cl_autosize_info_2' => 'cl_autosize_info_2' ,   
661                                                                    'URL' => $_SERVER['REQUEST_URI'] ,
662                                                                    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
663                                                                    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png',
664                    'ICON1' => AUTOSIZE_PATH . 'icons/button-no.png'
665                                                                )
666
667                                                        ); 
668                                        $template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
669                                        $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
670                                }
671
672                                 $template->set_filenames(
673                                                array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl',
674             'theme' => $theme   )
675                                        );
676
677                        $template->concat('autosize_content', $template->parse('autosize_content_header', true));               
678      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
679        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
680
681        $template->func_combine_script(array('id'=>'my_script_2',
682                                             'path'=> AUTOSIZE_PATH.'/js/JScript.js',
683                                             'require' => 'jquery'),
684                                              $template->smarty
685                                              );
686
687        $template->assign(array( 
688                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
689                          ));                                   
690        $template->parse('mes_script');
691      }   
[19003]692     
693
694if(preg_match("|vue_cookies|", $DEBUG_autosize, $val)) { 
695
696  $pictureSelType=$_COOKIE['picture_sel_type'];
697  $pictureDeriv=$_COOKIE['picture_deriv'];
698  $infos_message .= "cl_autosize_affiche: $pictureSelType  <--> $pictureDeriv \n" ;
699
700}
[19156]701 
[19003]702   if(preg_match("|test|", $DEBUG_autosize, $val)) { 
[19746]703    $infos_message .= "#683 <br>cl_autosize_affiche:_COOKIE:"  . cl_print_var($_COOKIE) ;   
[19003]704    $pictureMap=$_COOKIE['picture_map'];
[19156]705    $infos_message .= "<br />SelType:" . $pictureSelType."; pictureDeriv:".$pictureDeriv ."; pictureMap:".$pictureMap;
[19744]706   
[19746]707    self::Fin_php("#686: ".$DEBUG_autosize);
[19156]708 } 
709       cl_aff_infos_plus();
[18716]710        return $template->parse( 'autosize_content', false);
711        } //public function cl_autosize_affiche
[11961]712
[18716]713
[11961]714/****************************************
715*
716****************************************/
717function Get_Options(&$parametres,$str_index){
718    global $conf ;
[16124]719     if (!isset( $conf[$str_index]))  {   
720      $conf[$str_index]="";
721     }
[11961]722    $m_options=  $conf[$str_index];
723     if(isset($m_options))
724       if ( preg_match("|s:(.*)|", $m_options, $val) )
725        $parametres =  unserialize($conf[$str_index]);
726       else{
727         $parametres=explode(",",$_options);
728        }     
729        //====== par defaut =======================
730         $new_val=false;
731         $def_para=Array();
732
733    $def_para['query'] = 'Qt'  ;
734    $def_para['type'] = 'Ty' ;
735
[16931]736    $def_para['webmaster_type'] = 'Autosize' ; 
737    $def_para['admin_type'] = 'Autosize'  ; 
738    $def_para['generic_type'] = 'Autosize'  ;
739    $def_para['guest_type'] = 'Autosize'  ;
740    $def_para['normal_type']  =  'Autosize'  ;
741 
[11961]742
743
744    $def_para['mini_height'] =  '150' ;
745    $def_para['mini_width'] = '300' ;
746
747    $def_para['mini_height2'] =  '150' ;
748    $def_para['mini_width2'] =   '300' ;
749
750    $def_para['echelle_max'] =  '1.0'; 
751    $def_para['marge_basse'] =  '0';
752    $def_para['fade_in'] =   '0';
753    //==================================================
754    $def_para['check_desc_v'] =  "off" ;
755    $def_para['check_icon_v'] =  "off" ;
[18716]756    $def_para['defaut_type'] =  "off" ;
757
[11961]758    $def_para['webmaster_enabled'] =   "off" ;
759    $def_para['admin_enabled'] =   "off" ;
760    $def_para['generic_enabled'] =   "off" ;
761    $def_para['guest_enabled'] =   "off" ;
762    $def_para['normal_enabled'] =   "off" ;
763    //===================================================
764   $para=$def_para;   
765    foreach ($para as $key => $value) {   
766      if( isset($parametres->$key) ){
767         $value=$parametres->$key;         
768      } 
769    if($def_para[$key] =="on" ||$def_para[$key] =="off" ){
770       $val_pg=(isset($_POST[$key]))? ($_POST[$key]=="off"||$_POST[$key]=="on")?$_POST[$key]:"on" : "off" ;
771       $value =(isset($_POST[$key]))? $val_pg : $value ; 
772       $val_pg=(isset($_GET[$key]))? ($_GET[$key]=="off"||$_GET[$key]=="on")?$_GET[$key]:"on" : "off" ;
773       $value =(isset($_GET[$key]))? $val_pg  : $value ; 
774     }else{
775        $value =(isset($_POST[$key]))? $_POST[$key] : $value ; 
776        $value =(isset($_GET[$key]))? $_GET[$key] : $value ; 
777      }
778        unset( $parametres->$key) ;
779        $parametres->$key = $value ;           
780     }   
781    return $parametres ;
782  }
[18325]783  /****************************************************/
784 
785function listeFichiers($dir,$theme){
786  global $extensions_allowed;
787  $extensions_allowed = array();
788  $extensions_allowed [] = 'css';
789  if ($handle = opendir($dir)) {   
790    while (false !== ($file = readdir($handle))) {
791      if (($file <>'.') && ($file<>'..')) {
792        if (is_file($dir.'/'.$file)){
793          $extension = pathinfo($dir.'/'.$file, PATHINFO_EXTENSION);
794          if (in_array($extension,$extensions_allowed)){
795            $fileHandle = fopen($dir.'/'.$file, "r");
796           
797            $intro = fread($fileHandle,filesize ($dir.'/'.$file));
798            fclose($fileHandle);
799            if ($file== $theme){       
800              flush();   
801              return $intro ;
802            }
803          }
804      } else {
805        if (is_dir($dir.'/'.$file)){
806          listeFichiers($dir.'/'.$file,$theme);
807        }
808      }
809    }
810   }
811   closedir($handle);
812  }
813}
814//================================================
[18328]815static public function css($theme_local) {     
[18325]816    $path = $_SERVER['DOCUMENT_ROOT'];
817    if (substr($path,-1)=='/'){
818              $path =  substr($path,0,-1);
819          }
820     if(isset($_GET['path'])) 
821              $path=$_GET['path'];
822          else
823              $path=PHPWG_ROOT_PATH."local/css/";
824
825              $mycssfile=$path.$theme_local;
826
827              if(!file_exists($mycssfile))
828               $mycssfile=$path."default-rules.css";
829
[18326]830               if(!file_exists($mycssfile)){             
831              return Array();
832               }
833
[18325]834      $ret =   file_get_contents ($mycssfile);
835
[18735]836    function remove_comments( & $string ) { 
837       $string = preg_replace('#/\*.*?\*/#s',"",$string); 
838       return $string;
839     }
[18325]840
[18735]841    $order   = array("\r\n", "\n", "\r"," ");
842    $replace = '';
843    $newstr = str_replace($order, $replace, $ret); 
[18325]844
[18735]845    $order   = array('"');
846    $replace = "'";
847    $newstr = str_replace($order, $replace, $newstr); 
[18325]848
849
[18735]850    $order   = array("}");
851    $replace = '}\r\n';
852    $newstr = str_replace($order, $replace, $newstr);
853    remove_comments($newstr);
[18325]854
[18735]855    $newstr = explode('\r\n',$newstr);
856    $css=Array();
[18325]857   
858  foreach ($newstr as $key => $value) {   
859   if($value){
860    $css2=Array();
861      $key=explode("{",$value);   
862      $value = str_replace("}","",$key[1]) ;
863      $value=explode(";",$value); 
864           foreach ($value as $key2 => $value2) {   
865            if($value2){
866              $key2=explode(":",$value2);   
867                $value2 =  $key2[1] ;
868                $css2[$key2[0]] = $value2 ;
869            }
870           }
871      $css[$key[0]]=$css2 ;
872     }   
873}
874
875       
876                    return $css;
877        } 
878
[18716]879/***************************
880 *  get_min_max
881 ***************************/
882 static public function get_min_max(){
883 global $liste_type,$img_all,$set_miniature,$template,$infos_message,$error_message,$has_pamoorama ; 
884 global $theImageWidth,$theImageHeight,$pictureSelType,$pictureDeriv ;
[18823]885   global $DEBUG_autosize;
886 
887
[18716]888    $current = $template->get_template_vars('current'); 
889    $liste_type="";
890    $del_deriv_types = array();
891    $i=0;
892     $defined_types = array_keys(ImageStdParams::get_defined_type_map());     
893    foreach($defined_types as $type){
894   
895      if($type!="Autosize" && $type!="SelMaxi" ){
896            $last_derivative= $type ;
897            $del_deriv_types[$i] =  $last_derivative ; 
898        $i++;
899      }
900     
901    }
902    ;
903    $derivative=$current['derivatives'][$last_derivative] ;   
904    $img_all= $derivative->get_all($derivative->src_image);
[18325]905
[18716]906    $retour = (object) '';
907    $maxi_image = (object) '';
908    $mini_image = (object) '';
909    $std_image  = (object) '';
910    $default_image=(object) '';
[18925]911    $SelType_image=(object) '';
[18716]912    $last_image=(object) '';
913
914    global $imgSizeWH ;
915    $imgSizeWH  = $derivative->get_size();     
916    $theImage_maxi=0;
917     $theImage_mini=0;
918     $theImage_def=0;
919     $No_files= array();
920//================= Liste =========================   
921  $ok= 0 ;
[19844]922  $nofile=0 ;      global $max_crop;
[18716]923  //=============================================
924  // Liste mini maxi
925  //=============================================
926    foreach ($img_all as $img_select){
[19844]927
[18716]928            $img_type  =  $img_select->get_type();     
929            $img_url  = $img_select->get_path();     
[19844]930              $max_crop = 0 ;
931            $imgWH  =  self::Get_Size($img_select);       
[18716]932            if ($img_type=="square" || $img_type=="thumb" ) continue ;   
933            if($img_type=="Autosize" || $img_type=="SelMaxi"){
934            $theImage_def +=1 ;
935             continue;
936             }             
937           if(!file_exists(PHPWG_ROOT_PATH.$img_url)){   
938                  $No_files[$img_type] =   $img_select ;
939                  $nofile++ ;   
[18823]940                   if(preg_match("|get_infos|", $DEBUG_autosize, $val)) 
941                  $infos_message .=$nofile ." " ;
[18716]942            }         
[18823]943             if(preg_match("|get_minfos|", $DEBUG_autosize, $val)) 
[19844]944                      $infos_message .=$img_url . " " . $max_crop ." -> " . $img_type . " " . print_r($imgWH,true). " <br >";
[18823]945
[18716]946          if(file_exists(PHPWG_ROOT_PATH.$img_url)){    } // if file       
947                             
948                     if ($theImage_def==0){
949                        // Avant Autosize ou Original;
950                        if($img_type=="Original") {
951                            $theImage_def = 1;
952                            $theImage_maxi=1;
953                            $theImage_mini=1;
954                            if($ok==0){
955                                $last_image->type=$img_type;
956                                $last_image->url=$img_url;
957                                $last_image=$img_select;     
958                              }
959                         }else{
960                            $last_derivative=$img_type ;
961                            $last_image=  $img_select; 
962                           } 
963                       }
964                       if ($theImage_maxi==0){                       
965                            $maxi_image=  $img_select; 
966                          }
967                       if ($theImage_mini==0){                     
968                            $mini_image=  $img_select; 
969                          }
[18925]970                    $liste_type[$img_type]=$img_type.",".$img_url.",".$imgWH[0] .",".$imgWH[1] ;
971                    if( $img_type==$pictureSelType){
972                     if(preg_match("|get_minfos|", $DEBUG_autosize, $val))     $infos_message .= $pictureSelType . " <--> " . $img_type ."<br >";
[18716]973
[18925]974                          $SelType_image->type=$img_type;
975                          $SelType_image->url=$img_url;
976                          $SelType_image=$img_select;   
977                    }
[18716]978                    if( $img_type=="Original" && $theImage_def==0 ){ 
979                          $theImage_def=1;
980                          $img_type = $last_derivative ;                         
981                          $img_url= $derivative->get_path();
982                          $imgWH = $derivative->get_size();
983
984                          $default_image->type=$img_type;
985                          $default_image->url=$img_url;
986                          $default_image=$img_select;                     
987                       
988                        }
989
990                     if($has_pamoorama==true) 
991                          $test= ($imgWH[1] >  $theImageHeight)  ;
992                    else
993                          $test= ($imgWH[1] >  $theImageHeight  && $imgWH[0] >  $theImageWidth);             
994                    if($theImage_maxi==0)
995                        if( $test  ){ 
996                                $theImage_maxi=1; 
997                                $maxi_image->type =   $img_type;
998                                $img_type=$img_select->get_type();
999                                if($img_type=="Original")
1000                                    $maxi_image = $last_image; 
1001                                else
1002                                    $maxi_image = $img_select;   
1003                                                             
[18936]1004                               $maxi_image->url  =  $maxi_image->get_path();
1005
[18716]1006                            } else { 
1007                           
1008                                $mini_image->type=$img_type;
1009                                $mini_image->url=$img_url;
[18936]1010                                $mini_image=$img_select; 
1011                               $mini_image->url  =  $mini_image->get_path();           
[18716]1012                            }                         
1013       
1014      } // for
1015      //================================================ 
[18723]1016 
1017      $img_url = $img_select->src_image->get_url();
1018                $imgSizeWH  =  $img_select->src_image->get_size();
1019                $liste_type["Original"]="Original".",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1] ;
1020     
[18716]1021 
1022          $retour=(object)'' ;
1023      if ($pictureSelType=="Autosize") $retour= $maxi_image ;
1024      else if ($pictureSelType=="SelMaxi") $retour= $mini_image ;
[18925]1025      else{     
1026      $types = array_intersect(array_keys($liste_type), array($pictureSelType));
1027      if(!count($types)){
1028        $pictureSelType="Original";
1029      }
1030        $retours=  explode(",",$liste_type[$pictureSelType]);
1031        $retour=$SelType_image;
1032        $retour->type=$retours[0];
1033        $retour->url=$retours[1];
1034     }
[18823]1035
[18925]1036  if (!isset( $retour->type)){     
1037                  $retour=$last_image;
1038                  $retour->type =  $retour->get_type();
1039                  $retour->url  =  $retour->get_path();
[18936]1040               
[18925]1041}
1042if (isset( $retour->type) && $retour->type=="Original" ){     
1043                  $retour=$last_image;
1044                  $retour->type =  $last_derivative;
1045                  $retour->url  =  $retour->get_path();
[18936]1046             
[18925]1047}
1048      if($nofile > 0){ 
1049        $set_miniature=$No_files ;
[18716]1050      }
[18823]1051
[18936]1052    if(preg_match("|get_infos|", $DEBUG_autosize, $val)) 
[18823]1053            $infos_message .=$pictureSelType . " -> " . $retour->type . " : "  . $retour->url  ."<br >";
1054
[18716]1055return $retour ;
1056
1057  }
[19844]1058  //=================================================================
1059
1060static public function Get_Size($Img_Select){
1061      global  $max_crop;
[19986]1062            $imgWH  =  $Img_Select->get_size();   
1063            $img_type  =  $Img_Select->get_type();     
1064            if( $img_type =="Original")  return ;
[19844]1065              $smaller = ImageStdParams::get_by_type($img_type);   
1066              $max_crop=0;
1067              if($smaller->sizing->max_crop==1){
1068                $imgWH  =$smaller->sizing->min_size;
1069                 $max_crop=1;
1070          }     
1071          return $imgWH ;
1072      }
[18716]1073//==================================================================
1074static public  function  cl_autosize_nofile($img_all){
1075 //=== verification fichiers absents ===
1076 global $infos_message,$error_message;
[18975]1077 global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
1078global  $pictureDeriv;
[18716]1079  $ok=false ;
1080 $nofiles=array();
1081 $file_no=(object) '';
1082
1083 $nosrc=false ;
1084 $ok=true ;
[18975]1085 $listes="";     
[18716]1086  foreach ($img_all as $img_select){
1087    $img_url  = $img_select->get_url();
1088    if(!file_exists(PHPWG_ROOT_PATH.$img_url)){   
[19003]1089      $img_type  =  $img_select->get_type();     
1090     
[18716]1091      $file_id=explode("?",$img_url); 
1092      if(count($file_id) ==1){
1093          $file_id[]=$file_id[0] ;
[18735]1094      }   
[18716]1095        if ( !preg_match("|".$file_id[1]."|", $listes) ){
1096              $listes  .=  $file_id[1] ."<br />";
[18731]1097              $file_no->url= $file_id[1] ;         
[18716]1098              $id  =  $img_select->src_image->id;                 
1099              $file_no->id=$id ;
[18975]1100              $file_no->type=$img_type ; 
[19003]1101              array_push($nofiles,serialize($file_no)) ;   
1102               if( $img_type == $pictureDeriv){
1103         
1104          break ;
1105    }           
[18716]1106      }
1107      $ok=false ;     
1108    }
[18735]1109  }
1110  $exec_miniatures="";
[18716]1111  if(count($nofiles)>0){
1112  //=======================================================================================
1113    if($nosrc!=true  ){
[18975]1114      $script_miniatures = "<script type='text/javascript' src='".PHPWG_ROOT_PATH."themes/default/js/plugins/jquery.ajaxmanager.js' ></script>";     
1115      $script_miniatures .= "<script type='text/javascript' src='".PHPWG_ROOT_PATH."plugins/Autosize/js/autosize_ajax.js' id='autosize_ajax' >  </script >";
1116      $nosrc=true ;
[18735]1117    } 
[19003]1118    $exec_miniatures ="";
[18975]1119      $script_miniatures .= "<script type='text/javascript'>
[18716]1120        var nofile=Array(";
[18975]1121        for ($i=0;$i  <  count($nofiles)-1 ;$i++){       
1122             $file = unserialize($nofiles[$i]);
[18735]1123             $exec_miniatures .=  "{id:'".$file->id."',type:'". $file->type."',file:'". $file->url."',width:'".$theMainImageSize[0]."', height:'".$theMainImageSize[1]."'},\n" ;
1124          } 
[18975]1125          if($i  <  count($nofiles))
1126          {   $file = unserialize($nofiles[$i]);
1127             $exec_miniatures .=  "{id:'".$file->id."',type:'". $file->type."',file:'". $file->url."',width:'".$theMainImageSize[0]."', height:'".$theMainImageSize[1]."'}" ;
1128             }
1129             /*** Un seul ***********/
1130             $file = unserialize($nofiles[count($nofiles)-1]);
1131             $exec_miniatures =  "{id:'".$file->id."',type:'". $file->type."',file:'". $file->url."',width:'".$theMainImageSize[0]."', height:'".$theMainImageSize[1]."'}" ;
1132
1133          $script_miniatures  .= $exec_miniatures . "); </script>\n" ;                 
1134          $script_miniatures  .= "<script type='text/javascript' >
[18735]1135          if(typeof nofile!='undefined')
1136              getDerivativeUrls(nofile);
[18716]1137      </script>";
[18735]1138      //==================================================================================
[18975]1139      return $script_miniatures  ;
[18735]1140    }
[18716]1141 }
[19003]1142 /***************************
1143 *  get_cookies
1144 ****************************/
1145 static public  function  get_cookies(){
[19744]1146  global $pictureDeriv,$pictureSelType,$pictureDeriv,$pictureMap;
[19003]1147  if(!isset($_COOKIE['picture_deriv'])){
1148      $pictureDeriv= pwg_get_session_var('picture_deriv');
1149      $pictureSelType = pwg_get_session_var('picture_sel_type');
1150      $pictureMap = pwg_get_session_var('picture_map') | $pictureDeriv;
1151  }else{
1152      $pictureDeriv = $_COOKIE['picture_deriv'];
1153      $pictureSelType = isset( $_COOKIE['picture_sel_type'])?$_COOKIE['picture_sel_type']:$pictureDeriv;
1154     
1155      $pictureMap =  isset($_COOKIE['picture_map'])?$_COOKIE['picture_map']:$pictureDeriv;
1156  }
1157  $_COOKIE['picture_sel_type']=$pictureSelType;
1158  $_COOKIE['picture_deriv']=$pictureDeriv;
1159  $_COOKIE['picture_map']=$pictureMap;
1160
1161 }
1162 /***************************
1163 * save_cookies
1164 ****************************/
1165 static public  function  save_cookies(){
[19744]1166  global $pictureDeriv,$pictureSelType,$pictureDeriv,$pictureMap;
[19003]1167
1168  pwg_set_session_var('picture_deriv',$pictureDeriv);
1169  pwg_set_session_var('picture_sel_type',$pictureSelType);
1170  pwg_set_session_var('picture_map',$pictureDeriv);
1171//============================================================
1172  setcookie( 'picture_sel_type',
1173            $pictureSelType,
1174            time()+5,
1175            cookie_path() 
1176          );
1177//=============================================================
1178  setcookie( 'picture_map',
1179            $pictureDeriv,
1180            time()+5,
1181            cookie_path() 
1182          );
1183//============================================================
1184  setcookie( 'picture_deriv',
1185            $pictureDeriv,
1186            time()+5,
1187            cookie_path() 
1188          );
1189$_COOKIE['picture_sel_type']=$pictureSelType;
1190$_COOKIE['picture_deriv']=$pictureDeriv;
1191$_COOKIE['picture_map']=$pictureDeriv;
1192}
[19744]1193
1194static public function Fin_php($message_){
1195global  $infos_message;
1196 echo "End :".$message_."<br>";
1197die($infos_message);
1198}
[18716]1199 //==================================================
[7375]1200} // class
1201
[11961]1202/*************************************
[7375]1203        *
[11961]1204 *************************************/
[7193]1205 function cl_autosize_Get_Options()
1206  {
[7394]1207                global $conf,$autosize_parametres; 
[12652]1208    $autosize_parametres ="";
1209 
1210 if (!isset($conf['cl_autosize']))  {   
1211  $conf['cl_autosize']="";
1212  $q = '
1213   INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
1214   VALUES ("cl_autosize","","Parametres du plugin Autosize")
1215  ;';
1216  pwg_query($q);
1217  }
1218 
1219 
1220
[7394]1221                $autosize_parametres =  unserialize($conf['cl_autosize']);
[18823]1222      // $autosize_parametres = self::Get_Options($autosize_parametres,'cl_autosize');
[7394]1223                $autosize_parametres =  cl_autosize_Set_Options();
1224                return $autosize_parametres;
[7375]1225  }
1226        /*
1227        *
[7193]1228        */
[11961]1229function cl_autosize_Set_Options() {
[7193]1230  global $autosize_parametres;
1231//=============================================================================
[7962]1232$my_para=$autosize_parametres;
[16124]1233  if (empty($my_para))
1234$my_para = (object) '';
1235
[7962]1236$my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
1237$my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
[7193]1238
[16931]1239$my_para->webmaster_type =(isset($_POST['webmaster_type'])) ? $_POST['webmaster_type'] : ((isset($my_para->webmaster_type )) ? $my_para->webmaster_type : 'Autosize' ) ;
[7193]1240
[16931]1241$my_para->admin_type =(isset($_POST['admin_type'])) ? $_POST['admin_type'] : ((isset($my_para->admin_type )) ? $my_para->admin_type : 'Autosize' ) ;
[7193]1242
[16931]1243$my_para->generic_type =(isset($_POST['generic_type'])) ? $_POST['generic_type'] : ((isset($my_para->generic_type )) ? $my_para->generic_type : 'Autosize' ) ;
[7193]1244
1245
[16931]1246$my_para->guest_type =(isset($_POST['guest_type'])) ? $_POST['guest_type'] : ((isset($my_para->guest_type )) ? $my_para->guest_type : 'Autosize' ) ;
[7193]1247
[7725]1248
[16931]1249$my_para->normal_type =(isset($_POST['normal_type'])) ? $_POST['normal_type'] : ((isset($my_para->normal_type )) ? $my_para->normal_type : 'Autosize' ) ;
1250
1251
1252
[7962]1253$my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
1254$my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
1255
1256$my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
1257$my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
1258
[9473]1259$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
[9225]1260$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
[9473]1261$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
[7962]1262
[7193]1263//===============================================================================       
1264
1265if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
[7962]1266                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
1267                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
[18716]1268        $my_para->defaut_type= isset($_POST['defaut_type']) ? $_POST['defaut_type'] : "off" ;
[7394]1269
[7962]1270                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
1271                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
1272                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
1273                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
1274                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
[7394]1275
[7193]1276         }else{
[7962]1277                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : ( ( isset($my_para->check_desc_v) ) ? $my_para->check_desc_v :   'off') ; 
1278                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : ( ( isset($my_para->check_icon_v) ) ? $my_para->check_icon_v :   'off') ; 
[18716]1279                $my_para->defaut_type = isset($_POST['defaut_type']) ? $_POST['defaut_type'] : ( ( isset($my_para->defaut_type) ) ? $my_para->defaut_type :   'off') ; 
[7394]1280
[7962]1281$my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ; 
1282$my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ; 
1283$my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ; 
1284$my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
1285$my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ; 
[7394]1286
1287
[7193]1288   }
[7316]1289
[7962]1290return $my_para;
[7193]1291}
[7375]1292        /*
1293        *
[7193]1294        */
1295function cl_autosize_sauve_options_inf()
1296{
1297global $options,$infos_message,$conf,$autosize_parametres  ;
1298$infos_message .=l10n("cl_autosize_save_config")."<br>";
1299 $autosize_parametres=cl_autosize_Set_Options();
[12652]1300 if ( isset($autosize_parametres) )     { 
[7193]1301                $query = '
1302                UPDATE '.CONFIG_TABLE.'
1303                SET value="'.addslashes(serialize($autosize_parametres)).'"
1304                WHERE param = "cl_autosize"
1305                LIMIT 1';
1306                        pwg_query($query);
1307          }
[17503]1308    if (!isset($conf['cl_derivatives_sav']))  {   
1309      $q = '
1310        INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
1311        VALUES ("cl_derivatives_sav","","sauvegarde derivatives")
1312      ;';
1313      pwg_query($q);     
1314      }
[7193]1315 }
[18716]1316 /*************************
1317 *
1318 *************************/
1319 if(!function_exists("cl_print_var")){
1320   function cl_print_var($variables){
1321    ob_start();
1322    echo '<pre>';
1323    print_r($variables);
1324    echo '</pre>';
1325    $m= ob_get_contents();
1326    ob_end_clean();
1327    return $m;         
1328  }
[8729]1329}
[18716]1330/******************
1331*
1332******************/
1333if(!function_exists("cl_aff_infos_plus")){
1334        function cl_aff_infos_plus()
1335                {
1336                 global $template,$infos_message,$error_message,$warnings_message, $user ;
1337                 global  $conf,$lang,$page  ;
1338                 //==============================================================
1339                  if (isset($error_message))    {       
1340                                if ($error_message <> ""){
1341                                                $error_message=str_replace("\n",'<br />',$error_message) ;
1342                                                $template->assign('errors',$error_message);
1343                                                $error_message="";
1344                                        }
1345                        }
1346     //==============================================================
1347                  if (isset($warnings_message)) {       
1348                                if ($warnings_message <> ""){
1349                                                $warnings_message=str_replace("\n",'<br />',$warnings_message) ;
1350                                                $template->assign('warnings',$warnings_message);
1351                                                $warnings_message="";
1352                                        }
1353                        }
1354        //=============================================
1355                  if (isset($infos_message)){                   
1356                                if ($infos_message <> ""){
1357                                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
1358                                                $template->assign('infos',$infos_message);
1359                                                $infos_message="";
1360                                        }
1361                                }
1362                                //=============================================================
1363                return;         
1364               
1365                } // function cl_autosize_aff_infos_plus
1366        //===============================================================
1367}
[7375]1368
[7193]1369?>
Note: See TracBrowser for help on using the repository browser.