uppdated modules
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file query_string.inc
|
||||
* Context plugin that can extract arbitrary values from the query string.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $plugin array which will be used by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t('Query string value'),
|
||||
'description' => t('A context that extracts a value from the query string.'),
|
||||
'context' => 'ctools_context_query_string_create_query_string',
|
||||
'context name' => 'query_string',
|
||||
'keyword' => 'query_string',
|
||||
'edit form' => 'ctools_context_query_string_settings_form',
|
||||
'convert list' => array(
|
||||
'raw' => t('Raw string'),
|
||||
'html_safe' => t('HTML-safe string'),
|
||||
),
|
||||
'convert' => 'ctools_context_query_string_convert',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a context from manual configuration.
|
||||
*/
|
||||
function ctools_context_query_string_create_query_string($empty, $data = NULL, $conf = FALSE) {
|
||||
$context = new ctools_context('query_string');
|
||||
$context->plugin = 'query_string';
|
||||
|
||||
if ($empty) {
|
||||
return $context;
|
||||
}
|
||||
|
||||
if ($conf) {
|
||||
if (!empty($_GET[$data['key']])) {
|
||||
$context->data = $_GET[$data['key']];
|
||||
}
|
||||
else {
|
||||
$context->data = $data['fallback_value'];
|
||||
}
|
||||
}
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; settings for the context.
|
||||
*/
|
||||
function ctools_context_query_string_settings_form($form, &$form_state) {
|
||||
$form['key'] = array(
|
||||
'#title' => t('Query string key'),
|
||||
'#description' => t('Enter the key of the value that must be returned from the query string.'),
|
||||
'#type' => 'textfield',
|
||||
'#required' => TRUE
|
||||
);
|
||||
if (isset($form_state['conf']['key'])) {
|
||||
$form['key']['#default_value'] = $form_state['conf']['key'];
|
||||
}
|
||||
$form['fallback_value'] = array(
|
||||
'#title' => t('Fallback value'),
|
||||
'#description' => t('Enter a value that must be returned if the above specified key does not exist in the query string.'),
|
||||
'#type' => 'textfield',
|
||||
);
|
||||
if (!empty($form_state['conf']['fallback_value'])) {
|
||||
$form['fallback_value']['#default_value'] = $form_state['conf']['fallback_value'];
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler; settings form for the context.
|
||||
*/
|
||||
function ctools_context_query_string_settings_form_submit($form, &$form_state) {
|
||||
$form_state['conf']['key'] = $form_state['values']['key'];
|
||||
$form_state['conf']['fallback_value'] = $form_state['values']['fallback_value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a context into a string.
|
||||
*/
|
||||
function ctools_context_query_string_convert($context, $type) {
|
||||
switch ($type) {
|
||||
case 'raw':
|
||||
return $context->data;
|
||||
case 'html_safe':
|
||||
return check_plain($context->data);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,9 @@ function ctools_context_create_user($empty, $data = NULL, $conf = FALSE) {
|
||||
if ($data['type'] == 'current') {
|
||||
global $user;
|
||||
$data = user_load($user->uid);
|
||||
$data->logged_in_user = TRUE;
|
||||
if (user_is_logged_in()) {
|
||||
$data->logged_in_user = TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$data = user_load($data['uid']);
|
||||
|
||||
@@ -34,15 +34,15 @@ function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALS
|
||||
$category = !empty($conf['category']) ? $conf['category'] : FALSE;
|
||||
unset($conf['category']);
|
||||
|
||||
// If no category was specified, use the default 'account'.
|
||||
if (!$category) {
|
||||
$category = 'account';
|
||||
}
|
||||
// Return previously created contexts, per category.
|
||||
static $created = array();
|
||||
if (!empty($created[$category])) {
|
||||
return $created[$category];
|
||||
}
|
||||
// If no category was specified, use the default 'account'.
|
||||
if (!$category) {
|
||||
$category = 'account';
|
||||
}
|
||||
|
||||
$context = new ctools_context(array('form', 'user_edit', 'user_form', 'user_edit_form', 'user', 'entity:user'));
|
||||
// Store this context for later.
|
||||
@@ -107,7 +107,7 @@ function ctools_context_user_edit_form_settings_form($form, &$form_state) {
|
||||
);
|
||||
|
||||
if (!empty($conf['uid'])) {
|
||||
$info = db_query('SELECT * FROM {user} WHERE uid = :uid', array(':uid' => $conf['uid']))->fetchObject();
|
||||
$info = db_query('SELECT * FROM {users} WHERE uid = :uid', array(':uid' => $conf['uid']))->fetchObject();
|
||||
if ($info) {
|
||||
$link = l(t("'%name' [user id %uid]", array('%name' => $info->name, '%uid' => $info->uid)), "user/$info->uid", array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
|
||||
$form['user']['#description'] = t('Currently set to !link', array('!link' => $link));
|
||||
@@ -154,10 +154,10 @@ function ctools_context_user_edit_form_settings_form_validate($form, &$form_stat
|
||||
$uid = $preg_matches[1];
|
||||
}
|
||||
if (is_numeric($uid)) {
|
||||
$user = db_query('SELECT uid FROM {user} WHEREuid = :uid', array(':uid' => $uid))->fetchObject();
|
||||
$user = db_query('SELECT uid FROM {users} WHERE uid = :uid', array(':uid' => $uid))->fetchObject();
|
||||
}
|
||||
else {
|
||||
$user = db_query('SELECT uid FROM {user} WHERE LOWER(name) = LOWER(:name)', array(':name' => $uid))->fetchObject();
|
||||
$user = db_query('SELECT uid FROM {users} WHERE LOWER(name) = LOWER(:name)', array(':name' => $uid))->fetchObject();
|
||||
}
|
||||
|
||||
form_set_value($form['uid'], $user->uid, $form_state);
|
||||
|
||||
Reference in New Issue
Block a user