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