[23] | 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 |
|
---|
| 21 | if (is_root_index_page_call()){
|
---|
| 22 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
---|
| 23 | return false;
|
---|
| 24 |
|
---|
| 25 | if ( ! empty($current_user) )
|
---|
| 26 | return;
|
---|
| 27 |
|
---|
| 28 | if (check_xpress_auth_cookie()){
|
---|
| 29 | if ( $user = wp_validate_auth_cookie() ) {
|
---|
| 30 | wp_set_current_user($user);
|
---|
| 31 | return ;
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | xpress_login();
|
---|
| 35 | }else {
|
---|
| 36 | // WP2.7 original
|
---|
| 37 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
---|
| 38 | return false;
|
---|
| 39 |
|
---|
| 40 | if ( ! empty($current_user) )
|
---|
| 41 | return;
|
---|
| 42 |
|
---|
| 43 | if ( ! $user = wp_validate_auth_cookie() ) {
|
---|
| 44 | if ( empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) {
|
---|
| 45 | wp_set_current_user(0);
|
---|
| 46 | return false;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | wp_set_current_user($user);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | endif;
|
---|
| 54 |
|
---|
| 55 | function xpress_login(){
|
---|
| 56 | global $current_user;
|
---|
| 57 |
|
---|
| 58 | if(is_object($GLOBALS["xoopsUser"])){
|
---|
| 59 | $u_name = $GLOBALS["xoopsUser"]->getVar("uname");
|
---|
| 60 | $u_pass_md5 = $GLOBALS["xoopsUser"]->getVar("pass");
|
---|
| 61 | if ( ! empty($u_name) && ! empty($u_pass_md5) ) {
|
---|
| 62 | // include_once dirname( __FILE__ ).'/xpress_user.php';
|
---|
| 63 | // $mess = xpress_user_sync($GLOBALS["xoopsUser"]->getVar("uid"));
|
---|
| 64 | // if ($mess != 'NOT XPRESS USER'){
|
---|
| 65 | $user = new WP_User(0, $u_name);
|
---|
| 66 | if ( wp_login($u_name, $u_pass_md5, true) ) {
|
---|
| 67 | wp_setcookie($u_name, $u_pass_md5, true, '', '', false);
|
---|
| 68 | do_action('wp_login', $u_name);
|
---|
| 69 | wp_set_current_user($user->ID);
|
---|
| 70 | return true;
|
---|
| 71 | }
|
---|
| 72 | // }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | wp_set_current_user(0);
|
---|
| 76 | return 0;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | function check_xpress_auth_cookie() { // for wp2.5
|
---|
| 80 | if ( empty($_COOKIE[AUTH_COOKIE]) ){
|
---|
| 81 | return false;
|
---|
| 82 | }
|
---|
| 83 | $cookie = $_COOKIE[AUTH_COOKIE];
|
---|
| 84 |
|
---|
| 85 | $cookie_elements = explode('|', $cookie);
|
---|
| 86 | if ( count($cookie_elements) != 3 ){
|
---|
| 87 | return false;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | if(is_object($GLOBALS["xoopsModule"]) && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){
|
---|
| 91 | if(is_object($GLOBALS["xoopsUser"])){
|
---|
| 92 | $u_name = $GLOBALS["xoopsUser"]->getVar("uname");
|
---|
| 93 | list($username, $expiration, $hmac) = $cookie_elements;
|
---|
| 94 | if ($u_name == $username) {
|
---|
| 95 | return true;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | } else {
|
---|
| 99 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
| 100 | $org_url = $_SERVER['REQUEST_URI'];
|
---|
| 101 | $needle = '/modules/' . $mydirname . '/wp-admin/';
|
---|
| 102 | if (strstr($org_url , $needle)){
|
---|
| 103 | return true;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | return false;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | /*
|
---|
| 111 |
|
---|
| 112 | function wp_login($username, $password, $already_md5 = false) {
|
---|
| 113 | global $wpdb, $error;
|
---|
| 114 |
|
---|
| 115 | $username = sanitize_user($username);
|
---|
| 116 |
|
---|
| 117 | if ( '' == $username )
|
---|
| 118 | return false;
|
---|
| 119 |
|
---|
| 120 | if ( '' == $password ) {
|
---|
| 121 | $error = __('<strong>ERROR</strong>: The password field is empty.');
|
---|
| 122 | return false;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | $login = get_userdatabylogin($username);
|
---|
| 126 | //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
|
---|
| 127 |
|
---|
| 128 | if (!$login) {
|
---|
| 129 | $error = __('<strong>ERROR</strong>: Invalid username.');
|
---|
| 130 | return false;
|
---|
| 131 | } else {
|
---|
| 132 | if ($login->user_login == $username) {
|
---|
| 133 | if ($login->user_pass == $password) return true;
|
---|
| 134 | if ($login->user_pass == md5($password)) return true;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | $error = __('<strong>ERROR</strong>: Incorrect password.');
|
---|
| 138 | $pwd = '';
|
---|
| 139 | return false;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | */
|
---|
| 143 |
|
---|
| 144 | // for wordpress2.5
|
---|
| 145 | function wp_check_password($password, $hash, $user_id = '') {
|
---|
| 146 | global $wp_hasher;
|
---|
| 147 |
|
---|
| 148 | // If the hash is still md5...
|
---|
| 149 | if ( strlen($hash) <= 32 ) {
|
---|
[65] | 150 | if (( $hash == md5($password)) || ($hash == $password)) { // The password taken out of XOOPS is hash value.
|
---|
[23] | 151 | $check = true;
|
---|
| 152 | } else {
|
---|
| 153 | $check = false;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[65] | 156 | /* A new hash is not used because it differs from the hash on the XOOPS password.
|
---|
| 157 | * if ( $check && $user_id ) {
|
---|
| 158 | * // Rehash using new hash.
|
---|
| 159 | * wp_set_password($password, $user_id);
|
---|
| 160 | * $hash = wp_hash_password($password);
|
---|
| 161 | * }
|
---|
| 162 | */
|
---|
[23] | 163 | return apply_filters('check_password', $check, $password, $hash, $user_id);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | // If the stored hash is longer than an MD5, presume the
|
---|
| 167 | // new style phpass portable hash.
|
---|
| 168 | if ( empty($wp_hasher) ) {
|
---|
| 169 | require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
---|
| 170 | // By default, use the portable hash from phpass
|
---|
| 171 | $wp_hasher = new PasswordHash(8, TRUE);
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | $check = $wp_hasher->CheckPassword($password, $hash);
|
---|
| 175 |
|
---|
| 176 | return apply_filters('check_password', $check, $password, $hash, $user_id);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | /*
|
---|
| 181 |
|
---|
| 182 | function wp_mail($to, $subject, $message, $from_email="", $from_name="") {
|
---|
| 183 | $xoopsMailer =& getMailer();
|
---|
| 184 | $xoopsMailer->useMail();
|
---|
| 185 | $xoopsMailer->setToEmails($to);
|
---|
| 186 | $xoopsMailer->setFromEmail( empty($from_email) ? $GLOBALS["xoopsConfig"]['adminmail'] : $from_email);
|
---|
| 187 | $xoopsMailer->setFromName( empty($from_name) ? $GLOBALS["xoopsConfig"]['sitename'] : $from_name );
|
---|
| 188 | $xoopsMailer->setSubject($subject);
|
---|
| 189 | $xoopsMailer->setBody($message);
|
---|
| 190 | return $xoopsMailer->send();
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | */
|
---|
| 194 | /*
|
---|
| 195 | function auth_redirect($force = false, $message = "") {
|
---|
| 196 | if(!is_object($GLOBALS["xoopsUser"])){
|
---|
| 197 | header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
|
---|
| 198 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
---|
| 199 | header('Cache-Control: no-cache, must-revalidate, max-age=0');
|
---|
| 200 | header('Pragma: no-cache');
|
---|
| 201 |
|
---|
| 202 | header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
|
---|
| 203 | exit();
|
---|
| 204 | }elseif(!empty($force)){
|
---|
| 205 | $redirect = xoops_getenv("HTTP_REFERER");
|
---|
| 206 | $redirect = (strpos($redirect, XOOPS_URL) === 0)? $redirect: XOOPS_URL."/".$redirect;
|
---|
| 207 | redirect_header($redirect, 2, $message);
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 | */
|
---|
| 211 | // *********************************** End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************
|
---|
| 212 |
|
---|
| 213 | ?> |
---|