1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class dcUpgrade |
---|
15 | { |
---|
16 | public static function dotclearUpgrade($core) |
---|
17 | { |
---|
18 | $version = $core->getVersion('core'); |
---|
19 | |
---|
20 | if ($version === null) { |
---|
21 | return false; |
---|
22 | } |
---|
23 | |
---|
24 | if (version_compare($version,DC_VERSION,'<') == 1 || strpos(DC_VERSION,'dev')) |
---|
25 | { |
---|
26 | try |
---|
27 | { |
---|
28 | if ($core->con->driver() == 'sqlite') { |
---|
29 | return false; // Need to find a way to upgrade sqlite database |
---|
30 | } |
---|
31 | |
---|
32 | # Database upgrade |
---|
33 | $_s = new dbStruct($core->con,$core->prefix); |
---|
34 | require dirname(__FILE__).'/db-schema.php'; |
---|
35 | |
---|
36 | $si = new dbStruct($core->con,$core->prefix); |
---|
37 | $changes = $si->synchronize($_s); |
---|
38 | |
---|
39 | /* Some other upgrades |
---|
40 | ------------------------------------ */ |
---|
41 | $cleanup_sessions = self::growUp($core,$version); |
---|
42 | |
---|
43 | # Drop content from session table if changes or if needed |
---|
44 | if ($changes != 0 || $cleanup_sessions) { |
---|
45 | $core->con->execute('DELETE FROM '.$core->prefix.'session '); |
---|
46 | } |
---|
47 | |
---|
48 | # Empty templates cache directory |
---|
49 | try { |
---|
50 | $core->emptyTemplatesCache(); |
---|
51 | } catch (Exception $e) {} |
---|
52 | |
---|
53 | return $changes; |
---|
54 | } |
---|
55 | catch (Exception $e) |
---|
56 | { |
---|
57 | throw new Exception(__('Something went wrong with auto upgrade:'). |
---|
58 | ' '.$e->getMessage()); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | # No upgrade? |
---|
63 | return false; |
---|
64 | } |
---|
65 | |
---|
66 | public static function growUp($core,$version) |
---|
67 | { |
---|
68 | if ($version === null) { |
---|
69 | return false; |
---|
70 | } |
---|
71 | |
---|
72 | $cleanup_sessions = false; // update it in a step that needed sessions to be removed |
---|
73 | |
---|
74 | # Populate media_dir field (since 2.0-beta3.3) |
---|
75 | if (version_compare($version,'2.0-beta3.3','<')) |
---|
76 | { |
---|
77 | $strReq = 'SELECT media_id, media_file FROM '.$core->prefix.'media '; |
---|
78 | $rs_m = $core->con->select($strReq); |
---|
79 | while($rs_m->fetch()) { |
---|
80 | $cur = $core->con->openCursor($core->prefix.'media'); |
---|
81 | $cur->media_dir = dirname($rs_m->media_file); |
---|
82 | $cur->update('WHERE media_id = '.(integer) $rs_m->media_id); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | if (version_compare($version,'2.0-beta7.3','<')) |
---|
87 | { |
---|
88 | # Blowup becomes default theme |
---|
89 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
90 | "SET setting_value = '%s' ". |
---|
91 | "WHERE setting_id = 'theme' ". |
---|
92 | "AND setting_value = '%s' ". |
---|
93 | 'AND blog_id IS NOT NULL '; |
---|
94 | $core->con->execute(sprintf($strReq,'blueSilence','default')); |
---|
95 | $core->con->execute(sprintf($strReq,'default','blowup')); |
---|
96 | } |
---|
97 | |
---|
98 | if (version_compare($version,'2.1-alpha2-r2383','<')) |
---|
99 | { |
---|
100 | $schema = dbSchema::init($core->con); |
---|
101 | $schema->dropUnique($core->prefix.'category',$core->prefix.'uk_cat_title'); |
---|
102 | |
---|
103 | # Reindex categories |
---|
104 | $rs = $core->con->select( |
---|
105 | 'SELECT cat_id, cat_title, blog_id '. |
---|
106 | 'FROM '.$core->prefix.'category '. |
---|
107 | 'ORDER BY blog_id ASC , cat_position ASC ' |
---|
108 | ); |
---|
109 | $cat_blog = $rs->blog_id; |
---|
110 | $i = 2; |
---|
111 | while ($rs->fetch()) { |
---|
112 | if ($cat_blog != $rs->blog_id) { |
---|
113 | $i = 2; |
---|
114 | } |
---|
115 | $core->con->execute( |
---|
116 | 'UPDATE '.$core->prefix.'category SET ' |
---|
117 | .'cat_lft = '.($i++).', cat_rgt = '.($i++).' '. |
---|
118 | 'WHERE cat_id = '.(integer) $rs->cat_id |
---|
119 | ); |
---|
120 | $cat_blog = $rs->blog_id; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | if (version_compare($version,'2.1.6','<=')) |
---|
125 | { |
---|
126 | # ie7js has been upgraded |
---|
127 | $ie7files = array ( |
---|
128 | 'ie7-base64.php ', |
---|
129 | 'ie7-content.htc', |
---|
130 | 'ie7-core.js', |
---|
131 | 'ie7-css2-selectors.js', |
---|
132 | 'ie7-css3-selectors.js', |
---|
133 | 'ie7-css-strict.js', |
---|
134 | 'ie7-dhtml.js', |
---|
135 | 'ie7-dynamic-attributes.js', |
---|
136 | 'ie7-fixed.js', |
---|
137 | 'ie7-graphics.js', |
---|
138 | 'ie7-html4.js', |
---|
139 | 'ie7-ie5.js', |
---|
140 | 'ie7-layout.js', |
---|
141 | 'ie7-load.htc', |
---|
142 | 'ie7-object.htc', |
---|
143 | 'ie7-overflow.js', |
---|
144 | 'ie7-quirks.js', |
---|
145 | 'ie7-server.css', |
---|
146 | 'ie7-standard-p.js', |
---|
147 | 'ie7-xml-extras.js' |
---|
148 | ); |
---|
149 | foreach ($ie7files as $f) { |
---|
150 | @unlink(DC_ROOT.'/admin/js/ie7/'.$f); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | if (version_compare($version,'2.2-alpha1-r3043','<')) |
---|
155 | { |
---|
156 | # metadata has been integrated to the core. |
---|
157 | $core->plugins->loadModules(DC_PLUGINS_ROOT); |
---|
158 | if ($core->plugins->moduleExists('metadata')) { |
---|
159 | $core->plugins->deleteModule('metadata'); |
---|
160 | } |
---|
161 | |
---|
162 | # Tags template class has been renamed |
---|
163 | $sqlstr = |
---|
164 | 'SELECT blog_id, setting_id, setting_value '. |
---|
165 | 'FROM '.$core->prefix.'setting '. |
---|
166 | 'WHERE (setting_id = \'widgets_nav\' OR setting_id = \'widgets_extra\') '. |
---|
167 | 'AND setting_ns = \'widgets\';'; |
---|
168 | $rs = $core->con->select($sqlstr); |
---|
169 | while ($rs->fetch()) { |
---|
170 | $widgetsettings = base64_decode($rs->setting_value); |
---|
171 | $widgetsettings = str_replace ('s:11:"tplMetadata"','s:7:"tplTags"',$widgetsettings); |
---|
172 | $cur = $core->con->openCursor($core->prefix.'setting'); |
---|
173 | $cur->setting_value = base64_encode($widgetsettings); |
---|
174 | $sqlstr = 'WHERE setting_id = \''.$rs->setting_id.'\' AND setting_ns = \'widgets\' '. |
---|
175 | 'AND blog_id ' . |
---|
176 | ($rs->blog_id == NULL ? 'is NULL' : '= \''.$core->con->escape($rs->blog_id).'\''); |
---|
177 | $cur->update($sqlstr); |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | if (version_compare($version,'2.3','<')) |
---|
182 | { |
---|
183 | # Add global favorites |
---|
184 | $init_fav = array(); |
---|
185 | |
---|
186 | $init_fav['new_post'] = array('new_post','New entry','post.php', |
---|
187 | 'images/menu/edit.png','images/menu/edit-b.png', |
---|
188 | 'usage,contentadmin',null,null); |
---|
189 | $init_fav['newpage'] = array('newpage','New page','plugin.php?p=pages&act=page', |
---|
190 | 'index.php?pf=pages/icon-np.png','index.php?pf=pages/icon-np-big.png', |
---|
191 | 'contentadmin,pages',null,null); |
---|
192 | $init_fav['media'] = array('media','Media manager','media.php', |
---|
193 | 'images/menu/media.png','images/menu/media-b.png', |
---|
194 | 'media,media_admin',null,null); |
---|
195 | $init_fav['widgets'] = array('widgets','Presentation widgets','plugin.php?p=widgets', |
---|
196 | 'index.php?pf=widgets/icon.png','index.php?pf=widgets/icon-big.png', |
---|
197 | 'admin',null,null); |
---|
198 | $init_fav['blog_theme'] = array('blog_theme','Blog appearance','blog_theme.php', |
---|
199 | 'images/menu/themes.png','images/menu/blog-theme-b.png', |
---|
200 | 'admin',null,null); |
---|
201 | |
---|
202 | $count = 0; |
---|
203 | foreach ($init_fav as $k => $f) { |
---|
204 | $t = array('name' => $f[0],'title' => $f[1],'url' => $f[2], 'small-icon' => $f[3], |
---|
205 | 'large-icon' => $f[4],'permissions' => $f[5],'id' => $f[6],'class' => $f[7]); |
---|
206 | $sqlstr = 'INSERT INTO '.$core->prefix.'pref (pref_id, user_id, pref_ws, pref_value, pref_type, pref_label) VALUES ('. |
---|
207 | '\''.sprintf("g%03s",$count).'\',NULL,\'favorites\',\''.serialize($t).'\',\'string\',NULL);'; |
---|
208 | $core->con->execute($sqlstr); |
---|
209 | $count++; |
---|
210 | } |
---|
211 | |
---|
212 | # A bit of housecleaning for no longer needed files |
---|
213 | $remfiles = array ( |
---|
214 | 'admin/style/cat-bg.png', |
---|
215 | 'admin/style/footer-bg.png', |
---|
216 | 'admin/style/head-logo.png', |
---|
217 | 'admin/style/tab-bg.png', |
---|
218 | 'admin/style/tab-c-l.png', |
---|
219 | 'admin/style/tab-c-r.png', |
---|
220 | 'admin/style/tab-l-l.png', |
---|
221 | 'admin/style/tab-l-r.png', |
---|
222 | 'admin/style/tab-n-l.png', |
---|
223 | 'admin/style/tab-n-r.png', |
---|
224 | 'inc/clearbricks/_common.php', |
---|
225 | 'inc/clearbricks/common/lib.crypt.php', |
---|
226 | 'inc/clearbricks/common/lib.date.php', |
---|
227 | 'inc/clearbricks/common/lib.files.php', |
---|
228 | 'inc/clearbricks/common/lib.form.php', |
---|
229 | 'inc/clearbricks/common/lib.html.php', |
---|
230 | 'inc/clearbricks/common/lib.http.php', |
---|
231 | 'inc/clearbricks/common/lib.l10n.php', |
---|
232 | 'inc/clearbricks/common/lib.text.php', |
---|
233 | 'inc/clearbricks/common/tz.dat', |
---|
234 | 'inc/clearbricks/common/_main.php', |
---|
235 | 'inc/clearbricks/dblayer/class.cursor.php', |
---|
236 | 'inc/clearbricks/dblayer/class.mysql.php', |
---|
237 | 'inc/clearbricks/dblayer/class.pgsql.php', |
---|
238 | 'inc/clearbricks/dblayer/class.sqlite.php', |
---|
239 | 'inc/clearbricks/dblayer/dblayer.php', |
---|
240 | 'inc/clearbricks/dbschema/class.dbschema.php', |
---|
241 | 'inc/clearbricks/dbschema/class.dbstruct.php', |
---|
242 | 'inc/clearbricks/dbschema/class.mysql.dbschema.php', |
---|
243 | 'inc/clearbricks/dbschema/class.pgsql.dbschema.php', |
---|
244 | 'inc/clearbricks/dbschema/class.sqlite.dbschema.php', |
---|
245 | 'inc/clearbricks/diff/lib.diff.php', |
---|
246 | 'inc/clearbricks/diff/lib.unified.diff.php', |
---|
247 | 'inc/clearbricks/filemanager/class.filemanager.php', |
---|
248 | 'inc/clearbricks/html.filter/class.html.filter.php', |
---|
249 | 'inc/clearbricks/html.validator/class.html.validator.php', |
---|
250 | 'inc/clearbricks/image/class.image.meta.php', |
---|
251 | 'inc/clearbricks/image/class.image.tools.php', |
---|
252 | 'inc/clearbricks/mail/class.mail.php', |
---|
253 | 'inc/clearbricks/mail/class.socket.mail.php', |
---|
254 | 'inc/clearbricks/net/class.net.socket.php', |
---|
255 | 'inc/clearbricks/net.http/class.net.http.php', |
---|
256 | 'inc/clearbricks/net.http.feed/class.feed.parser.php', |
---|
257 | 'inc/clearbricks/net.http.feed/class.feed.reader.php', |
---|
258 | 'inc/clearbricks/net.xmlrpc/class.net.xmlrpc.php', |
---|
259 | 'inc/clearbricks/pager/class.pager.php', |
---|
260 | 'inc/clearbricks/rest/class.rest.php', |
---|
261 | 'inc/clearbricks/session.db/class.session.db.php', |
---|
262 | 'inc/clearbricks/template/class.template.php', |
---|
263 | 'inc/clearbricks/text.wiki2xhtml/class.wiki2xhtml.php', |
---|
264 | 'inc/clearbricks/url.handler/class.url.handler.php', |
---|
265 | 'inc/clearbricks/zip/class.unzip.php', |
---|
266 | 'inc/clearbricks/zip/class.zip.php', |
---|
267 | 'themes/default/tpl/.htaccess', |
---|
268 | 'themes/default/tpl/404.html', |
---|
269 | 'themes/default/tpl/archive.html', |
---|
270 | 'themes/default/tpl/archive_month.html', |
---|
271 | 'themes/default/tpl/category.html', |
---|
272 | 'themes/default/tpl/home.html', |
---|
273 | 'themes/default/tpl/post.html', |
---|
274 | 'themes/default/tpl/search.html', |
---|
275 | 'themes/default/tpl/tag.html', |
---|
276 | 'themes/default/tpl/tags.html', |
---|
277 | 'themes/default/tpl/user_head.html', |
---|
278 | 'themes/default/tpl/_flv_player.html', |
---|
279 | 'themes/default/tpl/_footer.html', |
---|
280 | 'themes/default/tpl/_head.html', |
---|
281 | 'themes/default/tpl/_mp3_player.html', |
---|
282 | 'themes/default/tpl/_top.html' |
---|
283 | ); |
---|
284 | $remfolders = array ( |
---|
285 | 'inc/clearbricks/common', |
---|
286 | 'inc/clearbricks/dblayer', |
---|
287 | 'inc/clearbricks/dbschema', |
---|
288 | 'inc/clearbricks/diff', |
---|
289 | 'inc/clearbricks/filemanager', |
---|
290 | 'inc/clearbricks/html.filter', |
---|
291 | 'inc/clearbricks/html.validator', |
---|
292 | 'inc/clearbricks/image', |
---|
293 | 'inc/clearbricks/mail', |
---|
294 | 'inc/clearbricks/net', |
---|
295 | 'inc/clearbricks/net.http', |
---|
296 | 'inc/clearbricks/net.http.feed', |
---|
297 | 'inc/clearbricks/net.xmlrpc', |
---|
298 | 'inc/clearbricks/pager', |
---|
299 | 'inc/clearbricks/rest', |
---|
300 | 'inc/clearbricks/session.db', |
---|
301 | 'inc/clearbricks/template', |
---|
302 | 'inc/clearbricks/text.wiki2xhtml', |
---|
303 | 'inc/clearbricks/url.handler', |
---|
304 | 'inc/clearbricks/zip', |
---|
305 | 'inc/clearbricks', |
---|
306 | 'themes/default/tpl' |
---|
307 | ); |
---|
308 | |
---|
309 | foreach ($remfiles as $f) { |
---|
310 | @unlink(DC_ROOT.'/'.$f); |
---|
311 | } |
---|
312 | foreach ($remfolders as $f) { |
---|
313 | @rmdir(DC_ROOT.'/'.$f); |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | if (version_compare($version,'2.3.1','<')) |
---|
318 | { |
---|
319 | # Remove unecessary file |
---|
320 | @unlink(DC_ROOT.'/'.'inc/libs/clearbricks/.hgignore'); |
---|
321 | } |
---|
322 | |
---|
323 | if (version_compare($version,'2.4.0','<=')) |
---|
324 | { |
---|
325 | # setup media_exclusion |
---|
326 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
327 | "SET setting_value = '/\\.php\$/i' ". |
---|
328 | "WHERE setting_id = 'media_exclusion' ". |
---|
329 | "AND setting_value = '' "; |
---|
330 | $core->con->execute($strReq); |
---|
331 | } |
---|
332 | |
---|
333 | if (version_compare($version,'2.5','<=')) |
---|
334 | { |
---|
335 | # Try to disable daInstaller plugin if it has been installed outside the default plugins directory |
---|
336 | $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); |
---|
337 | $default = path::real(dirname(__FILE__).'/../../plugins/'); |
---|
338 | foreach ($path as $root) |
---|
339 | { |
---|
340 | if (!is_dir($root) || !is_readable($root)) { |
---|
341 | continue; |
---|
342 | } |
---|
343 | if (substr($root,-1) != '/') { |
---|
344 | $root .= '/'; |
---|
345 | } |
---|
346 | if (($p = @dir($root)) === false) { |
---|
347 | continue; |
---|
348 | } |
---|
349 | if(path::real($root) == $default) { |
---|
350 | continue; |
---|
351 | } |
---|
352 | if (($d = @dir($root.'daInstaller')) === false) { |
---|
353 | continue; |
---|
354 | } |
---|
355 | $f = $root.'/daInstaller/_disabled'; |
---|
356 | if (!file_exists($f)) |
---|
357 | { |
---|
358 | @file_put_contents($f,''); |
---|
359 | } |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | if (version_compare($version,'2.5.1','<=')) |
---|
364 | { |
---|
365 | // Flash enhanced upload no longer needed |
---|
366 | @unlink(DC_ROOT.'/'.'inc/swf/swfupload.swf'); |
---|
367 | } |
---|
368 | |
---|
369 | if (version_compare($version,'2.6','<=')) |
---|
370 | { |
---|
371 | // README has been replaced by README.md and CONTRIBUTING.md |
---|
372 | @unlink(DC_ROOT.'/'.'README'); |
---|
373 | |
---|
374 | // trackbacks are now merged into posts |
---|
375 | @unlink(DC_ROOT.'/'.'admin/trackbacks.php'); |
---|
376 | |
---|
377 | # daInstaller has been integrated to the core. |
---|
378 | # Try to remove it |
---|
379 | $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); |
---|
380 | foreach ($path as $root) |
---|
381 | { |
---|
382 | if (!is_dir($root) || !is_readable($root)) { |
---|
383 | continue; |
---|
384 | } |
---|
385 | if (substr($root,-1) != '/') { |
---|
386 | $root .= '/'; |
---|
387 | } |
---|
388 | if (($p = @dir($root)) === false) { |
---|
389 | continue; |
---|
390 | } |
---|
391 | if (($d = @dir($root.'daInstaller')) === false) { |
---|
392 | continue; |
---|
393 | } |
---|
394 | files::deltree($root.'/daInstaller'); |
---|
395 | } |
---|
396 | |
---|
397 | # Some settings change, prepare db queries |
---|
398 | $strReqFormat = 'INSERT INTO '.$core->prefix.'setting'; |
---|
399 | $strReqFormat .= ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'; |
---|
400 | $strReqFormat .= ' VALUES(\'%s\',\'system\',\'%s\',\'string\',\'%s\')'; |
---|
401 | |
---|
402 | $strReqSelect = 'SELECT count(1) FROM '.$core->prefix.'setting'; |
---|
403 | $strReqSelect .= ' WHERE setting_id = \'%s\''; |
---|
404 | $strReqSelect .= ' AND setting_ns = \'system\''; |
---|
405 | $strReqSelect .= ' AND blog_id IS NULL'; |
---|
406 | |
---|
407 | # Add date and time formats |
---|
408 | $date_formats = array('%Y-%m-%d','%m/%d/%Y','%d/%m/%Y','%Y/%m/%d','%d.%m.%Y','%b %e %Y','%e %b %Y','%Y %b %e', |
---|
409 | '%a, %Y-%m-%d','%a, %m/%d/%Y','%a, %d/%m/%Y','%a, %Y/%m/%d','%B %e, %Y','%e %B, %Y','%Y, %B %e','%e. %B %Y', |
---|
410 | '%A, %B %e, %Y','%A, %e %B, %Y','%A, %Y, %B %e','%A, %Y, %B %e','%A, %e. %B %Y'); |
---|
411 | $time_formats = array('%H:%M','%I:%M','%l:%M','%Hh%M','%Ih%M','%lh%M'); |
---|
412 | if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { |
---|
413 | $date_formats = array_map(create_function('$f', |
---|
414 | 'return str_replace(\'%e\',\'%#d\',$f);' |
---|
415 | ),$date_formats); |
---|
416 | } |
---|
417 | |
---|
418 | $rs = $core->con->select(sprintf($strReqSelect,'date_formats')); |
---|
419 | if ($rs->f(0)==0) { |
---|
420 | $strReq = sprintf($strReqFormat,'date_formats',serialize($date_formats),'Date formats examples'); |
---|
421 | $core->con->execute($strReq); |
---|
422 | } |
---|
423 | $rs = $core->con->select(sprintf($strReqSelect,'time_formats')); |
---|
424 | if ($rs->f(0)==0) { |
---|
425 | $strReq = sprintf($strReqFormat,'time_formats',serialize($time_formats),'Time formats examples'); |
---|
426 | $core->con->execute($strReq); |
---|
427 | } |
---|
428 | |
---|
429 | # Add repository URL for themes and plugins as daInstaller move to core |
---|
430 | $rs = $core->con->select(sprintf($strReqSelect,'store_plugin_url')); |
---|
431 | if ($rs->f(0)==0) { |
---|
432 | $strReq = sprintf($strReqFormat,'store_plugin_url','http://update.dotaddict.org/dc2/plugins.xml','Plugins XML feed location'); |
---|
433 | $core->con->execute($strReq); |
---|
434 | } |
---|
435 | $rs = $core->con->select(sprintf($strReqSelect,'store_theme_url')); |
---|
436 | if ($rs->f(0)==0) { |
---|
437 | $strReq = sprintf($strReqFormat,'store_theme_url','http://update.dotaddict.org/dc2/themes.xml','Themes XML feed location'); |
---|
438 | $core->con->execute($strReq); |
---|
439 | } |
---|
440 | } |
---|
441 | |
---|
442 | if (version_compare($version,'2.7','<=')) |
---|
443 | { |
---|
444 | # Some new settings should be initialized, prepare db queries |
---|
445 | $strReqFormat = 'INSERT INTO '.$core->prefix.'setting'; |
---|
446 | $strReqFormat .= ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'; |
---|
447 | $strReqFormat .= ' VALUES(\'%s\',\'system\',\'%s\',\'string\',\'%s\')'; |
---|
448 | |
---|
449 | $strReqCount = 'SELECT count(1) FROM '.$core->prefix.'setting'; |
---|
450 | $strReqCount .= ' WHERE setting_id = \'%s\''; |
---|
451 | $strReqCount .= ' AND setting_ns = \'system\''; |
---|
452 | $strReqCount .= ' AND blog_id IS NULL'; |
---|
453 | |
---|
454 | $strReqSelect = 'SELECT setting_value FROM '.$core->prefix.'setting'; |
---|
455 | $strReqSelect .= ' WHERE setting_id = \'%s\''; |
---|
456 | $strReqSelect .= ' AND setting_ns = \'system\''; |
---|
457 | $strReqSelect .= ' AND blog_id IS NULL'; |
---|
458 | |
---|
459 | # Add nb of posts for home (first page), copying nb of posts on every page |
---|
460 | $rs = $core->con->select(sprintf($strReqCount,'nb_post_for_home')); |
---|
461 | if ($rs->f(0)==0) { |
---|
462 | $rs = $core->con->select(sprintf($strReqSelect,'nb_post_per_page')); |
---|
463 | $strReq = sprintf($strReqFormat,'nb_post_for_home',$rs->f(0),'Nb of posts on home (first page only)'); |
---|
464 | $core->con->execute($strReq); |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | if (version_compare($version,'2.8.1','<=')) |
---|
469 | { |
---|
470 | # switch from jQuery 1.11.1 to 1.11.2 |
---|
471 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
472 | " SET setting_value = '1.11.3' ". |
---|
473 | " WHERE setting_id = 'jquery_version' ". |
---|
474 | " AND setting_ns = 'system' ". |
---|
475 | " AND setting_value = '1.11.1' "; |
---|
476 | $core->con->execute($strReq); |
---|
477 | # setup media_exclusion (cope with php, php5, php7, … rather than only .php) |
---|
478 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
479 | " SET setting_value = '/\\.php[0-9]*\$/i' ". |
---|
480 | " WHERE setting_id = 'media_exclusion' ". |
---|
481 | " AND setting_ns = 'system' ". |
---|
482 | " AND setting_value = '/\\.php\$/i' "; |
---|
483 | $core->con->execute($strReq); |
---|
484 | # Some new settings should be initialized, prepare db queries |
---|
485 | $strReq = 'INSERT INTO '.$core->prefix.'setting'. |
---|
486 | ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. |
---|
487 | ' VALUES(\'%s\',\'system\',\'%s\',\'boolean\',\'%s\')'; |
---|
488 | $core->con->execute(sprintf($strReq,'no_search','0','Disable internal search system')); |
---|
489 | } |
---|
490 | |
---|
491 | if (version_compare($version,'2.8.2','<=')) |
---|
492 | { |
---|
493 | # Update flie exclusion upload regex |
---|
494 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
495 | " SET setting_value = '/\\.(phps?|pht(ml)?|phl)[0-9]*\$/i' ". |
---|
496 | " WHERE setting_id = 'media_exclusion' ". |
---|
497 | " AND setting_ns = 'system' ". |
---|
498 | " AND (setting_value = '/\\.php[0-9]*\$/i' ". |
---|
499 | " OR setting_value = '/\\.php\$/i') "; |
---|
500 | $core->con->execute($strReq); |
---|
501 | } |
---|
502 | |
---|
503 | if (version_compare($version,'2.9','<=')) |
---|
504 | { |
---|
505 | # Some new settings should be initialized, prepare db queries |
---|
506 | $strReq = 'INSERT INTO '.$core->prefix.'setting'. |
---|
507 | ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. |
---|
508 | ' VALUES(\'%s\',\'system\',\'%s\',\'%s\',\'%s\')'; |
---|
509 | $core->con->execute( |
---|
510 | sprintf($strReq,'media_video_width','400','integer','Media video insertion width')); |
---|
511 | $core->con->execute( |
---|
512 | sprintf($strReq,'media_video_height','300','integer','Media video insertion height')); |
---|
513 | $core->con->execute( |
---|
514 | sprintf($strReq,'media_flash_fallback','1','boolean','Flash player fallback for audio and video media')); |
---|
515 | |
---|
516 | # Some settings and prefs should be moved from string to array |
---|
517 | self::settings2array('system','date_formats'); |
---|
518 | self::settings2array('system','time_formats'); |
---|
519 | self::settings2array('antispam','antispam_filters'); |
---|
520 | self::settings2array('pings','pings_uris'); |
---|
521 | self::settings2array('system','simpleMenu'); |
---|
522 | self::prefs2array('dashboard','favorites'); |
---|
523 | } |
---|
524 | |
---|
525 | if (version_compare($version,'2.9.1','<=')) |
---|
526 | { |
---|
527 | # Some settings and prefs should be moved from string to array |
---|
528 | self::prefs2array('dashboard','favorites'); |
---|
529 | self::prefs2array('interface','media_last_dirs'); |
---|
530 | |
---|
531 | # Update flie exclusion upload regex |
---|
532 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
533 | " SET setting_value = '/\\.(phps?|pht(ml)?|phl|s?html?|js)[0-9]*\$/i' ". |
---|
534 | " WHERE setting_id = 'media_exclusion' ". |
---|
535 | " AND setting_ns = 'system' ". |
---|
536 | " AND (setting_value = '/\\.php[0-9]*\$/i' ". |
---|
537 | " OR setting_value = '/\\.php\$/i') ". |
---|
538 | " OR setting_value = '/\\.(phps?|pht(ml)?|phl)[0-9]*\$/i' "; |
---|
539 | $core->con->execute($strReq); |
---|
540 | } |
---|
541 | |
---|
542 | if (version_compare($version,'2.10','<')) |
---|
543 | { |
---|
544 | @unlink(DC_ROOT.'/'.'admin/js/jsUpload/vendor/jquery.ui.widget.js'); |
---|
545 | @rmdir(DC_ROOT.'/'.'admin/js/jsUpload/vendor'); |
---|
546 | |
---|
547 | # Create new var directory and its .htaccess file |
---|
548 | @files::makeDir(DC_VAR); |
---|
549 | $f = DC_VAR.'/.htaccess'; |
---|
550 | if (!file_exists($f)) |
---|
551 | { |
---|
552 | @file_put_contents($f,'Require all denied'."\n".'Deny from all'."\n"); |
---|
553 | } |
---|
554 | |
---|
555 | # Update flie exclusion upload regex |
---|
556 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
557 | " SET setting_value = '/\\.(phps?|pht(ml)?|phl|s?html?|js|htaccess)[0-9]*\$/i' ". |
---|
558 | " WHERE setting_id = 'media_exclusion' ". |
---|
559 | " AND setting_ns = 'system' ". |
---|
560 | " AND (setting_value = '/\\.php[0-9]*\$/i' ". |
---|
561 | " OR setting_value = '/\\.php\$/i') ". |
---|
562 | " OR setting_value = '/\\.(phps?|pht(ml)?|phl)[0-9]*\$/i' ". |
---|
563 | " OR setting_value = '/\\.(phps?|pht(ml)?|phl|s?html?|js)[0-9]*\$/i'"; |
---|
564 | $core->con->execute($strReq); |
---|
565 | |
---|
566 | # Some new settings should be initialized, prepare db queries |
---|
567 | $strReq = 'INSERT INTO '.$core->prefix.'setting'. |
---|
568 | ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. |
---|
569 | ' VALUES(\'%s\',\'system\',\'%s\',\'%s\',\'%s\')'; |
---|
570 | # Import feed control |
---|
571 | $core->con->execute( |
---|
572 | sprintf($strReq,'import_feed_url_control',true,'boolean','Control feed URL before import')); |
---|
573 | $core->con->execute( |
---|
574 | sprintf($strReq,'import_feed_no_private_ip',true,'boolean','Prevent import feed from private IP')); |
---|
575 | $core->con->execute( |
---|
576 | sprintf($strReq,'import_feed_ip_regexp','','string','Authorize import feed only from this IP regexp')); |
---|
577 | $core->con->execute( |
---|
578 | sprintf($strReq,'import_feed_port_regexp','/^(80|443)$/','string','Authorize import feed only from this port regexp')); |
---|
579 | # CSP directive (admin part) |
---|
580 | $core->con->execute( |
---|
581 | sprintf($strReq,'csp_admin_on',true,'boolean','Send CSP header (admin)')); |
---|
582 | $core->con->execute( |
---|
583 | sprintf($strReq,'csp_admin_default',"''self''",'string','CSP default-src directive')); |
---|
584 | $core->con->execute( |
---|
585 | sprintf($strReq,'csp_admin_script',"''self'' ''unsafe-inline'' ''unsafe-eval''",'string','CSP script-src directive')); |
---|
586 | $core->con->execute( |
---|
587 | sprintf($strReq,'csp_admin_style',"''self'' ''unsafe-inline''",'string','CSP style-src directive')); |
---|
588 | $core->con->execute( |
---|
589 | sprintf($strReq,'csp_admin_img',"''self'' data: media.dotaddict.org",'string','CSP img-src directive')); |
---|
590 | } |
---|
591 | |
---|
592 | if (version_compare($version,'2.11','<')) |
---|
593 | { |
---|
594 | // Remove the CSP report file from it's old place |
---|
595 | @unlink(DC_ROOT.'/admin/csp_report.txt'); |
---|
596 | |
---|
597 | # Some new settings should be initialized, prepare db queries |
---|
598 | $strReq = 'INSERT INTO '.$core->prefix.'setting'. |
---|
599 | ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. |
---|
600 | ' VALUES(\'%s\',\'system\',\'%s\',\'%s\',\'%s\')'; |
---|
601 | $core->con->execute( |
---|
602 | sprintf($strReq,'csp_admin_report_only',false,'boolean','CSP Report only violations (admin)')); |
---|
603 | |
---|
604 | # A bit of housecleaning for no longer needed files |
---|
605 | $remfiles = array ( |
---|
606 | 'admin/js/jquery/jquery.modal.js', |
---|
607 | 'admin/style/modal/close.png', |
---|
608 | 'admin/style/modal/loader.gif', |
---|
609 | 'admin/style/modal/modal.css', |
---|
610 | 'admin/js/dragsort-tablerows.js', |
---|
611 | 'admin/js/tool-man/cookies.js', |
---|
612 | 'admin/js/tool-man/coordinates.js', |
---|
613 | 'admin/js/tool-man/core.js', |
---|
614 | 'admin/js/tool-man/css.js', |
---|
615 | 'admin/js/tool-man/drag.js', |
---|
616 | 'admin/js/tool-man/dragsort.js', |
---|
617 | 'admin/js/tool-man/events.js' |
---|
618 | ); |
---|
619 | $remfolders = array ( |
---|
620 | 'admin/style/modal', |
---|
621 | 'admin/js/tool-man', |
---|
622 | ); |
---|
623 | |
---|
624 | foreach ($remfiles as $f) { |
---|
625 | @unlink(DC_ROOT.'/'.$f); |
---|
626 | } |
---|
627 | foreach ($remfolders as $f) { |
---|
628 | @rmdir(DC_ROOT.'/'.$f); |
---|
629 | } |
---|
630 | } |
---|
631 | |
---|
632 | $core->setVersion('core',DC_VERSION); |
---|
633 | $core->blogDefaults(); |
---|
634 | |
---|
635 | return $cleanup_sessions; |
---|
636 | } |
---|
637 | |
---|
638 | /** |
---|
639 | * Convert old-fashion serialized array setting to new-fashion json encoded array |
---|
640 | * @param $ns namespace |
---|
641 | * @param $setting setting name (id) |
---|
642 | */ |
---|
643 | public static function settings2array($ns,$setting) |
---|
644 | { |
---|
645 | global $core; |
---|
646 | |
---|
647 | $strReqSelect = |
---|
648 | "SELECT setting_id,blog_id,setting_ns,setting_type,setting_value FROM ".$core->prefix."setting ". |
---|
649 | "WHERE setting_id = '%s' ". |
---|
650 | "AND setting_ns = '%s' ". |
---|
651 | "AND setting_type = 'string'"; |
---|
652 | $rs = $core->con->select(sprintf($strReqSelect,$setting,$ns)); |
---|
653 | while ($rs->fetch()) { |
---|
654 | $value = @unserialize($rs->setting_value); |
---|
655 | if (!$value) { |
---|
656 | $value = array(); |
---|
657 | } |
---|
658 | settype($value,'array'); |
---|
659 | $value = json_encode($value); |
---|
660 | $rs2 = "UPDATE ".$core->prefix."setting ". |
---|
661 | "SET setting_type='array', setting_value = '".$core->con->escape($value)."' ". |
---|
662 | "WHERE setting_id='".$core->con->escape($rs->setting_id)."' ". |
---|
663 | "AND setting_ns='".$core->con->escape($rs->setting_ns)."' "; |
---|
664 | if ($rs->blog_id == '') { |
---|
665 | $rs2 .= "AND blog_id IS null"; |
---|
666 | } else { |
---|
667 | $rs2 .= "AND blog_id = '".$core->con->escape($rs->blog_id)."'"; |
---|
668 | } |
---|
669 | $core->con->execute($rs2); |
---|
670 | } |
---|
671 | } |
---|
672 | |
---|
673 | /** |
---|
674 | * Convert old-fashion serialized array pref to new-fashion json encoded array |
---|
675 | * @param $ws workspace |
---|
676 | * @param $pref pref name (id) |
---|
677 | */ |
---|
678 | public static function prefs2array($ws,$pref) |
---|
679 | { |
---|
680 | global $core; |
---|
681 | |
---|
682 | $strReqSelect = |
---|
683 | "SELECT pref_id,user_id,pref_ws,pref_type,pref_value FROM ".$core->prefix."pref ". |
---|
684 | "WHERE pref_id = '%s' ". |
---|
685 | "AND pref_ws = '%s' ". |
---|
686 | "AND pref_type = 'string'"; |
---|
687 | $rs = $core->con->select(sprintf($strReqSelect,$pref,$ws)); |
---|
688 | while ($rs->fetch()) { |
---|
689 | $value = @unserialize($rs->pref_value); |
---|
690 | if (!$value) { |
---|
691 | $value = array(); |
---|
692 | } |
---|
693 | settype($value,'array'); |
---|
694 | $value = json_encode($value); |
---|
695 | $rs2 = "UPDATE ".$core->prefix."pref ". |
---|
696 | "SET pref_type='array', pref_value = '".$core->con->escape($value)."' ". |
---|
697 | "WHERE pref_id='".$core->con->escape($rs->pref_id)."' ". |
---|
698 | "AND pref_ws='".$core->con->escape($rs->pref_ws)."' "; |
---|
699 | if ($rs->user_id == '') { |
---|
700 | $rs2 .= "AND user_id IS null"; |
---|
701 | } else { |
---|
702 | $rs2 .= "AND user_id = '".$core->con->escape($rs->user_id)."'"; |
---|
703 | } |
---|
704 | $core->con->execute($rs2); |
---|
705 | } |
---|
706 | } |
---|
707 | } |
---|