source: trunk/admin/configuration.php @ 26010

Last change on this file since 26010 was 25489, checked in by mistic100, 10 years ago

bug 2883: filter order_by for duplicated values

  • Property svn:eol-style set to LF
File size: 17.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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    'comments_author_mandatory',
78    'comments_email_mandatory',
79  );
80
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',
88    'index_new_icon',
89    'picture_metadata_icon',
90    'picture_slideshow_icon',
91    'picture_favorite_icon',
92    'picture_download_icon',
93    'picture_navigation_icons',
94    'picture_navigation_thumb',
95    'picture_menu',
96  );
97
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',
108    'rating_score',
109    'privacy_level',
110  );
111
112// image order management
113$sort_fields = array(
114  ''                    => '',
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'),
130  );
131
132$comments_order = array(
133  'ASC' => l10n('Show oldest comments first'),
134  'DESC' => l10n('Show latest comments first'),
135  );
136
137$mail_themes = array(
138  'clear' => 'Clear',
139  'dark' => 'Dark',
140  );
141
142//------------------------------ verification and registration of modifications
143if (isset($_POST['submit']))
144{
145  $int_pattern = '/^\d+$/';
146
147  switch ($page['section'])
148  {
149    case 'main' :
150    {
151      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
152      {
153        if ( !empty($_POST['order_by']) )
154        {
155          $used = array();
156          foreach ($_POST['order_by'] as $i => $val)
157          {
158            if (empty($val) or isset($used[$val]))
159            {
160              unset($_POST['order_by'][$i]);
161            }
162            else
163            {
164              $used[$val] = true;
165            }
166          }
167          if ( !count($_POST['order_by']) )
168          {
169            $page['errors'][] = l10n('No order field selected');
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));
175
176            // there is no rank outside categories
177            if ( ($i = array_search('rank ASC', $order_by)) !== false)
178            {
179              unset($order_by[$i]);
180            }
181
182            // must define a default order_by if user want to order by rank only
183            if ( count($order_by) == 0 )
184            {
185              $order_by = array('id ASC');
186            }
187
188            $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
189            $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
190          }
191        }
192        else
193        {
194          $page['errors'][] = l10n('No order field selected');
195        }
196      }
197
198      foreach( $main_checkboxes as $checkbox)
199      {
200        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
201      }
202      break;
203    }
204    case 'watermark' :
205    {
206      include(PHPWG_ROOT_PATH.'admin/include/configuration_watermark_process.inc.php');
207      break;
208    }
209    case 'sizes' :
210    {
211      include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php');
212      break;
213    }
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      {
222        $page['errors'][] = l10n('The number of comments a page must be between 5 and 50 included.');
223      }
224      foreach( $comments_checkboxes as $checkbox)
225      {
226        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
227      }
228      break;
229    }
230    case 'default' :
231    {
232      // Never go here
233      break;
234    }
235    case 'display' :
236    {
237      if (!preg_match($int_pattern, $_POST['nb_categories_page'])
238            or $_POST['nb_categories_page'] < 4)
239      {
240        $page['errors'][] = l10n('The number of albums a page must be above 4.');
241      }
242      foreach( $display_checkboxes as $checkbox)
243      {
244        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
245      }
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']));
252      break;
253    }
254  }
255
256  // updating configuration if no error found
257  if (!in_array($page['section'], array('sizes', 'watermark')) and count($page['errors']) == 0)
258  {
259    //echo '<pre>'; print_r($_POST); echo '</pre>';
260    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
261    while ($row = pwg_db_fetch_assoc($result))
262    {
263      if (isset($_POST[$row['param']]))
264      {
265        $value = $_POST[$row['param']];
266
267        if ('gallery_title' == $row['param'])
268        {
269          if (!$conf['allow_html_descriptions'])
270          {
271            $value = strip_tags($value);
272          }
273        }
274
275        $query = '
276UPDATE '.CONFIG_TABLE.'
277SET value = \''. str_replace("\'", "''", $value).'\'
278WHERE param = \''.$row['param'].'\'
279;';
280        pwg_query($query);
281      }
282    }
283    $page['infos'][] = l10n('Information data registered in database');
284  }
285
286  //------------------------------------------------------ $conf reinitialization
287  load_conf_from_db();
288}
289
290// restore default derivatives settings
291if ('sizes' == $page['section'] and isset($_GET['action']) and 'restore_settings' == $_GET['action'])
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();
296
297  $page['infos'][] = l10n('Your configuration settings are saved');
298}
299
300//----------------------------------------------------- template initialization
301$template->set_filename('config', 'configuration.tpl');
302
303// TabSheet
304$tabsheet = new tabsheet();
305$tabsheet->set_id('configuration');
306$tabsheet->select($page['section']);
307$tabsheet->assign();
308
309$action = get_root_url().'admin.php?page=configuration';
310$action.= '&amp;section='.$page['section'];
311
312$template->assign(
313  array(
314    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
315    'F_ACTION'=>$action
316    ));
317
318switch ($page['section'])
319{
320  case 'main' :
321  {
322
323    function order_by_is_local()
324    {
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      }
330
331      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
332    }
333
334    if (order_by_is_local())
335    {
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> !');
337    }
338
339    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
340    {
341      $order_by = array('');
342      $template->assign('ORDER_BY_IS_CUSTOM', true);
343    }
344    else
345    {
346      $out = array();
347      $order_by = trim($conf['order_by_inside_category']);
348      $order_by = str_replace('ORDER BY ', null, $order_by);
349      $order_by = explode(', ', $order_by);
350    }
351
352    $template->assign(
353      'main',
354      array(
355        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
356        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
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'],
362        'mail_theme' => $conf['mail_theme'],
363        'mail_theme_options' => $mail_themes,
364        'order_by' => $order_by,
365        'order_by_options' => $sort_fields,
366        )
367      );
368
369    foreach ($main_checkboxes as $checkbox)
370    {
371      $template->append(
372          'main',
373          array(
374            $checkbox => $conf[$checkbox]
375            ),
376          true
377        );
378    }
379    break;
380  }
381  case 'comments' :
382  {
383    $template->assign(
384      'comments',
385      array(
386        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
387        'comments_order'=>$conf['comments_order'],
388        'comments_order_options'=> $comments_order
389        )
390      );
391
392    foreach ($comments_checkboxes as $checkbox)
393    {
394      $template->append(
395          'comments',
396          array(
397            $checkbox => $conf[$checkbox]
398            ),
399          true
400        );
401    }
402    break;
403  }
404  case 'default' :
405  {
406    $edit_user = build_user($conf['guest_id'], false);
407    include_once(PHPWG_ROOT_PATH.'profile.php');
408
409    $errors = array();
410    if (save_profile_from_post($edit_user, $errors))
411    {
412      // Reload user
413      $edit_user = build_user($conf['guest_id'], false);
414      $page['infos'][] = l10n('Information data registered in database');
415    }
416    $page['errors'] = array_merge($page['errors'], $errors);
417
418    load_profile_in_template(
419      $action,
420      '',
421      $edit_user
422      );
423    $template->assign('default', array());
424    break;
425  }
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    }
438    $template->append(
439        'display',
440        array(
441          'picture_informations' => unserialize($conf['picture_informations']),
442          'NB_CATEGORIES_PAGE' => $conf['nb_categories_page'],
443          ),
444        true
445      );
446    break;
447  }
448  case 'sizes' :
449  {
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']))
453    {
454      $is_gd = (pwg_image::get_library()=='gd')? true : false;
455      $template->assign('is_gd', $is_gd);
456      $template->assign(
457        'sizes',
458        array(
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          )
463        );
464
465      foreach ($sizes_checkboxes as $checkbox)
466      {
467        $template->append(
468          'sizes',
469          array(
470            $checkbox => $conf[$checkbox]
471            ),
472          true
473          );
474      }
475
476      // derivatives = multiple size
477      $enabled = ImageStdParams::get_defined_type_map();
478      $disabled = @unserialize(@$conf['disabled_derivatives']);
479      if ($disabled === false)
480      {
481        $disabled = array();
482      }
483
484      $tpl_vars = array();
485      foreach(ImageStdParams::get_all_types() as $type)
486      {
487        $tpl_var = array();
488
489        $tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false);
490        $tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false;
491
492        if ($params = @$enabled[$type])
493        {
494          $tpl_var['enabled'] = true;
495        }
496        else
497        {
498          $tpl_var['enabled']=false;
499          $params=@$disabled[$type];
500        }
501
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;
516      }
517      $template->assign('derivatives', $tpl_vars);
518      $template->assign('resize_quality', ImageStdParams::$quality);
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);
527    }
528
529    break;
530  }
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    }
538    if ( ($glob=glob(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/*.png')) !== false)
539    {
540      foreach ($glob as $file)
541      {
542        $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
543      }
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
553    if ($template->get_template_vars('watermark') === null)
554    {
555      $wm = ImageStdParams::get_watermark();
556
557      $position = 'custom';
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      }
578
579      if ($wm->xrepeat != 0)
580      {
581        $position = 'custom';
582      }
583
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        );
597    }
598
599    break;
600  }
601}
602
603//----------------------------------------------------------- sending html code
604$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
605?>
Note: See TracBrowser for help on using the repository browser.