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
Line 
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// +-----------------------------------------------------------------------+
22class autosize_ctrl {
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
32
33
34/**************************
35*  autosize_calcContent   *
36**************************/
37 static public function autosize_calcContent($content,$element_info){
38   global $conf,$page, $template,$picture,$user; 
39  global $defined_types,$pictureSelType,$pictureMap ,$pictureDeriv ,$liste_type,$SRC_IMG;
40  global $autosize_parametres,$user_status;
41  global $infos_message,$error_message;
42    //==============================================================================
43  global $DEBUG_autosize;
44  if( isset($_GET['cl_debug']) && $_GET['cl_debug'] =='false') {
45      $DEBUG_autosize="";
46  }else{
47    $DEBUG_autosize = isset($_POST['cl_debug']) ? $_POST['cl_debug'] : "" ;
48    $DEBUG_autosize = isset($_GET['cl_debug']) ? $_GET['cl_debug'] :  $DEBUG_autosize ;
49    $DEBUG_autosize = isset($conf['cl_debug']) ? $conf['cl_debug']."," . $DEBUG_autosize : $DEBUG_autosize ;
50 //===============================================================
51}
52 if(preg_match("|event|", $DEBUG_autosize, $val))  $infos_message =  "autosize_calcContent, " ; 
53    $ma_page=isset($page['body_id'])?$page['body_id']:"" ; 
54   if ($ma_page !='thePicturePage') return ; 
55    $default_size =  $conf['derivative_default_size'];
56//============================================================
57self::get_cookies();
58    $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), array("Autosize","SelMaxi"));
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    }
67    if(preg_match("|test|", $DEBUG_autosize, $val)) { 
68        $infos_message .= "#65 autosize_calcContent: <br>";
69        if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
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 ";
75      //  self::Fin_php ("#75: ".$DEBUG_autosize);
76 }
77    if(!isset($_COOKIE['picture_deriv'] )){
78        if(preg_match("|test_1|", $DEBUG_autosize, $val)) { 
79          $infos_message .= "not COOKIE['picture_deriv'] -> reload(): <br>";         
80          self::Fin_php("#80 autosize_calcContent:" . $DEBUG_autosize );
81        }
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);
88        }
89          self::reload("#89");
90      //  self::Fin_php("#90 autosize_calcContent:" + $DEBUG_autosize);
91
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(); 
101
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; 
106    $picture['current']['thumbnail']=$SRC_IMG;
107
108//==============================================================
109    $autosize_parametres = cl_autosize_Get_Options();
110   return false ;
111 }//calc_content ;
112
113
114
115/*********************
116* INIT
117*********************/
118static public function init_3(){
119 
120}
121static public function init_1($content, $image)
122                {
123                  global $conf, $template, $page;   
124       if(!isset($conf['AS_panorama'])) return $content; 
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     
132       if ( !stristr($image['name'], $asp['in_mode_360']) and !stristr($image['name'], $asp['in_mode_180']) ) return $content;
133
134      $asp['min_viewport_width']=$_COOKIE['windowWidth'] -$_COOKIE['theImageLeft']-$_COOKIE['theImageRight'];
135          $asp['viewport_height']=$_COOKIE['windowHeight']-130 ;
136
137      $asp['start_position']= 10;     
138 
139      }
140/*********************/
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;
144  global  $has_pamoorama,$pictureSelType,$pictureDeriv,$pictureMap;
145  global $infos_message,$warnings_message;
146
147  global $set_miniature,$imgSizeWH,$DEBUG_autosize; 
148  global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
149//======================================================= 
150global $has_pamoorama ;
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
162  $has_pamoorama = isset($template->files['pamooramics_content'])?"true":"false"; 
163  $theme=$user['theme']; 
164 
165  $Css = self::css($theme."-rules.css"); 
166  $css_slideshow=isset($Css['.Autosize']['slideshow'])?$Css['.Autosize']['slideshow']:"yes"; 
167  $css_display= isset($Css['.Autosize']['display'])?$Css['.Autosize']['display']:"block"; 
168  $default_size =  $conf['derivative_default_size'];
169//============================================================
170self::get_cookies();
171 //==============================================================
172 if(preg_match("|test|", $DEBUG_autosize, $val)) { 
173    $infos_message .= "#133 <br>Init:SESSION:"  . cl_print_var($_SESSION) ;
174       if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
175        $infos_message .=  "GET:"  . cl_print_var($_GET) ;
176        $infos_message .= "POST:"  . cl_print_var($_POST) ;
177        $infos_message .= "$pictureDeriv $pictureSelType $pictureMap ";
178      //  self::Fin_php("#138: ".$DEBUG_autosize);
179 }
180  $autosize_parametres = cl_autosize_Get_Options();
181
182//=====================================================================
183  $current = $template->get_template_vars('current'); 
184   //=== Zone affichage ==       
185      $windowWidth=$_COOKIE['windowWidth'] ;
186      $windowHeight=$_COOKIE['windowHeight'] ;
187
188      $theImageTop= isset($_COOKIE['theImageTop'])?$_COOKIE['theImageTop']:0;
189      $theImageLeft=isset($_COOKIE['theImageLeft'])?$_COOKIE['theImageLeft']:0;
190
191       $theImageRight=isset($_COOKIE['theImageRight'])?$_COOKIE['theImageRight']:0;
192       $theImageBottom=isset($_COOKIE['theImageBottom'])?$_COOKIE['theImageBottom']:0;
193
194
195       $theImageMargeWidth=isset($_COOKIE['theImageMargeWidth']) ? $_COOKIE['theImageMargeWidth']:0;
196       $theImageMargeHeight=isset($_COOKIE['theImageMargeHeight'])?$_COOKIE['theImageMargeHeight']:0;
197
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 
206   if (isset($element_info['is_gvideo']) && $element_info['is_gvideo'] ){
207    $pictureDeriv=$default_size;
208
209   }else{
210
211
212    $retour = self::get_min_max() ; 
213
214    $theMainImageSize = $retour->get_size();
215    $theMainImageWidth=   isset($_COOKIE['theMainImageWidth'])?$_COOKIE['theMainImageWidth']:$theMainImageSize[0];
216    $theMainImageHeight=   isset($_COOKIE['theMainImageHeight'])?$_COOKIE['theMainImageHeight']:$theMainImageSize[1] ;
217
218  if($theImageHeight!=0 && $theImageWidth!=0){
219      $pictureDeriv=$retour->type ;
220   }else{
221      $pictureDeriv=$default_size;
222   }
223}
224 
225 if(preg_match("|test|", $DEBUG_autosize, $val)) { 
226    $infos_message .=  "#208 <br>Init:SESSION:"  . cl_print_var($_SESSION) ;
227   
228    if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
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);
233 }
234 $pattern = array();
235  if($has_pamoorama=="true"){ 
236  if(preg_match("|c1|", $DEBUG_autosize, $val)) echo  $theImageWidth . "x" . $theImageHeight ;
237      $pattern[0] = '/width\:(.*)(\d+),/';$replacement[0] = 'width:  '.$theImageWidth.' ,'; 
238      if(($theImageWidth!=0)){     
239            $content=  preg_replace($pattern, $replacement, $content);
240        }
241         if(preg_match("|c1|", $DEBUG_autosize, $val)) {
242         echo "<!-- " . $theImageWidth . "x" . $theImageHeight . " " .cl_print_var($content) ." -->";
243         self::Fin_php("#225: " . $DEBUG_autosize);
244    }
245      return  $content;
246  }
247if(isset($_GET['map'])){
248return  $content;
249}
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] = ' ';
254
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
263  $ncount=1;   
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);
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);
269  }else{
270      $content=str_replace( "<iframe" ,  "<iframe id='iframe' name='theMainImage' "  ,$content,$ncount);
271  }
272  $content=  preg_replace($pattern, "", $content);
273
274  $content= "<div id='theMainImage' style='height:".$theImageHeight."px  ;width:".$theImageWidth."px '>". $content . "</div>";
275 $content= "<style>#theImageAndInfos{height:auto;width:auto;position:relative}
276  #theImage{height:auto;align:center;text-align:center;position:relative}
277  #theMainImage{height:auto;align:center;text-align:center;position:static} 
278  #charlie{display:none }
279  #iframe{display:none }
280 </style>".$content;
281return  $content;
282 }
283 
284   $content=  preg_replace($pattern, "", $content);
285
286  return  $content;
287}//INIT
288
289/************************
290*  INIT 2
291*************************/
292static public function init2($content,$element_info){
293
294
295global  $template,$version,$icon_path,$page,$picture,$conf;
296global $user,$Css,$css_slideshow,$css_display,$liste_type;
297global $infos_message;
298//content = photo
299
300//=====================================================================
301  global  $has_pamoorama,$pictureSelType,$pictureDeriv;
302  global $DEBUG_autosize;
303  if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "init2, ";} ;
304   global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
305  //-- si Autosize correction redim ---------------
306  $current = $template->get_template_vars('current'); 
307  if (!isset($current)) return ;
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);
313if( $has_pamoorama=="true") return $content ;
314
315if( !preg_match("|c1|", $DEBUG_autosize, $val) ) return $content ;
316//************************  c1 ***************************************
317   echo "theMainImageWidth :" . $theMainImageSize[0] . " X " . $theMainImageSize[1]  . "<br >";
318   echo "theImageWidth :" . $theImageWidth . " X " . $theImageHeight . "<br >";
319   echo $infos_message."<br />";
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;'>";
338 self::Fin_php("#320 : " . $content + $DEBUG_autosize);
339   
340} //INIT2
341/***************************
342*
343***************************/
344static public  function reload($id_ret){
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
351  $set_miniature = "<!DOCTYPE html><html><head>
352   <meta http-equiv='content-type' content='text/html; charset=UTF-8'/>
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>
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>";     
357   
358    $set_miniature .= "<script type='text/javascript' src='".PHPWG_ROOT_PATH."plugins/Autosize/js/autosize_ajax.js' id='autosize_ajax' >  </script >";
359
360   $set_var = "<script type='text/javascript'>\n var COOKIE_PATH =  '".cookie_path()."';\n"; 
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"; 
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"; 
372
373   $set_var .= " </script >";
374   
375$autoscript="
376      </head>
377      <body onload=on_load() style='background-color:black;color :white;font-size:30px '  > 
378     please wait, loading($id_ret)...
379     <div></div>
380      </body></html>";   
381     
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);
411  self::Fin_php("#393: ".$DEBUG_autosize);
412}
413
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']) ;
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) ;
421        self::Fin_php("#403: ".$DEBUG_autosize);
422    }
423
424     $infos_message.="Reload: $userst <br> $usertype <br> autosize_parametres:"  . cl_print_var($autosize_parametres) ; 
425     if(!preg_match("|aff_init|", $DEBUG_autosize, $val)) { $infos_message=""; }
426        echo $set_miniature ;
427        echo $set_var ;       
428        echo $autoscript;       
429        if (!isset($_COOKIE['autosize_reload'])  ){ 
430            self::Fin_php("#424: ".$DEBUG_autosize);
431    } 
432  //     
433       
434}
435
436 /************************
437 *  cl_autosize_script_1
438 *************************/
439 static public function cl_autosize_script_1(){
440  global $user,$page,$template,$cl_plugin,$cl_version;
441    global  $has_pamoorama,$css_slideshow; 
442    global $pictureSelType,$pictureDeriv,$infos_message,$conf;
443    global $DEBUG_autosize;
444 if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "cl_autosize_script_1, " ;} ;
445    $ma_page=isset($page['body_id'])?$page['body_id']:"" ; 
446    if ($ma_page !='thePicturePage') return ; 
447    if ( $has_pamoorama=="false" ) return ; 
448 if ($page['slideshow']){
449 //==== mise à l'échelle ===
450    $current = $template->get_template_vars('current'); 
451    $default_size =  $conf['derivative_default_size'];
452
453    if(isset($current['selected_derivative'])) {
454        $model=$current['selected_derivative']->get_type() ;
455    }else{
456        $model=$default_size;
457    }
458   
459    $selected_derivative =  $current['derivatives'][$model]; 
460    $template->append('current', array(
461                                'selected_derivative' => $selected_derivative
462                                    ), 
463                      true);
464
465 }
466 
467
468
469    $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
470    $autosize_parametres =       cl_autosize_Get_Options() ;                   
471    $theme=$user['theme'];
472    //==============================================================================
473    $template->assign(
474      array(   
475          'autosize_parametres' => $autosize_parametres ,
476          'cl_plugins' => $cl_plugin ,
477          'cl_version' => $cl_version ,
478          'name' => $cl_plugin['name'] ,
479          'has_pamoorama' => $has_pamoorama,                                                             
480          'theme' => $theme  , 
481          'DEBUG_autosize' => $DEBUG_autosize,
482          'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
483          'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
484          'Version_pwg' => PHPWG_VERSION ,
485          'slide_show' => $page['slideshow']
486         )
487    );
488   if( preg_match("|c2|", $DEBUG_autosize, $val) ){ 
489   self::Fin_php( "446: " . $DEBUG_autosize);
490   return $content ;
491
492   }
493 
494    return $template->parse( 'autosize_init', false);
495
496
497        }// function cl_autosize_script_1
498
499 /*************************************
500 * cl_autosize_script_2()
501 **************************************/
502 static public function cl_autosize_script_2()
503 {  global $css_slideshow;
504   global $pictureSelType,$pictureDeriv,$infos_message;
505           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$cl_version,$known_script ;
506 
507     global  $has_pamoorama; 
508     global $DEBUG_autosize;
509  if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "cl_autosize_script_2, ";} ;
510    $ma_page=isset($page['body_id'])?$page['body_id']:"" ;   
511    if ($ma_page !='thePicturePage') return ; 
512 
513    $theme=$user['theme'];
514    if ($has_pamoorama=="false" ) return ; 
515    if ($css_slideshow == "no" and isset($_GET['slideshow'])) return ;   
516                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
517//=====================================================================
518                        $template->assign(
519                                        array(
520                                        'cl_version' => $cl_version ,
521                                        'name' => $cl_plugin['name'] ,
522                                        'ma_page' =>    $ma_page,
523                                        'theme' => $theme  ,
524                                        'DEBUG_autosize' => $DEBUG_autosize   ,
525                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH         
526                                        )
527                                                );
528                        $autoscript="<script type='text/javascript'>
529                        /* cl_autosize_script_2 */
530                        if (typeof (save_framework) == 'function')
531                           save_framework('".$ma_page."'); 
532     
533                        </script>";
534                $template->append('footer_elements',$autoscript); 
535     
536                return ; 
537 }// function cl_autosize_script_2
538
539  /*************************************
540 * cl_autosize_script_3()
541 **************************************/
542 static public function cl_autosize_script_3() {
543    global  $has_pamoorama,$template,$page,$infos_message;
544     global $DEBUG_autosize;
545      if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "cl_autosize_script_3, ";} ;
546$ma_page=isset($page['body_id'])?$page['body_id']:"" ;
547if ($ma_page !='thePicturePage') return ; 
548
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'>   
567                        if (typeof (Ajout_Ajax) == 'function')
568                           Ajout_Ajax(); 
569                        </script>";
570                $template->append('footer_elements',$autoscript); 
571
572     
573                return ; 
574 }// function cl_autosize_script_3
575
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;
594    global $DEBUG_autosize;
595      global $css_slideshow,$css_display; 
596      if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .=  "cl_autosize_affiche, " ;} ;
597$ma_page=isset($page['body_id'])?$page['body_id']:"" ;
598if ($ma_page !='thePicturePage') return ; 
599//============================================================
600 self::save_cookies();
601
602    if(isset($set_miniature)){
603          $set_miniature = self::cl_autosize_nofile($set_miniature) ;
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); 
614      }
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);
620
621 include_once (AUTOSIZE_PATH."include/affiche.php");   
622
623     $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
624     if ($css_display=="none"  &&  $has_pamoorama=="true" ) {   
625            $css_display="block" ;
626         }
627         $file_css=AUTOSIZE_PATH."css/".$theme.".css";
628         if (!file_exists($file_css))  $file_css="no";     
629     if ($css_display=="none" ) {       
630        return ;
631      } 
632     if($pictureSelType == $pictureDeriv ) {
633         if(preg_match("|event|", $DEBUG_autosize, $val)) {  cl_aff_infos_plus();} ;
634   
635     } 
636     
637    if (defined('GMAPS_VERSION')) $gmaps_function="true";
638          else $gmaps_function="false" ;
639
640
641
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,                                 
646                                  'theme' =>$theme,
647                                   'gmaps_function' => $gmaps_function
648                          ));
649        $template->concat('autosize_content', $template->parse('autosize_content_header', true)); 
650
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      }   
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}
701 
702   if(preg_match("|test|", $DEBUG_autosize, $val)) { 
703    $infos_message .= "#683 <br>cl_autosize_affiche:_COOKIE:"  . cl_print_var($_COOKIE) ;   
704    $pictureMap=$_COOKIE['picture_map'];
705    $infos_message .= "<br />SelType:" . $pictureSelType."; pictureDeriv:".$pictureDeriv ."; pictureMap:".$pictureMap;
706   
707    self::Fin_php("#686: ".$DEBUG_autosize);
708 } 
709       cl_aff_infos_plus();
710        return $template->parse( 'autosize_content', false);
711        } //public function cl_autosize_affiche
712
713
714/****************************************
715*
716****************************************/
717function Get_Options(&$parametres,$str_index){
718    global $conf ;
719     if (!isset( $conf[$str_index]))  {   
720      $conf[$str_index]="";
721     }
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
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 
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" ;
756    $def_para['defaut_type'] =  "off" ;
757
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  }
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//================================================
815static public function css($theme_local) {     
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
830               if(!file_exists($mycssfile)){             
831              return Array();
832               }
833
834      $ret =   file_get_contents ($mycssfile);
835
836    function remove_comments( & $string ) { 
837       $string = preg_replace('#/\*.*?\*/#s',"",$string); 
838       return $string;
839     }
840
841    $order   = array("\r\n", "\n", "\r"," ");
842    $replace = '';
843    $newstr = str_replace($order, $replace, $ret); 
844
845    $order   = array('"');
846    $replace = "'";
847    $newstr = str_replace($order, $replace, $newstr); 
848
849
850    $order   = array("}");
851    $replace = '}\r\n';
852    $newstr = str_replace($order, $replace, $newstr);
853    remove_comments($newstr);
854
855    $newstr = explode('\r\n',$newstr);
856    $css=Array();
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
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 ;
885   global $DEBUG_autosize;
886 
887
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);
905
906    $retour = (object) '';
907    $maxi_image = (object) '';
908    $mini_image = (object) '';
909    $std_image  = (object) '';
910    $default_image=(object) '';
911    $SelType_image=(object) '';
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 ;
922  $nofile=0 ;      global $max_crop;
923  //=============================================
924  // Liste mini maxi
925  //=============================================
926    foreach ($img_all as $img_select){
927
928            $img_type  =  $img_select->get_type();     
929            $img_url  = $img_select->get_path();     
930              $max_crop = 0 ;
931            $imgWH  =  self::Get_Size($img_select);       
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++ ;   
940                   if(preg_match("|get_infos|", $DEBUG_autosize, $val)) 
941                  $infos_message .=$nofile ." " ;
942            }         
943             if(preg_match("|get_minfos|", $DEBUG_autosize, $val)) 
944                      $infos_message .=$img_url . " " . $max_crop ." -> " . $img_type . " " . print_r($imgWH,true). " <br >";
945
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                          }
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 >";
973
974                          $SelType_image->type=$img_type;
975                          $SelType_image->url=$img_url;
976                          $SelType_image=$img_select;   
977                    }
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                                                             
1004                               $maxi_image->url  =  $maxi_image->get_path();
1005
1006                            } else { 
1007                           
1008                                $mini_image->type=$img_type;
1009                                $mini_image->url=$img_url;
1010                                $mini_image=$img_select; 
1011                               $mini_image->url  =  $mini_image->get_path();           
1012                            }                         
1013       
1014      } // for
1015      //================================================ 
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     
1021 
1022          $retour=(object)'' ;
1023      if ($pictureSelType=="Autosize") $retour= $maxi_image ;
1024      else if ($pictureSelType=="SelMaxi") $retour= $mini_image ;
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     }
1035
1036  if (!isset( $retour->type)){     
1037                  $retour=$last_image;
1038                  $retour->type =  $retour->get_type();
1039                  $retour->url  =  $retour->get_path();
1040               
1041}
1042if (isset( $retour->type) && $retour->type=="Original" ){     
1043                  $retour=$last_image;
1044                  $retour->type =  $last_derivative;
1045                  $retour->url  =  $retour->get_path();
1046             
1047}
1048      if($nofile > 0){ 
1049        $set_miniature=$No_files ;
1050      }
1051
1052    if(preg_match("|get_infos|", $DEBUG_autosize, $val)) 
1053            $infos_message .=$pictureSelType . " -> " . $retour->type . " : "  . $retour->url  ."<br >";
1054
1055return $retour ;
1056
1057  }
1058  //=================================================================
1059
1060static public function Get_Size($Img_Select){
1061      global  $max_crop;
1062            $imgWH  =  $Img_Select->get_size();   
1063            $img_type  =  $Img_Select->get_type();     
1064            if( $img_type =="Original")  return ;
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      }
1073//==================================================================
1074static public  function  cl_autosize_nofile($img_all){
1075 //=== verification fichiers absents ===
1076 global $infos_message,$error_message;
1077 global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
1078global  $pictureDeriv;
1079  $ok=false ;
1080 $nofiles=array();
1081 $file_no=(object) '';
1082
1083 $nosrc=false ;
1084 $ok=true ;
1085 $listes="";     
1086  foreach ($img_all as $img_select){
1087    $img_url  = $img_select->get_url();
1088    if(!file_exists(PHPWG_ROOT_PATH.$img_url)){   
1089      $img_type  =  $img_select->get_type();     
1090     
1091      $file_id=explode("?",$img_url); 
1092      if(count($file_id) ==1){
1093          $file_id[]=$file_id[0] ;
1094      }   
1095        if ( !preg_match("|".$file_id[1]."|", $listes) ){
1096              $listes  .=  $file_id[1] ."<br />";
1097              $file_no->url= $file_id[1] ;         
1098              $id  =  $img_select->src_image->id;                 
1099              $file_no->id=$id ;
1100              $file_no->type=$img_type ; 
1101              array_push($nofiles,serialize($file_no)) ;   
1102               if( $img_type == $pictureDeriv){
1103         
1104          break ;
1105    }           
1106      }
1107      $ok=false ;     
1108    }
1109  }
1110  $exec_miniatures="";
1111  if(count($nofiles)>0){
1112  //=======================================================================================
1113    if($nosrc!=true  ){
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 ;
1117    } 
1118    $exec_miniatures ="";
1119      $script_miniatures .= "<script type='text/javascript'>
1120        var nofile=Array(";
1121        for ($i=0;$i  <  count($nofiles)-1 ;$i++){       
1122             $file = unserialize($nofiles[$i]);
1123             $exec_miniatures .=  "{id:'".$file->id."',type:'". $file->type."',file:'". $file->url."',width:'".$theMainImageSize[0]."', height:'".$theMainImageSize[1]."'},\n" ;
1124          } 
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' >
1135          if(typeof nofile!='undefined')
1136              getDerivativeUrls(nofile);
1137      </script>";
1138      //==================================================================================
1139      return $script_miniatures  ;
1140    }
1141 }
1142 /***************************
1143 *  get_cookies
1144 ****************************/
1145 static public  function  get_cookies(){
1146  global $pictureDeriv,$pictureSelType,$pictureDeriv,$pictureMap;
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(){
1166  global $pictureDeriv,$pictureSelType,$pictureDeriv,$pictureMap;
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}
1193
1194static public function Fin_php($message_){
1195global  $infos_message;
1196 echo "End :".$message_."<br>";
1197die($infos_message);
1198}
1199 //==================================================
1200} // class
1201
1202/*************************************
1203        *
1204 *************************************/
1205 function cl_autosize_Get_Options()
1206  {
1207                global $conf,$autosize_parametres; 
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
1221                $autosize_parametres =  unserialize($conf['cl_autosize']);
1222      // $autosize_parametres = self::Get_Options($autosize_parametres,'cl_autosize');
1223                $autosize_parametres =  cl_autosize_Set_Options();
1224                return $autosize_parametres;
1225  }
1226        /*
1227        *
1228        */
1229function cl_autosize_Set_Options() {
1230  global $autosize_parametres;
1231//=============================================================================
1232$my_para=$autosize_parametres;
1233  if (empty($my_para))
1234$my_para = (object) '';
1235
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') ;
1238
1239$my_para->webmaster_type =(isset($_POST['webmaster_type'])) ? $_POST['webmaster_type'] : ((isset($my_para->webmaster_type )) ? $my_para->webmaster_type : 'Autosize' ) ;
1240
1241$my_para->admin_type =(isset($_POST['admin_type'])) ? $_POST['admin_type'] : ((isset($my_para->admin_type )) ? $my_para->admin_type : 'Autosize' ) ;
1242
1243$my_para->generic_type =(isset($_POST['generic_type'])) ? $_POST['generic_type'] : ((isset($my_para->generic_type )) ? $my_para->generic_type : 'Autosize' ) ;
1244
1245
1246$my_para->guest_type =(isset($_POST['guest_type'])) ? $_POST['guest_type'] : ((isset($my_para->guest_type )) ? $my_para->guest_type : 'Autosize' ) ;
1247
1248
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
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
1259$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
1260$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
1261$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
1262
1263//===============================================================================       
1264
1265if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
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" ;
1268        $my_para->defaut_type= isset($_POST['defaut_type']) ? $_POST['defaut_type'] : "off" ;
1269
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" ;
1275
1276         }else{
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') ; 
1279                $my_para->defaut_type = isset($_POST['defaut_type']) ? $_POST['defaut_type'] : ( ( isset($my_para->defaut_type) ) ? $my_para->defaut_type :   'off') ; 
1280
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') ; 
1286
1287
1288   }
1289
1290return $my_para;
1291}
1292        /*
1293        *
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();
1300 if ( isset($autosize_parametres) )     { 
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          }
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      }
1315 }
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  }
1329}
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}
1368
1369?>
Note: See TracBrowser for help on using the repository browser.