source: trunk/admin/configuration.php @ 27867

Last change on this file since 27867 was 26461, checked in by mistic100, 10 years ago

Update headers to 2014. Happy new year!!

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