| [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 ) {
 | 
|---|
 | 150 |                 if (( $hash == md5($password)) || ($hash == $password)) {
 | 
|---|
 | 151 |                         $check = true;
 | 
|---|
 | 152 |                 } else {
 | 
|---|
 | 153 |                         $check = false;
 | 
|---|
 | 154 |                 }
 | 
|---|
 | 155 | 
 | 
|---|
 | 156 |                 if ( $check && $user_id ) {
 | 
|---|
 | 157 |                         // Rehash using new hash.
 | 
|---|
 | 158 |                         wp_set_password($password, $user_id);
 | 
|---|
 | 159 |                         $hash = wp_hash_password($password);
 | 
|---|
 | 160 |                 }
 | 
|---|
 | 161 | 
 | 
|---|
 | 162 |                 return apply_filters('check_password', $check, $password, $hash, $user_id);
 | 
|---|
 | 163 |         }
 | 
|---|
 | 164 | 
 | 
|---|
 | 165 |         // If the stored hash is longer than an MD5, presume the
 | 
|---|
 | 166 |         // new style phpass portable hash.
 | 
|---|
 | 167 |         if ( empty($wp_hasher) ) {
 | 
|---|
 | 168 |                 require_once( ABSPATH . 'wp-includes/class-phpass.php');
 | 
|---|
 | 169 |                 // By default, use the portable hash from phpass
 | 
|---|
 | 170 |                 $wp_hasher = new PasswordHash(8, TRUE);
 | 
|---|
 | 171 |         }
 | 
|---|
 | 172 | 
 | 
|---|
 | 173 |         $check = $wp_hasher->CheckPassword($password, $hash);
 | 
|---|
 | 174 | 
 | 
|---|
 | 175 |         return apply_filters('check_password', $check, $password, $hash, $user_id);
 | 
|---|
 | 176 | }
 | 
|---|
 | 177 | 
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | /*
 | 
|---|
 | 180 | 
 | 
|---|
 | 181 | function wp_mail($to, $subject, $message, $from_email="", $from_name="") {
 | 
|---|
 | 182 |     $xoopsMailer =& getMailer();
 | 
|---|
 | 183 |     $xoopsMailer->useMail();
 | 
|---|
 | 184 |     $xoopsMailer->setToEmails($to);
 | 
|---|
 | 185 |     $xoopsMailer->setFromEmail( empty($from_email) ? $GLOBALS["xoopsConfig"]['adminmail'] : $from_email);
 | 
|---|
 | 186 |     $xoopsMailer->setFromName( empty($from_name) ? $GLOBALS["xoopsConfig"]['sitename'] : $from_name );
 | 
|---|
 | 187 |     $xoopsMailer->setSubject($subject);
 | 
|---|
 | 188 |     $xoopsMailer->setBody($message);
 | 
|---|
 | 189 |     return $xoopsMailer->send();
 | 
|---|
 | 190 | }
 | 
|---|
 | 191 | 
 | 
|---|
 | 192 | */
 | 
|---|
 | 193 | /*
 | 
|---|
 | 194 | function auth_redirect($force = false, $message = "") {
 | 
|---|
 | 195 |         if(!is_object($GLOBALS["xoopsUser"])){
 | 
|---|
 | 196 |                 header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
 | 
|---|
 | 197 |                 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
 | 
|---|
 | 198 |                 header('Cache-Control: no-cache, must-revalidate, max-age=0');
 | 
|---|
 | 199 |                 header('Pragma: no-cache');
 | 
|---|
 | 200 |         
 | 
|---|
 | 201 |                 header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
 | 
|---|
 | 202 |                 exit();
 | 
|---|
 | 203 |         }elseif(!empty($force)){
 | 
|---|
 | 204 |                 $redirect = xoops_getenv("HTTP_REFERER");
 | 
|---|
 | 205 |                 $redirect = (strpos($redirect, XOOPS_URL) === 0)? $redirect: XOOPS_URL."/".$redirect;
 | 
|---|
 | 206 |                 redirect_header($redirect, 2, $message);
 | 
|---|
 | 207 |         }
 | 
|---|
 | 208 | }
 | 
|---|
 | 209 | */
 | 
|---|
 | 210 | // ***********************************  End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************
 | 
|---|
 | 211 | 
 | 
|---|
 | 212 | ?> | 
|---|