public function find_other_user_details($user_hints, $current_extension, $message_object) { $details = array('messages' => array(), 'user' => array(), 'user_ids' => array()); // find other ucm messages by this user. if (!empty($user_hints['shub_user_id'])) { if (!is_array($user_hints['shub_user_id'])) { $user_hints['shub_user_id'] = array($user_hints['shub_user_id']); } foreach ($user_hints['shub_user_id'] as $shub_user_id) { if ((int) $shub_user_id > 0) { $details['user_ids'][$shub_user_id] = $shub_user_id; $shub_user = new SupportHubUser_ucm($shub_user_id); $envato_username = $shub_user->get_meta('envato_username'); if ($envato_username) { foreach ($envato_username as $envato_username1) { if (!empty($envato_username1)) { // todo - display multiple. $details['user']['username'] = $envato_username1; $details['user']['url'] = 'http://themeforest.net/user/' . $envato_username1; // see if we can find any other matching user accounts for this username $other_users = new SupportHubUser_ucm(); $other_users->load_by('user_username', $envato_username1); if ($other_users->get('shub_user_id') && !in_array($other_users->get('shub_user_id'), $user_hints['shub_user_id'])) { // pass these back to the calling method so we can get the correct values. $details['user_ids'][$other_users->get('shub_user_id')] = $other_users->get('shub_user_id'); } } } } } } } return $details; }
public function get_api_user_to_id($ucm_user_data) { //print_r($ucm_user_data);exit; $comment_user = new SupportHubUser_ucm(); if (!empty($ucm_user_data['email'])) { $comment_user->load_by('user_email', trim(strtolower($ucm_user_data['email']))); } if (!$comment_user->get('shub_user_id')) { // didn't find one yet. // find by envato username? if (isset($ucm_user_data['envato']['user'])) { $first = current($ucm_user_data['envato']['user']); if ($first && !empty($first['envato_username'])) { if ($comment_user->load_by_meta('envato_username', strtolower($first['envato_username']))) { // found! yay! SupportHub::getInstance()->log_data(_SUPPORT_HUB_LOG_INFO, 'ucm', 'Found a user based on envato username.', array('username' => $first['envato_username'], 'found_user_id' => $comment_user->get('shub_user_id'))); } } } } if (isset($ucm_user_data['envato']['purchases']) && is_array($ucm_user_data['envato']['purchases'])) { // find a matching user account with these purchases. foreach ($ucm_user_data['envato']['purchases'] as $purchase) { if (!empty($purchase['license_code'])) { // pull in the license code using the envato module if it's enabled. if (isset(SupportHub::getInstance()->message_managers['envato'])) { $result = SupportHub::getInstance()->message_managers['envato']->pull_purchase_code(false, $purchase['license_code'], array(), $comment_user->get('shub_user_id')); if ($result && !empty($result['shub_user_id'])) { $comment_user->load($result['shub_user_id']); SupportHub::getInstance()->log_data(_SUPPORT_HUB_LOG_INFO, 'ucm', 'Found a user based on license code.', array('license_code' => $purchase['license_code'], 'found_user_id' => $comment_user->get('shub_user_id'))); break; } } } } } if (!$comment_user->get('shub_user_id')) { // find a match based on email. if (!empty($ucm_user_data['email'])) { $comment_user->load_by('user_email', trim(strtolower($ucm_user_data['email']))); } } if (!$comment_user->get('shub_user_id')) { // no existing matches yet, create a new user with the above meta values so that we can find them again in the future. $comment_user->create_new(); } // now we add/update various meta/values of the user if anything is missing. if (!empty($ucm_user_data['email']) && !$comment_user->get('user_email')) { $comment_user->update('user_email', trim(strtolower($ucm_user_data['email']))); } if (isset($ucm_user_data['envato']['user'])) { $first = current($ucm_user_data['envato']['user']); if ($first && !empty($first['envato_username']) && !$comment_user->get_meta('envato_username', strtolower($first['envato_username']))) { $comment_user->add_meta('envato_username', strtolower($first['envato_username'])); if (!$comment_user->get('user_username')) { $comment_user->update('user_username', strtolower($first['envato_username'])); } } } if (isset($ucm_user_data['envato']['purchases'])) { foreach ($ucm_user_data['envato']['purchases'] as $purchase) { if (!empty($purchase['license_code']) && !$comment_user->get_meta('envato_license_code', strtolower($purchase['license_code']))) { $comment_user->add_meta('envato_license_code', strtolower($purchase['license_code'])); } } } if (!empty($ucm_user_data['name'])) { if (empty($ucm_user_data['last_name'])) { $bits = explode(" ", $ucm_user_data['name']); $ucm_user_data['name'] = array_shift($bits); $ucm_user_data['last_name'] = implode(" ", $bits); } } if (!$comment_user->get('user_fname') && !empty($ucm_user_data['name'])) { $comment_user->update('user_fname', $ucm_user_data['name']); } if (!$comment_user->get('user_lname') && !empty($ucm_user_data['last_name'])) { $comment_user->update('user_lname', $ucm_user_data['last_name']); } $comment_user->update_user_data($ucm_user_data); return $comment_user->get('shub_user_id'); }