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

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

[extensions] Autosize fix compatibility with 2.4, fix bug

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