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