本文整理汇总了PHP中drupal_anonymous_user函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_anonymous_user函数的具体用法?PHP drupal_anonymous_user怎么用?PHP drupal_anonymous_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_anonymous_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serveCachedPage
public function serveCachedPage()
{
$cache_enabled = $this->getCacheMode();
// If there is no session cookie and cache is enabled (or forced), try
// to serve a cached page.
if (!isset($_COOKIE[session_name()]) && $cache_enabled) {
global $user;
// Make sure there is a user object because its timestamp will be
// checked, hook_boot might check for anonymous user etc.
$user = drupal_anonymous_user();
// Get the page from the cache.
$cache = drupal_page_get_cache();
// If there is a cached page, display it.
if (is_object($cache)) {
header('X-Drupal-Cache: HIT');
// Restore the metadata cached with the page.
$_GET['q'] = $cache->data['path'];
drupal_set_title($cache->data['title'], PASS_THROUGH);
date_default_timezone_set(drupal_get_user_timezone());
// If the skipping of the bootstrap hooks is not enforced, call
// hook_boot.
if (variable_get('page_cache_invoke_hooks', TRUE)) {
bootstrap_invoke_all('boot');
}
drupal_serve_page_from_cache($cache);
// If the skipping of the bootstrap hooks is not enforced, call
// hook_exit.
if (variable_get('page_cache_invoke_hooks', TRUE)) {
bootstrap_invoke_all('exit');
}
// We are done.
exit;
} else {
header('X-Drupal-Cache: MISS');
}
}
}
示例2: blockForm
/**
* {@inheritdoc}
*/
public function blockForm($form, &$form_state)
{
$form['list_size'] = array('#type' => 'textfield', '#title' => t('Number of users to display in the list'), '#default_value' => $this->configuration['list_size'], '#size' => '3', '#maxlength' => '4');
$form['include_anon'] = array('#type' => 'checkbox', '#title' => t('Include %anonymous', array('%anonymous' => user_format_name(drupal_anonymous_user()))), '#default_value' => $this->configuration['include_anon']);
$form['show_form'] = array('#type' => 'checkbox', '#title' => t('Allow entering any user name'), '#default_value' => $this->configuration['show_form']);
return $form;
}
示例3: alterItems
public function alterItems(array &$items)
{
// Prevent session information from being saved while indexing.
drupal_save_session(FALSE);
// Force the current user to anonymous to prevent access bypass in search
// indexes.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
$entity_type = $this->index->getEntityType();
$entity_handler = panelizer_entity_plugin_get_handler($entity_type);
foreach ($items as &$item) {
$entity_id = entity_id($entity_type, $item);
$item->search_api_panelizer_content = NULL;
$item->search_api_panelizer_title = NULL;
try {
if ($render_info = $entity_handler->render_entity($item, 'page_manager')) {
$item->search_api_panelizer_content = $render_info['content'];
$item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL;
}
} catch (Exception $e) {
watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id));
}
}
// Restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);
}
示例4: logout
/**
* {@inheritdoc}
* @see user_logout()
*/
public function logout(Request $request, Response $response, TokenInterface $token)
{
$user = $token->getUser();
if (is_a($user, 'Bangpound\\Bundle\\DrupalBundle\\Security\\User\\User')) {
/** @var \Bangpound\Bundle\DrupalBundle\Security\User\User $user */
$user = $token->getUser()->getDrupalUser();
watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
module_invoke_all('user_logout', $user);
$GLOBALS['user'] = drupal_anonymous_user();
}
}
示例5: createUser
/**
* Helper function that creates a user object with the given role.
*/
protected function createUser($role)
{
$edit = array();
$edit['name'] = $this->randomName();
$edit['mail'] = $edit['name'] . '@example.com';
// @todo role ids are completely broken, if modules are enable in the wrong
// order.
$edit['roles'] = array($role->rid => $role->name);
$edit['pass'] = user_password();
$edit['status'] = 1;
$user = user_save(drupal_anonymous_user(), $edit);
$user->pass_raw = $edit['pass'];
return $user;
}
示例6: __construct
/**
* Constructor for RateLimitManager.
*
* @param ResourceInterface $resource
* Resource being checked.
* @param array $plugin_options
* Array of options keyed by plugin id.
* @param object $account
* The identified user account for the request.
* @param RateLimitPluginManager $manager
* The plugin manager.
*/
public function __construct(ResourceInterface $resource, array $plugin_options, $account = NULL, RateLimitPluginManager $manager = NULL)
{
$this->resource = $resource;
$account = $account ? $account : $resource->getAccount();
$this->account = $account ? $account : drupal_anonymous_user();
$manager = $manager ?: RateLimitPluginManager::create();
$options = array();
foreach ($plugin_options as $plugin_id => $rate_options) {
// Set the instance id to articles::request and specify the plugin id.
$instance_id = $resource->getResourceName() . PluginBase::DERIVATIVE_SEPARATOR . $plugin_id;
$options[$instance_id] = array('id' => $plugin_id, 'resource' => $resource);
$options[$instance_id] += $rate_options;
}
$this->plugins = new RateLimitPluginCollection($manager, $options);
}
示例7: access
/**
* {@inheritdoc}
*
* If "File entity" module exists, determine access by its provided
* permissions otherwise, check if variable is set to allow anonymous users to
* upload. Defaults to authenticated user.
*/
public function access()
{
// The getAccount method may return an UnauthorizedException when an
// authenticated user cannot be found. Since this is called from the access
// callback, not from the page callback we need to catch the exception.
try {
$account = $this->getAccount();
} catch (UnauthorizedException $e) {
// If a user is not found then load the anonymous user to check
// permissions.
$account = drupal_anonymous_user();
}
if (module_exists('file_entity')) {
return user_access('bypass file access', $account) || user_access('create files', $account);
}
return (variable_get('restful_file_upload_allow_anonymous_user', FALSE) || $account->uid) && parent::access();
}
示例8: alterItems
public function alterItems(array &$items)
{
// Prevent session information from being saved while indexing.
drupal_save_session(FALSE);
// Force the current user to anonymous to prevent access bypass in search
// indexes.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
$entity_type = $this->index->getEntityType();
$entity_handler = panelizer_entity_plugin_get_handler($entity_type);
foreach ($items as &$item) {
$entity_id = entity_id($entity_type, $item);
$item->search_api_panelizer_content = NULL;
$item->search_api_panelizer_title = NULL;
// If Search API specifies a language to view the item in, force the
// global language_content to be Search API item language. Fieldable
// panel panes will render in the correct language.
if (isset($item->search_api_language)) {
global $language_content;
$original_language_content = $language_content;
$languages = language_list();
if (isset($languages[$item->search_api_language])) {
$language_content = $languages[$item->search_api_language];
} else {
$language_content = language_default();
}
}
try {
if ($render_info = $entity_handler->render_entity($item, 'page_manager')) {
$item->search_api_panelizer_content = $render_info['content'];
$item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL;
}
} catch (Exception $e) {
watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id));
}
// Restore the language_content global if it was overridden.
if (isset($original_language_content)) {
$language_content = $original_language_content;
}
}
// Restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);
}
示例9: testAuthorize
/**
* Tests authorization.
*/
public function testAuthorize()
{
// Create a user with limited permissions. We can't use
// $this->drupalCreateUser here because we need to to set a specific user
// name.
$edit = array('name' => 'Poor user', 'mail' => 'poor@example.com', 'pass' => user_password(), 'status' => 1);
$account = user_save(drupal_anonymous_user(), $edit);
// // Adding a mapping to the user_name will invoke authorization.
$this->addMappings('comment', array(5 => array('source' => 'mail', 'target' => 'user_mail')));
$url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_comment_processor') . '/tests/test.csv';
$nid = $this->createFeedNode('comment', $url, 'Comment test');
$this->assertText('Failed importing 1 comment');
$this->assertText('User ' . $account->name . ' is not permitted to post comments.');
$this->assertEqual(0, db_query("SELECT COUNT(*) FROM {comment}")->fetchField());
user_role_change_permissions(2, array('post comments' => TRUE));
$this->drupalPost("node/{$nid}/import", array(), 'Import');
$this->assertText('Created 1 comment.');
$this->assertEqual(1, db_query("SELECT COUNT(*) FROM {comment}")->fetchField());
$comment = comment_load(1);
$this->assertEqual(0, $comment->status);
}
示例10: read
public function read($sessionId)
{
global $user;
if (!isset($_COOKIE[$this->sessionName])) {
$user = drupal_anonymous_user();
return '';
}
$cid = $this->getCid($sessionId);
if ($cached = $this->cacheBackend->get($cid)) {
$data = $cached->data;
if ($data && $data->uid > 0) {
$this->uid = $data->uid;
$serializedData = $data->session;
} else {
$serializedData = '';
}
$this->sessionDataSetHash($sessionId, $serializedData);
return $serializedData;
} else {
return NULL;
}
}
示例11: getAccount
/**
* Get the user account for the request.
*
* @param array $request
* The request.
* @param string $method
* The HTTP method.
* @param boolean $cache
* Boolean indicating if the resolved user should be cached for next calls.
*
* @throws RestfulUnauthorizedException
* @return \stdClass
* The user object.
*/
public function getAccount(array $request = array(), $method = \RestfulInterface::GET, $cache = TRUE) {
global $user;
// Return the previously resolved user, if any.
if (!empty($this->account)) {
return $this->account;
}
// Resolve the user based on the providers in the manager.
$account = NULL;
foreach ($this as $provider) {
if ($provider->applies($request, $method) && $account = $provider->authenticate($request, $method)) {
// The account has been loaded, we can stop looking.
break;
}
}
if (!$account) {
if ($this->count() && !$this->getIsOptional()) {
// Allow caching pages for anonymous users.
drupal_page_is_cacheable(variable_get('restful_page_cache', FALSE));
// User didn't authenticate against any provider, so we throw an error.
throw new \RestfulUnauthorizedException('Bad credentials');
}
// If the account could not be authenticated default to the global user.
// Most of the cases the cookie provider will do this for us.
$account = drupal_anonymous_user();
if (empty($request['__application']['rest_call'])) {
// If we are using the API from within Drupal and we have not tried to
// authenticate using the 'cookie' provider, then we expect to be logged
// in using the cookie authentication as a last resort.
$account = $user->uid ? user_load($user->uid) : $account;
}
}
if ($cache) {
$this->setAccount($account);
}
// Disable page caching for security reasons so that an authenticated user
// response never gets into the page cache for anonymous users.
// This is necessary because the page cache system only looks at session
// cookies, but not at HTTP Basic Auth headers.
drupal_page_is_cacheable(!$account->uid && variable_get('restful_page_cache', FALSE));
// Record the access time of this request.
$this->setAccessTime($account);
return $account;
}
示例12: isPubliclyVisible
/**
* @deprecated Use the entity_is_public module instead.
*/
public static function isPubliclyVisible($entity_type, $entity, array $options = array())
{
$options += array('needs alias' => FALSE);
$uri = entity_uri($entity_type, $entity);
if (empty($uri['path'])) {
return FALSE;
} elseif ($options['needs alias'] && !drupal_lookup_path('alias', $uri['path'], NULL)) {
return FALSE;
} elseif (module_exists('rabbit_hole') && rabbit_hole_get_action($entity_type, $entity) !== RABBIT_HOLE_DISPLAY_CONTENT) {
return FALSE;
} else {
return entity_access('view', $entity_type, $entity, drupal_anonymous_user());
}
}
示例13: drupalCreateUserWithRoles
/**
* Create a user with a particular role.
*
* @param array|string $role_names
* String role or array of role names to assign to user. Note that the user
* always has the default permissions derived from the "authenticated users"
* role.
* @param string $password
* Preferred password to set for the user.
* @param array $edit_overrides
* Values for user or user profile fields to override.
*
* @return object|bool
* A fully loaded user object with pass_raw property, or FALSE if account
* creation fails.
*/
protected function drupalCreateUserWithRoles($role_names = [], $password = NULL, $edit_overrides = [])
{
// Create a user assigned to that role.
$edit = [];
$edit['mail'] = Random::email();
$edit['name'] = $edit['mail'];
$edit['pass'] = is_null($password) ? user_password() : $password;
$edit['status'] = 1;
$edit['roles'] = [];
if (!empty($role_names)) {
$role_names = is_array($role_names) ? $role_names : [$role_names];
foreach ($role_names as $rolename) {
$role = user_role_load_by_name($rolename);
$edit['roles'][$role->rid] = $role->name;
}
}
// Merge fields with provided $edit_overrides.
$edit_overrides = array_merge($edit, $edit_overrides);
// Build an empty user object, including all default fields.
$account = drupal_anonymous_user();
$account->roles = array_merge($account->roles, $edit_overrides['roles']);
foreach (field_info_instances('user', 'user') as $field_name => $info) {
if (!isset($account->{$field_name})) {
$account->{$field_name} = [];
}
}
$account = user_save($account, $edit_overrides);
if (empty($account->uid)) {
return FALSE;
}
$account->pass_raw = $edit_overrides['pass'];
$this->assertTrue(!empty($account->uid), t('User created with name %name (%uid) and pass %pass and roles %roles', ['%roles' => implode(', ', $role_names), '%name' => $edit['name'], '%uid' => $account->uid, '%pass' => $edit['pass']]), t('User login'));
return $account;
}
示例14: __construct
/**
* Constructor for RestfulRateLimitManager.
*
* @param string $resource
* Resource name being checked.
* @param array $plugin
* The plugin info array for the rate limit.
* @param \stdClass $account
* The identified user account for the request.
*/
public function __construct($resource, array $plugin, $account = NULL) {
parent::__construct($plugin);
$this->resource = $resource;
$this->setPluginInfo($plugin);
$this->account = $account ? $account : drupal_anonymous_user();
}
示例15: tzbase_include_proto_classes
<?php
global $user;
tzbase_include_proto_classes();
$account = user_load(array('name' => 'Johan Heander'));
if ($account) {
TZIntellitimeBot::destroy_session_data($account->intellitime_session_data);
user_save($account, array('intellitime_session_data' => NULL));
}
// Login and logout to refresh cookie
$form_state = array('values' => array('name' => 'Johan Heander', 'pass' => '0733623516', 'op' => t('Log in')));
drupal_execute('user_login', $form_state);
// Destroy the current session:
session_destroy();
// Only variables can be passed by reference workaround.
$null = NULL;
user_module_invoke('logout', $null, $user);
// Load the anonymous user
$user = drupal_anonymous_user();
tzintellitime_sync_synchronize_users();
TZIntellitimeBot::destroy_session_data($account->intellitime_session_data);