XPressME Integration Kit

Trac

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

Last change on this file since 87 was 87, checked in by toemon, 15 years ago

XOOPS DBプレフィックス変更時の検出と修正機能の実装 #22
プレフィックス確認アップデートの対象としては
usermetaテーブル、のuser_level、capabilities、autosave_draft_ids、usersettings、usersettingstime
およびoptionテーブルのuser_roles

File size: 5.6 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
22
23        if ($xoopsModule){
24                if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
25                        return false;
26
27                if ( ! empty($current_user) )
28                        return;
29
30                if (check_xpress_auth_cookie()){        //The cookie is login user's or it checks it
31                        if ( $user = wp_validate_auth_cookie() ) {
32                                wp_set_current_user($user);
33                                return ;
34                        }
35                }                               
36                xpress_login();
37
38        } else {
39                // WP2.7 original
40                if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
41                        return false;
42
43                if ( ! empty($current_user) )
44                        return;
45
46                if ( ! $user = wp_validate_auth_cookie() ) {
47                         if ( empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) {
48                                wp_set_current_user(0);
49                                return false;
50                         }
51                }
52
53                wp_set_current_user($user);
54        }
55}
56endif;
57
58function xpress_login(){
59        global $current_user;
60       
61        if(is_object($GLOBALS["xoopsUser"])){
62                $u_name = $GLOBALS["xoopsUser"]->getVar("uname");
63                $u_pass_md5 = $GLOBALS["xoopsUser"]->getVar("pass");   
64                if ( ! empty($u_name) && ! empty($u_pass_md5) ) {
65                        include_once dirname( __FILE__ ).'/user_sync_xoops.php';
66                        repair_user_meta_prefix();  //Repair when data base prefix is changed on XOOPS side
67                        $messege = '';
68                        $ret = user_sync_to_wordpress($GLOBALS["xoopsUser"]->getVar("uid"),$messege);
69                        if ($ret){
70                                $user = new WP_User(0, $u_name);
71                                if ( wp_login($u_name, $u_pass_md5) ) {
72                                        wp_setcookie($u_name, $u_pass_md5, true, '', '', false);
73                                        do_action('wp_login', $u_name);
74                                        wp_set_current_user($user->ID);
75                                        return  true;
76                                }
77                        }
78                }
79        }
80        wp_set_current_user(0);
81        return 0;       
82}
83
84function check_xpress_auth_cookie() {           // for wp2.5
85        if ( empty($_COOKIE[AUTH_COOKIE]) ){
86                return false;
87        }
88        $cookie = $_COOKIE[AUTH_COOKIE];
89
90        $cookie_elements = explode('|', $cookie);
91        if ( count($cookie_elements) != 3 ){
92                        return false;
93        }
94                                       
95        if(is_object($GLOBALS["xoopsModule"])){
96//              && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){
97                if(is_object($GLOBALS["xoopsUser"])){
98                        $u_name = $GLOBALS["xoopsUser"]->getVar("uname");
99                        list($username, $expiration, $hmac) = $cookie_elements;
100                        if ($u_name == $username) {
101                                return true;
102                        }
103                }
104        } else {
105                $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
106                $org_url = $_SERVER['REQUEST_URI'];
107                $needle = '/modules/' . $mydirname . '/wp-admin/';
108                if (strstr($org_url , $needle)){
109                        return true;                           
110                }
111        }
112        return false;
113}
114
115if ( !function_exists('wp_check_password') ) :
116// for wordpress2.5
117function wp_check_password($password, $hash, $user_id = '') {
118        global $wp_hasher;
119
120        // If the hash is still md5...
121        if ( strlen($hash) <= 32 ) {
122                if (( $hash == md5($password)) || ($hash == $password)) {  // The password taken out of XOOPS is hash value.
123                        $check = true;
124                } else {
125                        $check = false;
126                }
127
128/* A new hash is not used because it differs from the hash on the XOOPS password.
129 *              if ( $check && $user_id ) {
130 *                      // Rehash using new hash.
131 *                      wp_set_password($password, $user_id);
132 *                      $hash = wp_hash_password($password);
133 *              }
134 */
135                return apply_filters('check_password', $check, $password, $hash, $user_id);
136        }
137
138        // If the stored hash is longer than an MD5, presume the
139        // new style phpass portable hash.
140        if ( empty($wp_hasher) ) {
141                require_once( ABSPATH . 'wp-includes/class-phpass.php');
142                // By default, use the portable hash from phpass
143                $wp_hasher = new PasswordHash(8, TRUE);
144        }
145
146        $check = $wp_hasher->CheckPassword($password, $hash);
147
148        return apply_filters('check_password', $check, $password, $hash, $user_id);
149}
150endif;
151
152if ( !function_exists('wp_redirect') ) :
153function wp_redirect($location, $status = 302) {
154        global $is_IIS;
155       
156        if ($location == 'wp-login.php?loggedout=true') $location = XOOPS_URL.'/user.php?op=logout'; //xoops logout at wp logout
157        if ($location == 'wp-login.php?action=register') $location = XOOPS_URL."/register.php";  //wp-register to xoops register
158
159        $location = apply_filters('wp_redirect', $location, $status);
160        $status = apply_filters('wp_redirect_status', $status, $location);
161
162        if ( !$location ) // allows the wp_redirect filter to cancel a redirect
163                return false;
164
165        $location = wp_sanitize_redirect($location);
166
167        if ( $is_IIS ) {
168                header("Refresh: 0;url=$location");
169        } else {
170                if ( php_sapi_name() != 'cgi-fcgi' )
171                        status_header($status); // This causes problems on IIS and some FastCGI setups
172                header("Location: $location");
173        }
174}
175endif;
176
177if ( !function_exists('wp_hash_password') ) :
178function wp_hash_password($password) {
179        global $wp_hasher;
180        return md5($password); // A new hash is not used because it differs from the hash on the XOOPS password.
181/*
182        if ( empty($wp_hasher) ) {
183                require_once( ABSPATH . 'wp-includes/class-phpass.php');
184                // By default, use the portable hash from phpass
185                $wp_hasher = new PasswordHash(8, TRUE);
186        }
187
188        return $wp_hasher->HashPassword($password);
189*/
190}
191endif;
192// ***********************************  End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************
193
194?>
Note: See TracBrowser for help on using the repository browser.