1 | <?php
|
---|
2 | /*
|
---|
3 | * XPressME - WordPress for XOOPS
|
---|
4 | *
|
---|
5 | * @copyright XPressME Project http://www.toemon.com
|
---|
6 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license
|
---|
7 | * @author toemon
|
---|
8 | * @package module::xpress
|
---|
9 | */
|
---|
10 | class wpInfo {
|
---|
11 | var $mod_dirpath;
|
---|
12 | var $mod_name;
|
---|
13 | var $mod_url;
|
---|
14 |
|
---|
15 | var $xoops_Lang;
|
---|
16 | var $wp_Lang;
|
---|
17 | var $php_version;
|
---|
18 | var $mysql_version;
|
---|
19 | // The language of XOOPS is set as Key of the array.
|
---|
20 | // The language of WP is set as Value of the array.
|
---|
21 | var $wp_lang_array = array(
|
---|
22 | 'english' => 'en_US',
|
---|
23 | 'japanese' => 'ja',
|
---|
24 | 'ja_utf8' => 'ja',
|
---|
25 | 'pt-br_utf8' => 'pt_BR',
|
---|
26 | // The key(language of XOOPS) of the following lists has not been set yet.
|
---|
27 | 'Afrikaans' => 'af',
|
---|
28 | 'Albanian' => 'al',
|
---|
29 | 'Arabic' => 'ar',
|
---|
30 | 'Bangla' => 'bn_BD',
|
---|
31 | 'Basque' => 'eu',
|
---|
32 | 'Belarusian' => 'be_BY',
|
---|
33 | 'Bosnian' => 'bs_BA',
|
---|
34 | 'Bulgarian' => 'bg_BG',
|
---|
35 | 'Catalan' => 'ca',
|
---|
36 | 'Chinese' => 'zh_CN',
|
---|
37 | 'Hong Kong' => 'zh_HK',
|
---|
38 | 'Taiwan' => 'zh_TW',
|
---|
39 | 'Croatian' => 'hr',
|
---|
40 | 'Czech' => 'cs_CZ',
|
---|
41 | 'Danish' => 'da_DK',
|
---|
42 | 'Dutch' => 'nl_NL',
|
---|
43 | 'Esperanto' => 'eo',
|
---|
44 | 'Estonian' => 'et',
|
---|
45 | 'Faroese' => 'fo',
|
---|
46 | 'Finnish' => 'fi',
|
---|
47 | 'Galician' => 'gl_ES',
|
---|
48 | 'Georgian' => 'ge_GE',
|
---|
49 | 'German' => 'de_DE',
|
---|
50 | 'Greek' => 'el',
|
---|
51 | 'Hebrew' => 'he_IL',
|
---|
52 | 'Hungarian' => 'hu_HU',
|
---|
53 | 'Icelandic' => 'is_IS',
|
---|
54 | 'Indonesian' => 'id_ID',
|
---|
55 | 'Italian' => 'it_IT',
|
---|
56 | 'Khmer' => 'km_KH',
|
---|
57 | 'ko_utf8' => 'ko_KR',
|
---|
58 | 'Latvian' => 'lv',
|
---|
59 | 'Lithuanian' => 'lt_LT',
|
---|
60 | 'Macedonian' => 'mk_MK',
|
---|
61 | 'Malagasy' => 'mg_MG',
|
---|
62 | 'Malay' => 'ms_MY',
|
---|
63 | 'Nias' => 'ni_ID',
|
---|
64 | 'Norwegian' => 'nb_NO',
|
---|
65 | 'Persian' => 'fa_IR',
|
---|
66 | 'Polish' => 'pl_PL',
|
---|
67 | 'European Portuguese' => 'pt_PT',
|
---|
68 | 'Romanian' => 'ro',
|
---|
69 | 'Russian' => 'ru_RU',
|
---|
70 | 'Serbian' => 'sr_RS',
|
---|
71 | 'Sinhala' => 'si_LK',
|
---|
72 | 'Slovak' => 'sk_SK',
|
---|
73 | 'Slovenian' => 'sl_SI',
|
---|
74 | 'Spanish' => 'es_ES',
|
---|
75 | 'Sundanese' => 'su_ID',
|
---|
76 | 'Swedish' => 'sv_SE',
|
---|
77 | 'Tajik' => 'tg',
|
---|
78 | 'Thai' => 'th',
|
---|
79 | 'Turkish' => 'tr',
|
---|
80 | 'Ukrainian' => 'uk',
|
---|
81 | 'Uzbek' => 'uz_UZ',
|
---|
82 | 'Vietnamse' => 'vi',
|
---|
83 | 'Welsh' => 'cy',
|
---|
84 | );
|
---|
85 |
|
---|
86 | function wpInfo(){
|
---|
87 | $this->__construct();
|
---|
88 | }
|
---|
89 | function __construct() {
|
---|
90 | $this->mod_dirpath = dirname(dirname(__FILE__));
|
---|
91 | $this->mod_name = basename(dirname(dirname(__FILE__)));
|
---|
92 | $this->mod_url = XOOPS_URL . '/modules/'.$this->mod_name;
|
---|
93 | $this->load_lang();
|
---|
94 | $this->xoops_Lang = @$GLOBALS["xoopsConfig"]['language'];
|
---|
95 | $this->php_version = phpversion();
|
---|
96 | $xoopsDB =& Database::getInstance();
|
---|
97 | list($SV) = $xoopsDB->fetchRow($xoopsDB->query('SELECT version()'));
|
---|
98 | $this->mysql_version = $SV;
|
---|
99 |
|
---|
100 | $this->get_wpLang();
|
---|
101 | }
|
---|
102 | function text_indent($text,$num = 1,$css_option='')
|
---|
103 | {
|
---|
104 | $ret = '';
|
---|
105 | $px = 24 * $num;
|
---|
106 | $ret = '<div style="padding-left:' .$px .'px;'.$css_option.'">';
|
---|
107 | $ret .= $text . '</div>';
|
---|
108 | return $ret;
|
---|
109 | }
|
---|
110 | public function load_lang()
|
---|
111 | {
|
---|
112 | $lang = @$GLOBALS["xoopsConfig"]['language'];
|
---|
113 |
|
---|
114 | // language file (modinfo.php)
|
---|
115 | if( file_exists( $this->mod_dirpath .'/language/'.$lang.'/admin.php' ) ) {
|
---|
116 | include_once $this->mod_dirpath .'/language/'.$lang.'/admin.php' ;
|
---|
117 | } else if( file_exists( $this->mod_dirpath .'/language/english/admin.php' ) ) {
|
---|
118 | include_once $this->mod_dirpath .'/language/english/admin.php' ;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | public function get_php_version()
|
---|
123 | {
|
---|
124 | return $this->php_version;
|
---|
125 | }
|
---|
126 | public function get_mysql_version()
|
---|
127 | {
|
---|
128 | return $this->mysql_version;
|
---|
129 | }
|
---|
130 | public function get_wpLang($xoops_Lang = '')
|
---|
131 | {
|
---|
132 | if(!empty($xoops_Lang)) $this->xoops_Lang = $xoops_Lang;
|
---|
133 | $this->wp_Lang = $this->wp_lang_array[$this->xoops_Lang];
|
---|
134 | if (empty($this->wp_Lang)) $this->wp_Lang = 'en_US';
|
---|
135 | return $this->wp_Lang;
|
---|
136 | }
|
---|
137 | public function get_mod_image_link($file_name='')
|
---|
138 | {
|
---|
139 | $link_url = '';
|
---|
140 | if(!empty($file_name)){
|
---|
141 | if(file_exists($this->mod_dirpath.'/images/'.$file_name)){
|
---|
142 | $link_url = '<img alt="'.$file_name.'" src="'. $this->mod_url .'/images/'.$file_name.'" title="'.$file_name.'" align=top>';
|
---|
143 | }
|
---|
144 | }
|
---|
145 | return $link_url;
|
---|
146 | }
|
---|
147 |
|
---|
148 | function is_wpdb_installed(){
|
---|
149 | $prefix_mod = XOOPS_DB_PREFIX .'_' . preg_replace('/wordpress/','wp',$this->mod_name) . '_';
|
---|
150 | $xoopsDB =& Database::getInstance();
|
---|
151 | $sql = "SHOW TABLES LIKE '$prefix_mod%'";
|
---|
152 | if ($result = $xoopsDB->queryf($sql)){
|
---|
153 | if($xoopsDB->getRowsNum($result)) return true;
|
---|
154 | }
|
---|
155 | return false;
|
---|
156 | }
|
---|
157 |
|
---|
158 | public function is_wp_file_found()
|
---|
159 | {
|
---|
160 | if (!file_exists($this->mod_dirpath . '/wp-settings.php')){
|
---|
161 | return false;
|
---|
162 | }
|
---|
163 | return true;
|
---|
164 | }
|
---|
165 | public function get_download_info($locale='')
|
---|
166 | {
|
---|
167 | $sql_version = preg_replace('/[^0-9.].*/', '', $this->mysql_version);
|
---|
168 | $php_version = $this->php_version;
|
---|
169 | if (empty($locale)) $locale = $this->wp_Lang;
|
---|
170 | $url = "http://api.wordpress.org/core/version-check/1.5/?php=" . $php_version . "&locale=" . $locale . "&mysql=" . $sql_version;
|
---|
171 |
|
---|
172 | $handle = @fopen($url,'r');
|
---|
173 | if ($handle) {
|
---|
174 | $ans = array();
|
---|
175 | $num = 0;
|
---|
176 | $pos = 0;
|
---|
177 | while (($buffer = fgets($handle, 4096)) !== false) {
|
---|
178 | $buffer = trim($buffer);
|
---|
179 | if (strlen($buffer) == 0) {
|
---|
180 | $num++;
|
---|
181 | $pos=0;
|
---|
182 | } else {
|
---|
183 | $ans[$num][$pos] = $buffer;
|
---|
184 | $pos++;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | if (!feof($handle)) {
|
---|
188 | echo "Error: unexpected fgets() fail\n";
|
---|
189 | }
|
---|
190 | fclose($handle);
|
---|
191 | }
|
---|
192 | $ressponce = $ans[0][0];
|
---|
193 | $site_url = $ans[0][1];
|
---|
194 | $download_url = $ans[0][2];
|
---|
195 | $wp_version = $ans[0][3];
|
---|
196 | $download_lang = $ans[0][4];
|
---|
197 | // print_r($ans);
|
---|
198 | if (isset($ans[1])){
|
---|
199 | $en_download_url = $ans[1][2];
|
---|
200 | }
|
---|
201 | if ($locale == $download_lang){
|
---|
202 | $ret = $this->text_indent(sprintf(_AM_XP2_WP_INFO_1,$locale),2);
|
---|
203 | $ret .= $this->text_indent('<a href="'.$download_url.'">' . $download_url .'</a>' ,3);
|
---|
204 | if (!empty($en_download_url)){
|
---|
205 | $ret .= $this->text_indent(_AM_XP2_WP_INFO_4,2);
|
---|
206 | $ret .= $this->text_indent('<a href="'.$en_download_url .'">' . $en_download_url .'</a>' ,3);
|
---|
207 | }
|
---|
208 | } else {
|
---|
209 | $ret = $this->text_indent(sprintf(_AM_XP2_WP_INFO_2,$locale));
|
---|
210 | $ret .= $this->text_indent(_AM_XP2_WP_INFO_3,2);
|
---|
211 | $ret .= $this->text_indent('<a href="http://codex.wordpress.org/WordPress_in_Your_Language" target=" _blank">WordPress_in_Your_Language</a>' ,3);
|
---|
212 | $ret .= $this->text_indent(_AM_XP2_WP_INFO_4,2);
|
---|
213 | $ret .= $this->text_indent('<a href="'.$download_url.'">' . $download_url .'</a>' ,3);
|
---|
214 | }
|
---|
215 | echo $ret;
|
---|
216 | }
|
---|
217 | }
|
---|
218 | ?> |
---|