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

Last change on this file since 18115 was 18115, checked in by cljosse, 12 years ago

[extensions] Autosize fix compatibility with 2.4, fix bug

File size: 29.0 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_controler {
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* INIT
34*********************/
35static public function init($content){
36  // header ('X-UA-Compatible: n=7')  ;
37 // header ('X-UA-Compatible: IE=Edge')  ;
38 global  $template,$version,$icon_path,$page,$picture,$conf;
39 
40   $current = $template->get_template_vars('current'); 
41      $has_pamoorama=isset($template->files['pamooramics_content']);
42 //====================================================================   
43    $pictureDeriv = pwg_get_session_var('picture_deriv',$conf['derivative_default_size']); 
44    $SRC_IMG=""; 
45    if(isset($current['derivatives']['Autosize']))
46       $_COOKIE['picture_deriv']="Autosize";
47   if(isset( $_COOKIE['picture_deriv']))
48      $model=  $_COOKIE['picture_deriv'] ;
49   else
50      $model= $pictureDeriv ;
51
52   $selected_derivative =  $current['derivatives'][$model];
53   if (!isset($current['selected_derivative'])){ 
54
55   $_COOKIE['picture_deriv']="Autosize";
56    $model=  $_COOKIE['picture_deriv'] ;
57         $current['SelMaxi']=ImageStdParams::get_custom(900,900); 
58         $current['derivatives'][$model]=ImageStdParams::get_custom($_COOKIE['theImageWidth'], $_COOKIE['theImageHeight']); 
59
60
61$selected_derivative=$current['derivatives'][$model];
62$selected_derivative->type="Autosize";
63          $template->append('current', array(
64                                        'selected_derivative' => $selected_derivative
65                                            ), 
66                             true);
67          $current = $template->get_template_vars('current');
68        }
69 
70        if(isset($current['derivatives'][$model])) {
71            $selected_derivative =  $current['derivatives'][$model];
72            $template->assign('current[selected_derivative]', $selected_derivative
73                              , true);
74            $current = $template->get_template_vars('current'); 
75        }
76
77    return $content;
78
79}//INIT
80/**************************
81*  autosize_calcContent   *
82**************************/
83 static public function autosize_calcContent($content){
84  global $conf,$page, $template,$picture,$user; 
85  global $defined_types,$maxi_img ,$pictureDeriv ,$liste_type,$SRC_IMG,$select_type;
86  global  $has_pamoorama;
87  global $autosize_parametres,$user_status;
88$defined_types = array_keys(ImageStdParams::get_defined_type_map());   
89//===============================================================
90 if(isset($page['body_id']) &&  $page['body_id'] == 'theAdminPage' ) return ;   
91    if (!isset($_COOKIE['autosize_reload'])){   
92            $autoscript="<script type='text/javascript' src='themes/default/js/jquery.min.js'></script>                        <script type='text/javascript' src='plugins/Autosize/js/autosizeDetect.js'></script>
93      <script type='text/javascript' src='plugins/Autosize/js/autosize.cookie.js'></script>
94      <body onload=on_load() style='background-color:black;color :white;font-size:30px '  > 
95     please wait, loading...
96      </body>";   
97                  echo $autoscript; 
98      die();
99    } 
100  $current = $template->get_template_vars('current'); 
101  if (!isset($current)) return ;
102//===============================================================
103    $derivative = $current['src_image'] ;
104    $imgScaledWH = $derivative->get_size();
105    $SRC_IMG    = $derivative->get_url(); 
106    $picture['current']['scaled_width']=$imgScaledWH[0];
107    $picture['current']['scaled_height']= $imgScaledWH[1];
108    $picture['current']['high_url']= $SRC_IMG;   
109    $picture['current']['image_url']=$SRC_IMG; 
110//===============================================================
111 
112    $user_status = $user['status'] ;
113    $autosize_parametres = cl_autosize_Get_Options();
114    $user_type= get_user_status($user_status)."_type";
115    $select_type=$autosize_parametres->$user_type ;
116 
117
118  if (isset($_COOKIE['theImageHeight'])){   
119      pwg_set_session_var('theImageWidtht',$_COOKIE['theImageWidth']); 
120      pwg_set_session_var('theImageHeight',$_COOKIE['theImageHeight']);   
121  } 
122if (isset($_COOKIE['theMainImageHeight']))  pwg_set_session_var('theMainImageHeight',$_COOKIE['theMainImageHeight']); 
123if (isset($_COOKIE['theMainImageWidth']))  pwg_set_session_var('theImageWidth',$_COOKIE['theMainImageWidth']); 
124
125
126if (isset($_COOKIE['picture_deriv'])) 
127    pwg_set_session_var('picture_deriv',$_COOKIE['picture_deriv']); 
128else 
129  pwg_set_session_var('picture_deriv',$select_type); 
130
131 
132$model=   $conf['derivative_default_size'] ; // par defaut
133  $pictureDeriv = pwg_get_session_var('picture_deriv',  $model); 
134
135 
136 $model=$pictureDeriv ;
137
138    $value=0;
139    $liste_type="";
140    $maxi_info="";
141    if($model!="Autosize" & $model!="SelMaxi"){
142     
143    }else{
144        $model=$conf['derivative_default_size'] ; 
145    }
146    $derivative=$current['derivatives'][$model] ; 
147    $img_all= $derivative->get_all($derivative->src_image);
148    $maxi_img="";
149    $mini_img="";
150    $maxi_url="";
151    $imgSizeWH  = $derivative->get_size();     
152    //==== valeur taille image ====
153   
154     $window_width=$imgSizeWH[0];
155     $window_height=$imgSizeWH[1];
156 //echo "<div style='background-color:black;color:white' >INIT: $model  w:$window_width x  h:$window_height  </div>";
157
158   
159   $window_width = pwg_get_session_var('theMainImageWidth',$imgSizeWH[0]); 
160 $window_height =  pwg_get_session_var('theMainImageHeight',$imgSizeWH[1]);
161
162if (!isset($_COOKIE['theMainImageHeight']))    setcookie('theMainImageHeight', $window_height ); 
163if (!isset($_COOKIE['theMainImageWidth']))  setcookie('theMainImageWidth',$window_width); 
164
165//echo "<div style='background-color:black;color:white' >$select_type w: $window_width x h: $window_height  </div>";
166
167    $last_defined=ImageStdParams::get_defined_type_map();   
168
169    foreach ($img_all as $img_select){
170            $img_type  =  $img_select->get_type();     
171            if ($img_type=="square" || $img_type=="thumb" ) continue ;
172            if (!isset($last_img)) $last_img=$img_select; 
173            $img_url  = $img_select->get_url();
174            $imgSizeWH  =  $img_select->get_size();     
175            if($img_type=="Autosize" || $img_type=="SelMaxi"){
176                $img_url = $img_select->src_image->get_url();
177                $imgSizeWH  =  $img_select->src_image->get_size();
178                $liste_type[$img_type]=$img_type.",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1] ;
179            }else{ 
180            $liste_type[$img_type]=$img_type.",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1] ;
181            if ($img_type=="Original"){
182         
183            break ;
184            }
185           
186               
187
188              if($window_height < $imgSizeWH[0] ){
189                          $maxi_img=  $img_type;
190                          $maxi_url= $img_url;
191                          $maxi_i=$img_select;
192              }
193              if($window_height < $imgSizeWH[0] && $mini_img==""){ 
194                      $mini_img=  $img_type;
195                      $mini_url= $img_url;
196                      $mini_i=$img_select;
197                     
198                 }else if($imgSizeWH[0] > 10 && $maxi_img==""){ 
199                      $last_img=$img_select;
200              }
201
202 
203               if($select_type==$img_type){ 
204                  if($maxi_img==""){
205                      $maxi_img=  $img_type;
206                      $maxi_url= $img_url;
207                      $maxi_i=$img_select;
208                  }
209                     
210                      break ;
211                    }
212         }
213
214      }
215 
216//==============================================================   
217  //==== Réécriture selection ====
218  if( $img_type=="SelMaxi"){
219  $maxi_img= $mini_img;
220  $maxi_url= $mini_img;
221  }
222  if ( !array_key_exists($maxi_img, $last_defined) ){
223            $maxi_img = $last_img->get_type();   
224            $maxi_url  = $last_img->get_url();
225            $imgSizeWH  =  $last_img->get_size();       
226  }
227    $model= $maxi_img;
228    pwg_set_session_var('picture_deriv', $maxi_img);
229    $_COOKIE['picture_deriv']=$maxi_img ;
230    $_COOKIE['picture_map']=  $maxi_img ;
231    $_COOKIE['imgSrc']=       $maxi_url;
232
233  if (isset($_COOKIE['picture_deriv'])){   
234      if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) ){
235            pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
236        }else{
237        echo "<pre>".$_COOKIE['picture_deriv']. "No exist  " ;
238        print_r($img_all );
239        die();
240        }
241    setcookie('picture_deriv', false, 0, cookie_path() );
242  } 
243
244 
245return false ;
246
247 }
248
249/************************
250* cl_autosize_affiche
251*************************/     
252        static public function cl_autosize_affiche(){
253                global $user, $picture, $template,$page,$known_script;
254                global $content, $element_info;   
255                global $infos_message,$erreur_message;
256                global  $conf,$lang ,$user,$userdata;
257      global $defined_types,$maxi_img ,$pictureDeriv ,$liste_type,$SRC_IMG,$select_type;
258  global  $has_pamoorama;
259  global $autosize_parametres,$user_status;
260
261    if(isset($page['body_id']) &&       $page['body_id'] == 'theAdminPage' ) return ;   
262
263 if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
264                load_language('plugin.lang', AUTOSIZE_PATH);
265                $AUTOSIZE_PATH = dirname(__FILE__).'/';
266                 if (isset( $page['body_id']) && $page['body_id']=='thePicturePage'  ) {
267
268                        if ( isset($picture['current'])){       
269                                include (AUTOSIZE_PATH."include/affiche.php"); 
270
271        $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
272        $template->set_filenames(array('autosize_content_header'=> $file )); 
273        $template->assign(
274                                        array( 
275            'select_type' =>$select_type,
276            ));
277
278        $template->concat('autosize_content', $template->parse('autosize_content_header', true)); 
279
280        $file =AUTOSIZE_PATH_ABS.'template/header.tpl' ;
281        $template->set_filenames(array('autosize_init_header'=> $file ));
282        $template->parse( 'autosize_init_header', false);     
283
284                $theme=$user['theme']; 
285                                       
286                                if($autosize_parametres->check_icon_v == 'on'){                         
287                                                $template->assign('cl_autosize_button', 
288                                                array(  'cl_autosize_info' => 'cl_autosize_info' ,
289                    'cl_autosize_info_1' => 'cl_autosize_info_' , 
290                                                                    'cl_autosize_info_2' => 'cl_autosize_info_2' ,   
291                                                                    'URL' => $_SERVER['REQUEST_URI'] ,
292                                                                    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
293                                                                    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png',
294                    'ICON1' => AUTOSIZE_PATH . 'icons/button-no.png'
295                                                                )
296
297                                                        ); 
298                                        $template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
299                                        $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
300                                }
301                                 $template->set_filenames(
302                                                array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl',
303             'theme' => $theme   )
304                                        );
305                        $template->concat('autosize_content', $template->parse('autosize_content_header', true));       
306       
307      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
308        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
309        $template->func_combine_script(array('id'=>'my_script_2',
310        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
311        'require' => 'jquery'),
312        $template->smarty);
313        $template->assign(array( 
314                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
315                          ));                                   
316        $template->parse('mes_script');
317      }   
318        return $template->parse( 'autosize_content', false);
319                                  }
320                }
321
322        } //public function cl_autosize_affiche
323
324   /************************
325 *  cl_autosize_script_1
326 *************************/
327 static public function cl_autosize_script_1(){
328  global $user,$page,$template,$cl_plugin;
329    if(isset($page['body_id']) &&       $page['body_id'] == 'theAdminPage' ) return ;   
330 
331    $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
332    if ($ma_page=='thePiwiShackControllerPage') return ;   
333    if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
334    global  $has_pamoorama;
335    $has_pamoorama=isset($template->files['pamooramics_content']);
336  if (!$has_pamoorama) return ; 
337
338    $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
339    $autosize_parametres =       cl_autosize_Get_Options() ;                   
340    $theme=$user['theme'];
341    //==============================================================================
342    $DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
343    $DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] :  $DEBUG_autosize ;
344    $DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ;
345    //==============================================================================
346    $template->assign(
347      array(   
348          'autosize_parametres' => $autosize_parametres ,
349          'cl_plugins' => $cl_plugin ,
350          'cl_version' => $cl_plugin['version'] ,
351          'name' => $cl_plugin['name'] ,
352          'pamoorama' =>  $has_pamoorama,                                                               
353          'theme' => $theme  , 
354          'DEBUG_autosize' => $DEBUG_autosize,
355          'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
356          'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
357          'Version_pwg' => PHPWG_VERSION           )
358    );
359    return $template->parse( 'autosize_init', false);
360        }// function cl_autosize_script_1
361
362 /*************************************
363 * cl_autosize_script_2()
364 **************************************/
365 static public function cl_autosize_script_2()
366 {
367           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$known_script ;
368                global  $template,$user,$conf,$picture ,$page, $cl_plugin ;
369            if(isset($page['body_id']) &&       $page['body_id'] == 'theAdminPage' ) return ;   
370   
371   if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
372     global  $has_pamoorama;
373       if (!$has_pamoorama) return ; 
374     
375                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
376//================================================================
377$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
378$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
379$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
380//=====================================================================
381    $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
382    $theme=$user['theme'];
383    if ($ma_page=='thePiwiShackControllerPage') return ;
384    $img_width=isset($picture['current']['width'])?$picture['current']['width']:480;
385    $img_height=isset($picture['current']['height'])?$picture['current']['height']:320;
386    $img_scaled_width=isset($picture['current']['scaled_width'])?$picture['current']['scaled_width']:480;
387    $img_scaled_height=isset($picture['current']['scaled_height'])?$picture['current']['scaled_height']:320;
388    $src_img_h=isset($_POST['src_img_h'])?$_POST['src_img_h']: $img_width               ;
389    $src_img_w= isset($_POST['src_img_w'])?$_POST['src_img_w']:$img_height              ;
390
391
392  include_once (PHPWG_ROOT_PATH.'include/functions_cookie.inc.php') ;
393if(isset($_COOKIE['img_w'])){
394    $src_img_w=$_COOKIE['img_w'];
395    $src_img_h=$_COOKIE['img_h'];
396}
397
398$window_height= isset($_SESSION['height'])?$_SESSION['height']: $img_scaled_height ;
399$window_width= isset($_SESSION['width'])?$_SESSION['width']: $img_scaled_width    ;
400
401
402$size=array(
403            'src_img_h' => $src_img_h,
404            'src_img_w' => $src_img_w,
405            'window_height' =>$window_height,
406            'window_width' => $window_width
407
408          );
409
410                        $template->assign(
411                                        array(
412                                        'cl_version' => $cl_plugin['version'] ,
413                                        'name' => $cl_plugin['name'] ,
414                                        'ma_page' =>    $ma_page,
415                                       
416                                        'theme' => $theme  ,
417                                        'DEBUG_autosize' => $DEBUG_autosize   ,
418                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH,
419          'Size' => $size
420           
421                                        )
422                                                );
423
424                        $autoscript="<script type='text/javascript'>
425                        /* cl_autosize_script_2 */
426                        if (typeof (save_framework) == 'function')
427                           save_framework('".$ma_page."'); 
428       var cookie_path   ='". cookie_path() ."'
429                        </script>";
430                $template->append('footer_elements',$autoscript); 
431                return ; 
432 }// function cl_autosize_script_2
433  /*************************************
434 * cl_autosize_script_3()
435 **************************************/
436 static public function cl_autosize_script_3() {
437           global  $template,$page;
438    if(isset($page['body_id']) &&       $page['body_id'] == 'theAdminPage' ) return ;   
439          global  $has_pamoorama;
440       if (!$has_pamoorama) return ; 
441
442                        $autoscript="<script type='text/javascript'>                   
443                        if (typeof (Ajout_Ajax) == 'function')
444                           Ajout_Ajax(); 
445                        </script>";
446                $template->append('footer_elements',$autoscript); 
447                return ; 
448 }// function cl_autosize_script_3
449
450        //===============================================================
451                /*
452        *
453        */
454        static public function cl_autosize_aff_infos_plus()
455                {
456                 global $template,$infos_message,$erreur_message, $user ;
457                 global  $conf,$lang ;
458       
459                 //==============================================================
460                  if (isset($erreur_message))
461                                {       
462                                if ($erreur_message <> "")
463                                        {
464                                                $erreur_message=str_replace("\n",'<br />',$erreur_message) ;
465                                                $template->assign('errors',$erreur_message);
466                                                $erreur_message="";
467                                        }
468                                }
469                  if (isset($infos_message))
470                                {       
471               
472                                if ($infos_message <> "")
473                                        {
474                                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
475                                                $template->assign('infos',$infos_message);
476                                                $infos_message="";
477                                        }
478                                }
479                                //=============================================================
480                return;         
481               
482                } // function cl_autosize_aff_infos_plus
483        //===============================================================
484        /*
485         *
486        */
487        static public function cl_ajuste_data($content){
488                global  $template,$user,$conf,$picture ;
489      global $size;
490                $AUTOSIZE_PATH = realpath(AUTOSIZE_PATH .'/');
491                $userdata=$user;
492                $fields = array( 'maxwidth', 'maxheight' );
493         
494                $ThePicture = $template->get_template_vars('current'); 
495                $data = array();
496         return $content;
497
498                $data['maxwidth'] = $size['src_img_w'];
499                $data['maxheight'] =$size['src_img_h'];
500                $data['user_id'] = $userdata['id'];
501                foreach ($fields as $field)
502                {
503                        if (isset($_POST[$field]))
504                        {
505                                $data[$field] = $_POST[$field];
506                        }
507                }
508       
509                if($data['maxwidth'] != "" )
510                        {
511                        $picture['current']['scaled_width']=$data['maxwidth'];
512                        $picture['current']['scaled_height']=$data['maxheight'];
513                        mass_updates(USER_INFOS_TABLE,
514                                        array('primary' => array('user_id'), 'update' => $fields),
515                                        array($data)); 
516                        }
517                 
518                        return $content;                                                                                 
519                 }
520
521
522/****************************************
523*
524****************************************/
525function Get_Options(&$parametres,$str_index){
526    global $conf ;
527     if (!isset( $conf[$str_index]))  {   
528      $conf[$str_index]="";
529     }
530    $m_options=  $conf[$str_index];
531     if(isset($m_options))
532       if ( preg_match("|s:(.*)|", $m_options, $val) )
533        $parametres =  unserialize($conf[$str_index]);
534       else{
535         $parametres=explode(",",$_options);
536        }     
537        //====== par defaut =======================
538         $new_val=false;
539         $def_para=Array();
540
541    $def_para['query'] = 'Qt'  ;
542    $def_para['type'] = 'Ty' ;
543
544    $def_para['webmaster_type'] = 'Autosize' ; 
545    $def_para['admin_type'] = 'Autosize'  ; 
546    $def_para['generic_type'] = 'Autosize'  ;
547    $def_para['guest_type'] = 'Autosize'  ;
548    $def_para['normal_type']  =  'Autosize'  ;
549 
550
551
552    $def_para['mini_height'] =  '150' ;
553    $def_para['mini_width'] = '300' ;
554
555    $def_para['mini_height2'] =  '150' ;
556    $def_para['mini_width2'] =   '300' ;
557
558    $def_para['echelle_max'] =  '1.0'; 
559    $def_para['marge_basse'] =  '0';
560    $def_para['fade_in'] =   '0';
561    //==================================================
562    $def_para['check_desc_v'] =  "off" ;
563    $def_para['check_icon_v'] =  "off" ;
564   
565    $def_para['webmaster_enabled'] =   "off" ;
566    $def_para['admin_enabled'] =   "off" ;
567    $def_para['generic_enabled'] =   "off" ;
568    $def_para['guest_enabled'] =   "off" ;
569    $def_para['normal_enabled'] =   "off" ;
570    //===================================================
571   $para=$def_para;   
572    foreach ($para as $key => $value) {   
573      if( isset($parametres->$key) ){
574         $value=$parametres->$key;         
575      } 
576    if($def_para[$key] =="on" ||$def_para[$key] =="off" ){
577       $val_pg=(isset($_POST[$key]))? ($_POST[$key]=="off"||$_POST[$key]=="on")?$_POST[$key]:"on" : "off" ;
578       $value =(isset($_POST[$key]))? $val_pg : $value ; 
579       $val_pg=(isset($_GET[$key]))? ($_GET[$key]=="off"||$_GET[$key]=="on")?$_GET[$key]:"on" : "off" ;
580       $value =(isset($_GET[$key]))? $val_pg  : $value ; 
581     }else{
582        $value =(isset($_POST[$key]))? $_POST[$key] : $value ; 
583        $value =(isset($_GET[$key]))? $_GET[$key] : $value ; 
584      }
585        unset( $parametres->$key) ;
586        $parametres->$key = $value ;           
587     }   
588    return $parametres ;
589  }
590} // class
591
592/*************************************
593        *
594 *************************************/
595 function cl_autosize_Get_Options()
596  {
597                global $conf,$autosize_parametres; 
598    $autosize_parametres ="";
599 
600 if (!isset($conf['cl_autosize']))  {   
601  $conf['cl_autosize']="";
602  $q = '
603   INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
604   VALUES ("cl_autosize","","Parametres du plugin Autosize")
605  ;';
606  pwg_query($q);
607  }
608 
609 
610
611                $autosize_parametres =  unserialize($conf['cl_autosize']);
612      // $autosize_parametres = autosize_controler::Get_Options($autosize_parametres,'cl_autosize');
613                $autosize_parametres =  cl_autosize_Set_Options();
614                return $autosize_parametres;
615  }
616        /*
617        *
618        */
619function cl_autosize_Set_Options() {
620  global $autosize_parametres;
621//=============================================================================
622$my_para=$autosize_parametres;
623  if (empty($my_para))
624$my_para = (object) '';
625
626$my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
627$my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
628
629$my_para->webmaster_type =(isset($_POST['webmaster_type'])) ? $_POST['webmaster_type'] : ((isset($my_para->webmaster_type )) ? $my_para->webmaster_type : 'Autosize' ) ;
630
631$my_para->admin_type =(isset($_POST['admin_type'])) ? $_POST['admin_type'] : ((isset($my_para->admin_type )) ? $my_para->admin_type : 'Autosize' ) ;
632
633$my_para->generic_type =(isset($_POST['generic_type'])) ? $_POST['generic_type'] : ((isset($my_para->generic_type )) ? $my_para->generic_type : 'Autosize' ) ;
634
635
636$my_para->guest_type =(isset($_POST['guest_type'])) ? $_POST['guest_type'] : ((isset($my_para->guest_type )) ? $my_para->guest_type : 'Autosize' ) ;
637
638
639$my_para->normal_type =(isset($_POST['normal_type'])) ? $_POST['normal_type'] : ((isset($my_para->normal_type )) ? $my_para->normal_type : 'Autosize' ) ;
640
641
642
643$my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
644$my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
645
646$my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
647$my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
648
649$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
650$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
651$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
652
653//===============================================================================       
654
655if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
656                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
657                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
658       
659
660                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
661                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
662                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
663                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
664                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
665
666         }else{
667                $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') ; 
668                $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') ; 
669
670
671
672$my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ; 
673$my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ; 
674$my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ; 
675$my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
676$my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ; 
677
678
679   }
680
681return $my_para;
682}
683        /*
684        *
685        */
686function cl_autosize_sauve_options_inf()
687{
688global $options,$infos_message,$conf,$autosize_parametres  ;
689$infos_message .=l10n("cl_autosize_save_config")."<br>";
690 $autosize_parametres=cl_autosize_Set_Options();
691 if ( isset($autosize_parametres) )     { 
692                $query = '
693                UPDATE '.CONFIG_TABLE.'
694                SET value="'.addslashes(serialize($autosize_parametres)).'"
695                WHERE param = "cl_autosize"
696                LIMIT 1';
697                        pwg_query($query);
698          }
699    if (!isset($conf['cl_derivatives_sav']))  {   
700      $q = '
701        INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
702        VALUES ("cl_derivatives_sav","","sauvegarde derivatives")
703      ;';
704      pwg_query($q);     
705      }
706 }
707
708 function print_var($variables)
709{
710  ob_start();
711  echo '<pre>';
712  print_r($variables);
713  echo '</pre>';
714  $m= ob_get_contents();
715  ob_end_clean();
716  return $m;           
717}
718   
719
720?>
Note: See TracBrowser for help on using the repository browser.