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

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

[Autosize][beta] fix bugs.

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