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

Last change on this file since 16859 was 16579, checked in by cljosse, 12 years ago

[extensions] Autosize fix compatibility with 2.4

File size: 20.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// | Autosize                                                              |
5// +-----------------------------------------------------------------------+
6// | Copyright(C) 2010      cljosse                                        |
7// +-----------------------------------------------------------------------+
8// | This program is free software; you can redistribute it and/or modify  |
9// | it under the terms of the GNU General Public License as published by  |
10// | the Free Software Foundation                                          |
11// |                                                                       |
12// | This program is distributed in the hope that it will be useful, but   |
13// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
14// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
15// | General Public License for more details.                              |
16// |                                                                       |
17// | You should have received a copy of the GNU General Public License     |
18// | along with this program; if not, write to the Free Software           |
19// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
20// | USA.                                                                  |
21// +-----------------------------------------------------------------------+
22class autosize_controler {
23 //============================================================
24 /*
25  *  cl_autosize_script_1
26 */
27 static public function cl_autosize_script_1()
28        {
29                global  $template,$user,$conf,$picture ,$page, $cl_plugin ;
30 
31 // header ('X-UA-Compatible: n=7')  ;
32 // header ('X-UA-Compatible: IE=Edge')  ;
33  if(isset($page['body_id']) && $page['body_id'] == 'theAdminPage' ) return ;
34
35    if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
36     
37    $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
38    if ($ma_page=='thePiwiShackControllerPage') return ;
39
40
41    if (PHPWG_VERSION < 2.2 ) 
42      $file =AUTOSIZE_PATH_ABS.'template/header_2_1.tpl' ;
43    else 
44      $file =AUTOSIZE_PATH_ABS.'template/header_2_2.tpl' ;
45    $template->set_filenames(array('autosize_init_header'=> $file ));
46    $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
47//=================================================================================================
48$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
49$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
50$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
51//=================================================================================================
52    $autosize_parametres =       cl_autosize_Get_Options() ;                   
53    $theme=$user['theme'];
54    $template->assign(
55      array(   
56        'autosize_parametres' => $autosize_parametres ,
57        'cl_plugins' => $cl_plugin ,
58        'cl_version' => $cl_plugin['version'] ,
59        'name' => $cl_plugin['name'] ,
60        'pamoorama' =>  isset($PAMOORAMICS_PATH)?"true":"false",                                                                 
61        'theme' => $theme  ,
62        'DEBUG_autosize' =>  $DEBUG_autosize ,
63        'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
64        'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
65        'Version_pwg' => PHPWG_VERSION       
66         )
67    );
68                $template->concat('cl_conflit_init', $template->parse('autosize_init_header', true));
69                return $template->parse( 'autosize_init', false);
70        }// function cl_autosize_script_1
71 //===========================================================
72 /*
73  * cl_autosize_script_2()
74 */
75 static public function cl_autosize_script_2()
76 {
77           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$known_script ;
78   if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
79
80                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
81//=================================================================================================
82$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
83$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
84$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
85//=================================================================================================
86
87
88                        $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
89                        $theme=$user['theme'];
90                        if ($ma_page=='thePiwiShackControllerPage') return ;
91
92
93$img_width=isset($picture['current']['width'])?$picture['current']['width']:480;
94$img_height=isset($picture['current']['height'])?$picture['current']['height']:320;
95
96$img_scaled_width=isset($picture['current']['scaled_width'])?$picture['current']['scaled_width']:480;
97$img_scaled_height=isset($picture['current']['scaled_height'])?$picture['current']['scaled_height']:320;
98
99
100
101
102$src_img_h=isset($_POST['src_img_h'])?$_POST['src_img_h']: $img_width               ;
103$src_img_w= isset($_POST['src_img_w'])?$_POST['src_img_w']:$img_height              ;
104if(isset($_COOKIE['img_w'])){
105$src_img_w=$_COOKIE['img_w'];
106$src_img_h=$_COOKIE['img_h'];
107}
108
109$window_height= isset($_POST['window_height'])?$_POST['window_height']: $img_scaled_height ;
110$window_width= isset($_POST['window_width'])?$_POST['window_width']: $img_scaled_width    ;
111
112
113$size=array(
114            'src_img_h' => $src_img_h,
115            'src_img_w' => $src_img_w,
116            'window_height' =>$window_height,
117            'window_width' => $window_width
118
119          );
120
121                        $template->assign(
122                                        array(
123                                        'cl_version' => $cl_plugin['version'] ,
124                                        'name' => $cl_plugin['name'] ,
125                                        'ma_page' =>    $ma_page,
126                                       
127                                        'theme' => $theme  ,
128                                        'DEBUG_autosize' => $DEBUG_autosize   ,
129                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH,
130          'Size' => $size
131           
132                                        )
133                                                );
134  include_once (PHPWG_ROOT_PATH.'include/functions_cookie.inc.php') ;
135                        $autoscript="<script type='text/javascript'>
136                        /* cl_autosize_script_2 */
137                        if (typeof (save_framework) == 'function')
138                           save_framework('".$ma_page."'); 
139       var cookie_path   ='". cookie_path() ."'
140                        </script>";
141         
142
143                $template->append('footer_elements',$autoscript); 
144                return ; 
145 }// function cl_autosize_script_2
146
147        //================================================================
148        /*
149        * cl_autosize_admin
150        */
151        static public function cl_autosize_admin($menu)
152                {
153                global  $lang ;
154                array_push($menu, array('NAME' => 'Autosize',
155                'URL' => get_admin_plugin_menu_link(AUTOSIZE_PATH . 'admin/admin_autosize.php')));
156                return $menu;
157        } //function cl_autosize_admin
158
159    //===============================================================
160        /*
161        *
162        */     
163        static public function cl_autosize_affiche()
164        {
165                global $user, $picture, $template,$page,$known_script;
166                global $content, $element_info;   
167                global $infos_message,$erreur_message;
168                global  $conf,$lang ,$user,$userdata;
169 if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
170                load_language('plugin.lang', AUTOSIZE_PATH);
171                $AUTOSIZE_PATH = dirname(__FILE__).'/';
172                 if (isset( $page['body_id']) && $page['body_id']=='thePicturePage'  ) {
173                        if ( isset($picture['current'])){       
174                                $autosize_parametres = cl_autosize_Get_Options();
175                                include (AUTOSIZE_PATH."include/affiche.php"); 
176
177       if (PHPWG_VERSION < 2.2 ) 
178                $file =AUTOSIZE_PATH_ABS.'template/picture_2_1.tpl' ;
179        else 
180                $file =AUTOSIZE_PATH_ABS.'template/picture_2_2.tpl' ;
181
182
183
184        $template->set_filenames(array('autosize_content_header'=> $file )); 
185        $template->concat('autosize_content', $template->parse('autosize_content_header', true));   
186                       
187        $template->set_filenames(array('autosize_init_header'=> $file ));
188                                       
189                                if($autosize_parametres->check_icon_v == 'on'){                         
190                                                $template->assign('cl_autosize_button', 
191                                                array(  'cl_autosize_info' => 'cl_autosize_info' ,
192            'cl_autosize_info_1' => 'cl_autosize_info_' , 
193                                                                    'cl_autosize_info_2' => 'cl_autosize_info_2' ,   
194                                                                    'URL' => $_SERVER['REQUEST_URI'] ,
195                                                                    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
196                                                                    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png'
197                                                                )
198
199                                                        ); 
200                                        $template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
201                                        $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
202                                }
203                                 $template->set_filenames(
204                                                array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl')
205                                        );
206                        $template->concat('autosize_content', $template->parse('autosize_content_header', true));               
207      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
208        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
209        $template->func_combine_script(array('id'=>'my_script_2',
210        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
211        'require' => 'jquery'),
212        $template->smarty);
213        $template->assign(array( 
214                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
215                          ));
216                                       
217        $template->parse('mes_script');
218      }     
219       
220       
221       
222        return $template->parse( 'autosize_content', false);
223                                  }
224                }
225
226        } //public function cl_autosize_affiche
227        //===============================================================
228                /*
229        *
230        */
231        static public function cl_autosize_aff_infos_plus()
232                {
233                 global $template,$infos_message,$erreur_message, $user ;
234                 global  $conf,$lang ;
235       
236                 //==============================================================
237                  if (isset($erreur_message))
238                                {       
239                                if ($erreur_message <> "")
240                                        {
241                                                $erreur_message=str_replace("\n",'<br />',$erreur_message) ;
242                                                $template->assign('errors',$erreur_message);
243                                                $erreur_message="";
244                                        }
245                                }
246                  if (isset($infos_message))
247                                {       
248               
249                                if ($infos_message <> "")
250                                        {
251                                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
252                                                $template->assign('infos',$infos_message);
253                                                $infos_message="";
254                                        }
255                                }
256                                //=============================================================
257                return;         
258               
259                } // function cl_autosize_aff_infos_plus
260        //===============================================================
261        /*
262         *
263        */
264        static public function cl_ajuste_data($content){
265                global  $template,$user,$conf,$picture ;
266      global $size;
267                $AUTOSIZE_PATH = realpath(AUTOSIZE_PATH .'/');
268                $userdata=$user;
269                $fields = array( 'maxwidth', 'maxheight' );
270         
271                $ThePicture = $template->get_template_vars('current'); 
272                $data = array();
273         return $content;
274
275                $data['maxwidth'] = $size['src_img_w'];
276                $data['maxheight'] =$size['src_img_h'];
277                $data['user_id'] = $userdata['id'];
278                foreach ($fields as $field)
279                {
280                        if (isset($_POST[$field]))
281                        {
282                                $data[$field] = $_POST[$field];
283                        }
284                }
285       
286                if($data['maxwidth'] != "" )
287                        {
288                        $picture['current']['scaled_width']=$data['maxwidth'];
289                        $picture['current']['scaled_height']=$data['maxheight'];
290                        mass_updates(USER_INFOS_TABLE,
291                                        array('primary' => array('user_id'), 'update' => $fields),
292                                        array($data)); 
293                        }
294                 
295                        return $content;                                                                                 
296                 }
297
298
299/****************************************
300*
301****************************************/
302function Get_Options(&$parametres,$str_index){
303    global $conf ;
304     if (!isset( $conf[$str_index]))  {   
305      $conf[$str_index]="";
306     }
307    $m_options=  $conf[$str_index];
308     if(isset($m_options))
309       if ( preg_match("|s:(.*)|", $m_options, $val) )
310        $parametres =  unserialize($conf[$str_index]);
311       else{
312         $parametres=explode(",",$_options);
313        }     
314        //====== par defaut =======================
315         $new_val=false;
316         $def_para=Array();
317
318    $def_para['query'] = 'Qt'  ;
319    $def_para['type'] = 'Ty' ;
320    $def_para['webmaster_height'] = '100%' ;
321    $def_para['webmaster_width'] = '100%' ;
322    $def_para['admin_height'] = '100%'  ;
323    $def_para['admin_width'] =  '100%' ;
324    $def_para['generic_height'] = '100%'  ;
325    $def_para['generic_width'] =  '100%' ;
326
327    $def_para['guest_height'] = '100%'  ;
328    $def_para['guest_width'] =  '100%' ;
329
330    $def_para['normal_height']  =  '100%'  ;
331    $def_para['normal_width'] =  '100%' ;
332
333
334    $def_para['mini_height'] =  '150' ;
335    $def_para['mini_width'] = '300' ;
336
337    $def_para['mini_height2'] =  '150' ;
338    $def_para['mini_width2'] =   '300' ;
339
340    $def_para['echelle_max'] =  '1.0'; 
341    $def_para['marge_basse'] =  '0';
342    $def_para['fade_in'] =   '0';
343    //==================================================
344    $def_para['check_desc_v'] =  "off" ;
345    $def_para['check_icon_v'] =  "off" ;
346    $def_para['check_auto_w'] =   "off" ;
347    $def_para['webmaster_enabled'] =   "off" ;
348    $def_para['admin_enabled'] =   "off" ;
349    $def_para['generic_enabled'] =   "off" ;
350    $def_para['guest_enabled'] =   "off" ;
351    $def_para['normal_enabled'] =   "off" ;
352    //===================================================
353   $para=$def_para;   
354    foreach ($para as $key => $value) {   
355      if( isset($parametres->$key) ){
356         $value=$parametres->$key;         
357      } 
358    if($def_para[$key] =="on" ||$def_para[$key] =="off" ){
359       $val_pg=(isset($_POST[$key]))? ($_POST[$key]=="off"||$_POST[$key]=="on")?$_POST[$key]:"on" : "off" ;
360       $value =(isset($_POST[$key]))? $val_pg : $value ; 
361       $val_pg=(isset($_GET[$key]))? ($_GET[$key]=="off"||$_GET[$key]=="on")?$_GET[$key]:"on" : "off" ;
362       $value =(isset($_GET[$key]))? $val_pg  : $value ; 
363     }else{
364        $value =(isset($_POST[$key]))? $_POST[$key] : $value ; 
365        $value =(isset($_GET[$key]))? $_GET[$key] : $value ; 
366      }
367        unset( $parametres->$key) ;
368        $parametres->$key = $value ;           
369     }   
370    return $parametres ;
371  }
372} // class
373
374/*************************************
375        *
376 *************************************/
377 function cl_autosize_Get_Options()
378  {
379                global $conf,$autosize_parametres; 
380    $autosize_parametres ="";
381 
382 if (!isset($conf['cl_autosize']))  {   
383  $conf['cl_autosize']="";
384  $q = '
385   INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
386   VALUES ("cl_autosize","","Parametres du plugin Autosize")
387  ;';
388  pwg_query($q);
389  }
390 
391 
392
393                $autosize_parametres =  unserialize($conf['cl_autosize']);
394      // $autosize_parametres = autosize_controler::Get_Options($autosize_parametres,'cl_autosize');
395                $autosize_parametres =  cl_autosize_Set_Options();
396                return $autosize_parametres;
397  }
398        /*
399        *
400        */
401function cl_autosize_Set_Options() {
402  global $autosize_parametres;
403//=============================================================================
404$my_para=$autosize_parametres;
405
406
407  if (empty($my_para))
408$my_para = (object) '';
409
410$my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
411$my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
412
413$my_para->webmaster_height =(isset($_POST['webmaster_height'])) ? $_POST['webmaster_height'] : ((isset($my_para->webmaster_height )) ? $my_para->webmaster_height : '100%' ) ;
414$my_para->webmaster_width=(isset($_POST['webmaster_width']))? $_POST['webmaster_width']: ((isset($my_para->webmaster_width)) ? $my_para->webmaster_width:  '100%') ;
415
416$my_para->admin_height =(isset($_POST['admin_height'])) ? $_POST['admin_height'] : ((isset($my_para->admin_height )) ? $my_para->admin_height : '100%' ) ;
417$my_para->admin_width=(isset($_POST['admin_width']))? $_POST['admin_width']: ((isset($my_para->admin_width)) ? $my_para->admin_width:  '100%') ;
418
419$my_para->generic_height =(isset($_POST['generic_height'])) ? $_POST['generic_height'] : ((isset($my_para->generic_height )) ? $my_para->generic_height : '100%' ) ;
420$my_para->generic_width=(isset($_POST['generic_width']))? $_POST['generic_width']: ((isset($my_para->generic_width)) ? $my_para->generic_width:  '100%') ;
421
422$my_para->guest_height =(isset($_POST['guest_height'])) ? $_POST['guest_height'] : ((isset($my_para->guest_height )) ? $my_para->guest_height : '100%' ) ;
423$my_para->guest_width=(isset($_POST['guest_width']))? $_POST['guest_width']: ((isset($my_para->guest_width)) ? $my_para->guest_width:  '100%') ;
424
425$my_para->normal_height =(isset($_POST['normal_height'])) ? $_POST['normal_height'] : ((isset($my_para->normal_height )) ? $my_para->normal_height : '100%' ) ;
426$my_para->normal_width=(isset($_POST['normal_width']))? $_POST['normal_width']: ((isset($my_para->normal_width)) ? $my_para->normal_width:  '100%') ;
427
428
429$my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
430$my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
431
432$my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
433$my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
434
435$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
436$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
437$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
438
439//===============================================================================       
440
441if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
442                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
443                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
444                $my_para->check_auto_w = isset($_POST['check_auto_w']) ? $_POST['check_auto_w'] : "off" ;
445
446                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
447                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
448                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
449                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
450                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
451
452         }else{
453                $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') ; 
454                $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') ; 
455                $my_para->check_auto_w = isset($_POST['check_auto_w']) ? $_POST['check_auto_w'] : ( ( isset($my_para->check_auto_w) ) ? $my_para->check_auto_w :   'off') ; 
456
457
458$my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ; 
459$my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ; 
460$my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ; 
461$my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
462$my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ; 
463
464
465   }
466
467return $my_para;
468}
469        /*
470        *
471        */
472function cl_autosize_sauve_options_inf()
473{
474global $options,$infos_message,$conf,$autosize_parametres  ;
475$infos_message .=l10n("cl_autosize_save_config")."<br>";
476 $autosize_parametres=cl_autosize_Set_Options();
477 if ( isset($autosize_parametres) )     { 
478                $query = '
479                UPDATE '.CONFIG_TABLE.'
480                SET value="'.addslashes(serialize($autosize_parametres)).'"
481                WHERE param = "cl_autosize"
482                LIMIT 1';
483                        pwg_query($query);
484          }
485         
486 }
487
488 function auto_memo_var($variables)
489{
490  ob_start();
491  echo '<pre>';
492  print_r($variables);
493  echo '</pre>';
494  $m= ob_get_contents();
495  ob_end_clean();
496  return $m;           
497}
498   
499
500?>
Note: See TracBrowser for help on using the repository browser.