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

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

[extensions] Autosize fix compatibility with 2.4, add theme directive

File size: 31.7 KB
RevLine 
[7375]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 {
[17503]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')  ;
[18325]38global  $template,$version,$icon_path,$page,$picture,$conf;
39global $user,$Css,$css_slideshow,$css_display;
[18234]40  $current = $template->get_template_vars('current'); 
[18325]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
[18127]48//====================================================================   
[18234]49  $pictureDeriv = pwg_get_session_var('picture_deriv',$conf['derivative_default_size']); 
50  $default_size =  $conf['derivative_default_size'];
51  $SRC_IMG=""; 
52//=====================================================================
[18325]53
[18234]54if(!isset($_COOKIE['picture_deriv']))
[18325]55    if(isset($current['derivatives']['Autosize'])){
[18234]56        $_COOKIE['picture_deriv']="Autosize";
[18325]57        }
58if(isset( $_COOKIE['picture_deriv'])) 
[18127]59  $model=  $_COOKIE['picture_deriv'] ;
60else
61  $model= $pictureDeriv ;
[18115]62
[18325]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
[18234]70 if(!isset($current['derivatives'][$model]))
71   $model=$default_size ;
[18325]72 
[18127]73$selected_derivative =  $current['derivatives'][$model];
[18325]74     /*
75      'selected_derivative' => $selected_derivative,
76      'unique_derivatives' => $unique_derivatives,
77      */
[18234]78
79
[18127]80if (!isset($current['selected_derivative'])){ 
[18234]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;
[18127]86  $template->append('current', array(
87                                'selected_derivative' => $selected_derivative
88                                    ), 
89                      true);
90  $current = $template->get_template_vars('current');
[18234]91   
[18127]92  }
[18115]93 
[18127]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'); 
[18325]98  } 
[18127]99return $content;
[17503]100
[18325]101
[17503]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'])){   
[17545]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>
[17503]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'); 
[18115]124  if (!isset($current)) return ;
[18325]125 
[17503]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//===============================================================
[18115]135 
[17503]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{
[18234]168        $model=$conf['derivative_default_size'] ;  // format par défaut
[17503]169    }
[18115]170    $derivative=$current['derivatives'][$model] ; 
[17503]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
[18234]181
[17503]182   
[18115]183   $window_width = pwg_get_session_var('theMainImageWidth',$imgSizeWH[0]); 
[17503]184 $window_height =  pwg_get_session_var('theMainImageHeight',$imgSizeWH[1]);
185
[18115]186if (!isset($_COOKIE['theMainImageHeight']))    setcookie('theMainImageHeight', $window_height ); 
[17503]187if (!isset($_COOKIE['theMainImageWidth']))  setcookie('theMainImageWidth',$window_width); 
188
[18325]189//================= Liste =========================
[18234]190    $last_defined=ImageStdParams::get_defined_type_map(); 
[17503]191    foreach ($img_all as $img_select){
192            $img_type  =  $img_select->get_type();     
193            if ($img_type=="square" || $img_type=="thumb" ) continue ;
[18234]194            if (!isset($last_img)) $last_img = $img_select; 
[18127]195           
[17503]196            $img_url  = $img_select->get_url();
197            $imgSizeWH  =  $img_select->get_size();     
[18234]198       
[18127]199
[17503]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] ;
[18234]204
205            } 
[18127]206              $liste_type[$img_type]=$img_type.",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1] ;
[18234]207 
[17503]208              if($window_height < $imgSizeWH[0] ){
209                          $maxi_img=  $img_type;
210                          $maxi_url= $img_url;
211                          $maxi_i=$img_select;
212              }
[18234]213
[17503]214              if($window_height < $imgSizeWH[0] && $mini_img==""){ 
215                      $mini_img=  $img_type;
216                      $mini_url= $img_url;
217                      $mini_i=$img_select;
[18234]218                 }
[17503]219
[18234]220               if($select_type == $img_type){ 
[17503]221                  if($maxi_img==""){
[18234]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                }
[17503]233      }
234
235return false ;
236
237 }
238
239/************************
240* cl_autosize_affiche
241*************************/     
242        static public function cl_autosize_affiche(){
[18234]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;
[18325]250   
[17503]251    if(isset($page['body_id']) &&       $page['body_id'] == 'theAdminPage' ) return ;   
252
[18325]253  global $css_slideshow,$css_display;
254                $AUTOSIZE_PATH = dirname(__FILE__).'/';
255   $theme=$user['theme']; 
[18127]256
[18325]257                load_language('plugin.lang', AUTOSIZE_PATH);
[17503]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' ;
[18325]262         if ($css_display=="none"  &&  $has_pamoorama) {   
263            $css_display="block" ;
264         }
[17503]265        $template->set_filenames(array('autosize_content_header'=> $file )); 
[18325]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   
[17503]276        $file =AUTOSIZE_PATH_ABS.'template/header.tpl' ;
277        $template->set_filenames(array('autosize_init_header'=> $file ));
[18234]278        $template->parse( 'autosize_init_header', false); 
279        $theme=$user['theme']; 
280                               
[17503]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                                        );
[18234]300                        $template->concat('autosize_content', $template->parse('autosize_content_header', true));               
[17503]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',
[18325]304                                             'path'=> AUTOSIZE_PATH.'/js/JScript.js',
305                                             'require' => 'jquery'),
[17503]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                                  }
[18127]314                } 
[17503]315
316        } //public function cl_autosize_affiche
317
318   /************************
319 *  cl_autosize_script_1
320 *************************/
321 static public function cl_autosize_script_1(){
[17192]322  global $user,$page,$template,$cl_plugin;
[17308]323    if(isset($page['body_id']) &&       $page['body_id'] == 'theAdminPage' ) return ;   
[17503]324 
[10347]325    $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
[18325]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 ; 
[17308]330
[18325]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 }
[10845]341    $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
[10347]342    $autosize_parametres =       cl_autosize_Get_Options() ;                   
343    $theme=$user['theme'];
[17503]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    //==============================================================================
[10347]349    $template->assign(
350      array(   
[17308]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,                                                               
[17503]356          'theme' => $theme  , 
357          'DEBUG_autosize' => $DEBUG_autosize,
[17308]358          'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
359          'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
[18325]360          'Version_pwg' => PHPWG_VERSION ,
361          'slideshow' => $page['slideshow']
362         )
[10347]363    );
[18325]364   
[17503]365    return $template->parse( 'autosize_init', false);
[18325]366
[8627]367        }// function cl_autosize_script_1
[16931]368
369 /*************************************
370 * cl_autosize_script_2()
371 **************************************/
[8627]372 static public function cl_autosize_script_2()
373 {
[8911]374           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$known_script ;
[18325]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   
[11429]384                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
[16931]385//================================================================
[10845]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 ; 
[16931]389//=====================================================================
[17308]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              ;
[17503]399
400
401  include_once (PHPWG_ROOT_PATH.'include/functions_cookie.inc.php') ;
[12527]402if(isset($_COOKIE['img_w'])){
[17308]403    $src_img_w=$_COOKIE['img_w'];
404    $src_img_h=$_COOKIE['img_h'];
[12527]405}
406
[17503]407$window_height= isset($_SESSION['height'])?$_SESSION['height']: $img_scaled_height ;
408$window_width= isset($_SESSION['width'])?$_SESSION['width']: $img_scaled_width    ;
[11961]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
[12527]416
[11961]417          );
418
[8627]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  ,
[10845]426                                        'DEBUG_autosize' => $DEBUG_autosize   ,
[11961]427                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH,
428          'Size' => $size
[16124]429           
[8627]430                                        )
431                                                );
[17503]432
[8627]433                        $autoscript="<script type='text/javascript'>
434                        /* cl_autosize_script_2 */
435                        if (typeof (save_framework) == 'function')
[16124]436                           save_framework('".$ma_page."'); 
[16579]437       var cookie_path   ='". cookie_path() ."'
[8627]438                        </script>";
439                $template->append('footer_elements',$autoscript); 
440                return ; 
441 }// function cl_autosize_script_2
[17308]442  /*************************************
443 * cl_autosize_script_3()
444 **************************************/
[17503]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 ; 
[8627]450
[17503]451                        $autoscript="<script type='text/javascript'>                   
[17308]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
[8627]459        //===============================================================
460                /*
[7375]461        *
462        */
[7193]463        static public function cl_autosize_aff_infos_plus()
464                {
465                 global $template,$infos_message,$erreur_message, $user ;
[8627]466                 global  $conf,$lang ;
[7669]467       
[7193]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               
[7375]491                } // function cl_autosize_aff_infos_plus
[8627]492        //===============================================================
493        /*
494         *
495        */
496        static public function cl_ajuste_data($content){
497                global  $template,$user,$conf,$picture ;
[11961]498      global $size;
[11429]499                $AUTOSIZE_PATH = realpath(AUTOSIZE_PATH .'/');
[8627]500                $userdata=$user;
501                $fields = array( 'maxwidth', 'maxheight' );
[8070]502         
[8627]503                $ThePicture = $template->get_template_vars('current'); 
504                $data = array();
505         return $content;
[7816]506
[11961]507                $data['maxwidth'] = $size['src_img_w'];
508                $data['maxheight'] =$size['src_img_h'];
[8627]509                $data['user_id'] = $userdata['id'];
510                foreach ($fields as $field)
[7943]511                {
[8627]512                        if (isset($_POST[$field]))
513                        {
514                                $data[$field] = $_POST[$field];
515                        }
[7943]516                }
[7193]517       
[8627]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                        }
[7943]526                 
[8627]527                        return $content;                                                                                 
528                 }
[7375]529
[11961]530
531/****************************************
532*
533****************************************/
534function Get_Options(&$parametres,$str_index){
535    global $conf ;
[16124]536     if (!isset( $conf[$str_index]))  {   
537      $conf[$str_index]="";
538     }
[11961]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
[16931]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 
[11961]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" ;
[16931]573   
[11961]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  }
[18325]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//================================================
631function 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      $ret =   file_get_contents ($mycssfile);
647
648function remove_comments( & $string ) { 
649   $string = preg_replace('#/\*.*?\*/#s',"",$string); 
650   return $string;
651 }
652
653$order   = array("\r\n", "\n", "\r"," ");
654$replace = '';
655$newstr = str_replace($order, $replace, $ret); 
656
657$order   = array('"');
658$replace = "'";
659$newstr = str_replace($order, $replace, $newstr); 
660
661
662$order   = array("}");
663$replace = '}\r\n';
664$newstr = str_replace($order, $replace, $newstr);
665remove_comments($newstr);
666
667$newstr = explode('\r\n',$newstr);
668$css=Array();
669   
670  foreach ($newstr as $key => $value) {   
671   if($value){
672    $css2=Array();
673      $key=explode("{",$value);   
674      $value = str_replace("}","",$key[1]) ;
675      $value=explode(";",$value); 
676           foreach ($value as $key2 => $value2) {   
677            if($value2){
678              $key2=explode(":",$value2);   
679                $value2 =  $key2[1] ;
680                $css2[$key2[0]] = $value2 ;
681            }
682           }
683      $css[$key[0]]=$css2 ;
684     }   
685}
686
687       
688                    return $css;
689        } 
690//=================================================
691
692
[7375]693} // class
694
[11961]695/*************************************
[7375]696        *
[11961]697 *************************************/
[7193]698 function cl_autosize_Get_Options()
699  {
[7394]700                global $conf,$autosize_parametres; 
[12652]701    $autosize_parametres ="";
702 
703 if (!isset($conf['cl_autosize']))  {   
704  $conf['cl_autosize']="";
705  $q = '
706   INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
707   VALUES ("cl_autosize","","Parametres du plugin Autosize")
708  ;';
709  pwg_query($q);
710  }
711 
712 
713
[7394]714                $autosize_parametres =  unserialize($conf['cl_autosize']);
[11961]715      // $autosize_parametres = autosize_controler::Get_Options($autosize_parametres,'cl_autosize');
[7394]716                $autosize_parametres =  cl_autosize_Set_Options();
717                return $autosize_parametres;
[7375]718  }
719        /*
720        *
[7193]721        */
[11961]722function cl_autosize_Set_Options() {
[7193]723  global $autosize_parametres;
724//=============================================================================
[7962]725$my_para=$autosize_parametres;
[16124]726  if (empty($my_para))
727$my_para = (object) '';
728
[7962]729$my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
730$my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
[7193]731
[16931]732$my_para->webmaster_type =(isset($_POST['webmaster_type'])) ? $_POST['webmaster_type'] : ((isset($my_para->webmaster_type )) ? $my_para->webmaster_type : 'Autosize' ) ;
[7193]733
[16931]734$my_para->admin_type =(isset($_POST['admin_type'])) ? $_POST['admin_type'] : ((isset($my_para->admin_type )) ? $my_para->admin_type : 'Autosize' ) ;
[7193]735
[16931]736$my_para->generic_type =(isset($_POST['generic_type'])) ? $_POST['generic_type'] : ((isset($my_para->generic_type )) ? $my_para->generic_type : 'Autosize' ) ;
[7193]737
738
[16931]739$my_para->guest_type =(isset($_POST['guest_type'])) ? $_POST['guest_type'] : ((isset($my_para->guest_type )) ? $my_para->guest_type : 'Autosize' ) ;
[7193]740
[7725]741
[16931]742$my_para->normal_type =(isset($_POST['normal_type'])) ? $_POST['normal_type'] : ((isset($my_para->normal_type )) ? $my_para->normal_type : 'Autosize' ) ;
743
744
745
[7962]746$my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
747$my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
748
749$my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
750$my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
751
[9473]752$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
[9225]753$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
[9473]754$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
[7962]755
[7193]756//===============================================================================       
757
758if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
[7962]759                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
760                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
[16931]761       
[7394]762
[7962]763                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
764                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
765                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
766                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
767                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
[7394]768
[7193]769         }else{
[7962]770                $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') ; 
771                $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') ; 
[7394]772
773
[16931]774
[7962]775$my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ; 
776$my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ; 
777$my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ; 
778$my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
779$my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ; 
[7394]780
781
[7193]782   }
[7316]783
[7962]784return $my_para;
[7193]785}
[7375]786        /*
787        *
[7193]788        */
789function cl_autosize_sauve_options_inf()
790{
791global $options,$infos_message,$conf,$autosize_parametres  ;
792$infos_message .=l10n("cl_autosize_save_config")."<br>";
793 $autosize_parametres=cl_autosize_Set_Options();
[12652]794 if ( isset($autosize_parametres) )     { 
[7193]795                $query = '
796                UPDATE '.CONFIG_TABLE.'
797                SET value="'.addslashes(serialize($autosize_parametres)).'"
798                WHERE param = "cl_autosize"
799                LIMIT 1';
800                        pwg_query($query);
801          }
[17503]802    if (!isset($conf['cl_derivatives_sav']))  {   
803      $q = '
804        INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
805        VALUES ("cl_derivatives_sav","","sauvegarde derivatives")
806      ;';
807      pwg_query($q);     
808      }
[7193]809 }
[7375]810
[17503]811 function print_var($variables)
[8729]812{
813  ob_start();
814  echo '<pre>';
815  print_r($variables);
816  echo '</pre>';
817  $m= ob_get_contents();
818  ob_end_clean();
819  return $m;           
820}
[7375]821
[18325]822
823
[7193]824?>
Note: See TracBrowser for help on using the repository browser.