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

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

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

File size: 50.5 KB
RevLine 
[7375]1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// | Autosize                                                              |
5// +-----------------------------------------------------------------------+
6// | Copyright(C) 2010      cljosse                                        |
7// +-----------------------------------------------------------------------+
8// | This program is free software; you can redistribute it and/or modify  |
9// | it under the terms of the GNU General Public License as published by  |
10// | the Free Software Foundation                                          |
11// |                                                                       |
12// | This program is distributed in the hope that it will be useful, but   |
13// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
14// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
15// | General Public License for more details.                              |
16// |                                                                       |
17// | You should have received a copy of the GNU General Public License     |
18// | along with this program; if not, write to the Free Software           |
19// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
20// | USA.                                                                  |
21// +-----------------------------------------------------------------------+
[18823]22class autosize_ctrl {
[17503]23        /*********************************
[22133]24         * cl_autosize_admin
[17503]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
[18716]32
33
[22133]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                //==============================================================================
[22191]42                global $DEBUG_autosize,$infos_message,$error_message;
[22133]43                if(preg_match("|event|", $DEBUG_autosize, $val))  $infos_message =  "autosize_calcContent, " ;
[22191]44                if(!realpath($element_info['path'])) return $content;
45
[22133]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) ;
[22218]68      $infos_message .= "SERVER:"  . cl_print_var($_SERVER["HTTP_HOST"]) ;
[22133]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();
[18823]79
[22133]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;
[18949]85
[22133]86                //==============================================================
87                $autosize_parametres = cl_autosize_Get_Options();
88                return false ;
89        }//calc_content ;
[18949]90
[18716]91
92
[22133]93        /*********************
94         * INIT
95        *********************/
96        static public function init_3(){
[22191]97                global $DEBUG_autosize,$infos_message,$error_message;
98                if(preg_match("|event|", $DEBUG_autosize, $val))  $infos_message .=  "init_3, " ;
[18716]99
[22133]100        }
101        static public function init_1($content, $image)
102        {
103                global $conf, $template, $page;
[22191]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, " ;
[22133]107                if(!isset($conf['AS_panorama'])) return $content;
[22191]108                if(  !is_array($conf['AS_panorama']) )                  return $content;
[22133]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;
[22191]122                global $warnings_message;
[18823]123
[22191]124                global $set_miniature,$imgSizeWH;
[22133]125                global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
126                //=======================================================
[22191]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, " ;
[18823]131
[22133]132                $has_pamoorama = isset($template->files['pamooramics_content'])?"true":"false";
133                $theme=$user['theme'];
[18325]134
[22133]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'] ;
[18325]156
[22133]157                $theImageTop= isset($_COOKIE['theImageTop'])?$_COOKIE['theImageTop']:0;
158                $theImageLeft=isset($_COOKIE['theImageLeft'])?$_COOKIE['theImageLeft']:0;
[18823]159
[22133]160                $theImageRight=isset($_COOKIE['theImageRight'])?$_COOKIE['theImageRight']:0;
161                $theImageBottom=isset($_COOKIE['theImageBottom'])?$_COOKIE['theImageBottom']:0;
[18234]162
[18736]163
[22133]164                $theImageMargeWidth=isset($_COOKIE['theImageMargeWidth']) ? $_COOKIE['theImageMargeWidth']:0;
165                $theImageMargeHeight=isset($_COOKIE['theImageMargeHeight'])?$_COOKIE['theImageMargeHeight']:0;
[18823]166
[22133]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 ;
[18823]174
[22133]175                if (isset($element_info['is_gvideo']) && $element_info['is_gvideo'] ){
176                        $pictureDeriv=$default_size;
[18823]177
[22133]178                }else{
[18823]179
[17503]180
[22133]181                        $retour = self::get_min_max() ;
[18949]182
[22133]183                        $theMainImageSize = $retour->get_size();
184                        $theMainImageWidth=   isset($_COOKIE['theMainImageWidth'])?$_COOKIE['theMainImageWidth']:$theMainImageSize[0];
185                        $theMainImageHeight=   isset($_COOKIE['theMainImageHeight'])?$_COOKIE['theMainImageHeight']:$theMainImageSize[1] ;
[18949]186
[22133]187                        if($theImageHeight!=0 && $theImageWidth!=0){
188                                $pictureDeriv=$retour->type ;
189                        }else{
190                                $pictureDeriv=$default_size;
191                        }
192                }
[18949]193
[22133]194                if(preg_match("|test|", $DEBUG_autosize, $val)) {
195                        $infos_message .=  "#208 <br>Init:SESSION:"  . cl_print_var($_SESSION) ;
[22191]196
[22133]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) ." -->";
[22191]212                                self::Fin_php("#211: " . $DEBUG_autosize);
[22133]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] = ' ';
[18234]223
[22133]224                if ( strstr( $content,"iframe")||strstr($content,"charlie" )){
[17503]225
[22133]226                        $pictureSelType="Autosize";
227                        $pictureDeriv=$conf['derivative_default_size'];
[17503]228
[22133]229                        $_COOKIE['picture_sel_type']=$pictureSelType;
230                        $_COOKIE['picture_deriv']=$pictureDeriv;
[18234]231
[22133]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);
[18234]242
[22133]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                }
[17503]252
[22133]253                $content=  preg_replace($pattern, "", $content);
[18735]254
[22133]255                return  $content;
256        }//INIT
[18735]257
[22133]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
[19003]266
[22133]267                //=====================================================================
268                global  $has_pamoorama,$pictureSelType,$pictureDeriv;
269                global $DEBUG_autosize;
[22191]270                if(preg_match("|event|", $DEBUG_autosize, $val)) $infos_message .= "init2, ";
271                if(!realpath($element_info['path'])) return $content;
[22133]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 ;
[17503]282
[22133]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];
[17503]289
[22133]290                $nh = intval($theImageWidth / $Ratio)  ;
291                $nw = intval($theImageHeight * $Ratio) ;
[19003]292
[22133]293                echo $nw . "x " . $nh ."<br />";
[19744]294
[22133]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                }
[18716]301
[22133]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;'>";
[22191]306                self::Fin_php("#305 : " . $content + $DEBUG_autosize);
[18716]307
[22133]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>
[22191]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 >";
[22133]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'){
[18325]353
[22133]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);
[22191]370                        self::Fin_php("#369:  No COOKIE['picture_deriv'] ".$DEBUG_autosize);
[22133]371                }
[18716]372
[22133]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) ;
[22191]380                        self::Fin_php("#379: ".$DEBUG_autosize);
[22133]381                }
[18716]382
[22133]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'])  ){
[22191]391                        self::Fin_php("#390:  Initialisation ".$DEBUG_autosize);
392                }                       
[22133]393        }
[18735]394
[22133]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'];
[18325]413
[22133]414                        if(isset($current['selected_derivative'])) {
415                                $model=$current['selected_derivative']->get_type() ;
416                        }else{
417                                $model=$default_size;
418                        }
[22220]419      if(!isset($current['derivatives'][$model])){
420      $model=$default_size;
421      }
422     
[22133]423                        $selected_derivative =  $current['derivatives'][$model];
424                        $template->append('current', array(
425                                        'selected_derivative' => $selected_derivative
426                        ),
427                                        true);
428
429                }
430
431
432
433                $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
434                $autosize_parametres =   cl_autosize_Get_Options() ;
435                $theme=$user['theme'];
436                //==============================================================================
437                $template->assign(
438                                array(
439                                                'autosize_parametres' => $autosize_parametres ,
440                                                'cl_plugins' => $cl_plugin ,
441                                                'cl_version' => $cl_version ,
442                                                'name' => $cl_plugin['name'] ,
443                                                'has_pamoorama' => $has_pamoorama,
444                                                'theme' => $theme  ,
445                                                'DEBUG_autosize' => $DEBUG_autosize,
446                                                'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
447                                                'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
448                                                'Version_pwg' => PHPWG_VERSION ,
449                                                'slide_show' => $page['slideshow']
450                                )
451                );
452                if( preg_match("|c2|", $DEBUG_autosize, $val) ){
[22191]453                        self::Fin_php( "449: " . $DEBUG_autosize);
[22133]454                        return $content ;
455
456                }
457
458                return $template->parse( 'autosize_init', false);
459
460
[8627]461        }// function cl_autosize_script_1
[16931]462
[22133]463        /*************************************
464         * cl_autosize_script_2()
465        **************************************/
466        static public function cl_autosize_script_2()
467        {
468                global $css_slideshow;
469                global $pictureSelType,$pictureDeriv,$infos_message;
470                global  $template,$user,$conf,$picture ,$page, $cl_plugin,$cl_version,$known_script ;
[18716]471
[22133]472                global  $has_pamoorama;
473                global $DEBUG_autosize;
474                if(preg_match("|event|", $DEBUG_autosize, $val)) {
475                        $infos_message .= "cl_autosize_script_2, ";
476                } ;
477                $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
478                if ($ma_page !='thePicturePage') return ;
[8627]479
[22133]480                $theme=$user['theme'];
481                if ($has_pamoorama=="false" ) return ;
482                if ($css_slideshow == "no" and isset($_GET['slideshow'])) return ;
483                $AUTOSIZE_PATH = dirname(__FILE__).'/';
484                //=====================================================================
485                $template->assign(
486                                array(
487                                                'cl_version' => $cl_version ,
488                                                'name' => $cl_plugin['name'] ,
489                                                'ma_page' =>    $ma_page,
490                                                'theme' => $theme  ,
491                                                'DEBUG_autosize' => $DEBUG_autosize   ,
492                                                'AUTOSIZE_PATH' => AUTOSIZE_PATH
493                                )
494                );
495                $autoscript="<script type='text/javascript'>
496                                /* cl_autosize_script_2 */
497                                if (typeof (save_framework) == 'function')
498                                save_framework('".$ma_page."');
[18716]499
[22133]500                                                </script>";
501                $template->append('footer_elements',$autoscript);
[18716]502
[22133]503                return ;
504        }// function cl_autosize_script_2
[18716]505
[22133]506        /*************************************
507         * cl_autosize_script_3()
508        **************************************/
509        static public function cl_autosize_script_3() {
510                global  $has_pamoorama,$template,$page,$infos_message;
511                global $DEBUG_autosize;
512                if(preg_match("|event|", $DEBUG_autosize, $val)) {
513                        $infos_message .= "cl_autosize_script_3, ";
514                } ;
515                $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
516                if ($ma_page !='thePicturePage') return ;
[18716]517
[22191]518                       
[22133]519                $template->func_combine_script(array('id'=>'my_script_2',
520                                'path'=> AUTOSIZE_PATH.'js/JScript.js',
521                                'require' => 'jquery'),
522                                $template->smarty);
[18716]523
[22133]524                $template->func_combine_css(array('id'=>'autosize.css',
525                                'path'=> AUTOSIZE_PATH.'css/autosize.css'
526                ));
[17308]527
[22133]528
529                $autoscript="<script type='text/javascript'>
530                                var COOKIE_PATH = '".cookie_path()."' ;
531                                                </script>";
532                $template->append('footer_elements',$autoscript);
533                if ($has_pamoorama=="false" ) return ;
534
535                $autoscript="<script type='text/javascript'>
536                                if (typeof (Ajout_Ajax) == 'function')
537                                Ajout_Ajax();
538                                </script>";
539                $template->append('footer_elements',$autoscript);
540
[22191]541                       
[22133]542                return ;
543        }// function cl_autosize_script_3
544
545        /************************
546         * cl_autosize_affiche
547        *************************/
[18716]548        static public function cl_autosize_affiche(){
[22133]549                if (!defined('AUTOSIZE_PATH')) {
550                        define(  'AUTOSIZE_PATH',   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/' );
551                        if (!defined('AUTOSIZE_PATH_ABS'))
552                                define(  'AUTOSIZE_PATH_ABS',  realpath(AUTOSIZE_PATH)."/");
553                }
[18716]554
[22133]555                global $user, $picture, $template,$page,$known_script;
556                global $content, $element_info;
557                global $infos_message,$error_message,$warnings_message;
558                global  $conf,$lang ,$user,$userdata;
559                global $defined_types,  $liste_type,$SRC_IMG;
560                global $set_miniature;
561                global $autosize_parametres,$user_status;
562                global  $has_pamoorama,$pictureSelType,$pictureDeriv;
563                global $DEBUG_autosize;
564                global $css_slideshow,$css_display;
565                if(preg_match("|event|", $DEBUG_autosize, $val)) {
566                        $infos_message .=  "cl_autosize_affiche, " ;
567                } ;
568                $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
569                if ($ma_page !='thePicturePage') return ;
570                //============================================================
571                self::save_cookies();
[19003]572
[22133]573                if(isset($set_miniature)){
574                        $set_miniature = self::cl_autosize_nofile($set_miniature) ;
575                        $set_miniatures= explode("script",$set_miniature);
576                        if(preg_match("|noGen|", $DEBUG_autosize, $val)) {
577                                if(count($set_miniatures)> 1 )
578                                        $infos_message .= "PictureDeriv:" . $pictureDeriv. ' miniature:' . cl_print_var( $set_miniature);
[22191]579                                       
[22133]580                        }else {
[18735]581
[19003]582
[22133]583                        } ;
584                        $template->append('footer_elements',$set_miniature);
585                }
586                if ($css_slideshow == "no" and isset($_GET['slideshow'])) return ;
[18949]587
[22133]588                $AUTOSIZE_PATH = dirname(__FILE__).'/';
589                $theme=$user['theme'];
590                load_language('plugin.lang', AUTOSIZE_PATH);
[19003]591
[22133]592                include_once (AUTOSIZE_PATH."include/affiche.php");
[19003]593
[22133]594                $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
595                if ($css_display=="none"  &&  $has_pamoorama=="true" ) {
596                        $css_display="block" ;
597                }
598                $file_css=AUTOSIZE_PATH."css/".$theme.".css";
599                if (!file_exists($file_css))  $file_css="no";
600                if ($css_display=="none" ) {
601                        return ;
602                }
603                if($pictureSelType == $pictureDeriv ) {
604                        if(preg_match("|event|", $DEBUG_autosize, $val)) {
605                                cl_aff_infos_plus();
606                        } ;
[18735]607
[22133]608                }
[18716]609
[22133]610                if (defined('GMAPS_VERSION')) $gmaps_function="true";
611                else $gmaps_function="false" ;
[18716]612
613
614
[22133]615                $template->set_filenames(array('autosize_content_header'=> $file ));
616                $template->assign(      array( AUTOSIZE_PATH,$AUTOSIZE_PATH,
617                                'file_css' =>$file_css,
618                                'css_display' => $css_display,
619                                'theme' =>$theme,
620                                'gmaps_function' => $gmaps_function
621                ));
622                $template->concat('autosize_content', $template->parse('autosize_content_header', true));
[18716]623
[22133]624                $file =AUTOSIZE_PATH_ABS.'template/header.tpl' ;
625                $template->set_filenames(array('autosize_init_header'=> $file ));
626                $template->parse( 'autosize_init_header', false);
627                $theme=$user['theme'];
[19003]628
[22133]629                if($autosize_parametres->check_icon_v == 'on'){
630                        $template->assign('cl_autosize_button',
631                                        array(  'cl_autosize_info' => 'cl_autosize_info' ,
632                                                        'cl_autosize_info_1' => 'cl_autosize_info_' ,
633                                                        'cl_autosize_info_2' => 'cl_autosize_info_2' ,
634                                                        'URL' => $_SERVER['REQUEST_URI'] ,
635                                                        'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
636                                                        'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png',
637                                                        'ICON1' => AUTOSIZE_PATH . 'icons/button-no.png'
638                                        )
[19003]639
[22133]640                        );
641                        $template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
642                        $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
643                }
[19003]644
[22133]645                $template->set_filenames(
646                                array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl',
647                                                'theme' => $theme   )
648                );
649
650                $template->concat('autosize_content', $template->parse('autosize_content_header', true));
651                if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
652                        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
653
654                        $template->func_combine_script(array('id'=>'my_script_2',
655                                        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
656                                        'require' => 'jquery'),
657                                        $template->smarty
658                        );
659
660                        $template->assign(array(
661                                        'MY_FOOTER_PATH' =>AUTOSIZE_PATH
662                        ));
663                        $template->parse('mes_script');
664                }
[22191]665                       
[22133]666
667                if(preg_match("|vue_cookies|", $DEBUG_autosize, $val)) {
668
669                        $pictureSelType=$_COOKIE['picture_sel_type'];
670                        $pictureDeriv=$_COOKIE['picture_deriv'];
671                        $infos_message .= "cl_autosize_affiche: $pictureSelType  <--> $pictureDeriv \n" ;
672
673                }
674
675                if(preg_match("|test|", $DEBUG_autosize, $val)) {
676                        $infos_message .= "#683 <br>cl_autosize_affiche:_COOKIE:"  . cl_print_var($_COOKIE) ;
677                        $pictureMap=$_COOKIE['picture_map'];
678                        $infos_message .= "<br />SelType:" . $pictureSelType."; pictureDeriv:".$pictureDeriv ."; pictureMap:".$pictureMap;
679
[22191]680                        self::Fin_php("#676: ".$DEBUG_autosize);
[22133]681                }
682                cl_aff_infos_plus();
683                return $template->parse( 'autosize_content', false);
[18716]684        } //public function cl_autosize_affiche
[11961]685
[18716]686
[22133]687        /****************************************
688         *
689        ****************************************/
690        function Get_Options(&$parametres,$str_index){
691                global $conf ;
692                if (!isset( $conf[$str_index]))  {
693                        $conf[$str_index]="";
694                }
695                $m_options=  $conf[$str_index];
696                if(isset($m_options))
697                        if ( preg_match("|s:(.*)|", $m_options, $val) )
698                        $parametres =  unserialize($conf[$str_index]);
699                else{
700                        $parametres=explode(",",$_options);
701                }
702                //====== par defaut =======================
703                $new_val=false;
704                $def_para=Array();
[11961]705
[22133]706                $def_para['query'] = 'Qt'  ;
707                $def_para['type'] = 'Ty' ;
[11961]708
[22133]709                $def_para['webmaster_type'] = 'Autosize' ;
710                $def_para['admin_type'] = 'Autosize'  ;
711                $def_para['generic_type'] = 'Autosize'  ;
712                $def_para['guest_type'] = 'Autosize'  ;
713                $def_para['normal_type']  =  'Autosize'  ;
[11961]714
715
716
[22133]717                $def_para['mini_height'] =  '150' ;
718                $def_para['mini_width'] = '300' ;
[11961]719
[22133]720                $def_para['mini_height2'] =  '150' ;
721                $def_para['mini_width2'] =   '300' ;
[18716]722
[22133]723                $def_para['echelle_max'] =  '1.0';
724                $def_para['marge_basse'] =  '0';
725                $def_para['fade_in'] =   '0';
726                //==================================================
727                $def_para['check_desc_v'] =  "off" ;
728                $def_para['check_icon_v'] =  "off" ;
729                $def_para['defaut_type'] =  "off" ;
[18325]730
[22133]731                $def_para['webmaster_enabled'] =   "off" ;
732                $def_para['admin_enabled'] =   "off" ;
733                $def_para['generic_enabled'] =   "off" ;
734                $def_para['guest_enabled'] =   "off" ;
735                $def_para['normal_enabled'] =   "off" ;
736                //===================================================
737                $para=$def_para;
738                foreach ($para as $key => $value) {
739                        if( isset($parametres->$key) ){
740                                $value=$parametres->$key;
741                        }
742                        if($def_para[$key] =="on" ||$def_para[$key] =="off" ){
743                                $val_pg=(isset($_POST[$key]))? ($_POST[$key]=="off"||$_POST[$key]=="on")?$_POST[$key]:"on" : "off" ;
744                                $value =(isset($_POST[$key]))? $val_pg : $value ;
745                                $val_pg=(isset($_GET[$key]))? ($_GET[$key]=="off"||$_GET[$key]=="on")?$_GET[$key]:"on" : "off" ;
746                                $value =(isset($_GET[$key]))? $val_pg  : $value ;
747                        }else{
748                                $value =(isset($_POST[$key]))? $_POST[$key] : $value ;
749                                $value =(isset($_GET[$key]))? $_GET[$key] : $value ;
750                        }
751                        unset( $parametres->$key) ;
752                        $parametres->$key = $value ;
753                }
754                return $parametres ;
755        }
756        /****************************************************/
[18325]757
[22133]758        function listeFichiers($dir,$theme){
759                global $extensions_allowed;
760                $extensions_allowed = array();
761                $extensions_allowed [] = 'css';
762                if ($handle = opendir($dir)) {
763                        while (false !== ($file = readdir($handle))) {
764                                if (($file <>'.') && ($file<>'..')) {
765                                        if (is_file($dir.'/'.$file)){
766                                                $extension = pathinfo($dir.'/'.$file, PATHINFO_EXTENSION);
767                                                if (in_array($extension,$extensions_allowed)){
768                                                        $fileHandle = fopen($dir.'/'.$file, "r");
[18325]769
[22133]770                                                        $intro = fread($fileHandle,filesize ($dir.'/'.$file));
771                                                        fclose($fileHandle);
772                                                        if ($file== $theme){
773                                                                flush();
774                                                                return $intro ;
775                                                        }
776                                                }
777                                        } else {
778                                                if (is_dir($dir.'/'.$file)){
779                                                        listeFichiers($dir.'/'.$file,$theme);
780                                                }
781                                        }
782                                }
783                        }
784                        closedir($handle);
785                }
786        }
787        //================================================
788        static public function css($theme_local) {
789                $path = $_SERVER['DOCUMENT_ROOT'];
790                if (substr($path,-1)=='/'){
791                        $path =  substr($path,0,-1);
792                }
793                if(isset($_GET['path']))
794                        $path=$_GET['path'];
795                else
796                        $path=PHPWG_ROOT_PATH."local/css/";
[18326]797
[22133]798                $mycssfile=$path.$theme_local;
[18325]799
[22133]800                if(!file_exists($mycssfile))
801                        $mycssfile=$path."default-rules.css";
[18325]802
[22133]803                if(!file_exists($mycssfile)){
804                        return Array();
805                }
[18325]806
[22133]807                $ret =   file_get_contents ($mycssfile);
[18325]808
[22133]809                function remove_comments( & $string ) {
810                        $string = preg_replace('#/\*.*?\*/#s',"",$string);
811                        return $string;
812                }
[18325]813
[22133]814                $order   = array("\r\n", "\n", "\r"," ");
815                $replace = '';
816                $newstr = str_replace($order, $replace, $ret);
[18325]817
[22133]818                $order   = array('"');
819                $replace = "'";
820                $newstr = str_replace($order, $replace, $newstr);
[18325]821
822
[22133]823                $order   = array("}");
824                $replace = '}\r\n';
825                $newstr = str_replace($order, $replace, $newstr);
826                remove_comments($newstr);
[18823]827
[22133]828                $newstr = explode('\r\n',$newstr);
829                $css=Array();
[18325]830
[22133]831                foreach ($newstr as $key => $value) {
832                        if($value){
833                                $css2=Array();
834                                $key=explode("{",$value);
835                                $value = str_replace("}","",$key[1]) ;
836                                $value=explode(";",$value);
837                                foreach ($value as $key2 => $value2) {
838                                        if($value2){
839                                                $key2=explode(":",$value2);
840                                                $value2 =  $key2[1] ;
841                                                $css2[$key2[0]] = $value2 ;
842                                        }
843                                }
844                                $css[$key[0]]=$css2 ;
845                        }
846                }
[18716]847
[22191]848                       
[22133]849                return $css;
850        }
[19844]851
[22133]852        /***************************
853         *  get_min_max
854        ***************************/
855        static public function get_min_max(){
856                global $liste_type,$img_all,$set_miniature,$template,$infos_message,$error_message,$has_pamoorama ;
857                global $theImageWidth,$theImageHeight,$pictureSelType,$pictureDeriv ;
858                global $DEBUG_autosize;
[18823]859
[18716]860
[22133]861                $current = $template->get_template_vars('current');
862                $liste_type="";
863                $del_deriv_types = array();
864                $i=0;
865                $defined_types = array_keys(ImageStdParams::get_defined_type_map());
866                foreach($defined_types as $type){
[18716]867
[22133]868                        if($type!="Autosize" && $type!="SelMaxi" ){
869                                $last_derivative= $type ;
870                                $del_deriv_types[$i] =  $last_derivative ;
871                                $i++;
872                        }
[22191]873
[22133]874                }
875                ;
876                $derivative=$current['derivatives'][$last_derivative] ;
877                $img_all= $derivative->get_all($derivative->src_image);
[18716]878
[22133]879                $retour = (object) '';
880                $maxi_image = (object) '';
881                $mini_image = (object) '';
882                $std_image  = (object) '';
883                $default_image=(object) '';
884                $SelType_image=(object) '';
885                $last_image=(object) '';
[18936]886
[22133]887                global $imgSizeWH ;
888                $imgSizeWH  = $derivative->get_size();
889                $theImage_maxi=0;
890                $theImage_mini=0;
891                $theImage_def=0;
892                $No_files= array();
893                //================= Liste =========================
894                $ok= 0 ;
895                $nofile=0 ;      global $max_crop;
896                //=============================================
897                // Liste mini maxi
898                //=============================================
899                foreach ($img_all as $img_select){
[18823]900
[22133]901                        $img_type  =  $img_select->get_type();
902                        $img_url  = $img_select->get_path();
903                        $max_crop = 0 ;
904                        $imgWH  =  self::Get_Size($img_select);
905                        if ($img_type=="square" || $img_type=="thumb" ) continue ;
906                        if($img_type=="Autosize" || $img_type=="SelMaxi"){
907                                $theImage_def +=1 ;
908                                continue;
909                        }
910                        if(!file_exists(PHPWG_ROOT_PATH.$img_url)){
911                                $No_files[$img_type] =   $img_select ;
912                                $nofile++ ;
913                                if(preg_match("|get_infos|", $DEBUG_autosize, $val))
914                                        $infos_message .=$nofile ." " ;
915                        }
916                        if(preg_match("|get_minfos|", $DEBUG_autosize, $val))
917                                $infos_message .=$img_url . " " . $max_crop ." -> " . $img_type . " " . print_r($imgWH,true). " <br >";
[18823]918
[22133]919                        if(file_exists(PHPWG_ROOT_PATH.$img_url)){
920                        } // if file
[22191]921
[22133]922                        if ($theImage_def==0){
923                                // Avant Autosize ou Original;
924                                if($img_type=="Original") {
925                                        $theImage_def = 1;
926                                        $theImage_maxi=1;
927                                        $theImage_mini=1;
928                                        if($ok==0){
929                                                $last_image->type=$img_type;
930                                                $last_image->url=$img_url;
931                                                $last_image=$img_select;
932                                        }
933                                }else{
934                                        $last_derivative=$img_type ;
935                                        $last_image=  $img_select;
936                                }
937                        }
938                        if ($theImage_maxi==0){
939                                $maxi_image=  $img_select;
940                        }
941                        if ($theImage_mini==0){
942                                $mini_image=  $img_select;
943                        }
944                        $liste_type[$img_type]=$img_type.",".$img_url.",".$imgWH[0] .",".$imgWH[1] ;
945                        if( $img_type==$pictureSelType){
946                                if(preg_match("|get_minfos|", $DEBUG_autosize, $val))     $infos_message .= $pictureSelType . " <--> " . $img_type ."<br >";
[18823]947
[22133]948                                $SelType_image->type=$img_type;
949                                $SelType_image->url=$img_url;
950                                $SelType_image=$img_select;
951                        }
952                        if( $img_type=="Original" && $theImage_def==0 ){
953                                $theImage_def=1;
954                                $img_type = $last_derivative ;
955                                $img_url= $derivative->get_path();
956                                $imgWH = $derivative->get_size();
[18716]957
[22133]958                                $default_image->type=$img_type;
959                                $default_image->url=$img_url;
960                                $default_image=$img_select;
[19844]961
[22133]962                        }
[18716]963
[22133]964                        if($has_pamoorama==true)
965                                $test= ($imgWH[1] >  $theImageHeight)  ;
966                        else
967                                $test= ($imgWH[1] >  $theImageHeight  && $imgWH[0] >  $theImageWidth);
968                        if($theImage_maxi==0)
969                                if( $test  ){
970                                $theImage_maxi=1;
971                                $maxi_image->type =   $img_type;
972                                $img_type=$img_select->get_type();
973                                if($img_type=="Original")
974                                        $maxi_image = $last_image;
975                                else
976                                        $maxi_image = $img_select;
[22191]977                                       
[22133]978                                $maxi_image->url  =  $maxi_image->get_path();
[18975]979
[22133]980                        } else {
[19003]981
[22133]982                                $mini_image->type=$img_type;
983                                $mini_image->url=$img_url;
984                                $mini_image=$img_select;
985                                $mini_image->url  =  $mini_image->get_path();
986                        }
[22191]987
[22133]988                } // for
989                //================================================
[19003]990
[22133]991                $img_url = $img_select->src_image->get_url();
992                $imgSizeWH  =  $img_select->src_image->get_size();
993                $liste_type["Original"]="Original".",".$img_url.",".$imgSizeWH[0] .",".$imgSizeWH[1] ;
[22191]994                       
[19744]995
[22133]996                $retour=(object)'' ;
997                if ($pictureSelType=="Autosize") $retour= $maxi_image ;
998                else if ($pictureSelType=="SelMaxi") $retour= $mini_image ;
999                else{
1000                        $types = array_intersect(array_keys($liste_type), array($pictureSelType));
1001                        if(!count($types)){
1002                                $pictureSelType="Original";
1003                        }
1004                        $retours=  explode(",",$liste_type[$pictureSelType]);
1005                        $retour=$SelType_image;
1006                        $retour->type=$retours[0];
1007                        $retour->url=$retours[1];
1008                }
1009
1010                if (!isset( $retour->type)){
1011                        $retour=$last_image;
1012                        $retour->type =  $retour->get_type();
1013                        $retour->url  =  $retour->get_path();
1014
1015                }
1016                if (isset( $retour->type) && $retour->type=="Original" ){
1017                        $retour=$last_image;
1018                        $retour->type =  $last_derivative;
1019                        $retour->url  =  $retour->get_path();
1020
1021                }
1022                if($nofile > 0){
1023                        $set_miniature=$No_files ;
1024                }
1025
1026                if(preg_match("|get_infos|", $DEBUG_autosize, $val))
1027                        $infos_message .=$pictureSelType . " -> " . $retour->type . " : "  . $retour->url  ."<br >";
1028
1029                return $retour ;
1030
1031        }
1032        //=================================================================
1033
1034        static public function Get_Size($Img_Select){
1035                global  $max_crop;
1036                $imgWH  =  $Img_Select->get_size();
1037                $img_type  =  $Img_Select->get_type();
1038                if( $img_type =="Original")  return ;
1039                $smaller = ImageStdParams::get_by_type($img_type);
1040                $max_crop=0;
1041                if($smaller->sizing->max_crop==1){
1042                        $imgWH  =$smaller->sizing->min_size;
1043                        $max_crop=1;
1044                }
1045                return $imgWH ;
1046        }
1047        //==================================================================
1048        static public  function  cl_autosize_nofile($img_all){
1049                //=== verification fichiers absents ===
1050                global $infos_message,$error_message;
1051                global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
1052                global  $pictureDeriv;
1053                $ok=false ;
1054                $nofiles=array();
1055                $file_no=(object) '';
1056
1057                $nosrc=false ;
1058                $ok=true ;
1059                $listes="";
1060                foreach ($img_all as $img_select){
1061                        $img_url  = $img_select->get_url();
1062                        if(!file_exists(PHPWG_ROOT_PATH.$img_url)){
1063                                $img_type  =  $img_select->get_type();
[22191]1064                                       
[22133]1065                                $file_id=explode("?",$img_url);
1066                                if(count($file_id) ==1){
1067                                        $file_id[]=$file_id[0] ;
1068                                }
1069                                if ( !preg_match("|".$file_id[1]."|", $listes) ){
1070                                        $listes  .=  $file_id[1] ."<br />";
1071                                        $file_no->url= $file_id[1] ;
1072                                        $id  =  $img_select->src_image->id;
1073                                        $file_no->id=$id ;
1074                                        $file_no->type=$img_type ;
1075                                        array_push($nofiles,serialize($file_no)) ;
1076                                        if( $img_type == $pictureDeriv){
[22191]1077                                                       
[22133]1078                                                break ;
1079                                        }
1080                                }
1081                                $ok=false ;
1082                        }
1083                }
1084                $exec_miniatures="";
1085                if(count($nofiles)>0){
1086                        //=======================================================================================
1087                        if($nosrc!=true  ){
1088                                $script_miniatures = "<script type='text/javascript' src='".PHPWG_ROOT_PATH."themes/default/js/plugins/jquery.ajaxmanager.js' ></script>";
1089                                $script_miniatures .= "<script type='text/javascript' src='".PHPWG_ROOT_PATH."plugins/Autosize/js/autosize_ajax.js' id='autosize_ajax' >  </script >";
1090                                $nosrc=true ;
1091                        }
1092                        $exec_miniatures ="";
1093                        $script_miniatures .= "<script type='text/javascript'>
1094                                        var nofile=Array(";
1095                        for ($i=0;$i  <  count($nofiles)-1 ;$i++){
1096                                $file = unserialize($nofiles[$i]);
1097                                $exec_miniatures .=  "{id:'".$file->id."',type:'". $file->type."',file:'". $file->url."',width:'".$theMainImageSize[0]."', height:'".$theMainImageSize[1]."'},\n" ;
1098                        }
1099                        if($i  <  count($nofiles))
1100                        {
1101                                $file = unserialize($nofiles[$i]);
1102                                $exec_miniatures .=  "{id:'".$file->id."',type:'". $file->type."',file:'". $file->url."',width:'".$theMainImageSize[0]."', height:'".$theMainImageSize[1]."'}" ;
1103                        }
1104                        /*** Un seul ***********/
1105                        $file = unserialize($nofiles[count($nofiles)-1]);
1106                        $exec_miniatures =  "{id:'".$file->id."',type:'". $file->type."',file:'". $file->url."',width:'".$theMainImageSize[0]."', height:'".$theMainImageSize[1]."'}" ;
1107
1108                        $script_miniatures  .= $exec_miniatures . "); </script>\n" ;
1109                        $script_miniatures  .= "<script type='text/javascript' >
1110                                        if(typeof nofile!='undefined')
1111                                        getDerivativeUrls(nofile);
1112                                        </script>";
1113                        //==================================================================================
1114                        return $script_miniatures  ;
1115                }
1116        }
1117        /***************************
1118         *  get_cookies
1119        ****************************/
1120        static public  function  get_cookies(){
[22191]1121                global $pictureDeriv,$pictureSelType,$pictureDeriv,$pictureMap,$DEBUG_autosize;
[22133]1122                if(!isset($_COOKIE['picture_deriv'])){
1123                        $pictureDeriv= pwg_get_session_var('picture_deriv');
1124                        $pictureSelType = pwg_get_session_var('picture_sel_type');
1125                        $pictureMap = pwg_get_session_var('picture_map') | $pictureDeriv;
1126                }else{
1127                        $pictureDeriv = $_COOKIE['picture_deriv'];
1128                        $pictureSelType = isset( $_COOKIE['picture_sel_type'])?$_COOKIE['picture_sel_type']:$pictureDeriv;
1129                        $pictureMap =  isset($_COOKIE['picture_map'])?$_COOKIE['picture_map']:$pictureDeriv;
1130                }
1131                $_COOKIE['picture_sel_type']=$pictureSelType;
1132                $_COOKIE['picture_deriv']=$pictureDeriv;
1133                $_COOKIE['picture_map']=$pictureMap;
1134                if(!isset($_COOKIE['picture_deriv'] )){
1135                        if(preg_match("|test_1|", $DEBUG_autosize, $val)) {
1136                                $infos_message .= "not COOKIE['picture_deriv'] -> reload(): <br>";
[22191]1137                                self::Fin_php("#1133 autosize_calcContent:" . $DEBUG_autosize );
[22133]1138                        }
1139                        unset($_COOKIE['autosize_reload']);
1140                }
1141                if (!isset($_COOKIE['autosize_reload'])  ){
1142                        if(preg_match("|test_2|", $DEBUG_autosize, $val)) {
1143                                $infos_message .= "not COOKIE['autosize_reload'] -> reload(): <br>";
[22191]1144                                self::Fin_php("#1140 autosize_calcContent:" . $DEBUG_autosize);
[22133]1145                        }
[22191]1146                        self::reload("#1142");
[22133]1147                }
1148        }
1149        /***************************
1150         * save_cookies
1151        ****************************/
1152        static public  function  save_cookies(){
1153                global $pictureDeriv,$pictureSelType,$pictureDeriv,$pictureMap;
1154
1155                pwg_set_session_var('picture_deriv',$pictureDeriv);
1156                pwg_set_session_var('picture_sel_type',$pictureSelType);
1157                pwg_set_session_var('picture_map',$pictureDeriv);
1158                //============================================================
1159                setcookie( 'picture_sel_type',
1160                $pictureSelType,
1161                time()+5,
1162                cookie_path()
1163                );
1164                //=============================================================
1165                setcookie( 'picture_map',
1166                $pictureDeriv,
1167                time()+5,
1168                cookie_path()
1169                );
1170                //============================================================
1171                setcookie( 'picture_deriv',
1172                $pictureDeriv,
1173                time()+5,
1174                cookie_path()
1175                );
1176                $_COOKIE['picture_sel_type']=$pictureSelType;
1177                $_COOKIE['picture_deriv']=$pictureDeriv;
1178                $_COOKIE['picture_map']=$pictureDeriv;
1179        }
1180
1181        static public function Fin_php($message_){
1182                global  $infos_message;
1183                echo "End :".$message_."<br>";
1184                die($infos_message);
1185        }
1186        //==================================================
[7375]1187} // class
1188
[11961]1189/*************************************
[22133]1190 *
1191*************************************/
1192function cl_autosize_Get_Options()
1193{
1194        global $conf,$autosize_parametres;
1195        $autosize_parametres ="";
1196        if (!isset($conf['cl_autosize']))  {
1197                $conf['cl_autosize']="";
1198                $q = '
1199                                INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
1200                                                VALUES ("cl_autosize","","Parametres du plugin Autosize")
1201                                                ;';
1202                pwg_query($q);
1203        }
1204        $autosize_parametres =  unserialize($conf['cl_autosize']);
1205        // $autosize_parametres = self::Get_Options($autosize_parametres,'cl_autosize');
1206        $autosize_parametres =  cl_autosize_Set_Options();
1207        return $autosize_parametres;
1208}
1209/*
1210 *
1211*/
[11961]1212function cl_autosize_Set_Options() {
[22133]1213        global $autosize_parametres;
1214        //=============================================================================
1215        $my_para=$autosize_parametres;
1216        if (empty($my_para))
1217                $my_para = (object) '';
[16124]1218
[22133]1219        $my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
1220        $my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
[7193]1221
[22133]1222        $my_para->webmaster_type =(isset($_POST['webmaster_type'])) ? $_POST['webmaster_type'] : ((isset($my_para->webmaster_type )) ? $my_para->webmaster_type : 'Autosize' ) ;
[7193]1223
[22133]1224        $my_para->admin_type =(isset($_POST['admin_type'])) ? $_POST['admin_type'] : ((isset($my_para->admin_type )) ? $my_para->admin_type : 'Autosize' ) ;
[7193]1225
[22133]1226        $my_para->generic_type =(isset($_POST['generic_type'])) ? $_POST['generic_type'] : ((isset($my_para->generic_type )) ? $my_para->generic_type : 'Autosize' ) ;
[7193]1227
1228
[22133]1229        $my_para->guest_type =(isset($_POST['guest_type'])) ? $_POST['guest_type'] : ((isset($my_para->guest_type )) ? $my_para->guest_type : 'Autosize' ) ;
[7193]1230
[7725]1231
[22133]1232        $my_para->normal_type =(isset($_POST['normal_type'])) ? $_POST['normal_type'] : ((isset($my_para->normal_type )) ? $my_para->normal_type : 'Autosize' ) ;
[16931]1233
1234
1235
[22133]1236        $my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
1237        $my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
[7962]1238
[22133]1239        $my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
1240        $my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
[7962]1241
[22133]1242        $my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0');
1243        $my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
1244        $my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
[7962]1245
[22133]1246        //===============================================================================
[7193]1247
[22133]1248        if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  {
[7962]1249                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
1250                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
[22133]1251                $my_para->defaut_type= isset($_POST['defaut_type']) ? $_POST['defaut_type'] : "off" ;
[7394]1252
[7962]1253                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
1254                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
1255                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
1256                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
1257                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
[7394]1258
[22133]1259        }else{
1260                $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') ;
1261                $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') ;
1262                $my_para->defaut_type = isset($_POST['defaut_type']) ? $_POST['defaut_type'] : ( ( isset($my_para->defaut_type) ) ? $my_para->defaut_type :   'off') ;
[7394]1263
[22133]1264                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ;
1265                $my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ;
1266                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ;
1267                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
1268                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ;
[7394]1269
1270
[22133]1271        }
[7316]1272
[22133]1273        return $my_para;
[7193]1274}
[22133]1275/*
1276 *
1277*/
[7193]1278function cl_autosize_sauve_options_inf()
1279{
[22133]1280        global $options,$infos_message,$conf,$autosize_parametres  ;
1281        $infos_message .=l10n("cl_autosize_save_config")."<br>";
1282        $autosize_parametres=cl_autosize_Set_Options();
1283        if ( isset($autosize_parametres) )      {
[7193]1284                $query = '
[22133]1285                                UPDATE '.CONFIG_TABLE.'
1286                                                SET value="'.addslashes(serialize($autosize_parametres)).'"
1287                                                                WHERE param = "cl_autosize"
1288                                                                LIMIT 1';
1289                pwg_query($query);
1290        }
1291        if (!isset($conf['cl_derivatives_sav']))  {
1292                $q = '
1293                                INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
1294                                                VALUES ("cl_derivatives_sav","","sauvegarde derivatives")
1295                                                ;';
1296                pwg_query($q);
1297        }
1298}
1299/*************************
[18716]1300 *
[22133]1301*************************/
1302if(!function_exists("cl_print_var")){
1303        function cl_print_var($variables){
1304                ob_start();
1305                echo '<pre>';
1306                print_r($variables);
1307                echo '</pre>';
1308                $m= ob_get_contents();
1309                ob_end_clean();
1310                return $m;
1311        }
[8729]1312}
[18716]1313/******************
[22133]1314 *
[18716]1315******************/
1316if(!function_exists("cl_aff_infos_plus")){
1317        function cl_aff_infos_plus()
[22133]1318        {
1319                global $template,$infos_message,$error_message,$warnings_message, $user ;
1320                global  $conf,$lang,$page  ;
1321                //==============================================================
1322                if (isset($error_message))      {
1323                        if ($error_message <> ""){
1324                                $error_message=str_replace("\n",'<br />',$error_message) ;
1325                                $template->assign('errors',$error_message);
1326                                $error_message="";
1327                        }
1328                }
1329                //==============================================================
1330                if (isset($warnings_message))   {
1331                        if ($warnings_message <> ""){
1332                                $warnings_message=str_replace("\n",'<br />',$warnings_message) ;
1333                                $template->assign('warnings',$warnings_message);
1334                                $warnings_message="";
1335                        }
1336                }
1337                //=============================================
1338                if (isset($infos_message)){
1339                        if ($infos_message <> ""){
1340                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
1341                                $template->assign('infos',$infos_message);
1342                                $infos_message="";
1343                        }
1344                }
1345                //=============================================================
1346                return;
1347
1348        } // function cl_autosize_aff_infos_plus
[18716]1349        //===============================================================
1350}
[7375]1351
[7193]1352?>
Note: See TracBrowser for help on using the repository browser.