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

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

[extensions] Autosize fix compatibility with charlies

File size: 17.2 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// +-----------------------------------------------------------------------+
22if (!defined('AUTOSIZE_PATH')) 
23define(
24  'AUTOSIZE_PATH',
25   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'
26);
27if (!defined('ROOT_URL')) 
28define(  'ROOT_URL',  get_root_url().'/' );
29 
30if (!defined('AUTOSIZE_PATH_ABS')) 
31define(
32  'AUTOSIZE_PATH_ABS',  realpath(AUTOSIZE_PATH)."/"
33);
34
35
36class autosize_controler {
37 //============================================================
38 /*
39  *  cl_autosize_script_1
40 */
41 static public function cl_autosize_script_1()
42        {
43                global  $template,$user,$conf,$picture ,$page, $cl_plugin ;
44 
45  header ('X-UA-Compatible: n=7')  ;
46   header ('X-UA-Compatible: IE=Edge')  ;
47  if(isset($page['body_id']) && $page['body_id'] == 'theAdminPage' ) return ;
48
49    if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
50     
51    $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
52    if ($ma_page=='thePiwiShackControllerPage') return ;
53
54
55    if (PHPWG_VERSION < 2.2 ) 
56      $file =AUTOSIZE_PATH_ABS.'template/header_2_1.tpl' ;
57    else 
58      $file =AUTOSIZE_PATH_ABS.'template/header_2_2.tpl' ;
59   
60;
61
62    $template->set_filenames(array('autosize_init_header'=> $file ));
63    $template->set_filenames(array('autosize_init'=>AUTOSIZE_PATH_ABS. "template/conflit.tpl" ) );
64//=================================================================================================
65$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
66$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
67$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
68//=================================================================================================
69
70    $autosize_parametres =       cl_autosize_Get_Options() ;                   
71    $theme=$user['theme'];
72    $template->assign(
73      array(   
74        'autosize_parametres' => $autosize_parametres ,
75        'cl_plugins' => $cl_plugin ,
76        'cl_version' => $cl_plugin['version'] ,
77        'name' => $cl_plugin['name'] ,
78        'pamoorama' =>  isset($PAMOORAMICS_PATH)?"true":"false",                                                                 
79        'theme' => $theme  ,
80        'DEBUG_autosize' =>  $DEBUG_autosize ,
81        'AUTOSIZE_PATH' => str_replace("../","",AUTOSIZE_PATH)  ,
82        'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
83        'Version_pwg' => PHPWG_VERSION
84         )
85    );
86                $template->concat('cl_conflit_init', $template->parse('autosize_init_header', true));
87                return $template->parse( 'autosize_init', false);
88        }// function cl_autosize_script_1
89 //===========================================================
90 /*
91  * cl_autosize_script_2(admin)
92 */
93 static public function cl_autosize_script_2()
94 {
95           global  $template,$user,$conf,$picture ,$page, $cl_plugin,$known_script ;
96   if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
97
98                        $AUTOSIZE_PATH = dirname(__FILE__).'/';
99//=================================================================================================
100$DEBUG_autosize = isset($_POST['cl_debug_conflit']) ? $_POST['cl_debug_conflit'] : "false" ;
101$DEBUG_autosize = isset($_GET['cl_debug_conflit']) ? $_GET['cl_debug_conflit'] : $DEBUG_autosize ;
102$DEBUG_autosize = isset($conf['cl_debug_conflit']) ? $conf['cl_debug_conflit'] : $DEBUG_autosize ; 
103//=================================================================================================
104
105
106                        $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
107                        $theme=$user['theme'];
108                        if ($ma_page=='thePiwiShackControllerPage') return ;
109                       
110                        $template->assign(
111                                        array(
112                                        'cl_version' => $cl_plugin['version'] ,
113                                        'name' => $cl_plugin['name'] ,
114                                        'ma_page' =>    $ma_page,
115                                       
116                                        'theme' => $theme  ,
117                                        'DEBUG_autosize' => $DEBUG_autosize   ,
118                                        'AUTOSIZE_PATH' => AUTOSIZE_PATH
119                                        )
120                                                );
121                                                 
122                        $autoscript="<script type='text/javascript'>
123                        /* cl_autosize_script_2 */
124                        if (typeof (save_framework) == 'function')
125                           save_framework('".$ma_page."');
126                        </script>";
127         
128            $autoscript .="<input id='ret_autosize'  type='hidden' value='' />";
129            $autoscript .="<input id='src_img_h'  type='hidden' value='' />";
130            $autoscript .="<input id='src_img_w'   type='hidden' value='' />";
131            $autoscript .="<input id='window_height'  type='hidden' value='' />";
132            $autoscript .="<input id='window_width'   type='hidden' value='' />";
133             $autoscript .='<div id="Debug6"  align=center style="display:none"></div>';
134                $template->append('footer_elements',$autoscript); 
135                return ; 
136 }// function cl_autosize_script_2
137
138        //================================================================
139        /*
140        * cl_autosize_admin
141        */
142        static public function cl_autosize_admin($menu)
143                {
144                global  $lang ;
145                array_push($menu, array('NAME' => 'Autosize',
146                'URL' => get_admin_plugin_menu_link(AUTOSIZE_PATH . 'admin/admin_autosize.php')));
147                return $menu;
148        } //function cl_autosize_admin
149
150    //===============================================================
151        /*
152        *
153        */     
154        static public function cl_autosize_affiche()
155        {
156                global $user, $picture, $template,$page,$known_script;
157                global $content, $element_info;   
158                global $infos_message,$erreur_message;
159                global  $conf,$lang ,$user,$userdata;
160 if ('kardon' == $user['theme'] and isset($_GET['slideshow'])) return ;
161                load_language('plugin.lang', AUTOSIZE_PATH);
162                $AUTOSIZE_PATH = dirname(__FILE__).'/';
163                 if (isset( $page['body_id']) && $page['body_id']=='thePicturePage'  ) {
164                        if ( isset($picture['current'])){       
165                                $autosize_parametres = cl_autosize_Get_Options();
166                                include (AUTOSIZE_PATH."include/affiche.php"); 
167
168       if (PHPWG_VERSION < 2.2 ) 
169                $file =AUTOSIZE_PATH_ABS.'template/picture_2_1.tpl' ;
170        else 
171                $file =AUTOSIZE_PATH_ABS.'template/picture_2_2.tpl' ;
172
173
174
175        $template->set_filenames(array('autosize_content_header'=> $file )); 
176        $template->concat('autosize_content', $template->parse('autosize_content_header', true));   
177                       
178        $template->set_filenames(array('autosize_init_header'=> $file ));
179                                       
180                                if($autosize_parametres->check_icon_v == 'on'){                         
181                                                $template->assign('cl_autosize_button', 
182                                                array(  'cl_autosize_info' => 'cl_autosize_info' ,
183                                                                    'cl_autosize_info_2' => 'cl_autosize_info_2' ,   
184                                                                    'URL' => $_SERVER['REQUEST_URI'] ,
185                                                                    'ICON2' => AUTOSIZE_PATH . 'icons/button-maximize.png',
186                                                                    'ICON' => AUTOSIZE_PATH . 'icons/button-minimize.png'
187                                                                )
188
189                                                        ); 
190                                        $template->set_filenames(array('cl_bp' => $AUTOSIZE_PATH. 'template/picture.tpl'));
191                                        $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('cl_bp', true));
192                                }
193                                 $template->set_filenames(
194                                                array('autosize_content'=> $AUTOSIZE_PATH.'template/autosize.tpl')
195                                        );
196                        $template->concat('autosize_content', $template->parse('autosize_content_header', true));               
197      if(isset($conf['go_up_down']) && ($conf['go_up_down']==true) ){
198        $template->set_filenames(array('mes_script' => realpath(AUTOSIZE_PATH).'/template/mes_scripts.tpl') );
199        $template->func_combine_script(array('id'=>'my_script_2',
200        'path'=> AUTOSIZE_PATH.'/js/JScript.js',
201        'require' => 'jquery'),
202        $template->smarty);
203        $template->assign(array( 
204                          'MY_FOOTER_PATH' =>AUTOSIZE_PATH
205                          ));
206                                       
207        $template->parse('mes_script');
208      }     
209       
210       
211       
212        return $template->parse( 'autosize_content', false);
213                                  }
214                }
215
216        } //public function cl_autosize_affiche
217        //===============================================================
218                /*
219        *
220        */
221        static public function cl_autosize_aff_infos_plus()
222                {
223                 global $template,$infos_message,$erreur_message, $user ;
224                 global  $conf,$lang ;
225       
226                 //==============================================================
227                  if (isset($erreur_message))
228                                {       
229                                if ($erreur_message <> "")
230                                        {
231                                                $erreur_message=str_replace("\n",'<br />',$erreur_message) ;
232                                                $template->assign('errors',$erreur_message);
233                                                $erreur_message="";
234                                        }
235                                }
236                  if (isset($infos_message))
237                                {       
238               
239                                if ($infos_message <> "")
240                                        {
241                                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
242                                                $template->assign('infos',$infos_message);
243                                                $infos_message="";
244                                        }
245                                }
246                                //=============================================================
247                return;         
248               
249                } // function cl_autosize_aff_infos_plus
250        //===============================================================
251        /*
252         *
253        */
254        static public function cl_ajuste_data($content){
255                global  $template,$user,$conf,$picture ;
256                $AUTOSIZE_PATH = realpath(AUTOSIZE_PATH .'/');
257                $userdata=$user;
258                $fields = array( 'maxwidth', 'maxheight' );
259         
260                $ThePicture = $template->get_template_vars('current'); 
261                $data = array();
262         return $content;
263
264                $data['maxwidth'] = '1200';
265                $data['maxheight'] ='250';
266                $data['user_id'] = $userdata['id'];
267                foreach ($fields as $field)
268                {
269                        if (isset($_POST[$field]))
270                        {
271                                $data[$field] = $_POST[$field];
272                        }
273                }
274       
275                if($data['maxwidth'] != "" )
276                        {
277                        $picture['current']['scaled_width']=$data['maxwidth'];
278                        $picture['current']['scaled_height']=$data['maxheight'];
279                        mass_updates(USER_INFOS_TABLE,
280                                        array('primary' => array('user_id'), 'update' => $fields),
281                                        array($data)); 
282                        }
283                 
284                        return $content;                                                                                 
285                 }
286
287} // class
288
289
290        /*
291        *
292        */
293 function cl_autosize_Get_Options()
294  {
295                global $conf,$autosize_parametres; 
296                $autosize_parametres =  unserialize($conf['cl_autosize']);
297                $autosize_parametres =  cl_autosize_Set_Options();
298                return $autosize_parametres;
299  }
300        /*
301        *
302        */
303function cl_autosize_Set_Options()
304  {
305
306  global $autosize_parametres;
307//=============================================================================
308$my_para=$autosize_parametres;
309
310$my_para->query =(isset($_POST['query'])) ? $_POST['query'] : ((isset($my_para->query )) ? $my_para->query : 'Qt' ) ;
311$my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type:  'Ty') ;
312
313$my_para->webmaster_height =(isset($_POST['webmaster_height'])) ? $_POST['webmaster_height'] : ((isset($my_para->webmaster_height )) ? $my_para->webmaster_height : '100%' ) ;
314$my_para->webmaster_width=(isset($_POST['webmaster_width']))? $_POST['webmaster_width']: ((isset($my_para->webmaster_width)) ? $my_para->webmaster_width:  '100%') ;
315
316$my_para->admin_height =(isset($_POST['admin_height'])) ? $_POST['admin_height'] : ((isset($my_para->admin_height )) ? $my_para->admin_height : '100%' ) ;
317$my_para->admin_width=(isset($_POST['admin_width']))? $_POST['admin_width']: ((isset($my_para->admin_width)) ? $my_para->admin_width:  '100%') ;
318
319$my_para->generic_height =(isset($_POST['generic_height'])) ? $_POST['generic_height'] : ((isset($my_para->generic_height )) ? $my_para->generic_height : '100%' ) ;
320$my_para->generic_width=(isset($_POST['generic_width']))? $_POST['generic_width']: ((isset($my_para->generic_width)) ? $my_para->generic_width:  '100%') ;
321
322$my_para->guest_height =(isset($_POST['guest_height'])) ? $_POST['guest_height'] : ((isset($my_para->guest_height )) ? $my_para->guest_height : '100%' ) ;
323$my_para->guest_width=(isset($_POST['guest_width']))? $_POST['guest_width']: ((isset($my_para->guest_width)) ? $my_para->guest_width:  '100%') ;
324
325$my_para->normal_height =(isset($_POST['normal_height'])) ? $_POST['normal_height'] : ((isset($my_para->normal_height )) ? $my_para->normal_height : '100%' ) ;
326$my_para->normal_width=(isset($_POST['normal_width']))? $_POST['normal_width']: ((isset($my_para->normal_width)) ? $my_para->normal_width:  '100%') ;
327
328
329$my_para->mini_height =(isset($_POST['mini_height'])) ? $_POST['mini_height'] : ((isset($my_para->mini_height )) ? $my_para->mini_height : '150' ) ;
330$my_para->mini_width=(isset($_POST['mini_width']))? $_POST['mini_width']: ((isset($my_para->mini_width)) ? $my_para->mini_width:  '300') ;
331
332$my_para->mini_height2 =(isset($_POST['mini_height2'])) ? $_POST['mini_height2'] : ((isset($my_para->mini_height2 )) ? $my_para->mini_height2 : '150' ) ;
333$my_para->mini_width2=(isset($_POST['mini_width2']))? $_POST['mini_width2']: ((isset($my_para->mini_width2)) ? $my_para->mini_width2:  '300') ;
334
335$my_para->echelle_max=(isset($_POST['echelle_max']))? $_POST['echelle_max'] : ((isset($my_para->echelle_max)) ? $my_para->echelle_max :  '1.0'); 
336$my_para->marge_basse=(isset($_POST['marge_basse']))? $_POST['marge_basse']: ((isset($my_para->marge_basse)) ? $my_para->marge_basse :  '0');
337$my_para->fade_in=(isset($_POST['fade_in']))? $_POST['fade_in']: ((isset($my_para->fade_in)) ? $my_para->fade_in :  '0');
338
339//===============================================================================       
340
341if ( isset($_POST['submit'] ) && $_POST['submit'] == l10n('cl_autosize_save') )  { 
342                $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ;
343                $my_para->check_icon_v = isset($_POST['check_icon_v']) ? $_POST['check_icon_v'] : "off" ;
344                $my_para->check_auto_w = isset($_POST['check_auto_w']) ? $_POST['check_auto_w'] : "off" ;
345
346                $my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : "off" ;
347                $my_para->admin_enabled = isset($_POST['admin_enabled']) ? $_POST['admin_enabled'] : "off" ;
348                $my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : "off" ;
349                $my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : "off" ;
350                $my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : "off" ;
351
352         }else{
353                $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') ; 
354                $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') ; 
355                $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') ; 
356
357
358$my_para->webmaster_enabled = isset($_POST['webmaster_enabled']) ? $_POST['webmaster_enabled'] : ( ( isset($my_para->webmaster_enabled) ) ? $my_para->webmaster_enabled :   'on') ; 
359$my_para->admin_enabled  = isset($_POST['admin_enabled ']) ? $_POST['admin_enabled '] : ( ( isset($my_para->admin_enabled ) ) ? $my_para->admin_enabled :   'on') ; 
360$my_para->generic_enabled = isset($_POST['generic_enabled']) ? $_POST['generic_enabled'] : ( ( isset($my_para->generic_enabled) ) ? $my_para->generic_enabled :   'on') ; 
361$my_para->guest_enabled = isset($_POST['guest_enabled']) ? $_POST['guest_enabled'] : ( ( isset($my_para->guest_enabled) ) ? $my_para->guest_enabled :   'on') ;
362$my_para->normal_enabled = isset($_POST['normal_enabled']) ? $_POST['normal_enabled'] : ( ( isset($my_para->normal_enabled) ) ? $my_para->normal_enabled :   'on') ; 
363
364
365   }
366
367return $my_para;
368}
369        /*
370        *
371        */
372function cl_autosize_sauve_options_inf()
373{
374global $options,$infos_message,$conf,$autosize_parametres  ;
375$infos_message .=l10n("cl_autosize_save_config")."<br>";
376 $autosize_parametres=cl_autosize_Set_Options();
377
378 if ( isset($autosize_parametres) )
379        {
380 
381                $query = '
382                UPDATE '.CONFIG_TABLE.'
383                SET value="'.addslashes(serialize($autosize_parametres)).'"
384                WHERE param = "cl_autosize"
385                LIMIT 1';
386                        pwg_query($query);
387          }
388         
389 }
390
391 function auto_memo_var($variables)
392{
393  ob_start();
394  echo '<pre>';
395  print_r($variables);
396  echo '</pre>';
397  $m= ob_get_contents();
398  ob_end_clean();
399  return $m;           
400}
401   
402
403?>
Note: See TracBrowser for help on using the repository browser.