[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

/textpattern/update/ -> _to_1.0.0.php (source)

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


Generated: Thu May 21 23:03:01 2009 Cross-referenced by PHPXref 0.7