source: branches/2.7/admin/configuration.php @ 30973

Last change on this file since 30973 was 29540, checked in by mistic100, 10 years ago

forgot file in svn:29539

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