XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/pluggable-override.php @ 862

Last change on this file since 862 was 862, checked in by toemon, 8 years ago

WP4.5よりxpressmeでオーバーライドしているget_currentuserinfo()が非推奨となったための対策 Fix #433

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