OSDN Git Service

FIX:MANAGER::instance()をstaticに
[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                 echo 'WARNING: You are running NucleusCMS on a older version of PHP that is no longer supported by NucleusCMS. Please upgrade to PHP5!';
29         }
30         
31         /* config table */
32         /* change Language setting to Locale */
33         if ( upgrade_checkIfCVExists('Language') )
34         {
35                 $res = sql_query("SELECT value FROM " . sql_table('config') . " WHERE name='Language'");
36                 if ( $res !== FALSE )
37                 {
38                         $row = sql_fetch_assoc($res);
39                         $locale = i18n_upg::convert_old_language_file_name_to_locale($row['value']);
40                         if ( $locale )
41                         {
42                                 $query = 'INSERT INTO ' . sql_table('config') . " VALUES ('Locale','{$locale}')";
43                                 upgrade_query('Creating Locale config value', $query);
44                                 
45                                 $query = 'DELETE FROM ' . sql_table('config') . " WHERE name='Language'";
46                                 upgrade_query("Removing Language config value", $query);
47                         }
48                 }
49         }
50         
51         /* change AdminCSS setting */
52         if ( upgrade_checkIfCVExists('AdminCSS') )
53         {
54                 $query = 'UPDATE ' . sql_table('config') . " SET value='original' WHERE name='AdminCSS'";
55                 upgrade_query('Changing AdminCSS config value', $query);
56         }
57         
58         /* create AdminSkin setting */
59         if ( !upgrade_checkIfCVExists('AdminSkin') )
60         {
61                 $query = 'INSERT INTO ' . sql_table('config') . " VALUES ('AdminSkin','0')";
62                 upgrade_query('Creating AdminSkin config value', $query);
63         }
64         
65         /* create BookmarkletSkin setting */
66         if ( !upgrade_checkIfCVExists('BookmarkletSkin') )
67         {
68                 $query = 'INSERT INTO ' . sql_table('config') . " VALUES ('BookmarkletSkin','0')";
69                 upgrade_query('Creating BookmarkletSkin config value', $query);
70         }
71         
72         
73         /* member table */
74         /* changing the member table to rename deflang to mlocale */
75         if ( !upgrade_checkIfColumnExists('member','mlocale') )
76         {
77                 $query =  'ALTER TABLE '.sql_table('member') . " CHANGE deflang mlocale varchar(20) NOT NULL default '' AFTER mcookiekey";
78                 upgrade_query("Renaming deflang column for members to mlocale", $query);
79         }
80         
81         /* changing the member table to add madminskin column */
82         if ( !upgrade_checkIfColumnExists('member','madminskin') )
83         {
84                 $query =  'ALTER TABLE '.sql_table('member') . " ADD madminskin tinyint(2) NOT NULL default '0'";
85                 upgrade_query("Adding a new row for the adminskin member option", $query);
86         }
87         
88         /* changing the member table to add mbkmklt column */
89                 if ( !upgrade_checkIfColumnExists('member','mbkmklt') )
90         {
91                 $query =  'ALTER TABLE '.sql_table('member') . " ADD mbkmklt tinyint(2) NOT NULL default '0'";
92                 upgrade_query("Adding a new row for the bkmklt member option", $query);
93         }
94         
95         // all member default value set
96         $result = sql_query("SELECT * FROM " . sql_table('member'));
97         while ( $row = mysql_fetch_assoc($result) )
98         {
99                 $locale = i18n_upg::convert_old_language_file_name_to_locale($row['mlocale']);
100                 if ( $locale )
101                 {
102                         $query = 'UPDATE $s SET mlocale=$s WHERE mnumber=$d';
103                         $query = sprintf($query, sql_table('member'), addslashes($locale), $row['mnumber']);
104                         upgrade_query('Changing mlocale value', $query);
105                 }
106         }
107         
108         // 3.6 -> 4.0
109         // update database version
110         update_version('400');
111         
112 }
113
114 class i18n_upg
115 {
116         /**
117         * i18n::convert_old_language_file_name_to_locale()
118         * NOTE: this should be obsoleted near future.
119         *
120         * @static
121         * @param        string  $target_language        old translation file name
122         * @return       string  locale name as language_script_region
123         */
124         static public function convert_old_language_file_name_to_locale($target_language)
125         {
126                 $target_locale = '';
127                 foreach ( self::$lang_refs as $language => $locale )
128                 {
129                         if ( $target_language == $language )
130                         {
131                                 if ( preg_match('#^(.+)\.(.+)$#', $locale, $match) )
132                                 {
133                                         $target_locale = $match[1];
134                                 }
135                                 else
136                                 {
137                                         $target_locale = $locale;
138                                 }
139                                 break;
140                         }
141                 }
142                 return $target_locale;
143         }
144         
145         /**
146          * i18n::$lang_refs
147          * reference table to convert old and new way to name translation files.
148          * NOTE: this should be obsoleted as soon as possible.
149          *
150          * @static
151          */
152         static private $lang_refs = array(
153                         "english"               => "en_Latn_US",
154                         "english-utf8"  => "en_Latn_US.UTF-8",
155                         "bulgarian"     => "bg_Cyrl_BG",
156                         "finnish"               => "fi_Latn_FI",
157                         "catalan"               => "ca_Latn_ES",
158                         "french"                => "fr_Latn_FR",
159                         "russian"               => "ru_Cyrl_RU",
160                         "chinese"               => "zh_Hans_CN",
161                         "simchinese"    => "zh_Hans_CN",
162                         "chineseb5"     => "zh_Hant_TW",
163                         "traditional_chinese"   =>      "zh_Hant_TW",
164                         "galego"                => "gl_Latn_ES",
165                         "german"                => "de_Latn_DE",
166                         "korean-utf"    => "ko_Kore_KR.UTF-8",
167                         "korean-euc-kr" => "ko_Kore_KR.EUC-KR",
168                         "slovak"                => "sk_Latn_SK",
169                         "czech"         => "cs_Latn_CZ",
170                         "hungarian"     => "hu_Latn_HU",
171                         "latvian"               => "lv_Latn_LV",
172                         "nederlands"    => "nl_Latn_NL",
173                         "italiano"              => "it_Latn_IT",
174                         "persian"               => "fa_Arab_IR",
175                         "spanish"               => "es_Latn_ES",
176                         "spanish-utf8"  => "es_Latn_ES.UTF-8",
177                         "japanese-euc"  => "ja_Jpan_JP.EUC-JP",
178                         "japanese-utf8" => "ja_Jpan_JP.UTF-8",
179                         "portuguese_brazil"     => "pt_Latn_BR"
180                         );
181 }