Changeset 1586077
- Timestamp:
- 01/31/2017 08:54:40 PM (9 years ago)
- Location:
- wp2smfbridge/trunk
- Files:
-
- 2 edited
-
bridge.php (modified) (6 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp2smfbridge/trunk/bridge.php
r1064319 r1586077 5 5 Description: Login bridge for use SMF with WP. For a correct use the users registration and logout is from WP. 6 6 Author: DSR! 7 Version: 1.07 Version: 2.0.0 8 8 Author URI: https://github.com/xchwarze 9 License: GPL 2 or later.9 License: GPL v2 10 10 */ 11 11 12 define('WP_SMFBRIDGE_MYSQLI_DRIVER', function_exists('mysqli_connect'));13 12 class WP_SMFBridge { 14 static $smf_db_user = ''; 15 static $smf_db_passwd = ''; 16 static $smf_db_server = ''; 13 14 /* 15 * CONFIG BLOCK! EDIT AFTER INSTALL 16 */ 17 static $default_activated_value = 0;// Values: 0 Deactivate, 3 Awaiting approval 18 static $is_activated_value = 1; // Values: 1 Activated (in this case by email), 3 Awaiting approval 19 static $cookie_length = '604800'; // Default login cookies length (in seconds) 20 static $localCookies = 0; // Enable local storage of cookies 21 static $globalCookies = 0; // Use subdomain independent cookies 22 static $secureCookies = 0; // Force cookies to be secure (This only applies if you are using HTTPS - don't use otherwise!) 23 static $cookiesConfigFromSMF = false;// Values: true -> read cookies options from SMF database 24 // false -> read config from this file 25 static $smf_path = 'EDIT THIS'; // Forum folder 26 // example 1) forum url: www.forum.com wordpress url: www.forum.com/wp config: $smf_path = '../' 27 // example 2) forum url: www.forum.com/forum wordpress url: www.forum.com config: $smf_path = 'forum/' 28 29 30 31 /*************************************************************************************** 32 * DO NOT EDIT BELOW THIS LINE 33 */ 17 34 static $smf_db_prefix = ''; 18 static $smf_db_name = '';19 35 static $smf_boardurl = ''; 20 36 static $smf_cookiename = ''; 21 static $bridge_loaded = false; 22 static $is_activated_value = ''; 23 static $cookie_length = ''; 24 25 //db functions 26 function dsr_db_open($db_host, $db_user, $db_password, $db_name){ 27 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 28 return mysqli_connect($db_host, $db_user, $db_password, $db_name); 29 else { 30 $link = mysql_connect($db_host, $db_user, $db_password); 31 mysql_select_db($db_name, $link); 32 return $link; 33 } 34 } 35 36 function dsr_db_query($db, $query){ 37 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 38 return mysqli_query($db, $query); 39 else 40 return mysql_query($query, $db); 41 } 42 43 function dsr_db_fetch_assoc($result){ 44 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 45 return mysqli_fetch_assoc($result); 46 else 47 return mysql_fetch_assoc($result); 48 } 49 50 function dsr_db_fetch_array($result){ 51 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 52 return mysqli_fetch_array($result); 53 else 54 return mysql_fetch_array($result); 55 } 56 57 function dsr_db_fetch_row($result){ 58 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 59 return mysqli_fetch_row($result); 60 else 61 return mysql_fetch_row($result); 62 } 63 64 function dsr_db_affected_rows($result) { 65 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 66 return mysqli_affected_rows($result); 67 else 68 return mysql_affected_rows($result); 69 } 70 71 function dsr_db_insert_id($result) { 72 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 73 return mysqli_insert_id($result); 74 else 75 return mysql_insert_id(); 76 } 77 78 function dsr_db_close($db){ 79 if (WP_SMFBRIDGE_MYSQLI_DRIVER) 80 return mysqli_close($db); 81 else 82 return mysql_close($db); 83 } 84 85 //misc 37 static $smf_db = false; 38 39 86 40 function loadConfig(){ 87 $s mf_dir = ABSPATH . get_option('WP2SMF_smfdir');88 if (!file_exists( "{$smf_dir}Settings.php"))41 $settingsFile = ABSPATH . self::$smf_path . 'Settings.php'; 42 if (!file_exists($settingsFile)) { 89 43 return false; 90 91 if (self::$bridge_loaded) 44 } 45 46 if (self::$smf_db) { 92 47 return true; 48 } 93 49 94 require_once "{$smf_dir}Settings.php"; 95 self::$smf_db_user = $db_user; 96 self::$smf_db_passwd = $db_passwd; 97 self::$smf_db_server = $db_server; 50 require $settingsFile; 51 98 52 self::$smf_db_prefix = $db_prefix; 99 self::$smf_db_name = $db_name;100 53 self::$smf_boardurl = $boardurl; 101 54 self::$smf_cookiename = $cookiename; 102 103 self::$bridge_loaded = true; 104 self::$is_activated_value = 1; // Values: 1 Activated (in this case by email), 3 Awaiting approval 105 self::$cookie_length = 3600; 55 self::$smf_db = new wpdb($db_user, $db_passwd, $db_name, $db_server); 106 56 107 57 return true; … … 112 62 } 113 63 114 function smfCheckCookieConfig(){ 115 if (!self::loadConfig()) 116 return false; 117 118 $link = self::dsr_db_open(self::$smf_db_server, self::$smf_db_user, self::$smf_db_passwd, self::$smf_db_name); 119 $query = self::dsr_db_query($link, "SELECT variable, value FROM " . self::$smf_db_prefix . "settings WHERE variable = 'localCookies' OR variable = 'globalCookies'"); 120 while ($row = self::dsr_db_fetch_row($query)) 121 $cookies[ $row[0] ] = $row[1]; 122 123 self::dsr_db_close($link); 124 return $cookies; 125 } 126 127 function smfLogoutByMember($member_name){ 128 if (!self::loadConfig()) 129 return false; 130 131 $localCookies = false; 132 $globalCookies = false; 133 134 $link = self::dsr_db_open(self::$smf_db_server, self::$smf_db_user, self::$smf_db_passwd, self::$smf_db_name); 135 self::dsr_db_query($link, "DELETE FROM " . self::$smf_db_prefix . "log_online WHERE id_member IN (SELECT id_member FROM " . self::$smf_db_prefix . "members WHERE member_name = '{$member_name}') LIMIT 1"); 136 137 $parsed_url = self::smfURLParts($localCookies, $globalCookies); 138 //setcookie('PHPSESSID', $HTTP_COOKIE_VARS['PHPSESSID'], time() - 3600, $parsed_url['path'] . '/', $parsed_url['host'], 0); 139 setcookie(self::$smf_cookiename, '', time() - 3600, $parsed_url['path'] . '/', $parsed_url['host'], 0); 140 unset($_SESSION['login_' . self::$smf_cookiename]); 141 142 self::dsr_db_query($link, "UPDATE " . self::$smf_db_prefix . "members SET pssword_salt = '" . substr(md5(mt_rand()), 0, 4) . "' WHERE member_name = '{$member_name}'"); 143 self::dsr_db_close($link); 144 } 145 146 //based on url_parts (SMF Subs-Auth.php) 147 function smfURLParts($local, $global) { 148 $parsed_url = parse_url(self::$smf_boardurl); 149 150 if (empty($parsed_url['path']) || !$local) 151 $parsed_url['path'] = ''; 152 153 if ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) 154 $parsed_url['host'] = '.' . $parts[1]; 155 else if (!$local && !$global) 156 $parsed_url['host'] = ''; 157 else if (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) 158 $parsed_url['host'] = ''; 159 160 return array($parsed_url['host'], $parsed_url['path'] . '/'); 161 } 162 163 //based on setLoginCookie (SMF Subs-Auth.php) 164 function smfSetLoginCookie($id, $password, $salt) { 165 $localCookies = false; 166 $globalCookies = false; 167 168 $data = serialize(array($id, sha1($password . $salt), time() + self::$cookie_length)); 169 $parsed_url = self::smfURLParts($localCookies, $globalCookies); 170 171 setcookie(self::$smf_cookiename, $data, time() + self::$cookie_length, $parsed_url['path'] . '/', $parsed_url['host'], 0); 172 173 //deleted... 174 // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. 175 // Any alias URLs? This is mainly for use with frames, etc. 176 177 $_COOKIE[self::$smf_cookiename] = $data; 178 $_SESSION['login_' . self::$smf_cookiename] = $data; 179 } 180 181 182 function addInACP() { 183 add_submenu_page('options-general.php', 'WP2SMFBridge Settings', 'WP2SMFBridge', 8, __FILE__, array('WP_SMFBridge', 'settings')); 184 } 185 186 function settings() { 187 load_plugin_textdomain('WP2SMFBridge', false, 'WP2SMFBridge/languages/'); 188 189 if (isset($_POST['action'])) { 190 switch ($_POST['action']) { 191 case "save": 192 if (substr($_POST['smf_realpath'], -1) != '/') 193 $_POST['smf_realpath'] .= '/'; 194 195 if (get_option('WP2SMF_smfdir') === False) 196 add_option('WP2SMF_smfdir', $_POST['smf_realpath']); 197 else 198 update_option('WP2SMF_smfdir', $_POST['smf_realpath']); 199 200 break; 201 202 case "sync": 203 //TODO 204 break; 205 } 206 } 207 208 require dirname(__FILE__) . '/settings.php'; 209 } 210 211 //SMF magic 212 function createUser($login, $email_address, $errors){ 213 if (!self::loadConfig()) 214 return false; 215 216 $link = self::dsr_db_open(self::$smf_db_server, self::$smf_db_user, self::$smf_db_passwd, self::$smf_db_name); 217 218 //checks 219 $result = self::dsr_db_query($link, "SELECT member_name, email_address FROM " . self::$smf_db_prefix . "members WHERE member_name = '{$login}' OR email_address = '{$email_address}'"); 220 while ($row = self::dsr_db_fetch_array($result)){ 221 if ($row['member_name'] === $login) 222 $errors->add('username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.')); 223 224 if ($row['email_address'] === $email_address) 225 $errors->add('email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.')); 226 } 227 228 if (!empty($errors->errors)) 229 return $errors; 230 231 //add 232 $register_vars = array( 233 'member_name' => "'{$login}'", 234 'real_name' => "'{$login}'", 235 'email_address' => "'" . addslashes($user_email) . "'", 236 'passwd' => "'DSR!WP2SMF-Bridge'", 237 'password_salt' => "'" . substr(md5(mt_rand()), 0, 4) . "'", 64 function smfLoadCookieConfig(){ 65 $config = array( 66 'localCookies' => self::$localCookies, 67 'globalCookies' => self::$globalCookies, 68 'secureCookies' => self::$secureCookies, 69 ); 70 71 if (!self::$cookiesConfigFromSMF) { 72 return $config; 73 } 74 75 $sql = "SELECT variable, value " . 76 "FROM " . self::$smf_db_prefix . "settings " . 77 "WHERE variable = 'localCookies' OR variable = 'globalCookies' OR variable = 'secureCookies'"; 78 $results = self::$smf_db->get_results($sql, ARRAY_A); 79 foreach ($results as $row) { 80 $config[ $row['variable'] ] = $row['value']; 81 } 82 83 return $config; 84 } 85 86 function smfAddNewUser($login, $email_address, $passwd) { 87 $insert = array( 88 'member_name' => $login, 89 'real_name' => $login, 90 'email_address' => $email_address, 91 'passwd' => $passwd, 92 'password_salt' => substr(md5(mt_rand()), 0, 4), 238 93 'date_registered' => (string)time(), 239 'is_activated' => '0',94 'is_activated' => self::$default_activated_value, 240 95 'pm_email_notify' => '1', 241 'member_ip' => "'{$_SERVER['HTTP_REFERER']}'",96 'member_ip' => $_SERVER['REMOTE_ADDR'], 242 97 /* 243 98 'posts' => 0, … … 249 104 ); 250 105 251 self::dsr_db_query($link, "INSERT INTO " . self::$smf_db_prefix . "members (" . implode(', ', array_keys($register_vars)) . ") VALUES (" . implode(', ', $register_vars) . ")"); 252 //self::dsr_db_query($link, "INSERT INTO " . self::$smf_db_prefix . "members (" . implode(', ', array_keys($register_vars)) . ") VALUES (" . implode(', ', $register_vars) . ") ON DUPLICATE KEY UPDATE passwd = 'DSR!WP2SMF-Bridge', email_address = '" . addslashes($user_email) . "'"); 253 self::dsr_db_query($link, "REPLACE INTO " . self::$smf_db_prefix . "settings (variable, value) VALUES ('latestMember', " . self::dsr_db_insert_id($link) . "), ('latestRealName', '{$login}')"); 254 self::dsr_db_query($link, "UPDATE " . self::$smf_db_prefix . "settings SET value = value + 1 WHERE variable = 'totalMembers' LIMIT 1"); 255 self::dsr_db_close($link); 106 $result = self::$smf_db->insert(self::$smf_db_prefix . 'members', $insert); 107 if ($result == false) { 108 return; 109 } 110 111 $sql = "REPLACE INTO " . self::$smf_db_prefix . "settings (variable, value) VALUES ('latestMember', %s), ('latestRealName', %s)"; 112 self::$smf_db->query( self::$smf_db->prepare($sql, self::$smf_db->insert_id, $login) ); 113 114 self::$smf_db->query("UPDATE " . self::$smf_db_prefix . "settings SET value = value + 1 WHERE variable = 'totalMembers'"); 115 } 116 117 function smfLogoutByMember($member_name){ 118 if (!self::loadConfig()) { 119 return; 120 } 121 122 $modSettings = self::smfLoadCookieConfig(); 123 124 $sql = "DELETE FROM " . self::$smf_db_prefix . "log_online " . 125 "WHERE id_member IN ( " . 126 "SELECT id_member FROM " . self::$smf_db_prefix . "members WHERE member_name = %s" . 127 ") " . 128 "LIMIT 1"; 129 self::$smf_db->query( self::$smf_db->prepare($sql, $member_name) ); 130 131 $parsed_url = self::smfURLParts($modSettings['localCookies'], $modSettings['globalCookies']); 132 //setcookie('PHPSESSID', $HTTP_COOKIE_VARS['PHPSESSID'], time() - 3600, $parsed_url['path'] . '/', $parsed_url['host'], 0); 133 setcookie(self::$smf_cookiename, '', time() - 3600, $parsed_url['path'] . '/', $parsed_url['host'], 0); 134 unset($_SESSION['login_' . self::$smf_cookiename]); 135 136 $update = array('password_salt' => substr(md5(mt_rand()), 0, 4)); 137 $where = array('member_name' => $member_name ); 138 self::$smf_db->update(self::$smf_db_prefix . 'members', $update, $where); 139 } 140 141 //based on url_parts (SMF Subs-Auth.php) 142 function smfURLParts($local, $global) { 143 //global $boardurl; 144 145 // Parse the URL with PHP to make life easier. 146 //$parsed_url = parse_url($boardurl); 147 $parsed_url = parse_url(self::$smf_boardurl); 148 149 // Is local cookies off? 150 if (empty($parsed_url['path']) || !$local) 151 $parsed_url['path'] = ''; 152 153 // Globalize cookies across domains (filter out IP-addresses)? 154 if ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) 155 $parsed_url['host'] = '.' . $parts[1]; 156 157 // We shouldn't use a host at all if both options are off. 158 elseif (!$local && !$global) 159 $parsed_url['host'] = ''; 160 161 // The host also shouldn't be set if there aren't any dots in it. 162 elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) 163 $parsed_url['host'] = ''; 164 165 return array($parsed_url['host'], $parsed_url['path'] . '/'); 166 } 167 168 //based on setLoginCookie (SMF Subs-Auth.php) 169 function smfSetLoginCookie($id, $password, $salt) { 170 $modSettings = self::smfLoadCookieConfig(); 171 $password = sha1($password . $salt); 172 173 //global $cookiename, $boardurl, $modSettings; 174 175 // If changing state force them to re-address some permission caching. 176 //$_SESSION['mc']['time'] = 0; 177 178 // The cookie may already exist, and have been set with different options. 179 $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2); 180 /*if (isset($_COOKIE[self::$smf_cookiename]) && preg_match('~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:"\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~', $_COOKIE[self::$smf_cookiename]) === 1) 181 { 182 $array = safe_unserialize($_COOKIE[self::$smf_cookiename]); 183 184 // Out with the old, in with the new! 185 if (isset($array[3]) && $array[3] != $cookie_state) 186 { 187 $cookie_url = self::smfURLParts($array[3] & 1 > 0, $array[3] & 2 > 0); 188 setcookie(self::$smf_cookiename, serialize(array(0, '', 0)), time() - 3600, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); 189 } 190 }*/ 191 192 // Get the data and path to set it on. 193 $data = serialize(empty($id) ? array(0, '', 0) : array($id, $password, time() + self::$cookie_length, $cookie_state)); 194 $cookie_url = self::smfURLParts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); 195 196 // Set the cookie, $_COOKIE, and session variable. 197 setcookie(self::$smf_cookiename, $data, time() + self::$cookie_length, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); 198 199 // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. 200 if (empty($id) && !empty($modSettings['globalCookies'])) 201 setcookie(self::$smf_cookiename, $data, time() + self::$cookie_length, $cookie_url[1], '', !empty($modSettings['secureCookies'])); 202 203 // Any alias URLs? This is mainly for use with frames, etc. 204 /*if (!empty($modSettings['forum_alias_urls'])) 205 { 206 $aliases = explode(',', $modSettings['forum_alias_urls']); 207 208 $temp = $boardurl; 209 foreach ($aliases as $alias) 210 { 211 // Fake the $boardurl so we can set a different cookie. 212 $alias = strtr(trim($alias), array('http://' => '', 'https://' => '')); 213 $boardurl = 'http://' . $alias; 214 215 $cookie_url = self::smfURLParts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); 216 217 if ($cookie_url[0] == '') 218 $cookie_url[0] = strtok($alias, '/'); 219 220 setcookie(self::$smf_cookiename, $data, time() + self::$cookie_length, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); 221 } 222 223 $boardurl = $temp; 224 }*/ 225 226 $_COOKIE[self::$smf_cookiename] = $data; 227 228 // Make sure the user logs in with a new session ID. 229 /*if (!isset($_SESSION['login_' . self::$smf_cookiename]) || $_SESSION['login_' . self::$smf_cookiename] !== $data) 230 { 231 // Backup and remove the old session. 232 $oldSessionData = $_SESSION; 233 $_SESSION = array(); 234 session_destroy(); 235 236 // Recreate and restore the new session. 237 loadSession(); 238 session_regenerate_id(); 239 $_SESSION = $oldSessionData; 240 241 // Version 4.3.2 didn't store the cookie of the new session. 242 if (version_compare(PHP_VERSION, '4.3.2') === 0) 243 { 244 $sessionCookieLifetime = @ini_get('session.cookie_lifetime'); 245 setcookie(session_name(), session_id(), time() + (empty($sessionCookieLifetime) ? self::$cookie_length : $sessionCookieLifetime), $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); 246 } 247 248 $_SESSION['login_' . self::$smf_cookiename] = $data; 249 }*/ 250 } 251 252 //SMF magic 253 function createUser($login, $email_address, $errors){ 254 if (!self::loadConfig()) { 255 return; 256 } 257 258 //checks 259 $sql = "SELECT member_name, email_address " . 260 "FROM " . self::$smf_db_prefix . "members " . 261 "WHERE member_name = %s OR email_address = %s"; 262 $results = self::$smf_db->get_results(self::$smf_db->prepare($sql, $login, $email_address), ARRAY_A); 263 foreach ($results as $row) { 264 if ($row['member_name'] === $login) { 265 $errors->add('username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.')); 266 } 267 268 if ($row['email_address'] === $email_address) { 269 $errors->add('email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.')); 270 } 271 } 272 273 if (!empty($errors->errors)) { 274 return $errors; 275 } 276 277 //add 278 $passwd = 'DSR!WP2SMF-Bridge'; //como no tengo el pass aun lo marco asi 279 self::smfAddNewUSer($login, $email_address, $passwd); 280 } 281 282 function smfGetUserLoginInfo($login) { 283 $sql = "SELECT id_member, passwd, password_salt " . 284 "FROM " . self::$smf_db_prefix . "members " . 285 "WHERE member_name = %s"; 286 return self::$smf_db->get_row( self::$smf_db->prepare($sql, $login), ARRAY_A ); 256 287 } 257 288 258 289 function authenticateUser($login, $pass){ 259 if ((empty($login) || empty($pass)) || !self::loadConfig()) 260 return false; 290 if ((empty($login) || empty($pass)) || !self::loadConfig()) { 291 return; 292 } 261 293 262 294 $passwd = self::smfPassword($login, $pass); 263 $link = self::dsr_db_open(self::$smf_db_server, self::$smf_db_user, self::$smf_db_passwd, self::$smf_db_name); 264 self::dsr_db_query($link, "UPDATE " . self::$smf_db_prefix . "members SET is_activated = '" . self::$is_activated_value . "', passwd = '{$passwd}' WHERE member_name = '{$login}' AND passwd = 'DSR!WP2SMF-Bridge' LIMIT 1"); 265 266 //Oh my God, that's the funky sh... 267 $user = self::dsr_db_fetch_assoc(self::dsr_db_query($link, "SELECT id_member, passwd, password_salt FROM " . self::$smf_db_prefix . "members WHERE member_name = '{$login}' AND passwd = '{$passwd}' LIMIT 1")); 268 self::dsr_db_close($link); 295 296 // si es el primer login actualizo el pass y el estado de la cuenta en smf para que pueda loggearse si apago el plugin 297 $update = array('last_login' => (string)time(), 'passwd' => $passwd, 'is_activated' => self::$is_activated_value); 298 $where = array('member_name' => $login); 299 self::$smf_db->update(self::$smf_db_prefix . 'members', $update, $where); 300 301 // loggeo el user 302 $user = self::smfGetUserLoginInfo($login); 303 if (!$user) { 304 $wp_user = wp_get_current_user(); 305 self::smfAddNewUser($login, $wp_user->user_email, $passwd); 306 $user = self::smfGetUserLoginInfo($login); 307 if (!$user) { 308 return; 309 } 310 } 311 269 312 self::smfSetLoginCookie($user['id_member'], $user['passwd'], $user['password_salt']); 270 313 } 271 314 272 function passReset($login, $pass){273 $link = self::dsr_db_open(self::$smf_db_server, self::$smf_db_user, self::$smf_db_passwd, self::$smf_db_name);274 $ret = self::dsr_db_query($link, "UPDATE " . self::$smf_db_prefix . "members SET passwd = '" . self::smfPassword($login, $pass) . "' WHERE member_name = '{$login}' LIMIT 1");275 self::dsr_db_close($link);276 return $ret;277 }278 279 315 function userPassReset($user, $pass){ 280 if (empty($pass) || !self::loadConfig()) 281 return false; 282 283 self::passReset($user->data->user_login, $pass); 316 if (empty($pass) || !self::loadConfig()) { 317 return; 318 } 319 320 $update = array('passwd' => self::smfPassword($user->data->user_login, $pass)); 321 $where = array('member_name' => $user->data->user_login ); 322 self::$smf_db->update(self::$smf_db_prefix . 'members', $update, $where); 284 323 } 285 324 286 325 function userEditProfile($user_id, $old_user_data){ 287 if (empty($_POST['pass1']) || !self::loadConfig()) 288 return false; 289 290 self::passReset($old_user_data->user_login, $_POST['pass1']); 326 if (!self::loadConfig()) { 327 return; 328 } 329 330 $update = array(); 331 332 //contrastes fix 333 if (!empty($_POST['user_pass'])) { 334 $_POST['pass1'] = $_POST['user_pass']; 335 } 336 337 if (!empty($_POST['user_email'])) { 338 $_POST['email'] = $_POST['user_email']; 339 } 340 341 // password change 342 if (!empty($_POST['pass1'])) { 343 $update['passwd'] = self::smfPassword($old_user_data->user_login, $_POST['pass1']); 344 } 345 346 // email change 347 if ($old_user_data->user_email !== $_POST['email']) { 348 $update['email_address'] = $_POST['email']; 349 } 350 351 if (empty($update)) { 352 return; 353 } 354 355 $where = array('member_name' => $old_user_data->user_login); 356 self::$smf_db->update(self::$smf_db_prefix . 'members', $update, $where); 291 357 } 292 358 … … 297 363 298 364 function authenticateWPCookie($cookie_elements, $user){ 299 if (!self::loadConfig() || isset($_SESSION['login_' . self::$smf_cookiename])) 300 return false; 301 302 $link = self::dsr_db_open(self::$smf_db_server, self::$smf_db_user, self::$smf_db_passwd, self::$smf_db_name); 303 $user = self::dsr_db_fetch_assoc(self::dsr_db_query($link, "SELECT id_member, passwd, password_salt FROM " . self::$smf_db_prefix . "members WHERE member_name = '{$user->data->user_login}' LIMIT 1")); 304 self::dsr_db_close($link); 305 self::smfSetLoginCookie($user['id_member'], $user['passwd'], $user['password_salt']); 365 if (!$user || isset($_SESSION['login_' . self::$smf_cookiename]) || !self::loadConfig()) { 366 return; 367 } 368 369 $user = self::smfGetUserLoginInfo($user->data->user_login); 370 if ($user) { 371 self::smfSetLoginCookie($user['id_member'], $user['passwd'], $user['password_salt']); 372 } 373 } 374 375 function deleteUser($id, $reassign){ 376 if (!self::loadConfig()) { 377 return; 378 } 379 380 $user = new WP_User($id); 381 382 $sql = "DELETE FROM " . self::$smf_db_prefix . "members WHERE member_name = %s"; 383 self::$smf_db->query( self::$smf_db->prepare($sql, $user->user_login) ); 384 385 $sql = "UPDATE " . self::$smf_db_prefix . "settings SET value = value - 1 WHERE variable = 'totalMembers'"; 386 self::$smf_db->query($sql); 306 387 } 307 388 } … … 309 390 310 391 // Hooks! 311 add_action('admin_menu', array('WP_SMFBridge', 'addInACP'));312 392 add_action('register_post', array('WP_SMFBridge', 'createUser'), 100, 3); 313 393 add_action('wp_authenticate', array('WP_SMFBridge', 'authenticateUser'), 100, 2); … … 316 396 add_action('wp_logout', array('WP_SMFBridge', 'logoutUser')); 317 397 add_action('auth_cookie_valid', array('WP_SMFBridge', 'authenticateWPCookie'), 100, 2); 398 add_action('delete_user', array('WP_SMFBridge', 'deleteUser'), 100, 2); 318 399 ?> -
wp2smfbridge/trunk/readme.txt
r1067387 r1586077 4 4 Tags: smf, forums, users, bridge, wordpress 5 5 Requires at least: 2.5 6 Tested up to: 4. 17 Stable tag: 1. 08 License: GPL v2 or later6 Tested up to: 4.7 7 Stable tag: 1.1 8 License: GPL v2 9 9 10 10 Login bridge from Wordpress to Simple Machine Forum. … … 22 22 * Users that are created in SMF can be used once disabled WP plugin. 23 23 * For a full way integration use with SMF2WPBridge plugin. 24 https://github.com/xchwarze/SMF2WPBridge 25 http://custom.simplemachines.org/mods/index.php?mod=4030 24 26 25 27 … … 33 35 2. Uncheck "Enable local storage of cookies" and "Use subdomain independent cookie" in SMF. You can turn it off from Admin -> Configuration -> Server Settings -> Cookies and Sessions 34 36 3. Activate the plugin through the 'Plugins' menu in WordPress 35 4. Visit WP2SMFBridge Settings in your Admin Settings section, enter path to your forum, then Save it. If it is accessible, then at this point, WP2SMFBridge is fully activated.37 4. Edit plugin with edit link. Enter path to your forum, then Save it. If it is accessible, then at this point, WP2SMFBridge is fully activated. 36 38 37 39 … … 59 61 * First public version 60 62 63 = 1.1 = 64 * Bug fixes 65 66 = 2.0 = 67 * Rebuilt all code 68 * Use wpdb for all querys 69 * Add private fixes 70 61 71 62 72 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.