source: trunk/admin/configuration.php @ 12879

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

feature 2548, multiple size:

  • adapt the upload script
  • remove the resize settings screen
  • add a new screen [Administration > Configuration > Options > Photo Sizes] with the ability to resize original after upload
  • Property svn:eol-style set to LF
File size: 14.3 KB
RevLine 
[362]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 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
39if (!isset($_GET['section']))
40{
[1894]41  $page['section'] = 'main';
[512]42}
43else
44{
45  $page['section'] = $_GET['section'];
46}
[1617]47
[1894]48$main_checkboxes = array(
[2249]49    'gallery_locked',
[2032]50    'allow_user_registration',
51    'obligatory_user_mail_address',
[1920]52    'rate',
53    'rate_anonymous',
[1652]54    'email_admin_on_new_user',
[5328]55    'allow_user_customization',
[1617]56   );
57
[12879]58$sizes_checkboxes = array(
59    'original_resize',
60  );
61
[1884]62$history_checkboxes = array(
63    'log',
64    'history_admin',
65    'history_guest'
66   );
67
[1617]68$comments_checkboxes = array(
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(
112  '' => '',
113  'rank' => l10n('Rank'),
114  'file' => l10n('File name'),
[12782]115  'name' => l10n('Photo name'),
[11587]116  'date_creation' => l10n('Creation date'),
117  'date_available' => l10n('Post date'),
[11893]118  'rating_score' => l10n('Rating score'),
[11587]119  'hit' => l10n('Most visited'),
120  'id' => 'Id',
[11279]121  );
[5304]122
[11587]123$sort_directions = array(
124  'ASC' => l10n('ascending'),
125  'DESC' => l10n('descending'),
126  );
127
[2]128//------------------------------ verification and registration of modifications
[8126]129if (isset($_POST['submit']))
[2]130{
[21]131  $int_pattern = '/^\d+$/';
[1926]132
[512]133  switch ($page['section'])
[2]134  {
[1894]135    case 'main' :
[11587]136    {     
137      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
[11279]138      {
[11587]139        if ( !empty($_POST['order_by_field']) )
[11279]140        {
[11587]141          $order_by = array();
142          $order_by_inside_category = array();
[12872]143         
[11587]144          for ($i=0; $i<count($_POST['order_by_field']); $i++)
145          {
[12872]146            if ( $i >= (count($sort_fields)-1) ) break; // limit to the number of available parameters
147            if ( empty($_POST['order_by_field'][$i]) )
[11587]148            {
149              array_push($page['errors'], l10n('No field selected'));
[12872]150              break;
[11587]151            }
152            else
153            {
[12872]154              // there is no rank outside categories
[11587]155              if ($_POST['order_by_field'][$i] != 'rank')
156              {
157                $order_by[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
158              }
159              $order_by_inside_category[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
160            }
161          }
[12872]162          // must define a default order_by if user want to order by rank only
163          if ( count($order_by) == 0 )
164          {
165            $order_by = array('id ASC');
166          }
167         
[11587]168          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
169          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
[12872]170          unset($_POST['order_by_field']);
[11279]171        }
172      }
173     
[9544]174      if (empty($_POST['gallery_locked']) and $conf['gallery_locked'])
175      {
176        $tpl_var = & $template->get_template_vars('header_msgs');
177        $msg_key = array_search(l10n('The gallery is locked for maintenance. Please, come back later.'), $tpl_var);
178        unset($tpl_var[$msg_key]);
179      }
180      elseif (!empty($_POST['gallery_locked']) and !$conf['gallery_locked'])
181      {
182        $template->append('header_msgs', l10n('The gallery is locked for maintenance. Please, come back later.'));
183      }
[1894]184      foreach( $main_checkboxes as $checkbox)
[1617]185      {
186        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
187      }
[512]188      break;
[130]189    }
[12879]190    case 'sizes' :
191    {
192      $fields = array(
193        'original_resize',
194        'original_resize_maxwidth',
195        'original_resize_maxheight',
196        'original_resize_quality',
197        );
198
199      $updates = array();
200     
201      foreach ($fields as $field)
202      {
203        $value = !empty($_POST[$field]) ? $_POST[$field] : null;
204        $form_values[$field] = $value;
205        $updates[$field] = $value;
206      }
207
208      save_upload_form_config($updates, $page['errors']);
209 
210      if (count($page['errors']) == 0)
211      {
212        array_push(
213          $page['infos'],
214          l10n('Your configuration settings are saved')
215          );
216      }
217
218      break;
219    }
[1884]220    case 'history' :
221    {
222      foreach( $history_checkboxes as $checkbox)
223      {
224        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
225      }
226      break;
227    }
[512]228    case 'comments' :
229    {
230      // the number of comments per page must be an integer between 5 and 50
231      // included
232      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
233           or $_POST['nb_comment_page'] < 5
234           or $_POST['nb_comment_page'] > 50)
235      {
[5021]236        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
[512]237      }
[1617]238      foreach( $comments_checkboxes as $checkbox)
239      {
240        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
241      }
[512]242      break;
243    }
244    case 'default' :
245    {
[1926]246      // Never go here
[512]247      break;
248    }
[5293]249    case 'display' :
250    {
251      foreach( $display_checkboxes as $checkbox)
252      {
253        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
254      }
[5304]255      foreach( $display_info_checkboxes as $checkbox)
256      {
257        $_POST['picture_informations'][$checkbox] =
258          empty($_POST['picture_informations'][$checkbox])? false : true;
259      }
260      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
[5293]261      break;
262    }
[2]263  }
[1071]264
[528]265  // updating configuration if no error found
[12879]266  if ('sizes' != $page['section'] and count($page['errors']) == 0)
[345]267  {
[1565]268    //echo '<pre>'; print_r($_POST); echo '</pre>';
[1748]269    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
[4325]270    while ($row = pwg_db_fetch_assoc($result))
[512]271    {
272      if (isset($_POST[$row['param']]))
273      {
[882]274        $value = $_POST[$row['param']];
[1071]275
276        if ('gallery_title' == $row['param'])
[882]277        {
278          if (!$conf['allow_html_descriptions'])
279          {
280            $value = strip_tags($value);
281          }
282        }
[1071]283
[528]284        $query = '
285UPDATE '.CONFIG_TABLE.'
[1926]286SET value = \''. str_replace("\'", "''", $value).'\'
287WHERE param = \''.$row['param'].'\'
[528]288;';
[587]289        pwg_query($query);
[512]290      }
291    }
[5021]292    array_push($page['infos'], l10n('Information data registered in database'));
[345]293  }
[527]294
[1748]295  //------------------------------------------------------ $conf reinitialization
296  load_conf_from_db();
[1565]297}
298
[512]299//----------------------------------------------------- template initialization
[2530]300$template->set_filename('config', 'configuration.tpl');
[512]301
[2226]302// TabSheet
303$tabsheet = new tabsheet();
[1881]304// TabSheet initialization
[5021]305$tabsheet->add('main', l10n('Main'), $conf_link.'main');
[12879]306$tabsheet->add('sizes', l10n('Photo Sizes'), $conf_link.'sizes');
[5293]307$tabsheet->add('display', l10n('Display'), $conf_link.'display');
[5021]308$tabsheet->add('history', l10n('History'), $conf_link.'history');
309$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
[5293]310$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
[2226]311// TabSheet selection
312$tabsheet->select($page['section']);
[1881]313// Assign tabsheet to template
[2226]314$tabsheet->assign();
[1881]315
[2249]316$action = get_root_url().'admin.php?page=configuration';
[528]317$action.= '&amp;section='.$page['section'];
[21]318
[2288]319$template->assign(
[528]320  array(
[5920]321    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
[1004]322    'F_ACTION'=>$action
[528]323    ));
324
[527]325switch ($page['section'])
[528]326{
[1894]327  case 'main' :
[11587]328  {   
329   
330    function order_by_is_local()
[11279]331    {
[11587]332      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
333      if (isset($conf['local_dir_site']))
334      {
335        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
336      }
337     
338      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
[11279]339    }
[11587]340   
341    if (order_by_is_local())
[11279]342    {
[11587]343      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]344    }
[11587]345   
346    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
[11279]347    {
[11587]348      $order_by = array(array(
349        'FIELD' => '',   
350        'DIRECTION' => 'ASC', 
351        ));
352       
353      $template->assign('ORDER_BY_IS_CUSTOM', true);
[11279]354    }
355    else
356    {
[11587]357      $out = array();
358      $order_by = trim($conf['order_by_inside_category']);
359      $order_by = str_replace('ORDER BY ', null, $order_by);
360      $order_by = explode(', ', $order_by);
361      foreach ($order_by as $field)
362      {
363        $field= explode(' ', $field);
364        $out[] = array(
365          'FIELD' => $field[0],   
366          'DIRECTION' => $field[1],   
367        );
368      }
369      $order_by = $out;
[11279]370    }
[11587]371 
[2249]372    $template->assign(
[1894]373      'main',
[528]374      array(
[2021]375        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
376        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
[8626]377        'week_starts_on_options' => array(
378          'sunday' => $lang['day'][0],
379          'monday' => $lang['day'][1],
380          ),
381        'week_starts_on_options_selected' => $conf['week_starts_on'],
[11587]382        'order_by' => $order_by,
383        'order_field_options' => $sort_fields,
384        'order_direction_options' => $sort_directions,
385        )
386      );
[1617]387
[2325]388    foreach ($main_checkboxes as $checkbox)
[1617]389    {
[2249]390      $template->append(
[1894]391          'main',
[1617]392          array(
[2249]393            $checkbox => $conf[$checkbox]
394            ),
395          true
[1617]396        );
397    }
[528]398    break;
399  }
[1884]400  case 'history' :
401  {
402    //Necessary for merge_block_vars
[2325]403    foreach ($history_checkboxes as $checkbox)
[1884]404    {
[2249]405      $template->append(
[1884]406          'history',
407          array(
[2249]408            $checkbox => $conf[$checkbox]
409            ),
410          true
[1884]411        );
412    }
413    break;
414  }
[528]415  case 'comments' :
416  {
[2249]417    $template->assign(
[528]418      'comments',
419      array(
420        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
421        ));
[1617]422
[2325]423    foreach ($comments_checkboxes as $checkbox)
[1617]424    {
[2249]425      $template->append(
[1617]426          'comments',
427          array(
[2249]428            $checkbox => $conf[$checkbox]
429            ),
430          true
[1617]431        );
432    }
[528]433    break;
434  }
435  case 'default' :
436  {
[5994]437    $edit_user = build_user($conf['guest_id'], false);
[1926]438    include_once(PHPWG_ROOT_PATH.'profile.php');
[1071]439
[1926]440    $errors = array();
[8126]441    if (save_profile_from_post($edit_user, $errors))
[858]442    {
[8126]443      // Reload user
444      $edit_user = build_user($conf['guest_id'], false);
445      array_push($page['infos'], l10n('Information data registered in database'));
[858]446    }
[1926]447    $page['errors'] = array_merge($page['errors'], $errors);
[541]448
[1926]449    load_profile_in_template(
450      $action,
451      '',
452      $edit_user
453      );
[2249]454    $template->assign('default', array());
[528]455    break;
456  }
[5293]457  case 'display' :
458  {
459    foreach ($display_checkboxes as $checkbox)
460    {
461      $template->append(
462          'display',
463          array(
464            $checkbox => $conf[$checkbox]
465            ),
466          true
467        );
468    }
[5304]469    $template->append(
470        'display',
471        array(
472          'picture_informations' => unserialize($conf['picture_informations'])
473          ),
474        true
475      );
[5293]476    break;
477  }
[12879]478  case 'sizes' :
479  {
480    $template->assign(
481      'sizes',
482      array(
483        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
484        'original_resize_maxheight' => $conf['original_resize_maxheight'],
485        'original_resize_quality' => $conf['original_resize_quality'],
486        )
487      );
488   
489    foreach ($sizes_checkboxes as $checkbox)
490    {
491      $template->append(
492        'sizes',
493        array(
494          $checkbox => $conf[$checkbox]
495          ),
496        true
497        );
498    }
499
500    break;
501  }
[528]502}
[1926]503
[2]504//----------------------------------------------------------- sending html code
[393]505$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
[362]506?>
Note: See TracBrowser for help on using the repository browser.