[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 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 | function dotclearUpgrade($core) |
---|
| 15 | { |
---|
| 16 | $version = $core->getVersion('core'); |
---|
| 17 | |
---|
| 18 | if ($version === null) { |
---|
| 19 | return false; |
---|
| 20 | } |
---|
| 21 | |
---|
[462] | 22 | if (version_compare($version,DC_VERSION,'<') == 1 || strpos(DC_VERSION,'dev')) |
---|
[0] | 23 | { |
---|
| 24 | try |
---|
| 25 | { |
---|
| 26 | if ($core->con->driver() == 'sqlite') { |
---|
| 27 | throw new Exception(__('SQLite Database Schema cannot be upgraded.')); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | # Database upgrade |
---|
| 31 | $_s = new dbStruct($core->con,$core->prefix); |
---|
| 32 | require dirname(__FILE__).'/db-schema.php'; |
---|
| 33 | |
---|
| 34 | $si = new dbStruct($core->con,$core->prefix); |
---|
[1083] | 35 | $changes = $si->synchronize($_s); |
---|
[0] | 36 | |
---|
| 37 | /* Some other upgrades |
---|
| 38 | ------------------------------------ */ |
---|
| 39 | # Populate media_dir field (since 2.0-beta3.3) |
---|
| 40 | if (version_compare($version,'2.0-beta3.3','<')) |
---|
| 41 | { |
---|
| 42 | $strReq = 'SELECT media_id, media_file FROM '.$core->prefix.'media '; |
---|
| 43 | $rs_m = $core->con->select($strReq); |
---|
| 44 | while($rs_m->fetch()) { |
---|
| 45 | $cur = $core->con->openCursor($core->prefix.'media'); |
---|
| 46 | $cur->media_dir = dirname($rs_m->media_file); |
---|
| 47 | $cur->update('WHERE media_id = '.(integer) $rs_m->media_id); |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | if (version_compare($version,'2.0-beta7.3','<')) |
---|
| 52 | { |
---|
| 53 | # Blowup becomes default theme |
---|
| 54 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
| 55 | "SET setting_value = '%s' ". |
---|
| 56 | "WHERE setting_id = 'theme' ". |
---|
| 57 | "AND setting_value = '%s' ". |
---|
| 58 | 'AND blog_id IS NOT NULL '; |
---|
| 59 | $core->con->execute(sprintf($strReq,'blueSilence','default')); |
---|
| 60 | $core->con->execute(sprintf($strReq,'default','blowup')); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if (version_compare($version,'2.1-alpha2-r2383','<')) |
---|
| 64 | { |
---|
| 65 | $schema = dbSchema::init($core->con); |
---|
| 66 | $schema->dropUnique($core->prefix.'category',$core->prefix.'uk_cat_title'); |
---|
| 67 | |
---|
| 68 | # Reindex categories |
---|
| 69 | $rs = $core->con->select( |
---|
| 70 | 'SELECT cat_id, cat_title, blog_id '. |
---|
| 71 | 'FROM '.$core->prefix.'category '. |
---|
| 72 | 'ORDER BY blog_id ASC , cat_position ASC ' |
---|
| 73 | ); |
---|
| 74 | $cat_blog = $rs->blog_id; |
---|
| 75 | $i = 2; |
---|
| 76 | while ($rs->fetch()) { |
---|
| 77 | if ($cat_blog != $rs->blog_id) { |
---|
| 78 | $i = 2; |
---|
| 79 | } |
---|
| 80 | $core->con->execute( |
---|
| 81 | 'UPDATE '.$core->prefix.'category SET ' |
---|
| 82 | .'cat_lft = '.($i++).', cat_rgt = '.($i++).' '. |
---|
| 83 | 'WHERE cat_id = '.(integer) $rs->cat_id |
---|
| 84 | ); |
---|
| 85 | $cat_blog = $rs->blog_id; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if (version_compare($version,'2.1.6','<=')) |
---|
| 90 | { |
---|
| 91 | # ie7js has been upgraded |
---|
| 92 | $ie7files = array ( |
---|
| 93 | 'ie7-base64.php ', |
---|
| 94 | 'ie7-content.htc', |
---|
| 95 | 'ie7-core.js', |
---|
| 96 | 'ie7-css2-selectors.js', |
---|
| 97 | 'ie7-css3-selectors.js', |
---|
| 98 | 'ie7-css-strict.js', |
---|
| 99 | 'ie7-dhtml.js', |
---|
| 100 | 'ie7-dynamic-attributes.js', |
---|
| 101 | 'ie7-fixed.js', |
---|
| 102 | 'ie7-graphics.js', |
---|
| 103 | 'ie7-html4.js', |
---|
| 104 | 'ie7-ie5.js', |
---|
| 105 | 'ie7-layout.js', |
---|
| 106 | 'ie7-load.htc', |
---|
| 107 | 'ie7-object.htc', |
---|
| 108 | 'ie7-overflow.js', |
---|
| 109 | 'ie7-quirks.js', |
---|
| 110 | 'ie7-server.css', |
---|
| 111 | 'ie7-standard-p.js', |
---|
| 112 | 'ie7-xml-extras.js' |
---|
| 113 | ); |
---|
| 114 | foreach ($ie7files as $f) { |
---|
| 115 | @unlink(DC_ROOT.'/admin/js/ie7/'.$f); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | if (version_compare($version,'2.2-alpha1-r3043','<')) |
---|
| 120 | { |
---|
| 121 | # metadata has been integrated to the core. |
---|
| 122 | $core->plugins->loadModules(DC_PLUGINS_ROOT); |
---|
| 123 | if ($core->plugins->moduleExists('metadata')) { |
---|
| 124 | $core->plugins->deleteModule('metadata'); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | # Tags template class has been renamed |
---|
| 128 | $sqlstr = |
---|
| 129 | 'SELECT blog_id, setting_id, setting_value '. |
---|
| 130 | 'FROM '.$core->prefix.'setting '. |
---|
| 131 | 'WHERE (setting_id = \'widgets_nav\' OR setting_id = \'widgets_extra\') '. |
---|
| 132 | 'AND setting_ns = \'widgets\';'; |
---|
| 133 | $rs = $core->con->select($sqlstr); |
---|
| 134 | while ($rs->fetch()) { |
---|
| 135 | $widgetsettings = base64_decode($rs->setting_value); |
---|
| 136 | $widgetsettings = str_replace ('s:11:"tplMetadata"','s:7:"tplTags"',$widgetsettings); |
---|
| 137 | $cur = $core->con->openCursor($core->prefix.'setting'); |
---|
| 138 | $cur->setting_value = base64_encode($widgetsettings); |
---|
| 139 | $sqlstr = 'WHERE setting_id = \''.$rs->setting_id.'\' AND setting_ns = \'widgets\' '. |
---|
| 140 | 'AND blog_id ' . |
---|
| 141 | ($rs->blog_id == NULL ? 'is NULL' : '= \''.$core->con->escape($rs->blog_id).'\''); |
---|
| 142 | $cur->update($sqlstr); |
---|
| 143 | } |
---|
| 144 | } |
---|
[3] | 145 | |
---|
| 146 | if (version_compare($version,'2.3','<')) |
---|
| 147 | { |
---|
| 148 | # Add global favorites |
---|
[19] | 149 | $init_fav = array(); |
---|
| 150 | |
---|
[324] | 151 | $init_fav['new_post'] = array('new_post','New entry','post.php', |
---|
[19] | 152 | 'images/menu/edit.png','images/menu/edit-b.png', |
---|
| 153 | 'usage,contentadmin',null,'menu-new-post'); |
---|
[1765] | 154 | $init_fav['newpage'] = array('newpage','New page','plugin.php?p=pages&act=page', |
---|
| 155 | 'index.php?pf=pages/icon-np.png','index.php?pf=pages/icon-np-big.png', |
---|
| 156 | 'contentadmin,pages',null,null); |
---|
| 157 | $init_fav['media'] = array('media','Media manager','media.php', |
---|
| 158 | 'images/menu/media.png','images/menu/media-b.png', |
---|
| 159 | 'media,media_admin',null,null); |
---|
| 160 | $init_fav['widgets'] = array('widgets','Presentation widgets','plugin.php?p=widgets', |
---|
| 161 | 'index.php?pf=widgets/icon.png','index.php?pf=widgets/icon-big.png', |
---|
[19] | 162 | 'admin',null,null); |
---|
[324] | 163 | $init_fav['blog_theme'] = array('blog_theme','Blog appearance','blog_theme.php', |
---|
[19] | 164 | 'images/menu/themes.png','images/menu/blog-theme-b.png', |
---|
| 165 | 'admin',null,null); |
---|
| 166 | |
---|
| 167 | $count = 0; |
---|
| 168 | foreach ($init_fav as $k => $f) { |
---|
| 169 | $t = array('name' => $f[0],'title' => $f[1],'url' => $f[2], 'small-icon' => $f[3], |
---|
| 170 | 'large-icon' => $f[4],'permissions' => $f[5],'id' => $f[6],'class' => $f[7]); |
---|
| 171 | $sqlstr = 'INSERT INTO '.$core->prefix.'pref (pref_id, user_id, pref_ws, pref_value, pref_type, pref_label) VALUES ('. |
---|
| 172 | '\''.sprintf("g%03s",$count).'\',NULL,\'favorites\',\''.serialize($t).'\',\'string\',NULL);'; |
---|
| 173 | $core->con->execute($sqlstr); |
---|
| 174 | $count++; |
---|
| 175 | } |
---|
[107] | 176 | |
---|
| 177 | # A bit of housecleaning for no longer needed files |
---|
| 178 | $remfiles = array ( |
---|
| 179 | 'admin/style/cat-bg.png', |
---|
| 180 | 'admin/style/footer-bg.png', |
---|
| 181 | 'admin/style/head-logo.png', |
---|
| 182 | 'admin/style/tab-bg.png', |
---|
| 183 | 'admin/style/tab-c-l.png', |
---|
| 184 | 'admin/style/tab-c-r.png', |
---|
| 185 | 'admin/style/tab-l-l.png', |
---|
| 186 | 'admin/style/tab-l-r.png', |
---|
| 187 | 'admin/style/tab-n-l.png', |
---|
| 188 | 'admin/style/tab-n-r.png', |
---|
| 189 | 'inc/clearbricks/_common.php', |
---|
| 190 | 'inc/clearbricks/common/lib.crypt.php', |
---|
| 191 | 'inc/clearbricks/common/lib.date.php', |
---|
| 192 | 'inc/clearbricks/common/lib.files.php', |
---|
| 193 | 'inc/clearbricks/common/lib.form.php', |
---|
| 194 | 'inc/clearbricks/common/lib.html.php', |
---|
| 195 | 'inc/clearbricks/common/lib.http.php', |
---|
| 196 | 'inc/clearbricks/common/lib.l10n.php', |
---|
| 197 | 'inc/clearbricks/common/lib.text.php', |
---|
| 198 | 'inc/clearbricks/common/tz.dat', |
---|
| 199 | 'inc/clearbricks/common/_main.php', |
---|
| 200 | 'inc/clearbricks/dblayer/class.cursor.php', |
---|
| 201 | 'inc/clearbricks/dblayer/class.mysql.php', |
---|
| 202 | 'inc/clearbricks/dblayer/class.pgsql.php', |
---|
| 203 | 'inc/clearbricks/dblayer/class.sqlite.php', |
---|
| 204 | 'inc/clearbricks/dblayer/dblayer.php', |
---|
| 205 | 'inc/clearbricks/dbschema/class.dbschema.php', |
---|
| 206 | 'inc/clearbricks/dbschema/class.dbstruct.php', |
---|
| 207 | 'inc/clearbricks/dbschema/class.mysql.dbschema.php', |
---|
| 208 | 'inc/clearbricks/dbschema/class.pgsql.dbschema.php', |
---|
| 209 | 'inc/clearbricks/dbschema/class.sqlite.dbschema.php', |
---|
| 210 | 'inc/clearbricks/diff/lib.diff.php', |
---|
| 211 | 'inc/clearbricks/diff/lib.unified.diff.php', |
---|
| 212 | 'inc/clearbricks/filemanager/class.filemanager.php', |
---|
| 213 | 'inc/clearbricks/html.filter/class.html.filter.php', |
---|
| 214 | 'inc/clearbricks/html.validator/class.html.validator.php', |
---|
| 215 | 'inc/clearbricks/image/class.image.meta.php', |
---|
| 216 | 'inc/clearbricks/image/class.image.tools.php', |
---|
| 217 | 'inc/clearbricks/mail/class.mail.php', |
---|
| 218 | 'inc/clearbricks/mail/class.socket.mail.php', |
---|
| 219 | 'inc/clearbricks/net/class.net.socket.php', |
---|
| 220 | 'inc/clearbricks/net.http/class.net.http.php', |
---|
| 221 | 'inc/clearbricks/net.http.feed/class.feed.parser.php', |
---|
| 222 | 'inc/clearbricks/net.http.feed/class.feed.reader.php', |
---|
| 223 | 'inc/clearbricks/net.xmlrpc/class.net.xmlrpc.php', |
---|
| 224 | 'inc/clearbricks/pager/class.pager.php', |
---|
| 225 | 'inc/clearbricks/rest/class.rest.php', |
---|
| 226 | 'inc/clearbricks/session.db/class.session.db.php', |
---|
| 227 | 'inc/clearbricks/template/class.template.php', |
---|
| 228 | 'inc/clearbricks/text.wiki2xhtml/class.wiki2xhtml.php', |
---|
| 229 | 'inc/clearbricks/url.handler/class.url.handler.php', |
---|
| 230 | 'inc/clearbricks/zip/class.unzip.php', |
---|
| 231 | 'inc/clearbricks/zip/class.zip.php', |
---|
| 232 | 'themes/default/tpl/.htaccess', |
---|
| 233 | 'themes/default/tpl/404.html', |
---|
| 234 | 'themes/default/tpl/archive.html', |
---|
| 235 | 'themes/default/tpl/archive_month.html', |
---|
| 236 | 'themes/default/tpl/category.html', |
---|
| 237 | 'themes/default/tpl/home.html', |
---|
| 238 | 'themes/default/tpl/post.html', |
---|
| 239 | 'themes/default/tpl/search.html', |
---|
| 240 | 'themes/default/tpl/tag.html', |
---|
| 241 | 'themes/default/tpl/tags.html', |
---|
| 242 | 'themes/default/tpl/user_head.html', |
---|
| 243 | 'themes/default/tpl/_flv_player.html', |
---|
| 244 | 'themes/default/tpl/_footer.html', |
---|
| 245 | 'themes/default/tpl/_head.html', |
---|
| 246 | 'themes/default/tpl/_mp3_player.html', |
---|
| 247 | 'themes/default/tpl/_top.html' |
---|
| 248 | ); |
---|
| 249 | $remfolders = array ( |
---|
| 250 | 'inc/clearbricks/common', |
---|
| 251 | 'inc/clearbricks/dblayer', |
---|
| 252 | 'inc/clearbricks/dbschema', |
---|
| 253 | 'inc/clearbricks/diff', |
---|
| 254 | 'inc/clearbricks/filemanager', |
---|
| 255 | 'inc/clearbricks/html.filter', |
---|
| 256 | 'inc/clearbricks/html.validator', |
---|
| 257 | 'inc/clearbricks/image', |
---|
| 258 | 'inc/clearbricks/mail', |
---|
| 259 | 'inc/clearbricks/net', |
---|
| 260 | 'inc/clearbricks/net.http', |
---|
| 261 | 'inc/clearbricks/net.http.feed', |
---|
| 262 | 'inc/clearbricks/net.xmlrpc', |
---|
| 263 | 'inc/clearbricks/pager', |
---|
| 264 | 'inc/clearbricks/rest', |
---|
| 265 | 'inc/clearbricks/session.db', |
---|
| 266 | 'inc/clearbricks/template', |
---|
| 267 | 'inc/clearbricks/text.wiki2xhtml', |
---|
| 268 | 'inc/clearbricks/url.handler', |
---|
| 269 | 'inc/clearbricks/zip', |
---|
| 270 | 'inc/clearbricks', |
---|
| 271 | 'themes/default/tpl' |
---|
| 272 | ); |
---|
| 273 | |
---|
| 274 | foreach ($remfiles as $f) { |
---|
| 275 | @unlink(DC_ROOT.'/'.$f); |
---|
| 276 | } |
---|
| 277 | foreach ($remfolders as $f) { |
---|
| 278 | @rmdir(DC_ROOT.'/'.$f); |
---|
| 279 | } |
---|
[3] | 280 | } |
---|
[0] | 281 | |
---|
[291] | 282 | if (version_compare($version,'2.3.1','<')) |
---|
| 283 | { |
---|
| 284 | # Remove unecessary file |
---|
| 285 | @unlink(DC_ROOT.'/'.'inc/libs/clearbricks/.hgignore'); |
---|
| 286 | } |
---|
[706] | 287 | |
---|
| 288 | if (version_compare($version,'2.4.0','<=')) |
---|
| 289 | { |
---|
| 290 | # setup media_exclusion |
---|
| 291 | $strReq = 'UPDATE '.$core->prefix.'setting '. |
---|
| 292 | "SET setting_value = '/\\.php\$/i' ". |
---|
| 293 | "WHERE setting_id = 'media_exclusion' ". |
---|
| 294 | "AND setting_value = '' "; |
---|
| 295 | $core->con->execute($strReq); |
---|
| 296 | } |
---|
[1082] | 297 | |
---|
[1083] | 298 | if (version_compare($version,'2.5','<=')) |
---|
[1082] | 299 | { |
---|
| 300 | # Try to disable daInstaller plugin if it has been installed outside the default plugins directory |
---|
| 301 | $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); |
---|
| 302 | $default = path::real(dirname(__FILE__).'/../../plugins/'); |
---|
| 303 | foreach ($path as $root) |
---|
| 304 | { |
---|
| 305 | if (!is_dir($root) || !is_readable($root)) { |
---|
| 306 | continue; |
---|
| 307 | } |
---|
| 308 | if (substr($root,-1) != '/') { |
---|
| 309 | $root .= '/'; |
---|
| 310 | } |
---|
| 311 | if (($p = @dir($root)) === false) { |
---|
| 312 | continue; |
---|
| 313 | } |
---|
| 314 | if(path::real($root) == $default) { |
---|
| 315 | continue; |
---|
| 316 | } |
---|
| 317 | if (($d = @dir($root.'daInstaller')) === false) { |
---|
| 318 | continue; |
---|
| 319 | } |
---|
| 320 | $f = $root.'/daInstaller/_disabled'; |
---|
| 321 | if (!file_exists($f)) |
---|
| 322 | { |
---|
| 323 | @file_put_contents($f,''); |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | } |
---|
[1205] | 327 | |
---|
[1581] | 328 | if (version_compare($version,'2.5.1','<=')) |
---|
[1205] | 329 | { |
---|
| 330 | // Flash enhanced upload no longer needed |
---|
| 331 | @unlink(DC_ROOT.'/'.'inc/swf/swfupload.swf'); |
---|
| 332 | } |
---|
[1581] | 333 | |
---|
| 334 | if (version_compare($version,'2.6','<=')) |
---|
| 335 | { |
---|
| 336 | // README has been replaced by README.md and CONTRIBUTING.md |
---|
| 337 | @unlink(DC_ROOT.'/'.'README'); |
---|
[1785] | 338 | |
---|
| 339 | // trackbacks are now merged into posts |
---|
| 340 | @unlink(DC_ROOT.'/'.'admin/trackbacks.php'); |
---|
[1581] | 341 | } |
---|
[291] | 342 | |
---|
[0] | 343 | $core->setVersion('core',DC_VERSION); |
---|
| 344 | $core->blogDefaults(); |
---|
| 345 | |
---|
| 346 | # Drop content from session table |
---|
| 347 | $core->con->execute('DELETE FROM '.$core->prefix.'session '); |
---|
| 348 | |
---|
| 349 | # Empty templates cache directory |
---|
| 350 | try { |
---|
| 351 | $core->emptyTemplatesCache(); |
---|
| 352 | } catch (Exception $e) {} |
---|
| 353 | |
---|
| 354 | return $changes; |
---|
| 355 | } |
---|
| 356 | catch (Exception $e) |
---|
| 357 | { |
---|
| 358 | throw new Exception(__('Something went wrong with auto upgrade:'). |
---|
| 359 | ' '.$e->getMessage()); |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | # No upgrade? |
---|
| 364 | return false; |
---|
| 365 | } |
---|
| 366 | ?> |
---|