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