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

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

[extensions] Autosize update to piwigo 2.5 (fix bugs with pamooramics, charlies's )

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