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

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

[extensions] Autosize update to piwigo 2.5 (fix init)

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