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

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

[extensions] Autosize fix compatibility with 2.4, fix bug on line 631

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