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 | if ($xoopsModule){
|
---|
23 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
---|
24 | return false;
|
---|
25 |
|
---|
26 | if (is_object($xoopsUser)){ // When the user is logging in xoops
|
---|
27 | if ( ! empty($current_user) ){
|
---|
28 | $xoops_user = $xoopsUser->getVar("uname");
|
---|
29 | if ($current_user->user_login == $xoops_user){ // If xoops login user and wordpress current user are the same
|
---|
30 | return;
|
---|
31 | }
|
---|
32 | }
|
---|
33 | if (check_xpress_auth_cookie()){ //The cookie is login user's or it checks it
|
---|
34 | if ( $user = wp_validate_auth_cookie() ) {
|
---|
35 | // When the user meta prefix is different according to the change in the xoops data base prefix, it restores it.
|
---|
36 | if (!check_user_meta_prefix($user)){
|
---|
37 | repair_user_meta_prefix();
|
---|
38 | }
|
---|
39 | wp_set_current_user($user);
|
---|
40 | return ;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | return xpress_login();
|
---|
44 | } else { // For the xoops guest
|
---|
45 | if ( ! empty($current_user) ){ // When a current user of wordpress is set, a current user is cleared.
|
---|
46 | wp_set_current_user(0);
|
---|
47 | wp_logout();
|
---|
48 | wp_clear_auth_cookie();
|
---|
49 | }
|
---|
50 | return false;
|
---|
51 | }
|
---|
52 | } else {
|
---|
53 | // WP2.7 original
|
---|
54 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
---|
55 | return false;
|
---|
56 |
|
---|
57 | if ( ! empty($current_user) )
|
---|
58 | return;
|
---|
59 |
|
---|
60 | if ( ! $user = wp_validate_auth_cookie() ) {
|
---|
61 | if ( empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) {
|
---|
62 | wp_set_current_user(0);
|
---|
63 | return false;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | wp_set_current_user($user);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | endif;
|
---|
71 |
|
---|
72 | if ( !function_exists('xpress_login') ) :
|
---|
73 | function xpress_login(){
|
---|
74 | global $current_user;
|
---|
75 | global $xoopsModule,$xoopsUser,$xoopsUserIsAdmin;
|
---|
76 |
|
---|
77 | if(is_object($xoopsUser)){
|
---|
78 | $u_name = $xoopsUser->getVar("uname");
|
---|
79 | $u_pass_md5 = $xoopsUser->getVar("pass");
|
---|
80 | if ( ! empty($u_name) && ! empty($u_pass_md5) ) {
|
---|
81 | include_once dirname( __FILE__ ).'/user_sync_xoops.php';
|
---|
82 | repair_user_meta_prefix(); //Repair when data base prefix is changed on XOOPS side
|
---|
83 | $messege = '';
|
---|
84 | $ret = user_sync_to_wordpress($xoopsUser->getVar("uid"),$messege);
|
---|
85 | if ($ret){
|
---|
86 | $user = new WP_User(0, $u_name);
|
---|
87 | if ( wp_login($u_name, $u_pass_md5) ) {
|
---|
88 | wp_setcookie($u_name, $u_pass_md5, true, '', '', false);
|
---|
89 | do_action('wp_login', $u_name);
|
---|
90 | wp_set_current_user($user->ID);
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 | wp_set_current_user(0);
|
---|
97 | return 0;
|
---|
98 | }
|
---|
99 | endif;
|
---|
100 |
|
---|
101 | if ( !function_exists('check_xpress_auth_cookie') ) :
|
---|
102 | function check_xpress_auth_cookie() { // for wp2.5
|
---|
103 | if ( empty($_COOKIE[AUTH_COOKIE]) ){
|
---|
104 | return false;
|
---|
105 | }
|
---|
106 | $cookie = $_COOKIE[AUTH_COOKIE];
|
---|
107 |
|
---|
108 | $cookie_elements = explode('|', $cookie);
|
---|
109 | if ( count($cookie_elements) != 3 ){
|
---|
110 | return false;
|
---|
111 | }
|
---|
112 |
|
---|
113 | if(is_object($GLOBALS["xoopsModule"])){
|
---|
114 | // && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){
|
---|
115 | if(is_object($GLOBALS["xoopsUser"])){
|
---|
116 | $u_name = $GLOBALS["xoopsUser"]->getVar("uname");
|
---|
117 | list($username, $expiration, $hmac) = $cookie_elements;
|
---|
118 | if ($u_name == $username) {
|
---|
119 | return true;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | } else {
|
---|
123 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
124 | $org_url = $_SERVER['REQUEST_URI'];
|
---|
125 | $needle = '/modules/' . $mydirname . '/wp-admin/';
|
---|
126 | if (strstr($org_url , $needle)){
|
---|
127 | return true;
|
---|
128 | }
|
---|
129 | }
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 | endif;
|
---|
133 |
|
---|
134 | if ( !function_exists('wp_check_password') ) :
|
---|
135 | // for wordpress2.5
|
---|
136 | function wp_check_password($password, $hash, $user_id = '') {
|
---|
137 | global $wp_hasher;
|
---|
138 | global $xoops_config,$xoops_db;
|
---|
139 |
|
---|
140 | // For attestation when password has been sent as hash value. (When having logged it in from Xoops and ImpressCMS)
|
---|
141 | if ($hash == $password){
|
---|
142 | return apply_filters('check_password', true, $password, $hash, $user_id);
|
---|
143 | }
|
---|
144 |
|
---|
145 | // Password authentication for Xoops
|
---|
146 | if ( strlen($hash) <= 32 ) {
|
---|
147 | $check = ( $hash == md5($password) );
|
---|
148 | return apply_filters('check_password', $check, $password, $hash, $user_id);
|
---|
149 | }
|
---|
150 |
|
---|
151 | // Password authentication for ImpressCMS
|
---|
152 | if($xoops_config->is_impress && function_exists('hash')){
|
---|
153 | $mainSalt = $xoops_config->xoops_db_salt;
|
---|
154 | // get user salt
|
---|
155 | $xpress_user_db = $xoops_config->module_db_prefix . 'users';
|
---|
156 | $xoops_user_db = $xoops_config->xoops_db_prefix . '_users';
|
---|
157 | $login_name = $xoops_db->get_var("SELECT user_login FROM $xpress_user_db WHERE ID = $user_id");
|
---|
158 | $user_salt = $xoops_db->get_var("SELECT salt FROM $xoops_user_db WHERE uname = '$login_name'");
|
---|
159 | // Make Impress hash
|
---|
160 | $impress_hash = hash('sha256', $user_salt.md5($password).$mainSalt);
|
---|
161 | if ($hash == $impress_hash){
|
---|
162 | return apply_filters('check_password', true, $password, $hash, $user_id);
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | // If the hash is still md5...
|
---|
167 | if ( strlen($hash) <= 32 ) {
|
---|
168 | $check = ( $hash == md5($password) );
|
---|
169 | /* A new hash is not used because it differs from the hash on the XOOPS password.
|
---|
170 | * if ( $check && $user_id ) {
|
---|
171 | * // Rehash using new hash.
|
---|
172 | * wp_set_password($password, $user_id);
|
---|
173 | * $hash = wp_hash_password($password);
|
---|
174 | * }
|
---|
175 | */
|
---|
176 | return apply_filters('check_password', $check, $password, $hash, $user_id);
|
---|
177 | }
|
---|
178 |
|
---|
179 | // If the stored hash is longer than an MD5, presume the
|
---|
180 | // new style phpass portable hash.
|
---|
181 | if ( empty($wp_hasher) ) {
|
---|
182 | require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
---|
183 | // By default, use the portable hash from phpass
|
---|
184 | $wp_hasher = new PasswordHash(8, TRUE);
|
---|
185 | }
|
---|
186 |
|
---|
187 | $check = $wp_hasher->CheckPassword($password, $hash);
|
---|
188 |
|
---|
189 | return apply_filters('check_password', $check, $password, $hash, $user_id);
|
---|
190 | }
|
---|
191 | endif;
|
---|
192 |
|
---|
193 | if ( !function_exists('wp_redirect') ) :
|
---|
194 | function wp_redirect($location, $status = 302) {
|
---|
195 | global $is_IIS,$xoops_config,$action;
|
---|
196 |
|
---|
197 | if ($location == 'wp-login.php?loggedout=true') $location = $xoops_config->xoops_url.'/user.php?op=logout'; //xoops logout at wp logout
|
---|
198 | if ($location == 'wp-login.php?action=register') $location = $xoops_config->xoops_url."/register.php"; //wp-register to xoops register
|
---|
199 | if ($action == 'logout') $location = $xoops_config->xoops_url.'/user.php?op=logout'; //xoops logout at comment logout
|
---|
200 |
|
---|
201 | $location = apply_filters('wp_redirect', $location, $status);
|
---|
202 | $status = apply_filters('wp_redirect_status', $status, $location);
|
---|
203 |
|
---|
204 | if ( !$location ) // allows the wp_redirect filter to cancel a redirect
|
---|
205 | return false;
|
---|
206 |
|
---|
207 | $location = wp_sanitize_redirect($location);
|
---|
208 |
|
---|
209 | if ( $is_IIS ) {
|
---|
210 | header("Refresh: 0;url=$location");
|
---|
211 | } else {
|
---|
212 | if ( php_sapi_name() != 'cgi-fcgi' )
|
---|
213 | status_header($status); // This causes problems on IIS and some FastCGI setups
|
---|
214 | header("Location: $location");
|
---|
215 | }
|
---|
216 | }
|
---|
217 | endif;
|
---|
218 |
|
---|
219 | if ( !function_exists('wp_hash_password') ) :
|
---|
220 | function wp_hash_password($password) {
|
---|
221 | global $wp_hasher;
|
---|
222 | return md5($password); // A new hash is not used because it differs from the hash on the XOOPS password.
|
---|
223 | /*
|
---|
224 | if ( empty($wp_hasher) ) {
|
---|
225 | require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
---|
226 | // By default, use the portable hash from phpass
|
---|
227 | $wp_hasher = new PasswordHash(8, TRUE);
|
---|
228 | }
|
---|
229 |
|
---|
230 | return $wp_hasher->HashPassword($password);
|
---|
231 | */
|
---|
232 | }
|
---|
233 | endif;
|
---|
234 |
|
---|
235 | if ( !function_exists('wp_clear_auth_cookie') ) :
|
---|
236 | /**
|
---|
237 | * Removes all of the cookies associated with authentication.
|
---|
238 | *
|
---|
239 | * @since 2.5
|
---|
240 | */
|
---|
241 | function wp_clear_auth_cookie() {
|
---|
242 | do_action('clear_auth_cookie');
|
---|
243 |
|
---|
244 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
|
---|
245 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
|
---|
246 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
|
---|
247 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
|
---|
248 | @setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
---|
249 | @setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
---|
250 |
|
---|
251 | // Old cookies
|
---|
252 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
---|
253 | @setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
---|
254 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
---|
255 | @setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
---|
256 |
|
---|
257 | // Even older cookies
|
---|
258 | @setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
---|
259 | @setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
---|
260 | @setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
---|
261 | @setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
---|
262 | }
|
---|
263 | endif;
|
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 |
|
---|
269 |
|
---|
270 | // *********************************** End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************
|
---|
271 |
|
---|
272 | ?> |
---|