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

Last change on this file since 12153 was 11961, checked in by cljosse, 13 years ago

[extensions] Autosize fix compatibility with 'charlies video'

File size: 20.1 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
53    $autosize_parametres =       cl_autosize_Get_Options() ;                   
54    $theme=$user['theme'];
55    $template->assign(
56      array(   
57        'autosize_parametres' => $autosize_parametres ,
58        'cl_plugins' => $cl_plugin ,
59        'cl_version' => $cl_plugin['version'] ,
60        'name' => $cl_plugin['name'] ,
61        'pamoorama' =>  isset($PAMOORAMICS_PATH)?"true":"false",                                                                 
62        'theme' => $theme  ,
63        'DEBUG_autosize' =>  $DEBUG_autosize ,
64        'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
65        'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
66        'Version_pwg' => PHPWG_VERSION
67         )
68    );
69                $template->concat('cl_conflit_init', $template->parse('autosize_init_header', true));
70                return $template->parse( 'autosize_init', false);
71        }// function cl_autosize_script_1
72 //===========================================================
73 /*
74  * cl_autosize_script_2(admin)
75 */
76 static public function cl_autosize_script_2()
77 {
78           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$known_script ;
79   if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
80
81                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
82//=================================================================================================
83$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
84$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
85$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
86//=================================================================================================
87
88
89                        $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
90                        $theme=$user['theme'];
91                        if ($ma_page=='thePiwiShackControllerPage') return ;
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$src_img_h=isset($_POST['src_img_h'])?$_POST['src_img_h']: $img_width               ;
99$src_img_w= isset($_POST['src_img_w'])?$_POST['src_img_w']:$img_height              ;
100$window_height= isset($_POST['window_height'])?$_POST['window_height']: $img_scaled_height ;
101$window_width= isset($_POST['window_width'])?$_POST['window_width']: $img_scaled_width    ;
102
103
104$size=array(
105            'src_img_h' => $src_img_h,
106            'src_img_w' => $src_img_w,
107            'window_height' =>$window_height,
108            'window_width' => $window_width
109          );
110
111                        $template->assign(
112                                        array(
113                                        'cl_version' => $cl_plugin['version'] ,
114                                        'name' => $cl_plugin['name'] ,
115                                        'ma_page' =>    $ma_page,
116                                       
117                                        'theme' => $theme  ,
118                                        'DEBUG_autosize' => $DEBUG_autosize   ,
119                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH,
120          'Size' => $size
121
122                                        )
123                                                );
124                                                 
125                        $autoscript="<script type='text/javascript'>
126                        /* cl_autosize_script_2 */
127                        if (typeof (save_framework) == 'function')
128                           save_framework('".$ma_page."');
129                        </script>";
130         
131
132                $template->append('footer_elements',$autoscript); 
133                return ; 
134 }// function cl_autosize_script_2
135
136        //================================================================
137        /*
138        * cl_autosize_admin
139        */
140        static public function cl_autosize_admin($menu)
141                {
142                global  $lang ;
143                array_push($menu, array('NAME' => 'Autosize',
144                'URL' => get_admin_plugin_menu_link(AUTOSIZE_PATH . 'admin/admin_autosize.php')));
145                return $menu;
146        } //function cl_autosize_admin
147
148    //===============================================================
149        /*
150        *
151        */     
152        static public function cl_autosize_affiche()
153        {
154                global $user, $picture, $template,$page,$known_script;
155                global $content, $element_info;   
156                global $infos_message,$erreur_message;
157                global  $conf,$lang ,$user,$userdata;
158 if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
159                load_language('plugin.lang', AUTOSIZE_PATH);
160                $AUTOSIZE_PATH = dirname(__FILE__).'/';
161                 if (isset( $page['body_id']) && $page['body_id']=='thePicturePage'  ) {
162                        if ( isset($picture['current'])){       
163                                $autosize_parametres = cl_autosize_Get_Options();
164                                include (AUTOSIZE_PATH."include/affiche.php"); 
165
166       if (PHPWG_VERSION < 2.2 ) 
167                $file =AUTOSIZE_PATH_ABS.'template/picture_2_1.tpl' ;
168        else 
169                $file =AUTOSIZE_PATH_ABS.'template/picture_2_2.tpl' ;
170
171
172
173        $template->set_filenames(array('autosize_content_header'=> $file )); 
174        $template->concat('autosize_content', $template->parse('autosize_content_header', true));   
175                       
176        $template->set_filenames(array('autosize_init_header'=> $file ));
177                                       
178                                if($autosize_parametres->check_icon_v == 'on'){                         
179                                                $template->assign('cl_autosize_button', 
180                                                array(  'cl_autosize_info' => 'cl_autosize_info' ,
181                                                                    'cl_autosize_info_2' => 'cl_autosize_info_2' ,   
182                                                                    'URL' => $_SERVER['REQUEST_URI'] ,
183                                                                    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
184                                                                    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png'
185                                                                )
186
187                                                        ); 
188                                        $template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
189                                        $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
190                                }
191                                 $template->set_filenames(
192                                                array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl')
193                                        );
194                        $template->concat('autosize_content', $template->parse('autosize_content_header', true));               
195      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
196        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
197        $template->func_combine_script(array('id'=>'my_script_2',
198        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
199        'require' => 'jquery'),
200        $template->smarty);
201        $template->assign(array( 
202                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
203                          ));
204                                       
205        $template->parse('mes_script');
206      }     
207       
208       
209       
210        return $template->parse( 'autosize_content', false);
211                                  }
212                }
213
214        } //public function cl_autosize_affiche
215        //===============================================================
216                /*
217        *
218        */
219        static public function cl_autosize_aff_infos_plus()
220                {
221                 global $template,$infos_message,$erreur_message, $user ;
222                 global  $conf,$lang ;
223       
224                 //==============================================================
225                  if (isset($erreur_message))
226                                {       
227                                if ($erreur_message <> "")
228                                        {
229                                                $erreur_message=str_replace("\n",'<br />',$erreur_message) ;
230                                                $template->assign('errors',$erreur_message);
231                                                $erreur_message="";
232                                        }
233                                }
234                  if (isset($infos_message))
235                                {       
236               
237                                if ($infos_message <> "")
238                                        {
239                                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
240                                                $template->assign('infos',$infos_message);
241                                                $infos_message="";
242                                        }
243                                }
244                                //=============================================================
245                return;         
246               
247                } // function cl_autosize_aff_infos_plus
248        //===============================================================
249        /*
250         *
251        */
252        static public function cl_ajuste_data($content){
253                global  $template,$user,$conf,$picture ;
254      global $size;
255                $AUTOSIZE_PATH = realpath(AUTOSIZE_PATH .'/');
256                $userdata=$user;
257                $fields = array( 'maxwidth', 'maxheight' );
258         
259                $ThePicture = $template->get_template_vars('current'); 
260                $data = array();
261         return $content;
262
263                $data['maxwidth'] = $size['src_img_w'];
264                $data['maxheight'] =$size['src_img_h'];
265                $data['user_id'] = $userdata['id'];
266                foreach ($fields as $field)
267                {
268                        if (isset($_POST[$field]))
269                        {
270                                $data[$field] = $_POST[$field];
271                        }
272                }
273       
274                if($data['maxwidth'] != "" )
275                        {
276                        $picture['current']['scaled_width']=$data['maxwidth'];
277                        $picture['current']['scaled_height']=$data['maxheight'];
278                        mass_updates(USER_INFOS_TABLE,
279                                        array('primary' => array('user_id'), 'update' => $fields),
280                                        array($data)); 
281                        }
282                 
283                        return $content;                                                                                 
284                 }
285
286
287/****************************************
288*
289****************************************/
290function Get_Options(&$parametres,$str_index){
291    global $conf ;
292    $m_options=  $conf[$str_index];
293     if(isset($m_options))
294       if ( preg_match("|s:(.*)|", $m_options, $val) )
295        $parametres =  unserialize($conf[$str_index]);
296       else{
297         $parametres=explode(",",$_options);
298        }     
299        //====== par defaut =======================
300         $new_val=false;
301         $def_para=Array();
302
303    $def_para['query'] = 'Qt'  ;
304    $def_para['type'] = 'Ty' ;
305    $def_para['webmaster_height'] = '100%' ;
306    $def_para['webmaster_width'] = '100%' ;
307    $def_para['admin_height'] = '100%'  ;
308    $def_para['admin_width'] =  '100%' ;
309    $def_para['generic_height'] = '100%'  ;
310    $def_para['generic_width'] =  '100%' ;
311
312    $def_para['guest_height'] = '100%'  ;
313    $def_para['guest_width'] =  '100%' ;
314
315    $def_para['normal_height']  =  '100%'  ;
316    $def_para['normal_width'] =  '100%' ;
317
318
319    $def_para['mini_height'] =  '150' ;
320    $def_para['mini_width'] = '300' ;
321
322    $def_para['mini_height2'] =  '150' ;
323    $def_para['mini_width2'] =   '300' ;
324
325    $def_para['echelle_max'] =  '1.0'; 
326    $def_para['marge_basse'] =  '0';
327    $def_para['fade_in'] =   '0';
328    //==================================================
329    $def_para['check_desc_v'] =  "off" ;
330    $def_para['check_icon_v'] =  "off" ;
331    $def_para['check_auto_w'] =   "off" ;
332    $def_para['webmaster_enabled'] =   "off" ;
333    $def_para['admin_enabled'] =   "off" ;
334    $def_para['generic_enabled'] =   "off" ;
335    $def_para['guest_enabled'] =   "off" ;
336    $def_para['normal_enabled'] =   "off" ;
337    //===================================================
338   $para=$def_para;   
339    foreach ($para as $key => $value) {   
340      if( isset($parametres->$key) ){
341         $value=$parametres->$key;         
342      } 
343    if($def_para[$key] =="on" ||$def_para[$key] =="off" ){
344       $val_pg=(isset($_POST[$key]))? ($_POST[$key]=="off"||$_POST[$key]=="on")?$_POST[$key]:"on" : "off" ;
345       $value =(isset($_POST[$key]))? $val_pg : $value ; 
346       $val_pg=(isset($_GET[$key]))? ($_GET[$key]=="off"||$_GET[$key]=="on")?$_GET[$key]:"on" : "off" ;
347       $value =(isset($_GET[$key]))? $val_pg  : $value ; 
348     }else{
349        $value =(isset($_POST[$key]))? $_POST[$key] : $value ; 
350        $value =(isset($_GET[$key]))? $_GET[$key] : $value ; 
351      }
352        unset( $parametres->$key) ;
353        $parametres->$key = $value ;           
354     }   
355    return $parametres ;
356  }
357} // class
358
359/*************************************
360        *
361 *************************************/
362 function cl_autosize_Get_Options()
363  {
364                global $conf,$autosize_parametres; 
365                $autosize_parametres =  unserialize($conf['cl_autosize']);
366      // $autosize_parametres = autosize_controler::Get_Options($autosize_parametres,'cl_autosize');
367                $autosize_parametres =  cl_autosize_Set_Options();
368                return $autosize_parametres;
369  }
370        /*
371        *
372        */
373function cl_autosize_Set_Options() {
374  global $autosize_parametres;
375//=============================================================================
376$my_para=$autosize_parametres;
377
378
379$my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
380$my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
381
382$my_para->webmaster_height =(isset($_POST['webmaster_height'])) ? $_POST['webmaster_height'] : ((isset($my_para->webmaster_height )) ? $my_para->webmaster_height : '100%' ) ;
383$my_para->webmaster_width=(isset($_POST['webmaster_width']))? $_POST['webmaster_width']: ((isset($my_para->webmaster_width)) ? $my_para->webmaster_width:  '100%') ;
384
385$my_para->admin_height =(isset($_POST['admin_height'])) ? $_POST['admin_height'] : ((isset($my_para->admin_height )) ? $my_para->admin_height : '100%' ) ;
386$my_para->admin_width=(isset($_POST['admin_width']))? $_POST['admin_width']: ((isset($my_para->admin_width)) ? $my_para->admin_width:  '100%') ;
387
388$my_para->generic_height =(isset($_POST['generic_height'])) ? $_POST['generic_height'] : ((isset($my_para->generic_height )) ? $my_para->generic_height : '100%' ) ;
389$my_para->generic_width=(isset($_POST['generic_width']))? $_POST['generic_width']: ((isset($my_para->generic_width)) ? $my_para->generic_width:  '100%') ;
390
391$my_para->guest_height =(isset($_POST['guest_height'])) ? $_POST['guest_height'] : ((isset($my_para->guest_height )) ? $my_para->guest_height : '100%' ) ;
392$my_para->guest_width=(isset($_POST['guest_width']))? $_POST['guest_width']: ((isset($my_para->guest_width)) ? $my_para->guest_width:  '100%') ;
393
394$my_para->normal_height =(isset($_POST['normal_height'])) ? $_POST['normal_height'] : ((isset($my_para->normal_height )) ? $my_para->normal_height : '100%' ) ;
395$my_para->normal_width=(isset($_POST['normal_width']))? $_POST['normal_width']: ((isset($my_para->normal_width)) ? $my_para->normal_width:  '100%') ;
396
397
398$my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
399$my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
400
401$my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
402$my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
403
404$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
405$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
406$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
407
408//===============================================================================       
409
410if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
411                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
412                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
413                $my_para->check_auto_w = isset($_POST['check_auto_w']) ? $_POST['check_auto_w'] : "off" ;
414
415                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
416                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
417                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
418                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
419                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
420
421         }else{
422                $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') ; 
423                $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') ; 
424                $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') ; 
425
426
427$my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ; 
428$my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ; 
429$my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ; 
430$my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
431$my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ; 
432
433
434   }
435
436return $my_para;
437}
438        /*
439        *
440        */
441function cl_autosize_sauve_options_inf()
442{
443global $options,$infos_message,$conf,$autosize_parametres  ;
444$infos_message .=l10n("cl_autosize_save_config")."<br>";
445 $autosize_parametres=cl_autosize_Set_Options();
446
447 if ( isset($autosize_parametres) )
448        {
449 
450                $query = '
451                UPDATE '.CONFIG_TABLE.'
452                SET value="'.addslashes(serialize($autosize_parametres)).'"
453                WHERE param = "cl_autosize"
454                LIMIT 1';
455                        pwg_query($query);
456          }
457         
458 }
459
460 function auto_memo_var($variables)
461{
462  ob_start();
463  echo '<pre>';
464  print_r($variables);
465  echo '</pre>';
466  $m= ob_get_contents();
467  ob_end_clean();
468  return $m;           
469}
470   
471
472?>
Note: See TracBrowser for help on using the repository browser.