diff --git a/[ >= 3.1. ] EXTENSION/oneall/sociallogin/acp/sociallogin_acp_module.php b/[ >= 3.1. ] EXTENSION/oneall/sociallogin/acp/sociallogin_acp_module.php index 091004d..a9ad59b 100644 --- a/[ >= 3.1. ] EXTENSION/oneall/sociallogin/acp/sociallogin_acp_module.php +++ b/[ >= 3.1. ] EXTENSION/oneall/sociallogin/acp/sociallogin_acp_module.php @@ -27,38 +27,38 @@ class sociallogin_acp_module { // Version - const USER_AGENT = 'SocialLogin/2.7 phpBB/3.1.x (+http://www.oneall.com/)'; - + const USER_AGENT = 'SocialLogin/2.8 phpBB/3.1.x (+http://www.oneall.com/)'; + // @var \phpbb\config\config protected $config; - + // @var \phpbb\config\db_text protected $config_text; - + // @var \phpbb\db\driver\driver_interface protected $db; - + // @var \phpbb\log\log protected $log; - + // @var \phpbb\request\request protected $request; - + // @var \phpbb\template\template protected $template; - + // @var \phpbb\user protected $user; - + // @var ContainerInterface protected $phpbb_container; - + // @var string protected $phpbb_root_path; - + // @var string protected $php_ext; - + // @var string public $u_action; @@ -68,21 +68,21 @@ class sociallogin_acp_module public function main ($id, $mode) { global $request; - + // Task that needs to be done $task = $request->variable('task', ''); - + // Tasks switch ($task) { // Verify API settings. case 'verify_api_settings' : return $this->admin_ajax_verify_api_settings (); - + // Autodetect API connection. case 'autodetect_api_connection' : return $this->admin_ajax_autodetect_api_connection (); - + // Show Settings. default: return $this->admin_main (); @@ -95,27 +95,27 @@ public function main ($id, $mode) public function admin_main () { global $db, $user, $auth, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $request; - + // Add the language file. $user->add_lang_ext ('oneall/sociallogin', 'backend'); - + // Set up the page $this->tpl_name = 'sociallogin'; $this->page_title = $user->lang ['OA_SOCIAL_LOGIN_ACP']; - + // Enable Social Login? $oa_social_login_disable = ((isset ($config ['oa_social_login_disable']) && $config ['oa_social_login_disable'] == '1') ? '1' : '0'); - + // API Connection $oa_social_login_api_connection_handler = ((isset ($config ['oa_social_login_api_connection_handler']) && $config ['oa_social_login_api_connection_handler'] == 'fsockopen') ? 'fsockopen' : 'curl'); $oa_social_login_api_connection_port = ((isset ($config ['oa_social_login_api_connection_port']) && $config ['oa_social_login_api_connection_port'] == 80) ? 80 : 443); $oa_social_login_api_subdomain = (isset ($config ['oa_social_login_api_subdomain']) ? $config ['oa_social_login_api_subdomain'] : ''); $oa_social_login_api_key = (isset ($config ['oa_social_login_api_key']) ? $config ['oa_social_login_api_key'] : ''); $oa_social_login_api_secret = (isset ($config ['oa_social_login_api_secret']) ? $config ['oa_social_login_api_secret'] : ''); - + // Social Networks. $oa_social_login_providers = (isset ($config ['oa_social_login_providers']) ? explode (",", $config ['oa_social_login_providers']) : array()); - + // Profile Validation. if (isset ($config ['oa_social_login_validate']) && $config ['oa_social_login_validate'] == '1') { @@ -129,16 +129,16 @@ public function admin_main () { $oa_social_login_validate = 0; } - + // Social Link. $oa_social_login_disable_linking = ((isset ($config ['oa_social_login_disable_linking']) && $config ['oa_social_login_disable_linking'] == '1') ? '1' : '0'); - + // Upload Avatars. $oa_social_login_avatars_enable = ((isset ($config ['oa_social_login_avatars_enable']) && $config ['oa_social_login_avatars_enable'] == '1') ? '1' : '0'); - + // Redirection. $oa_social_login_redirect = (isset ($config ['oa_social_login_redirect']) ? $config ['oa_social_login_redirect'] : ''); - + // Login Page. $oa_social_login_login_page_disable = ((isset ($config ['oa_social_login_login_page_disable']) && $config ['oa_social_login_login_page_disable'] == '1') ? '1' : '0'); $oa_social_login_login_page_caption = (isset ($config ['oa_social_login_login_page_caption']) ? $config ['oa_social_login_login_page_caption'] : 'Login with your social network account'); @@ -146,50 +146,50 @@ public function admin_main () // Login Page - Inline. $oa_social_login_inline_page_disable = ((isset ($config ['oa_social_login_inline_page_disable']) && $config ['oa_social_login_inline_page_disable'] == '1') ? '1' : '0'); $oa_social_login_inline_page_caption = (isset ($config ['oa_social_login_inline_page_caption']) ? $config ['oa_social_login_inline_page_caption'] : 'or Login with your social network account'); - + // Registration Page. $oa_social_login_registration_page_disable = ((isset ($config ['oa_social_login_registration_page_disable']) && $config ['oa_social_login_registration_page_disable'] == '1') ? '1' : '0'); $oa_social_login_registration_page_caption = (isset ($config ['oa_social_login_registration_page_caption']) ? $config ['oa_social_login_registration_page_caption'] : 'Connect with your social network account'); - + // Index Page. $oa_social_login_index_page_disable = ((isset ($config ['oa_social_login_index_page_disable']) && $config ['oa_social_login_index_page_disable'] == '1') ? '1' : '0'); $oa_social_login_index_page_caption = (isset ($config ['oa_social_login_index_page_caption']) ? $config ['oa_social_login_index_page_caption'] : 'Connect with your social network account'); - + // Index Page. $oa_social_login_other_page_disable = (empty ($config ['oa_social_login_other_page_disable']) ? '0' : 1); $oa_social_login_other_page_caption = (isset ($config ['oa_social_login_other_page_caption']) ? $config ['oa_social_login_other_page_caption'] : 'Connect with your social network account'); - + // Triggers a form message. $oa_social_login_settings_saved = false; - + // Security Check. add_form_key ('oa_social_login'); - + // Form submitted. if ($request->variable('submit', '') <> '') - { + { // Form Security Check. if (!check_form_key ('oa_social_login')) { trigger_error ($user->lang ['FORM_INVALID'] . adm_back_link ($this->u_action), E_USER_WARNING); } - + // Triggers the settings saved message, $oa_social_login_settings_saved = true; - + // Gather API Connection details. $oa_social_login_api_connection_handler = ($request->variable ('oa_social_login_api_connection_handler', 'curl') == 'fs' ? 'fsockopen' : 'curl'); $oa_social_login_api_connection_port = ($request->variable ('oa_social_login_api_connection_port', 443) == 80 ? 80 : 443); $oa_social_login_api_subdomain = $request->variable ('oa_social_login_api_subdomain', ''); $oa_social_login_api_key = $request->variable ('oa_social_login_api_key', ''); $oa_social_login_api_secret = $request->variable ('oa_social_login_api_secret', ''); - + // Check for full subdomain. if (preg_match ("/([a-z0-9\-]+)\.api\.oneall\.com/i", $oa_social_login_api_subdomain, $matches)) { $oa_social_login_api_subdomain = $matches [1]; } - + // Social Networks. $oa_social_login_providers = array(); foreach (self::get_providers () as $provider_key => $provider_data) @@ -199,7 +199,7 @@ public function admin_main () $oa_social_login_providers [] = $provider_key; } } - + // Other options. $oa_social_login_disable = (($request->variable ('oa_social_login_disable', 0) == 1) ? 1 : 0); $oa_social_login_disable_linking = (($request->variable ('oa_social_login_disable_linking', 0) == 1) ? 1 : 0); @@ -218,27 +218,27 @@ public function admin_main () { $oa_social_login_validate = 0; } - + // Login page, default 1. $oa_social_login_login_page_disable = (($request->variable ('oa_social_login_login_page_disable', 0) == 1) ? 1 : 0); $oa_social_login_login_page_caption = $request->variable ('oa_social_login_login_page_caption', '', true); - + // Login page inline, default 1. $oa_social_login_inline_page_disable = (($request->variable ('oa_social_login_inline_page_disable', 0) == 1) ? 1 : 0); - $oa_social_login_linline_page_caption = $request->variable ('oa_social_login_inline_page_caption', '', true); + $oa_social_login_inline_page_caption = $request->variable ('oa_social_login_inline_page_caption', '', true); // Registration page, default 1. $oa_social_login_registration_page_disable = (($request->variable ('oa_social_login_registration_page_disable', 0) == 1) ? 1 : 0); $oa_social_login_registration_page_caption = $request->variable ('oa_social_login_registration_page_caption', '', true); - + // Main page, default 1. $oa_social_login_index_page_disable = (($request->variable ('oa_social_login_index_page_disable', 0) == 1) ? 1 : 0); $oa_social_login_index_page_caption = $request->variable ('oa_social_login_index_page_caption', '', true); - + // Other pages, default 0. $oa_social_login_other_page_disable = (($request->variable ('oa_social_login_other_page_disable', 1) == 0) ? 0 : 1); $oa_social_login_other_page_caption = $request->variable ('oa_social_login_other_page_caption', '', true); - + // Save configuration. $config->set ('oa_social_login_disable', $oa_social_login_disable); $config->set ('oa_social_login_disable_linking', $oa_social_login_disable_linking); @@ -262,17 +262,17 @@ public function admin_main () $config->set ('oa_social_login_other_page_caption', $oa_social_login_other_page_caption); $config->set ('oa_social_login_validate', $oa_social_login_validate); } - + // Setup Social Network Vars foreach (self::get_providers () as $key => $data) { $template->assign_block_vars ('provider', array( 'KEY' => $key, 'NAME' => $data ['name'], - 'ENABLE' => in_array ($key, $oa_social_login_providers) + 'ENABLE' => in_array ($key, $oa_social_login_providers) )); } - + // Setup Vars $template->assign_vars (array( 'U_ACTION' => $this->u_action, @@ -301,9 +301,9 @@ public function admin_main () 'OA_SOCIAL_LOGIN_INDEX_PAGE_DISABLE' => ($oa_social_login_index_page_disable == '1'), 'OA_SOCIAL_LOGIN_INDEX_PAGE_CAPTION' => $oa_social_login_index_page_caption, 'OA_SOCIAL_LOGIN_OTHER_PAGE_DISABLE' => ($oa_social_login_other_page_disable == '1'), - 'OA_SOCIAL_LOGIN_OTHER_PAGE_CAPTION' => $oa_social_login_other_page_caption + 'OA_SOCIAL_LOGIN_OTHER_PAGE_CAPTION' => $oa_social_login_other_page_caption )); - + // Done return true; } @@ -314,10 +314,10 @@ public function admin_main () public function admin_ajax_autodetect_api_connection () { global $phpbb_root_path, $phpEx, $user; - + // Add the language file. $user->add_lang_ext ('oneall/sociallogin', 'backend'); - + // Check CURL HTTPS - Port 443. if (self::check_curl (true) === true) { @@ -343,10 +343,10 @@ public function admin_ajax_autodetect_api_connection () { $status_message = 'error|none|' . $user->lang ['OA_SOCIAL_LOGIN_API_DETECT_NONE']; } - + // Call the garbage collector. garbage_collection (); - + // Output for AJAX. die ($status_message); } @@ -357,20 +357,20 @@ public function admin_ajax_autodetect_api_connection () public function admin_ajax_verify_api_settings () { global $phpbb_root_path, $phpEx, $user, $request; - + // Add language file. $user->add_lang_ext ('oneall/sociallogin', 'backend'); - + // Read arguments. $api_subdomain = trim (strtolower ($request->variable ('api_subdomain', ''))); $api_key = trim ($request->variable ('api_key', '')); $api_secret = trim ($request->variable ('api_secret', '')); $api_connection_port = $request->variable ('api_connection_port', ''); $api_connection_handler = $request->variable ('api_connection_handler', ''); - + // Init status message. $status_message = null; - + // Check if all fields have been filled out. if (strlen ($api_subdomain) == 0 || strlen ($api_key) == 0 || strlen ($api_secret) == 0) { @@ -381,7 +381,7 @@ public function admin_ajax_verify_api_settings () // Check the handler $api_connection_handler = ($api_connection_handler == 'fs' ? 'fsockopen' : 'curl'); $api_connection_use_https = ($api_connection_port == 443 ? true : false); - + // FSOCKOPEN if ($api_connection_handler == 'fsockopen') { @@ -398,7 +398,7 @@ public function admin_ajax_verify_api_settings () $status_message = 'error|' . $user->lang ['OA_SOCIAL_LOGIN_API_CREDENTIALS_USE_AUTO']; } } - + // No errors until now. if (empty ($status_message)) { @@ -407,7 +407,7 @@ public function admin_ajax_verify_api_settings () { $api_subdomain = $matches [1]; } - + // Check format of the subdomain. if (!preg_match ("/^[a-z0-9\-]+$/i", $api_subdomain)) { @@ -418,15 +418,15 @@ public function admin_ajax_verify_api_settings () // Construct full API Domain. $api_domain = $api_subdomain . '.api.oneall.com'; $api_resource_url = ($api_connection_use_https ? 'https' : 'http') . '://' . $api_domain . '/tools/ping.json'; - + // API Credentialls. $api_credentials = array(); $api_credentials ['api_key'] = $api_key; $api_credentials ['api_secret'] = $api_secret; - + // Try to establish a connection. $result = self::do_api_request ($api_connection_handler, $api_resource_url, $api_credentials); - + // Parse result. if (is_object ($result) && property_exists ($result, 'http_code') && property_exists ($result, 'http_data')) { @@ -436,17 +436,17 @@ public function admin_ajax_verify_api_settings () case 200 : $status_message = 'success|' . $user->lang ['OA_SOCIAL_LOGIN_API_CREDENTIALS_OK']; break; - + // Authentication Error. case 401 : $status_message = 'error|' . $user->lang ['OA_SOCIAL_LOGIN_API_CREDENTIALS_KEYS_WRONG']; break; - + // Wrong Subdomain. case 404 : $status_message = 'error|' . $user->lang ['OA_SOCIAL_LOGIN_API_CREDENTIALS_SUBDOMAIN_WRONG']; break; - + // Other error. default : $status_message = 'error|' . $user->lang ['OA_SOCIAL_LOGIN_API_CREDENTIALS_CHECK_COM']; @@ -460,10 +460,10 @@ public function admin_ajax_verify_api_settings () } } } - + // Garbage Collector. garbage_collection (); - + // Output for Ajax. die ($status_message); } @@ -474,7 +474,7 @@ public function admin_ajax_verify_api_settings () public function count_login_identity_token ($identity_token) { global $db, $table_prefix; - + // Update the counter for the given identity_token. $sql = "UPDATE " . $table_prefix . "oasl_identity SET num_logins=num_logins+1, date_updated='" . time () . "' WHERE identity_token = '" . $db->sql_escape ($identity_token) . "'"; $query = $db->sql_query ($sql); @@ -487,38 +487,38 @@ public function count_login_identity_token ($identity_token) public function unlink_identity_token ($identity_token) { global $db, $table_prefix; - + // Retrieve the oasl_user_id from the identity_token, using the oasl_identity table. $sql = "SELECT oasl_user_id FROM " . $table_prefix . 'oasl_identity' . " WHERE identity_token = '" . $db->sql_escape ($identity_token) . "'"; $query = $db->sql_query ($sql); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // No identity token found if (!is_array ($result) || empty ($result ['oasl_user_id'])) { return false; } - + $user_id = $result ['oasl_user_id']; - + // Delete the identity_token. $sql = "DELETE FROM " . $table_prefix . 'oasl_identity' . " WHERE identity_token = '" . $db->sql_escape ($identity_token) . "'"; $query = $db->sql_query ($sql); - + // Check if there are any other identities linked to the user_id. $sql = "SELECT oasl_user_id FROM " . $table_prefix . 'oasl_identity' . " WHERE oasl_user_id = '" . $db->sql_escape ($user_id) . "'"; $query = $db->sql_query ($sql); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // If no identity linked to the oasl_user_id: delete oasl_user_id row from oasl_user table. if (!is_array ($result)) { $sql = "DELETE FROM " . $table_prefix . 'oasl_user' . " WHERE oasl_user_id = '" . $db->sql_escape ($user_id) . "'"; $query = $db->sql_query ($sql); } - + return true; } @@ -528,21 +528,21 @@ public function unlink_identity_token ($identity_token) public function link_tokens_to_user_id ($user_id, $user_token, $identity_token, $identity_provider) { global $db, $table_prefix; - + // Make sure that that the user exists. $sql = "SELECT user_id FROM " . USERS_TABLE . " WHERE user_id = " . intval ($user_id) . ""; $query = $db->sql_query_limit ($sql, 1); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The user exists. if (is_array ($result) && !empty ($result ['user_id'])) { $user_id = $result ['user_id']; - + $oasl_user_id = null; $oasl_identity_id = null; - + // Delete superfluous user_token. $sql = "SELECT oasl_user_id FROM " . $table_prefix . 'oasl_user' . " WHERE user_id = " . intval ($user_id) . " AND user_token <> '" . $db->sql_escape ($user_token) . "'"; @@ -553,14 +553,14 @@ public function link_tokens_to_user_id ($user_id, $user_token, $identity_token, $sql = "DELETE FROM " . $table_prefix . 'oasl_user' . " WHERE oasl_user_id = '" . $db->sql_escape ($row ['oasl_user_id']) . "'"; $query = $db->sql_query ($sql); - + // Delete the wrongly linked identity_token. $sql = "DELETE FROM " . $table_prefix . 'oasl_identity' . " WHERE oasl_user_id = '" . $db->sql_escape ($row ['oasl_user_id']) . "'"; $query = $db->sql_query ($sql); } $db->sql_freeresult ($query); - + // Read the entry for the given user_token. $sql = "SELECT oasl_user_id, user_id FROM " . $table_prefix . 'oasl_user' . " @@ -568,13 +568,13 @@ public function link_tokens_to_user_id ($user_id, $user_token, $identity_token, $query = $db->sql_query ($sql); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The user_token exists if (is_array ($result) && !empty ($result ['oasl_user_id'])) { $oasl_user_id = $result ['oasl_user_id']; } - + // The user_token either does not exist or has been reset. if (empty ($oasl_user_id)) { @@ -582,15 +582,15 @@ public function link_tokens_to_user_id ($user_id, $user_token, $identity_token, $sql_arr = array( 'user_id' => intval ($user_id), 'user_token' => $user_token, - 'date_added' => time () + 'date_added' => time () ); $sql = "INSERT INTO " . $table_prefix . 'oasl_user' . " " . $db->sql_build_array ('INSERT', $sql_arr); $query = $db->sql_query ($sql); - + // Identifier of the newly created user_token entry. $oasl_user_id = $db->sql_nextid (); } - + // Read the entry for the given identity_token. $sql = "SELECT oasl_identity_id, oasl_user_id, identity_token FROM " . $table_prefix . 'oasl_identity' . " @@ -598,24 +598,24 @@ public function link_tokens_to_user_id ($user_id, $user_token, $identity_token, $query = $db->sql_query ($sql); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The identity_token exists if (is_array ($result) && !empty ($result ['oasl_identity_id'])) { $oasl_identity_id = $result ['oasl_identity_id']; - + // The identity_token is linked to another user_token. if (!empty ($result ['oasl_user_id']) && $result ['oasl_user_id'] != $oasl_user_id) { // Delete the wrongly linked identity_token. $sql = "DELETE FROM " . $table_prefix . "oasl_identity WHERE oasl_identity_id = " . intval ($oasl_identity_id); $query = $db->sql_query_limit ($sql, 1); - + // Reset the identifier $oasl_identity_id = null; } } - + // The identity_token either does not exist or has been reset. if (empty ($oasl_identity_id)) { @@ -626,19 +626,19 @@ public function link_tokens_to_user_id ($user_id, $user_token, $identity_token, 'identity_provider' => $identity_provider, 'num_logins' => 1, 'date_added' => time (), - 'date_updated' => time () + 'date_updated' => time () ); $sql = "INSERT INTO " . $table_prefix . 'oasl_identity' . " " . $db->sql_build_array ('INSERT', $sql_arr); $query = $db->sql_query ($sql); - + // Identifier of the newly created identity_token entry. $oasl_identity_id = $db->sql_nextid (); } - + // Done. return true; } - + // An error occured. return false; } @@ -653,7 +653,7 @@ public function put_session_validation_data ($session_id, $validation) $sql_arr = array( 'session_id' => $session_id, 'user_data' => $validation, - 'date_creation' => time () + 'date_creation' => time () ); $sql = "INSERT INTO " . $table_prefix . 'oasl_session' . " " . $db->sql_build_array ('INSERT', $sql_arr); $query = $db->sql_query ($sql); @@ -692,7 +692,7 @@ protected function generate_random_email () $email = $this->generate_hash (10) . "@example.com"; } while ( $this->get_user_id_by_email ($email) !== false ); - + // Done return $email; } @@ -703,7 +703,7 @@ protected function generate_random_email () protected function generate_hash ($length) { $hash = ''; - + for($i = 0; $i < $length; $i ++) { do @@ -713,7 +713,7 @@ protected function generate_hash ($length) while ( !preg_match ('/[a-zA-Z0-9]/', $char) ); $hash .= $char; } - + // Done return $hash; } @@ -724,27 +724,27 @@ protected function generate_hash ($length) protected function do_login ($user_id, $check_admin = false) { global $auth, $db, $user, $table_prefix; - + // Grab the list of admins to check if this user is an administrator. if ($check_admin === true) { $admin_user_ids = $auth->acl_get_list (false, 'a_user', false); $admin_user_ids = (!empty ($admin_user_ids [0] ['a_user'])) ? $admin_user_ids [0] ['a_user'] : array(); $is_admin = (in_array ($user_id, $admin_user_ids) ? true : false); - + // Store the old session id for later use. $old_session_id = $user->session_id; - + // This user is an administrator. if ($is_admin === true) { global $SID, $_SID; - + // Refresh the cookie. $cookie_expire = time () - 31536000; $user->set_cookie ('u', '', $cookie_expire); $user->set_cookie ('sid', '', $cookie_expire); - + // Refresh the session id. $SID = '?sid='; $user->session_id = $_SID = ''; @@ -754,10 +754,10 @@ protected function do_login ($user_id, $check_admin = false) { $is_admin = false; } - + // Log the user in. $result = $user->session_create ($user_id, $is_admin); - + // Session created successfully. if ($result === true) { @@ -767,14 +767,14 @@ protected function do_login ($user_id, $check_admin = false) $sql = 'DELETE FROM ' . SESSIONS_TABLE . " WHERE session_id = '" . $db->sql_escape ($old_session_id) . "' AND session_user_id = " . intval ($user_id) . ""; $db->sql_query ($sql); } - + // We re-init the auth array to get correct results on login/logout. $auth->acl ($user->data); - + // Done. return true; } - + // An error has occurred. return false; } @@ -785,19 +785,19 @@ protected function do_login ($user_id, $check_admin = false) protected function get_user_id_by_email ($email) { global $db, $table_prefix; - + // Read the user_id for this email address. $sql = "SELECT user_id FROM " . USERS_TABLE . " WHERE user_email = '" . $db->sql_escape ($email) . "'"; $query = $db->sql_query_limit ($sql, 1); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // We have found an user_id. if (is_array ($result) && !empty ($result ['user_id'])) { return $result ['user_id']; } - + // Not found. return false; } @@ -808,19 +808,19 @@ protected function get_user_id_by_email ($email) protected function get_user_id_by_username ($user_login) { global $db, $table_prefix; - + // Read the user_id for this login $sql = "SELECT user_id FROM " . USERS_TABLE . " WHERE username_clean = '" . $db->sql_escape (utf8_clean_string ($user_login)) . "'"; $query = $db->sql_query_limit ($sql, 1); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // We have found an user_id. if (is_array ($result) && !empty ($result ['user_id'])) { return $result ['user_id']; } - + // Not found. return false; } @@ -831,47 +831,47 @@ protected function get_user_id_by_username ($user_login) protected function get_user_id_for_user_token ($user_token) { global $db, $table_prefix; - + // Make sure it is not empty. $user_token = trim ($user_token); if (strlen ($user_token) == 0) { return false; } - + // Read the user_id for this user_token. $sql = "SELECT oasl_user_id, user_id FROM " . $table_prefix . 'oasl_user' . " WHERE user_token = '" . $db->sql_escape ($user_token) . "'"; $query = $db->sql_query ($sql); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The user_token exists if (is_array ($result) && !empty ($result ['oasl_user_id'])) { $user_id = intval ($result ['user_id']); $oasl_user_id = intval ($result ['oasl_user_id']); - + // Check if the user account exists. $sql = "SELECT user_id FROM " . USERS_TABLE . " WHERE user_id = " . intval ($user_id); $query = $db->sql_query_limit ($sql, 1); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The user account exists, return it's identifier. if (is_array ($result) && !empty ($result ['user_id'])) { return $result ['user_id']; } - + // Delete the wrongly linked user_token. $sql = "DELETE FROM " . $table_prefix . 'oasl_user' . " WHERE user_token = '" . $db->sql_escape ($user_token) . "'"; $query = $db->sql_query ($sql); - + // Delete the wrongly linked identity_token. $sql = "DELETE FROM " . $table_prefix . 'oasl_identity' . " WHERE oasl_user_id = " . intval ($oasl_user_id) . ""; $query = $db->sql_query ($sql); } - + // No entry found. return false; } @@ -882,19 +882,19 @@ protected function get_user_id_for_user_token ($user_token) public function get_user_token_for_user_id ($user_id) { global $db, $table_prefix; - + // Read the user_id for this user_token. $sql = "SELECT user_token FROM " . $table_prefix . 'oasl_user' . " WHERE user_id = " . intval ($user_id); $query = $db->sql_query_limit ($sql, 1); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The user_token exists if (is_array ($result) && !empty ($result ['user_token'])) { return $result ['user_token']; } - + // Not found return false; } @@ -905,19 +905,19 @@ public function get_user_token_for_user_id ($user_id) protected function get_user_id_for_login_token ($login_token) { global $db, $table_prefix; - + // Read the user_id for this login_token $sql = "SELECT user_id FROM " . $table_prefix . 'oasl_login_token' . " WHERE login_token = '" . $db->sql_escape ($login_token) . "'"; $query = $db->sql_query_limit ($sql, 1); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The login_token exists if (is_array ($result) && !empty ($result ['user_id'])) { return $result ['user_id']; } - + // Not found return false; } @@ -928,28 +928,28 @@ protected function get_user_id_for_login_token ($login_token) public function create_login_token_for_user_id ($user_id) { global $db, $table_prefix; - + // Remove old or existing login token. $sql = "DELETE FROM " . $table_prefix . 'oasl_login_token' . " WHERE (user_id = " . intval ($user_id) . " OR date_creation < " . (time () - 60 * 5) . ")"; $query = $db->sql_query ($sql); - + // Create a new and unique token. do { $login_token = $this->get_uuid_v4 (); } while ( $this->get_user_id_for_login_token ($login_token) !== false ); - + // Add the new token. $sql_arr = array( 'login_token' => $login_token, 'user_id' => $user_id, - 'date_creation' => time () + 'date_creation' => time () ); - + $sql = "INSERT INTO " . $table_prefix . 'oasl_login_token' . " " . $db->sql_build_array ('INSERT', $sql_arr); $query = $db->sql_query ($sql); - + // Done return $login_token; } @@ -960,19 +960,19 @@ public function create_login_token_for_user_id ($user_id) function get_default_group_id () { global $db; - + // Read the default group. $sql = "SELECT group_id FROM " . GROUPS_TABLE . " WHERE group_name = 'REGISTERED' AND group_type = " . GROUP_SPECIAL; $query = $db->sql_query ($sql); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // Group found; if (is_array ($result) && isset ($result ['group_id'])) { return $result ['group_id']; } - + // Not found return false; } @@ -983,19 +983,19 @@ function get_default_group_id () function get_user_data_by_user_id ($user_id) { global $db, $table_prefix; - + // Read the user data. $sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = " . intval ($user_id) . ""; $query = $db->sql_query_limit ($sql, 1); $result = $db->sql_fetchrow ($query); $db->sql_freeresult ($query); - + // The user has been found. if (is_array ($result)) { return $result; } - + // Not found. return array(); } @@ -1015,92 +1015,92 @@ public function get_providers () { $providers = array( 'amazon' => array( - 'name' => 'Amazon' + 'name' => 'Amazon' ), 'blogger' => array( - 'name' => 'Blogger' + 'name' => 'Blogger' ), 'disqus' => array( - 'name' => 'Disqus' + 'name' => 'Disqus' ), 'draugiem' => array( - 'name' => 'Draugiem' + 'name' => 'Draugiem' ), 'dribbble' => array( 'name' => 'Dribbble' ), 'facebook' => array( - 'name' => 'Facebook' + 'name' => 'Facebook' ), 'foursquare' => array( - 'name' => 'Foursquare' + 'name' => 'Foursquare' ), 'github' => array( - 'name' => 'Github.com' + 'name' => 'Github.com' ), 'google' => array( - 'name' => 'Google' + 'name' => 'Google' ), 'instagram' => array( - 'name' => 'Instagram' + 'name' => 'Instagram' ), 'linkedin' => array( - 'name' => 'LinkedIn' + 'name' => 'LinkedIn' ), 'livejournal' => array( - 'name' => 'LiveJournal' + 'name' => 'LiveJournal' ), 'mailru' => array( - 'name' => 'Mail.ru' + 'name' => 'Mail.ru' ), 'odnoklassniki' => array( - 'name' => 'Odnoklassniki' + 'name' => 'Odnoklassniki' ), 'openid' => array( - 'name' => 'OpenID' + 'name' => 'OpenID' ), 'paypal' => array( - 'name' => 'PayPal' + 'name' => 'PayPal' ), 'reddit' => array( - 'name' => 'Reddit' + 'name' => 'Reddit' ), 'skyrock' => array( - 'name' => 'Skyrock.com' + 'name' => 'Skyrock.com' ), 'stackexchange' => array( - 'name' => 'StackExchange' + 'name' => 'StackExchange' ), 'steam' => array( - 'name' => 'Steam' + 'name' => 'Steam' ), 'twitch' => array( - 'name' => 'Twitch.tv' + 'name' => 'Twitch.tv' ), 'twitter' => array( - 'name' => 'Twitter' + 'name' => 'Twitter' ), 'vimeo' => array( - 'name' => 'Vimeo' + 'name' => 'Vimeo' ), 'vkontakte' => array( - 'name' => 'VKontakte' + 'name' => 'VKontakte' ), 'windowslive' => array( - 'name' => 'Windows Live' + 'name' => 'Windows Live' ), 'wordpress' => array( - 'name' => 'WordPress.com' + 'name' => 'WordPress.com' ), 'yahoo' => array( - 'name' => 'Yahoo' + 'name' => 'Yahoo' ), 'youtube' => array( - 'name' => 'YouTube' + 'name' => 'YouTube' ), 'battlenet' => array( - 'name' => 'BattleNet' - ) + 'name' => 'BattleNet' + ) ); return $providers; } @@ -1136,7 +1136,7 @@ public function do_api_request ($handler, $url, $options = array(), $timeout = 3 // CURL else { - + return $this->curl_request ($url, $options, $timeout); } } @@ -1192,7 +1192,7 @@ function curl_request ($url, $options = array(), $timeout = 30, $num_redirects = { // Store the result $result = new \stdClass (); - + // Send request $curl = curl_init (); curl_setopt ($curl, CURLOPT_URL, $url); @@ -1204,29 +1204,29 @@ function curl_request ($url, $options = array(), $timeout = 30, $num_redirects = curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($curl, CURLOPT_USERAGENT, self::USER_AGENT); - + // Does not work in PHP Safe Mode, we manually follow the locations if necessary. curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 0); - + // BASIC AUTH? if (isset ($options ['api_key']) && isset ($options ['api_secret'])) { curl_setopt ($curl, CURLOPT_USERPWD, $options ['api_key'] . ':' . $options ['api_secret']); } - + // Proxy Settings if ( ! empty ($options ['proxy_url'])) { // Proxy Location curl_setopt ($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt ($curl, CURLOPT_PROXY, $options ['proxy_url']); - + // Proxy Port if ( ! empty ($options ['proxy_port'])) - { + { curl_setopt ($curl, CURLOPT_PROXYPORT, $options ['proxy_port']); } - + // Proxy Authentication if ( ! empty ($options ['proxy_username']) && ! empty ($options ['proxy_password'])) { @@ -1234,19 +1234,19 @@ function curl_request ($url, $options = array(), $timeout = 30, $num_redirects = curl_setopt ($curl, CURLOPT_PROXYUSERPWD, $options ['proxy_username'] . ':' . $options ['proxy_password']); } } - + // Make request if (($response = curl_exec ($curl)) !== false) { // Get Information $curl_info = curl_getinfo ($curl); - + // Save result $result->http_code = $curl_info ['http_code']; $result->http_headers = preg_split ('/\r\n|\n|\r/', trim (substr ($response, 0, $curl_info ['header_size']))); $result->http_data = trim (substr ($response, $curl_info ['header_size'])); $result->http_error = null; - + // Check if we have a redirection header if (in_array ($result->http_code, array(301, 302)) && $num_redirects < 4) { @@ -1255,7 +1255,7 @@ function curl_request ($url, $options = array(), $timeout = 30, $num_redirects = { // Header found ? $header_found = false; - + // Loop through headers. while ( !$header_found && (list (, $header) = each ($result->http_headers)) ) { @@ -1269,7 +1269,7 @@ function curl_request ($url, $options = array(), $timeout = 30, $num_redirects = { // Header found! $header_found = true; - + // Follow redirection url. $result = self::curl_request ($url_tmp, $options, $timeout, $num_redirects + 1); } @@ -1284,7 +1284,7 @@ function curl_request ($url, $options = array(), $timeout = 30, $num_redirects = $result->http_data = null; $result->http_error = curl_error ($curl); } - + // Done return $result; } @@ -1296,7 +1296,7 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ { // Store the result $result = new \stdClass (); - + // Make that this is a valid URL if (($uri = parse_url ($url)) == false) { @@ -1305,7 +1305,7 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ $result->http_error = 'invalid_uri'; return $result; } - + // Make sure we can handle the schema switch ($uri ['scheme']) { @@ -1314,13 +1314,13 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ $host = ($uri ['host'] . ($port != 80 ? ':' . $port : '')); $fp = @fsockopen ($uri ['host'], $port, $errno, $errstr, $timeout); break; - + case 'https' : $port = (isset ($uri ['port']) ? $uri ['port'] : 443); $host = ($uri ['host'] . ($port != 443 ? ':' . $port : '')); $fp = @fsockopen ('ssl://' . $uri ['host'], $port, $errno, $errstr, $timeout); break; - + default : $result->http_code = -1; $result->http_data = null; @@ -1328,7 +1328,7 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ return $result; break; } - + // Make sure the socket opened properly if (!$fp) { @@ -1337,53 +1337,53 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ $result->http_error = trim ($errstr); return $result; } - + // Construct the path to act on $path = (isset ($uri ['path']) ? $uri ['path'] : '/'); if (isset ($uri ['query'])) { $path .= '?' . $uri ['query']; } - + // Create HTTP request $defaults = array(); $defaults ['Host'] = 'Host: ' . $host; $defaults ['User-Agent'] = 'User-Agent: ' . self::USER_AGENT; - + // BASIC AUTH? if (isset ($options ['api_key']) && isset ($options ['api_secret'])) { $defaults ['Authorization'] = 'Authorization: Basic ' . base64_encode ($options ['api_key'] . ":" . $options ['api_secret']); } - + // Build and send request $request = 'GET ' . $path . " HTTP/1.0\r\n"; $request .= implode ("\r\n", $defaults); $request .= "\r\n\r\n"; fwrite ($fp, $request); - + // Fetch response $response = ''; while ( !feof ($fp) ) { $response .= fread ($fp, 1024); } - + // Close connection fclose ($fp); - + // Parse response list ($response_header, $response_body) = explode ("\r\n\r\n", $response, 2); - + // Parse header $response_header = preg_split ("/\r\n|\n|\r/", $response_header); list ($header_protocol, $header_code, $header_status_message) = explode (' ', trim (array_shift ($response_header)), 3); - + // Set result $result->http_code = $header_code; $result->http_headers = $response_header; $result->http_data = $response_body; - + // Make sure we we have a redirection status code if (in_array ($result->http_code, array(301, 302)) && $num_redirects <= 4) { @@ -1392,7 +1392,7 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ { // Header found? $header_found = false; - + // Loop through headers. while ( !$header_found && (list (, $header) = each ($result->http_headers)) ) { @@ -1401,11 +1401,11 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ { // Found $header_found = true; - + // Clean url $url_tmp = trim (str_replace ($matches [1], "", $matches [0])); $url_parsed = parse_url ($url_tmp); - + // Found if (!empty ($url_parsed)) { @@ -1415,7 +1415,7 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ } } } - + // Done return $result; } @@ -1426,19 +1426,19 @@ protected function fsockopen_request ($url, $options = array(), $timeout = 30, $ public static function undo_camel_case ($input) { $result = $input; - + if (preg_match_all ('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches)) { $ret = $matches [0]; - + foreach ($ret as &$match) { $match = ($match == strtoupper ($match) ? strtolower ($match) : lcfirst ($match)); } - + $result = implode ('_', $ret); } - + return $result; } @@ -1452,7 +1452,7 @@ public static function extract_social_network_profile ($reply) { // Decode the social network profile Data. $social_data = json_decode ($reply->http_data); - + // Make sur that the data has beeen decoded properly if (is_object ($social_data)) { @@ -1462,16 +1462,16 @@ public static function extract_social_network_profile ($reply) error_log ($social_data->response->result->status->info . ' (' . $social_data->response->result->status->code . ')'); return false; } - + // Container for user data $data = array(); - + // Parse plugin data. if (isset ($social_data->response->result->data->plugin)) { // Plugin. $plugin = $social_data->response->result->data->plugin; - + // Add plugin data. $data ['plugin_key'] = $plugin->key; $data ['plugin_action'] = (isset ($plugin->data->action) ? $plugin->data->action : null); @@ -1479,26 +1479,26 @@ public static function extract_social_network_profile ($reply) $data ['plugin_reason'] = (isset ($plugin->data->reason) ? $plugin->data->reason : null); $data ['plugin_status'] = (isset ($plugin->data->status) ? $plugin->data->status : null); } - + // Do we have a user? if (isset ($social_data->response->result->data->user) && is_object ($social_data->response->result->data->user)) { // User. $user = $social_data->response->result->data->user; - + // Add user data. $data ['user_token'] = $user->user_token; - + // Do we have an identity ? if (isset ($user->identity) && is_object ($user->identity)) { // Identity. $identity = $user->identity; - + // Add identity data. $data ['identity_token'] = $identity->identity_token; $data ['identity_provider'] = !empty ($identity->source->name) ? $identity->source->name : ''; - + $data ['user_first_name'] = !empty ($identity->name->givenName) ? $identity->name->givenName : ''; $data ['user_last_name'] = !empty ($identity->name->familyName) ? $identity->name->familyName : ''; $data ['user_formatted_name'] = !empty ($identity->name->formatted) ? $identity->name->formatted : ''; @@ -1509,7 +1509,7 @@ public static function extract_social_network_profile ($reply) $data ['user_current_location'] = !empty ($identity->currentLocation) ? $identity->currentLocation : ''; $data ['user_about_me'] = !empty ($identity->aboutMe) ? $identity->aboutMe : ''; $data ['user_note'] = !empty ($identity->note) ? $identity->note : ''; - + // Birthdate - MM/DD/YYYY if (!empty ($identity->birthday) && preg_match ('/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/', $identity->birthday, $matches)) { @@ -1521,7 +1521,7 @@ public static function extract_social_network_profile ($reply) { $data ['user_birthdate'] = ''; } - + // Fullname. if (!empty ($identity->name->formatted)) { @@ -1535,7 +1535,7 @@ public static function extract_social_network_profile ($reply) { $data ['user_full_name'] = $data ['user_constructed_name']; } - + // Preferred Username. if (!empty ($identity->preferredUsername)) { @@ -1549,10 +1549,10 @@ public static function extract_social_network_profile ($reply) { $data ['user_login'] = $data ['user_full_name']; } - + // phpBB does not like spaces here $data ['user_login'] = str_replace (' ', '', trim ($data ['user_login'])); - + // Website/Homepage. $data ['user_website'] = ''; if (!empty ($identity->profileUrl)) @@ -1563,7 +1563,7 @@ public static function extract_social_network_profile ($reply) { $data ['user_website'] = $identity->urls [0]->value; } - + // Gender. $data ['user_gender'] = ''; if (!empty ($identity->gender)) @@ -1573,21 +1573,21 @@ public static function extract_social_network_profile ($reply) case 'male' : $data ['user_gender'] = 'm'; break; - + case 'female' : $data ['user_gender'] = 'f'; break; } } - + // Email Addresses. $data ['user_emails'] = array(); $data ['user_emails_simple'] = array(); - + // Email Address. $data ['user_email'] = ''; $data ['user_email_is_verified'] = false; - + // Extract emails. if (property_exists ($identity, 'emails') && is_array ($identity->emails)) { @@ -1596,13 +1596,13 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_emails_simple'] [] = $email->value; - + // Add to list. $data ['user_emails'] [] = array( 'user_email' => $email->value, - 'user_email_is_verified' => $email->is_verified + 'user_email_is_verified' => $email->is_verified ); - + // Keep one, if possible a verified one. if (empty ($data ['user_email']) || $email->is_verified) { @@ -1611,11 +1611,11 @@ public static function extract_social_network_profile ($reply) } } } - + // Addresses. $data ['user_addresses'] = array(); $data ['user_addresses_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'addresses') && is_array ($identity->addresses)) { @@ -1624,18 +1624,18 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_addresses_simple'] [] = $address->formatted; - + // Add to list. $data ['user_addresses'] [] = array( - 'formatted' => $address->formatted + 'formatted' => $address->formatted ); } } - + // Phone Number. $data ['user_phone_numbers'] = array(); $data ['user_phone_numbers_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'phoneNumbers') && is_array ($identity->phoneNumbers)) { @@ -1644,19 +1644,19 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_phone_numbers_simple'] [] = $phone_number->value; - + // Add to list. $data ['user_phone_numbers'] [] = array( 'value' => $phone_number->value, - 'type' => (isset ($phone_number->type) ? $phone_number->type : null) + 'type' => (isset ($phone_number->type) ? $phone_number->type : null) ); } } - + // URLs. $data ['user_interests'] = array(); $data ['user_interests_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'interests') && is_array ($identity->interests)) { @@ -1665,19 +1665,19 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_interests_simple'] [] = $interest->value; - + // Add to list. $data ['users_interests'] [] = array( 'value' => $interest->value, - 'category' => (isset ($interest->category) ? $interest->category : null) + 'category' => (isset ($interest->category) ? $interest->category : null) ); } } - + // URLs. $data ['user_urls'] = array(); $data ['user_urls_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'urls') && is_array ($identity->urls)) { @@ -1686,19 +1686,19 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_urls_simple'] [] = $url->value; - + // Add to list. $data ['user_urls'] [] = array( 'value' => $url->value, - 'type' => (isset ($url->type) ? $url->type : null) + 'type' => (isset ($url->type) ? $url->type : null) ); } } - + // Certifications. $data ['user_certifications'] = array(); $data ['user_certifications_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'certifications') && is_array ($identity->certifications)) { @@ -1707,21 +1707,21 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_certifications_simple'] [] = $certification->name; - + // Add to list. $data ['user_certifications'] [] = array( 'name' => $certification->name, 'number' => (isset ($certification->number) ? $certification->number : null), 'authority' => (isset ($certification->authority) ? $certification->authority : null), - 'start_date' => (isset ($certification->startDate) ? $certification->startDate : null) + 'start_date' => (isset ($certification->startDate) ? $certification->startDate : null) ); } } - + // Recommendations. $data ['user_recommendations'] = array(); $data ['user_recommendations_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'recommendations') && is_array ($identity->recommendations)) { @@ -1730,32 +1730,32 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_recommendations_simple'] [] = $recommendation->value; - + // Build data. $data_entry = array( - 'value' => $recommendation->value + 'value' => $recommendation->value ); - + // Add recommender if (property_exists ($recommendation, 'recommender') && is_object ($recommendation->recommender)) { $data_entry ['recommender'] = array(); - + // Add recommender details foreach (get_object_vars ($recommendation->recommender) as $field => $value) { $data_entry ['recommender'] [self::undo_camel_case ($field)] = $value; } } - + // Add to list. $data ['user_recommendations'] [] = $data_entry; } } - + // Accounts. $data ['user_accounts'] = array(); - + // Extract entries. if (property_exists ($identity, 'accounts') && is_array ($identity->accounts)) { @@ -1766,15 +1766,15 @@ public static function extract_social_network_profile ($reply) $data ['user_accounts'] [] = array( 'domain' => (isset ($account->domain) ? $account->domain : null), 'userid' => (isset ($account->userid) ? $account->userid : null), - 'username' => (isset ($account->username) ? $account->username : null) + 'username' => (isset ($account->username) ? $account->username : null) ); } } - + // Photos. $data ['user_photos'] = array(); $data ['user_photos_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'photos') && is_array ($identity->photos)) { @@ -1783,19 +1783,19 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_photos_simple'] [] = $photo->value; - + // Add to list. $data ['user_photos'] [] = array( 'value' => $photo->value, - 'size' => $photo->size + 'size' => $photo->size ); } } - + // Languages. $data ['user_languages'] = array(); $data ['user_languages_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'languages') && is_array ($identity->languages)) { @@ -1804,19 +1804,19 @@ public static function extract_social_network_profile ($reply) { // Add to simple list $data ['user_languages_simple'] [] = $language->value; - + // Add to list. $data ['user_languages'] [] = array( 'value' => $language->value, - 'type' => $language->type + 'type' => $language->type ); } } - + // Educations. $data ['user_educations'] = array(); $data ['user_educations_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'educations') && is_array ($identity->educations)) { @@ -1825,19 +1825,19 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_educations_simple'] [] = $education->value; - + // Add to list. $data ['user_educations'] [] = array( 'value' => $education->value, - 'type' => $education->type + 'type' => $education->type ); } } - + // Organizations. $data ['user_organizations'] = array(); $data ['user_organizations_simple'] = array(); - + // Extract entries. if (property_exists ($identity, 'organizations') && is_array ($identity->organizations)) { @@ -1849,16 +1849,16 @@ public static function extract_social_network_profile ($reply) { // Add to simple list. $data ['user_organizations_simple'] [] = $organization->name; - + // Build entry. $data_entry = array(); - + // Add all fields. foreach (get_object_vars ($organization) as $field => $value) { $data_entry [self::undo_camel_case ($field)] = $value; } - + // Add to list. $data ['user_organizations'] [] = $data_entry; } @@ -1879,15 +1879,15 @@ public function handle_callback () { // Required global variables. global $db, $auth, $user, $config, $template, $phpbb_root_path, $phpbb_admin_path, $phpEx, $request; - + // Add language file. $user->add_lang_ext ('oneall/sociallogin', 'frontend'); - + // Read arguments. $connection_token = trim ($request->variable ('connection_token', '')); $login_token = trim ($request->variable ('oa_social_login_login_token', '')); $oa_action = strtolower (trim ($request->variable ('oa_action', ''))); - + // Make sure we need to call the callback handler. if (strlen ($oa_action) > 0 && strlen ($connection_token) > 0) { @@ -1901,15 +1901,15 @@ public function handle_callback () $api_connection_handler = ((!empty ($config ['oa_social_login_api_connection_handler']) && $config ['oa_social_login_api_connection_handler'] == 'fsockopen') ? 'fsockopen' : 'curl'); $api_connection_use_https = ((!empty ($config ['oa_social_login_api_connection_port']) && $config ['oa_social_login_api_connection_port'] == '80') ? false : true); $api_connection_url = ($api_connection_use_https ? 'https' : 'http') . '://' . $config ['oa_social_login_api_subdomain'] . '.api.oneall.com/connections/' . $connection_token . '.json'; - + // API Credentials. $api_credentials = array(); $api_credentials ['api_key'] = $config ['oa_social_login_api_key']; $api_credentials ['api_secret'] = $config ['oa_social_login_api_secret']; - + // Make Request. $result = $this->do_api_request ($api_connection_handler, $api_connection_url, $api_credentials); - + // Parse result if (is_object ($result) && property_exists ($result, 'http_code') && $result->http_code == 200) { @@ -1929,16 +1929,16 @@ public function handle_callback () { // Read the user_id for this login_token. $user_id_login_token = $this->get_user_id_for_login_token ($login_token); - + // We have a user for this login token if (is_numeric ($user_id_login_token)) { // Update the tokens? $update_tokens = true; - + // Read the user_id for this user_token $user_id_user_token = $this->get_user_id_for_user_token ($user_data ['user_token']); - + // There is already a user_id for this token if (!empty ($user_id_user_token)) { @@ -1947,12 +1947,12 @@ public function handle_callback () { // Show an error to the user. $template->assign_var ('OA_SOCIAL_LINK_ERROR', $user->lang ['OA_SOCIAL_LOGIN_ACCOUNT_ALREADY_LINKED']); - + // Do not updated the tokens. $update_tokens = false; } } - + // Update token? if ($update_tokens === true) { @@ -1965,10 +1965,10 @@ public function handle_callback () $this->unlink_identity_token ($user_data ['identity_token']); } } - + // Log the user in $this->do_login ($user_id_login_token); - + // Redirect to the same page self::http_redirect (append_sid (self::get_current_url ())); } @@ -1991,22 +1991,22 @@ public function handle_callback () protected function social_login_handle_callback ($user_data) { global $db, $auth, $user, $config, $template, $phpbb_root_path, $phpbb_admin_path, $phpEx; - + $error_message = null; $user_id = null; - + // Get user_id by token. $user_id_tmp = $this->get_user_id_for_user_token ($user_data ['user_token']); - + // We already have a user for this token. if (is_numeric ($user_id_tmp)) { // Process this user. $user_id = $user_id_tmp; - + // Load user data. $user_profile = $this->get_user_data_by_user_id ($user_id); - + // The user account needs to be activated. if (!empty ($user_profile ['user_inactive_reason'])) { @@ -2031,7 +2031,7 @@ protected function social_login_handle_callback ($user_data) { // Read existing user $user_id_tmp = $this->get_user_id_by_email ($user_data ['user_email']); - + // Existing user found if (is_numeric ($user_id_tmp)) { @@ -2051,10 +2051,10 @@ protected function social_login_handle_callback ($user_data) { require ($phpbb_root_path . 'includes/functions_user.' . $phpEx); } - + // Will validation be required ('1' means always). $do_validation = $config ['oa_social_login_validate'] === '1' ? true : false; - + // Username is mandatory. if (!isset ($user_data ['user_login']) || strlen (trim ($user_data ['user_login'])) == 0) { @@ -2075,7 +2075,7 @@ protected function social_login_handle_callback ($user_data) $do_validation = true; } } - + if (!$do_validation && $config ['oa_social_login_validate'] !== '0' && (empty ($user_data ['user_email']) || (!empty ($user_data ['user_email']) && $this->get_user_id_by_email ($user_data ['user_email']) !== false && $config ['oa_social_login_disable_linking'] === '1'))) { $do_validation = true; @@ -2085,7 +2085,7 @@ protected function social_login_handle_callback ($user_data) { // Create a random email $user_data ['user_email'] = $this->generate_random_email (); - + // This is a random email (the flag is used further down) $user_random_email = true; } @@ -2121,10 +2121,10 @@ public function social_login_resume_handle_callback ($user_data) protected function social_login_user_add ($user_random_email, $user_data) { global $db, $auth, $user, $config, $template, $phpbb_root_path, $phpbb_log, $phpbb_admin_path, $phpEx, $phpbb_dispatcher, $phpbb_container; - + $error_message = null; $user_id = null; - + // User functions if (!function_exists ('user_add')) { @@ -2140,22 +2140,22 @@ protected function social_login_user_add ($user_random_email, $user_data) { $user_row ['user_lang'] = 'en'; } - + // Default group_id is required. $group_id = $this->get_default_group_id (); - + // No group has been set. if (!is_numeric ($group_id)) { trigger_error ('NO_GROUP'); } - + // Activation Required. if (!$user_random_email && ($config ['require_activation'] == USER_ACTIVATION_SELF || $config ['require_activation'] == USER_ACTIVATION_ADMIN) && $config ['email_enable']) { $user_type = USER_INACTIVE; $user_actkey = gen_rand_string (mt_rand (6, 10)); - + $user_inactive_reason = INACTIVE_REGISTER; $user_inactive_time = time (); } @@ -2164,17 +2164,17 @@ protected function social_login_user_add ($user_random_email, $user_data) { $user_type = USER_NORMAL; $user_actkey = ''; - + $user_inactive_reason = 0; $user_inactive_time = 0; } - + // Generate a random password. $new_password = $this->generate_hash ($config ['min_pass_chars'] + rand (3, 5)); - + // Instantiate passwords manager. $passwords_manager = $phpbb_container->get('passwords.manager'); - + // Setup user details. $user_row = array( 'group_id' => $group_id, @@ -2187,15 +2187,15 @@ protected function social_login_user_add ($user_random_email, $user_data) 'user_lastvisit' => time (), 'user_lang' => $user_row ['user_lang'], 'username' => $user_data ['user_login'], - 'user_email' => $user_data ['user_email'] + 'user_email' => $user_data ['user_email'] ); - + // Adds the user to the Newly registered users group. if ($config ['new_member_post_limit']) { $user_row ['user_new'] = 1; } - + /** * Use this event to modify the values to be inserted when a user is added * Inspired by the core event: core.user_add_modify_data (which does not get our profile data) @@ -2209,10 +2209,10 @@ protected function social_login_user_add ($user_random_email, $user_data) $social_profile = $user_data; // Copy of profile user_data, updates ignore, to simulate read-only. $evt_vars = array('user_row', 'cp_data', 'social_profile'); extract ($phpbb_dispatcher->trigger_event ('oneall_sociallogin.user_add_modify_data', compact ($evt_vars))); - + // Register user, with optional custom fields. $user_id_tmp = user_add ($user_row, $cp_data); - + // This should not happen, because the required variables are listed above. if ($user_id_tmp === false) { @@ -2228,7 +2228,7 @@ protected function social_login_user_add ($user_random_email, $user_data) $oa_group_id = (int) $db->sql_fetchfield ('group_id'); $db->sql_freeresult ($result); $error = group_user_add ($oa_group_id, $user_id_tmp); - if ($error !== false) + if ($error !== false) { trigger_error ($error, E_USER_ERROR); } @@ -2237,19 +2237,19 @@ protected function social_login_user_add ($user_random_email, $user_data) { // Process this user. $user_id = $user_id_tmp; - + // Add the avatar if ($config ['oa_social_login_avatars_enable'] == 0) { $this->upload_user_avatar ($user_id, $user_data); } - + // Send Email (Only if it is not a random email address). if ($config ['email_enable'] && !$user_random_email) { // Do we have to include messenger? require ($phpbb_root_path . "includes/functions_messenger." . $phpEx); - + // Activation Type. if ($config ['require_activation'] == USER_ACTIVATION_SELF) { @@ -2265,10 +2265,10 @@ protected function social_login_user_add ($user_random_email, $user_data) { $email_template = 'user_welcome'; } - + // Url for activation. $server_url = generate_board_url (); - + // Send email to new user $messenger = new \messenger (false); $messenger->template ($email_template, $user_row ['user_lang']); @@ -2278,42 +2278,42 @@ protected function social_login_user_add ($user_random_email, $user_data) 'WELCOME_MSG' => htmlspecialchars_decode (sprintf ($user->lang ['WELCOME_SUBJECT'], $config ['sitename'])), 'USERNAME' => htmlspecialchars_decode ($user_row ['username']), 'PASSWORD' => htmlspecialchars_decode ($new_password), - 'U_ACTIVATE' => $server_url . '/ucp.' . $phpEx . '?mode=activate&u=' . $user_id . '&k=' . $user_actkey + 'U_ACTIVATE' => $server_url . '/ucp.' . $phpEx . '?mode=activate&u=' . $user_id . '&k=' . $user_actkey )); $messenger->send (NOTIFY_EMAIL); $messenger->save_queue (); - + // Send email to administrators. if ($config ['require_activation'] == USER_ACTIVATION_ADMIN) { // Read founders. $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type FROM ' . USERS_TABLE . ' WHERE user_type = ' . USER_FOUNDER; - + // Grab an array of user_id's with a_user permissions ... these users can activate a user. $acl_admins = $auth->acl_get_list (false, 'a_user', false); $acl_admins = (!empty ($acl_admins [0] ['a_user'])) ? $acl_admins [0] ['a_user'] : array(); - + // Include admins if (is_array ($acl_admins) && count ($acl_admins) > 0) { $sql .= ' OR ' . $db->sql_in_set ('user_id', $acl_admins); } - + // Retrieve founders/admins $query = $db->sql_query ($sql); - + // Send emails to them while ( $row = $db->sql_fetchrow ($query) ) { $messenger->template ('admin_activate', $row ['user_lang']); $messenger->set_addresses ($row); - + $messenger->assign_vars (array( 'USERNAME' => htmlspecialchars_decode ($user_row ['username']), 'U_USER_DETAILS' => $server_url . '/memberlist.' . $phpEx . '?mode=viewprofile&u=' . $user_id, - 'U_ACTIVATE' => $server_url . '/ucp.' . $phpEx . '?mode=activate&u=' . $user_id . '&k=' . $user_actkey + 'U_ACTIVATE' => $server_url . '/ucp.' . $phpEx . '?mode=activate&u=' . $user_id . '&k=' . $user_actkey )); - + $messenger->send ($row ['user_notify_type']); } $db->sql_freeresult ($query); @@ -2322,7 +2322,7 @@ protected function social_login_user_add ($user_random_email, $user_data) } return array( $error_message, - $user_id + $user_id ); } } @@ -2333,7 +2333,7 @@ protected function social_login_user_add ($user_random_email, $user_data) protected function social_login_redirect ($error_message, $user_id, $user_data) { global $user, $phpbb_root_path, $phpEx, $config, $request; - + // Display an error message if (isset ($error_message)) { @@ -2347,28 +2347,28 @@ protected function social_login_redirect ($error_message, $user_id, $user_data) { // Update statistics $this->count_login_identity_token ($user_data ['identity_token']); - + // Log the user in $this->do_login ($user_id); - + // Redirect to a custom page if (!empty ($config ['oa_social_login_redirect'])) { self::http_redirect (append_sid ($config ['oa_social_login_redirect'])); } - + // Do not stay on the login/registration page if (in_array ($request->variable ('mode', ''), array('login', 'register'))) { self::http_redirect (append_sid ($phpbb_root_path . 'index.' . $phpEx)); } - + // If the user validated his credentials, then the original page is in session data: if (isset ($user_data ['redirect'])) { self::http_redirect (append_sid ($user_data ['redirect'])); } - + // Default: Reload the page self::http_redirect (append_sid (self::get_current_url ())); } @@ -2381,32 +2381,32 @@ public static function http_redirect ($url) { redirect ($url, false, true); } - + /** * Check if the current connection is being made over https */ private static function is_https_on () { global $request; - + if ($request->server ('SERVER_PORT') == 443) { return true; } - + if ($request->server ('HTTP_X_FORWARDED_PROTO') == 'https') { return true; } - + if (in_array (strtolower (trim ($request->server ('HTTPS'))), array( 'on', - '1' + '1' ))) { return true; } - + return false; } @@ -2416,7 +2416,7 @@ private static function is_https_on () function get_current_url ($remove_vars = array ('oa_social_login_login_token', 'sid')) { global $request; - + // Extract Uri if (strlen (trim ($request->server ('REQUEST_URI'))) > 0) { @@ -2426,10 +2426,10 @@ function get_current_url ($remove_vars = array ('oa_social_login_login_token', ' { $request_uri = trim ($request->server ('PHP_SELF')); } - + // Decod $request_uri = htmlspecialchars_decode ($request_uri); - + // Extract Protocol if (self::is_https_on ()) { @@ -2439,7 +2439,7 @@ function get_current_url ($remove_vars = array ('oa_social_login_login_token', ' { $request_protocol = 'http'; } - + // Extract Host if (strlen (trim ($request->server ('HTTP_X_FORWARDED_HOST'))) > 0) { @@ -2453,10 +2453,10 @@ function get_current_url ($remove_vars = array ('oa_social_login_login_token', ' { $request_host = trim ($request->server ('SERVER_NAME')); } - + // Port of this request $request_port = ''; - + // We are using a proxy if (strlen (trim ($request->server ('HTTP_X_FORWARDED_PORT'))) > 0) { @@ -2468,20 +2468,20 @@ function get_current_url ($remove_vars = array ('oa_social_login_login_token', ' { $request_port = intval ($request->server ('SERVER_PORT')); } - + // Remove standard ports $request_port = (!in_array ($request_port, array(80, 443)) ? $request_port : ''); - + // Build url $current_url = $request_protocol . '://' . $request_host . (!empty ($request_port) ? (':' . $request_port) : '') . $request_uri; - + // Remove query arguments. if (is_array ($remove_vars) && count ($remove_vars) > 0) { // Break up url list ($url_part, $query_part) = array_pad (explode ('?', $current_url), 2, ''); parse_str ($query_part, $query_vars); - + // Remove argument. if (is_array ($query_vars)) { @@ -2492,12 +2492,12 @@ function get_current_url ($remove_vars = array ('oa_social_login_login_token', ' unset ($query_vars [$var]); } } - + // Build new url $current_url = $url_part . ((is_array ($query_vars) and count ($query_vars) > 0) ? ('?' . http_build_query ($query_vars)) : ''); } } - + // Done return $current_url; } @@ -2508,7 +2508,7 @@ function get_current_url ($remove_vars = array ('oa_social_login_login_token', ' public function upload_user_avatar ($user_id, $user_data) { global $db, $phpbb_root_path, $phpEx, $user, $config; - + // Make sure avatars are allowed if ($config ['allow_avatar_upload']) { @@ -2517,75 +2517,75 @@ public function upload_user_avatar ($user_id, $user_data) { // Use this avatar $user_avatar_url = (!empty ($user_data ['user_picture']) ? $user_data ['user_picture'] : $user_data ['user_thumbnail']); - + // Which connection handler do we have to use? $api_connection_handler = ((!empty ($config ['oa_social_login_api_connection_handler']) && $config ['oa_social_login_api_connection_handler'] == 'fsockopen') ? 'fsockopen' : 'curl'); - + // Retrieve file data $api_result = self::do_api_request ($api_connection_handler, $user_avatar_url); - + // Success? if (is_object ($api_result) && property_exists ($api_result, 'http_code') && $api_result->http_code == 200) { // File data $file_data = $api_result->http_data; - + // Temporary filename $file_tmp_path = (@ini_get ('open_basedir') || @ini_get ('safe_mode') || strtolower (@ini_get ('safe_mode')) == 'on') ? $phpbb_root_path . 'cache' : false; $file_tmp_name = tempnam ($file_tmp_path, unique_id () . '-'); - + // Save file if (($fp = @fopen ($file_tmp_name, 'wb')) !== false) { // Write file $avatar_size = fwrite ($fp, $file_data); fclose ($fp); - + // Allowed file extensions $file_exts = array(); $file_exts [IMAGETYPE_GIF] = 'gif'; $file_exts [IMAGETYPE_JPEG] = 'jpg'; $file_exts [IMAGETYPE_PNG] = 'png'; - + // Get image data list ($width, $height, $type, $attr) = @getimagesize ($file_tmp_name); - + // Check image size and type if ($width > $config ['avatar_min_width'] && $height > $config ['avatar_min_height'] && isset ($file_exts [$type])) { // File extension $file_ext = $file_exts [$type]; - + // Check if we can resize the image if needd if (function_exists ('imagecreatetruecolor') && function_exists ('imagecopyresampled')) { $max_height = $config ['avatar_max_height']; $max_width = $config ['avatar_max_width']; - + // Check if we need to resize if ($width > $max_width || $height > $max_height) { // Keep original size $orig_height = $height; $orig_width = $width; - + // Taller if ($height > $max_height) { $width = ($max_height / $height) * $width; $height = $max_height; } - + // Wider if ($width > $max_width) { $height = ($max_width / $width) * $height; $width = $max_width; } - + // Destination $destination = imagecreatetruecolor ($width, $height); - + // Resize switch ($file_ext) { @@ -2594,13 +2594,13 @@ public function upload_user_avatar ($user_id, $user_data) imagecopyresampled ($destination, $source, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height); imagegif ($destination, $file_tmp_name); break; - + case 'png' : $source = imagecreatefrompng ($file_tmp_name); imagecopyresampled ($destination, $source, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height); imagepng ($destination, $file_tmp_name); break; - + case 'jpg' : $source = imagecreatefromjpeg ($file_tmp_name); imagecopyresampled ($destination, $source, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height); @@ -2609,32 +2609,32 @@ public function upload_user_avatar ($user_id, $user_data) } } } - + // Final path $avatar_name = $config ['avatar_salt'] . '_' . $user_id . '.' . $file_exts [$type]; $avatar_full_name = $phpbb_root_path . $config ['avatar_path'] . '/' . $avatar_name; - + // Move file if (@copy ($file_tmp_name, $avatar_full_name)) { // Remove temporary file @unlink ($file_tmp_name); - + $sql_arr = array(); $sql_arr ['user_avatar'] = ($user_id . '_' . time () . '.' . $file_ext); $sql_arr ['user_avatar_type'] = AVATAR_UPLOAD; $sql_arr ['user_avatar_width'] = $width; $sql_arr ['user_avatar_height'] = $height; - + // Update user $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array ('UPDATE', $sql_arr) . ' WHERE user_id = ' . $user_id; $db->sql_query ($sql); - + // Done return true; } } - + // Error @unlink ($file_tmp_name); return false; @@ -2642,7 +2642,7 @@ public function upload_user_avatar ($user_id, $user_data) } } } - + // Error return false; }