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

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

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

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