XPressME Integration Kit

Trac

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

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

コメント部のログアウトを実行すると、ログアウト後、もとのページに戻ると、XOOSユーザとしてはログアウトしていないので、再びログインしてしまうバグ?を修正
コメントのログアウト時も、XOOPSログアウトへリダイレクトするようにした。

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