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

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

[extensions] Autosize fix compatibility with 2.4, new options

File size: 21.3 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      $file =AUTOSIZE_PATH_ABS.'template/header.tpl' ;
40    $template->set_filenames(array('autosize_init_header'=> $file ));
41    $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
42//================================================================
43$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
44$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
45$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
46//======================================================================
47    $autosize_parametres =       cl_autosize_Get_Options() ;                   
48    $theme=$user['theme'];
49    $template->assign(
50      array(   
51        'autosize_parametres' => $autosize_parametres ,
52        'cl_plugins' => $cl_plugin ,
53        'cl_version' => $cl_plugin['version'] ,
54        'name' => $cl_plugin['name'] ,
55        'pamoorama' =>  isset($PAMOORAMICS_PATH)?"true":"false",                                                                 
56        'theme' => $theme  ,
57        'DEBUG_autosize' =>  $DEBUG_autosize ,
58        'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
59        'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
60        'Version_pwg' => PHPWG_VERSION       
61         )
62    );
63                $template->concat('cl_conflit_init', $template->parse('autosize_init_header', true));
64                return $template->parse( 'autosize_init', false);
65        }// function cl_autosize_script_1
66
67 /*************************************
68 * cl_autosize_script_2()
69 **************************************/
70 static public function cl_autosize_script_2()
71 {
72           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$known_script ;
73   if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
74
75                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
76//================================================================
77$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
78$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
79$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
80//=====================================================================
81
82
83                        $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
84                        $theme=$user['theme'];
85                        if ($ma_page=='thePiwiShackControllerPage') return ;
86
87
88$img_width=isset($picture['current']['width'])?$picture['current']['width']:480;
89$img_height=isset($picture['current']['height'])?$picture['current']['height']:320;
90
91$img_scaled_width=isset($picture['current']['scaled_width'])?$picture['current']['scaled_width']:480;
92$img_scaled_height=isset($picture['current']['scaled_height'])?$picture['current']['scaled_height']:320;
93
94
95
96
97$src_img_h=isset($_POST['src_img_h'])?$_POST['src_img_h']: $img_width               ;
98$src_img_w= isset($_POST['src_img_w'])?$_POST['src_img_w']:$img_height              ;
99if(isset($_COOKIE['img_w'])){
100$src_img_w=$_COOKIE['img_w'];
101$src_img_h=$_COOKIE['img_h'];
102}
103
104$window_height= isset($_POST['window_height'])?$_POST['window_height']: $img_scaled_height ;
105$window_width= isset($_POST['window_width'])?$_POST['window_width']: $img_scaled_width    ;
106
107
108$size=array(
109            'src_img_h' => $src_img_h,
110            'src_img_w' => $src_img_w,
111            'window_height' =>$window_height,
112            'window_width' => $window_width
113
114          );
115
116                        $template->assign(
117                                        array(
118                                        'cl_version' => $cl_plugin['version'] ,
119                                        'name' => $cl_plugin['name'] ,
120                                        'ma_page' =>    $ma_page,
121                                       
122                                        'theme' => $theme  ,
123                                        'DEBUG_autosize' => $DEBUG_autosize   ,
124                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH,
125          'Size' => $size
126           
127                                        )
128                                                );
129  include_once (PHPWG_ROOT_PATH.'include/functions_cookie.inc.php') ;
130                        $autoscript="<script type='text/javascript'>
131                        /* cl_autosize_script_2 */
132                        if (typeof (save_framework) == 'function')
133                           save_framework('".$ma_page."'); 
134       var cookie_path   ='". cookie_path() ."'
135                        </script>";
136         
137
138                $template->append('footer_elements',$autoscript); 
139                return ; 
140 }// function cl_autosize_script_2
141
142        //================================================================
143        /*
144        * cl_autosize_admin
145        */
146        static public function cl_autosize_admin($menu)
147                {
148                global  $lang ;
149                array_push($menu, array('NAME' => 'Autosize',
150                'URL' => get_admin_plugin_menu_link(AUTOSIZE_PATH . 'admin/admin_autosize.php')));
151                return $menu;
152        } //function cl_autosize_admin
153  //=====================================
154
155
156  // this is the default handler that generates the display for the element
157 static public function autosize_RenderContent($content, $element_info)
158{
159  global $conf; 
160  if ( !empty($content) )
161  {// someone hooked us - so we skip;
162    return $content;
163  }
164  if (isset($_COOKIE['picture_deriv']))
165  {
166    if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) )
167    {
168      pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
169    }
170    setcookie('picture_deriv', false, 0, cookie_path() );
171  }
172  $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
173  $selected_derivative = $element_info['derivatives'][$deriv_type];
174
175  $unique_derivatives = array();
176  $show_original = isset($element_info['element_url']);
177  $added = array();
178  foreach($element_info['derivatives'] as $type => $derivative)
179   $element_info['derivatives']['Autosize']=$derivative; // last
180
181  foreach($element_info['derivatives'] as $type => $derivative) {     
182  if ($type=='Autosize'){   
183       
184    $url = $derivative->get_url(); 
185    if (isset($added[$url]))
186      continue;
187    $added[$url] = 1;
188    $show_original &= !($derivative->same_as_source());
189    $unique_derivatives[$type]= $derivative;
190     }
191
192  }
193
194  global $page, $template;
195
196  if ($show_original)
197  {
198    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
199  }
200
201  $template->append('current', array(
202      'selected_derivative' => $selected_derivative,
203      'unique_derivatives' => $unique_derivatives,
204    ), true);   
205      $file =AUTOSIZE_PATH_ABS.'template/picture_content.tpl' ;
206  $template->set_filenames(
207    array('autosize_content'=> $file)
208    );
209
210  $template->assign( array(
211      'ALT_IMG' => $element_info['file'],
212      'COOKIE_PATH' => cookie_path(),
213      )
214    );
215   return $template->parse( 'autosize_content', false);
216 }
217
218    //===============================================================
219        /*
220        *
221        */     
222        static public function cl_autosize_affiche()
223        {
224                global $user, $picture, $template,$page,$known_script;
225                global $content, $element_info;   
226                global $infos_message,$erreur_message;
227                global  $conf,$lang ,$user,$userdata;
228 if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
229                load_language('plugin.lang', AUTOSIZE_PATH);
230                $AUTOSIZE_PATH = dirname(__FILE__).'/';
231                 if (isset( $page['body_id']) && $page['body_id']=='thePicturePage'  ) {
232                        if ( isset($picture['current'])){       
233                                $autosize_parametres = cl_autosize_Get_Options();
234                                include (AUTOSIZE_PATH."include/affiche.php"); 
235        $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
236        $template->set_filenames(array('autosize_content_header'=> $file )); 
237        $template->concat('autosize_content', $template->parse('autosize_content_header', true));                           
238        $template->set_filenames(array('autosize_init_header'=> $file ));
239                $theme=$user['theme'];   
240          $deriv_type = pwg_get_session_var('picture_deriv', IMG_LARGE);                               
241                                if($autosize_parametres->check_icon_v == 'on'){                         
242                                                $template->assign('cl_autosize_button', 
243                                                array(  'cl_autosize_info' => 'cl_autosize_info' ,
244                    'cl_autosize_info_1' => 'cl_autosize_info_' , 
245                                                                    'cl_autosize_info_2' => 'cl_autosize_info_2' ,   
246                                                                    'URL' => $_SERVER['REQUEST_URI'] ,
247                                                                    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
248                                                                    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png',
249                    'ICON1' => AUTOSIZE_PATH . 'icons/button-no.png'
250                                                                )
251
252                                                        ); 
253                                        $template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
254                                        $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
255                                }
256                                 $template->set_filenames(
257                                                array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl',
258             'theme' => $theme   )
259                                        );
260                        $template->concat('autosize_content', $template->parse('autosize_content_header', true));               
261      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
262        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
263        $template->func_combine_script(array('id'=>'my_script_2',
264        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
265        'require' => 'jquery'),
266        $template->smarty);
267        $template->assign(array( 
268                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
269                          ));
270                                       
271        $template->parse('mes_script');
272      }     
273       
274        return $template->parse( 'autosize_content', false);
275                                  }
276                }
277
278        } //public function cl_autosize_affiche
279        //===============================================================
280                /*
281        *
282        */
283        static public function cl_autosize_aff_infos_plus()
284                {
285                 global $template,$infos_message,$erreur_message, $user ;
286                 global  $conf,$lang ;
287       
288                 //==============================================================
289                  if (isset($erreur_message))
290                                {       
291                                if ($erreur_message <> "")
292                                        {
293                                                $erreur_message=str_replace("\n",'<br />',$erreur_message) ;
294                                                $template->assign('errors',$erreur_message);
295                                                $erreur_message="";
296                                        }
297                                }
298                  if (isset($infos_message))
299                                {       
300               
301                                if ($infos_message <> "")
302                                        {
303                                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
304                                                $template->assign('infos',$infos_message);
305                                                $infos_message="";
306                                        }
307                                }
308                                //=============================================================
309                return;         
310               
311                } // function cl_autosize_aff_infos_plus
312        //===============================================================
313        /*
314         *
315        */
316        static public function cl_ajuste_data($content){
317                global  $template,$user,$conf,$picture ;
318      global $size;
319                $AUTOSIZE_PATH = realpath(AUTOSIZE_PATH .'/');
320                $userdata=$user;
321                $fields = array( 'maxwidth', 'maxheight' );
322         
323                $ThePicture = $template->get_template_vars('current'); 
324                $data = array();
325         return $content;
326
327                $data['maxwidth'] = $size['src_img_w'];
328                $data['maxheight'] =$size['src_img_h'];
329                $data['user_id'] = $userdata['id'];
330                foreach ($fields as $field)
331                {
332                        if (isset($_POST[$field]))
333                        {
334                                $data[$field] = $_POST[$field];
335                        }
336                }
337       
338                if($data['maxwidth'] != "" )
339                        {
340                        $picture['current']['scaled_width']=$data['maxwidth'];
341                        $picture['current']['scaled_height']=$data['maxheight'];
342                        mass_updates(USER_INFOS_TABLE,
343                                        array('primary' => array('user_id'), 'update' => $fields),
344                                        array($data)); 
345                        }
346                 
347                        return $content;                                                                                 
348                 }
349
350
351/****************************************
352*
353****************************************/
354function Get_Options(&$parametres,$str_index){
355    global $conf ;
356     if (!isset( $conf[$str_index]))  {   
357      $conf[$str_index]="";
358     }
359    $m_options=  $conf[$str_index];
360     if(isset($m_options))
361       if ( preg_match("|s:(.*)|", $m_options, $val) )
362        $parametres =  unserialize($conf[$str_index]);
363       else{
364         $parametres=explode(",",$_options);
365        }     
366        //====== par defaut =======================
367         $new_val=false;
368         $def_para=Array();
369
370    $def_para['query'] = 'Qt'  ;
371    $def_para['type'] = 'Ty' ;
372
373    $def_para['webmaster_type'] = 'Autosize' ; 
374    $def_para['admin_type'] = 'Autosize'  ; 
375    $def_para['generic_type'] = 'Autosize'  ;
376    $def_para['guest_type'] = 'Autosize'  ;
377    $def_para['normal_type']  =  'Autosize'  ;
378 
379
380
381    $def_para['mini_height'] =  '150' ;
382    $def_para['mini_width'] = '300' ;
383
384    $def_para['mini_height2'] =  '150' ;
385    $def_para['mini_width2'] =   '300' ;
386
387    $def_para['echelle_max'] =  '1.0'; 
388    $def_para['marge_basse'] =  '0';
389    $def_para['fade_in'] =   '0';
390    //==================================================
391    $def_para['check_desc_v'] =  "off" ;
392    $def_para['check_icon_v'] =  "off" ;
393   
394    $def_para['webmaster_enabled'] =   "off" ;
395    $def_para['admin_enabled'] =   "off" ;
396    $def_para['generic_enabled'] =   "off" ;
397    $def_para['guest_enabled'] =   "off" ;
398    $def_para['normal_enabled'] =   "off" ;
399    //===================================================
400   $para=$def_para;   
401    foreach ($para as $key => $value) {   
402      if( isset($parametres->$key) ){
403         $value=$parametres->$key;         
404      } 
405    if($def_para[$key] =="on" ||$def_para[$key] =="off" ){
406       $val_pg=(isset($_POST[$key]))? ($_POST[$key]=="off"||$_POST[$key]=="on")?$_POST[$key]:"on" : "off" ;
407       $value =(isset($_POST[$key]))? $val_pg : $value ; 
408       $val_pg=(isset($_GET[$key]))? ($_GET[$key]=="off"||$_GET[$key]=="on")?$_GET[$key]:"on" : "off" ;
409       $value =(isset($_GET[$key]))? $val_pg  : $value ; 
410     }else{
411        $value =(isset($_POST[$key]))? $_POST[$key] : $value ; 
412        $value =(isset($_GET[$key]))? $_GET[$key] : $value ; 
413      }
414        unset( $parametres->$key) ;
415        $parametres->$key = $value ;           
416     }   
417    return $parametres ;
418  }
419} // class
420
421/*************************************
422        *
423 *************************************/
424 function cl_autosize_Get_Options()
425  {
426                global $conf,$autosize_parametres; 
427    $autosize_parametres ="";
428 
429 if (!isset($conf['cl_autosize']))  {   
430  $conf['cl_autosize']="";
431  $q = '
432   INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
433   VALUES ("cl_autosize","","Parametres du plugin Autosize")
434  ;';
435  pwg_query($q);
436  }
437 
438 
439
440                $autosize_parametres =  unserialize($conf['cl_autosize']);
441      // $autosize_parametres = autosize_controler::Get_Options($autosize_parametres,'cl_autosize');
442                $autosize_parametres =  cl_autosize_Set_Options();
443                return $autosize_parametres;
444  }
445        /*
446        *
447        */
448function cl_autosize_Set_Options() {
449  global $autosize_parametres;
450//=============================================================================
451$my_para=$autosize_parametres;
452  if (empty($my_para))
453$my_para = (object) '';
454
455$my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
456$my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
457
458$my_para->webmaster_type =(isset($_POST['webmaster_type'])) ? $_POST['webmaster_type'] : ((isset($my_para->webmaster_type )) ? $my_para->webmaster_type : 'Autosize' ) ;
459
460$my_para->admin_type =(isset($_POST['admin_type'])) ? $_POST['admin_type'] : ((isset($my_para->admin_type )) ? $my_para->admin_type : 'Autosize' ) ;
461
462$my_para->generic_type =(isset($_POST['generic_type'])) ? $_POST['generic_type'] : ((isset($my_para->generic_type )) ? $my_para->generic_type : 'Autosize' ) ;
463
464
465$my_para->guest_type =(isset($_POST['guest_type'])) ? $_POST['guest_type'] : ((isset($my_para->guest_type )) ? $my_para->guest_type : 'Autosize' ) ;
466
467
468$my_para->normal_type =(isset($_POST['normal_type'])) ? $_POST['normal_type'] : ((isset($my_para->normal_type )) ? $my_para->normal_type : 'Autosize' ) ;
469
470
471
472$my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
473$my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
474
475$my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
476$my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
477
478$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
479$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
480$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
481
482//===============================================================================       
483
484if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
485                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
486                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
487       
488
489                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
490                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
491                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
492                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
493                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
494
495         }else{
496                $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') ; 
497                $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') ; 
498
499
500
501$my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ; 
502$my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ; 
503$my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ; 
504$my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
505$my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ; 
506
507
508   }
509
510return $my_para;
511}
512        /*
513        *
514        */
515function cl_autosize_sauve_options_inf()
516{
517global $options,$infos_message,$conf,$autosize_parametres  ;
518$infos_message .=l10n("cl_autosize_save_config")."<br>";
519 $autosize_parametres=cl_autosize_Set_Options();
520 if ( isset($autosize_parametres) )     { 
521                $query = '
522                UPDATE '.CONFIG_TABLE.'
523                SET value="'.addslashes(serialize($autosize_parametres)).'"
524                WHERE param = "cl_autosize"
525                LIMIT 1';
526                        pwg_query($query);
527          }
528         
529 }
530
531 function auto_memo_var($variables)
532{
533  ob_start();
534  echo '<pre>';
535  print_r($variables);
536  echo '</pre>';
537  $m= ob_get_contents();
538  ob_end_clean();
539  return $m;           
540}
541   
542
543?>
Note: See TracBrowser for help on using the repository browser.