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

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

[extensions] autosize compatibility with pamooramics & gmaps

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