本文整理汇总了PHP中get_user_by_username函数的典型用法代码示例。如果您正苦于以下问题:PHP get_user_by_username函数的具体用法?PHP get_user_by_username怎么用?PHP get_user_by_username使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_by_username函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: polls_page_handler
/**
* poll page handler; allows the use of fancy URLs
*
* @param array $page From the page_handler function
* @return true|false Depending on success
*/
function polls_page_handler($page)
{
elgg_load_library('elgg:polls');
$page_type = $page[0];
switch ($page_type) {
case "view":
echo polls_get_page_view($page[1]);
break;
case "all":
echo polls_get_page_list($page_type);
break;
case "add":
case "edit":
echo polls_get_page_edit($page_type, $page[1]);
break;
case "friends":
case "owner":
$username = $page[1];
$user = get_user_by_username($username);
$user_guid = $user->guid;
echo polls_get_page_list($page_type, $user_guid);
break;
case "group":
echo polls_get_page_list($page_type, $page[1]);
break;
default:
return FALSE;
break;
}
return TRUE;
}
示例2: page_owner
/**
* Gets the page owner for the current page.
* @uses $CONFIG
* @return int|false The current page owner guid (0 if none).
*/
function page_owner()
{
global $CONFIG;
$setpageowner = set_page_owner();
if ($setpageowner !== false) {
return $setpageowner;
}
if ($username = get_input("username")) {
//if (substr_count($username,'group:')) {
if (substr_count($username, 'group_')) {
//preg_match('/group\:([0-9]+)/i',$username,$matches);
preg_match('/group\\_([0-9]+)/i', $username, $matches);
$guid = $matches[1];
if ($entity = get_entity($guid)) {
return $entity->getGUID();
}
}
if ($user = get_user_by_username($username)) {
return $user->getGUID();
}
}
if ($owner = get_input("owner_guid")) {
if ($user = get_entity($owner)) {
return $user->getGUID();
}
}
if (!empty($CONFIG->page_owner_handlers) && is_array($CONFIG->page_owner_handlers)) {
foreach ($CONFIG->page_owner_handlers as $handler) {
if ($guid = $handler()) {
return $guid;
}
}
}
return 0;
}
示例3: triggerMentionNotificationEvent
/**
* This functions performs actions when a wire post is created
*
* @param string $event 'create'
* @param string $type 'object'
* @param \ElggObject $object the ElggObject created
*
* @return void
*/
public static function triggerMentionNotificationEvent($event, $type, \ElggObject $object)
{
if (!elgg_instanceof($object, 'object', 'thewire')) {
return;
}
// @todo replace with decent Elgg 2.0 notification event handling
//send out notification to users mentioned in a wire post
$usernames = [];
preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames);
if (empty($usernames)) {
return;
}
$usernames = array_unique($usernames[0]);
$params = ['object' => $object, 'action' => 'mention'];
foreach ($usernames as $username) {
$username = str_ireplace('@', '', $username);
$user = get_user_by_username($username);
if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) {
continue;
}
$setting = thewire_tools_get_notification_settings($user->getGUID());
if (empty($setting)) {
continue;
}
$subject = elgg_echo('thewire_tools:notify:mention:subject');
$message = elgg_echo('thewire_tools:notify:mention:message', [$user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@{$user->username}")]);
notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting);
}
}
示例4: profile_page_handler
/**
* Profile page handler
*
* @param array $page Array of URL segments passed by the page handling mechanism
* @return bool
*/
function profile_page_handler($page)
{
if (isset($page[0])) {
$username = $page[0];
$user = get_user_by_username($username);
elgg_set_page_owner_guid($user->guid);
} elseif (elgg_is_logged_in()) {
forward(elgg_get_logged_in_user_entity()->getURL());
}
// short circuit if invalid or banned username
if (!$user || $user->isBanned() && !elgg_is_admin_logged_in()) {
register_error(elgg_echo('profile:notfound'));
forward();
}
$action = NULL;
if (isset($page[1])) {
$action = $page[1];
}
if ($action == 'edit') {
// use the core profile edit page
$base_dir = elgg_get_root_path();
require "{$base_dir}pages/profile/edit.php";
return true;
}
$content = elgg_view('profile/layout', array('entity' => $user));
$body = elgg_view_layout('one_column', array('content' => $content));
echo elgg_view_page($user->name, $body);
return true;
}
示例5: messageboard_page_handler
/**
* Messageboard dispatcher for flat message board.
* Profile (and eventually group) widgets handle their own.
*
* URLs take the form of
* User's messageboard: messageboard/owner/<username>
* Y's history of posts on X's board: messageboard/owner/<X>/history/<Y>
* New post: messageboard/add/<guid> (container: user or group)
* Group messageboard: messageboard/group/<guid>/all (not implemented)
*
* @param array $page Array of page elements
* @return bool
*/
function messageboard_page_handler($page)
{
$pages = dirname(__FILE__) . '/pages/messageboard';
switch ($page[0]) {
case 'owner':
//@todo if they have the widget disabled, don't allow this.
$owner_name = elgg_extract(1, $page);
$owner = get_user_by_username($owner_name);
set_input('page_owner_guid', $owner->guid);
$history = elgg_extract(2, $page);
$username = elgg_extract(3, $page);
if ($history && $username) {
set_input('history_username', $username);
}
include "{$pages}/owner.php";
break;
case 'add':
$container_guid = elgg_extract(1, $page);
set_input('container_guid', $container_guid);
include "{$pages}/add.php";
break;
case 'group':
elgg_group_gatekeeper();
$owner_guid = elgg_extract(1, $page);
set_input('page_owner_guid', $owner_guid);
include "{$pages}/owner.php";
break;
default:
return false;
}
return true;
}
示例6: au_landing_router
function au_landing_router($hook, $type, $return, $params)
{
if ($type == 'blog' && $return['segments'][0] == 'new') {
$user = get_user_by_username($return['segments'][1]);
if ($user) {
system_message(elgg_echo('changebookmark'));
forward(elgg_get_site_url() . 'blog/add/' . $user->guid);
exit;
}
// must be a group
$guid = str_replace('group:', '', $return['segments'][1]);
$group = get_entity($guid);
if (elgg_instanceof($group, 'group', '', 'ElggGroup')) {
system_message(elgg_echo('changebookmark'));
forward(elgg_get_site_url() . 'blog/add/' . $group->guid);
}
return FALSE;
}
// forward old groups urls to new group urls
if ($type == 'groups' && is_numeric($return['segments'][0])) {
$group = get_entity($return['segments'][0]);
if ($group instanceof \ElggGroup) {
system_message(elgg_echo('changebookmark'));
forward($group->getURL());
}
}
}
示例7: profile_page_handler
/**
* Profile page handler
*
* @param array $page Array of page elements, forwarded by the page handling mechanism
*/
function profile_page_handler($page)
{
if (isset($page[0])) {
$username = $page[0];
$user = get_user_by_username($username);
elgg_set_page_owner_guid($user->guid);
}
// short circuit if invalid or banned username
if (!$user || $user->isBanned() && !elgg_is_admin_logged_in()) {
register_error(elgg_echo('profile:notfound'));
forward();
}
$action = NULL;
if (isset($page[1])) {
$action = $page[1];
}
if ($action == 'edit') {
// use the core profile edit page
$base_dir = elgg_get_root_path();
require "{$base_dir}pages/profile/edit.php";
return;
}
// main profile page
$params = array('content' => elgg_view('profile/wrapper'), 'num_columns' => 3);
$content = elgg_view_layout('widgets', $params);
$body = elgg_view_layout('one_column', array('content' => $content));
echo elgg_view_page($title, $body);
}
示例8: profile_page_handler
/**
* Profile page handler
*
* @param array $page Array of URL segments passed by the page handling mechanism
* @return bool
*/
function profile_page_handler($page)
{
if (isset($page[0])) {
$username = $page[0];
$user = get_user_by_username($username);
elgg_set_page_owner_guid($user->guid);
} elseif (elgg_is_logged_in()) {
forward(elgg_get_logged_in_user_entity()->getURL());
}
// short circuit if invalid or banned username
if (!$user || $user->isBanned() && !elgg_is_admin_logged_in()) {
register_error(elgg_echo('profile:notfound'));
forward();
}
$action = NULL;
if (isset($page[1])) {
$action = $page[1];
}
if ($action == 'edit') {
// use the core profile edit page
echo elgg_view_resource('profile/edit');
return true;
}
echo elgg_view_resource('profile/view', ['username' => $page[0]]);
return true;
}
示例9: notifications_page_handler
/**
* Route page requests
*
* @param array $page Array of url parameters
* @return bool
*/
function notifications_page_handler($page)
{
gatekeeper();
$current_user = elgg_get_logged_in_user_entity();
// default to personal notifications
if (!isset($page[0])) {
$page[0] = 'personal';
}
if (!isset($page[1])) {
forward("notifications/{$page[0]}/{$current_user->username}");
}
$user = get_user_by_username($page[1]);
if ($user->guid != $current_user->guid && !$current_user->isAdmin()) {
forward();
}
$base = elgg_get_plugins_path() . 'notifications';
// note: $user passed in
switch ($page[0]) {
case 'group':
require "{$base}/groups.php";
break;
case 'personal':
require "{$base}/index.php";
break;
default:
return false;
}
return true;
}
示例10: monashees_profile_page_handler
function monashees_profile_page_handler($page)
{
if (isset($page[0])) {
$username = $page[0];
$user = get_user_by_username($username);
elgg_set_page_owner_guid($user->guid);
} elseif (elgg_is_logged_in()) {
forward(elgg_get_logged_in_user_entity()->getURL());
}
// short circuit if invalid or banned username
if (!$user || $user->isBanned() && !elgg_is_admin_logged_in()) {
register_error(elgg_echo('profile:notfound'));
forward();
}
$action = NULL;
if (isset($page[1])) {
$action = $page[1];
}
if ($action == 'edit') {
// use the core profile edit page
$base_dir = elgg_get_root_path();
require "{$base_dir}pages/profile/edit.php";
return true;
}
// main profile page
/*$params = array (
'content' => elgg_view ( 'profile/wrapper' ),
'num_columns' => 3
);*/
//$content = elgg_view_layout ( 'widgets', $params );
$body = elgg_view_layout('two_sidebar', array('content' => elgg_view('profile/wrapper') . "" . elgg_view("profile/owner_block") . "" . elgg_view("profile/homeposts"), 'username' => $username));
echo elgg_view_page($user->name, $body);
return true;
}
示例11: messageboard_page_handler
/**
* Messageboard dispatcher for flat message board.
* Profile (and eventually group) widgets handle their own.
*
* URLs take the form of
* User's messageboard: messageboard/owner/<username>
* Y's history of posts on X's board: messageboard/owner/<X>/history/<Y>
* New post: messageboard/add/<guid> (container: user or group)
* Group messageboard: messageboard/group/<guid>/all (not implemented)
*
* @param array $page Array of page elements
* @return bool
*/
function messageboard_page_handler($page)
{
switch ($page[0]) {
case 'owner':
//@todo if they have the widget disabled, don't allow this.
$owner_name = elgg_extract(1, $page);
$owner = get_user_by_username($owner_name);
set_input('page_owner_guid', $owner->guid);
$history = elgg_extract(2, $page);
$username = elgg_extract(3, $page);
if ($history && $username) {
set_input('history_username', $username);
}
echo elgg_view('resources/messageboard/owner');
break;
case 'add':
$container_guid = elgg_extract(1, $page);
set_input('container_guid', $container_guid);
echo elgg_view('resources/messageboard/add');
break;
case 'group':
elgg_group_gatekeeper();
$owner_guid = elgg_extract(1, $page);
set_input('page_owner_guid', $owner_guid);
echo elgg_view('resources/messageboard/owner');
break;
default:
return false;
}
return true;
}
示例12: thewire_tools_create_object_event_handler
/**
* This functions performs actions when a wire post is created
*
* @param string $event 'create'
* @param string $type 'object'
* @param ElggObject $object the ElggObject created
*
* @return void
*/
function thewire_tools_create_object_event_handler($event, $type, ElggObject $object)
{
if (empty($object) || !elgg_instanceof($object, "object", "thewire")) {
return;
}
//send out notification to users mentioned in a wire post
$usernames = array();
preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames);
if (empty($usernames)) {
return;
}
$usernames = array_unique($usernames[0]);
$params = array("object" => $object, "action" => "mention");
foreach ($usernames as $username) {
$username = str_ireplace("@", "", $username);
$user = get_user_by_username($username);
if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) {
continue;
}
$setting = thewire_tools_get_notification_settings($user->getGUID());
if (empty($setting)) {
continue;
}
$subject = elgg_echo("thewire_tools:notify:mention:subject");
$message = elgg_echo("thewire_tools:notify:mention:message", array($user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@" . $user->username)));
notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting);
}
}
示例13: getUserData
/**
* Return user info
*
* Returns info about the given user needs to contain
* at least these fields:
*
* name string full name of the user
* mail string email addres of the user
* grps array list of groups the user is in
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getUserData($username)
{
$user = get_user_by_username($username);
//error_log("getUserData:".$username);
if (!$user) {
return false;
}
//error_log("getUserData:".$username);
$page_owner = elgg_get_page_owner_entity();
$grps = array();
if ($page_owner instanceof ElggGroup) {
if ($page_owner->canEdit($user->getGUID())) {
$grps[] = "admin";
$grps[] = "root";
//error_log('operator');
} elseif ($page_owner->isMember($user)) {
$grps[] = "member";
}
} elseif ($page_owner instanceof ElggUser) {
if ($page_owner == $user) {
$grps[] = "admin";
} elseif ($page_owner->isFriendsWith($user->getGUID())) {
$grps[] = "member";
}
}
if ($user->isAdmin()) {
$grps[] = "root";
$grps[] = "admin";
}
$groups = elgg_get_entities_from_relationship(array('relationship' => 'member', 'relationship_guid' => $user->getGUID(), 'inverse_relationship' => FALSE, 'limit' => 0));
foreach ($groups as $group) {
$grps[] = $this->cleanUser($group->name);
}
return array('name' => $user->name, 'mail' => $user->email, 'grps' => $grps);
}
示例14: stripe_page_handler
/**
* Stripe related pages
*
* @param array $page
* @param string $handler
* @return boolean
*/
function stripe_page_handler($page, $handler)
{
gatekeeper();
$username = elgg_extract(0, $page, false);
if ($username) {
$user = get_user_by_username($username);
}
if (!elgg_instanceof($user) || !$user->canEdit()) {
$user = elgg_get_logged_in_user_entity();
forward("{$handler}/{$user->username}");
}
elgg_set_context('settings');
elgg_set_page_owner_guid($user->guid);
elgg_push_breadcrumb(elgg_echo('stripe:billing'), 'billing');
$context = elgg_extract(1, $page, 'cards');
$action = elgg_extract(2, $page, 'all');
$view = "stripe/pages/{$context}/{$action}";
if (elgg_view_exists($view)) {
$params = array('entity' => $user, 'id' => elgg_extract(3, $page, false), 'context' => $page);
$title = elgg_echo("stripe:{$context}:{$action}");
$content = elgg_view($view, $params);
$sidebar = elgg_view('stripe/sidebar', $params);
$filter = elgg_view("stripe/filters/{$context}/{$action}", $params);
}
if ($content) {
if (elgg_is_xhr()) {
echo $content;
} else {
$layout = elgg_view_layout('content', array('title' => $title, 'content' => $content, 'sidebar' => $sidebar, 'filter' => $filter));
echo elgg_view_page($title, $layout);
}
return true;
}
return false;
}
示例15: show_members_json
function show_members_json($context, $limit = 30, $offset = 0, $username)
{
if (!$username) {
$user = elgg_get_logged_in_user_entity();
} else {
$user = get_user_by_username($username);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
}
if ($context == "newest") {
$params = array('types' => 'user', 'limit' => $limit, 'full_view' => FALSE);
$latest_member = elgg_get_entities($params);
//return $return;
}
if ($context == "online") {
$latest_member = get_online_users();
}
if ($context == "popular") {
$params = array('types' => 'user', 'relationship' => 'friend', 'inverse_relationship' => false);
$latest_member = elgg_list_entities_from_relationship_count($params);
}
if ($latest_member) {
foreach ($latest_member as $single) {
$member['guid'] = $single->guid;
$member['name'] = $single->name;
//$member['avatar_url'] = get_entity_icon_url($single,'small');
$return[] = $member;
}
}
//return $return;
return json_encode($return, true);
}