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 |
|
---|
22 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
---|
23 | return false;
|
---|
24 |
|
---|
25 | if ( ! empty($current_user) )
|
---|
26 | return;
|
---|
27 |
|
---|
28 | if (is_xpress_index_page_call()){
|
---|
29 | if (check_xpress_auth_cookie()){ //The cookie is login user's or it checks it
|
---|
30 | if ( $user = wp_validate_auth_cookie() ) {
|
---|
31 | wp_set_current_user($user);
|
---|
32 | return ;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | xpress_login();
|
---|
36 |
|
---|
37 | } else {
|
---|
38 | // WP2.7 original
|
---|
39 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
---|
40 | return false;
|
---|
41 |
|
---|
42 | if ( ! empty($current_user) )
|
---|
43 | return;
|
---|
44 |
|
---|
45 | if ( ! $user = wp_validate_auth_cookie() ) {
|
---|
46 | if ( empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) {
|
---|
47 | wp_set_current_user(0);
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | wp_set_current_user($user);
|
---|
53 | }
|
---|
54 | }
|
---|
55 | endif;
|
---|
56 |
|
---|
57 | function xpress_login(){
|
---|
58 | global $current_user;
|
---|
59 |
|
---|
60 | if(is_object($GLOBALS["xoopsUser"])){
|
---|
61 | $u_name = $GLOBALS["xoopsUser"]->getVar("uname");
|
---|
62 | $u_pass_md5 = $GLOBALS["xoopsUser"]->getVar("pass");
|
---|
63 | if ( ! empty($u_name) && ! empty($u_pass_md5) ) {
|
---|
64 | include_once dirname( __FILE__ ).'/user_sync.php';
|
---|
65 | $messege = '';
|
---|
66 | $ret = xpress_user_sync($GLOBALS["xoopsUser"]->getVar("uid"),$messege);
|
---|
67 | if ($ret){
|
---|
68 | $user = new WP_User(0, $u_name);
|
---|
69 | if ( wp_login($u_name, $u_pass_md5) ) {
|
---|
70 | wp_setcookie($u_name, $u_pass_md5, true, '', '', false);
|
---|
71 | do_action('wp_login', $u_name);
|
---|
72 | wp_set_current_user($user->ID);
|
---|
73 | return true;
|
---|
74 | }
|
---|
75 | }else {
|
---|
76 | echo $messege;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 | wp_set_current_user(0);
|
---|
81 | return 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 | function check_xpress_auth_cookie() { // for wp2.5
|
---|
85 | if ( empty($_COOKIE[AUTH_COOKIE]) ){
|
---|
86 | return false;
|
---|
87 | }
|
---|
88 | $cookie = $_COOKIE[AUTH_COOKIE];
|
---|
89 |
|
---|
90 | $cookie_elements = explode('|', $cookie);
|
---|
91 | if ( count($cookie_elements) != 3 ){
|
---|
92 | return false;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if(is_object($GLOBALS["xoopsModule"])){
|
---|
96 | // && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){
|
---|
97 | if(is_object($GLOBALS["xoopsUser"])){
|
---|
98 | $u_name = $GLOBALS["xoopsUser"]->getVar("uname");
|
---|
99 | list($username, $expiration, $hmac) = $cookie_elements;
|
---|
100 | if ($u_name == $username) {
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | } else {
|
---|
105 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
106 | $org_url = $_SERVER['REQUEST_URI'];
|
---|
107 | $needle = '/modules/' . $mydirname . '/wp-admin/';
|
---|
108 | if (strstr($org_url , $needle)){
|
---|
109 | return true;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | // for wordpress2.5
|
---|
117 | function wp_check_password($password, $hash, $user_id = '') {
|
---|
118 | global $wp_hasher;
|
---|
119 |
|
---|
120 | // If the hash is still md5...
|
---|
121 | if ( strlen($hash) <= 32 ) {
|
---|
122 | if (( $hash == md5($password)) || ($hash == $password)) { // The password taken out of XOOPS is hash value.
|
---|
123 | $check = true;
|
---|
124 | } else {
|
---|
125 | $check = false;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /* A new hash is not used because it differs from the hash on the XOOPS password.
|
---|
129 | * if ( $check && $user_id ) {
|
---|
130 | * // Rehash using new hash.
|
---|
131 | * wp_set_password($password, $user_id);
|
---|
132 | * $hash = wp_hash_password($password);
|
---|
133 | * }
|
---|
134 | */
|
---|
135 | return apply_filters('check_password', $check, $password, $hash, $user_id);
|
---|
136 | }
|
---|
137 |
|
---|
138 | // If the stored hash is longer than an MD5, presume the
|
---|
139 | // new style phpass portable hash.
|
---|
140 | if ( empty($wp_hasher) ) {
|
---|
141 | require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
---|
142 | // By default, use the portable hash from phpass
|
---|
143 | $wp_hasher = new PasswordHash(8, TRUE);
|
---|
144 | }
|
---|
145 |
|
---|
146 | $check = $wp_hasher->CheckPassword($password, $hash);
|
---|
147 |
|
---|
148 | return apply_filters('check_password', $check, $password, $hash, $user_id);
|
---|
149 | }
|
---|
150 |
|
---|
151 | // *********************************** End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************
|
---|
152 |
|
---|
153 | ?> |
---|