XPressME Integration Kit

Trac

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

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

bump 0.03

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