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