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