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

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

[extensions] Autosize update to piwigo 2.5 (fix compatability theme simple)

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