source: trunk/admin/configuration.php @ 17302

Last change on this file since 17302 was 17302, checked in by rvelices, 12 years ago

merge-r17295 from branch 2.4 feature 2708: in admin, display allowed custom derivatives and ability to delete them

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