本文整理汇总了PHP中user_access函数的典型用法代码示例。如果您正苦于以下问题:PHP user_access函数的具体用法?PHP user_access怎么用?PHP user_access使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_access函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createUser
/**
* Function to create a user in Drupal.
*
* @param array $params associated array
* @param string $mail email id for cms user
*
* @return uid if user exists, false otherwise
*
* @access public
*
*/
function createUser(&$params, $mail)
{
$form_state = array();
$form_state['input'] = array('name' => $params['cms_name'], 'mail' => $params[$mail], 'op' => 'Create new account');
$admin = user_access('administer users');
if (!variable_get('user_email_verification', TRUE) || $admin) {
$form_state['input']['pass'] = array('pass1' => $params['cms_pass'], 'pass2' => $params['cms_pass']);
}
$form_state['rebuild'] = FALSE;
$form_state['programmed'] = TRUE;
$form_state['method'] = 'post';
$form_state['build_info']['args'] = array();
$config = CRM_Core_Config::singleton();
// we also need to redirect b
$config->inCiviCRM = TRUE;
$form = drupal_retrieve_form('user_register_form', $form_state);
$form_state['process_input'] = 1;
$form_state['submitted'] = 1;
drupal_process_form('user_register_form', $form, $form_state);
$config->inCiviCRM = FALSE;
if (form_get_errors()) {
return FALSE;
} else {
return $form_state['user']->uid;
}
}
示例2: hook_twitter_accounts
/**
* Retrieves what Twitter accounts the given user can post to.
*/
function hook_twitter_accounts($drupal_user, $full_access = FALSE) {
$accounts = array();
if (user_access('use global twitter account') &&
($name = variable_get('twitter_global_name', NULL)) &&
($pass = variable_get('twitter_global_password', NULL))) {
$accounts[$name] = array(
'screen_name' => $name,
'password' => $pass,
);
}
$sql = " SELECT ta.*, tu.uid, tu.password, tu.import FROM {twitter_user} tu ";
$sql .= "LEFT JOIN {twitter_account} ta ON (tu.screen_name = ta.screen_name) ";
$sql .= "WHERE tu.uid = %d";
if ($full_access) {
$sql .= " AND tu.password IS NOT NULL";
}
$args = array($drupal_user->uid);
$results = db_query($sql, $args);
while ($account = db_fetch_array($results)) {
$accounts[$account['screen_name']] = $account;
}
return $accounts;
}
示例3: hook_admin_menu_output_alter
/**
* Alter content in Administration menu bar before it is rendered.
*
* @param $content
* A structured array suitable for drupal_render(), at the very least
* containing the keys 'menu' and 'links'. Most implementations likely want
* to alter or add to 'links'.
*
* $content['menu'] contains the HTML representation of the 'admin_menu' menu
* tree.
* @see admin_menu_menu_alter()
*
* $content['links'] contains additional top-level links in the Administration
* menu, such as the icon menu or the logout link. You can add more items here
* or play with the #weight attribute to customize them.
* @see theme_admin_menu_links()
* @see admin_menu_links_icon()
* @see admin_menu_links_user()
*/
function hook_admin_menu_output_alter(&$content)
{
// Add new top-level item.
$content['menu']['myitem'] = array('#title' => t('My item'), '#attributes' => array('class' => array('mymodule-myitem')), '#href' => 'mymodule/path', '#options' => array('query' => drupal_get_destination()), '#weight' => 50);
// Add link to manually run cron.
$content['menu']['myitem']['cron'] = array('#title' => t('Run cron'), '#access' => user_access('administer site configuration'), '#href' => 'admin/reports/status/run-cron');
}
示例4: quickdrupal_username
/**
* Override theme_username() function.
* Removes the text '(not verified)' for anonymous users.
*/
function quickdrupal_username($object)
{
if ($object->uid && $object->name) {
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) . '...';
} else {
$name = $object->name;
}
if (user_access('access user profiles')) {
$output = l($name, 'user/' . $object->uid, array('attributes' => array('title' => t('View user profile.'))));
} else {
$output = check_plain($name);
}
} else {
if ($object->name) {
if (!empty($object->homepage)) {
$output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
} else {
$output = check_plain($object->name);
}
} else {
$output = check_plain(variable_get('anonymous', t('Anonymous')));
}
}
return $output;
}
示例5: gavias_laikafood_preprocess_html
/**
* Override or insert variables into the html template.
* @param $vars
* An array of variables to pass to the theme template.
*/
function gavias_laikafood_preprocess_html(&$vars)
{
global $theme, $base_url;
global $parent_root;
$skin = theme_get_setting('theme_skin');
drupal_add_css(drupal_get_path('theme', 'gavias_laikafood') . '/css/' . ($skin ? 'skins/' . $skin . '/' : '') . 'template.css', array('group' => CSS_DEFAULT, 'type' => 'file'));
drupal_add_css(drupal_get_path('theme', 'gavias_laikafood') . '/css/' . ($skin ? 'skins/' . $skin . '/' : '') . 'bootstrap.css', array('group' => CSS_DEFAULT, 'type' => 'file'));
if (module_exists('gavias_themer') && theme_get_setting('frontend_panel') == '1' && user_access('gavias_customize_preview')) {
gavias_load_fontend();
}
if (theme_get_setting('enable_custom_style') == 1 && trim(variable_get('gavias_profile'))) {
drupal_add_css(drupal_get_path('theme', 'gavias_laikafood') . '/customize/save/' . variable_get('gavias_profile') . '.css', array('group' => CSS_DEFAULT, 'type' => 'file'));
}
$viewport = array('#type' => 'html_tag', '#tag' => 'meta', '#attributes' => array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1, maximum-scale=1'), '#weight' => 1);
drupal_add_html_head($viewport, 'viewport');
// Add boxed class if layout is set that way.
if (theme_get_setting('site_layout') == 'boxed') {
$vars['classes_array'][] = 'boxed';
}
if (theme_get_setting('preloader') == '1') {
$vars['classes_array'][] = 'js-preloader';
} else {
$vars['classes_array'][] = 'not-preloader';
}
}
示例6: phptemplate_username
function phptemplate_username($object)
{
if ($object->uid && $object->name) {
// Shorten the name when it is too long or it will break many tables.
if (arg(0) == 'user' or 'groups') {
$name = $object->name;
} else {
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) . '...';
} else {
$name = $object->name;
}
}
if (user_access('access user profiles')) {
$output = l($name, 'user/' . $object->uid, array('title' => t('View user profile.')));
} else {
$output = check_plain($name);
}
} else {
if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if ($object->homepage) {
$output = l($object->name, $object->homepage, array('class' => 'anonymous', 'title' => t('not verified')));
} else {
$output = '<span class="anonymous" title="' . t('not verified') . '">' . check_plain($object->name) . '</span>';
}
} else {
$output = variable_get('anonymous', t('Anonymous'));
}
}
return $output;
}
示例7: getList
/**
* Overrides \RestfulEntityBase::getList().
*
* Make sure only privileged users may see a list of users.
*/
public function getList() {
$account = $this->getAccount();
if (!user_access('administer users', $account) && !user_access('access user profiles', $account)) {
throw new \RestfulForbiddenException('You do not have access to listing of users.');
}
return parent::getList();
}
示例8: __construct
/**
* Default constructor.
*
* @param null|int $id
* Comment id if a comment edit form is to be loaded and null if comment
* add form is to be loaded.
*/
public function __construct($id)
{
if (!user_access('post comments')) {
$this->setErrors("User is not allowed to post comments.");
$this->setInitialized(FALSE);
return;
}
$args = func_get_args();
array_shift($args);
$nid = array_shift($args);
$pid = array_shift($args);
$classname = get_called_class();
$class = new \ReflectionClass($classname);
$class_shortname = $class->getShortName();
$class_fullname = "RedTest\\entities\\Comment\\" . substr($class_shortname, 0, -4);
$commentObject = new $class_fullname($id, $nid, $pid);
if (!$commentObject->getInitialized()) {
$this->setErrors($commentObject->getErrors());
$this->setInitialized(FALSE);
return;
}
$this->setEntityObject($commentObject);
$nid = $commentObject->getNidValues();
$node = node_load($nid);
if ($node->comment != COMMENT_NODE_OPEN && is_null($id)) {
$this->setErrors("Node {$nid} does not allow posting of comments.");
$this->setInitialized(FALSE);
return;
}
$type = Utils::makeSnakeCase(substr($class_shortname, 0, -11));
parent::__construct('comment_node_' . $type . '_form', (object) array('nid' => $nid, 'pid' => $pid));
}
示例9: cubert_preprocess_views_view_table
function cubert_preprocess_views_view_table(&$vars)
{
// Table headers are collapsible by default - override that for specific views here.
$no_collapse = array('tickets_feature_requests', 'tickets_bug_reports');
if (!in_array($vars['view']->name, $no_collapse)) {
$vars['collapsible_title'] = TRUE;
}
$extra_classes = '';
// Add "Completed" value for milestones
if ($vars['view']->name == 'milestones') {
$can_edit = user_access('administer milestones');
$vars['can_edit'] = $can_edit;
$key = key($vars['result']);
$nid = !empty($vars['result'][$key]->nid) ? $vars['result'][$key]->nid : '';
if (!empty($nid)) {
$node = node_load($nid);
$completed = !empty($node->field_milestone_completed[LANGUAGE_NONE][0]['value']) ? $node->field_milestone_completed[LANGUAGE_NONE][0]['value'] : FALSE;
$vars['milestone_completed'] = $completed;
if ($completed) {
$vars['completed_class'] = 'completed';
} else {
$vars['completed_class'] = 'uncompleted';
}
$vars['nid'] = $nid;
$extra_classes = ' collapse';
}
}
$vars['extra_classes'] = $extra_classes;
}
示例10: thearchivetheme_process_page
function thearchivetheme_process_page(&$vars)
{
$usernav = '';
if (user_is_logged_in()) {
global $user;
$node = menu_get_object();
$ar = array();
if ($node) {
$nid = $node->nid;
if (user_access('update collection')) {
$ar[] = '<a href="collection/edit/' . $nid . '">編輯</a>';
}
if (user_access('update collection')) {
$ar[] = '<a href="collection/update/file/' . $nid . '">更新數位檔</a>';
}
if (user_access('update collection') && editcol_is_video_collection($nid)) {
$ar[] = '<a href="collection/upload/video_icons/' . $nid . '">自定影片圖示</a>';
}
if (user_access('delete collection')) {
$ar[] = '<a href="collection/delete/' . $nid . '">刪除</a>';
}
}
if (user_access('control panel')) {
$ar[] = '<a href="/control_panel/1">Control Panel</a>';
}
$ar[] = 'Login as ' . $user->name;
$ar[] = '<a href="/user/logout">Log out</a>';
$usernav = '<div class="row">' . implode(' | ', $ar) . '</div>';
}
$vars['usernav'] = $usernav;
}
示例11: _maximenu_menu_options
/**
* Loads options to Maximenu admin
*
*/
function _maximenu_menu_options($menu_content = array(), $settings = array())
{
$form_new = array();
// Skin
$output_options = isset($settings['outputs']) ? $settings['outputs'] : '';
if (!empty($output_options)) {
$form_new['stacking'] = array('#type' => 'select', '#title' => t('Stacking'), '#options' => array('row' => 'Row', 'column' => 'Column'), '#default_value' => isset($menu_content['stacking']) ? $menu_content['stacking'] : 'row', '#description' => t('
<ul>
<li><strong>Row</strong> - all links in 1 row</li>
<li><strong>Column</strong> -all links in 1 column</li>
</ul>
'));
$form_new['direction'] = array('#type' => 'select', '#title' => t('Block Menu Direction'), '#options' => array('block-down' => 'Dropdown', 'block-up' => 'Dropup', 'block-right' => 'Right', 'block-left' => 'Left'), '#default_value' => isset($menu_content['direction']) ? $menu_content['direction'] : 'block-down', '#description' => t('OM Maximenu will popup on this direction. Applicable only with dropdown style.'));
$access = user_access('use PHP for settings');
if (isset($menu_content['visibility']) && $menu_content['visibility'] == 2 && !$access) {
$form_new['visibility'] = array('#type' => 'value', '#value' => 2);
$form_new['pages'] = array('#type' => 'value', '#value' => $menu_content['pages']);
} else {
$options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'));
$description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcardfor every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
if (module_exists('php') && $access) {
$options[] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
$description .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code canbreak your Drupal site.', array('%php' => '<?php ?>'));
}
$form_new['visibility'] = array('#type' => 'radios', '#title' => t('Show menu on specific pages'), '#options' => $options, '#default_value' => isset($menu_content['visibility']) ? $menu_content['visibility'] : 0);
$form_new['pages'] = array('#type' => 'textarea', '#title' => t('Pages'), '#default_value' => isset($menu_content['pages']) ? $menu_content['pages'] : '', '#description' => $description);
}
}
return $form_new;
}
示例12: mooc_foundation_access_preprocess_page
/**
* Implements template_preprocess_page.
*/
function mooc_foundation_access_preprocess_page(&$variables)
{
// speedreader is enabled
if (module_exists('speedreader')) {
$variables['speedreader'] = TRUE;
}
// mespeak is enabled
if (module_exists('mespeak')) {
$variables['mespeak'] = TRUE;
}
// support for add child page shortcut
$node = menu_get_object();
if ($node && user_access('access printer-friendly version')) {
$variables['tabs_extras'][200][] = '<hr>';
$variables['tabs_extras'][200][] = l(t('Print'), 'book/export/html/' . arg(1));
}
$child_type = variable_get('book_child_type', 'book');
if ($node && !empty($node->book) && (user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && isset($node->book['depth']) && $node->book['depth'] < MENU_MAX_DEPTH) {
$variables['tabs_extras'][200][] = '<hr>';
$variables['tabs_extras'][200][] = l(t('Add child page'), 'node/add/' . str_replace('_', '-', $child_type), array('query' => array('parent' => $node->book['mlid'])));
}
if (user_access('access contextual links')) {
$variables['tabs_extras'][0][] = '<li class="cis_accessibility_check"></li>';
}
// remove the prefix that provides a link to the home page
// as MOOC is the thing that currently provides support directly for this
// and slightly overrides the behavior
$keys = array_keys($variables['page']['header']);
$keyname = array_shift($keys);
unset($variables['page']['header'][$keyname]['#prefix']);
}
示例13: borg_preprocess_page
/**
* Prepares variables for page.tpl.php
*/
function borg_preprocess_page(&$variables)
{
// Add the Source Sans Pro font.
backdrop_add_css('https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700', array('type' => 'external'));
// Add FontAwesome.
backdrop_add_js('https://use.fontawesome.com/baf3c35582.js', array('type' => 'external'));
// Add Flexslider to the front page only.
if (backdrop_is_front_page()) {
$path = backdrop_get_path('theme', 'borg');
backdrop_add_css($path . '/css/flexslider.css');
backdrop_add_js($path . '/js/jquery.flexslider.js');
$script = "\n\$(window).load(function() {\n \$('.flexslider').flexslider();\n});";
backdrop_add_js($script, array('type' => 'inline'));
}
$node = menu_get_object();
if (isset($node) && isset($node->type) && $node->type === 'book') {
$variables['classes'][] = 'drawer-open';
$variables['classes'][] = 'layout-both-sidebars';
} else {
$variables['classes'][] = 'drawer-closed';
$array_key = array_search('layout-both-sidebars', $variables['classes']);
if ($array_key !== FALSE) {
$variables['classes'][$array_key] = 'layout-one-sidebar';
}
}
if (module_exists('admin_bar') && user_access('admin_bar')) {
$variables['classes'][] = 'admin-bar';
}
}
示例14: createOrUpdateWorkSession
/**
* Create a new session or update an open session.
*/
public function createOrUpdateWorkSession()
{
$request = $this->getRequest();
$account = $this->getAccount();
if (!user_access('timewatch punch')) {
throw new RestfulForbiddenException('No punch access.');
}
if (empty($request['pincode'])) {
throw new \RestfulBadRequestException('Pincode is required');
}
$uid = timewatch_session_get_uid_by_pincode($request['pincode']);
if (!$uid) {
throw new \RestfulBadRequestException('Wrong pincode');
}
$employee_account = user_load($uid);
// Find an existing session with no end date.
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'work_session')->propertyCondition('status', NODE_PUBLISHED)->fieldCondition('field_employee', 'target_id', $uid)->fieldCondition('field_session_date', 'value2', NULL)->range(0, 1)->execute();
if (empty($result['node'])) {
// When there's no open session, create a new one.
$values = array('type' => 'work_session', 'uid' => $account->uid, 'status' => NODE_PUBLISHED, 'title' => format_string('@date - @user', array('@date' => date('d/m/y'), '@user' => $employee_account->name)));
$node = entity_create('node', $values);
$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->field_employee->set($uid);
$wrapper->field_session_date->value->set(REQUEST_TIME);
} else {
// Otherwise set the end date of the open session.
$wrapper = entity_metadata_wrapper('node', key($result['node']));
$wrapper->field_session_date->value2->set(REQUEST_TIME);
}
$wrapper->save();
return $this->viewEntity($wrapper->getIdentifier());
}
示例15: _contact_personal_tab_access
/**
* Menu access callback for a user's personal contact form.
*
* @param $account
* The user object of the user whose contact form is being requested.
*/
function _contact_personal_tab_access($account)
{
global $user;
// Anonymous users cannot have contact forms.
if (!$account->uid) {
return FALSE;
}
// User administrators should always have access to personal contact forms.
if (user_access('administer users')) {
return TRUE;
}
// Users may not contact themselves.
if ($user->uid == $account->uid) {
return FALSE;
}
// If the requested user has disabled their contact form, or this preference
// has not yet been saved, do not allow users to contact them.
if (empty($account->data['contact'])) {
return FALSE;
}
// If requested user has been blocked, do not allow users to contact them.
if (empty($account->status)) {
return FALSE;
}
return user_access('access user contact forms');
}