Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/update/_to_1.0.0.php - 709 lines - 28969 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * http://textpattern.com
   6   *
   7   * Copyright (C) 2016 The Textpattern Development Team
   8   *
   9   * This file is part of Textpattern.
  10   *
  11   * Textpattern is free software; you can redistribute it and/or
  12   * modify it under the terms of the GNU General Public License
  13   * as published by the Free Software Foundation, version 2.
  14   *
  15   * Textpattern is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18   * GNU General Public License for more details.
  19   *
  20   * You should have received a copy of the GNU General Public License
  21   * along with Textpattern. If not, see <http://www.gnu.org/licenses/>.
  22   */
  23  
  24  if (!defined('TXP_UPDATE')) {
  25      exit("Nothing here. You can't access this file directly.");
  26  }
  27  
  28  safe_delete('txp_category', "name = ''");
  29  safe_delete('txp_category', "name = ' '");
  30  
  31  $txpcat = getThings("DESCRIBE `".PFX."txp_category`");
  32  
  33  if (!in_array('id', $txpcat)) {
  34      safe_alter('txp_category', "ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
  35  }
  36  
  37  if (!in_array('parent', $txpcat)) {
  38      safe_alter('txp_category', "ADD parent VARCHAR(64) NOT NULL DEFAULT ''");
  39  }
  40  
  41  if (!in_array('lft', $txpcat)) {
  42      safe_alter('txp_category', "ADD lft INT NOT NULL DEFAULT '0'");
  43  }
  44  
  45  if (!in_array('rgt', $txpcat)) {
  46      safe_alter('txp_category', "ADD rgt INT NOT NULL DEFAULT '0'");
  47  }
  48  
  49  if (in_array('level', $txpcat)) {
  50      safe_alter('txp_category', "DROP level");
  51  }
  52  
  53  $txp = getThings("DESCRIBE `".PFX."textpattern`");
  54  
  55  if (!in_array('Keywords', $txp)) {
  56      safe_alter('textpattern', "ADD Keywords VARCHAR(255) NOT NULL");
  57  }
  58  
  59  if (in_array('Listing1', $txp) && !in_array('textile_body', $txp)) {
  60      safe_alter('textpattern', "CHANGE Listing1 textile_body INT DEFAULT '1' NOT NULL");
  61  }
  62  
  63  if (in_array('Listing2', $txp) && !in_array('textile_excerpt', $txp)) {
  64      safe_alter('textpattern', "CHANGE Listing2 textile_excerpt INT DEFAULT '1' NOT NULL");
  65  }
  66  
  67  if (!in_array('url_title', $txp)) {
  68      safe_alter('textpattern', "ADD url_title VARCHAR(255) NOT NULL");
  69  }
  70  
  71  if (!in_array('Excerpt', $txp)) {
  72      safe_alter('textpattern', "ADD Excerpt MEDIUMTEXT NOT NULL AFTER Body_html");
  73  }
  74  
  75  // Excerpt_html added in 1.0.
  76  if (!in_array('Excerpt_html', $txp)) {
  77      safe_alter('textpattern', "ADD Excerpt_html MEDIUMTEXT NOT NULL AFTER Excerpt ");
  78  }
  79  
  80  // Comments count cache field.
  81  if (!in_array('comments_count', $txp)) {
  82      safe_alter('textpattern', "ADD comments_count INT NOT NULL AFTER AnnotateInvite ");
  83  }
  84  
  85  // Custom fields added for g1.19.
  86  if (!in_array('custom_1', $txp)) {
  87      safe_alter('textpattern', "ADD custom_1 VARCHAR(255) NOT NULL");
  88  }
  89  
  90  if (!in_array('custom_2', $txp)) {
  91      safe_alter('textpattern', "ADD custom_2 VARCHAR(255) NOT NULL");
  92  }
  93  
  94  if (!in_array('custom_3', $txp)) {
  95      safe_alter('textpattern', "ADD custom_3 VARCHAR(255) NOT NULL");
  96  }
  97  
  98  if (!in_array('custom_4', $txp)) {
  99      safe_alter('textpattern', "ADD custom_4 VARCHAR(255) NOT NULL");
 100  }
 101  
 102  if (!in_array('custom_5', $txp)) {
 103      safe_alter('textpattern', "ADD custom_5 VARCHAR(255) NOT NULL");
 104  }
 105  
 106  if (!in_array('custom_6', $txp)) {
 107      safe_alter('textpattern', "ADD custom_6 VARCHAR(255) NOT NULL");
 108  }
 109  
 110  if (!in_array('custom_7', $txp)) {
 111      safe_alter('textpattern', "ADD custom_7 VARCHAR(255) NOT NULL");
 112  }
 113  
 114  if (!in_array('custom_8', $txp)) {
 115      safe_alter('textpattern', "ADD custom_8 VARCHAR(255) NOT NULL");
 116  }
 117  
 118  if (!in_array('custom_9', $txp)) {
 119      safe_alter('textpattern', "ADD custom_9 VARCHAR(255) NOT NULL");
 120  }
 121  
 122  if (!in_array('custom_10', $txp)) {
 123      safe_alter('textpattern', "ADD custom_10 VARCHAR(255) NOT NULL");
 124  }
 125  
 126  $txpsect = getThings("DESCRIBE `".PFX."txp_section`");
 127  
 128  if (!in_array('searchable', $txpsect)) {
 129      safe_alter('txp_section', "ADD searchable INT NOT NULL DEFAULT 1");
 130  }
 131  
 132  $txpuser = getThings("DESCRIBE `".PFX."txp_users`");
 133  
 134  if (!in_array('nonce', $txpuser)) {
 135      safe_alter('txp_users', "ADD nonce VARCHAR(64) NOT NULL");
 136  };
 137  
 138  // 1.0rc: checking nonce in txp_users table.
 139  $txpusers = safe_rows_start("name, nonce", 'txp_users', "1 = 1");
 140  
 141  if ($txpusers) {
 142      while ($a = nextRow($txpusers)) {
 143          extract($a);
 144          if (!$nonce) {
 145              $nonce = md5(uniqid(rand(), true));
 146              safe_update('txp_users', "nonce = '$nonce'", "name = '".doSlash($name)."'");
 147          }
 148      }
 149  }
 150  
 151  // 1.0rc: expanding password field in txp_users.
 152  safe_alter('txp_users',   "MODIFY pass VARCHAR(128) NOT NULL");
 153  
 154  safe_alter('textpattern', "MODIFY Body      MEDIUMTEXT NOT NULL");
 155  safe_alter('textpattern', "MODIFY Body_html MEDIUMTEXT NOT NULL");
 156  safe_alter('textpattern', "MODIFY Excerpt   TEXT       NOT NULL");
 157  
 158  $popcom = fetch("*", 'txp_form', 'name', "popup_comments");
 159  
 160  if (!$popcom) {
 161      $popform = <<<eod
 162  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 163  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 164  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 165  <head>
 166  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
 167  <link rel="Stylesheet" href="<txp:css />" type="text/css" />
 168  <title><txp:page_title /></title>
 169  </head>
 170  <body>
 171  <div style="text-align: left; padding: 1em; width:300px">
 172  
 173  <txp:popup_comments />
 174  
 175  </div>
 176  </body>
 177  </html>
 178  eod;
 179      $popform = addslashes($popform);
 180      safe_insert('txp_form', "name = 'popup_comments', type = 'comment', Form = '$popform'");
 181  }
 182  
 183  safe_update('txp_category', "lft = 0, rgt = 0", "name != 'root'");
 184  
 185  safe_delete('txp_category', "name = 'root'");
 186  
 187  safe_update('txp_category', "parent = 'root'", "parent = ''");
 188  
 189  safe_insert('txp_category', "name = 'root', parent = '', type = 'article', lft = 1, rgt = 0");
 190  rebuild_tree('root', 1, 'article');
 191  
 192  safe_insert('txp_category', "name = 'root', parent = '', type = 'link', lft = 1, rgt = 0");
 193  rebuild_tree('root', 1, 'link');
 194  
 195  safe_insert('txp_category', "name = 'root', parent = '', type = 'image', lft = 1, rgt = 0");
 196  rebuild_tree('root', 1, 'image');
 197  
 198  if (safe_field("val", 'txp_prefs', "name = 'article_list_pageby'") === false) {
 199      safe_insert('txp_prefs', "prefs_id = 1, name = 'article_list_pageby', val = 25");
 200  }
 201  
 202  if (safe_field("val", 'txp_prefs', "name = 'link_list_pageby'") === false) {
 203      safe_insert('txp_prefs', "prefs_id = 1, name = 'link_list_pageby', val = 25");
 204  }
 205  
 206  if (safe_field("val", 'txp_prefs', "name = 'image_list_pageby'") === false) {
 207      safe_insert('txp_prefs', "prefs_id = 1, name = 'image_list_pageby', val = 25");
 208  }
 209  
 210  if (safe_field("val", 'txp_prefs', "name = 'log_list_pageby'") === false) {
 211      safe_insert('txp_prefs', "prefs_id = 1, name = 'log_list_pageby', val = 25");
 212  }
 213  
 214  if (safe_field("val", 'txp_prefs', "name = 'comment_list_pageby'") === false) {
 215      safe_insert('txp_prefs', "prefs_id = 1, name = 'comment_list_pageby', val = 25");
 216  }
 217  
 218  if (safe_field("val", 'txp_prefs', "name = 'permlink_mode'") === false) {
 219      safe_insert('txp_prefs', "prefs_id = 1, name = 'permlink_mode', val = 'section_id_title'");
 220  }
 221  
 222  if (safe_field("val", 'txp_prefs', "name = 'comments_are_ol'") === false) {
 223      safe_insert('txp_prefs', "prefs_id = 1, name = 'comments_are_ol', val = '1'");
 224  }
 225  
 226  if (safe_field("name", 'txp_prefs', "name = 'path_to_site'") === false) {
 227      safe_insert('txp_prefs', "prefs_id = 1, name = 'path_to_site', val = ''");
 228  }
 229  
 230  // 1.0: need to get non-manually set url-only titles into the textpattern table,
 231  // so we can start using title as an url search option.
 232  
 233  $rs = mysqli_query($DB->link, "SELECT ID, Title FROM `".PFX."textpattern` WHERE url_title LIKE ''");
 234  
 235  while ($a = mysqli_fetch_array($rs)) {
 236      extract($a);
 237      $url_title = addslashes(stripSpace($Title, 1));
 238      assert_int($ID);
 239      safe_update('textpattern', "url_title = '$url_title'", "ID = $ID");
 240  }
 241  
 242  // 1.0: properly i18n.
 243  // Change current language names by language codes.
 244  $lang = fetch("val", 'txp_prefs', 'name', 'language');
 245  
 246  switch ($lang) {
 247      case 'czech':
 248          $rs = safe_update('txp_prefs', "val = 'cs-cs'", "name = 'language' AND val = 'czech'");
 249      break;
 250      case 'danish':
 251          $rs = safe_update('txp_prefs', "val = 'da-da'", "name = 'language' AND val = 'danish'");
 252      break;
 253      case 'dutch':
 254          $rs = safe_update('txp_prefs', "val = 'nl-nl'", "name = 'language' AND val = 'dutch'");
 255      break;
 256      case 'finish':
 257          $rs = safe_update('txp_prefs', "val = 'fi-fi'", "name = 'language' AND val = 'finish'");
 258      break;
 259      case 'french':
 260          $rs = safe_update('txp_prefs', "val = 'fr-fr'", "name = 'language' AND val = 'french'");
 261      break;
 262      case 'german':
 263          $rs = safe_update('txp_prefs', "val = 'de-de'", "name = 'language' AND val = 'german'");
 264      break;
 265      case 'italian':
 266          $rs = safe_update('txp_prefs', "val = 'it-it'", "name = 'language' AND val = 'italian'");
 267      break;
 268      case 'polish':
 269          $rs = safe_update('txp_prefs', "val = 'pl-pl'", "name = 'language' AND val = 'polish'");
 270      break;
 271      case 'portuguese':
 272          $rs = safe_update('txp_prefs', "val = 'pt-pt'", "name = 'language' AND val = 'portuguese'");
 273      break;
 274      case 'russian':
 275          $rs = safe_update('txp_prefs', "val = 'ru-ru'", "name = 'language' AND val = 'russian'");
 276      break;
 277      case 'scotts':
 278          //I'm not sure of this one
 279          $rs = safe_update('txp_prefs', "val = 'gl-gl'", "name = 'language' AND val = 'scotts'");
 280      break;
 281      case 'spanish':
 282          $rs = safe_update('txp_prefs', "val = 'es-es'", "name = 'language' AND val = 'spanish'");
 283      break;
 284      case 'swedish':
 285          $rs = safe_update('txp_prefs', "val = 'sv-sv'", "name = 'language' AND val = 'swedish'");
 286      break;
 287      case 'tagalog':
 288          $rs = safe_update('txp_prefs', "val = 'tl-tl'", "name = 'language' AND val = 'tagalog'");
 289      break;
 290      case 'english':
 291      default:
 292          $rs = safe_update('txp_prefs', "val = 'en-gb'", "name = 'language' AND val = 'english'");
 293      break;
 294  }
 295  
 296  // 1.0: new time zone offset.
 297  // If we check for a val, and the val is 0, this add another empty one.
 298  if (safe_field("name", 'txp_prefs', "name = 'is_dst'") === false) {
 299      safe_insert('txp_prefs', "prefs_id = 1, name = 'is_dst', val = 0");
 300  }
 301  
 302  // FIXME: this presupposes 'gmtoffset' won't be set at clean install (RC4+ probably will)
 303  if (safe_field("val", 'txp_prefs', "name = 'gmtoffset'") === false) {
 304      $old_offset = safe_field("val", 'txp_prefs', "name = 'timeoffset'");
 305      $serveroffset = gmmktime(0, 0, 0) - mktime(0, 0, 0);
 306      $gmtoffset = sprintf("%+d", $serveroffset + $old_offset);
 307      safe_insert('txp_prefs', "prefs_id = 1, name = 'gmtoffset', val = '".doSlash($gmtoffset)."'");
 308  }
 309  
 310  $tempdir = doSlash(find_temp_dir());
 311  
 312  // 1.0: locale support.
 313  if (safe_field("val", 'txp_prefs', "name = 'locale'") === false) {
 314      safe_insert('txp_prefs', "prefs_id = 1, name = 'locale', val = 'en_GB'");
 315  }
 316  
 317  // 1.0: temp dir.
 318  if (safe_field("val", 'txp_prefs', "name = 'tempdir'") === false) {
 319      safe_insert('txp_prefs', "prefs_id = 1, name = 'tempdir', val = '$tempdir'");
 320  }
 321  
 322  // Non image file upload tab.
 323  if (safe_field("val", 'txp_prefs', "name = 'file_list_pageby'") === false) {
 324      safe_insert('txp_prefs', "val = 25, name = 'file_list_pageby', prefs_id = 1");
 325  }
 326  
 327  // 1.0: max file upload size.
 328  if (safe_field("val", 'txp_prefs', "name = 'file_max_upload_size'") === false) {
 329      safe_insert('txp_prefs', "prefs_id = 1, name = 'file_max_upload_size', val = 2000000");
 330  }
 331  
 332  // 1.0: txp_file root cat.
 333  if (!safe_field("name", 'txp_category', "type = 'file' AND name = 'root'")) {
 334      safe_insert('txp_category', "name = 'root', type = 'file', lft = 1, rgt = 0");
 335  }
 336  rebuild_tree('root', 1, 'file');
 337  
 338  // 1.0: txp_file folder.
 339  if (safe_field("val", 'txp_prefs', "name = 'file_base_path'") === false) {
 340      safe_insert('txp_prefs', "val = '$tempdir', name = 'file_base_path', prefs_id = 1");
 341  }
 342  
 343  // 1.0: txp_file table.
 344  safe_create('txp_file', "
 345      id          INT          NOT NULL AUTO_INCREMENT,
 346      filename    VARCHAR(255) NOT NULL DEFAULT '',
 347      category    VARCHAR(255) NOT NULL DEFAULT '',
 348      permissions VARCHAR(32)  NOT NULL DEFAULT '0',
 349      description TEXT         NOT NULL,
 350      downloads   INT UNSIGNED NOT NULL DEFAULT '0',
 351      PRIMARY KEY     (id),
 352      UNIQUE filename (filename)"
 353  );
 354  
 355  if (safe_field("name", 'txp_form', "type = 'file'") === false) {
 356      safe_insert('txp_form', "
 357          name = 'files',
 358          type = 'file',
 359          Form = '<txp:text item=\"file\" />: \n<txp:file_download_link>\n<txp:file_download_name /> [<txp:file_download_size format=\"auto\" decimals=\"2\" />]\n</txp:file_download_link>\n<br />\n<txp:text item=\"category\" />: <txp:file_download_category /><br />\n<txp:text item=\"download\" />: <txp:file_download_downloads />'");
 360  }
 361  // EOF: non image file upload tab.
 362  
 363  // 1.0: improved comment spam nonce.
 364  $txpnonce = getThings("DESCRIBE `".PFX."txp_discuss_nonce`");
 365  if (!in_array('secret', $txpnonce)) {
 366      safe_alter('txp_discuss_nonce', "ADD secret VARCHAR(255) NOT NULL DEFAULT ''");
 367  }
 368  
 369  // 1.0: flag for admin-side plugins.
 370  $txpplugin = getThings("DESCRIBE `".PFX."txp_plugin`");
 371  if (!in_array('type', $txpplugin)) {
 372      safe_alter('txp_plugin', "ADD type INT NOT NULL DEFAULT '0'");
 373  }
 374  
 375  // 1.0: log status and method.
 376  $txplog = getThings("DESCRIBE `".PFX."txp_log`");
 377  
 378  if (!in_array('status', $txplog)) {
 379      safe_alter('txp_log', "ADD status INT NOT NULL DEFAULT '200'");
 380  }
 381  
 382  if (!in_array('method', $txplog)) {
 383      safe_alter('txp_log', "ADD method VARCHAR(16) NOT NULL DEFAULT 'GET'");
 384  }
 385  
 386  if (!in_array('ip', $txplog)) {
 387      safe_alter('txp_log', "ADD ip VARCHAR(16) NOT NULL DEFAULT ''");
 388  }
 389  
 390  // 1.0: need to get Excerpt_html values into the textpattern table, so catch
 391  // empty ones and populate them.
 392  $rs = mysqli_query($DB->link, "SELECT ID, Excerpt, textile_excerpt FROM `".PFX."textpattern` WHERE Excerpt_html LIKE ''");
 393  $textile = new \Netcarver\Textile\Parser();
 394  
 395  while ($a = @mysqli_fetch_assoc($rs)) {
 396      extract($a);
 397      assert_int($ID);
 398      $lite = ($textile_excerpt) ? '' : 1;
 399      $Excerpt_html = $textile->textileThis($Excerpt, $lite);
 400      safe_update('textpattern', "Excerpt_html = '".doSlash($Excerpt_html)."'", "ID = $ID");
 401  }
 402  
 403  // 1.0 feed unique ids.
 404  
 405  // Blog unique id.
 406  if (safe_field("val", 'txp_prefs', "name = 'blog_uid'") === false) {
 407      $prefs['blog_uid'] = md5(uniqid(rand(), true));
 408      safe_insert('txp_prefs', "name = 'blog_uid', val = '".$prefs['blog_uid']."', prefs_id = '1'");
 409  }
 410  
 411  if (safe_field("name", 'txp_prefs', "name = 'blog_mail_uid'") === false) {
 412      $mail = safe_field('email', 'txp_users', "privs = '1' LIMIT 1");
 413      safe_insert('txp_prefs', "name = 'blog_mail_uid', val = '".doSlash($mail)."', prefs_id = '1'");
 414  }
 415  
 416  if (safe_field("val", 'txp_prefs', "name = 'blog_time_uid'") === false) {
 417      safe_insert('txp_prefs', "name = 'blog_time_uid', val = '".date("Y")."', prefs_id = '1'");
 418  }
 419  
 420  // Articles unique id.
 421  if (!in_array('uid', $txp)) {
 422      safe_alter('textpattern', "ADD uid VARCHAR(32) NOT NULL");
 423      safe_alter('textpattern', "ADD feed_time DATE NOT NULL DEFAULT 1970-01-01");
 424      safe_update('textpattern', "feed_time = DATE(Posted)", "feed_time = '1970-01-01'");
 425      safe_alter('textpattern', "MODIFY feed_time DATE NOT NULL");
 426  
 427      $rs = safe_rows_start('ID, Posted', 'textpattern', '1');
 428  
 429      if ($rs) {
 430          while ($a = nextRow($rs)) {
 431              assert_int($a['ID']);
 432              $feed_time = substr($a['Posted'], 0, 10);
 433              safe_update('textpattern', "uid = '".md5(uniqid(rand(), true))."', feed_time = '".doSlash($feed_time)."'", "ID = {$a['ID']}");
 434          }
 435      }
 436  }
 437  
 438  // 1.0: populate comments_count field.
 439  
 440  $rs = safe_rows_start("parentid, count(*) AS thecount", 'txp_discuss', "visible = 1 GROUP BY parentid");
 441  
 442  if ($rs) {
 443      while ($a = nextRow($rs)) {
 444          assert_int($a['parentid']);
 445          safe_update('textpattern', "comments_count = ".$a['thecount'], "ID = ".$a['parentid']);
 446      }
 447  }
 448  
 449  // 1.0: Human-friendly title for sections and categories, to solve i18n problems.
 450  if (!in_array('title', $txpsect)) {
 451      safe_alter('txp_section', "ADD title VARCHAR(255) NOT NULL DEFAULT ''");
 452  }
 453  
 454  if (!in_array('title', $txpcat)) {
 455      safe_alter('txp_category', "ADD title VARCHAR(255) NOT NULL DEFAULT ''");
 456  }
 457  
 458  if (safe_count('txp_section', "title = ''") > 0) {
 459      safe_update('txp_section', "title = name", "title = ''");
 460  }
 461  
 462  if (safe_count('txp_category', "title = ''") > 0) {
 463      safe_update('txp_category', "title = name", "title = ''");
 464  }
 465  
 466  // 1.0: Unique key and 'type' field for the txp_prefs table.
 467  safe_create_index('txp_prefs', 'prefs_id, name', 'prefs_idx', 'unique');
 468  
 469  $txpprefs = getThings('DESCRIBE `'.PFX.'txp_prefs`');
 470  
 471  if (!in_array('type', $txpprefs)) {
 472      safe_alter('txp_prefs', "ADD type SMALLINT UNSIGNED NOT NULL DEFAULT '2'");
 473  }
 474  
 475  // Update the updated with default hidden type for old plugins prefs.
 476  safe_alter('txp_prefs', "MODIFY type SMALLINT UNSIGNED NOT NULL DEFAULT '2'");
 477  
 478  if (!in_array('event', $txpprefs)) {
 479      safe_alter('txp_prefs', "ADD event VARCHAR(12) NOT NULL DEFAULT 'publish'");
 480  }
 481  
 482  if (!in_array('html', $txpprefs)) {
 483      safe_alter('txp_prefs', "ADD html VARCHAR(64) NOT NULL DEFAULT ''");
 484  }
 485  
 486  if (!in_array('position', $txpprefs)) {
 487      safe_alter('txp_prefs', "ADD position SMALLINT UNSIGNED NOT NULL DEFAULT '0'");
 488  
 489      // Add new column values to prefs.
 490      $prefs_new_cols = array(
 491          'attach_titles_to_permalinks' => array('html' => 'yesnoradio',       'event' => 'publish',  'type' => '1', 'position' => '1'),
 492          'sitename'                    => array('html' => 'text_input',       'event' => 'publish',  'type' => '0', 'position' => '1'),
 493          'siteurl'                     => array('html' => 'text_input',       'event' => 'publish',  'type' => '0', 'position' => '2'),
 494          'site_slogan'                 => array('html' => 'text_input',       'event' => 'publish',  'type' => '0', 'position' => '3'),
 495          'language'                    => array('html' => 'languages',        'event' => 'publish',  'type' => '0', 'position' => '4'),
 496          'gmtoffset'                   => array('html' => 'gmtoffset_select', 'event' => 'publish',  'type' => '0', 'position' => '5'),
 497          'is_dst'                      => array('html' => 'yesnoradio',       'event' => 'publish',  'type' => '0', 'position' => '6'),
 498          'dateformat'                  => array('html' => 'dateformats',      'event' => 'publish',  'type' => '0', 'position' => '7'),
 499          'archive_dateformat'          => array('html' => 'dateformats',      'event' => 'publish',  'type' => '0', 'position' => '8'),
 500          'permlink_mode'               => array('html' => 'permlinkmodes',    'event' => 'publish',  'type' => '0', 'position' => '9'),
 501          'send_lastmod'                => array('html' => 'yesnoradio',       'event' => 'admin',    'type' => '1', 'position' => '0'),
 502          'ping_weblogsdotcom'          => array('html' => 'yesnoradio',       'event' => 'publish',  'type' => '1', 'position' => '0'),
 503          'use_comments'                => array('html' => 'yesnoradio',       'event' => 'publish',  'type' => '0', 'position' => '12'),
 504          'logging'                     => array('html' => 'logging',          'event' => 'publish',  'type' => '0', 'position' => '10'),
 505          'use_textile'                 => array('html' => 'pref_text',        'event' => 'publish',  'type' => '0', 'position' => '11'),
 506          'tempdir'                     => array('html' => 'text_input',       'event' => 'admin',    'type' => '1', 'position' => '0'),
 507          'file_base_path'              => array('html' => 'text_input',       'event' => 'admin',    'type' => '1', 'position' => '0'),
 508          'file_max_upload_size'        => array('html' => 'text_input',       'event' => 'admin',    'type' => '1', 'position' => '0'),
 509          'comments_moderate'           => array('html' => 'yesnoradio',       'event' => 'comments', 'type' => '0', 'position' => '13'),
 510          'comments_on_default'         => array('html' => 'yesnoradio',       'event' => 'comments', 'type' => '0', 'position' => '14'),
 511          'comments_are_ol'             => array('html' => 'yesnoradio',       'event' => 'comments', 'type' => '0', 'position' => '15'),
 512          'comments_sendmail'           => array('html' => 'yesnoradio',       'event' => 'comments', 'type' => '0', 'position' => '16'),
 513          'comments_disallow_images'    => array('html' => 'yesnoradio',       'event' => 'comments', 'type' => '0', 'position' => '17'),
 514          'comments_default_invite'     => array('html' => 'text_input',       'event' => 'comments', 'type' => '0', 'position' => '18'),
 515          'comments_dateformat'         => array('html' => 'dateformats',      'event' => 'comments', 'type' => '0', 'position' => '19'),
 516          'comments_mode'               => array('html' => 'commentmode',      'event' => 'comments', 'type' => '0', 'position' => '20'),
 517          'comments_disabled_after'     => array('html' => 'weeks',            'event' => 'comments', 'type' => '0', 'position' => '21'),
 518          'img_dir'                     => array('html' => 'text_input',       'event' => 'admin',    'type' => '1', 'position' => '0'),
 519          'rss_how_many'                => array('html' => 'text_input',       'event' => 'admin',    'type' => '1', 'position' => '0'),
 520      );
 521  
 522      foreach ($prefs_new_cols as $pref_key => $pref_val) {
 523          safe_update('txp_prefs', "html = '$pref_val[html]', event = '$pref_val[event]', type = '$pref_val[type]', position = '$pref_val[position]'", "name = '$pref_key' AND prefs_id = '1'");
 524      }
 525  
 526      $prefs_hidden_rows = array('prefs_id', 'use_categories', 'use_sections', 'path_from_root', 'url_mode', 'record_mentions',
 527          'locale', 'file_base_path', 'lastmod', 'version', 'path_to_site', 'dbupdatetime', 'timeoffset', 'article_list_pageby',
 528          'blog_mail_uid', 'blog_time_uid', 'blog_uid', 'comment_list_pageby', 'file_list_pageby', 'image_list_pageby', 'link_list_pageby',
 529          'log_list_pageby',);
 530  
 531      foreach ($prefs_hidden_rows as $hidden_pref) {
 532          safe_update('txp_prefs', "type = '2'", "name = '$hidden_pref' AND prefs_id = '1'");
 533      }
 534  
 535      global $txpac;
 536  
 537      // Advanced prefs.
 538      foreach ($txpac as $key => $val) {
 539          if (!in_array($key, array_keys($prefs))) {
 540              switch ($key) {
 541                  case 'custom_1_set':
 542                  case 'custom_2_set':
 543                  case 'custom_3_set':
 544                  case 'custom_4_set':
 545                  case 'custom_5_set':
 546                  case 'custom_6_set':
 547                  case 'custom_7_set':
 548                  case 'custom_8_set':
 549                  case 'custom_9_set':
 550                  case 'custom_10_set':
 551                      $evt = 'custom';
 552                      $html = 'text_input';
 553                  break;
 554  
 555                  case 'edit_raw_css_by_default':
 556                      $evt = 'css';
 557                      $html = 'yesnoradio';
 558                  break;
 559                  case 'spam_blacklists':
 560                  case 'expire_logs_after':
 561                  case 'max_url_len':
 562                      $html = 'text_input';
 563                      $evt = 'publish';
 564                  break;
 565                  case 'textile_links':
 566                      $html = 'yesnoradio';
 567                      $evt = 'link';
 568                  break;
 569                  case 'show_article_category_count':
 570                      $html = 'yesnoradio';
 571                      $evt = 'category';
 572                  break;
 573                  case 'comments_require_name':
 574                  case 'comments_require_email':
 575                      $html = 'yesnoradio';
 576                      $evt = 'comments';
 577                  break;
 578                  default:
 579                      $html = 'yesnoradio';
 580                      $evt = 'publish';
 581                  break;
 582              }
 583              safe_insert('txp_prefs', "val = '$val', name = '$key' , prefs_id = '1', type = '1', html = '$html', event = '$evt'");
 584          }
 585      }
 586  }
 587  
 588  safe_alter('txp_prefs', "MODIFY html VARCHAR(64) DEFAULT 'text_input' NOT NULL");
 589  safe_update('txp_prefs', "html = 'text_input'", "html = ''");
 590  
 591  if (!fetch("form", 'txp_form', 'name', 'search_results')) {
 592      $form = <<<EOF
 593  <h3><txp:permlink><txp:title /></txp:permlink></h3>
 594  <p><txp:search_result_excerpt /><br/>
 595  <small><txp:permlink><txp:permlink /></txp:permlink> &middot;
 596  <txp:posted /></small></p>
 597  EOF;
 598      safe_insert('txp_form', "name = 'search_results', type = 'article', Form = '".doSlash($form)."'");
 599  }
 600  
 601  if (!safe_query("SELECT 1 FROM `".PFX."txp_lang` LIMIT 0")) {
 602      // Do install.
 603      safe_query("CREATE TABLE `".PFX."txp_lang` (
 604          id      INT         NOT NULL AUTO_INCREMENT,
 605          lang    VARCHAR(16) NOT NULL,
 606          name    VARCHAR(64) NOT NULL,
 607          event   VARCHAR(64) NOT NULL,
 608          data    TINYTEXT,
 609          lastmod TIMESTAMP,
 610          PRIMARY KEY   (id),
 611          UNIQUE lang   (lang, name),
 612          INDEX  lang_2 (lang, event)
 613      ) $tabletype ");
 614  
 615      require_once txpath.'/lib/IXRClass.php';
 616  
 617      $client = new IXR_Client('http://rpc.textpattern.com');
 618  
 619      if (!$client->query('tups.getLanguage', $prefs['blog_uid'], LANG)) {
 620          echo '<p style="color:red">Error trying to install language. Please, try it again again.<br />
 621          If problem connecting to the RPC server persists, you can go to <a href="http://rpc.textpattern.com/lang/">http://rpc.textpattern.com/lang/</a>, download the
 622          desired language file and place it in the /lang/ directory of your textpattern install. You can then install the language from file.</p>';
 623      } else {
 624          $response = $client->getResponse();
 625          $lang_struct = unserialize($response);
 626  
 627          function install_lang_key($value, $key)
 628          {
 629              $q = "name = '".doSlash($value[name])."', event = '".doSlash($value[event])."', data = '".doSlash($value[data])."', lastmod = '".doSlash(strftime('%Y%m%d%H%M%S', $value['uLastmod']))."'";
 630              safe_insert('txp_lang', $q.", lang = '".LANG."'");
 631          }
 632  
 633          array_walk($lang_struct, 'install_lang_key');
 634      }
 635  }
 636  
 637  $maxpos = safe_field("MAX(position)", 'txp_prefs', "1 = 1");
 638  
 639  // 1.0: production_status setting to control error reporting.
 640  if (safe_field("val", 'txp_prefs', "name = 'production_status'") === false) {
 641      safe_insert('txp_prefs', "name = 'production_status', val = 'testing', prefs_id = '1', type = '0', position = '".doSlash($maxpos)."', html = 'prod_levels'");
 642  }
 643  
 644  // Multiply position on prefs to allow easy reordering.
 645  if (intval($maxpos) < 100) {
 646      safe_update('txp_prefs', "position = position * 10", "1 = 1");
 647  }
 648  
 649  // Remove, remove.
 650  if (safe_field("name", 'txp_prefs', "name = 'logs_expire'") !== false) {
 651      safe_delete('txp_prefs', "name = 'logs_expire'");
 652  }
 653  
 654  // Let's make this visible in advanced prefs.
 655  safe_update('txp_prefs', "type = '1'", "name = 'file_base_path'");
 656  
 657  // 1.0: add option to override charset for emails (ISO-8559-1 instead of UTF-8).
 658  if (safe_field("name", 'txp_prefs', "name = 'override_emailcharset'") === false) {
 659      safe_insert('txp_prefs', "name = 'override_emailcharset', val = '0', prefs_id = '1', type = '1', event = 'admin', position = '".doSlash($maxpos)."', html = 'yesnoradio'");
 660  }
 661  
 662  if (safe_field("val", 'txp_prefs', "name = 'comments_auto_append'") === false) {
 663      safe_insert('txp_prefs', "val = '1', name = 'comments_auto_append' , prefs_id = '1', type = '0', html = 'yesnoradio', event = 'comments', position = '211'");
 664  
 665      if (safe_field("name", 'txp_form', "name = 'comments_display'") === false) {
 666          $form = <<<EOF
 667  <txp:comments />
 668  <txp:if_comments_allowed>
 669  <txp:comments_form />
 670  </txp:if_comments_allowed>
 671  EOF;
 672          safe_insert('txp_form', "name = 'comments_display', type = 'article', Form = '".doSlash($form)."'");
 673      }
 674  }
 675  
 676  // /tmp is bad for permanent storage of files, if no files are uploaded yet,
 677  // switch to the files directory in the top-txp dir.
 678  if (!safe_count('txp_file', "1")) {
 679      $tempdir = find_temp_dir();
 680  
 681      if ($tempdir === safe_field("val", 'txp_prefs', "name = 'file_base_path'")) {
 682          safe_update('txp_prefs', "val = '".doSlash(dirname(txpath).DS.'files')."', prefs_id = 1", "name = 'file_base_path'");
 683      }
 684  }
 685  
 686  // After this point the changes after RC4.
 687  
 688  // Let's get the advanced fields in the right order.
 689  for ($i = 1; $i <= 10; $i++) {
 690      safe_update('txp_prefs', "position = $i", "name = 'custom_$i}_set'");
 691  }
 692  
 693  // Index ip column in txp_log.
 694  safe_create_index('txp_log', 'ip', 'ip');
 695  
 696  // Language selection moves to Manage languages, Hide it from prefs.
 697  safe_update('txp_prefs', "type = 2", "name = 'language'");
 698  
 699  // Show gmt-selection in prefs.
 700  safe_update('txp_prefs', "type = 0, html = 'gmtoffset_select', position = 50", "name = 'gmtoffset'");
 701  
 702  if (safe_field("name", 'txp_prefs', "prefs_id = 1 AND name = 'plugin_cache_dir'") === false) {
 703      $maxpos = safe_field("MAX(position)", 'txp_prefs', "1 = 1");
 704      safe_insert('txp_prefs', "name = 'plugin_cache_dir', val = '', prefs_id = '1', type = '1', event = 'admin', position = '".doSlash($maxpos)."', html = 'text_input'");
 705  }
 706  
 707  // Update version.
 708  safe_delete('txp_prefs', "name = 'version'");
 709  safe_insert('txp_prefs', "prefs_id = 1, name = 'version', val = '4.0', type = '2'");

title

Description

title

Description

title

Description

title

title

Body