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
195
196
197
198
199
200
201
|
<?php /************************* Coppermine Photo Gallery ************************ Copyright (c) 2003-2008 Dev Team v1.1 originally written by Gregory DEMAR
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. ******************************************** Coppermine version: 1.4.19 $HeadURL: https://coppermine.svn.sourceforge.net/svnroot/coppermine/trunk/cpg1.4.x/update.php $ $Revision: 4392 $ $Author: gaugau $ $Date: 2008-04-16 09:25:35 +0200 (Mi, 16 Apr 2008) $ **********************************************/
// Report all errors except E_NOTICE // This is the default value set in php.ini error_reporting (E_ALL ^ E_NOTICE);
require ('include/sql_parse.php'); require ('include/config.inc.php'); require ('include/update.inc.php');
// ---------------------------- TEST PREREQUIRED --------------------------- // function test_fs() { global $errors, $DFLT; // No Filesystem Updates yet
// If plugins folder doesn't exist create it if (!is_dir('./plugins')) { $mask = umask(0); mkdir('./plugins',0777); umask($mask); } }
function update_system_thumbs() { global $CONFIG;
$results = mysql_query("SELECT * FROM ".$CONFIG['TABLE_PREFIX']."config;"); while ($row = mysql_fetch_array($results)) { $CONFIG[$row['name']] = $row['value']; } // while mysql_free_result($results);
// Code to rename system thumbs in images folder (except nopic.jpg and private.jpg) $old_thumb_pfx = 'thumb_';
if ($old_thumb_pfx != $CONFIG['thumb_pfx']) { $folders = array('images/', $THEME_DIR.'images/'); foreach ($folders as $folder) { $thumbs = cpg_get_system_thumb_list($folder); foreach ($thumbs as $thumb) { @rename($folder.$thumb['filename'], $folder.str_replace($old_thumb_pfx,$CONFIG['thumb_pfx'],$thumb['filename'])); } } }
// If old images for nopic.jpg and private.jpg exist, delete the new ones if (file_exists('images/nopic.jpg')) { @unlink('images/thumb_nopic.jpg'); }
if (file_exists('images/private.jpg')) { @unlink('images/thumb_private.jpg'); }
// Rename old images to new format @rename('images/nopic.jpg','images/'.$CONFIG['thumb_pfx'].'nopic.jpg'); @rename('images/private.jpg','images/'.$CONFIG['thumb_pfx'].'private.jpg'); }
/** * Return an array containing the system thumbs in a directory */ function cpg_get_system_thumb_list($search_folder = 'images/') { global $CONFIG; static $thumbs = array();
$folder = 'images/';
$thumb_pfx =& $CONFIG['thumb_pfx']; // If thumb array is empty get list from coppermine 'images' folder if ((count($thumbs) == 0) && ($folder == $search_folder)) { $dir = opendir($folder); while (($file = readdir($dir))!==false) { if (is_file($folder . $file) && strpos($file,$thumb_pfx) === 0) { // Store filenames in an array $thumbs[] = array('filename' => $file); } } closedir($dir); return $thumbs; } elseif ($folder == $search_folder) { // Search folder is the same as coppermine images folder; just return the array return $thumbs; } else { // Search folder is the different; check for files in the given folder $results = array(); foreach ($thumbs as $thumb) { if (is_file($search_folder.$thumb['filename'])) { $results[] = array('filename' => $thumb['filename']); } } return $results; } }
// ----------------------------- TEST FUNCTIONS ---------------------------- // function test_sql_connection() { global $errors, $CONFIG;
if (! $connect_id = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass'])) { $errors .= "<hr /><br />Could not create a mySQL connection, please check the SQL values in include/config.inc.php<br /><br />MySQL error was : " . mysql_error() . "<br /><br />"; } elseif (! mysql_select_db($CONFIG['dbname'], $connect_id)) { $errors .= "<hr /><br />mySQL could not locate a database called '{$CONFIG['dbname']}' please check the value entered for this in include/config.inc.php<br /><br />"; } } // ------------------------- HTML OUTPUT FUNCTIONS ------------------------- // // Moved to include/update.inc.php -- chtito
// ------------------------- SQL QUERIES TO CREATE TABLES ------------------ // function update_tables() { global $errors, $CONFIG;
//$PHP_SELF = $_SERVER['PHP_SELF']; $gallery_dir = strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'); $gallery_url_prefix = 'http://' . $_SERVER['HTTP_HOST'] . $gallery_dir . (substr($gallery_dir, -1) == '/' ? '' : '/');
$db_update = 'sql/update.sql'; $sql_query = fread(fopen($db_update, 'r'), filesize($db_update)); // Update table prefix $sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
$sql_query = remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ';');
?> <h2>Performing Database Updates<h2> <table class="maintable">
<?php
foreach($sql_query as $q) { echo "<tr><td class='tableb'>$q</td>"; if (@mysql_query($q)) { echo "<td class='updatesOK'>OK</td>"; } else { echo "<td class='updatesFail'>Already Done</td>"; } } echo "</table>"; }
// --------------------------------- MAIN CODE ----------------------------- // // The defaults values $table_prefix = $_POST['table_prefix']; $DFLT = array('lck_f' => 'install.lock', // Name of install lock file 'cfg_d' => 'include', // The config file dir 'cfg_f' => 'include/config.inc.php', // The config file name 'alb_d' => 'albums', // The album dir 'upl_d' => 'userpics' // The uploaded pic dir );
$errors = ''; $notes = ''; // The installer html_header("Coppermine - Upgrade"); html_logo();
test_fs(); if ($errors != '') html_prereq_errors($errors); else { test_sql_connection(); if ($errors == '') { update_tables(); update_system_thumbs(); } else { html_error($errors); } if ($errors == '') { html_install_success($notes); } else { html_error($errors); } }
html_footer(); ?>
|