This repository has been archived by the owner on Jul 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupgrade.php
194 lines (175 loc) · 6.83 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
// prevent this file from being accessed directly
if (!defined('WB_PATH'))
die(header('Location: index.php'));
global $database;
/*******************************************************************************
*
* Update from Version 1.20/1.21 to newer Versions
*
* * new Settings Table
* * new Thumbnail-Settings
* * categorie text field now as text
* * delete unused files (many of them are moved to the admin folder)
*
******************************************************************************/
/*
* BEGIN: Create new settings table
*/
// Check if the table has still it's old format
// (Maybe this script runs a second time, so wo don't have to run the whole script again
$oldFormat = true;
$sql = "SHOW FIELDS FROM `" . TABLE_PREFIX . "mod_foldergallery_settings`";
$query = $database->query($sql);
while ($row = $query->fetchRow()) {
if ($row['Field'] == 's_name') {
$oldFormat = false;
break;
}
}
if ($oldFormat) {
// Save the old Settings
$sql = "SELECT * FROM `" . TABLE_PREFIX . "mod_foldergallery_settings`";
$query = $database->query($sql);
while ($row = $query->fetchRow()) {
$settings[] = $row;
}
// Delete the old Settings Table
$database->query("DROP TABLE IF EXISTS `" . TABLE_PREFIX . "mod_foldergallery_settings`;");
// Create the new Settings Table
$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "mod_foldergallery_settings` ("
. "`id` int(11) NOT NULL AUTO_INCREMENT,"
. "`section_id` int(11) NOT NULL,"
. "`s_name` varchar(100) NOT NULL,"
. "`s_value` TEXT NOT NULL,"
. "PRIMARY KEY (`id`));";
$database->query($sql);
// Write the new Settings
foreach ($settings as $value) {
$section_id = $value['section_id'];
foreach ($value as $key => $val) {
// Prevent entries with numeric values (they are generated by fetchRow)
if (is_numeric($key)) {
continue;
}
// The following values are no longer needed
if ($key == 'section_id') {
continue;
}
if ($key == 'thumb_size') {
continue;
}
if ($key == 'ratio') {
continue;
}
$sql = "INSERT INTO `" . TABLE_PREFIX . "mod_foldergallery_settings` (`id`, `section_id`, `s_name`, `s_value`) VALUES "
. "(null, '" . $section_id . "', '" . $key . "', '" . $val . "');";
$database->query($sql);
}
/**
* The thumbnail Settings are now stored as a serialized array
* the folowing switch statement calculates the new values
*/
switch ($value['ratio']) {
case 1:
$thumbSettings = array(
'image_resize' => true,
'image_x' => $value['thumb_size'],
'image_y' => $value['thumb_size']
);
break;
case 1.3333:
$thumbSettings = array(
'image_resize' => true,
'image_x' => $value['thumb_size'],
'image_y' => floor($value['thumb_size']*3/4)
);
break;
case 0.75:
$thumbSettings = array(
'image_resize' => true,
'image_x' => floor($value['thumb_size']*3/4),
'image_y' => $value['thumb_size']
);
break;
case 1.7778:
$thumbSettings = array(
'image_resize' => true,
'image_x' => $value['thumb_size'],
'image_y' => floor($value['thumb_size']*9/16)
);
break;
case 0.5625:
$thumbSettings = array(
'image_resize' => true,
'image_x' => floor($value['thumb_size']*9/16),
'image_y' => $value['thumb_size']
);
default:
break;
}
/**
* the folowing values are default for new pages. As there was no
* equivalten value before, we set them on update to default.
*/
$thumbSettings['image_ratio_fill'] = false;
$thumbSettings['image_ratio_crop'] = true;
$thumbSettings['image_background_color'] = '#FFFFFF';
$sql = "INSERT INTO `" . TABLE_PREFIX . "mod_foldergallery_settings` (`id`, `section_id`, `s_name`, `s_value`) VALUES "
. "(null, '" . $section_id . "', 'tbSettings', '".serialize($thumbSettings)."');";
$database->query($sql);
}
}
/**
* END: Create new settings table
*/
/**
* alter categories Table to allow more than 255 characters as categoriedescription
*/
$sql = "ALTER TABLE `".TABLE_PREFIX."mod_foldergallery_categories` CHANGE `description` `description` TEXT NOT NULL DEFAULT '';";
$database->query($sql);
/**
* END alter categories Table
*/
/**
* There are files which are moved or no longer needed.
* So we need to delete the old files and directories
*/
$fg_path = WB_PATH.'/modules/foldergallery/';
$file_list = array(
$fg_path.'modify_cat.php', // Moved to admin
$fg_path.'modify_cat_sort.php', // Moved to admin
$fg_path.'modify_settings.php', // Moved to admin
$fg_path.'modify_thumb.php', // Moved to admin
$fg_path.'save_cat.php', // Moved to admin
$fg_path.'save_files.php', // Moved to admin
$fg_path.'save_settings.php', // Moved to admin
$fg_path.'sync.php', // Moved to admin
$fg_path.'frontend.css.orig', // No longer needed
$fg_path.'scripts/backend.functions.php', // Moved to admin/scripts
$fg_path.'scripts/delete_cat.php', // Moved to admin/scripts
$fg_path.'scripts/delete_img.php', // Moved to admin/scripts
$fg_path.'scripts/move_down.php', // Moved to admin/scripts
$fg_path.'scripts/move_up.php', // Moved to admin/scripts
$fg_path.'scripts/quick_img_sort.php', // Moved to admin/scripts
$fg_path.'scripts/reorderCNC.php', // Moved to admin/scripts
$fg_path.'scripts/reorderDND.php', // Moved to admin/scripts
$fg_path.'templates/modify_cat.htt', // Moved to admin/templates
$fg_path.'templates/modify_cat_sort.htt', // Moved to admin/templates
$fg_path.'templates/modify_settings.htt', // Moved to admin/templates
$fg_path.'templates/modify.htt', // Moved to admin/templates
$fg_path.'images/eck.gif', // No longer needed
$fg_path.'images/crumbs.gif' // No longer needed
);
foreach($file_list as $file) {
if(file_exists($file)) {
unlink($file);
}
}
/**
* END: Deleting old files
*/
/**
* END: Update from Version 1.20/1.21
*/
?>