source: trunk/admin/configuration.php @ 14166

Last change on this file since 14166 was 13958, checked in by plg, 12 years ago

merge r13957 from branch 2.3 to trunk

bug 2611 fixed: check $_GETsection input parameter

  • Property svn:eol-style set to LF
File size: 14.5 KB
RevLine 
[362]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[2]23
[527]24if( !defined("PHPWG_ROOT_PATH") )
[393]25{
[1072]26  die ("Hacking attempt!");
[393]27}
[527]28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[12879]30include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
[2226]31include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[1072]32
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36check_status(ACCESS_ADMINISTRATOR);
37
[512]38//-------------------------------------------------------- sections definitions
[13958]39
40check_input_parameter('section', $_GET, false, '/^[a-z]+$/i');
41
[512]42if (!isset($_GET['section']))
43{
[1894]44  $page['section'] = 'main';
[512]45}
46else
47{
48  $page['section'] = $_GET['section'];
49}
[1617]50
[1894]51$main_checkboxes = array(
[2032]52    'allow_user_registration',
53    'obligatory_user_mail_address',
[1920]54    'rate',
55    'rate_anonymous',
[1652]56    'email_admin_on_new_user',
[5328]57    'allow_user_customization',
[13004]58    'log',
59    'history_admin',
60    'history_guest',
[1617]61   );
62
[12879]63$sizes_checkboxes = array(
64    'original_resize',
65  );
66
[1617]67$comments_checkboxes = array(
[12887]68    'activate_comments',
[1617]69    'comments_forall',
70    'comments_validation',
71    'email_admin_on_comment',
72    'email_admin_on_comment_validation',
[3445]73    'user_can_delete_comment',
74    'user_can_edit_comment',
75    'email_admin_on_comment_edition',
76    'email_admin_on_comment_deletion'
[1617]77  );
78
[5293]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',
[11285]86    'index_new_icon',
[5293]87    'picture_metadata_icon',
88    'picture_slideshow_icon',
89    'picture_favorite_icon',
[5618]90    'picture_download_icon',
[5293]91    'picture_navigation_icons',
92    'picture_navigation_thumb',
[10812]93    'picture_menu',
[5293]94  );
95
[5304]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',
[11893]106    'rating_score',
[5723]107    'privacy_level',
[5304]108  );
[11279]109 
[11587]110// image order management
111$sort_fields = array(
[13087]112  ''                    => '',
[13840]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'),
[11279]128  );
[13087]129 
[13224]130$comments_order = array(
131  'ASC' => l10n('Show oldest comments first'),
[13225]132  'DESC' => l10n('Show latest comments first'),
[13224]133  );
[5304]134
[13224]135
[2]136//------------------------------ verification and registration of modifications
[8126]137if (isset($_POST['submit']))
[2]138{
[21]139  $int_pattern = '/^\d+$/';
[1926]140
[512]141  switch ($page['section'])
[2]142  {
[1894]143    case 'main' :
[11587]144    {     
145      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
[11279]146      {
[13087]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));
[12872]151         
[13087]152          // there is no rank outside categories
153          unset($order_by[ array_search('rank ASC', $order_by) ]);
154         
[12872]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         
[11587]161          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
162          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
[11279]163        }
[13087]164        else
165        {
166          array_push($page['errors'], l10n('No field selected'));
167        }
[11279]168      }
169     
[1894]170      foreach( $main_checkboxes as $checkbox)
[1617]171      {
172        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
173      }
[512]174      break;
[130]175    }
[12879]176    case 'sizes' :
177    {
178      $fields = array(
179        'original_resize',
180        'original_resize_maxwidth',
181        'original_resize_maxheight',
182        'original_resize_quality',
183        );
184
185      $updates = array();
186     
187      foreach ($fields as $field)
188      {
189        $value = !empty($_POST[$field]) ? $_POST[$field] : null;
190        $form_values[$field] = $value;
191        $updates[$field] = $value;
192      }
193
194      save_upload_form_config($updates, $page['errors']);
195 
196      if (count($page['errors']) == 0)
197      {
198        array_push(
199          $page['infos'],
200          l10n('Your configuration settings are saved')
201          );
202      }
203
204      break;
205    }
[512]206    case 'comments' :
207    {
208      // the number of comments per page must be an integer between 5 and 50
209      // included
210      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
211           or $_POST['nb_comment_page'] < 5
212           or $_POST['nb_comment_page'] > 50)
213      {
[5021]214        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
[512]215      }
[1617]216      foreach( $comments_checkboxes as $checkbox)
217      {
218        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
219      }
[512]220      break;
221    }
222    case 'default' :
223    {
[1926]224      // Never go here
[512]225      break;
226    }
[5293]227    case 'display' :
228    {
229      foreach( $display_checkboxes as $checkbox)
230      {
231        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
232      }
[5304]233      foreach( $display_info_checkboxes as $checkbox)
234      {
235        $_POST['picture_informations'][$checkbox] =
236          empty($_POST['picture_informations'][$checkbox])? false : true;
237      }
238      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
[5293]239      break;
240    }
[2]241  }
[1071]242
[528]243  // updating configuration if no error found
[12879]244  if ('sizes' != $page['section'] and count($page['errors']) == 0)
[345]245  {
[1565]246    //echo '<pre>'; print_r($_POST); echo '</pre>';
[1748]247    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
[4325]248    while ($row = pwg_db_fetch_assoc($result))
[512]249    {
250      if (isset($_POST[$row['param']]))
251      {
[882]252        $value = $_POST[$row['param']];
[1071]253
254        if ('gallery_title' == $row['param'])
[882]255        {
256          if (!$conf['allow_html_descriptions'])
257          {
258            $value = strip_tags($value);
259          }
260        }
[1071]261
[528]262        $query = '
263UPDATE '.CONFIG_TABLE.'
[1926]264SET value = \''. str_replace("\'", "''", $value).'\'
265WHERE param = \''.$row['param'].'\'
[528]266;';
[587]267        pwg_query($query);
[512]268      }
269    }
[5021]270    array_push($page['infos'], l10n('Information data registered in database'));
[345]271  }
[527]272
[1748]273  //------------------------------------------------------ $conf reinitialization
274  load_conf_from_db();
[1565]275}
276
[512]277//----------------------------------------------------- template initialization
[2530]278$template->set_filename('config', 'configuration.tpl');
[512]279
[2226]280// TabSheet
281$tabsheet = new tabsheet();
[1881]282// TabSheet initialization
[5021]283$tabsheet->add('main', l10n('Main'), $conf_link.'main');
[13068]284$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
[5293]285$tabsheet->add('display', l10n('Display'), $conf_link.'display');
[5021]286$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
[5293]287$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
[2226]288// TabSheet selection
289$tabsheet->select($page['section']);
[1881]290// Assign tabsheet to template
[2226]291$tabsheet->assign();
[1881]292
[2249]293$action = get_root_url().'admin.php?page=configuration';
[528]294$action.= '&amp;section='.$page['section'];
[21]295
[2288]296$template->assign(
[528]297  array(
[5920]298    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
[1004]299    'F_ACTION'=>$action
[528]300    ));
301
[527]302switch ($page['section'])
[528]303{
[1894]304  case 'main' :
[11587]305  {   
306   
307    function order_by_is_local()
[11279]308    {
[11587]309      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
310      if (isset($conf['local_dir_site']))
311      {
312        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
313      }
314     
315      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
[11279]316    }
[11587]317   
318    if (order_by_is_local())
[11279]319    {
[11587]320      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> !'));
[11279]321    }
[11587]322   
323    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
[11279]324    {
[13087]325      $order_by = array('');
[11587]326      $template->assign('ORDER_BY_IS_CUSTOM', true);
[11279]327    }
328    else
329    {
[11587]330      $out = array();
331      $order_by = trim($conf['order_by_inside_category']);
332      $order_by = str_replace('ORDER BY ', null, $order_by);
333      $order_by = explode(', ', $order_by);
[11279]334    }
[11587]335 
[2249]336    $template->assign(
[1894]337      'main',
[528]338      array(
[2021]339        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
340        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
[8626]341        'week_starts_on_options' => array(
342          'sunday' => $lang['day'][0],
343          'monday' => $lang['day'][1],
344          ),
345        'week_starts_on_options_selected' => $conf['week_starts_on'],
[11587]346        'order_by' => $order_by,
[13087]347        'order_by_options' => $sort_fields,
[11587]348        )
349      );
[1617]350
[2325]351    foreach ($main_checkboxes as $checkbox)
[1617]352    {
[2249]353      $template->append(
[1894]354          'main',
[1617]355          array(
[2249]356            $checkbox => $conf[$checkbox]
357            ),
358          true
[1617]359        );
360    }
[528]361    break;
362  }
363  case 'comments' :
364  {
[2249]365    $template->assign(
[528]366      'comments',
367      array(
368        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
[12894]369        'comments_order'=>$conf['comments_order'],
[13224]370        'comments_order_options'=> $comments_order
[12894]371        )
372      );
[1617]373
[2325]374    foreach ($comments_checkboxes as $checkbox)
[1617]375    {
[2249]376      $template->append(
[1617]377          'comments',
378          array(
[2249]379            $checkbox => $conf[$checkbox]
380            ),
381          true
[1617]382        );
383    }
[528]384    break;
385  }
386  case 'default' :
387  {
[5994]388    $edit_user = build_user($conf['guest_id'], false);
[1926]389    include_once(PHPWG_ROOT_PATH.'profile.php');
[1071]390
[1926]391    $errors = array();
[8126]392    if (save_profile_from_post($edit_user, $errors))
[858]393    {
[8126]394      // Reload user
395      $edit_user = build_user($conf['guest_id'], false);
396      array_push($page['infos'], l10n('Information data registered in database'));
[858]397    }
[1926]398    $page['errors'] = array_merge($page['errors'], $errors);
[541]399
[1926]400    load_profile_in_template(
401      $action,
402      '',
403      $edit_user
404      );
[2249]405    $template->assign('default', array());
[528]406    break;
407  }
[5293]408  case 'display' :
409  {
410    foreach ($display_checkboxes as $checkbox)
411    {
412      $template->append(
413          'display',
414          array(
415            $checkbox => $conf[$checkbox]
416            ),
417          true
418        );
419    }
[5304]420    $template->append(
421        'display',
422        array(
423          'picture_informations' => unserialize($conf['picture_informations'])
424          ),
425        true
426      );
[5293]427    break;
428  }
[12879]429  case 'sizes' :
430  {
431    $template->assign(
432      'sizes',
433      array(
434        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
435        'original_resize_maxheight' => $conf['original_resize_maxheight'],
436        'original_resize_quality' => $conf['original_resize_quality'],
437        )
438      );
439   
440    foreach ($sizes_checkboxes as $checkbox)
441    {
442      $template->append(
443        'sizes',
444        array(
445          $checkbox => $conf[$checkbox]
446          ),
447        true
448        );
449    }
450
[13883]451    // derivaties = multiple size
452    $enabled = ImageStdParams::get_defined_type_map();
453    $disabled = @unserialize(@$conf['disabled_derivatives']);
454    if ($disabled === false)
455    {
456      $disabled = array();
457    }
458
459    $tpl_vars = array();
460    foreach(ImageStdParams::get_all_types() as $type)
461    {
462      $tpl_var = array();
463     
464      $tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false);
465      $tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false;
466     
467      if ($params=@$enabled[$type])
468      {
469        $tpl_var['enabled']=true;
470      }
471      else
472      {
473        $tpl_var['enabled']=false;
474        $params=@$disabled[$type];
475      }
476     
477      if ($params)
478      {
479        list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size;
480        if ( ($tpl_var['crop'] = round(100*$params->sizing->max_crop)) > 0)
481        {
482          list($tpl_var['minw'],$tpl_var['minh']) = $params->sizing->min_size;
483        }
484        else
485        {
486          $tpl_var['minw'] = $tpl_var['minh'] = "";
487        }
488        $tpl_var['sharpen'] = $params->sharpen;
489        $tpl_var['quality'] = $params->quality;
490      }
491      $tpl_vars[$type]=$tpl_var;
492    }
493    $template->assign('derivatives', $tpl_vars);
494
[12879]495    break;
496  }
[528]497}
[1926]498
[2]499//----------------------------------------------------------- sending html code
[393]500$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
[362]501?>
Note: See TracBrowser for help on using the repository browser.