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

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

[Autosize][beta] fix bug in autosize.inc


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