root/trunk/admin/configuration.php @ 14228

Revision 14228, 14.8 KB (checked in by rvelices, 13 months ago)

added a button to restore multiple size default sizes ...

  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
31include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
32
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36check_status(ACCESS_ADMINISTRATOR);
37
38//-------------------------------------------------------- sections definitions
39
40check_input_parameter('section', $_GET, false, '/^[a-z]+$/i');
41
42if (!isset($_GET['section']))
43{
44  $page['section'] = 'main';
45}
46else
47{
48  $page['section'] = $_GET['section'];
49}
50
51$main_checkboxes = array(
52    'allow_user_registration',
53    'obligatory_user_mail_address',
54    'rate',
55    'rate_anonymous',
56    'email_admin_on_new_user',
57    'allow_user_customization',
58    'log',
59    'history_admin',
60    'history_guest',
61   );
62
63$sizes_checkboxes = array(
64    'original_resize',
65  );
66
67$comments_checkboxes = array(
68    'activate_comments',
69    'comments_forall',
70    'comments_validation',
71    'email_admin_on_comment',
72    'email_admin_on_comment_validation',
73    'user_can_delete_comment',
74    'user_can_edit_comment',
75    'email_admin_on_comment_edition',
76    'email_admin_on_comment_deletion'
77  );
78
79$display_checkboxes = array(
80    'menubar_filter_icon',
81    'index_sort_order_input',
82    'index_flat_icon',
83    'index_posted_date_icon',
84    'index_created_date_icon',
85    'index_slideshow_icon',
86    'index_new_icon',
87    'picture_metadata_icon',
88    'picture_slideshow_icon',
89    'picture_favorite_icon',
90    'picture_download_icon',
91    'picture_navigation_icons',
92    'picture_navigation_thumb',
93    'picture_menu',
94  );
95
96$display_info_checkboxes = array(
97    'author',
98    'created_on',
99    'posted_on',
100    'dimensions',
101    'file',
102    'filesize',
103    'tags',
104    'categories',
105    'visits',
106    'rating_score',
107    'privacy_level',
108  );
109 
110// image order management
111$sort_fields = array(
112  ''                    => '',
113  'file ASC'            => l10n('File name, A &rarr; Z'),
114  'file DESC'           => l10n('File name, Z &rarr; A'),
115  'name ASC'            => l10n('Photo title, A &rarr; Z'),
116  'name DESC'           => l10n('Photo title, Z &rarr; A'),
117  'date_creation DESC'  => l10n('Date created, new &rarr; old'),
118  'date_creation ASC'   => l10n('Date created, old &rarr; new'),
119  'date_available DESC' => l10n('Date posted, new &rarr; old'),
120  'date_available ASC'  => l10n('Date posted, old &rarr; new'),
121  'rating_score DESC'   => l10n('Rating score, high &rarr; low'),
122  'rating_score ASC'    => l10n('Rating score, low &rarr; high'),
123  'hit DESC'            => l10n('Visits, high &rarr; low'),
124  'hit ASC'             => l10n('Visits, low &rarr; high'),
125  'id ASC'              => l10n('Numeric identifier, 1 &rarr; 9'),
126  'id DESC'             => l10n('Numeric identifier, 9 &rarr; 1'),
127  'rank ASC'            => l10n('Manual sort order'),
128  );
129 
130$comments_order = array(
131  'ASC' => l10n('Show oldest comments first'),
132  'DESC' => l10n('Show latest comments first'),
133  );
134
135
136//------------------------------ verification and registration of modifications
137if (isset($_POST['submit']))
138{
139  $int_pattern = '/^\d+$/';
140
141  switch ($page['section'])
142  {
143    case 'main' :
144    {     
145      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
146      {
147        if ( !empty($_POST['order_by']) )
148        {         
149          // limit to the number of available parameters
150          $order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));
151         
152          // there is no rank outside categories
153          unset($order_by[ array_search('rank ASC', $order_by) ]);
154         
155          // must define a default order_by if user want to order by rank only
156          if ( count($order_by) == 0 )
157          {
158            $order_by = array('id ASC');
159          }
160         
161          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
162          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
163        }
164        else
165        {
166          array_push($page['errors'], l10n('No field selected'));
167        }
168      }
169     
170      foreach( $main_checkboxes as $checkbox)
171      {
172        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
173      }
174      break;
175    }
176    case 'sizes' :
177    {
178      include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php');       
179      break;
180    }
181    case 'comments' :
182    {
183      // the number of comments per page must be an integer between 5 and 50
184      // included
185      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
186           or $_POST['nb_comment_page'] < 5
187           or $_POST['nb_comment_page'] > 50)
188      {
189        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
190      }
191      foreach( $comments_checkboxes as $checkbox)
192      {
193        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
194      }
195      break;
196    }
197    case 'default' :
198    {
199      // Never go here
200      break;
201    }
202    case 'display' :
203    {
204      foreach( $display_checkboxes as $checkbox)
205      {
206        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
207      }
208      foreach( $display_info_checkboxes as $checkbox)
209      {
210        $_POST['picture_informations'][$checkbox] =
211          empty($_POST['picture_informations'][$checkbox])? false : true;
212      }
213      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
214      break;
215    }
216  }
217
218  // updating configuration if no error found
219  if ('sizes' != $page['section'] and count($page['errors']) == 0)
220  {
221    //echo '<pre>'; print_r($_POST); echo '</pre>';
222    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
223    while ($row = pwg_db_fetch_assoc($result))
224    {
225      if (isset($_POST[$row['param']]))
226      {
227        $value = $_POST[$row['param']];
228
229        if ('gallery_title' == $row['param'])
230        {
231          if (!$conf['allow_html_descriptions'])
232          {
233            $value = strip_tags($value);
234          }
235        }
236
237        $query = '
238UPDATE '.CONFIG_TABLE.'
239SET value = \''. str_replace("\'", "''", $value).'\'
240WHERE param = \''.$row['param'].'\'
241;';
242        pwg_query($query);
243      }
244    }
245    array_push($page['infos'], l10n('Information data registered in database'));
246  }
247
248  //------------------------------------------------------ $conf reinitialization
249  load_conf_from_db();
250}
251elseif (isset($_POST['restore_settings']))
252{
253  ImageStdParams::set_and_save( ImageStdParams::get_default_sizes() );
254  pwg_query('DELETE FROM '.CONFIG_TABLE.' WHERE param = \'disabled_derivatives\'');
255  clear_derivative_cache();
256}
257
258//----------------------------------------------------- template initialization
259$template->set_filename('config', 'configuration.tpl');
260
261// TabSheet
262$tabsheet = new tabsheet();
263// TabSheet initialization
264$tabsheet->add('main', l10n('Main'), $conf_link.'main');
265$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
266$tabsheet->add('display', l10n('Display'), $conf_link.'display');
267$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
268$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
269// TabSheet selection
270$tabsheet->select($page['section']);
271// Assign tabsheet to template
272$tabsheet->assign();
273
274$action = get_root_url().'admin.php?page=configuration';
275$action.= '&amp;section='.$page['section'];
276
277$template->assign(
278  array(
279    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
280    'F_ACTION'=>$action
281    ));
282
283switch ($page['section'])
284{
285  case 'main' :
286  {   
287   
288    function order_by_is_local()
289    {
290      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
291      if (isset($conf['local_dir_site']))
292      {
293        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
294      }
295     
296      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
297    }
298   
299    if (order_by_is_local())
300    {
301      array_push($page['warnings'], l10n('You have specified <i>$conf[\'order_by\']</i> in your local configuration file, this parameter in deprecated, please remove it or rename it into <i>$conf[\'order_by_custom\']</i> !'));
302    }
303   
304    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
305    {
306      $order_by = array('');
307      $template->assign('ORDER_BY_IS_CUSTOM', true);
308    }
309    else
310    {
311      $out = array();
312      $order_by = trim($conf['order_by_inside_category']);
313      $order_by = str_replace('ORDER BY ', null, $order_by);
314      $order_by = explode(', ', $order_by);
315    }
316 
317    $template->assign(
318      'main',
319      array(
320        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
321        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
322        'week_starts_on_options' => array(
323          'sunday' => $lang['day'][0],
324          'monday' => $lang['day'][1],
325          ),
326        'week_starts_on_options_selected' => $conf['week_starts_on'],
327        'order_by' => $order_by,
328        'order_by_options' => $sort_fields,
329        )
330      );
331
332    foreach ($main_checkboxes as $checkbox)
333    {
334      $template->append(
335          'main',
336          array(
337            $checkbox => $conf[$checkbox]
338            ),
339          true
340        );
341    }
342    break;
343  }
344  case 'comments' :
345  {
346    $template->assign(
347      'comments',
348      array(
349        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
350        'comments_order'=>$conf['comments_order'],
351        'comments_order_options'=> $comments_order
352        )
353      );
354
355    foreach ($comments_checkboxes as $checkbox)
356    {
357      $template->append(
358          'comments',
359          array(
360            $checkbox => $conf[$checkbox]
361            ),
362          true
363        );
364    }
365    break;
366  }
367  case 'default' :
368  {
369    $edit_user = build_user($conf['guest_id'], false);
370    include_once(PHPWG_ROOT_PATH.'profile.php');
371
372    $errors = array();
373    if (save_profile_from_post($edit_user, $errors))
374    {
375      // Reload user
376      $edit_user = build_user($conf['guest_id'], false);
377      array_push($page['infos'], l10n('Information data registered in database'));
378    }
379    $page['errors'] = array_merge($page['errors'], $errors);
380
381    load_profile_in_template(
382      $action,
383      '',
384      $edit_user
385      );
386    $template->assign('default', array());
387    break;
388  }
389  case 'display' :
390  {
391    foreach ($display_checkboxes as $checkbox)
392    {
393      $template->append(
394          'display',
395          array(
396            $checkbox => $conf[$checkbox]
397            ),
398          true
399        );
400    }
401    $template->append(
402        'display',
403        array(
404          'picture_informations' => unserialize($conf['picture_informations'])
405          ),
406        true
407      );
408    break;
409  }
410  case 'sizes' :
411  {
412    // we only load the derivatives if it was not already loaded: it occurs
413    // when submitting the form and an error remains
414    if (!isset($page['sizes_loaded_in_tpl']))
415    {
416      $template->assign(
417        'sizes',
418        array(
419          'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
420          'original_resize_maxheight' => $conf['original_resize_maxheight'],
421          'original_resize_quality' => $conf['original_resize_quality'],
422          )
423        );
424     
425      foreach ($sizes_checkboxes as $checkbox)
426      {
427        $template->append(
428          'sizes',
429          array(
430            $checkbox => $conf[$checkbox]
431            ),
432          true
433          );
434      }
435     
436      // derivatives = multiple size
437      $enabled = ImageStdParams::get_defined_type_map();
438      $disabled = @unserialize(@$conf['disabled_derivatives']);
439      if ($disabled === false)
440      {
441        $disabled = array();
442      }
443
444      $common_quality = 50;
445
446      $tpl_vars = array();
447      foreach(ImageStdParams::get_all_types() as $type)
448      {
449        $tpl_var = array();
450       
451        $tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false);
452        $tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false;
453       
454        if ($params = @$enabled[$type])
455        {
456          $tpl_var['enabled'] = true;
457        }
458        else
459        {
460          $tpl_var['enabled']=false;
461          $params=@$disabled[$type];
462        }
463       
464        if ($params)
465        {
466          list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size;
467          if ( ($tpl_var['crop'] = round(100*$params->sizing->max_crop)) > 0)
468          {
469            list($tpl_var['minw'],$tpl_var['minh']) = $params->sizing->min_size;
470          }
471          else
472          {
473            $tpl_var['minw'] = $tpl_var['minh'] = "";
474          }
475          $tpl_var['sharpen'] = $params->sharpen;
476          $tpl_var['quality'] = $params->quality;
477         
478          if ($params->quality > $common_quality and $tpl_var['enabled'])
479          {
480            $common_quality = $params->quality;
481          }
482        }
483        $tpl_vars[$type]=$tpl_var;
484      }
485      $template->assign('derivatives', $tpl_vars);
486      $template->assign('resize_quality', $common_quality);
487    }
488
489    break;
490  }
491}
492
493//----------------------------------------------------------- sending html code
494$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
495?>
Note: See TracBrowser for help on using the browser.