source: trunk/admin/configuration.php @ 23643

Last change on this file since 23643 was 23643, checked in by flop25, 11 years ago

bug:2840
disable the "resize after upload" options if gd
1 lang key added

  • Property svn:eol-style set to LF
File size: 17.3 KB
RevLine 
[362]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 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',
[18164]76    'email_admin_on_comment_deletion',
77    'comments_author_mandatory',
78    'comments_email_mandatory',
[1617]79  );
80
[5293]81$display_checkboxes = array(
82    'menubar_filter_icon',
83    'index_sort_order_input',
84    'index_flat_icon',
85    'index_posted_date_icon',
86    'index_created_date_icon',
87    'index_slideshow_icon',
[11285]88    'index_new_icon',
[5293]89    'picture_metadata_icon',
90    'picture_slideshow_icon',
91    'picture_favorite_icon',
[5618]92    'picture_download_icon',
[5293]93    'picture_navigation_icons',
94    'picture_navigation_thumb',
[10812]95    'picture_menu',
[5293]96  );
97
[5304]98$display_info_checkboxes = array(
99    'author',
100    'created_on',
101    'posted_on',
102    'dimensions',
103    'file',
104    'filesize',
105    'tags',
106    'categories',
107    'visits',
[11893]108    'rating_score',
[5723]109    'privacy_level',
[5304]110  );
[17302]111
[11587]112// image order management
113$sort_fields = array(
[13087]114  ''                    => '',
[13840]115  'file ASC'            => l10n('File name, A &rarr; Z'),
116  'file DESC'           => l10n('File name, Z &rarr; A'),
117  'name ASC'            => l10n('Photo title, A &rarr; Z'),
118  'name DESC'           => l10n('Photo title, Z &rarr; A'),
119  'date_creation DESC'  => l10n('Date created, new &rarr; old'),
120  'date_creation ASC'   => l10n('Date created, old &rarr; new'),
121  'date_available DESC' => l10n('Date posted, new &rarr; old'),
122  'date_available ASC'  => l10n('Date posted, old &rarr; new'),
123  'rating_score DESC'   => l10n('Rating score, high &rarr; low'),
124  'rating_score ASC'    => l10n('Rating score, low &rarr; high'),
125  'hit DESC'            => l10n('Visits, high &rarr; low'),
126  'hit ASC'             => l10n('Visits, low &rarr; high'),
127  'id ASC'              => l10n('Numeric identifier, 1 &rarr; 9'),
128  'id DESC'             => l10n('Numeric identifier, 9 &rarr; 1'),
129  'rank ASC'            => l10n('Manual sort order'),
[11279]130  );
[17302]131
[13224]132$comments_order = array(
133  'ASC' => l10n('Show oldest comments first'),
[13225]134  'DESC' => l10n('Show latest comments first'),
[13224]135  );
[5304]136
[13224]137
[2]138//------------------------------ verification and registration of modifications
[8126]139if (isset($_POST['submit']))
[2]140{
[21]141  $int_pattern = '/^\d+$/';
[1926]142
[512]143  switch ($page['section'])
[2]144  {
[1894]145    case 'main' :
[17302]146    {
[11587]147      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
[11279]148      {
[13087]149        if ( !empty($_POST['order_by']) )
[15950]150        {
151          foreach ($_POST['order_by'] as $i => $val)
[12872]152          {
[15950]153            if (empty($val)) unset($_POST['order_by'][$i]);
[12872]154          }
[15950]155          if ( !count($_POST['order_by']) )
156          {
157            array_push($page['errors'], l10n('No order field selected'));
158          }
159          else
160          {
161            // limit to the number of available parameters
162            $order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));
[17302]163
[15950]164            // there is no rank outside categories
165            if ( ($i = array_search('rank ASC', $order_by)) !== false)
166            {
167              unset($order_by[$i]);
168            }
[17302]169
[15950]170            // must define a default order_by if user want to order by rank only
171            if ( count($order_by) == 0 )
172            {
173              $order_by = array('id ASC');
174            }
[17302]175
[15950]176            $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
177            $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
178          }
[11279]179        }
[13087]180        else
181        {
[15950]182          array_push($page['errors'], l10n('No order field selected'));
[13087]183        }
[11279]184      }
[17302]185
[1894]186      foreach( $main_checkboxes as $checkbox)
[1617]187      {
188        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
189      }
[512]190      break;
[130]191    }
[14512]192    case 'watermark' :
193    {
[17302]194      include(PHPWG_ROOT_PATH.'admin/include/configuration_watermark_process.inc.php');
[14512]195      break;
196    }
[12879]197    case 'sizes' :
198    {
[17302]199      include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php');
[12879]200      break;
201    }
[512]202    case 'comments' :
203    {
204      // the number of comments per page must be an integer between 5 and 50
205      // included
206      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
207           or $_POST['nb_comment_page'] < 5
208           or $_POST['nb_comment_page'] > 50)
209      {
[5021]210        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
[512]211      }
[1617]212      foreach( $comments_checkboxes as $checkbox)
213      {
214        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
215      }
[512]216      break;
217    }
218    case 'default' :
219    {
[1926]220      // Never go here
[512]221      break;
222    }
[5293]223    case 'display' :
224    {
[18165]225      if (!preg_match($int_pattern, $_POST['nb_categories_page'])
226            or $_POST['nb_categories_page'] < 4)
227      {
228        array_push($page['errors'], l10n('The number of albums a page must be above 4.'));
229      }
[5293]230      foreach( $display_checkboxes as $checkbox)
231      {
232        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
233      }
[5304]234      foreach( $display_info_checkboxes as $checkbox)
235      {
236        $_POST['picture_informations'][$checkbox] =
237          empty($_POST['picture_informations'][$checkbox])? false : true;
238      }
239      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
[5293]240      break;
241    }
[2]242  }
[1071]243
[528]244  // updating configuration if no error found
[14513]245  if (!in_array($page['section'], array('sizes', 'watermark')) and count($page['errors']) == 0)
[345]246  {
[1565]247    //echo '<pre>'; print_r($_POST); echo '</pre>';
[1748]248    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
[4325]249    while ($row = pwg_db_fetch_assoc($result))
[512]250    {
251      if (isset($_POST[$row['param']]))
252      {
[882]253        $value = $_POST[$row['param']];
[1071]254
255        if ('gallery_title' == $row['param'])
[882]256        {
257          if (!$conf['allow_html_descriptions'])
258          {
259            $value = strip_tags($value);
260          }
261        }
[1071]262
[528]263        $query = '
264UPDATE '.CONFIG_TABLE.'
[1926]265SET value = \''. str_replace("\'", "''", $value).'\'
266WHERE param = \''.$row['param'].'\'
[528]267;';
[587]268        pwg_query($query);
[512]269      }
270    }
[5021]271    array_push($page['infos'], l10n('Information data registered in database'));
[345]272  }
[527]273
[1748]274  //------------------------------------------------------ $conf reinitialization
275  load_conf_from_db();
[1565]276}
[14251]277
278// restore default derivatives settings
279if ('sizes' == $page['section'] and isset($_GET['action']) and 'restore_settings' == $_GET['action'])
[14228]280{
281  ImageStdParams::set_and_save( ImageStdParams::get_default_sizes() );
282  pwg_query('DELETE FROM '.CONFIG_TABLE.' WHERE param = \'disabled_derivatives\'');
283  clear_derivative_cache();
[14251]284
285  array_push(
286    $page['infos'],
287    l10n('Your configuration settings are saved')
288    );
[14228]289}
[1565]290
[512]291//----------------------------------------------------- template initialization
[2530]292$template->set_filename('config', 'configuration.tpl');
[512]293
[2226]294// TabSheet
295$tabsheet = new tabsheet();
[16925]296$tabsheet->set_id('configuration');
[2226]297$tabsheet->select($page['section']);
298$tabsheet->assign();
[1881]299
[2249]300$action = get_root_url().'admin.php?page=configuration';
[528]301$action.= '&amp;section='.$page['section'];
[21]302
[2288]303$template->assign(
[528]304  array(
[5920]305    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
[1004]306    'F_ACTION'=>$action
[528]307    ));
308
[527]309switch ($page['section'])
[528]310{
[1894]311  case 'main' :
[17302]312  {
313
[11587]314    function order_by_is_local()
[11279]315    {
[11587]316      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
317      if (isset($conf['local_dir_site']))
318      {
319        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
320      }
[17302]321
[11587]322      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
[11279]323    }
[17302]324
[11587]325    if (order_by_is_local())
[11279]326    {
[11587]327      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]328    }
[17302]329
[11587]330    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
[11279]331    {
[13087]332      $order_by = array('');
[11587]333      $template->assign('ORDER_BY_IS_CUSTOM', true);
[11279]334    }
335    else
336    {
[11587]337      $out = array();
338      $order_by = trim($conf['order_by_inside_category']);
339      $order_by = str_replace('ORDER BY ', null, $order_by);
340      $order_by = explode(', ', $order_by);
[11279]341    }
[17302]342
[2249]343    $template->assign(
[1894]344      'main',
[528]345      array(
[2021]346        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
347        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
[8626]348        'week_starts_on_options' => array(
349          'sunday' => $lang['day'][0],
350          'monday' => $lang['day'][1],
351          ),
352        'week_starts_on_options_selected' => $conf['week_starts_on'],
[11587]353        'order_by' => $order_by,
[13087]354        'order_by_options' => $sort_fields,
[11587]355        )
356      );
[1617]357
[2325]358    foreach ($main_checkboxes as $checkbox)
[1617]359    {
[2249]360      $template->append(
[1894]361          'main',
[1617]362          array(
[2249]363            $checkbox => $conf[$checkbox]
364            ),
365          true
[1617]366        );
367    }
[528]368    break;
369  }
370  case 'comments' :
371  {
[2249]372    $template->assign(
[528]373      'comments',
374      array(
375        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
[12894]376        'comments_order'=>$conf['comments_order'],
[13224]377        'comments_order_options'=> $comments_order
[12894]378        )
379      );
[1617]380
[2325]381    foreach ($comments_checkboxes as $checkbox)
[1617]382    {
[2249]383      $template->append(
[1617]384          'comments',
385          array(
[2249]386            $checkbox => $conf[$checkbox]
387            ),
388          true
[1617]389        );
390    }
[528]391    break;
392  }
393  case 'default' :
394  {
[5994]395    $edit_user = build_user($conf['guest_id'], false);
[1926]396    include_once(PHPWG_ROOT_PATH.'profile.php');
[1071]397
[1926]398    $errors = array();
[8126]399    if (save_profile_from_post($edit_user, $errors))
[858]400    {
[8126]401      // Reload user
402      $edit_user = build_user($conf['guest_id'], false);
403      array_push($page['infos'], l10n('Information data registered in database'));
[858]404    }
[1926]405    $page['errors'] = array_merge($page['errors'], $errors);
[541]406
[1926]407    load_profile_in_template(
408      $action,
409      '',
410      $edit_user
411      );
[2249]412    $template->assign('default', array());
[528]413    break;
414  }
[5293]415  case 'display' :
416  {
417    foreach ($display_checkboxes as $checkbox)
418    {
419      $template->append(
420          'display',
421          array(
422            $checkbox => $conf[$checkbox]
423            ),
424          true
425        );
426    }
[5304]427    $template->append(
428        'display',
429        array(
[18165]430          'picture_informations' => unserialize($conf['picture_informations']),
431          'NB_CATEGORIES_PAGE' => $conf['nb_categories_page'],
[5304]432          ),
433        true
434      );
[5293]435    break;
436  }
[12879]437  case 'sizes' :
438  {
[14221]439    // we only load the derivatives if it was not already loaded: it occurs
440    // when submitting the form and an error remains
441    if (!isset($page['sizes_loaded_in_tpl']))
[12879]442    {
[23643]443      $is_gd = (pwg_image::get_library()=='gd')? true : false;
444      $template->assign('is_gd', $is_gd);
[14221]445      $template->assign(
[12879]446        'sizes',
447        array(
[14221]448          'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
449          'original_resize_maxheight' => $conf['original_resize_maxheight'],
450          'original_resize_quality' => $conf['original_resize_quality'],
451          )
[12879]452        );
[17302]453
[14221]454      foreach ($sizes_checkboxes as $checkbox)
[13883]455      {
[14221]456        $template->append(
457          'sizes',
458          array(
459            $checkbox => $conf[$checkbox]
460            ),
461          true
462          );
[13883]463      }
[17302]464
[14221]465      // derivatives = multiple size
466      $enabled = ImageStdParams::get_defined_type_map();
467      $disabled = @unserialize(@$conf['disabled_derivatives']);
468      if ($disabled === false)
[13883]469      {
[14221]470        $disabled = array();
[13883]471      }
[14221]472
473      $tpl_vars = array();
474      foreach(ImageStdParams::get_all_types() as $type)
[13883]475      {
[14221]476        $tpl_var = array();
[17302]477
[14221]478        $tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false);
479        $tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false;
[17302]480
[14221]481        if ($params = @$enabled[$type])
[13883]482        {
[14221]483          $tpl_var['enabled'] = true;
[13883]484        }
485        else
486        {
[14221]487          $tpl_var['enabled']=false;
488          $params=@$disabled[$type];
[13883]489        }
[17302]490
[14221]491        if ($params)
492        {
493          list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size;
494          if ( ($tpl_var['crop'] = round(100*$params->sizing->max_crop)) > 0)
495          {
496            list($tpl_var['minw'],$tpl_var['minh']) = $params->sizing->min_size;
497          }
498          else
499          {
500            $tpl_var['minw'] = $tpl_var['minh'] = "";
501          }
502          $tpl_var['sharpen'] = $params->sharpen;
503        }
504        $tpl_vars[$type]=$tpl_var;
[13883]505      }
[14221]506      $template->assign('derivatives', $tpl_vars);
[14649]507      $template->assign('resize_quality', ImageStdParams::$quality);
[17302]508
509      $tpl_vars = array();
510      $now = time();
511      foreach(ImageStdParams::$custom as $custom=>$time)
512      {
513        $tpl_vars[$custom] = ($now-$time<=24*3600) ? l10n('today') : time_since($time, 'day');
514      }
515      $template->assign('custom_derivatives', $tpl_vars);
[13883]516    }
517
[12879]518    break;
519  }
[14512]520  case 'watermark' :
521  {
522    $watermark_files = array();
523    foreach (glob(PHPWG_ROOT_PATH.'themes/default/watermarks/*.png') as $file)
524    {
525      $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
526    }
[16167]527    if ( ($glob=glob(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/*.png')) !== false)
[14512]528    {
[16167]529      foreach ($glob as $file)
530      {
531        $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
532      }
[14512]533    }
534    $watermark_filemap = array( '' => '---' );
535    foreach( $watermark_files as $file)
536    {
537      $display = basename($file);
538      $watermark_filemap[$file] = $display;
539    }
540    $template->assign('watermark_files', $watermark_filemap);
541
[14513]542    if ($template->get_template_vars('watermark') === null)
[14512]543    {
[14513]544      $wm = ImageStdParams::get_watermark();
[14512]545
546      $position = 'custom';
[14513]547      if ($wm->xpos == 0 and $wm->ypos == 0)
548      {
549        $position = 'topleft';
550      }
551      if ($wm->xpos == 100 and $wm->ypos == 0)
552      {
553        $position = 'topright';
554      }
555      if ($wm->xpos == 50 and $wm->ypos == 50)
556      {
557        $position = 'middle';
558      }
559      if ($wm->xpos == 0 and $wm->ypos == 100)
560      {
561        $position = 'bottomleft';
562      }
563      if ($wm->xpos == 100 and $wm->ypos == 100)
564      {
565        $position = 'bottomright';
566      }
[17302]567
[14513]568      if ($wm->xrepeat != 0)
569      {
570        $position = 'custom';
571      }
[17302]572
[14513]573      $template->assign(
574        'watermark',
575        array(
576          'file' => $wm->file,
577          'minw' => $wm->min_size[0],
578          'minh' => $wm->min_size[1],
579          'xpos' => $wm->xpos,
580          'ypos' => $wm->ypos,
581          'xrepeat' => $wm->xrepeat,
582          'opacity' => $wm->opacity,
583          'position' => $position,
584          )
585        );
[14512]586    }
[17302]587
[14512]588    break;
589  }
[528]590}
[1926]591
[2]592//----------------------------------------------------------- sending html code
[393]593$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
[362]594?>
Note: See TracBrowser for help on using the repository browser.