source: trunk/install/db/123-database.php @ 26461

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

Update headers to 2014. Happy new year!!

File size: 7.0 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
29$upgrade_description = 'convert 2.3 resize settings into 2.4 derivative settings';
30
31include_once(PHPWG_ROOT_PATH.'include/constants.php');
32
33$dbconf = array();
34$conf_orig = $conf;
35load_conf_from_db();
36$dbconf = $conf;
37$conf = $conf_orig;
38
39//
40// Piwigo 2.3 "HD resize" settings become "original resize" settings in Piwigo 2.4
41//
42
43if ($dbconf['upload_form_hd_keep'])
44{
45  if ($dbconf['upload_form_hd_resize'])
46  {
47    conf_update_param('original_resize', 'true');
48    conf_update_param('original_resize_maxwidth', $dbconf['upload_form_hd_maxwidth']);
49    conf_update_param('original_resize_maxheight', $dbconf['upload_form_hd_maxheight']);
50    conf_update_param('original_resize_quality', $dbconf['upload_form_hd_quality']);
51  }
52}
53else
54{
55  // The user has decided to remove the high quality. In Piwigo 2.4, this
56  // setting does not exists anymore, but we can simulate it by an original
57  // resize with 2.3 websize dimensions
58  conf_update_param('original_resize', 'true');
59 
60  conf_update_param(
61    'original_resize_maxwidth',
62    is_numeric($dbconf['upload_form_websize_maxwidth']) ? $dbconf['upload_form_websize_maxwidth'] : 800
63    );
64                   
65  conf_update_param(
66    'original_resize_maxheight',
67    is_numeric($dbconf['upload_form_websize_maxheight']) ? $dbconf['upload_form_websize_maxheight'] : 600
68    );
69 
70  conf_update_param('original_resize_quality', $dbconf['upload_form_hd_quality']);
71}
72
73$types = ImageStdParams::get_default_sizes();
74
75//
76// Piwigo 2.3 "thumbnail" becomes "thumb" size in Piwigo 2.4
77//
78
79$thumb_width_min = 128; // the default value in Piwigo 2.3
80$thumb_width_max = 300; // slightly bigger than XXS default maxwidth
81$thumb_height_min = 96; // the default value in Piwigo 2.3
82$thumb_height_max = 300; // slightly bigger than XXS default maxheight
83
84$thumb_is_square = false;
85if ($dbconf['upload_form_thumb_crop'])
86{
87  if ($dbconf['upload_form_thumb_maxwidth'] == $dbconf['upload_form_thumb_maxheight'])
88  {
89    $thumb_is_square = true;
90  }
91}
92
93if ($dbconf['upload_form_thumb_maxwidth'] < $thumb_width_min)
94{
95  $dbconf['upload_form_thumb_maxwidth'] = $thumb_width_min;
96}
97
98if ($dbconf['upload_form_thumb_maxwidth'] > $thumb_width_max)
99{
100  $dbconf['upload_form_thumb_maxwidth'] = $thumb_width_max;
101}
102
103if ($dbconf['upload_form_thumb_maxheight'] < $thumb_height_min)
104{
105  $dbconf['upload_form_thumb_maxheight'] = $thumb_height_min;
106}
107
108if ($dbconf['upload_form_thumb_maxheight'] > $thumb_height_max)
109{
110  $dbconf['upload_form_thumb_maxheight'] = $thumb_height_max;
111}
112
113if ($thumb_is_square)
114{
115  $dbconf['upload_form_thumb_maxheight'] = $dbconf['upload_form_thumb_maxwidth'];
116}
117
118$size = array($dbconf['upload_form_thumb_maxwidth'], $dbconf['upload_form_thumb_maxheight']);
119
120$thumb = new DerivativeParams(
121  new SizingParams(
122    $size,
123    $dbconf['upload_form_thumb_crop'] ? 1 : 0,
124    $dbconf['upload_form_thumb_crop'] ? $size : null
125    )
126  );
127
128$types[IMG_THUMB] = $thumb;
129
130// slightly enlarge XSS to be bigger than thumbnail size (but smaller than XS)
131if ($dbconf['upload_form_thumb_maxwidth'] >= $types[IMG_XXSMALL]->sizing->ideal_size[0]
132    or $dbconf['upload_form_thumb_maxheight'] >= $types[IMG_XXSMALL]->sizing->ideal_size[1])
133{
134  $xxs_maxwidth = $types[IMG_XXSMALL]->sizing->ideal_size[0];
135  if ($dbconf['upload_form_thumb_maxwidth'] >= $xxs_maxwidth)
136  {
137    $xxs_maxwidth = 350;
138  }
139
140  $xxs_maxheight = $types[IMG_XXSMALL]->sizing->ideal_size[1];
141  if ($dbconf['upload_form_thumb_maxheight'] >= $xxs_maxheight)
142  {
143    $xxs_maxheight = 310;
144  }
145
146  $xxs = new DerivativeParams(new SizingParams(array($xxs_maxwidth, $xxs_maxheight)));
147
148  $types[IMG_XXSMALL] = $xxs;
149}
150
151//
152// Piwigo 2.3 "websize" becomes "medium" size in Piwigo 2.4
153//
154
155// if there was no "websize resize" on Piwigo 2.3, we can't take the resize
156// settings into account, we keep the default settings of Piwigo 2.4.
157if ($dbconf['upload_form_websize_resize'])
158{
159  $medium_width_min = 577; // default S maxwidth + 1 pixel
160  $medium_width_max = 1007; // default L maxwidth - 1 pixel
161  $medium_height_min = 433; // default S maxheight + 1 pixel
162  $medium_height_max = 755; // default L maxheight - 1 pixel
163
164  // width
165  if (!is_numeric($dbconf['upload_form_websize_maxwidth'])) // sometimes maxwidth="false"
166  {
167    $dbconf['upload_form_websize_maxwidth'] = $medium_width_max;
168  }
169 
170  if ($dbconf['upload_form_websize_maxwidth'] < $medium_width_min)
171  {
172    $dbconf['upload_form_websize_maxwidth'] = $medium_width_min;
173  }
174 
175  if ($dbconf['upload_form_websize_maxwidth'] > $medium_width_max)
176  {
177    $dbconf['upload_form_websize_maxwidth'] = $medium_width_max;
178  }
179 
180  // height
181  if (!is_numeric($dbconf['upload_form_websize_maxheight'])) // sometimes maxheight="false"
182  {
183    $dbconf['upload_form_websize_maxheight'] = $medium_height_max;
184  }
185 
186  if ($dbconf['upload_form_websize_maxheight'] < $medium_height_min)
187  {
188    $dbconf['upload_form_websize_maxheight'] = $medium_height_min;
189  }
190 
191  if ($dbconf['upload_form_websize_maxheight'] > $medium_height_max)
192  {
193    $dbconf['upload_form_websize_maxheight'] = $medium_height_max;
194  }
195
196  $medium = new DerivativeParams(
197    new SizingParams(
198      array(
199        $dbconf['upload_form_websize_maxwidth'],
200        $dbconf['upload_form_websize_maxheight']
201        )
202      )
203    );
204
205  $types[IMG_MEDIUM] = $medium;
206}
207
208//
209// Save derivative new settings
210//
211
212ImageStdParams::set_and_save($types);
213
214pwg_query('DELETE FROM '.CONFIG_TABLE.' WHERE param = \'disabled_derivatives\'');
215clear_derivative_cache();
216
217echo "\n".$upgrade_description."\n";
218?>
Note: See TracBrowser for help on using the repository browser.