本文整理汇总了PHP中JUserHelper::getUserId方法的典型用法代码示例。如果您正苦于以下问题:PHP JUserHelper::getUserId方法的具体用法?PHP JUserHelper::getUserId怎么用?PHP JUserHelper::getUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUserHelper
的用法示例。
在下文中一共展示了JUserHelper::getUserId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* validate the elements data against the rule
* @param string data to check
* @param object element
* @param int plugin sequence ref
* @return bol true if validation passes, false if fails
*/
function validate($data, &$element, $c)
{
$params =& $this->getParams();
$ornot = $params->get('userexists_or_not');
$condition = $params->get('userexists-validation_condition');
$condition = $condition[$c];
if ($condition !== '') {
if (@eval($condition)) {
return true;
}
}
$ornot = $ornot[$c];
jimport('joomla.user.helper');
$id = 0;
if (!($id = JUserHelper::getUserId($data))) {
if ($ornot == 'fail_if_exists') {
return true;
}
} else {
if ($ornot == 'fail_if_not_exists') {
return true;
}
}
return false;
}
示例2: get
/**
* Returns the global KunenaUser object, only creating it if it doesn't already exist.
*
* @param mixed $identifier The user to load - Can be an integer or string - If string, it is converted to ID automatically.
* @param bool $reload Reload user from database.
*
* @return KunenaUser
*/
public static function get($identifier = null, $reload = false)
{
KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
if ($identifier === null || $identifier === false) {
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return self::$_me;
}
if ($identifier instanceof KunenaUser) {
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return $identifier;
}
// Find the user id
if ($identifier instanceof JUser) {
$id = (int) $identifier->id;
} elseif ((string) (int) $identifier === (string) $identifier) {
// Ignore imported users, which haven't been mapped to Joomla (id<0).
$id = (int) max($identifier, 0);
} else {
// Slow, don't use usernames!
$id = (int) JUserHelper::getUserId((string) $identifier);
}
// Always return fresh user if id is anonymous/not found
if ($id === 0) {
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return new KunenaUser($id);
} elseif ($reload || empty(self::$_instances[$id])) {
self::$_instances[$id] = new KunenaUser($id);
// Preload avatar if configured.
$avatars = KunenaFactory::getAvatarIntegration();
$avatars->load(array($id));
}
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return self::$_instances[$id];
}
示例3: getChannels
/**
* getChannels
*
* @param string $author Param
*
* @return array
*/
public function getChannels($author)
{
$channels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel');
$channels->set('published', true);
$channels->set('scope', 'S');
$channels->set('filter_order', 'ordering');
$channels->set('filter_order_Dir', 'ASC');
$list = $channels->getItemList(true);
if (!empty($author)) {
$user_id = JUserHelper::getUserId($author);
if ($user_id) {
$userChannels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel');
$userChannels->set('published', true);
$userChannels->set('scope', 'U');
$userChannels->set('created_by', $user_id);
$userChannels->set('filter_order', 'ordering');
$userChannels->set('filter_order_Dir', 'ASC');
$userList = $userChannels->getItemList(true);
$list = array_merge($list, $userList);
}
}
$channels = array();
foreach ($list as $channel) {
$channels[$channel->id] = self::createChannel($channel);
}
$logger = AutotweetLogger::getInstance();
$channels_ids = array_keys($channels);
$logger->log(JLog::INFO, 'ChannelFactory getChannels user=' . $author, $channels_ids);
return $channels;
}
示例4: createUser
/**
* @inheritDoc
*/
public function createUser(&$params, $mail)
{
$baseDir = JPATH_SITE;
require_once $baseDir . '/components/com_users/models/registration.php';
$userParams = JComponentHelper::getParams('com_users');
$model = new UsersModelRegistration();
$ufID = NULL;
// get the default usertype
$userType = $userParams->get('new_usertype');
if (!$userType) {
$userType = 2;
}
if (isset($params['name'])) {
$fullname = trim($params['name']);
} elseif (isset($params['contactID'])) {
$fullname = trim(CRM_Contact_BAO_Contact::displayName($params['contactID']));
} else {
$fullname = trim($params['cms_name']);
}
// Prepare the values for a new Joomla user.
$values = array();
$values['name'] = $fullname;
$values['username'] = trim($params['cms_name']);
$values['password1'] = $values['password2'] = $params['cms_pass'];
$values['email1'] = $values['email2'] = trim($params[$mail]);
$lang = JFactory::getLanguage();
$lang->load('com_users', $baseDir);
$register = $model->register($values);
$ufID = JUserHelper::getUserId($values['username']);
return $ufID;
}
示例5: getInstance
/**
* Returns the global KunenaUser object, only creating it if it doesn't already exist.
*
* @access public
* @param int $id The user to load - Can be an integer or string - If string, it is converted to ID automatically.
* @return JUser The User object.
* @since 1.6
*/
public static function getInstance($identifier = null, $reset = false)
{
$c = __CLASS__;
if ($identifier instanceof KunenaUser) {
return $identifier;
}
if ($identifier === null || $identifier === false) {
$identifier = JFactory::getUser();
}
// Find the user id
if ($identifier instanceof JUser) {
$id = intval($identifier->id);
} else {
if (is_numeric($identifier)) {
$id = intval($identifier);
} else {
jimport('joomla.user.helper');
$id = intval(JUserHelper::getUserId((string) $identifier));
}
}
if ($id < 1) {
return new $c();
}
if (!$reset && empty(self::$_instances[$id])) {
self::$_instances[$id] = new $c($id);
}
return self::$_instances[$id];
}
示例6: get
/**
* Returns the global KunenaUserHelper object, only creating it if it doesn't already exist.
*
* @access public
* @param int $id The user to load - Can be an integer or string - If string, it is converted to ID automatically.
* @return JUser The User object.
* @since 1.6
*/
public static function get($identifier = null, $reload = false)
{
KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
if ($identifier === null || $identifier === false) {
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return self::$_me;
}
if ($identifier instanceof KunenaUser) {
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return $identifier;
}
// Find the user id
if ($identifier instanceof JUser) {
$id = intval($identifier->id);
} else {
if (is_numeric($identifier)) {
$id = intval($identifier);
} else {
jimport('joomla.user.helper');
$id = intval(JUserHelper::getUserId((string) $identifier));
}
}
// Always return fresh user if id is anonymous/not found
if ($id === 0) {
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return new KunenaUser($id);
} else {
if ($reload || empty(self::$_instances[$id])) {
self::$_instances[$id] = new KunenaUser($id);
}
}
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
return self::$_instances[$id];
}
示例7: _getUser
/**
* This method will return a user object
*
* If options['autoregister'] is true, if the user doesn't exist yet he will be created
*
* @param array $user Holds the user data.
* @param array $options Array holding options (remember, autoregister, group).
*
* @return object A JUser object
* @since 1.5
*/
protected function _getUser($user, $options = array())
{
$instance = JUser::getInstance();
if ($id = intval(JUserHelper::getUserId($user['username']))) {
$instance->load($id);
return $instance;
}
//TODO : move this out of the plugin
jimport('joomla.application.component.helper');
$config = JComponentHelper::getParams('com_users');
// Default to Registered.
$defaultUserGroup = $config->get('new_usertype', 2);
$acl = JFactory::getACL();
$instance->set('id', 0);
$instance->set('name', $user['fullname']);
$instance->set('username', $user['username']);
$instance->set('password_clear', $user['password_clear']);
$instance->set('email', $user['email']);
// Result should contain an email (check)
$instance->set('usertype', 'deprecated');
$instance->set('groups', array($defaultUserGroup));
//If autoregister is set let's register the user
$autoregister = isset($options['autoregister']) ? $options['autoregister'] : $this->params->get('autoregister', 1);
if ($autoregister) {
if (!$instance->save()) {
return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError());
}
} else {
// No existing user and autoregister off, this is a temporary user.
$instance->set('tmp_user', true);
}
return $instance;
}
示例8: display
function display($tpl = null)
{
$user = User::getRoot();
// If this is an auth_link account update, carry on, otherwise raise an error
if (!is_object($user) || !array_key_exists('auth_link_id', $user) || !is_numeric($user->get('username')) || !$user->get('username') < 0) {
App::abort('405', 'Method not allowed');
return;
}
// Get and add the js and extra css to the page
\Hubzero\Document\Assets::addComponentStylesheet('com_users', 'link.css');
\Hubzero\Document\Assets::addComponentStylesheet('com_users', 'providers.css');
\Hubzero\Document\Assets::addComponentScript('com_users', 'link');
// Import a few things
jimport('joomla.user.helper');
// Look up a few things
$hzal = \Hubzero\Auth\Link::find_by_id($user->get("auth_link_id"));
$hzad = \Hubzero\Auth\Domain::find_by_id($hzal->auth_domain_id);
$plugins = Plugin::byType('authentication');
// Get the display name for the current plugin being used
Plugin::import('authentication', $hzad->authenticator);
$plugin = Plugin::byType('authentication', $hzad->authenticator);
$pparams = new \Hubzero\Config\Registry($plugin->params);
$refl = new ReflectionClass("plgAuthentication{$plugin->name}");
$display_name = $pparams->get('display_name', $refl->hasMethod('onGetLinkDescription') ? $refl->getMethod('onGetLinkDescription')->invoke(NULL) : ucfirst($plugin->name));
// Look for conflicts - first check in the hub accounts
$profile_conflicts = \Hubzero\User\Profile\Helper::find_by_email($hzal->email);
// Now check the auth_link table
$link_conflicts = \Hubzero\Auth\Link::find_by_email($hzal->email, array($hzad->id));
$conflict = array();
if ($profile_conflicts) {
foreach ($profile_conflicts as $p) {
$user_id = JUserHelper::getUserId($p);
$juser = User::getInstance($user_id);
$auth_link = \Hubzero\Auth\Link::find_by_user_id($juser->id);
$dname = is_object($auth_link) && $auth_link->auth_domain_name ? $auth_link->auth_domain_name : 'hubzero';
$conflict[] = array("auth_domain_name" => $dname, "name" => $juser->name, "email" => $juser->email);
}
}
if ($link_conflicts) {
foreach ($link_conflicts as $l) {
$juser = User::getInstance($l['user_id']);
$conflict[] = array("auth_domain_name" => $l['auth_domain_name'], "name" => $juser->name, "email" => $l['email']);
}
}
// Make sure we don't somehow have any duplicate conflicts
$conflict = array_map("unserialize", array_unique(array_map("serialize", $conflict)));
// @TODO: Could also check for high probability of name matches???
// Get the site name
$sitename = Config::get('sitename');
// Assign variables to the view
$this->assign('hzal', $hzal);
$this->assign('hzad', $hzad);
$this->assign('plugins', $plugins);
$this->assign('display_name', $display_name);
$this->assign('conflict', $conflict);
$this->assign('sitename', $sitename);
$this->assignref('juser', $user);
parent::display($tpl);
}
示例9: validate
/**
* Validate the elements data against the rule
*
* @param string $data to check
* @param object &$elementModel element Model
* @param int $pluginc plugin sequence ref
* @param int $repeatCounter repeat group counter
*
* @return bool true if validation passes, false if fails
*/
public function validate($data, &$elementModel, $pluginc, $repeatCounter)
{
$params = $this->getParams();
$pluginc = trim((string) $pluginc);
// As ornot is a radio button it gets json encoded/decoded as an object
$ornot = (object) $params->get('userexists_or_not');
$ornot = isset($ornot->{$pluginc}) ? $ornot->{$pluginc} : 'fail_if_exists';
$user = JFactory::getUser();
jimport('joomla.user.helper');
$result = JUserHelper::getUserId($data);
if ($user->get('guest')) {
if (!$result) {
if ($ornot == 'fail_if_exists') {
return true;
}
} else {
if ($ornot == 'fail_if_not_exists') {
return true;
}
}
return false;
} else {
if (!$result) {
if ($ornot == 'fail_if_exists') {
return true;
}
} else {
$user_field = (array) $params->get('userexists_user_field', array());
$user_field = $user_field[$pluginc];
$user_id = 0;
if ((int) $user_field !== 0) {
$user_elementModel = FabrikWorker::getPluginManager()->getElementPlugin($user_field);
$user_fullName = $user_elementModel->getFullName(false, true, false);
$user_field = $user_elementModel->getFullName(false, false, false);
}
if (!empty($user_field)) {
// $$$ the array thing needs fixing, for now just grab 0
$formdata = $elementModel->getForm()->_formData;
$user_id = JArrayHelper::getValue($formdata, $user_fullName . '_raw', JArrayHelper::getValue($formdata, $user_fullName, ''));
if (is_array($user_id)) {
$user_id = JArrayHelper::getValue($user_id, 0, '');
}
}
if ($user_id != 0) {
if ($result == $user_id) {
return $ornot == 'fail_if_exists' ? true : false;
}
return false;
} else {
// The connected user is editing his own data
if ($result == $user->get('id')) {
return $ornot == 'fail_if_exists' ? true : false;
}
return false;
}
}
return false;
}
}
示例10: validate
/**
* Validate the elements data against the rule
*
* @param string $data To check
* @param int $repeatCounter Repeat group counter
*
* @return bool true if validation passes, false if fails
*/
public function validate($data, $repeatCounter)
{
$params = $this->getParams();
$elementModel = $this->elementModel;
// As ornot is a radio button it gets json encoded/decoded as an object
$orNot = $params->get('userexists_or_not', 'fail_if_exists');
jimport('joomla.user.helper');
$result = JUserHelper::getUserId($data);
if ($this->user->get('guest')) {
if (!$result) {
if ($orNot == 'fail_if_exists') {
return true;
}
} else {
if ($orNot == 'fail_if_not_exists') {
return true;
}
}
return false;
} else {
if (!$result) {
if ($orNot == 'fail_if_exists') {
return true;
}
} else {
$userField = $params->get('userexists_user_field');
$userId = 0;
if ((int) $userField !== 0) {
$userElementModel = FabrikWorker::getPluginManager()->getElementPlugin($userField);
$userFullName = $userElementModel->getFullName(true, false);
$userField = $userElementModel->getFullName(false, false);
}
if (!empty($userField)) {
// $$$ the array thing needs fixing, for now just grab 0
$formData = $elementModel->getForm()->formData;
$userId = FArrayHelper::getValue($formData, $userFullName . '_raw', FArrayHelper::getValue($formData, $userFullName, ''));
if (is_array($userId)) {
$userId = FArrayHelper::getValue($userId, 0, '');
}
}
if ($userId != 0) {
if ($result == $userId) {
return $orNot == 'fail_if_exists' ? true : false;
}
return false;
} else {
// The connected user is editing his own data
if ($result == $this->user->get('id')) {
return $orNot == 'fail_if_exists' ? true : false;
}
return false;
}
}
return false;
}
}
示例11: activate_joomla_user
static function activate_joomla_user($username)
{
$user_id = JUserHelper::getUserId($username);
$user = JFactory::getUser($user_id);
$user->set('block', '0');
if (!$user->save()) {
return false;
}
return true;
}
示例12: send_registration_email
static function send_registration_email($username, $password)
{
$config = JFactory::getConfig();
$params = JComponentHelper::getParams('com_users');
$useractivation = $params->get('useractivation');
$sendpassword = $params->get('sendpassword', 1);
JPlugin::loadLanguage('com_users', JPATH_SITE);
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$data['siteurl'] = JUri::base();
$user_id = JUserHelper::getUserId($username);
$user = JFactory::getUser($user_id);
$data['username'] = $username;
$data['password_clear'] = $password;
$data['name'] = $user->name;
$data['email'] = $user->email;
$data['activation'] = $user->activation;
// Handle account activation/confirmation emails.
if ($useractivation == 2) {
// Set the link to confirm the user email.
$uri = JURI::getInstance();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
$emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
if ($sendpassword) {
$emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']);
} else {
$emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']);
}
} else {
if ($useractivation == 1) {
// Set the link to activate the user account.
$uri = JURI::getInstance();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
$emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
if ($sendpassword) {
$emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']);
} else {
$emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']);
}
} else {
$emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
if ($sendpassword) {
$emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']);
} else {
$emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']);
}
}
}
// Send the registration email.
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
}
示例13: getUserByUsername
/**
* Get user by username
*
* @param string $username The username of the user to load
*
* @return \JUser|null A user object if it exists, null if it doesn't
*/
public function getUserByUsername($username)
{
try {
$id = \JUserHelper::getUserId($username);
} catch (\Exception $e) {
$id = null;
}
if (empty($id)) {
return null;
}
return $this->getUser($id);
}
示例14: onBeforeBrowse
public function onBeforeBrowse()
{
// If we have a username/password pair, log in the user if he's a guest
$username = $this->input->getString('username', '');
$password = $this->input->getString('password', '');
$user = JFactory::getUser();
if ($user->guest && !empty($username) && !empty($password)) {
JLoader::import('joomla.user.authentication');
$credentials = array('username' => $username, 'password' => $password);
$app = JFactory::getApplication();
$options = array('remember' => false);
$authenticate = JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials, $options);
if ($response->status == JAuthentication::STATUS_SUCCESS) {
JPluginHelper::importPlugin('user');
$results = $app->triggerEvent('onLoginUser', array((array) $response, $options));
JLoader::import('joomla.user.helper');
$userid = JUserHelper::getUserId($response->username);
$user = JFactory::getUser($userid);
$parameters['username'] = $user->get('username');
$parameters['id'] = $user->get('id');
}
}
// If we still have a guest user, show the login page
if ($user->guest) {
// Show login page
$juri = JURI::getInstance();
$myURI = base64_encode($juri->toString());
$com = version_compare(JVERSION, '1.6.0', 'ge') ? 'users' : 'user';
JFactory::getApplication()->redirect(JURI::base() . 'index.php?option=com_' . $com . '&view=login&return=' . $myURI);
return false;
}
// Does the user have core.manage access or belongs to SA group?
$isAdmin = $user->authorise('core.manage', 'com_akeebasubs');
if ($this->input->getInt('allUsers', 0) && $isAdmin) {
$this->getThisModel()->user_id(null);
} else {
$this->getThisModel()->user_id(JFactory::getUser()->id);
}
if ($this->input->getInt('allStates', 0) && $isAdmin) {
$this->getThisModel()->paystate(null);
} else {
$this->getThisModel()->paystate('C,P');
}
// Let me cheat. If the request doesn't specify how many records to show, show them all!
if ($this->input->getCmd('format', 'html') != 'html') {
if (!$this->input->getInt('limit', 0) && !$this->input->getInt('limitstart', 0)) {
$this->getThisModel()->limit(0);
$this->getThisModel()->limitstart(0);
}
}
return true;
}
示例15: addTask
/**
* Short description for 'addmanager'
*
* @return void
*/
public function addTask()
{
// Check for request forgeries
Request::checkToken();
// Incoming member ID
$id = Request::getInt('id', 0);
if (!$id) {
$this->setError(Lang::txt('COM_COURSES_ERROR_NO_ID'));
$this->displayTask();
return;
}
// Load the profile
$course = \Components\Courses\Models\Course::getInstance($id);
$managers = $course->managers();
//get('managers');
// Incoming host
$m = Request::getVar('usernames', '', 'post');
$mbrs = explode(',', $m);
jimport('joomla.user.helper');
$users = array();
foreach ($mbrs as $mbr) {
// Retrieve user's account info
$mbr = trim($mbr);
// User ID
if (is_numeric($mbr)) {
// Make sure the user exists
$user = User::getInstance($mbr);
if (is_object($user) && $user->get('username')) {
$uid = $mbr;
}
} else {
$uid = \JUserHelper::getUserId($mbr);
}
// Ensure we found an account
if ($uid) {
// Loop through existing members and make sure the user isn't already a member
if (isset($managers[$uid])) {
$this->setError(Lang::txt('COM_COURSES_ERROR_ALREADY_MANAGER', $mbr));
continue;
}
// They user is not already a member, so we can go ahead and add them
$users[] = $uid;
} else {
$this->setError(Lang::txt('COM_COURSES_ERROR_USER_NOTFOUND') . ' ' . $mbr);
}
}
// Add users
$course->add($users, Request::getInt('role', 0));
// Push through to the hosts view
$this->displayTask($course);
}