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