source: trunk/admin/configuration.php @ 23675

Last change on this file since 23675 was 23675, checked in by rvelices, 11 years ago

bug 2931: photos sort order, "default" is meaningless (was not working with ascending order fields in admin)

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