1 | <?php |
---|
2 | /** |
---|
3 | * XPress - WordPress for XOOPS |
---|
4 | * |
---|
5 | * Adding multi-author features to XPressME |
---|
6 | * |
---|
7 | * @copyright The XPressME project |
---|
8 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
---|
9 | * @author toemon |
---|
10 | * @since 2.05 |
---|
11 | * @version $Id$ |
---|
12 | * @package module::xpress |
---|
13 | */ |
---|
14 | |
---|
15 | // *********************************** Start Pluggable Function Edit (wp-include/pluggable.php) ************************************ |
---|
16 | |
---|
17 | if ( !function_exists('get_currentuserinfo') ) : |
---|
18 | function get_currentuserinfo() { |
---|
19 | global $current_user; |
---|
20 | global $xoopsModule,$xoopsUser,$xoopsUserIsAdmin; |
---|
21 | |
---|
22 | |
---|
23 | if ($xoopsModule){ |
---|
24 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) |
---|
25 | return false; |
---|
26 | |
---|
27 | if (is_object($xoopsUser)){ // When the user is logging in xoops |
---|
28 | if ( ! empty($current_user) ){ |
---|
29 | $xoops_user = $xoopsUser->getVar("uname"); |
---|
30 | if ($current_user->user_login == $xoops_user){ // If xoops login user and wordpress current user are the same |
---|
31 | return; |
---|
32 | } |
---|
33 | } |
---|
34 | if (check_xpress_auth_cookie()){ //The cookie is login user's or it checks it |
---|
35 | if (function_exists('wp_validate_auth_cookie')){ |
---|
36 | if ( $user = wp_validate_auth_cookie() ) { |
---|
37 | // When the user meta prefix is different according to the change in the xoops data base prefix, it restores it. |
---|
38 | if (!check_user_meta_prefix($user)){ |
---|
39 | repair_user_meta_prefix(); |
---|
40 | } |
---|
41 | wp_set_current_user($user); |
---|
42 | return ; |
---|
43 | } |
---|
44 | } else { // for WP2.0 |
---|
45 | if ( !empty($_COOKIE[USER_COOKIE]) && !empty($_COOKIE[PASS_COOKIE])){ |
---|
46 | if(wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { |
---|
47 | $user_login = $_COOKIE[USER_COOKIE]; |
---|
48 | wp_set_current_user(0, $user_login); |
---|
49 | return; |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | } |
---|
54 | return xpress_login(); |
---|
55 | } else { // For the xoops guest |
---|
56 | |
---|
57 | if (function_exists('wp_validate_auth_cookie')){ |
---|
58 | if ( ! $user = wp_validate_auth_cookie() ) { |
---|
59 | if ( empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) { |
---|
60 | wp_set_current_user(0); |
---|
61 | return false; |
---|
62 | } |
---|
63 | } |
---|
64 | wp_set_current_user($user); |
---|
65 | } else { // for WP2.0 |
---|
66 | if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || |
---|
67 | !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { |
---|
68 | wp_set_current_user(0); |
---|
69 | return false; |
---|
70 | } |
---|
71 | $user_login = $_COOKIE[USER_COOKIE]; |
---|
72 | wp_set_current_user(0, $user_login); |
---|
73 | } |
---|
74 | return false; |
---|
75 | } |
---|
76 | } else { |
---|
77 | // WP original |
---|
78 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) |
---|
79 | return false; |
---|
80 | |
---|
81 | if ( ! empty($current_user) ) |
---|
82 | return; |
---|
83 | |
---|
84 | if (function_exists('wp_validate_auth_cookie')){ |
---|
85 | if ( ! $user = wp_validate_auth_cookie() ) { |
---|
86 | if ( empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) { |
---|
87 | wp_set_current_user(0); |
---|
88 | return false; |
---|
89 | } |
---|
90 | } |
---|
91 | wp_set_current_user($user); |
---|
92 | } else { // for WP2.0 |
---|
93 | if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || |
---|
94 | !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { |
---|
95 | wp_set_current_user(0); |
---|
96 | return false; |
---|
97 | } |
---|
98 | $user_login = $_COOKIE[USER_COOKIE]; |
---|
99 | wp_set_current_user(0, $user_login); |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | endif; |
---|
104 | |
---|
105 | if ( !function_exists('xpress_login') ) : |
---|
106 | function xpress_login(){ |
---|
107 | global $current_user; |
---|
108 | global $xoopsModule,$xoopsUser,$xoopsUserIsAdmin; |
---|
109 | |
---|
110 | if(is_object($xoopsUser)){ |
---|
111 | $u_name = $xoopsUser->getVar("uname"); |
---|
112 | $u_pass_md5 = $xoopsUser->getVar("pass"); |
---|
113 | if ( ! empty($u_name) && ! empty($u_pass_md5) ) { |
---|
114 | include_once dirname( __FILE__ ).'/user_sync_xoops.php'; |
---|
115 | repair_user_meta_prefix(); //Repair when data base prefix is changed on XOOPS side |
---|
116 | $messege = ''; |
---|
117 | $ret = user_sync_to_wordpress($xoopsUser->getVar("uid"),$messege); |
---|
118 | if ($ret){ |
---|
119 | $user = new WP_User(0, $u_name); |
---|
120 | if ( wp_login($u_name, $u_pass_md5) ) { |
---|
121 | wp_setcookie($u_name, $u_pass_md5, true, '', '', false); |
---|
122 | do_action('wp_login', $u_name); |
---|
123 | wp_set_current_user($user->ID); |
---|
124 | return true; |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | if ( ! empty($current_user) ){ |
---|
130 | wp_set_current_user(0); |
---|
131 | wp_logout(); |
---|
132 | wp_clear_auth_cookie(); |
---|
133 | } |
---|
134 | return false; |
---|
135 | } |
---|
136 | endif; |
---|
137 | |
---|
138 | if ( !function_exists('check_xpress_auth_cookie') ) : |
---|
139 | function check_xpress_auth_cookie() { // for wp2.5 |
---|
140 | if ( empty($_COOKIE[AUTH_COOKIE]) ){ |
---|
141 | return false; |
---|
142 | } |
---|
143 | $cookie = $_COOKIE[AUTH_COOKIE]; |
---|
144 | |
---|
145 | $cookie_elements = explode('|', $cookie); |
---|
146 | if ( count($cookie_elements) != 3 ){ |
---|
147 | return false; |
---|
148 | } |
---|
149 | |
---|
150 | if(is_object($GLOBALS["xoopsModule"])){ |
---|
151 | // && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){ |
---|
152 | if(is_object($GLOBALS["xoopsUser"])){ |
---|
153 | $u_name = $GLOBALS["xoopsUser"]->getVar("uname"); |
---|
154 | list($username, $expiration, $hmac) = $cookie_elements; |
---|
155 | if ($u_name == $username) { |
---|
156 | return true; |
---|
157 | } |
---|
158 | } |
---|
159 | } else { |
---|
160 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; |
---|
161 | $org_url = $_SERVER['REQUEST_URI']; |
---|
162 | $needle = '/modules/' . $mydirname . '/wp-admin/'; |
---|
163 | if (strstr($org_url , $needle)){ |
---|
164 | return true; |
---|
165 | } |
---|
166 | } |
---|
167 | return false; |
---|
168 | } |
---|
169 | endif; |
---|
170 | |
---|
171 | if ( !function_exists('wp_check_password') ) : |
---|
172 | // for wordpress2.5 |
---|
173 | function wp_check_password($password, $hash, $user_id = '') { |
---|
174 | global $wp_hasher; |
---|
175 | global $xoops_config,$xoops_db; |
---|
176 | |
---|
177 | // For attestation when password has been sent as hash value. (When having logged it in from Xoops and ImpressCMS) |
---|
178 | if ($hash == $password){ |
---|
179 | return apply_filters('check_password', true, $password, $hash, $user_id); |
---|
180 | } |
---|
181 | |
---|
182 | // Password authentication for Xoops |
---|
183 | if ( strlen($hash) <= 32 ) { |
---|
184 | $check = ( $hash == md5($password) ); |
---|
185 | return apply_filters('check_password', $check, $password, $hash, $user_id); |
---|
186 | } |
---|
187 | |
---|
188 | // Password authentication for ImpressCMS |
---|
189 | if($xoops_config->is_impress && function_exists('hash')){ |
---|
190 | $mainSalt = $xoops_config->xoops_db_salt; |
---|
191 | // get user salt |
---|
192 | $xpress_user_db = $xoops_config->module_db_prefix . 'users'; |
---|
193 | $xoops_user_db = $xoops_config->xoops_db_prefix . '_users'; |
---|
194 | $login_name = $xoops_db->get_var("SELECT user_login FROM $xpress_user_db WHERE ID = $user_id"); |
---|
195 | $user_salt = $xoops_db->get_var("SELECT salt FROM $xoops_user_db WHERE uname = '$login_name'"); |
---|
196 | $enc_type = intval( $xoops_db->get_var("SELECT enc_type FROM $xoops_user_db WHERE uname = '$login_name'") ); |
---|
197 | |
---|
198 | // Make Impress hash |
---|
199 | if($enc_type == 0) {$impress_hash = md5($password);} // no salt used for compatibility with external scripts such as ipb/phpbb etc. |
---|
200 | elseif($enc_type == 1) {$impress_hash = hash('sha256', $user_salt.md5($password).$mainSalt);} |
---|
201 | elseif($enc_type == 2) {$impress_hash = hash('sha384', $user_salt.md5($password).$mainSalt);} |
---|
202 | elseif($enc_type == 3) {$impress_hash = hash('sha512', $user_salt.md5($password).$mainSalt);} |
---|
203 | elseif($enc_type == 4) {$impress_hash = hash('ripemd128', $user_salt.md5($password).$mainSalt);} |
---|
204 | elseif($enc_type == 5) {$impress_hash = hash('ripemd160', $user_salt.md5($password).$mainSalt);} |
---|
205 | elseif($enc_type == 6) {$impress_hash = hash('whirlpool', $user_salt.md5($password).$mainSalt);} |
---|
206 | elseif($enc_type == 7) {$impress_hash = hash('haval128,4', $user_salt.md5($password).$mainSalt);} |
---|
207 | elseif($enc_type == 8) {$impress_hash = hash('haval160,4', $user_salt.md5($password).$mainSalt);} |
---|
208 | elseif($enc_type == 9) {$impress_hash = hash('haval192,4', $user_salt.md5($password).$mainSalt);} |
---|
209 | elseif($enc_type == 10) {$impress_hash = hash('haval224,4', $user_salt.md5($password).$mainSalt);} |
---|
210 | elseif($enc_type == 11) {$impress_hash = hash('haval256,4', $user_salt.md5($password).$mainSalt);} |
---|
211 | elseif($enc_type == 12) {$impress_hash = hash('haval128,5', $user_salt.md5($password).$mainSalt);} |
---|
212 | elseif($enc_type == 13) {$impress_hash = hash('haval160,5', $user_salt.md5($password).$mainSalt);} |
---|
213 | elseif($enc_type == 14) {$impress_hash = hash('haval192,5', $user_salt.md5($password).$mainSalt);} |
---|
214 | elseif($enc_type == 15) {$impress_hash = hash('haval224,5', $user_salt.md5($password).$mainSalt);} |
---|
215 | elseif($enc_type == 16) {$impress_hash = hash('haval256,5', $user_salt.md5($password).$mainSalt);} |
---|
216 | |
---|
217 | if ($hash == $impress_hash){ |
---|
218 | return apply_filters('check_password', true, $password, $hash, $user_id); |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | // If the hash is still md5... |
---|
223 | if ( strlen($hash) <= 32 ) { |
---|
224 | $check = ( $hash == md5($password) ); |
---|
225 | /* A new hash is not used because it differs from the hash on the XOOPS password. |
---|
226 | * if ( $check && $user_id ) { |
---|
227 | * // Rehash using new hash. |
---|
228 | * wp_set_password($password, $user_id); |
---|
229 | * $hash = wp_hash_password($password); |
---|
230 | * } |
---|
231 | */ |
---|
232 | return apply_filters('check_password', $check, $password, $hash, $user_id); |
---|
233 | } |
---|
234 | |
---|
235 | // If the stored hash is longer than an MD5, presume the |
---|
236 | // new style phpass portable hash. |
---|
237 | if ( empty($wp_hasher) ) { |
---|
238 | require_once( ABSPATH . 'wp-includes/class-phpass.php'); |
---|
239 | // By default, use the portable hash from phpass |
---|
240 | $wp_hasher = new PasswordHash(8, TRUE); |
---|
241 | } |
---|
242 | |
---|
243 | $check = $wp_hasher->CheckPassword($password, $hash); |
---|
244 | |
---|
245 | return apply_filters('check_password', $check, $password, $hash, $user_id); |
---|
246 | } |
---|
247 | endif; |
---|
248 | |
---|
249 | if ( !function_exists('wp_redirect') ) : |
---|
250 | function wp_redirect($location, $status = 302) { |
---|
251 | global $is_IIS,$xoops_config,$action; |
---|
252 | |
---|
253 | if ($location == 'wp-login.php?loggedout=true') $location = $xoops_config->xoops_url.'/user.php?op=logout'; //xoops logout at wp logout |
---|
254 | if ($location == 'wp-login.php?action=register') $location = $xoops_config->xoops_url."/register.php"; //wp-register to xoops register |
---|
255 | if ($action == 'logout') $location = $xoops_config->xoops_url.'/user.php?op=logout'; //xoops logout at comment logout |
---|
256 | |
---|
257 | $location = apply_filters('wp_redirect', $location, $status); |
---|
258 | $status = apply_filters('wp_redirect_status', $status, $location); |
---|
259 | |
---|
260 | if ( !$location ) // allows the wp_redirect filter to cancel a redirect |
---|
261 | return false; |
---|
262 | |
---|
263 | $location = wp_sanitize_redirect($location); |
---|
264 | |
---|
265 | if (!headers_sent()) { |
---|
266 | ob_end_clean(); |
---|
267 | if ( $is_IIS ) { |
---|
268 | header("Refresh: 0;url=$location"); |
---|
269 | } else { |
---|
270 | if ( php_sapi_name() != 'cgi-fcgi' ) |
---|
271 | status_header($status); // This causes problems on IIS and some FastCGI setups |
---|
272 | header("Location: $location"); |
---|
273 | } |
---|
274 | } else { // force redirect |
---|
275 | echo ("<HTML>"); |
---|
276 | echo("<META http-equiv=\"Refresh\" content=\"0;url=$location\">"); |
---|
277 | echo ("<BODY onload=\"try {self.location.href='$location' } catch(e) {}\">"); |
---|
278 | printf(__("If the page does not automatically reload, please click <a href='%s'>here</a>","xpressme"),$location); |
---|
279 | echo ("</BODY>"); |
---|
280 | echo ("</HTML>"); |
---|
281 | } |
---|
282 | } |
---|
283 | endif; |
---|
284 | |
---|
285 | if ( !function_exists('wp_hash_password') ) : |
---|
286 | function wp_hash_password($password) { |
---|
287 | global $wp_hasher; |
---|
288 | return md5($password); // A new hash is not used because it differs from the hash on the XOOPS password. |
---|
289 | /* |
---|
290 | if ( empty($wp_hasher) ) { |
---|
291 | require_once( ABSPATH . 'wp-includes/class-phpass.php'); |
---|
292 | // By default, use the portable hash from phpass |
---|
293 | $wp_hasher = new PasswordHash(8, TRUE); |
---|
294 | } |
---|
295 | |
---|
296 | return $wp_hasher->HashPassword($password); |
---|
297 | */ |
---|
298 | } |
---|
299 | endif; |
---|
300 | |
---|
301 | if ( !function_exists('wp_clear_auth_cookie') ) : |
---|
302 | /** |
---|
303 | * Removes all of the cookies associated with authentication. |
---|
304 | * |
---|
305 | * @since 2.5 |
---|
306 | */ |
---|
307 | function wp_clear_auth_cookie() { |
---|
308 | do_action('clear_auth_cookie'); |
---|
309 | |
---|
310 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); |
---|
311 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); |
---|
312 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); |
---|
313 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); |
---|
314 | @setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
---|
315 | @setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
---|
316 | |
---|
317 | // Old cookies |
---|
318 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
---|
319 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
---|
320 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
---|
321 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
---|
322 | |
---|
323 | // Even older cookies |
---|
324 | @setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
---|
325 | @setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
---|
326 | @setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
---|
327 | @setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
---|
328 | |
---|
329 | } |
---|
330 | endif; |
---|
331 | |
---|
332 | if ( !function_exists('is_user_logged_in') ) : |
---|
333 | /** |
---|
334 | * Checks if the current visitor is a logged in user. |
---|
335 | * |
---|
336 | * @since 2.0.0 |
---|
337 | * |
---|
338 | * @return bool True if user is logged in, false if not logged in. |
---|
339 | */ |
---|
340 | function is_user_logged_in() { |
---|
341 | $user = wp_get_current_user(); |
---|
342 | if (method_exists($user, 'exists')) { |
---|
343 | if ( ! $user->exists() ) return false; |
---|
344 | } else { |
---|
345 | if ( empty( $user->ID ) ) return false; |
---|
346 | } |
---|
347 | return true; |
---|
348 | } |
---|
349 | endif; |
---|
350 | |
---|
351 | |
---|
352 | // *********************************** End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************ |
---|
353 | |
---|
354 | ?> |
---|