[71] | 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 |
|
---|
[87] | 23 | if ($xoopsModule){
|
---|
[114] | 24 | if (!is_object($xoopsUser)){
|
---|
| 25 | wp_set_current_user(0);
|
---|
[216] | 26 | wp_clearcookie();
|
---|
| 27 |
|
---|
[173] | 28 | // wp_logout(); // When IE is used, it becomes page error by the guest if the wp_logout() is executed here.
|
---|
[114] | 29 | return false;
|
---|
| 30 | }
|
---|
[87] | 31 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
---|
| 32 | return false;
|
---|
[71] | 33 |
|
---|
[114] | 34 | if ( ! empty($current_user) ){
|
---|
| 35 | $xoops_user = $xoopsUser->getVar("uname");
|
---|
| 36 | if ($current_user->user_login == $xoops_user)
|
---|
| 37 | return;
|
---|
| 38 | }
|
---|
[71] | 39 |
|
---|
| 40 | if (check_xpress_auth_cookie()){ //The cookie is login user's or it checks it
|
---|
| 41 | if ( $user = wp_validate_auth_cookie() ) {
|
---|
[175] | 42 | if (!check_user_meta_prefix($user)){
|
---|
| 43 | repair_user_meta_prefix();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[71] | 46 | wp_set_current_user($user);
|
---|
| 47 | return ;
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
[87] | 50 | xpress_login();
|
---|
[71] | 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 |
|
---|
[96] | 72 | if ( !function_exists('xpress_login') ) :
|
---|
[71] | 73 | function xpress_login(){
|
---|
| 74 | global $current_user;
|
---|
[130] | 75 | global $xoopsModule,$xoopsUser,$xoopsUserIsAdmin;
|
---|
[71] | 76 |
|
---|
[130] | 77 | if(is_object($xoopsUser)){
|
---|
| 78 | $u_name = $xoopsUser->getVar("uname");
|
---|
| 79 | $u_pass_md5 = $xoopsUser->getVar("pass");
|
---|
[87] | 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 = '';
|
---|
[130] | 84 | $ret = user_sync_to_wordpress($xoopsUser->getVar("uid"),$messege);
|
---|
[87] | 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;
|
---|
[71] | 92 | }
|
---|
| 93 | }
|
---|
[87] | 94 | }
|
---|
| 95 | }
|
---|
| 96 | wp_set_current_user(0);
|
---|
| 97 | return 0;
|
---|
[71] | 98 | }
|
---|
[96] | 99 | endif;
|
---|
[71] | 100 |
|
---|
[96] | 101 | if ( !function_exists('check_xpress_auth_cookie') ) :
|
---|
[71] | 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 | }
|
---|
[96] | 132 | endif;
|
---|
[71] | 133 |
|
---|
[83] | 134 | if ( !function_exists('wp_check_password') ) :
|
---|
[71] | 135 | // for wordpress2.5
|
---|
| 136 | function wp_check_password($password, $hash, $user_id = '') {
|
---|
| 137 | global $wp_hasher;
|
---|
[131] | 138 | global $xoops_config,$xoops_db;
|
---|
[71] | 139 |
|
---|
[131] | 140 | // For attestation when password has been sent as hash value. (When having logged it in from Xoops and ImpressCMS)
|
---|
| 141 | if ($hash == $password){
|
---|
[130] | 142 | return apply_filters('check_password', true, $password, $hash, $user_id);
|
---|
| 143 | }
|
---|
[131] | 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 |
|
---|
[71] | 166 | // If the hash is still md5...
|
---|
| 167 | if ( strlen($hash) <= 32 ) {
|
---|
[130] | 168 | $check = ( $hash == md5($password) );
|
---|
[71] | 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 | }
|
---|
[83] | 191 | endif;
|
---|
[71] | 192 |
|
---|
[83] | 193 | if ( !function_exists('wp_redirect') ) :
|
---|
[71] | 194 | function wp_redirect($location, $status = 302) {
|
---|
[123] | 195 | global $is_IIS,$xoops_config,$action;
|
---|
[71] | 196 |
|
---|
[114] | 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
|
---|
[123] | 199 | if ($action == 'logout') $location = $xoops_config->xoops_url.'/user.php?op=logout'; //xoops logout at comment logout
|
---|
[71] | 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 | }
|
---|
[83] | 217 | endif;
|
---|
[71] | 218 |
|
---|
[83] | 219 | if ( !function_exists('wp_hash_password') ) :
|
---|
[71] | 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 | }
|
---|
[83] | 233 | endif;
|
---|
[153] | 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 |
|
---|
[71] | 270 | // *********************************** End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************
|
---|
| 271 |
|
---|
| 272 | ?> |
---|