OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / upgrades / upgrade4.0.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2012 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  */
12 /**
13  * @license http://nucleuscms.org/license.txt GNU General Public License
14  * @copyright Copyright (C) 2002-2012 The Nucleus Group
15  * @version $Id$
16  */
17
18 function upgrade_do400()
19 {
20         if ( upgrade_checkinstall(400) )
21         {
22                 return "already installed";
23         }
24         
25         // Give user warning if they are running old version of PHP
26         if ( phpversion() < '5' )
27         {
28 <<<<<<< HEAD
29                 $res = DB::getResult("SELECT * FROM " . sql_table('config') . " WHERE name='Language'");
30                 foreach ( $res as $row )
31                 {
32                         $locale = $row['Language'];
33 =======
34                 echo 'WARNING: You are running NucleusCMS on a older version of PHP that is no longer supported by NucleusCMS. Please upgrade to PHP5!';
35         }
36         
37         /* config table */
38         /* change Language setting to Locale */
39         if ( upgrade_checkIfCVExists('Language') )
40         {
41                 $res = sql_query("SELECT value FROM " . sql_table('config') . " WHERE name='Language'");
42                 if ( $res !== FALSE )
43                 {
44                         $row = sql_fetch_assoc($res);
45                         $locale = i18n_upg::convert_old_language_file_name_to_locale($row['value']);
46                         if ( $locale )
47                         {
48                                 $query = 'INSERT INTO ' . sql_table('config') . " VALUES ('Locale','{$locale}')";
49                                 upgrade_query('Creating Locale config value', $query);
50                                 
51                                 $query = 'DELETE FROM ' . sql_table('config') . " WHERE name='Language'";
52                                 upgrade_query("Removing Language config value", $query);
53                         }
54 >>>>>>> skinnable-master
55                 }
56         }
57         
58         /* change AdminCSS setting */
59         if ( upgrade_checkIfCVExists('AdminCSS') )
60         {
61                 $query = 'UPDATE ' . sql_table('config') . " SET value='original' WHERE name='AdminCSS'";
62                 upgrade_query('Changing AdminCSS config value', $query);
63         }
64         
65         /* create AdminSkin setting */
66         if ( !upgrade_checkIfCVExists('AdminSkin') )
67         {
68                 $query = 'INSERT INTO ' . sql_table('config') . " VALUES ('AdminSkin','0')";
69                 upgrade_query('Creating AdminSkin config value', $query);
70         }
71         
72         /* create BookmarkletSkin setting */
73         if ( !upgrade_checkIfCVExists('BookmarkletSkin') )
74         {
75                 $query = 'INSERT INTO ' . sql_table('config') . " VALUES ('BookmarkletSkin','0')";
76                 upgrade_query('Creating BookmarkletSkin config value', $query);
77         }
78         
79         
80         /* member table */
81         /* changing the member table to rename deflang to mlocale */
82         if ( !upgrade_checkIfColumnExists('member','mlocale') )
83         {
84                 $query =  'ALTER TABLE '.sql_table('member') . " CHANGE deflang mlocale varchar(20) NOT NULL default '' AFTER mcookiekey";
85                 upgrade_query("Renaming deflang column for members to mlocale", $query);
86         }
87         
88         /* changing the member table to add madminskin column */
89         if ( !upgrade_checkIfColumnExists('member','madminskin') )
90         {
91                 $query =  'ALTER TABLE '.sql_table('member') . " ADD madminskin tinyint(2) NOT NULL default '0'";
92                 upgrade_query("Adding a new row for the adminskin member option", $query);
93         }
94         
95         /* changing the member table to add mbkmklt column */
96                 if ( !upgrade_checkIfColumnExists('member','mbkmklt') )
97         {
98                 $query =  'ALTER TABLE '.sql_table('member') . " ADD mbkmklt tinyint(2) NOT NULL default '0'";
99                 upgrade_query("Adding a new row for the bkmklt member option", $query);
100         }
101         
102         // all member default value set
103         $result = sql_query("SELECT * FROM " . sql_table('member'));
104         while ( $row = mysql_fetch_assoc($result) )
105         {
106                 $locale = i18n_upg::convert_old_language_file_name_to_locale($row['mlocale']);
107                 if ( $locale )
108                 {
109                         $query = 'UPDATE $s SET mlocale=$s WHERE mnumber=$d';
110                         $query = sprintf($query, sql_table('member'), addslashes($locale), $row['mnumber']);
111                         upgrade_query('Changing mlocale value', $query);
112                 }
113         }
114         
115         // 3.6 -> 4.0
116         // update database version
117         update_version('400');
118         
119 }
120
121 class i18n_upg
122 {
123         /**
124         * i18n::convert_old_language_file_name_to_locale()
125         * NOTE: this should be obsoleted near future.
126         *
127         * @static
128         * @param        string  $target_language        old translation file name
129         * @return       string  locale name as language_script_region
130         */
131         static public function convert_old_language_file_name_to_locale($target_language)
132         {
133                 $target_locale = '';
134                 foreach ( self::$lang_refs as $language => $locale )
135                 {
136                         if ( $target_language == $language )
137                         {
138                                 if ( preg_match('#^(.+)\.(.+)$#', $locale, $match) )
139                                 {
140                                         $target_locale = $match[1];
141                                 }
142                                 else
143                                 {
144                                         $target_locale = $locale;
145                                 }
146                                 break;
147                         }
148                 }
149                 return $target_locale;
150         }
151         
152         /**
153          * i18n::$lang_refs
154          * reference table to convert old and new way to name translation files.
155          * NOTE: this should be obsoleted as soon as possible.
156          *
157          * @static
158          */
159         static private $lang_refs = array(
160                         "english"               => "en_Latn_US",
161                         "english-utf8"  => "en_Latn_US.UTF-8",
162                         "bulgarian"     => "bg_Cyrl_BG",
163                         "finnish"               => "fi_Latn_FI",
164                         "catalan"               => "ca_Latn_ES",
165                         "french"                => "fr_Latn_FR",
166                         "russian"               => "ru_Cyrl_RU",
167                         "chinese"               => "zh_Hans_CN",
168                         "simchinese"    => "zh_Hans_CN",
169                         "chineseb5"     => "zh_Hant_TW",
170                         "traditional_chinese"   =>      "zh_Hant_TW",
171                         "galego"                => "gl_Latn_ES",
172                         "german"                => "de_Latn_DE",
173                         "korean-utf"    => "ko_Kore_KR.UTF-8",
174                         "korean-euc-kr" => "ko_Kore_KR.EUC-KR",
175                         "slovak"                => "sk_Latn_SK",
176                         "czech"         => "cs_Latn_CZ",
177                         "hungarian"     => "hu_Latn_HU",
178                         "latvian"               => "lv_Latn_LV",
179                         "nederlands"    => "nl_Latn_NL",
180                         "italiano"              => "it_Latn_IT",
181                         "persian"               => "fa_Arab_IR",
182                         "spanish"               => "es_Latn_ES",
183                         "spanish-utf8"  => "es_Latn_ES.UTF-8",
184                         "japanese-euc"  => "ja_Jpan_JP.EUC-JP",
185                         "japanese-utf8" => "ja_Jpan_JP.UTF-8",
186                         "portuguese_brazil"     => "pt_Latn_BR"
187                         );
188 }