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

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

[extensions] Autosize update to piwigo 2.5 (fix bugs with jquery 1.9 )

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