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

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

[extensions] Autosize fix compatibility with 2.4 (compatibility charlie's,iframe )

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