security update core+modules

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-26 18:38:56 +02:00
parent 2f45ea820a
commit 7c96373038
1022 changed files with 30319 additions and 11259 deletions

View File

@@ -0,0 +1,94 @@
<?php
/**
* @file
* Plugin to provide access control based on whether a node belongs to a book.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
if (module_exists('book')) {
$plugin = array(
'title' => t("Book: node is in a book"),
'description' => t('Control access based upon a node belonging to a book.'),
'callback' => 'ctools_book_node_ctools_access_check',
'default' => array('book' => array()),
'settings form' => 'ctools_book_node_ctools_access_settings',
'settings form submit' => 'ctools_book_node_ctools_access_settings_submit',
'summary' => 'ctools_book_node_ctools_access_summary',
'required context' => new ctools_context_required(t('Node'), 'node'),
);
}
/**
* Settings form for the 'by book_node' access plugin.
*/
function ctools_book_node_ctools_access_settings($form, &$form_state, $conf) {
$options = array(
'any' => t('In any book'),
);
$books = book_get_books();
foreach ($books as $bid => $book) {
$options[$bid] = $book['title'];
}
$form['settings']['book'] = array(
'#title' => t('Book'),
'#type' => 'checkboxes',
'#options' => $options,
'#description' => t('Pass only if the node belongs to one of the selected books'),
'#default_value' => $conf['book'],
'#required' => TRUE,
);
return $form;
}
/**
* Check for access.
*/
function ctools_book_node_ctools_access_check($conf, $context) {
// As far as I know there should always be a context at this point, but this
// is safe.
if (empty($context) || empty($context->data) || empty($context->data->book)) {
return FALSE;
}
if ($conf['book']['any']) {
return !empty($context->data->book);
}
foreach ($conf['book'] as $bid => $value) {
if ($bid == 'any') {
continue;
}
if ($value && ($bid == $context->data->book['bid'])) {
return TRUE;
}
}
return FALSE;
}
/**
* Provide a summary description based upon the checked node_languages.
*/
function ctools_book_node_ctools_access_summary($conf, $context) {
if ($conf['book']['any']) {
return t('@identifier belongs to a book', array('@identifier' => $context->identifier));
}
$books = array();
foreach ($conf['book'] as $bid => $value) {
if ($value) {
$node = node_load($bid);
$books[] = $node->title;
}
}
if (count($books) == 1) {
return t('@identifier belongs to the book "@book"', array('@book' => $books[0], '@identifier' => $context->identifier));
}
return t('@identifier belongs in multiple books', array('@identifier' => $context->identifier));
}

View File

@@ -16,8 +16,8 @@ $plugin = array(
'get child' => 'ctools_entity_field_value_ctools_access_get_child',
'get children' => 'ctools_entity_field_value_ctools_access_get_children',
);
function ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $child) {
function ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $child) {
$plugins = &drupal_static(__FUNCTION__, array());
if (empty($plugins[$parent . ':' . $child])) {
list($entity_type, $bundle_type, $field_name) = explode(':', $child);
@@ -48,7 +48,6 @@ function ctools_entity_field_value_ctools_access_get_children($plugin, $parent)
}
function _ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $entity_type, $bundle_type, $field_name, $entity = NULL, $bundle = NULL, $field = NULL) {
// check that the entity, bundle and field arrays have a value.
// If not, load theme using machine names.
if (empty($entity)) {
@@ -86,12 +85,34 @@ function ctools_entity_field_value_ctools_access_settings($form, &$form_state, $
$instance = $instances[$field_name];
$field = field_info_field_by_id($instance['field_id']);
foreach ($field['columns'] as $column => $attributes) {
$columns[] = _field_sql_storage_columnname($field_name, $column);
$columns[$column] = _field_sql_storage_columnname($field_name, $column);
}
ctools_include('fields');
$entity = (object)array(
$entity_info['entity keys']['bundle'] => $bundle_type,
);
foreach ($columns as $column => $sql_column) {
if (isset($conf[$sql_column])) {
if (is_array($conf[$sql_column])) {
foreach ($conf[$sql_column] as $delta => $conf_value) {
if (is_numeric($delta)) {
if (is_array($conf_value)) {
$entity->{$field_name}[LANGUAGE_NONE][$delta][$column] = $conf_value[$column];
}
else {
$entity->{$field_name}[LANGUAGE_NONE][$delta][$column] = $conf_value;
}
}
}
}
else {
$entity->{$field_name}[LANGUAGE_NONE][0][$column] = $conf[$sql_column];
}
}
}
$form['#parents'] = array('settings');
$langcode = field_valid_language(NULL);
$form['settings'] += (array) ctools_field_invoke_field($instance, 'form', $entity_type, $entity, $form, $form_state, array('default' => TRUE, 'language' => $langcode));
// weight is really not important once this is populated and will only interfere with the form layout.
@@ -99,26 +120,9 @@ function ctools_entity_field_value_ctools_access_settings($form, &$form_state, $
unset($form['settings'][$element]['#weight']);
}
// Need more logic here to handle compound fields.
foreach ($columns as $column) {
if (isset($conf[$column]) && is_array($conf[$column])) {
foreach ($conf[$column] as $delta => $conf_value) {
if (is_numeric($delta) && is_array($conf_value)) {
$form['settings'][$field_name][LANGUAGE_NONE][$delta]['value']['#default_value'] = $conf_value['value'];
}
}
}
else {
$form['settings'][$field_name][LANGUAGE_NONE]['#default_value'] = $conf[$column];
}
}
return $form;
}
/**
* Compress the entity bundles allowed to the minimum.
*/
function ctools_entity_field_value_ctools_access_settings_submit($form, &$form_state) {
$plugin = $form_state['plugin'];
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
@@ -128,17 +132,82 @@ function ctools_entity_field_value_ctools_access_settings_submit($form, &$form_s
$instance = $instances[$field_name];
$field = field_info_field_by_id($instance['field_id']);
foreach ($field['columns'] as $column => $attributes) {
$columns[] = _field_sql_storage_columnname($field_name, $column);
$columns[$column] = _field_sql_storage_columnname($field_name, $column);
}
$items = _ctools_entity_field_value_get_proper_form_items($field, $form_state['values']['settings'][$field_name][$langcode], array_keys($columns));
foreach ($columns as $column => $sql_column) {
$column_items = _ctools_entity_field_value_filter_items_by_column($items, $column);
$form_state['values']['settings'][$sql_column] = $column_items;
}
$form_state['values']['settings'][$field_name][$langcode] = $items;
}
function _ctools_entity_field_value_get_proper_form_items($field, $form_items, $columns) {
$items = array();
if (!is_array($form_items)) { // Single value item.
foreach ($columns as $column) {
$items[0][$column] = $form_items;
}
return $items;
}
foreach ($form_items as $delta => $value) {
$item = array();
if (is_numeric($delta)) { // Array of field values.
if (!is_array($value)) { // Single value in array.
foreach ($columns as $column) {
$item[$column] = $value;
}
}
else { // Value has colums.
foreach ($columns as $column) {
$item[$column] = isset($value[$column]) ? $value[$column] : '';
}
}
}
$items[] = $item;
}
// Check if $form_items is an array of columns.
$item = array();
$has_columns = FALSE;
foreach ($columns as $column) {
$form_state['values']['settings'][$column] = $form_state['input']['settings'][$field_name][$langcode];
if (isset($form_items[$column])) {
$has_columns = TRUE;
$item[$column] = $form_items[$column];
}
else {
$item[$column] = '';
}
}
if ($has_columns) {
$items[] = $item;
}
// Remove empty values.
$items = _field_filter_items($field, $items);
return $items;
}
function _ctools_entity_field_value_filter_items_by_column($items, $column) {
$column_items = array();
foreach ($items as $delta => $values) {
$column_items[$delta] = isset($values[$column]) ? $values[$column] : '';
}
return $column_items;
}
/**
* Check for access.
*/
function ctools_entity_field_value_ctools_access_check($conf, $context, $plugin) {
if ((!is_object($context)) || (empty($context->data))) {
// If the context doesn't exist -- for example, a newly added entity
// reference is used as a pane visibility criteria -- we deny access.
return FALSE;
}
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
if ($field_items = field_get_items($entity_type, $context->data, $field_name)) {
@@ -150,35 +219,46 @@ function ctools_entity_field_value_ctools_access_check($conf, $context, $plugin)
foreach ($field['columns'] as $column => $attributes) {
$columns[$column] = _field_sql_storage_columnname($field_name, $column);
}
foreach ($conf as $potential_field => $values) {
if ($field_name === $potential_field) {
$conf_value_array = _ctools_entity_field_value_ctools_access_get_conf_field_values($values, $langcode);
if (empty($conf_value_array)) {
return FALSE;
}
if (isset($conf[$field_name])) {
// We have settings for this field.
$conf_value_array = _ctools_entity_field_value_ctools_access_get_conf_field_values($conf[$field_name], $langcode);
if (empty($conf_value_array)) {
return FALSE;
}
// Check field value.
foreach ($field_items as $field_value) {
// Check field value.
foreach ($field_items as $field_value) {
// Iterate through config values.
foreach ($conf_value_array as $conf_value) {
$match = FALSE;
foreach ($field_value as $field_column => $value) {
// Iterate through config values.
foreach ($conf_value_array as $conf_value) {
//
// Check access only for stored in config column values.
if (isset($conf_value[$field_column])) {
if ($value == $conf_value[$field_column]) {
return TRUE;
$match = TRUE;
}
else {
$match = FALSE;
break;
}
}
}
if ($match) {
return TRUE;
}
}
}
return FALSE;
}
}
return FALSE;
}
function _ctools_entity_field_value_ctools_access_get_conf_field_values($values, $langcode = LANGUAGE_NONE) {
if (!is_array($values) || !isset($values[$langcode])) {
return;
return NULL;
}
$conf_values = array();
@@ -201,39 +281,130 @@ function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugi
$entity = (object)array(
$entity_info['entity keys']['bundle'] => $bundle_type,
);
$string = '';
$keys = array();
$values = array();
$value_keys = array();
$keyed_elements = array();
foreach ($field['columns'] as $column => $attributes) {
$conf_key = _field_sql_storage_columnname($field_name, $column);
if (count($field['columns']) > 1) {
// Add some sort of handling for compound fields
}
else {
if (isset($conf[$conf_key])) {
$entity->{$field_name}[LANGUAGE_NONE][] = array($column => $conf[$conf_key]);
$keyed_elements["@{$column}_value"] = array();
if (isset($conf[$conf_key])) {
if (is_array($conf[$conf_key])) {
$i = 0;
foreach ($conf[$conf_key] as $conf_value) {
if (!is_array($conf_value)) {
$entity->{$field_name}[LANGUAGE_NONE][$i][$column] = $conf_value;
$keyed_elements["@{$column}_value"][$i] = array('#markup' => $conf_value);
}
elseif (isset($conf_value[$column])) {
$entity->{$field_name}[LANGUAGE_NONE][$i][$column] = $conf_value[$column];
$keyed_elements["@{$column}_value"][$i] = array('#markup' => $conf_value[$column]);
}
$i++;
}
}
else {
$entity->{$field_name}[LANGUAGE_NONE][0][$column] = $conf[$conf_key];
$keyed_elements["@{$column}_value"][0] = array('#markup' => $conf[$conf_key]);
}
}
$string .= " @{$column} equals @{$column}_value";
$keys['@' . $column] = $column;
$values["@{$column}_value"] = $conf[$conf_key];
}
$view_mode = 'full';
$null = NULL;
$options = array('language' => LANGUAGE_NONE);
ctools_include('fields');
$display = field_get_display($instance, $view_mode, $entity);
$display['type'] = 'list_default';
$function = $display['module'] . '_field_formatter_view';
$items = isset($entity->{$field_name}[LANGUAGE_NONE]) ? $entity->{$field_name}[LANGUAGE_NONE] : array();
if (function_exists($function)) {
$elements = $function($entity_type, $entity, $field, $instance, LANGUAGE_NONE, $items, $display);
}
$value_keys = array_keys($values);
foreach ($value_keys as $key => $value) {
$values[$value] = $elements[$key]['#markup'];
}
$values = array_merge($keys, $values);
return t($string, $values);
}
$keys['@' . $column] = $column;
$value_keys[] = "@{$column}_value";
}
$elements = array();
$items = isset($entity->{$field_name}[LANGUAGE_NONE]) ? $entity->{$field_name}[LANGUAGE_NONE] : array();
$view_mode = 'full';
ctools_include('fields');
$display = field_get_display($instance, $view_mode, $entity);
if (!isset($display['module'])) {
$display['module'] = $field['module'];
}
if (isset($display['module'])) {
// Choose simple formatter for well known cases.
switch ($display['module']) {
case 'text':
$display['type'] = 'text_default';
break;
case 'list':
$display['type'] = 'list_default';
if ($field['type'] == 'list_boolean') {
$allowed_values = list_allowed_values($field, $instance, $entity_type, $entity);
foreach ($items as $item) {
if (isset($allowed_values[$item['value']])) {
if ($allowed_values[$item['value']] == '') {
$display['type'] = 'list_key';
break;
}
}
else {
$display['type'] = 'list_key';
}
}
}
break;
case 'taxonomy':
$display['type'] = 'taxonomy_term_reference_plain';
break;
case 'entityreference':
$display['type'] = 'entityreference_label';
break;
default :
// Use field instance formatter setting.
break;
}
$function = $display['module'] . '_field_formatter_view';
if (function_exists($function)) {
$entity_group = array(0 => $entity);
$item_group = array(0 => $items);
$instance_group = array(0 => $instance);
field_default_prepare_view($entity_type, $entity_group, $field, $instance_group, LANGUAGE_NONE, $item_group, $display);
$elements = $function($entity_type, $entity, $field, $instance, LANGUAGE_NONE, $item_group[0], $display);
}
}
if (count($elements) > 0) {
foreach ($field['columns'] as $column => $attributes) {
if (count($field['columns']) == 1) {
$keyed_elements["@{$column}_value"] = $elements;
}
}
}
$values = array();
foreach ($value_keys as $key) {
$output = array();
$elements = $keyed_elements[$key];
if (is_array($elements)) {
foreach ($elements as $element_key => $element) {
if (is_numeric($element_key)) {
$value_str= strip_tags(drupal_render($element));
if (strlen($value_str) > 0) {
$output[] = $value_str;
}
}
}
}
else {
$value_str = strip_tags(drupal_render($elements));
if (strlen($value_str) > 0) {
$output[] = $value_str;
}
}
$value = implode(', ', $output);
if ($value !== '') {
$values[$key] = implode(', ', $output);
}
}
$string = '';
$value_count = count($values);
foreach ($keys as $key_name => $column) {
if (isset($values[$key_name . '_value'])) {
$string .= ($value_count > 1) ? " @{$column} = @{$column}_value" : "@{$column}_value";
}
}
return t('@field is set to "!value"', array('@field' => $instance['label'], '!value' => format_string($string, array_merge($keys, $values))));
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* @file
* Plugin to provide access control based upon node comment status.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t("Node: comments are open"),
'description' => t('Control access by the nodes comment status.'),
'callback' => 'ctools_node_comment_ctools_access_check',
'summary' => 'ctools_node_comment_ctools_access_summary',
'required context' => new ctools_context_required(t('Node'), 'node'),
);
/**
* Checks for access.
*/
function ctools_node_comment_ctools_access_check($conf, $context) {
return (!empty($context->data) && $context->data->comment == 2);
}
/**
* Provides a summary description based upon the checked node_status.
*/
function ctools_node_comment_ctools_access_summary($conf, $context) {
return t('Returns true if the nodes comment status is "open".');
}

View File

@@ -59,7 +59,7 @@ function ctools_string_length_ctools_access_check($conf, $context) {
return $length < $conf['length'];
case '<=':
return $length <= $conf['length'];
case '==':
case '=':
return $length == $conf['length'];
case '!=':
return $length != $conf['length'];
@@ -68,6 +68,8 @@ function ctools_string_length_ctools_access_check($conf, $context) {
case '>=':
return $length >= $conf['length'];
}
// Invalid Operator sent, return FALSE.
return FALSE;
}
/**

View File

@@ -17,7 +17,11 @@ $plugin = array(
'settings form' => 'ctools_term_vocabulary_ctools_access_settings',
'settings form submit' => 'ctools_term_vocabulary_ctools_access_settings_submit',
'summary' => 'ctools_term_vocabulary_ctools_access_summary',
'required context' => new ctools_context_required(t('Vocabulary'), array('taxonomy_term', 'terms', 'taxonomy_vocabulary')),
'required context' => new ctools_context_required(t('Vocabulary'), array(
'taxonomy_term',
'terms',
'taxonomy_vocabulary'
)),
);
/**
@@ -27,15 +31,17 @@ function ctools_term_vocabulary_ctools_access_settings($form, &$form_state, $con
$options = array();
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
$options[$voc->vid] = check_plain($voc->name);
$options[$voc->machine_name] = check_plain($voc->name);
}
$form['settings']['vids'] = array(
_ctools_term_vocabulary_ctools_access_map_vids($conf);
$form['settings']['machine_name'] = array(
'#type' => 'checkboxes',
'#title' => t('Vocabularies'),
'#options' => $options,
'#description' => t('Only the checked vocabularies will be valid.'),
'#default_value' => $conf['vids'],
'#default_value' => $conf['machine_name'],
);
return $form;
}
@@ -44,7 +50,7 @@ function ctools_term_vocabulary_ctools_access_settings($form, &$form_state, $con
* Compress the term_vocabularys allowed to the minimum.
*/
function ctools_term_vocabulary_ctools_access_settings_submit($form, &$form_state) {
$form_state['values']['settings']['vids'] = array_filter($form_state['values']['settings']['vids']);
$form_state['values']['settings']['machine_name'] = array_filter($form_state['values']['settings']['machine_name']);
}
/**
@@ -53,11 +59,13 @@ function ctools_term_vocabulary_ctools_access_settings_submit($form, &$form_stat
function ctools_term_vocabulary_ctools_access_check($conf, $context) {
// As far as I know there should always be a context at this point, but this
// is safe.
if (empty($context) || empty($context->data) || empty($context->data->vid)) {
if (empty($context) || empty($context->data) || empty($context->data->vocabulary_machine_name)) {
return FALSE;
}
if (array_filter($conf['vids']) && empty($conf['vids'][$context->data->vid])) {
_ctools_term_vocabulary_ctools_access_map_vids($conf);
if (array_filter($conf['machine_name']) && empty($conf['machine_name'][$context->data->vocabulary_machine_name])) {
return FALSE;
}
@@ -73,15 +81,47 @@ function ctools_term_vocabulary_ctools_access_summary($conf, $context) {
}
$vocabularies = taxonomy_get_vocabularies();
_ctools_term_vocabulary_ctools_access_map_vids($conf);
$names = array();
foreach (array_filter($conf['vids']) as $vid) {
$names[] = check_plain($vocabularies[$vid]->name);
if (!empty($conf['machine_name'])) {
foreach (array_filter($conf['machine_name']) as $machine_name) {
foreach ($vocabularies as $vocabulary) {
if ($vocabulary->machine_name === $machine_name) {
$names[] = check_plain($vocabulary->name);
continue;
}
}
}
}
if (empty($names)) {
return t('@identifier is any vocabulary', array('@identifier' => $context->identifier));
}
return format_plural(count($names), '@identifier vocabulary is "@vids"', '@identifier vocabulary is one of "@vids"', array('@vids' => implode(', ', $names), '@identifier' => $context->identifier));
return format_plural(count($names), '@identifier vocabulary is "@machine_names"', '@identifier vocabulary is one of "@machine_names"', array(
'@machine_names' => implode(', ', $names),
'@identifier' => $context->identifier
));
}
/**
* Helper function to map the vids from old features to the new machine_name.
*
* Add the machine_name key to $conf if the vids key exist.
*
* @param array $conf
* The configuration of this plugin.
*/
function _ctools_term_vocabulary_ctools_access_map_vids(&$conf) {
if (!empty($conf['vids'])) {
$conf['machine_name'] = array();
$vocabularies = taxonomy_get_vocabularies();
foreach ($conf['vids'] as $vid) {
$machine_name = $vocabularies[$vid]->machine_name;
$conf['machine_name'][$machine_name] = $vocabularies[$vid]->machine_name;
}
}
}

View File

@@ -3,7 +3,7 @@
/**
* @file
*
* Plugin to provide an argument handler for all entity ids
* Plugin to provide an argument handler for all entity ids.
*/
/**
@@ -16,6 +16,10 @@ $plugin = array(
'context' => 'ctools_argument_entity_id_context',
'get child' => 'ctools_argument_entity_id_get_child',
'get children' => 'ctools_argument_entity_id_get_children',
'default' => array(
'entity_id' => '',
),
'placeholder form' => 'ctools_argument_entity_id_ctools_argument_placeholder',
);
function ctools_argument_entity_id_get_child($plugin, $parent, $child) {
@@ -37,6 +41,7 @@ function ctools_argument_entity_id_get_children($original_plugin, $parent) {
$plugins[$plugin_id] = $plugin;
}
drupal_alter('ctools_entity_contexts', $plugins);
return $plugins;
}
@@ -56,15 +61,87 @@ function ctools_argument_entity_id_context($arg = NULL, $conf = NULL, $empty = F
return ctools_context_create('entity:' . $entity_type, $arg);
}
// Trim spaces and other garbage.
$arg = trim($arg);
if (!is_numeric($arg)) {
$preg_matches = array();
$match = preg_match('/\[id: (\d+)\]/', $arg, $preg_matches);
if (!$match) {
$match = preg_match('/^id: (\d+)/', $arg, $preg_matches);
}
if ($match) {
$id = $preg_matches[1];
}
if (isset($id) && is_numeric($id)) {
return ctools_context_create('entity:' . $entity_type, $id);
}
return FALSE;
}
$entity = entity_load($entity_type, array($arg));
if (!$entity) {
$entities = entity_load($entity_type, array($arg));
if (empty($entities)) {
return FALSE;
}
return ctools_context_create('entity:' . $entity_type, $entity[$arg]);
return ctools_context_create('entity:' . $entity_type, reset($entities));
}
function ctools_argument_entity_id_settings_form(&$form, &$form_state, $conf) {
$plugin = &$form_state['plugin'];
$form['settings']['entity'] = array(
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $plugin['keyword'])),
'#type' => 'textfield',
'#maxlength' => 512,
'#autocomplete_path' => 'ctools/autocomplete/' . $plugin['keyword'],
'#weight' => -10,
);
if (!empty($conf['entity_id'])) {
$info = entity_load($plugin['keyword'], array($conf['entity_id']));
$info = $info[$conf['entity_id']];
if ($info) {
$entity = entity_get_info($plugin['keyword']);
$uri = entity_uri($plugin['keyword'], $info);
if (is_array($uri) && $entity['entity keys']['label']) {
$link = l(t("'%title' [%type id %id]", array('%title' => $info->{$entity['entity keys']['label']}, '%type' => $plugin['keyword'], '%id' => $conf['entity_id'])), $uri['path'], array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
}
elseif (is_array($uri)) {
$link = l(t("[%type id %id]", array('%type' => $plugin['keyword'], '%id' => $conf['entity_id'])), $uri['path'], array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
}
elseif ($entity['entity keys']['label']) {
$link = l(t("'%title' [%type id %id]", array('%title' => $info->{$entity['entity keys']['label']}, '%type' => $plugin['keyword'], '%id' => $conf['entity_id'])), file_create_url($uri), array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
}
else {
$link = t("[%type id %id]", array('%type' => $plugin['keyword'], '%id' => $conf['entity_id']));
}
$form['settings']['entity']['#description'] = t('Currently set to !link', array('!link' => $link));
}
}
$form['settings']['entity_id'] = array(
'#type' => 'value',
'#value' => isset($conf['entity_id']) ? $conf['entity_id'] : '',
);
$form['settings']['entity_type'] = array(
'#type' => 'value',
'#value' => $plugin['keyword'],
);
return $form;
}
function ctools_argument_entity_id_ctools_argument_placeholder($conf) {
$conf = array(
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $conf['keyword'])),
'#type' => 'textfield',
'#maxlength' => 512,
'#autocomplete_path' => 'ctools/autocomplete/' . $conf['keyword'],
'#weight' => -10,
);
return $conf;
}

View File

@@ -39,7 +39,7 @@ function ctools_argument_rid_context($arg = NULL, $conf = NULL, $empty = FALSE)
return FALSE;
}
$nid = db_query('SELECT nid FROM {node_revisions} WHERE vid = :vid', array(':vid' => $arg))->fetchField();
$nid = db_query('SELECT nid FROM {node_revision} WHERE vid = :vid', array(':vid' => $arg))->fetchField();
$node = node_load($nid, $arg);
if (!$node) {
return FALSE;

View File

@@ -44,5 +44,4 @@ function ctools_user_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
// This will perform a node_access check, so we don't have to.
return ctools_context_create('user_edit_form', $account);
return NULL;
}

View File

@@ -40,6 +40,11 @@ function ctools_block_content_type_content_type($subtype_id) {
* of the form "$module . '_ctools_block_info'".
*/
function ctools_block_content_type_content_types() {
$types = &drupal_static(__FUNCTION__);
if (isset($types)) {
return $types;
}
$types = array();
foreach (module_implements('block_info') as $module) {
$module_blocks = module_invoke($module, 'block_info');
@@ -143,27 +148,32 @@ function ctools_block_content_type_render($subtype, $conf) {
$block = module_invoke($module, 'block_view', $delta);
if (!empty($info)) {
// Valid PHP function names cannot contain hyphens.
$block_delta = str_replace('-', '_', $delta);
// Allow modules to modify the block before it is viewed, via either
// hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
drupal_alter(array('block_view', "block_view_{$module}_{$delta}"), $block, $info);
drupal_alter(array('block_view', "block_view_{$module}_{$block_delta}"), $block, $info);
}
$block = (object) $block;
if (empty($block)) {
return;
}
$block = (object) $block;
$block->module = $module;
$block->delta = $delta;
if ($module == 'block' && !empty($info) && isset($info->title)) {
$block->title = $info->title;
}
else if (isset($block->subject)) {
$block->title = $block->subject;
}
else {
$block->title = NULL;
if (!isset($block->title)) {
if ($module == 'block' && !empty($info) && isset($info->title)) {
$block->title = $info->title;
}
else if (isset($block->subject)) {
$block->title = $block->subject;
}
else {
$block->title = NULL;
}
}
if (module_exists('block') && user_access('administer blocks')) {
@@ -286,13 +296,18 @@ function ctools_block_content_type_admin_info($subtype, $conf) {
list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
$block = (object) module_invoke($module, 'block_view', $delta);
// Sanitize the block because <script> tags can hose javascript up:
if (!empty($block->content)) {
$block->content = filter_xss_admin($block->content);
}
if (!empty($block)) {
// Sanitize the block because <script> tags can hose javascript up:
if (!empty($block->content)) {
$block->content = filter_xss_admin(render($block->content));
}
if (!empty($block) && !empty($block->subject)) {
$block->title = $block->subject;
if (!empty($block->subject)) {
$block->title = $block->subject;
}
elseif (empty($block->title)) {
$block->title = t('No title');
}
return $block;
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'single' => TRUE,
'title' => t('Comment links'),
'icon' => 'icon_comment.png',
'description' => t('Comment links of the referenced comment.'),
'required context' => new ctools_context_required(t('Comment'), 'entity:comment'),
'category' => t('Comment'),
'defaults' => array(
'override_title' => FALSE,
'override_title_text' => '',
'build_mode' => '',
),
);
/**
* Output function for the comment links.
*/
function ctools_comment_links_content_type_render($subtype, $conf, $panel_args, $context) {
if (!empty($context) && empty($context->data)) {
return;
}
$comment = isset($context->data) ? clone($context->data) : NULL;
$block = new stdClass();
$block->module = 'comment';
$block->delta = $comment->cid;
if (empty($comment)) {
$block->delta = 'placeholder';
$block->subject = t('Comment subject.');
$block->content = t('Comment links go here.');
}
else {
$node = node_load($comment->nid);
$block->subject = $comment->subject;
comment_build_content($comment, $node, $conf['build_mode']);
$block->content = $comment->content['links'];
}
return $block;
}
/**
* Returns an edit form for the custom type.
*/
function ctools_comment_links_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$entity = entity_get_info('comment');
$build_mode_options = array();
foreach ($entity['view modes'] as $mode => $option) {
$build_mode_options[$mode] = $option['label'];
}
$form['build_mode'] = array(
'#title' => t('Build mode'),
'#type' => 'select',
'#description' => t('Select a build mode for this comment.'),
'#options' => $build_mode_options,
'#default_value' => $conf['build_mode'],
);
return $form;
}
function ctools_comment_links_content_type_edit_form_submit($form, &$form_state) {
// Copy everything from our defaults.
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
function ctools_comment_links_content_type_admin_title($subtype, $conf, $context) {
return t('"@s" links', array('@s' => $context->identifier));
}

View File

@@ -25,7 +25,7 @@ if (module_exists('comment')) {
function ctools_comment_reply_form_content_type_render($subtype, $conf, $panel_args, $context) {
$comment = ($context[1]->identifier == 'No context') ? NULL : clone($context[1]->data);
$comment = ($context[1]->identifier == t('No context')) ? NULL : clone($context[1]->data);
$block = new stdClass();
$block->module = 'comments';
if ($comment) $block->delta = $comment->cid;

View File

@@ -45,6 +45,11 @@ function ctools_custom_content_type_content_type($subtype_id) {
* Return all custom content types available.
*/
function ctools_custom_content_type_content_types() {
$types = &drupal_static(__FUNCTION__);
if (isset($types)) {
return $types;
}
ctools_include('export');
$types = array();
$types['custom'] = _ctools_default_content_type_content_type();

View File

@@ -38,27 +38,33 @@ function ctools_entity_field_content_type_content_types() {
$context_types = array();
$entities = entity_get_info();
$description = t('Field on the referenced entity.');
$styles = t('Formatter Styles');
$categories = array();
foreach ($entities as $entity_type => $entity) {
$category = t(ucfirst($entity_type));
$categories[$entity_type] = $category;
foreach ($entity['bundles'] as $type => $bundle) {
foreach (field_info_instances($entity_type, $type) as $field_name => $field) {
if (!isset($types[$entity_type . ':' . $field_name])) {
$label = t($field['label']);
$types[$entity_type . ':' . $field_name] = array(
'category' => t(ucfirst($entity_type)),
'category' => $category,
'icon' => 'icon_field.png',
'title' => t('Field: @widget_label (@field_name)', array(
'@widget_label' => t($field['label']),
'@widget_label' => $label,
'@field_name' => $field_name,
)),
'description' => t('Field on the referenced entity.'),
'description' => $description,
'edit form' => array(
'ctools_entity_field_content_type_formatter_options' => array(
'default' => TRUE,
'title' => t('Formatter options for: @widget_label (@field_name)', array(
'@widget_label' => t($field['label']),
'@widget_label' => $label,
'@field_name' => $field_name,
)),
),
'ctools_entity_field_content_type_formatter_styles' => t('Formatter Styles'),
'ctools_entity_field_content_type_formatter_styles' => $styles,
),
);
}
@@ -70,7 +76,7 @@ function ctools_entity_field_content_type_content_types() {
// Create the required context for each field related to the bundle types.
foreach ($types as $key => $field_content_type) {
list($entity_type, $field_name) = explode(':', $key, 2);
$types[$key]['required context'] = new ctools_context_required(t(ucfirst($entity_type)), $entity_type, array(
$types[$key]['required context'] = new ctools_context_required($categories[$entity_type], $entity_type, array(
'type' => array_keys($context_types[$key]['types']),
));
unset($context_types[$key]['types']);
@@ -112,6 +118,8 @@ function ctools_entity_field_content_type_render($subtype, $conf, $panel_args, $
$field_settings = array(
'label' => $label,
'type' => $conf['formatter'],
// Pass all entity field panes settings to field display settings.
'pane_settings' => $conf,
);
// Get the field output, and the title.
@@ -121,33 +129,19 @@ function ctools_entity_field_content_type_render($subtype, $conf, $panel_args, $
$all_values = field_get_items($entity_type, $entity, $field_name, $language);
if (!is_array($all_values)) {
$all_values = array();
// Do not render if the field is empty.
return;
}
// Reverse values.
if (isset($conf['delta_reversed']) && $conf['delta_reversed']) {
$all_values = array_reverse($all_values);
$all_values = array_reverse($all_values, TRUE);
}
if (isset($conf['delta_limit'])) {
$delta_limit = $conf['delta_limit'];
$offset = intval($conf['delta_offset']);
$total = count($all_values);
if ($delta_limit == 0) {
$delta_limit = $total - $offset;
}
$new_values = array();
for ($i = 0; $i < $delta_limit; $i++) {
$new_delta = $offset + $i;
if (isset($all_values[$new_delta])) {
$new_values[] = $all_values[$new_delta];
}
}
$all_values = $new_values;
$limit = !empty($conf['delta_limit']) ? $conf['delta_limit'] : NULL;
$all_values = array_slice($all_values, $offset, $limit, TRUE);
}
$clone = clone $entity;
@@ -257,10 +251,21 @@ function ctools_entity_field_content_type_formatter_styles_submit($form, &$form_
}
/**
* Returns the administrative title for a type.
*/
* Returns the administrative title for a type.
*/
function ctools_entity_field_content_type_admin_title($subtype, $conf, $context) {
list($bundle, $field_name) = explode(':', $subtype);
ctools_include('fields');
return t('"@s" @field', array('@s' => $context->identifier, '@field' => ctools_field_label($field_name)));
if (is_object($context) && isset($context->identifier)) {
$identifier = $context->identifier;
}
else {
$type = 'ctools_entity_field_content_type_admin_title';
$message = t('Context is missing for field: @name', array('@name' => $subtype));
$variables = array($subtype, $conf, $context);
watchdog($type, $message, $variables, $severity = WATCHDOG_NOTICE);
$identifier = t('Unknown');
}
return t('"@s" @field', array('@s' => $identifier, '@field' => ctools_field_label($field_name)));
}

View File

@@ -25,6 +25,11 @@ function ctools_entity_field_extra_content_type_content_type($subtype) {
*/
function ctools_entity_field_extra_content_type_content_types() {
// This will hold all the individual field content types.
$types = &drupal_static(__FUNCTION__);
if (isset($types)) {
return $types;
}
$types = array();
$context_types = array();
$entities = entity_get_info();
@@ -97,13 +102,20 @@ function ctools_entity_field_extra_content_type_render($subtype, $conf, $panel_a
$entity = clone $context->data;
list($entity_type, $field_name) = explode(':', $subtype, 2);
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
// Invoke the view-hook to get the extra field.
$entity->content = array();
$langcode = $GLOBALS['language_content']->language;
module_invoke_all($entity_type . '_view', $entity, $conf['view_mode'], $langcode);
module_invoke_all('entity_view', $entity, $entity_type, $conf['view_mode'], $langcode);
$function = $entity_type . '_view';
if (in_array($entity_type, array('node', 'taxonomy_term', 'user')) && function_exists($function)) {
// Call known ENTITY_view() to get the extra field.
$entity->content = $function($entity, $conf['view_mode'], $langcode);
}
else {
// Invoke the view-hook to get the extra field.
$entity->content = array();
module_invoke_all($entity_type . '_view', $entity, $conf['view_mode'], $langcode);
module_invoke_all('entity_view', $entity, $entity_type, $conf['view_mode'], $langcode);
}
if (isset($entity->content[$field_name])) {
// Build the content type block.

View File

@@ -30,6 +30,11 @@ function ctools_entity_form_field_content_type_content_type($subtype) {
*/
function ctools_entity_form_field_content_type_content_types() {
// This will hold all the individual field content types.
$types = &drupal_static(__FUNCTION__);
if (isset($types)) {
return $types;
}
$types = array();
$content_types = array();
$entities = entity_get_info();

View File

@@ -11,7 +11,7 @@
* by the system that includes this file.
*/
$plugin = array(
'title' => t('Node'),
'title' => t('Existing node'),
'single' => TRUE,
'defaults' => array(
'nid' => '',
@@ -20,7 +20,6 @@ $plugin = array(
'identifier' => '',
'build_mode' => 'teaser',
),
'title' => t('Existing node'),
'icon' => 'icon_node.png',
'description' => t('Add a node from your site as content.'),
'category' => t('Custom'),

View File

@@ -0,0 +1,117 @@
<?php
if (module_exists('comment')) {
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'single' => TRUE,
'title' => t('Comments and comment form.'),
'icon' => 'icon_node.png',
'description' => t('The comments and comment form for the referenced node.'),
'required context' => new ctools_context_required(t('Node'), 'node'),
'category' => t('Node'),
'defaults' => array(
'mode' => variable_get('comment_default_mode', COMMENT_MODE_THREADED),
'comments_per_page' => variable_get('comment_default_per_page', '50'),
),
);
}
/**
* Render the node comments.
*/
function ctools_node_comment_wrapper_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$block = new stdClass();
$block->module = 'comments';
$block->delta = $node->nid;
$renderable = array(
'#theme' => 'comment_wrapper__node_' . $node->type,
'#node' => $node,
'comments' => array(),
'comment_form' => array(),
);
// Add in the comments.
if (($node->comment_count && user_access('access comments')) || user_access('administer comments')) {
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
$comments = comment_load_multiple($cids);
comment_prepare_thread($comments);
$build = comment_view_multiple($comments, $node);
$build['pager']['#theme'] = 'pager';
$renderable['comments'] = $build;
}
}
// Stuff in the comment form.
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('post comments')) {
$comment = new stdClass();
$comment->nid = $node->nid;
$comment->pid = NULL;
$form_state = array(
'ctools comment alter' => TRUE,
'node' => $node,
'build_info' => array(
'args' => array(
$comment,
),
),
);
$renderable['comment_form'] = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
}
else if (!empty($conf['anon_links'])) {
$renderable['comment_form'] = theme('comment_post_forbidden', array('node' => $node));
}
}
$block->content = drupal_render($renderable);
return $block;
}
/**
* Returns an edit form for the comment wrapper.
*/
function ctools_node_comment_wrapper_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$form['mode'] = array(
'#type' => 'select',
'#title' => t('Mode'),
'#default_value' => $conf['mode'],
'#options' => _comment_get_modes(),
'#weight' => 1,
);
foreach (_comment_per_page() as $i) {
$options[$i] = t('!a comments per page', array('!a' => $i));
}
$form['comments_per_page'] = array('#type' => 'select',
'#title' => t('Pager'),
'#default_value' => $conf['comments_per_page'],
'#options' => $options,
'#weight' => 3,
);
return $form;
}
/**
* Submit handler for the comment wrapper settings form.
*/
function ctools_node_comment_wrapper_content_type_edit_form_submit($form, &$form_state) {
// Copy everything from our defaults.
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
/**
* Returns the administrative title.
*/
function ctools_node_comment_wrapper_content_type_admin_title($subtype, $conf, $context) {
return t('Comments and comment form');
}

View File

@@ -13,6 +13,9 @@ $plugin = array(
'category' => t('Node'),
'defaults' => array(
'link' => TRUE,
'markup' => 'none',
'id' => '',
'class' => '',
),
);
@@ -30,11 +33,27 @@ function ctools_node_title_content_type_render($subtype, $conf, $panel_args, $co
// Load information about the node type.
$type = node_type_get_type($node);
// Generate the title
$content = !empty($conf['link']) ? l($node->title, 'node/' . $node->nid) : check_plain($node->title);
// Build any surrounding markup if so configured
if (isset($conf['markup']) && $conf['markup'] != 'none') {
$markup = '<' . $conf['markup'];
if (!empty($conf['id'])) {
$markup .= ' id="' . $conf['id'] . '"';
}
if (!empty($conf['class'])) {
$markup .= ' class="' . $conf['class'] . '"';
}
$markup .= '>' . $content . '</' . $conf['markup'] . '>' . "\n";
$content = $markup;
}
// Build the content type block.
$block = new stdClass();
$block->module = 'node_title';
$block->title = $type->title_label;
$block->content = !empty($conf['link']) ? l($node->title, 'node/' . $node->nid) : check_plain($node->title);
$block->content = $content;
$block->delta = $node->nid;
return $block;
@@ -46,6 +65,34 @@ function ctools_node_title_content_type_render($subtype, $conf, $panel_args, $co
function ctools_node_title_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$form['markup'] = array(
'#title' => t('Title tag'),
'#type' => 'select',
'#options' => array(
'none' => t('- No tag -'),
'h1' => t('h1'),
'h2' => t('h2'),
'h3' => t('h3'),
'h4' => t('h4'),
'h5' => t('h5'),
'h6' => t('h6'),
'div' => t('div'),
),
'#default_value' => $conf['markup'],
);
$form['id'] = array(
'#title' => t('CSS id to use'),
'#type' => 'textfield',
'#default_value' => $conf['id'],
);
$form['class'] = array(
'#title' => t('CSS class to use'),
'#type' => 'textfield',
'#default_value' => $conf['class'],
);
$form['link'] = array(
'#title' => t('Link to node'),
'#type' => 'checkbox',

View File

@@ -20,7 +20,7 @@ $plugin = array(
* Render the custom content type.
*/
function ctools_node_updated_content_type_render($subtype, $conf, $panel_args, $context) {
if (empty($context) || empty($context->data)) {
if (empty($context) || empty($context->data) || empty($context->data->nid)) {
return;
}

View File

@@ -7,18 +7,48 @@
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
* Plugins are described by creating a $plugin array which will be used by the
* system that includes this file.
*/
$plugin = array(
'title' => t('Site name'),
'single' => TRUE,
'icon' => 'icon_page.png',
'description' => t('The name of the site.'),
'description' => t('The name of the site, optionally links to the front page.'),
'category' => t('Page elements'),
'render last' => TRUE,
'defaults' => array(
'linked' => FALSE,
),
);
/**
* Settings form for the Site Name pane.
*/
function ctools_page_site_name_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$form['linked'] = array(
'#title' => t('Linked'),
'#description' => t('Link the site name to the home page.'),
'#type' => 'checkbox',
'#default_value' => isset($conf['linked']) ? $conf['linked'] : FALSE,
);
return $form;
}
/**
* The submit form stores the data in $conf.
*/
function ctools_page_site_name_content_type_edit_form_submit($form, &$form_state) {
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
if (isset($form_state['values'][$key])) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
}
/**
* Output function for the 'page_site_name' content type.
*
@@ -26,7 +56,13 @@ $plugin = array(
*/
function ctools_page_site_name_content_type_render($subtype, $conf, $panel_args) {
$block = new stdClass();
$block->content = filter_xss_admin(variable_get('site_name', 'Drupal'));
// Optionally link the site name to the homepage.
if (!empty($conf['linked'])) {
$block->content = l($block->content, '<front>');
}
return $block;
}

View File

@@ -14,7 +14,7 @@ $plugin = array(
'title' => t('Site slogan'),
'single' => TRUE,
'icon' => 'icon_page.png',
'description' => t('Add the slogan trail as content.'),
'description' => t("Add the site's slogan as content."),
'category' => t('Page elements'),
'render last' => TRUE,
);
@@ -26,7 +26,7 @@ $plugin = array(
*/
function ctools_page_slogan_content_type_render($subtype, $conf, $panel_args) {
$block = new stdClass();
$block->content = (theme_get_setting('toggle_slogan') ? filter_xss_admin(variable_get('site_slogan', '')) : '');
$block->content = filter_xss_admin(variable_get('site_slogan', ''));
return $block;
}

View File

@@ -11,7 +11,13 @@ $plugin = array(
'description' => t('Terms related to an existing term; may be child, siblings or top level.'),
'required context' => new ctools_context_required(t('Term'), array('term', 'taxonomy_term')),
'category' => t('Taxonomy term'),
'defaults' => array('title' => '', 'type' => 'child', 'list_type' => 'ul', 'path' => 'taxonomy/term'),
'defaults' => array(
'title' => '',
'type' => 'child',
'include_current_term' => FALSE,
'list_type' => 'ul',
'path' => 'taxonomy/term',
),
);
function ctools_term_list_content_type_render($subtype, $conf, $panel_args, $context) {
@@ -40,6 +46,9 @@ function ctools_term_list_content_type_render($subtype, $conf, $panel_args, $con
case 'child':
default:
if (!empty($conf['include_current_term'])) {
$terms[] = $term;
}
$terms = taxonomy_get_children($term->tid);
break;
@@ -49,7 +58,10 @@ function ctools_term_list_content_type_render($subtype, $conf, $panel_args, $con
case 'parent':
$terms = taxonomy_get_parents($term->tid);
$block->title = format_plural(count($terms), 'Parent term', 'Parent terms');
if (!empty($conf['include_current_term'])) {
$terms[] = $term;
}
$block->title = count($terms) == 1 ? t('Parent term') : t('Parent terms');
break;
case 'sibling':
@@ -116,6 +128,20 @@ function ctools_term_list_content_type_edit_form($form, &$form_state) {
'#suffix' => '</div>',
);
$form['include_current_term'] = array(
'#type' => 'checkbox',
'#title' => t('Include the current term in the list'),
'#default_value' => !empty($conf['include_current_term']),
'#prefix' => '<div class="clearfix no-float">',
'#suffix' => '</div>',
'#states' => array(
'invisible' => array(
':input[name="type"], unique1' => array('!value' => 'child'),
':input[name="type"], unique2' => array('!value' => 'parent'),
),
),
);
$form['list_type'] = array(
'#type' => 'select',
'#title' => t('List type'),

View File

@@ -0,0 +1,121 @@
<?php
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'single' => TRUE,
'title' => t('Term name'),
'icon' => 'icon_term.png',
'description' => t('The name of this taxonomy term.'),
'required context' => new ctools_context_required(t('Term'), array('term', 'taxonomy_term')),
'category' => t('Taxonomy term'),
'defaults' => array(
'link' => TRUE,
'markup' => 'none',
'id' => '',
'class' => '',
),
);
/**
* Render the custom content type.
*/
function ctools_term_name_content_type_render($subtype, $conf, $panel_args, $context) {
if (empty($context) || empty($context->data)) {
return;
}
// Get a shortcut to the term.
$term = $context->data;
// Load the vocabulary.
$vocab = taxonomy_vocabulary_load($term->vid);
// Generate the title
$content = !empty($conf['link']) ? l($term->name, 'taxonomy/term/' . $term->tid) : check_plain($term->name);
// Build any surrounding markup if so configured
if (isset($conf['markup']) && $conf['markup'] != 'none') {
$markup = '<' . $conf['markup'];
if (!empty($conf['id'])) {
$markup .= ' id="' . $conf['id'] . '"';
}
if (!empty($conf['class'])) {
$markup .= ' class="' . $conf['class'] . '"';
}
$markup .= '>' . $content . '</' . $conf['markup'] . '>' . "\n";
$content = $markup;
}
// Build the content type block.
$block = new stdClass();
$block->module = 'term_name';
$block->title = t('Name');
$block->content = $content;
$block->delta = $term->tid;
return $block;
}
/**
* Returns an edit form for custom type settings.
*/
function ctools_term_name_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$form['markup'] = array(
'#title' => t('Title tag'),
'#type' => 'select',
'#options' => array(
'none' => t('- No tag -'),
'h1' => t('h1'),
'h2' => t('h2'),
'h3' => t('h3'),
'h4' => t('h4'),
'h5' => t('h5'),
'h6' => t('h6'),
'div' => t('div'),
),
'#default_value' => $conf['markup'],
);
$form['id'] = array(
'#title' => t('CSS id to use'),
'#type' => 'textfield',
'#default_value' => $conf['id'],
);
$form['class'] = array(
'#title' => t('CSS class to use'),
'#type' => 'textfield',
'#default_value' => $conf['class'],
);
$form['link'] = array(
'#title' => t('Link to term'),
'#type' => 'checkbox',
'#default_value' => $conf['link'],
'#description' => t('Check here to make the name link to the term page.'),
);
return $form;
}
/**
* Submit handler for the custom type settings form.
*/
function ctools_term_name_content_type_edit_form_submit($form, &$form_state) {
// Copy everything from our defaults.
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
/**
* Returns the administrative title for a type.
*/
function ctools_term_name_content_type_admin_title($subtype, $conf, $context) {
return t('"@s" name', array('@s' => $context->identifier));
}

View File

@@ -33,19 +33,26 @@ function ctools_token_content_type_content_type($subtype) {
*/
function ctools_token_content_type_content_types() {
// This will hold all the properties.
$types = &drupal_static(__FUNCTION__);
if (isset($types)) {
return $types;
}
$types = array();
$info = token_info();
foreach ($info['tokens'] as $entity_type => $tokens) {
$category = t('@entity (tokens)', array('@entity' => ucfirst($entity_type)));
$context = new ctools_context_required(t(ucfirst($entity_type)), $entity_type);
foreach ($tokens as $name => $token) {
if (!empty($token['name'])) {
$token += array('description' => '');
$types[$entity_type . ':' . $name] = array(
'category' => t('@entity (tokens)', array('@entity' => ucfirst($entity_type))),
'category' => $category,
'icon' => 'icon_token.png',
'title' => $token['name'],
'description' => $token['description'],
'required context' => new ctools_context_required(t(ucfirst($entity_type)), $entity_type),
'required context' => $context,
);
}
}

View File

@@ -1,6 +1,6 @@
<?php
if (module_exists('profile') && !is_null(profile_user_categories())) {
if (module_exists('profile') && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') && !is_null(profile_user_categories())) {
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.

View File

@@ -0,0 +1,84 @@
<?php
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'single' => TRUE,
'title' => t('User links'),
'icon' => 'icon_user.png',
'description' => t('User links of the referenced user.'),
'required context' => new ctools_context_required(t('User'), 'user'),
'category' => t('User'),
'defaults' => array(
'override_title' => FALSE,
'override_title_text' => '',
'build_mode' => '',
),
);
/**
* Output function for the user links.
*/
function ctools_user_links_content_type_render($subtype, $conf, $panel_args, $context) {
if (!empty($context) && empty($context->data)) {
return;
}
$account = clone $context->data;
$block = new stdClass();
$block->module = 'user';
$block->delta = $account->uid;
if (empty($account)) {
$block->delta = 'placeholder';
$block->subject = t('User name.');
$block->content = t('User links go here.');
}
else {
$block->subject = $account->name;
user_build_content($account, $conf['build_mode']);
if (!empty($account->content['links'])) {
$block->content = $account->content['links'];
}
else {
$block->content = '';
}
}
return $block;
}
/**
* Returns an edit form for the custom type.
*/
function ctools_user_links_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$entity = entity_get_info('user');
$build_mode_options = array();
foreach ($entity['view modes'] as $mode => $option) {
$build_mode_options[$mode] = $option['label'];
}
$form['build_mode'] = array(
'#title' => t('Build mode'),
'#type' => 'select',
'#description' => t('Select a build mode for this user.'),
'#options' => $build_mode_options,
'#default_value' => $conf['build_mode'],
);
return $form;
}
function ctools_user_links_content_type_edit_form_submit($form, &$form_state) {
// Copy everything from our defaults.
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
function ctools_user_links_content_type_admin_title($subtype, $conf, $context) {
return t('"@s" links', array('@s' => $context->identifier));
}

View File

@@ -14,12 +14,15 @@ $plugin = array(
'title' => t('String'),
'description' => t('A context that is just a string.'),
'context' => 'ctools_context_create_string',
'edit form' => 'ctools_context_string_settings_form',
'defaults' => '',
'keyword' => 'string',
'no ui' => FALSE,
'context name' => 'string',
'convert list' => array(
'raw' => t('Raw string'),
'html_safe' => t('HTML-safe string'),
'uppercase_words_html_safe' => t('Uppercase words HTML-safe string'),
),
'convert' => 'ctools_context_string_convert',
'placeholder form' => array(
@@ -44,7 +47,8 @@ function ctools_context_create_string($empty, $data = NULL, $conf = FALSE) {
}
if ($data !== FALSE ) {
$context->data = $data;
// Support the array storage from the settings form but also handle direct input from arguments.
$context->data = is_array($data) ? $data['string'] : $data;
$context->title = ($conf) ? check_plain($data['identifier']) : check_plain($data);
return $context;
}
@@ -59,6 +63,28 @@ function ctools_context_string_convert($context, $type) {
return $context->data;
case 'html_safe':
return check_plain($context->data);
case 'uppercase_words_html_safe':
return ucwords(str_replace('-', ' ', check_plain($context->data)));
}
}
/**
* String settings form.
*/
function ctools_context_string_settings_form($form, &$form_state) {
$conf = &$form_state['conf'];
$form['string'] = array(
'#title' => t('Enter the string'),
'#type' => 'textfield',
'#maxlength' => 512,
'#weight' => -10,
'#default_value' => $conf['string'],
);
return $form;
}
function ctools_context_string_settings_form_submit($form, &$form_state) {
$form_state['conf']['string'] = $form_state['values']['string'];
}

View File

@@ -51,8 +51,9 @@ function ctools_context_token_convert_list() {
function ctools_context_token_convert($context, $token) {
$tokens = token_info();
list($type, $token) = explode(':', $token, 2);
$parts = explode(':', $token, 2);
$real_type = isset($tokens['types'][$type]['type']) ? $tokens['types'][$type]['type'] : $type;
if (isset($tokens['tokens'][$real_type][$token])) {
if (isset($tokens['tokens'][$real_type][$parts[0]])) {
$values = token_generate($type, array($token => $token));
if (isset($values[$token])) {
return $values[$token];

View File

@@ -88,7 +88,7 @@ function ctools_context_user_settings_form($form, &$form_state) {
if (!empty($conf['uid'])) {
$info = user_load($conf['uid']);
if ($info) {
$form['user']['#description'] = t('Currently set to !link', array('!link' => theme('username', $info)));
$form['user']['#description'] = t('Currently set to !link', array('!link' => theme('username', array('account' => $info))));
}
}

View File

@@ -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);

View File

@@ -121,7 +121,7 @@ class ctools_export_ui {
switch ($op) {
case 'import':
return user_access('use PHP for settings');
return user_access('use ctools import');
case 'revert':
return ($item->export_type & EXPORT_IN_DATABASE) && ($item->export_type & EXPORT_IN_CODE);
case 'delete':
@@ -152,7 +152,7 @@ class ctools_export_ui {
if (isset($input['op']) && $input['op'] == t('Reset')) {
unset($_SESSION['ctools_export_ui'][$this->plugin['name']]);
if (!$js) {
return drupal_goto($_GET['q']);
drupal_goto($_GET['q']);
}
// clear everything but form id, form build id and form token:
$keys = array_keys($input);
@@ -639,7 +639,7 @@ class ctools_export_ui {
}
function add_page($js, $input, $step = NULL) {
drupal_set_title($this->get_page_title('add'));
drupal_set_title($this->get_page_title('add'), PASS_THROUGH);
// If a step not set, they are trying to create a new item. If a step
// is set, they're in the process of creating an item.
@@ -665,7 +665,7 @@ class ctools_export_ui {
);
$output = $this->edit_execute_form($form_state);
if (!empty($form_state['executed'])) {
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
$this->redirect($form_state['op'], $form_state['item']);
}
@@ -676,7 +676,7 @@ class ctools_export_ui {
* Main entry point to edit an item.
*/
function edit_page($js, $input, $item, $step = NULL) {
drupal_set_title($this->get_page_title('edit', $item));
drupal_set_title($this->get_page_title('edit', $item), PASS_THROUGH);
// Check to see if there is a cached item to get if we're using the wizard.
if (!empty($this->plugin['use wizard'])) {
@@ -701,7 +701,7 @@ class ctools_export_ui {
);
$output = $this->edit_execute_form($form_state);
if (!empty($form_state['executed'])) {
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
$this->redirect($form_state['op'], $form_state['item']);
}
@@ -712,7 +712,7 @@ class ctools_export_ui {
* Main entry point to clone an item.
*/
function clone_page($js, $input, $original, $step = NULL) {
drupal_set_title($this->get_page_title('clone', $original));
drupal_set_title($this->get_page_title('clone', $original), PASS_THROUGH);
// If a step not set, they are trying to create a new clone. If a step
// is set, they're in the process of cloning an item.
@@ -749,7 +749,7 @@ class ctools_export_ui {
);
$output = $this->edit_execute_form($form_state);
if (!empty($form_state['executed'])) {
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
$this->redirect($form_state['op'], $form_state['item']);
}
@@ -778,7 +778,7 @@ class ctools_export_ui {
*/
function edit_execute_form_standard(&$form_state) {
$output = drupal_build_form('ctools_export_ui_edit_item_form', $form_state);
if (!empty($form_state['executed'])) {
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
$this->edit_save_form($form_state);
}
@@ -1218,7 +1218,7 @@ class ctools_export_ui {
* Page callback to display export information for an exportable item.
*/
function export_page($js, $input, $item) {
drupal_set_title($this->get_page_title('export', $item));
drupal_set_title($this->get_page_title('export', $item), PASS_THROUGH);
return drupal_get_form('ctools_export_form', ctools_export_crud_export($this->plugin['schema'], $item), t('Export'));
}
@@ -1226,7 +1226,7 @@ class ctools_export_ui {
* Page callback to import information for an exportable item.
*/
function import_page($js, $input, $step = NULL) {
drupal_set_title($this->get_page_title('import'));
drupal_set_title($this->get_page_title('import'), PASS_THROUGH);
// Import is basically a multi step wizard form, so let's go ahead and
// use CTools' wizard.inc for it.
@@ -1339,7 +1339,7 @@ function _ctools_export_ui_add_form_files($form, &$form_state) {
*
* This simply loads the object defined in the plugin and hands it off.
*/
function ctools_export_ui_list_form($form, $form_state) {
function ctools_export_ui_list_form($form, &$form_state) {
$form_state['object']->list_form($form, $form_state);
return $form;
}
@@ -1441,7 +1441,7 @@ function ctools_export_ui_delete_confirm_form($form, &$form_state) {
$export_key = $plugin['export']['key'];
$question = str_replace('%title', check_plain($item->{$export_key}), $plugin['strings']['confirmation'][$form_state['op']]['question']);
$path = empty($_REQUEST['cancel_path']) ? ctools_export_ui_plugin_base_path($plugin) : $_REQUEST['cancel_path'];
$path = (!empty($_REQUEST['cancel_path']) && !url_is_external($_REQUEST['cancel_path'])) ? $_REQUEST['cancel_path'] : ctools_export_ui_plugin_base_path($plugin);
$form = confirm_form($form,
$question,

View File

@@ -42,7 +42,9 @@ function ctools_book_parent_context($context, $conf) {
// Load the node.
$node = node_load($nid);
// Generate the context.
return ctools_context_create('node', $node);
if (node_access('view', $node)) {
return ctools_context_create('node', $node);
}
}
}
else {

View File

@@ -154,6 +154,11 @@ function ctools_entity_from_field_get_children($parent_plugin, $parent) {
* Return a new context based on an existing context.
*/
function ctools_entity_from_field_context($context, $conf) {
// Perform access check on current logged in user.
global $user;
// Clone user object so account can be passed by value to access callback.
$account = clone $user;
$delta = !empty($conf['delta']) ? intval($conf['delta']) : 0;
$plugin = $conf['name'];
list($plugin, $plugin_name) = explode(':', $plugin);
@@ -173,11 +178,20 @@ function ctools_entity_from_field_context($context, $conf) {
if (isset($items[$delta])) {
ctools_include('fields');
$to_entity_info = entity_get_info($to_entity);
$plugin_info = ctools_get_relationship($conf['name']);
$to_entity_id = $items[$delta][$plugin_info['source key']];
$loaded_to_entity = entity_load($to_entity, array($to_entity_id));
$loaded_to_entity = array_shift($loaded_to_entity);
// Send it to ctools.
return ctools_context_create('entity:' . $to_entity, $to_entity_id);
// Pass current user account and entity type to access callback.
if (function_exists($to_entity_info['access callback']) && !call_user_func($to_entity_info['access callback'], 'view', $loaded_to_entity, $account, $to_entity)) {
return ctools_context_create_empty('entity:' . $to_entity, NULL);
}
else {
// Send it to ctools.
return ctools_context_create('entity:' . $to_entity, $to_entity_id);
}
}
else {
// In case that delta was empty.

View File

@@ -35,7 +35,7 @@ function ctools_terms_from_node_context($context, $conf) {
$fields = field_info_instances('node', $node->type);
foreach ($fields as $name => $info) {
$field_info = field_info_field($name);
if ($field_info['type'] == 'taxonomy_term_reference' && (empty($conf['vocabulary']) || $conf['vocabulary'][$field_info['settings']['allowed_values'][0]['vocabulary']])) {
if ($field_info['type'] == 'taxonomy_term_reference' && (empty($conf['vocabulary']) || !empty($conf['vocabulary'][$field_info['settings']['allowed_values'][0]['vocabulary']]))) {
$items = field_get_items('node', $node, $name);
if (is_array($items)) {
foreach ($items as $item) {