first import
70
sites/all/modules/ctools/plugins/access/compare_users.inc
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Ctools access plugin to provide access/visiblity if two user contexts are equal.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User: compare"),
|
||||
'description' => t('Compare two users (logged-in user and user being viewed, for example)'),
|
||||
'callback' => 'ctools_compare_users_access_check',
|
||||
'default' => array(
|
||||
'equality' => 1,
|
||||
),
|
||||
'settings form' => 'ctools_compare_users_settings',
|
||||
'summary' => 'ctools_compare_users_ctools_access_summary',
|
||||
'required context' => array(
|
||||
new ctools_context_required(t('First User'), 'user'),
|
||||
new ctools_context_required(t("Second User"), 'user')
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by perm' access plugin
|
||||
*/
|
||||
function ctools_compare_users_settings($form, &$form_state, $conf) {
|
||||
|
||||
$form['settings']['helptext'] = array(
|
||||
'#type' => 'markup',
|
||||
'#value' => '<div>' . t('Grant access based on comparison of the two user contexts. For example, to grant access to a user to view their own profile, choose "logged in user" and "user being viewed" and say "grant access if equal". When they\'re the same, access will be granted.') . '</div>',
|
||||
);
|
||||
|
||||
$form['settings']['equality'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Grant access if user contexts are'),
|
||||
'#options' => array(1 => t('Equal'), 0 => t('Not equal')),
|
||||
'#default_value' => $conf['equality'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_compare_users_access_check($conf, $context) {
|
||||
|
||||
if (empty($context) || count($context) != 2 || empty($context[0]->data) || empty($context[1]->data)) {
|
||||
return FALSE;
|
||||
}
|
||||
$account1 = $context[0]->data;
|
||||
$account2 = $context[1]->data;
|
||||
|
||||
// xor returns false if the two bools are the same, and true if they are not.
|
||||
// i.e, if we asked for equality and they are equal, return true.
|
||||
// If we asked for inequality and they are equal, return false.
|
||||
return ($account1->uid == $account2->uid) xor empty($conf['equality']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe an instance of this plugin.
|
||||
*/
|
||||
function ctools_compare_users_ctools_access_summary($conf, $context) {
|
||||
$comparison = !empty($conf['equality']) ? "is" : 'is not';
|
||||
|
||||
return t('@id1 @comp @id2', array('@comp' => $comparison, '@id1' => $context[0]->identifier, '@id2' => $context[1]->identifier));
|
||||
}
|
51
sites/all/modules/ctools/plugins/access/context_exists.inc
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control/visibility based on existence of a specified context
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t("Context exists"),
|
||||
'description' => t('Control access by whether or not a context exists and contains data.'),
|
||||
'callback' => 'ctools_context_exists_ctools_access_check',
|
||||
'settings form' => 'ctools_context_exists_ctools_access_settings',
|
||||
'summary' => 'ctools_context_exists_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Context'), 'any', TRUE),
|
||||
'defaults' => array('exists' => TRUE),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form
|
||||
*/
|
||||
function ctools_context_exists_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$form['settings']['exists'] = array(
|
||||
'#type' => 'radios',
|
||||
'#description' => t("Check to see if the context exists (contains data) or does not exist (contains no data). For example, if a context is optional and the path does not contain an argument for that context, it will not exist."),
|
||||
'#options' => array(TRUE => t('Exists'), FALSE => t("Doesn't exist")),
|
||||
'#default_value' => $conf['exists'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access
|
||||
*/
|
||||
function ctools_context_exists_ctools_access_check($conf, $context) {
|
||||
// xor returns false if the two bools are the same, and true if they are not.
|
||||
// i.e, if we asked for context_exists and it does, return true.
|
||||
// If we asked for context does not exist and it does, return false.
|
||||
return (empty($context->data) xor !empty($conf['exists']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the specified context
|
||||
*/
|
||||
function ctools_context_exists_ctools_access_summary($conf, $context) {
|
||||
if (!empty($conf['exists'])) {
|
||||
return t('@identifier exists', array('@identifier' => $context->identifier));
|
||||
}
|
||||
else {
|
||||
return t('@identifier does not exist', array('@identifier' => $context->identifier));
|
||||
}
|
||||
}
|
136
sites/all/modules/ctools/plugins/access/entity_bundle.inc
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon entity bundle.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Entity: bundle"),
|
||||
'description' => t('Control access by entity bundle.'),
|
||||
'callback' => 'ctools_entity_bundle_ctools_access_check',
|
||||
'default' => array('type' => array()),
|
||||
'settings form' => 'ctools_entity_bundle_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_entity_bundle_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_entity_bundle_ctools_access_summary',
|
||||
'restrictions' => 'ctools_entity_bundle_ctools_access_restrictions',
|
||||
'get child' => 'ctools_entity_bundle_ctools_access_get_child',
|
||||
'get children' => 'ctools_entity_bundle_ctools_access_get_children',
|
||||
);
|
||||
|
||||
function ctools_entity_bundle_ctools_access_get_child($plugin, $parent, $child) {
|
||||
$plugins = ctools_entity_bundle_ctools_access_get_children($plugin, $parent);
|
||||
return $plugins[$parent . ':' . $child];
|
||||
}
|
||||
|
||||
function ctools_entity_bundle_ctools_access_get_children($plugin, $parent) {
|
||||
$entities = entity_get_info();
|
||||
$plugins = array();
|
||||
foreach ($entities as $entity_type => $entity) {
|
||||
$plugin['title'] = t('@entity: Bundle', array('@entity' => $entity['label']));
|
||||
$plugin['keyword'] = $entity_type;
|
||||
$plugin['description'] = t('Control access by @entity entity bundle.', array('@entity' => $entity_type));
|
||||
$plugin['name'] = $parent . ':' . $entity_type;
|
||||
$plugin['required context'] = new ctools_context_required(t(ucfirst($entity_type)), $entity_type);
|
||||
$plugins[$parent . ':' . $entity_type] = $plugin;
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the 'by entity_bundle' access plugin
|
||||
*/
|
||||
function ctools_entity_bundle_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$plugin = $form_state['plugin'];
|
||||
$entity_type = explode(':', $plugin['name']);
|
||||
$entity_type = $entity_type[1];
|
||||
$entity = entity_get_info($entity_type);
|
||||
foreach ($entity['bundles'] as $type => $info) {
|
||||
$options[$type] = check_plain($info['label']);
|
||||
}
|
||||
|
||||
$form['settings']['type'] = array(
|
||||
'#title' => t('Entity Bundle'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#description' => t('Only the checked entity bundles will be valid.'),
|
||||
'#default_value' => $conf['type'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the entity bundles allowed to the minimum.
|
||||
*/
|
||||
function ctools_entity_bundle_ctools_access_settings_submit($form, &$form_state) {
|
||||
$form_state['values']['settings']['type'] = array_filter($form_state['values']['settings']['type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_entity_bundle_ctools_access_check($conf, $context, $plugin) {
|
||||
list($plugin_name, $entity_type) = explode(':', $plugin['name']);
|
||||
if (!$entity_type) {
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
$entity = entity_get_info($entity_type);
|
||||
// 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->{$entity['entity keys']['bundle']})) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (array_filter($conf['type']) && empty($conf['type'][$context->data->{$entity['entity keys']['bundle']}])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the UI that we've eliminated a bunch of possibilities for this
|
||||
* context.
|
||||
*/
|
||||
function ctools_entity_bundle_ctools_access_restrictions($conf, &$context) {
|
||||
if (isset($context->restrictions['type'])) {
|
||||
$context->restrictions['type'] = array_unique(array_merge($context->restrictions['type'], array_keys(array_filter($conf['type']))));
|
||||
}
|
||||
else {
|
||||
$context->restrictions['type'] = array_keys(array_filter($conf['type']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked entity_bundle.
|
||||
*/
|
||||
function ctools_entity_bundle_ctools_access_summary($conf, $context, $plugin) {
|
||||
if (!isset($conf['type'])) {
|
||||
$conf['type'] = array();
|
||||
}
|
||||
|
||||
list($plugin_name, $entity_type) = explode(':', $plugin['name']);
|
||||
if (!$entity_type) {
|
||||
return t('Error, misconfigured entity_bundle access plugin');
|
||||
};
|
||||
|
||||
$entity = entity_get_info($entity_type);
|
||||
|
||||
$names = array();
|
||||
foreach (array_filter($conf['type']) as $type) {
|
||||
$names[] = check_plain($entity['bundles'][$type]['label']);
|
||||
}
|
||||
|
||||
if (empty($names)) {
|
||||
return t('@identifier is any bundle', array('@identifier' => $context->identifier));
|
||||
}
|
||||
|
||||
return format_plural(count($names), '@identifier is bundle "@types"', '@identifier bundle is one of "@types"', array('@types' => implode(', ', $names), '@identifier' => $context->identifier));
|
||||
}
|
||||
|
239
sites/all/modules/ctools/plugins/access/entity_field_value.inc
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon entity bundle.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t("(Custom) Entity: Field Value"),
|
||||
'description' => t('Control access by entity field value.'),
|
||||
'callback' => 'ctools_entity_field_value_ctools_access_check',
|
||||
'default' => array('type' => array()),
|
||||
'settings form' => 'ctools_entity_field_value_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_entity_field_value_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_entity_field_value_ctools_access_summary',
|
||||
'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) {
|
||||
|
||||
$plugins = &drupal_static(__FUNCTION__, array());
|
||||
if (empty($plugins[$parent . ':' . $child])) {
|
||||
list($entity_type, $bundle_type, $field_name) = explode(':', $child);
|
||||
$plugins[$parent . ':' . $child] = _ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $entity_type, $bundle_type, $field_name);
|
||||
}
|
||||
|
||||
return $plugins[$parent . ':' . $child];
|
||||
}
|
||||
|
||||
function ctools_entity_field_value_ctools_access_get_children($plugin, $parent) {
|
||||
$plugins = &drupal_static(__FUNCTION__, array());
|
||||
if (!empty($plugins)) {
|
||||
return $plugins;
|
||||
}
|
||||
$entities = entity_get_info();
|
||||
foreach ($entities as $entity_type => $entity) {
|
||||
foreach ($entity['bundles'] as $bundle_type => $bundle) {
|
||||
foreach (field_info_instances($entity_type, $bundle_type) as $field_name => $field) {
|
||||
if (!isset($plugins[$parent . ':' . $entity_type . ':' . $bundle_type . ':' . $field_name])) {
|
||||
$plugin = _ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $entity_type, $bundle_type, $field_name, $entity, $bundle, $field);
|
||||
$plugins[$parent . ':' . $entity_type . ':' . $bundle_type . ':' . $field_name] = $plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
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)) {
|
||||
$entity = entity_get_info($entity_type);
|
||||
}
|
||||
|
||||
if (empty($bundle)) {
|
||||
$bundle = $entity['bundles'][$bundle_type];
|
||||
}
|
||||
|
||||
if (empty($field)) {
|
||||
$field_instances = field_info_instances($entity_type, $bundle_type);
|
||||
$field = $field_instances[$field_name];
|
||||
}
|
||||
|
||||
$plugin['title'] = t('@entity @type: @field Field', array('@entity' => $entity['label'], '@type' => $bundle_type, '@field' => $field['label']));
|
||||
$plugin['keyword'] = $entity_type;
|
||||
$plugin['description'] = t('Control access by @entity entity bundle.', array('@entity' => $entity_type));
|
||||
$plugin['name'] = $parent . ':' . $entity_type . ':' . $bundle_type . ':' . $field_name;
|
||||
$plugin['required context'] = new ctools_context_required(t(ucfirst($entity_type)), $entity_type, array(
|
||||
'type' => $bundle_type,
|
||||
));
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the 'by entity_bundle' access plugin
|
||||
*/
|
||||
function ctools_entity_field_value_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$plugin = $form_state['plugin'];
|
||||
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
$instances = field_info_instances($entity_type, $bundle_type);
|
||||
$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);
|
||||
}
|
||||
ctools_include('fields');
|
||||
$entity = (object)array(
|
||||
$entity_info['entity keys']['bundle'] => $bundle_type,
|
||||
);
|
||||
$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.
|
||||
foreach (element_children($form['settings']) as $element) {
|
||||
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']);
|
||||
$langcode = field_valid_language(NULL);
|
||||
$langcode = isset($form_state['input']['settings'][$field_name][$langcode]) ? $langcode : LANGUAGE_NONE;
|
||||
$instances = field_info_instances($entity_type, $bundle_type);
|
||||
$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);
|
||||
}
|
||||
foreach ($columns as $column) {
|
||||
$form_state['values']['settings'][$column] = $form_state['input']['settings'][$field_name][$langcode];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_entity_field_value_ctools_access_check($conf, $context, $plugin) {
|
||||
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
|
||||
|
||||
if ($field_items = field_get_items($entity_type, $context->data, $field_name)) {
|
||||
$langcode = field_language($entity_type, $context->data, $field_name);
|
||||
// Get field storage columns.
|
||||
$instance = field_info_instance($entity_type, $field_name, $bundle_type);
|
||||
$field = field_info_field_by_id($instance['field_id']);
|
||||
$columns = array();
|
||||
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;
|
||||
}
|
||||
|
||||
// Check field value.
|
||||
foreach ($field_items as $field_value) {
|
||||
foreach ($field_value as $field_column => $value) {
|
||||
// Iterate through config values.
|
||||
foreach ($conf_value_array as $conf_value) {
|
||||
//
|
||||
if ($value == $conf_value[$field_column]) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
$conf_values = array();
|
||||
|
||||
foreach ($values[$langcode] as $delta => $value) {
|
||||
$conf_values[$delta] = $value;
|
||||
}
|
||||
|
||||
return $conf_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked entity_bundle.
|
||||
*/
|
||||
function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugin) {
|
||||
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
|
||||
$instances = field_info_instances($entity_type, $bundle_type);
|
||||
$instance = $instances[$field_name];
|
||||
$field = field_info_field_by_id($instance['field_id']);
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
$entity = (object)array(
|
||||
$entity_info['entity keys']['bundle'] => $bundle_type,
|
||||
);
|
||||
$string = '';
|
||||
$keys = array();
|
||||
$values = 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]);
|
||||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
46
sites/all/modules/ctools/plugins/access/front.inc
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based on drupal_is_front_page.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t('Front page'),
|
||||
'description' => t('Is this the front page.'),
|
||||
'callback' => 'ctools_front_ctools_access_check',
|
||||
'default' => array('negate' => 0),
|
||||
'settings form' => 'ctools_front_ctools_access_settings',
|
||||
'summary' => 'ctools_front_ctools_access_summary',
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by parent term' access plugin
|
||||
*/
|
||||
function ctools_front_ctools_access_settings($form, &$form_state, $conf) {
|
||||
// No additional configuration necessary.
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_front_ctools_access_check($conf, $context) {
|
||||
if (drupal_is_front_page()) {
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked terms.
|
||||
*/
|
||||
function ctools_front_ctools_access_summary($conf, $context) {
|
||||
return t('The front page');
|
||||
}
|
0
sites/all/modules/ctools/plugins/access/node.inc
Normal file
89
sites/all/modules/ctools/plugins/access/node_access.inc
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon node type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node: accessible"),
|
||||
'description' => t('Control access with built in Drupal node access test.'),
|
||||
'callback' => 'ctools_node_access_ctools_access_check',
|
||||
'default' => array('type' => 'view'),
|
||||
'settings form' => 'ctools_node_access_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_node_access_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_node_access_ctools_access_summary',
|
||||
'required context' => array(
|
||||
new ctools_context_required(t('User'), 'user'),
|
||||
new ctools_context_required(t('Node'), 'node'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by node_access' access plugin
|
||||
*/
|
||||
function ctools_node_access_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$form['settings']['type'] = array(
|
||||
'#title' => t('Operation'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
'view' => t('View'),
|
||||
'update' => t('Update'),
|
||||
'delete' => t('Delete'),
|
||||
'create' => t('Create nodes of the same type'),
|
||||
),
|
||||
'#description' => t('Using built in Drupal node access rules, determine if the user can perform the selected operation on the node.'),
|
||||
'#default_value' => $conf['type'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_node_access_ctools_access_check($conf, $context) {
|
||||
// As far as I know there should always be a context at this point, but this
|
||||
// is safe.
|
||||
list($user_context, $node_context) = $context;
|
||||
if (empty($node_context) || empty($node_context->data) || empty($node_context->data->type)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (empty($user_context) || empty($user_context->data)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($conf['type'] == 'create') {
|
||||
return node_access('create', $node_context->data->type, $user_context->data);
|
||||
}
|
||||
else {
|
||||
return node_access($conf['type'], $node_context->data, $user_context->data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked node_accesss.
|
||||
*/
|
||||
function ctools_node_access_ctools_access_summary($conf, $context) {
|
||||
list($user_context, $node_context) = $context;
|
||||
$replacement = array('@user' => $user_context->identifier, '@node' => $node_context->identifier);
|
||||
|
||||
switch ($conf['type']) {
|
||||
case 'view':
|
||||
return t('@user can view @node.', $replacement);
|
||||
|
||||
case 'update':
|
||||
return t('@user can edit @node.', $replacement);
|
||||
|
||||
case 'delete':
|
||||
return t('@user can delete @node.', $replacement);
|
||||
|
||||
case 'create':
|
||||
return t('@user can create nodes of the same type as @node.', $replacement);
|
||||
}
|
||||
}
|
||||
|
114
sites/all/modules/ctools/plugins/access/node_language.inc
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon node type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
if (module_exists('locale')) {
|
||||
$plugin = array(
|
||||
'title' => t("Node: language"),
|
||||
'description' => t('Control access by node language.'),
|
||||
'callback' => 'ctools_node_language_ctools_access_check',
|
||||
'default' => array('language' => array()),
|
||||
'settings form' => 'ctools_node_language_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_node_language_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_node_language_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the 'by node_language' access plugin
|
||||
*/
|
||||
function ctools_node_language_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$options = array(
|
||||
'current' => t('Current site language'),
|
||||
'default' => t('Default site language'),
|
||||
'no_language' => t('No language'),
|
||||
);
|
||||
$options = array_merge($options, locale_language_list());
|
||||
$form['settings']['language'] = array(
|
||||
'#title' => t('Language'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#description' => t('Pass only if the node is in one of the selected languages.'),
|
||||
'#default_value' => $conf['language'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_node_language_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) || !isset($context->data->language)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
global $language;
|
||||
|
||||
// Specialcase: if 'no language' is checked, return TRUE if the language field is
|
||||
// empty.
|
||||
if (!empty($conf['language']['no_language'])) {
|
||||
if (empty($context->data->language)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Specialcase: if 'current' is checked, return TRUE if the current site language
|
||||
// matches the node language.
|
||||
if (!empty($conf['language']['current'])) {
|
||||
if ($context->data->language == $language->language) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Specialcase: If 'default' is checked, return TRUE if the default site language
|
||||
// matches the node language.
|
||||
if (!empty($conf['language']['default'])) {
|
||||
if ($context->data->language == language_default('language')) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_filter($conf['language']) && empty($conf['language'][$context->data->language])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked node_languages.
|
||||
*/
|
||||
function ctools_node_language_ctools_access_summary($conf, $context) {
|
||||
$languages = array(
|
||||
'current' => t('Current site language'),
|
||||
'default' => t('Default site language'),
|
||||
'no_language' => t('No language'),
|
||||
);
|
||||
$languages = array_merge($languages, locale_language_list());
|
||||
|
||||
if (!isset($conf['language'])) {
|
||||
$conf['language'] = array();
|
||||
}
|
||||
|
||||
$names = array();
|
||||
foreach (array_filter($conf['language']) as $language) {
|
||||
$names[] = $languages[$language];
|
||||
}
|
||||
|
||||
if (empty($names)) {
|
||||
return t('@identifier is in any language', array('@identifier' => $context->identifier));
|
||||
}
|
||||
|
||||
return format_plural(count($names), '@identifier language is "@languages"', '@identifier language is one of "@languages"', array('@languages' => implode(', ', $names), '@identifier' => $context->identifier));
|
||||
}
|
||||
|
33
sites/all/modules/ctools/plugins/access/node_status.inc
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon node (un)published 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: (un)published"),
|
||||
'description' => t('Control access by the nodes published status.'),
|
||||
'callback' => 'ctools_node_status_ctools_access_check',
|
||||
'summary' => 'ctools_node_status_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_node_status_ctools_access_check($conf, $context) {
|
||||
return (!empty($context->data) && $context->data->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked node_statuss.
|
||||
*/
|
||||
function ctools_node_status_ctools_access_summary($conf, $context) {
|
||||
return t('Returns true if the nodes status is "published".');
|
||||
}
|
||||
|
117
sites/all/modules/ctools/plugins/access/node_type.inc
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon node type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node: type"),
|
||||
'description' => t('Control access by node_type.'),
|
||||
'callback' => 'ctools_node_type_ctools_access_check',
|
||||
'default' => array('type' => array()),
|
||||
'settings form' => 'ctools_node_type_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_node_type_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_node_type_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'restrictions' => 'ctools_node_type_ctools_access_restrictions',
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by node_type' access plugin
|
||||
*/
|
||||
function ctools_node_type_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$types = node_type_get_types();
|
||||
foreach ($types as $type => $info) {
|
||||
$options[$type] = check_plain($info->name);
|
||||
}
|
||||
|
||||
$form['settings']['type'] = array(
|
||||
'#title' => t('Node type'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#description' => t('Only the checked node types will be valid.'),
|
||||
'#default_value' => $conf['type'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the node_types allowed to the minimum.
|
||||
*/
|
||||
function ctools_node_type_ctools_access_settings_submit($form, &$form_state) {
|
||||
$form_state['values']['settings']['type'] = array_filter($form_state['values']['settings']['type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_node_type_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->type)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (array_filter($conf['type']) && empty($conf['type'][$context->data->type])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the UI that we've eliminated a bunch of possibilities for this
|
||||
* context.
|
||||
*/
|
||||
function ctools_node_type_ctools_access_restrictions($conf, &$context) {
|
||||
if (isset($context->restrictions['type'])) {
|
||||
$context->restrictions['type'] = array_unique(array_merge($context->restrictions['type'], array_keys(array_filter($conf['type']))));
|
||||
}
|
||||
else {
|
||||
$context->restrictions['type'] = array_keys(array_filter($conf['type']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked node_types.
|
||||
*/
|
||||
function ctools_node_type_ctools_access_summary($conf, $context) {
|
||||
if (!isset($conf['type'])) {
|
||||
$conf['type'] = array();
|
||||
}
|
||||
$types = node_type_get_types();
|
||||
|
||||
$names = array();
|
||||
// If a node type doesn't exist, let the user know, but prevent a notice.
|
||||
$missing_types = array();
|
||||
|
||||
foreach (array_filter($conf['type']) as $type) {
|
||||
if (!empty($types[$type])) {
|
||||
$names[] = check_plain($types[$type]->name);
|
||||
}
|
||||
else {
|
||||
$missing_types[] = check_plain($type);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($names) && empty($missing_types)) {
|
||||
return t('@identifier is any node type', array('@identifier' => $context->identifier));
|
||||
}
|
||||
|
||||
if (!empty($missing_types)) {
|
||||
$output = array();
|
||||
if (!empty($names)) {
|
||||
$output[] = format_plural(count($names), '@identifier is type "@types"', '@identifier type is one of "@types"', array('@types' => implode(', ', $names), '@identifier' => $context->identifier));
|
||||
}
|
||||
$output[] = format_plural(count($missing_types), 'Missing/ deleted type "@types"', 'Missing/ deleted type is one of "@types"', array('@types' => implode(', ', $missing_types)));
|
||||
return implode(' | ', $output);
|
||||
}
|
||||
|
||||
return format_plural(count($names), '@identifier is type "@types"', '@identifier type is one of "@types"', array('@types' => implode(', ', $names), '@identifier' => $context->identifier));
|
||||
}
|
||||
|
88
sites/all/modules/ctools/plugins/access/path_visibility.inc
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control/visibility based on path.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t('String: URL path'),
|
||||
'description' => t('Control access by the current path.'),
|
||||
'callback' => 'ctools_path_visibility_ctools_access_check',
|
||||
'settings form' => 'ctools_path_visibility_ctools_access_settings',
|
||||
'summary' => 'ctools_path_visibility_ctools_access_summary',
|
||||
'required context' => new ctools_context_optional(t('Path'), 'string'),
|
||||
'default' => array('visibility_setting' => 1, 'paths' => ''),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form
|
||||
*/
|
||||
function ctools_path_visibility_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$form['settings']['note'] = array(
|
||||
'#value' => '<div class="description">' . t('Note: if no context is chosen, the current page path will be used.') . '</div>',
|
||||
);
|
||||
|
||||
$form['settings']['visibility_setting'] = array(
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
1 => t('Allow access on the following pages'),
|
||||
0 => t('Allow access on all pages except the following pages'),
|
||||
),
|
||||
'#default_value' => $conf['visibility_setting'],
|
||||
);
|
||||
|
||||
$form['settings']['paths'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Paths'),
|
||||
'#default_value' => $conf['paths'],
|
||||
'#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-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_path_visibility_ctools_access_check($conf, $context) {
|
||||
if (isset($context->data)) {
|
||||
$base_path = $context->data;
|
||||
}
|
||||
else {
|
||||
$base_path = $_GET['q'];
|
||||
}
|
||||
|
||||
$path = drupal_get_path_alias($base_path);
|
||||
$page_match = drupal_match_path($path, $conf['paths']);
|
||||
|
||||
// If there's a path alias, we may still be at the un-aliased path
|
||||
// so check that as well.
|
||||
if (!isset($context->data) && $path != $base_path) {
|
||||
$page_match = $page_match || drupal_match_path($base_path, $conf['paths']);
|
||||
}
|
||||
|
||||
// When $conf['visibility_setting'] has a value of 0, the block is displayed
|
||||
// on all pages except those listed in $block->pages. When set to 1, it
|
||||
// is displayed only on those pages listed in $block->pages.
|
||||
$page_match = !($conf['visibility_setting'] xor $page_match);
|
||||
|
||||
return $page_match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description.
|
||||
*/
|
||||
function ctools_path_visibility_ctools_access_summary($conf, $context) {
|
||||
$paths = array();
|
||||
foreach (explode("\n", $conf['paths']) as $path) {
|
||||
$paths[] = check_plain($path);
|
||||
}
|
||||
|
||||
$identifier = $context->type == 'any' ? t('Current path') : $context->identifier;
|
||||
if ($conf['visibility_setting']) {
|
||||
return format_plural(count($paths), '@identifier is "@paths"', '@identifier type is one of "@paths"', array('@paths' => implode(', ', $paths), '@identifier' => $identifier));
|
||||
}
|
||||
else {
|
||||
return format_plural(count($paths), '@identifier is not "@paths"', '@identifier type is not one of "@paths"', array('@paths' => implode(', ', $paths), '@identifier' => $identifier));
|
||||
}
|
||||
}
|
73
sites/all/modules/ctools/plugins/access/perm.inc
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based on user permission strings.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User: permission"),
|
||||
'description' => t('Control access by permission string.'),
|
||||
'callback' => 'ctools_perm_ctools_access_check',
|
||||
'default' => array('perm' => 'access content'),
|
||||
'settings form' => 'ctools_perm_ctools_access_settings',
|
||||
'summary' => 'ctools_perm_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('User'), 'user'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by perm' access plugin
|
||||
*/
|
||||
function ctools_perm_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$perms = array();
|
||||
// Get list of permissions
|
||||
foreach (module_list(FALSE, FALSE, TRUE) as $module) {
|
||||
// By keeping them keyed by module we can use optgroups with the
|
||||
// 'select' type.
|
||||
if ($permissions = module_invoke($module, 'permission')) {
|
||||
foreach ($permissions as $id => $permission) {
|
||||
$perms[$module][$id] = $permission['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['settings']['perm'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $perms,
|
||||
'#title' => t('Permission'),
|
||||
'#default_value' => $conf['perm'],
|
||||
'#description' => t('Only users with the selected permission flag will be able to access this.'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_perm_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)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return user_access($conf['perm'], $context->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked roles.
|
||||
*/
|
||||
function ctools_perm_ctools_access_summary($conf, $context) {
|
||||
if (!isset($conf['perm'])) {
|
||||
return t('Error, unset permission');
|
||||
}
|
||||
|
||||
$permissions = module_invoke_all('permission');
|
||||
return t('@identifier has "@perm"', array('@identifier' => $context->identifier, '@perm' => $permissions[$conf['perm']]['title']));
|
||||
}
|
||||
|
64
sites/all/modules/ctools/plugins/access/php.inc
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based on evaluated PHP.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("PHP Code"),
|
||||
'description' => t('Control access through arbitrary PHP code.'),
|
||||
'callback' => 'ctools_php_ctools_access_check',
|
||||
'default' => array('description' => '', 'php' => ''),
|
||||
'settings form' => 'ctools_php_ctools_access_settings',
|
||||
'summary' => 'ctools_php_ctools_access_summary',
|
||||
'all contexts' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by perm' access plugin
|
||||
*
|
||||
* @todo Need a way to provide a list of all available contexts to be used by
|
||||
* the eval-ed PHP.
|
||||
*/
|
||||
function ctools_php_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$perms = array();
|
||||
|
||||
$form['settings']['description'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Administrative desc'),
|
||||
'#default_value' => $conf['description'],
|
||||
'#description' => t('A description for this test for administrative purposes.'),
|
||||
);
|
||||
$form['settings']['php'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('PHP Code'),
|
||||
'#default_value' => $conf['php'],
|
||||
'#description' => t('Access will be granted if the following PHP code returns <code>TRUE</code>. Do not include <?php ?>. Note that executing incorrect PHP-code can break your Drupal site. All contexts will be available in the <em>$contexts</em> variable.'),
|
||||
);
|
||||
if (!user_access('use PHP for settings')) {
|
||||
$form['settings']['php']['#disabled'] = TRUE;
|
||||
$form['settings']['php']['#value'] = $conf['php'];
|
||||
$form['settings']['php']['#description'] .= ' ' . t('You do not have sufficient permissions to edit PHP code.');
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_php_ctools_access_check($__conf, $contexts) {
|
||||
$access = eval($__conf['php']);
|
||||
return $access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked roles.
|
||||
*/
|
||||
function ctools_php_ctools_access_summary($conf, $contexts) {
|
||||
return !empty($conf['description']) ? check_plain($conf['description']) : t('No description');
|
||||
}
|
79
sites/all/modules/ctools/plugins/access/role.inc
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon role membership.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User: role"),
|
||||
'description' => t('Control access by role.'),
|
||||
'callback' => 'ctools_role_ctools_access_check',
|
||||
'default' => array('rids' => array()),
|
||||
'settings form' => 'ctools_role_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_role_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_role_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('User'), 'user'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by role' access plugin
|
||||
*/
|
||||
function ctools_role_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$form['settings']['rids'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Role'),
|
||||
'#default_value' => $conf['rids'],
|
||||
'#options' => ctools_get_roles(),
|
||||
'#description' => t('Only the checked roles will be granted access.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the roles allowed to the minimum.
|
||||
*/
|
||||
function ctools_role_ctools_access_settings_submit($form, &$form_state) {
|
||||
$form_state['values']['settings']['rids'] = array_keys(array_filter($form_state['values']['settings']['rids']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_role_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) || !isset($context->data->roles)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$roles = array_keys($context->data->roles);
|
||||
$roles[] = $context->data->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
|
||||
return (bool) array_intersect($conf['rids'], $roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked roles.
|
||||
*/
|
||||
function ctools_role_ctools_access_summary($conf, $context) {
|
||||
if (!isset($conf['rids'])) {
|
||||
$conf['rids'] = array();
|
||||
}
|
||||
$roles = ctools_get_roles();
|
||||
|
||||
$names = array();
|
||||
foreach (array_filter($conf['rids']) as $rid) {
|
||||
$names[] = check_plain($roles[$rid]);
|
||||
}
|
||||
|
||||
if (empty($names)) {
|
||||
return t('@identifier can have any role', array('@identifier' => $context->identifier));
|
||||
}
|
||||
|
||||
return format_plural(count($names), '@identifier has role "@roles"', '@identifier has one of "@roles"', array('@roles' => implode(', ', $names), '@identifier' => $context->identifier));
|
||||
}
|
||||
|
87
sites/all/modules/ctools/plugins/access/site_language.inc
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon node type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
if (module_exists('locale')) {
|
||||
$plugin = array(
|
||||
'title' => t("User: language"),
|
||||
'description' => t('Control access by the language the user or site currently uses.'),
|
||||
'callback' => 'ctools_site_language_ctools_access_check',
|
||||
'default' => array('language' => array()),
|
||||
'settings form' => 'ctools_site_language_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_site_language_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_site_language_ctools_access_summary',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the 'by site_language' access plugin
|
||||
*/
|
||||
function ctools_site_language_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$options = array(
|
||||
'default' => t('Default site language'),
|
||||
);
|
||||
$options = array_merge($options, locale_language_list());
|
||||
$form['settings']['language'] = array(
|
||||
'#title' => t('Language'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#description' => t('Pass only if the current site language is one of the selected languages.'),
|
||||
'#default_value' => $conf['language'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_site_language_ctools_access_check($conf, $context) {
|
||||
global $language;
|
||||
|
||||
// Specialcase: If 'default' is checked, return TRUE if the default site language
|
||||
// matches the node language.
|
||||
if (!empty($conf['language']['default'])) {
|
||||
if ($language->language == language_default('language')) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_filter($conf['language']) && empty($conf['language'][$language->language])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked site_languages.
|
||||
*/
|
||||
function ctools_site_language_ctools_access_summary($conf, $context) {
|
||||
$languages = array(
|
||||
'default' => t('Default site language'),
|
||||
);
|
||||
$languages = array_merge($languages, locale_language_list());
|
||||
|
||||
if (!isset($conf['language'])) {
|
||||
$conf['language'] = array();
|
||||
}
|
||||
|
||||
$names = array();
|
||||
foreach (array_filter($conf['language']) as $language) {
|
||||
$names[] = $languages[$language];
|
||||
}
|
||||
|
||||
if (empty($names)) {
|
||||
return t('Site language is any language');
|
||||
}
|
||||
|
||||
return format_plural(count($names), 'Site language is "@languages"', 'Site language is one of "@languages"', array('@languages' => implode(', ', $names)));
|
||||
}
|
||||
|
94
sites/all/modules/ctools/plugins/access/string_equal.inc
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control/visibility based on specified context string matching user-specified string
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t("String: comparison"),
|
||||
'description' => t('Control access by string match.'),
|
||||
'callback' => 'ctools_string_equal_ctools_access_check',
|
||||
'settings form' => 'ctools_string_equal_ctools_access_settings',
|
||||
'summary' => 'ctools_string_equal_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('String'), 'string'),
|
||||
'defaults' => array('operator' => '=', 'value' => '', 'case' => FALSE),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form
|
||||
*/
|
||||
function ctools_string_equal_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$form['settings']['operator'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Operator'),
|
||||
'#options' => array(
|
||||
'=' => t('Equal'),
|
||||
'!=' => t('Not equal'),
|
||||
'regex' => t('Regular expression'),
|
||||
'!regex' => t('Not equal to regular expression'),
|
||||
),
|
||||
'#default_value' => $conf['operator'],
|
||||
'#description' => t('If using a regular expression, you should enclose the pattern in slashes like so: <em>/foo/</em>. If you need to compare against slashes you can use another character to enclose the pattern, such as @. See <a href="http://www.php.net/manual/en/reference.pcre.pattern.syntax.php">PHP regex documentation</a> for more.'),
|
||||
);
|
||||
|
||||
$form['settings']['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('String'),
|
||||
'#default_value' => $conf['value'],
|
||||
);
|
||||
|
||||
$form['settings']['case'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Case sensitive'),
|
||||
'#default_value' => $conf['case'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access
|
||||
*/
|
||||
function ctools_string_equal_ctools_access_check($conf, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
$string = '';
|
||||
}
|
||||
else {
|
||||
$string = $context->data;
|
||||
}
|
||||
|
||||
$value = $conf['value'];
|
||||
if (empty($conf['case'])) {
|
||||
$string = drupal_strtolower($string);
|
||||
$value = drupal_strtolower($value);
|
||||
}
|
||||
|
||||
switch ($conf['operator']) {
|
||||
case '=':
|
||||
return $string === $value;
|
||||
case '!=':
|
||||
return $string !== $value;
|
||||
case 'regex':
|
||||
return preg_match($value, $string);
|
||||
case '!regex':
|
||||
return !preg_match($value, $string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the specified context
|
||||
*/
|
||||
function ctools_string_equal_ctools_access_summary($conf, $context) {
|
||||
$values = array('@identifier' => $context->identifier, '@value' => $conf['value']);
|
||||
switch ($conf['operator']) {
|
||||
case '=':
|
||||
return t('@identifier is "@value"', $values);
|
||||
case '!=':
|
||||
return t('@identifier is not "@value"', $values);
|
||||
case 'regex':
|
||||
return t('@identifier matches "@value"', $values);
|
||||
case '!regex':
|
||||
return t('@identifier does not match "@value"', $values);
|
||||
}
|
||||
}
|
||||
|
78
sites/all/modules/ctools/plugins/access/string_length.inc
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control/visibility based on length of
|
||||
* a string context.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t("String: length"),
|
||||
'description' => t('Control access by length of string context.'),
|
||||
'callback' => 'ctools_string_length_ctools_access_check',
|
||||
'settings form' => 'ctools_string_length_ctools_access_settings',
|
||||
'summary' => 'ctools_string_length_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('String'), 'string'),
|
||||
'defaults' => array('operator' => '=', 'length' => 0),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by role' access plugin.
|
||||
*/
|
||||
function ctools_string_length_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$form['settings']['operator'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Operator'),
|
||||
'#options' => array(
|
||||
'>' => t('Greater than'),
|
||||
'>=' => t('Greater than or equal to'),
|
||||
'=' => t('Equal to'),
|
||||
'!=' => t('Not equal to'),
|
||||
'<' => t('Less than'),
|
||||
'<=' => t('Less than or equal to'),
|
||||
),
|
||||
'#default_value' => $conf['operator'],
|
||||
);
|
||||
$form['settings']['length'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Length of string'),
|
||||
'#size' => 3,
|
||||
'#default_value' => $conf['length'],
|
||||
'#description' => t('Access/visibility will be granted based on string context length.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_string_length_ctools_access_check($conf, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
$length = 0;
|
||||
}
|
||||
else {
|
||||
$length = drupal_strlen($context->data);
|
||||
}
|
||||
|
||||
switch ($conf['operator']) {
|
||||
case '<':
|
||||
return $length < $conf['length'];
|
||||
case '<=':
|
||||
return $length <= $conf['length'];
|
||||
case '==':
|
||||
return $length == $conf['length'];
|
||||
case '!=':
|
||||
return $length != $conf['length'];
|
||||
case '>':
|
||||
return $length > $conf['length'];
|
||||
case '>=':
|
||||
return $length >= $conf['length'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked roles.
|
||||
*/
|
||||
function ctools_string_length_ctools_access_summary($conf, $context) {
|
||||
return t('@identifier must be @comp @length characters', array('@identifier' => $context->identifier, '@comp' => $conf['operator'], '@length' => $conf['length']));
|
||||
}
|
129
sites/all/modules/ctools/plugins/access/term.inc
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon specific terms.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy: term"),
|
||||
'description' => t('Control access by a specific term.'),
|
||||
'callback' => 'ctools_term_ctools_access_check',
|
||||
'default' => array('vids' => array()),
|
||||
'settings form' => 'ctools_term_ctools_access_settings',
|
||||
'settings form validation' => 'ctools_term_ctools_access_settings_validate',
|
||||
'settings form submit' => 'ctools_term_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_term_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Term'), array('taxonomy_term', 'terms')),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by term' access plugin
|
||||
*/
|
||||
function ctools_term_ctools_access_settings($form, &$form_state, $conf) {
|
||||
// If no configuration was saved before, set some defaults.
|
||||
if (empty($conf)) {
|
||||
$conf = array(
|
||||
'vid' => 0,
|
||||
);
|
||||
}
|
||||
if (!isset($conf['vid'])) {
|
||||
$conf['vid'] = 0;
|
||||
}
|
||||
|
||||
$form['settings']['vid'] = array(
|
||||
'#title' => t('Vocabulary'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(),
|
||||
'#description' => t('Select the vocabulary for this form.'),
|
||||
'#id' => 'ctools-select-vid',
|
||||
'#default_value' => $conf['vid'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
ctools_include('dependent');
|
||||
$options = array();
|
||||
|
||||
// A note: Dependency works strangely on these forms as they have never been
|
||||
// updated to a more modern system so they are not individual forms of their
|
||||
// own like the content types.
|
||||
|
||||
$form['settings']['#tree'] = TRUE;
|
||||
|
||||
// Loop over each of the configured vocabularies.
|
||||
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
|
||||
$options[$vid] = $vocabulary->name;
|
||||
$form['settings'][$vocabulary->vid] = array(
|
||||
'#title' => t('Terms'),
|
||||
'#description' => t('Select a term or terms from @vocabulary.', array('@vocabulary' => $vocabulary->name)), //. $description,
|
||||
'#dependency' => array('ctools-select-vid' => array($vocabulary->vid)),
|
||||
'#default_value' => !empty($conf[$vid]) ? $conf[$vid] : '',
|
||||
'#multiple' => TRUE,
|
||||
);
|
||||
|
||||
$terms = array();
|
||||
foreach (taxonomy_get_tree($vocabulary->vid) as $tid => $term) {
|
||||
$terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name;
|
||||
}
|
||||
$form['settings'][$vocabulary->vid]['#type'] = 'select';
|
||||
$form['settings'][$vocabulary->vid]['#options'] = $terms;
|
||||
unset($terms);
|
||||
}
|
||||
$form['settings']['vid']['#options'] = $options;
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_term_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) || empty($context->data->tid)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get the $vid.
|
||||
if (!isset($conf['vid'])) {
|
||||
return FALSE;
|
||||
}
|
||||
$vid = $conf['vid'];
|
||||
|
||||
// Get the terms.
|
||||
if (!isset($conf[$vid])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$return = FALSE;
|
||||
|
||||
$terms = array_filter($conf[$vid]);
|
||||
// For multi-term if any terms coincide, let's call that good enough:
|
||||
if (isset($context->tids)) {
|
||||
return (bool) array_intersect($terms, $context->tids);
|
||||
}
|
||||
else {
|
||||
return in_array($context->data->tid, $terms);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked terms.
|
||||
*/
|
||||
function ctools_term_ctools_access_summary($conf, $context) {
|
||||
$vid = $conf['vid'];
|
||||
$terms = array();
|
||||
foreach ($conf[$vid] as $tid) {
|
||||
$term = taxonomy_term_load($tid);
|
||||
$terms[] = $term->name;
|
||||
}
|
||||
|
||||
return format_plural(count($terms),
|
||||
'@term can be the term "@terms"',
|
||||
'@term can be one of these terms: @terms',
|
||||
array('@terms' => implode(', ', $terms),
|
||||
'@term' => $context->identifier));
|
||||
}
|
172
sites/all/modules/ctools/plugins/access/term_has_parent.inc
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon a parent term.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy: term has parent(s)"),
|
||||
'description' => t('Control access if a term belongs to a specific parent term.'),
|
||||
'callback' => 'ctools_term_has_parent_ctools_access_check',
|
||||
'default' => array('vid' => array(), 'negate' => 0),
|
||||
'settings form' => 'ctools_term_has_parent_ctools_access_settings',
|
||||
'settings form submit' => 'ctools_term_has_parent_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_term_has_parent_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Term'), array('taxonomy_term', 'terms')),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by parent term' access plugin
|
||||
*/
|
||||
function ctools_term_has_parent_ctools_access_settings($form, &$form_state, $conf) {
|
||||
// If no configuration was saved before, set some defaults.
|
||||
if (empty($conf)) {
|
||||
$conf = array(
|
||||
'vid' => 0,
|
||||
);
|
||||
}
|
||||
if (!isset($conf['vid'])) {
|
||||
$conf['vid'] = 0;
|
||||
}
|
||||
|
||||
$form['settings']['vid'] = array(
|
||||
'#title' => t('Vocabulary'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(),
|
||||
'#description' => t('Select the vocabulary for this form.'),
|
||||
'#id' => 'ctools-select-vid',
|
||||
'#default_value' => $conf['vid'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
ctools_include('dependent');
|
||||
$options = array();
|
||||
|
||||
// A note: Dependency works strangely on these forms as they have never been
|
||||
// updated to a more modern system so they are not individual forms of their
|
||||
// own like the content types.
|
||||
|
||||
$form['settings']['#tree'] = TRUE;
|
||||
|
||||
// Loop over each of the configured vocabularies.
|
||||
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
|
||||
$options[$vid] = $vocabulary->name;
|
||||
$form['settings']['vid_' . $vid] = array(
|
||||
'#title' => t('Terms'),
|
||||
'#description' => t('Select a term or terms from @vocabulary.', array('@vocabulary' => $vocabulary->name)),
|
||||
'#dependency' => array('ctools-select-vid' => array($vocabulary->vid)),
|
||||
'#default_value' => !empty($conf['vid_' . $vid]) ? $conf['vid_' . $vid] : '',
|
||||
'#size' => 10,
|
||||
'#multiple' => TRUE,
|
||||
//@todo: Remove the following workaround when the following patch is in core. {@see:http://drupal.org/node/1117526}
|
||||
'#name' => sprintf("settings[%u][]", $vid),
|
||||
'#attributes' => array('multiple' => 'multiple'),
|
||||
);
|
||||
|
||||
$terms = array();
|
||||
foreach (taxonomy_get_tree($vocabulary->vid) as $term) {
|
||||
$terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name;
|
||||
}
|
||||
//$form['settings']['vid_' . $vid]['#type'] = 'select';
|
||||
$form['settings']['vid_' . $vid]['#type'] = 'checkboxes';
|
||||
$form['settings']['vid_' . $vid]['#options'] = $terms;
|
||||
unset($terms);
|
||||
}
|
||||
$form['settings']['vid']['#options'] = $options;
|
||||
$form['settings']['include_self'] = array(
|
||||
'#title' => t('Include these term(s) as candidates?'),
|
||||
'#description' => t('When this rule is evaluated, should the term(s) you select be included as candidates for access?'),
|
||||
'#default_value' => !empty($conf['include_self']) ? $conf['include_self'] : FALSE,
|
||||
'#type' => 'checkbox',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters values to store less.
|
||||
*/
|
||||
function ctools_term_has_parent_ctools_access_settings_submit($form, &$form_state) {
|
||||
foreach ($form_state['values']['settings'] as $key => $value) {
|
||||
if (strpos($key, 'vid_') === 0) {
|
||||
$form_state['values']['settings'][$key] = array_filter($form_state['values']['settings'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_term_has_parent_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) || empty($context->data->tid)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get the $vid.
|
||||
if (!isset($conf['vid'])) {
|
||||
return FALSE;
|
||||
}
|
||||
$vid = $conf['vid'];
|
||||
|
||||
// we'll start looking up the hierarchy from our context term id.
|
||||
$current_term = $context->data->tid;
|
||||
|
||||
$term='';
|
||||
|
||||
// scan up the tree.
|
||||
while (true) {
|
||||
// select parent as term_parent to avoid PHP5 complications with the parent keyword
|
||||
//@todo: Find a way to reduce the number of queries required for really deep hierarchies.
|
||||
$term = db_query("SELECT parent AS term_parent, tid AS tid FROM {taxonomy_term_hierarchy} th WHERE th.tid = :tid", array(':tid'=>$current_term))->fetchObject();
|
||||
|
||||
// if no term is found, get out of the loop
|
||||
if (!$term || empty($term->tid)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// check the term selected, if the user asked it to.
|
||||
if (!empty($conf['include_self']) && isset($conf['vid_' . $vid][$term->tid])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// did we find the parent TID we were looking for?
|
||||
if (isset($conf['vid_' . $vid][$term->tid])) {
|
||||
// YES, we're done!
|
||||
return TRUE;
|
||||
}
|
||||
// Nope, we didn't find it.
|
||||
|
||||
// If this is the top of the hierarchy, stop scanning.
|
||||
if ($term->term_parent==0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// update the parent, and keep scanning.
|
||||
$current_term = $term->term_parent;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked terms.
|
||||
*/
|
||||
function ctools_term_has_parent_ctools_access_summary($conf, $context) {
|
||||
$vid = (int)$conf['vid'];
|
||||
$terms = array();
|
||||
foreach ($conf['vid_' . $vid] as $tid) {
|
||||
$term = taxonomy_term_load($tid);
|
||||
$terms[] = $term->name;
|
||||
}
|
||||
|
||||
return format_plural(count($terms),
|
||||
'@term can have the parent "@terms"',
|
||||
'@term can have one of these parents: @terms',
|
||||
array('@terms' => implode(', ', $terms),
|
||||
'@term' => $context->identifier));
|
||||
}
|
86
sites/all/modules/ctools/plugins/access/term_parent.inc
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon a parent term.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy: parent term"),
|
||||
'description' => t('Control access by existence of a parent term.'),
|
||||
'callback' => 'ctools_term_parent_ctools_access_check',
|
||||
'default' => array('vid' => array(), 'negate' => 0),
|
||||
'settings form' => 'ctools_term_parent_ctools_access_settings',
|
||||
'settings form validation' => 'ctools_term_parent_ctools_access_settings_validate',
|
||||
'settings form submit' => 'ctools_term_parent_ctools_access_settings_submit',
|
||||
'summary' => 'ctools_term_parent_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Term'), array('taxonomy_term', 'terms')),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by parent term' access plugin
|
||||
*/
|
||||
function ctools_term_parent_ctools_access_settings($form, &$form_state, $conf) {
|
||||
// If no configuration was saved before, set some defaults.
|
||||
if (empty($conf)) {
|
||||
$conf = array(
|
||||
'vid' => 0,
|
||||
);
|
||||
}
|
||||
if (!isset($conf['vid'])) {
|
||||
$conf['vid'] = 0;
|
||||
}
|
||||
|
||||
$form['settings']['vid'] = array(
|
||||
'#title' => t('Vocabulary'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(),
|
||||
'#description' => t('Select the vocabulary for this form. If there exists a parent term in that vocabulary, this access check will succeed.'),
|
||||
'#id' => 'ctools-select-vid',
|
||||
'#default_value' => $conf['vid'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$options = array();
|
||||
|
||||
// Loop over each of the configured vocabularies.
|
||||
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
|
||||
$options[$vid] = $vocabulary->name;
|
||||
}
|
||||
$form['settings']['vid']['#options'] = $options;
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_term_parent_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) || empty($context->data->tid)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get the $vid.
|
||||
if (!isset($conf['vid'])) {
|
||||
return FALSE;
|
||||
}
|
||||
$vid = $conf['vid'];
|
||||
|
||||
$count = db_query('SELECT COUNT(*) FROM {taxonomy_term_hierarchy} th INNER JOIN {taxonomy_term_data} td ON th.parent = td.tid WHERE th.tid = :tid AND td.vid = :vid', array(':tid' => $context->data->tid, ':vid' => $vid))->fetchField();
|
||||
|
||||
return $count ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked terms.
|
||||
*/
|
||||
function ctools_term_parent_ctools_access_summary($conf, $context) {
|
||||
$vocab = taxonomy_vocabulary_load($conf['vid']);
|
||||
|
||||
return t('"@term" has parent in vocabulary "@vocab"', array('@term' => $context->identifier, '@vocab' => $vocab->name));
|
||||
}
|
87
sites/all/modules/ctools/plugins/access/term_vocabulary.inc
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon term vocabulary
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy: vocabulary"),
|
||||
'description' => t('Control access by vocabulary.'),
|
||||
'callback' => 'ctools_term_vocabulary_ctools_access_check',
|
||||
'default' => array('vids' => 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')),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by term_vocabulary' access plugin
|
||||
*/
|
||||
function ctools_term_vocabulary_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$options = array();
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
$options[$voc->vid] = check_plain($voc->name);
|
||||
}
|
||||
|
||||
$form['settings']['vids'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Vocabularies'),
|
||||
'#options' => $options,
|
||||
'#description' => t('Only the checked vocabularies will be valid.'),
|
||||
'#default_value' => $conf['vids'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
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)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (array_filter($conf['vids']) && empty($conf['vids'][$context->data->vid])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked term_vocabularys.
|
||||
*/
|
||||
function ctools_term_vocabulary_ctools_access_summary($conf, $context) {
|
||||
if (!isset($conf['type'])) {
|
||||
$conf['type'] = array();
|
||||
}
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
|
||||
$names = array();
|
||||
foreach (array_filter($conf['vids']) as $vid) {
|
||||
$names[] = check_plain($vocabularies[$vid]->name);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
70
sites/all/modules/ctools/plugins/access/theme.inc
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based on user themeission strings.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Current theme"),
|
||||
'description' => t('Control access by checking which theme is in use.'),
|
||||
'callback' => 'ctools_theme_ctools_access_check',
|
||||
'default' => array('theme' => variable_get('theme_default', 'garland')),
|
||||
'settings form' => 'ctools_theme_ctools_access_settings',
|
||||
'summary' => 'ctools_theme_ctools_access_summary',
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by theme' access plugin
|
||||
*/
|
||||
function ctools_theme_ctools_access_settings($form, &$form_state, $conf) {
|
||||
$themes = array();
|
||||
foreach (list_themes() as $key => $theme) {
|
||||
$themes[$key] = $theme->info['name'];
|
||||
}
|
||||
|
||||
$form['settings']['theme'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $themes,
|
||||
'#title' => t('Themes'),
|
||||
'#default_value' => $conf['theme'],
|
||||
'#description' => t('This will only be accessed if the current theme is the selected theme.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_theme_ctools_access_check($conf, $context) {
|
||||
if (!empty($GLOBALS['theme'])) {
|
||||
$theme = $GLOBALS['theme'];
|
||||
}
|
||||
else if (!empty($GLOBALS['custom_theme'])) {
|
||||
$theme = $GLOBALS['custom_theme'];
|
||||
}
|
||||
else if (!empty($GLOBALS['user']->theme)) {
|
||||
$theme = $GLOBALS['user']->theme;
|
||||
}
|
||||
else {
|
||||
$theme = variable_get('theme_default', 'garland');
|
||||
}
|
||||
|
||||
return $conf['theme'] == $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked roles.
|
||||
*/
|
||||
function ctools_theme_ctools_access_summary($conf, $context) {
|
||||
if (!isset($conf['theme'])) {
|
||||
return t('Error, unset theme');
|
||||
}
|
||||
$themes = list_themes();
|
||||
|
||||
return t('Current theme is "@theme"', array('@theme' => $themes[$conf['theme']]->info['name']));
|
||||
}
|
70
sites/all/modules/ctools/plugins/arguments/entity_id.inc
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for all entity ids
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Entity: ID"),
|
||||
'description' => t('Creates an entity context from an entity ID argument.'),
|
||||
'context' => 'ctools_argument_entity_id_context',
|
||||
'get child' => 'ctools_argument_entity_id_get_child',
|
||||
'get children' => 'ctools_argument_entity_id_get_children',
|
||||
);
|
||||
|
||||
function ctools_argument_entity_id_get_child($plugin, $parent, $child) {
|
||||
$plugins = ctools_argument_entity_id_get_children($plugin, $parent);
|
||||
return $plugins[$parent . ':' . $child];
|
||||
}
|
||||
|
||||
function ctools_argument_entity_id_get_children($original_plugin, $parent) {
|
||||
$entities = entity_get_info();
|
||||
$plugins = array();
|
||||
foreach ($entities as $entity_type => $entity) {
|
||||
$plugin = $original_plugin;
|
||||
$plugin['title'] = t('@entity: ID', array('@entity' => $entity['label']));
|
||||
$plugin['keyword'] = $entity_type;
|
||||
$plugin['description'] = t('Creates @entity context from an ID argument.', array('@entity' => $entity_type));
|
||||
$plugin['name'] = $parent . ':' . $entity_type;
|
||||
$plugin_id = $parent . ':' . $entity_type;
|
||||
drupal_alter('ctools_entity_context', $plugin, $entity, $plugin_id);
|
||||
$plugins[$plugin_id] = $plugin;
|
||||
}
|
||||
drupal_alter('ctools_entity_contexts', $plugins);
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the entity we crave.
|
||||
*/
|
||||
function ctools_argument_entity_id_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
$entity_type = explode(':', $conf['name']);
|
||||
$entity_type = $entity_type[1];
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('entity:' . $entity_type);
|
||||
}
|
||||
|
||||
// We can accept either an entity object or a pure id.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('entity:' . $entity_type, $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$entity = entity_load($entity_type, array($arg));
|
||||
if (!$entity) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ctools_context_create('entity:' . $entity_type, $entity[$arg]);
|
||||
}
|
||||
|
50
sites/all/modules/ctools/plugins/arguments/nid.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a node id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node: ID"),
|
||||
'keyword' => 'node',
|
||||
'description' => t('Creates a node context from a node ID argument.'),
|
||||
'context' => 'ctools_argument_nid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the node ID of a node for this argument'),
|
||||
),
|
||||
'no ui' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_argument_nid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('node');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('node', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$node = node_load($arg);
|
||||
if (!$node) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ctools_context_create('node', $node);
|
||||
}
|
||||
|
32
sites/all/modules/ctools/plugins/arguments/node_add.inc
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Node add form
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node add form: node type"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'node_type',
|
||||
'description' => t('Creates a node add form context from a node type argument.'),
|
||||
'context' => 'ctools_node_add_context',
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_node_add_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if (!isset($arg)) {
|
||||
return ctools_context_create_empty('node_add_form');
|
||||
}
|
||||
|
||||
return ctools_context_create('node_add_form', $arg);
|
||||
}
|
||||
|
51
sites/all/modules/ctools/plugins/arguments/node_edit.inc
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Node edit form
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Node edit form: node ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'node',
|
||||
'description' => t('Creates a node edit form context from a node ID argument.'),
|
||||
'context' => 'ctools_node_edit_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the node ID of a node for this argument'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_node_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('node_edit_form');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('node_edit_form', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$node = node_load($arg);
|
||||
if (!$node) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This will perform a node_access check, so we don't have to.
|
||||
return ctools_context_create('node_edit_form', $node);
|
||||
}
|
||||
|
50
sites/all/modules/ctools/plugins/arguments/rid.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a node revision id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Revision: ID"),
|
||||
'keyword' => 'revision',
|
||||
'description' => t('Creates a node context from a revision ID argument.'),
|
||||
'context' => 'ctools_argument_rid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the revision ID of a node for this argument'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the node we crave.
|
||||
*/
|
||||
function ctools_argument_rid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('node');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('node', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$nid = db_query('SELECT nid FROM {node_revisions} WHERE vid = :vid', array(':vid' => $arg))->fetchField();
|
||||
$node = node_load($nid, $arg);
|
||||
if (!$node) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ctools_context_create('node', $node);
|
||||
}
|
||||
|
64
sites/all/modules/ctools/plugins/arguments/string.inc
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a raw string
|
||||
*/
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("String"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'string',
|
||||
'description' => t('A string is a minimal context that simply holds a string that can be used for some other purpose.'),
|
||||
'settings form' => 'ctools_string_settings_form',
|
||||
'context' => 'ctools_string_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a value for this argument'),
|
||||
),
|
||||
'path placeholder' => 'ctools_string_path_placeholder', // This is in pagemanager.
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_string_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('string');
|
||||
}
|
||||
|
||||
$context = ctools_context_create('string', $arg);
|
||||
$context->original_argument = $arg;
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the argument
|
||||
*/
|
||||
function ctools_string_settings_form(&$form, &$form_state, $conf) {
|
||||
$form['settings']['use_tail'] = array(
|
||||
'#title' => t('Get all arguments after this one'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['use_tail']),
|
||||
'#description' => t('If checked, this string will include all arguments. For example, if the path is "path/%" and the user visits "path/foo/bar", if this is not checked the string will be "foo". If it is checked the string will be "foo/bar".'),
|
||||
);
|
||||
// return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch the placeholder based upon user settings.
|
||||
*/
|
||||
function ctools_string_path_placeholder($argument) {
|
||||
if (empty($argument['settings']['use_tail'])) {
|
||||
return '%pm_arg';
|
||||
}
|
||||
else {
|
||||
return '%pm_arg_tail';
|
||||
}
|
||||
}
|
163
sites/all/modules/ctools/plugins/arguments/term.inc
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Taxonomy term
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy term: ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'term',
|
||||
'description' => t('Creates a single taxonomy term from a taxonomy ID or taxonomy term name.'),
|
||||
'context' => 'ctools_term_context',
|
||||
'default' => array('input_form' => 'tid', 'breadcrumb' => TRUE, 'transform' => FALSE),
|
||||
'settings form' => 'ctools_term_settings_form',
|
||||
'placeholder form' => 'ctools_term_ctools_argument_placeholder',
|
||||
'breadcrumb' => 'ctools_term_breadcrumb',
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('entity:taxonomy_term');
|
||||
}
|
||||
|
||||
if (is_object($arg)) {
|
||||
$term = $arg;
|
||||
}
|
||||
else {
|
||||
switch ($conf['input_form']) {
|
||||
case 'tid':
|
||||
default:
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
$term = taxonomy_term_load($arg);
|
||||
break;
|
||||
|
||||
case 'term':
|
||||
if (!empty($conf['transform'])) {
|
||||
$arg = strtr($arg, '-', ' ');
|
||||
}
|
||||
|
||||
$terms = taxonomy_get_term_by_name($arg);
|
||||
|
||||
$conf['vids'] = is_array($conf['vids']) ? array_filter($conf['vids']) : NULL;
|
||||
if ((count($terms) > 1) && isset($conf['vids'])) {
|
||||
foreach ($terms as $potential) {
|
||||
foreach ($conf['vids'] as $vid => $active) {
|
||||
if ($active && $potential->vid == $vid) {
|
||||
$term = $potential;
|
||||
// break out of the foreaches AND the case
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$term = array_shift($terms);
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($term)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$context = ctools_context_create('entity:taxonomy_term', $term);
|
||||
$context->original_argument = $arg;
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the argument
|
||||
*/
|
||||
function ctools_term_settings_form(&$form, &$form_state, $conf) {
|
||||
// @todo allow synonym use like Views does.
|
||||
$form['settings']['input_form'] = array(
|
||||
'#title' => t('Argument type'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array('tid' => t('Term ID'), 'term' => t('Term name')),
|
||||
'#default_value' => $conf['input_form'],
|
||||
'#prefix' => '<div class="clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
$options = array();
|
||||
foreach ($vocabularies as $vid => $vocab) {
|
||||
$options[$vid] = $vocab->name;
|
||||
}
|
||||
$form['settings']['vids'] = array(
|
||||
'#title' => t('Limit to these vocabularies'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#default_value' => !empty($conf['vids']) ? $conf['vids'] : array(),
|
||||
'#description' => t('If no vocabularies are checked, terms from all vocabularies will be accepted.'),
|
||||
);
|
||||
|
||||
$form['settings']['breadcrumb'] = array(
|
||||
'#title' => t('Inject hierarchy into breadcrumb trail'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['breadcrumb']),
|
||||
'#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
|
||||
);
|
||||
|
||||
$form['settings']['transform'] = array(
|
||||
'#title' => t('Transform dashes in URL to spaces in term name filter values'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['transform']),
|
||||
);
|
||||
// return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form fragment to get an argument to convert a placeholder for preview.
|
||||
*/
|
||||
function ctools_term_ctools_argument_placeholder($conf) {
|
||||
switch ($conf['input_form']) {
|
||||
case 'tid':
|
||||
default:
|
||||
return array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a taxonomy term ID.'),
|
||||
);
|
||||
case 'term':
|
||||
return array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a taxonomy term name.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the breadcrumb trail if necessary.
|
||||
*/
|
||||
function ctools_term_breadcrumb($conf, $context) {
|
||||
if (empty($conf['breadcrumb']) || empty($context->data) || empty($context->data->tid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$breadcrumb = array();
|
||||
$current = new stdClass();
|
||||
$current->tid = $context->data->tid;
|
||||
while ($parents = taxonomy_get_parents($current->tid)) {
|
||||
$current = array_shift($parents);
|
||||
$breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
|
||||
}
|
||||
|
||||
$breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
}
|
77
sites/all/modules/ctools/plugins/arguments/terms.inc
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Taxonomy term
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Taxonomy term (multiple): ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'term',
|
||||
'description' => t('Creates a group of taxonomy terms from a list of tids separated by a comma or a plus sign. In general the first term of the list will be used for panes.'),
|
||||
'context' => 'ctools_terms_context',
|
||||
'default' => array('breadcrumb' => TRUE),
|
||||
'settings form' => 'ctools_terms_settings_form',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a term ID or a list of term IDs separated by a + or a ,'),
|
||||
),
|
||||
'breadcrumb' => 'ctools_terms_breadcrumb',
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_terms_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('terms');
|
||||
}
|
||||
|
||||
$terms = ctools_break_phrase($arg);
|
||||
if (empty($terms->value) || !empty($terms->invalid_input)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$context = ctools_context_create('terms', $terms);
|
||||
$context->original_argument = $arg;
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the argument
|
||||
*/
|
||||
function ctools_terms_settings_form(&$form, &$form_state, $conf) {
|
||||
$form['settings']['breadcrumb'] = array(
|
||||
'#title' => t('Inject hierarchy of first term into breadcrumb trail'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['breadcrumb']),
|
||||
'#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
|
||||
);
|
||||
// return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the breadcrumb trail if necessary.
|
||||
*/
|
||||
function ctools_terms_breadcrumb($conf, $context) {
|
||||
if (empty($conf['breadcrumb'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current->tid = $context->tids[0];
|
||||
$breadcrumb = array();
|
||||
while ($parents = taxonomy_get_parents($current->tid)) {
|
||||
$current = array_shift($parents);
|
||||
$breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
|
||||
}
|
||||
|
||||
$breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
}
|
53
sites/all/modules/ctools/plugins/arguments/uid.inc
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a user id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User: ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'user',
|
||||
'description' => t('Creates a user context from a user ID argument.'),
|
||||
'context' => 'ctools_argument_uid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the user ID of a user for this argument'),
|
||||
),
|
||||
'default' => array('to_arg' => TRUE),
|
||||
'path placeholder' => '%pm_uid_arg', // This is in pagemanager.
|
||||
'path placeholder to_arg' => TRUE,
|
||||
'no ui' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the user we crave.
|
||||
*/
|
||||
function ctools_argument_uid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('user');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('user', $arg);
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$account = user_load($arg);
|
||||
if (!$account) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctools_context_create('user', $account);
|
||||
}
|
48
sites/all/modules/ctools/plugins/arguments/user_edit.inc
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a Taxonomy term
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User edit form: User ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'user',
|
||||
'description' => t('Creates a user edit form context from a user ID argument.'),
|
||||
'context' => 'ctools_user_edit_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the user ID for this argument.'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the term we crave.
|
||||
*/
|
||||
function ctools_user_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('user_edit_form');
|
||||
}
|
||||
if(is_object($arg)){
|
||||
return ctools_context_create('user_edit_form', $arg);
|
||||
}
|
||||
if (!is_numeric($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$account= user_load($arg);
|
||||
if (!$account) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This will perform a node_access check, so we don't have to.
|
||||
return ctools_context_create('user_edit_form', $account);
|
||||
return NULL;
|
||||
}
|
47
sites/all/modules/ctools/plugins/arguments/user_name.inc
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a username
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("User: name"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'user',
|
||||
'description' => t('Creates a user context from a user name.'),
|
||||
'context' => 'ctools_argument_user_name_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the username of a user for this argument'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the user we crave.
|
||||
*/
|
||||
function ctools_argument_user_name_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('user');
|
||||
}
|
||||
|
||||
// We can accept either a node object or a pure nid.
|
||||
if (is_object($arg)) {
|
||||
return ctools_context_create('user', $arg);
|
||||
}
|
||||
|
||||
$account = user_load_by_name($arg);
|
||||
if (!$account) {
|
||||
return NULL;
|
||||
}
|
||||
return ctools_context_create('user', $account);
|
||||
}
|
||||
|
||||
|
||||
|
46
sites/all/modules/ctools/plugins/arguments/vid.inc
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Plugin to provide an argument handler for a vocabulary id
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Vocabulary: ID"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'vocabulary',
|
||||
'description' => t('Creates a vocabulary context from a vocabulary ID argument.'),
|
||||
'context' => 'ctools_vid_context',
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter the vocabulary ID for this argument'),
|
||||
),
|
||||
'no ui' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Discover if this argument gives us the vocabulary we crave.
|
||||
*/
|
||||
function ctools_vid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If unset it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('entity:taxonomy_vocabulary');
|
||||
}
|
||||
|
||||
if (!is_numeric($arg)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$vocabulary = taxonomy_vocabulary_load($arg);
|
||||
if (!$vocabulary) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctools_context_create('vocabulary', $vocabulary);
|
||||
}
|
||||
|
39
sites/all/modules/ctools/plugins/cache/export_ui.inc
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* A caching mechanism for use with subsystems that use the export ui.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
// cache plugins are the rare plugin types that have no real UI but
|
||||
// we're providing a title just in case.
|
||||
'title' => t('Export UI wizard cache'),
|
||||
'cache get' => 'ctools_cache_export_ui_cache_get',
|
||||
'cache set' => 'ctools_cache_export_ui_cache_set',
|
||||
// Some operations use a 'finalize' but that really just means set
|
||||
// for us, since we're not using temporary storage for subsystems.
|
||||
'cache finalize' => 'ctools_cache_export_ui_cache_set',
|
||||
);
|
||||
|
||||
function ctools_cache_export_ui_cache_get($plugin_name, $key) {
|
||||
ctools_include('export-ui');
|
||||
$plugin = ctools_get_export_ui($plugin_name);
|
||||
$handler = ctools_export_ui_get_handler($plugin);
|
||||
if ($handler) {
|
||||
$item = $handler->edit_cache_get($key);
|
||||
if (!$item) {
|
||||
$item = ctools_export_crud_load($handler->plugin['schema'], $key);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
function ctools_cache_export_ui_cache_set($plugin_name, $key, $item) {
|
||||
ctools_include('export-ui');
|
||||
$plugin = ctools_get_export_ui($plugin_name);
|
||||
$handler = ctools_export_ui_get_handler($plugin);
|
||||
if ($handler) {
|
||||
return $handler->edit_cache_set_key($item, $key);
|
||||
}
|
||||
}
|
51
sites/all/modules/ctools/plugins/cache/simple.inc
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* A simple cache indirection mechanism that just uses the basic object cache.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
// cache plugins are the rare plugin types that have no real UI but
|
||||
// we're providing a title just in case.
|
||||
'title' => t('Simple'),
|
||||
'cache get' => 'ctools_cache_simple_cache_get',
|
||||
'cache set' => 'ctools_cache_simple_cache_set',
|
||||
'cache clear' => 'ctools_cache_simple_cache_clear',
|
||||
);
|
||||
|
||||
function ctools_cache_simple_cache_get($data, $key) {
|
||||
ctools_include('object-cache');
|
||||
|
||||
// Ensure that if there is somehow no data, we at least don't stomp on other
|
||||
// people's caches.
|
||||
if (empty($data)) {
|
||||
$data = 'simple_cache_plugin';
|
||||
}
|
||||
|
||||
return ctools_object_cache_get($data, $key);
|
||||
}
|
||||
|
||||
function ctools_cache_simple_cache_set($data, $key, $object) {
|
||||
ctools_include('object-cache');
|
||||
|
||||
// Ensure that if there is somehow no data, we at least don't stomp on other
|
||||
// people's caches.
|
||||
if (empty($data)) {
|
||||
$data = 'simple_cache_plugin';
|
||||
}
|
||||
|
||||
return ctools_object_cache_set($data, $key, $object);
|
||||
}
|
||||
|
||||
function ctools_cache_simple_cache_clear($data, $key) {
|
||||
ctools_include('object-cache');
|
||||
|
||||
// Ensure that if there is somehow no data, we at least don't stomp on other
|
||||
// people's caches.
|
||||
if (empty($data)) {
|
||||
$data = 'simple_cache_plugin';
|
||||
}
|
||||
|
||||
return ctools_object_cache_clear($data, $key);
|
||||
}
|
550
sites/all/modules/ctools/plugins/content_types/block/block.inc
Normal file
@@ -0,0 +1,550 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide Drupal blocks as content.
|
||||
*
|
||||
* Since blocks don't provide all of the features we do, we have to do a little
|
||||
* extra work, including providing icons and categories for core blocks. Blocks
|
||||
* from contrib modules get to provide their own stuff, or get relegated to
|
||||
* the old "Miscellaneous" category.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
// And this is just the administrative title.
|
||||
// All our callbacks are named according to the standard pattern and can be deduced.
|
||||
'title' => t('Block'),
|
||||
'content type' => 'ctools_block_content_type_content_type',
|
||||
);
|
||||
|
||||
/**
|
||||
* Return the block content types with the specified $subtype_id.
|
||||
*/
|
||||
function ctools_block_content_type_content_type($subtype_id) {
|
||||
list($module, $delta) = explode('-', $subtype_id, 2);
|
||||
$module_blocks = module_invoke($module, 'block_info');
|
||||
if (isset($module_blocks[$delta])) {
|
||||
return _ctools_block_content_type_content_type($module, $delta, $module_blocks[$delta]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all block content types available.
|
||||
*
|
||||
* Modules wanting to make special adjustments the way that CTools handles their blocks
|
||||
* can implement an extension to the hook_block() family, where the function name is
|
||||
* of the form "$module . '_ctools_block_info'".
|
||||
*/
|
||||
function ctools_block_content_type_content_types() {
|
||||
$types = array();
|
||||
foreach (module_implements('block_info') as $module) {
|
||||
$module_blocks = module_invoke($module, 'block_info');
|
||||
if ($module_blocks) {
|
||||
foreach ($module_blocks as $delta => $block) {
|
||||
$info = _ctools_block_content_type_content_type($module, $delta, $block);
|
||||
// this check means modules can remove their blocks; particularly useful
|
||||
// if they offer the block some other way (like we do for views)
|
||||
if ($info) {
|
||||
$types["$module-$delta"] = $info;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an info array for a specific block.
|
||||
*/
|
||||
function _ctools_block_content_type_content_type($module, $delta, $block) {
|
||||
// strip_tags used because it goes through check_plain and that
|
||||
// just looks bad.
|
||||
$info = array(
|
||||
'title' => strip_tags($block['info']),
|
||||
);
|
||||
|
||||
// Ask around for further information by invoking the hook_block() extension.
|
||||
$function = $module . '_ctools_block_info';
|
||||
if (!function_exists($function)) {
|
||||
$function = 'ctools_default_block_info';
|
||||
}
|
||||
$function($module, $delta, $info);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load block info from the database.
|
||||
*
|
||||
* This is copied from _block_load_blocks(). It doesn't use that
|
||||
* function because _block_load_blocks sorts by region, and it
|
||||
* doesn't cache its results anyway.
|
||||
*/
|
||||
function _ctools_block_load_blocks() {
|
||||
if (!module_exists('block')) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$blocks = &drupal_static(__FUNCTION__, NULL);
|
||||
if (!isset($blocks)) {
|
||||
global $theme_key;
|
||||
|
||||
$query = db_select('block', 'b');
|
||||
$result = $query
|
||||
->fields('b')
|
||||
->condition('b.theme', $theme_key)
|
||||
->orderBy('b.region')
|
||||
->orderBy('b.weight')
|
||||
->orderBy('b.module')
|
||||
->addTag('block_load')
|
||||
->addTag('translatable')
|
||||
->execute();
|
||||
|
||||
$block_info = $result->fetchAllAssoc('bid');
|
||||
// Allow modules to modify the block list.
|
||||
drupal_alter('block_list', $block_info);
|
||||
|
||||
$blocks = array();
|
||||
foreach ($block_info as $block) {
|
||||
$blocks["{$block->module}_{$block->delta}"] = $block;
|
||||
}
|
||||
}
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the stored info for a block.
|
||||
*
|
||||
* The primary reason to use this is so that modules which perform alters
|
||||
* can have their alters make it to the block.
|
||||
*/
|
||||
function _ctools_get_block_info($module, $delta) {
|
||||
$blocks = _ctools_block_load_blocks();
|
||||
|
||||
$key = $module . '_' . $delta;
|
||||
if (isset($blocks[$key])) {
|
||||
return $blocks[$key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output function for the 'block' content type. Outputs a block
|
||||
* based on the module and delta supplied in the configuration.
|
||||
*/
|
||||
function ctools_block_content_type_render($subtype, $conf) {
|
||||
list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
|
||||
|
||||
$info = _ctools_get_block_info($module, $delta);
|
||||
$block = module_invoke($module, 'block_view', $delta);
|
||||
|
||||
if (!empty($info)) {
|
||||
// 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);
|
||||
}
|
||||
$block = (object) $block;
|
||||
|
||||
if (empty($block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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 (module_exists('block') && user_access('administer blocks')) {
|
||||
$block->admin_links = array(
|
||||
array(
|
||||
'title' => t('Configure block'),
|
||||
'href' => "admin/structure/block/manage/$module/$delta/configure",
|
||||
'query' => drupal_get_destination(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty form so we can have the default override title.
|
||||
*/
|
||||
function ctools_block_content_type_edit_form($form, &$form_state) {
|
||||
// Does nothing!
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit function to fix the subtype for really old panel panes.
|
||||
*/
|
||||
function ctools_block_content_type_edit_form_submit($form, &$form_state) {
|
||||
if (empty($form_state['subtype']) && isset($form_state['pane'])) {
|
||||
$form_state['pane']->subtype = $form_state['conf']['module'] . '-' . $form_state['conf']['delta'];
|
||||
unset($form_state['conf']['module']);
|
||||
unset($form_state['conf']['delta']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for a block.
|
||||
*/
|
||||
//function ctools_block_content_type_edit_form($id, $parents, $conf) {
|
||||
// if (user_access('administer advanced pane settings')) {
|
||||
// $form['block_visibility'] = array(
|
||||
// '#type' => 'checkbox',
|
||||
// '#title' => t('Use block visibility settings (see block config)'),
|
||||
// '#default_value' => !empty($conf['block_visibility']),
|
||||
// '#description' => t('If checked, the block visibility settings for this block will apply to this block.'),
|
||||
// );
|
||||
// // Module-specific block configurations.
|
||||
// if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
|
||||
// // Specifically modify a couple of core block forms.
|
||||
// if ($module == 'block') {
|
||||
// unset($settings['submit']);
|
||||
// $settings['info']['#type'] = 'value';
|
||||
// $settings['info']['#value'] = $settings['info']['#default_value'];
|
||||
// }
|
||||
// ctools_admin_fix_block_tree($settings);
|
||||
// $form['block_settings'] = array(
|
||||
// '#type' => 'fieldset',
|
||||
// '#title' => t('Block settings'),
|
||||
// '#description' => t('Settings in this section are global and are for all blocks of this type, anywhere in the system.'),
|
||||
// '#tree' => FALSE,
|
||||
// );
|
||||
//
|
||||
//
|
||||
// $form['block_settings'] += $settings;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $form;
|
||||
//}
|
||||
|
||||
//function ctools_admin_submit_block(&$form_values) {
|
||||
// if (!empty($form_values['block_settings'])) {
|
||||
// module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values['block_settings']);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Because form api cannot collapse just part of a tree, and the block settings
|
||||
// * assume no tree, we have to collapse the tree ourselves.
|
||||
// */
|
||||
//function ctools_admin_fix_block_tree(&$form, $key = NULL) {
|
||||
// if ($key) {
|
||||
// if (!empty($form['#parents'])) {
|
||||
// $form['#parents'] = array_merge(array('configuration', 'block_settings'), $form['#parents']);
|
||||
// }
|
||||
// else if (empty($form['#tree'])) {
|
||||
// $form['#parents'] = array('configuration', 'block_settings', $key);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (isset($form['#type']) && $form['#type'] == 'textarea' && !empty($form['#rows']) && $form['#rows'] > 10) {
|
||||
// $form['#rows'] = 10;
|
||||
// }
|
||||
//
|
||||
// foreach (element_children($form) as $key) {
|
||||
// ctools_admin_fix_block_tree($form[$key], $key);
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* Returns the administrative title for a type.
|
||||
*/
|
||||
function ctools_block_content_type_admin_title($subtype, $conf) {
|
||||
list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
|
||||
$block = module_invoke($module, 'block_info');
|
||||
if (empty($block) || empty($block[$delta])) {
|
||||
return t('Deleted/missing block @module-@delta', array('@module' => $module, '@delta' => $delta));
|
||||
}
|
||||
|
||||
// The block description reported by hook_block() is plain text, but the title
|
||||
// reported by this hook should be HTML.
|
||||
$title = check_plain($block[$delta]['info']);
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output function for the 'block' content type. Outputs a block
|
||||
* based on the module and delta supplied in the configuration.
|
||||
*/
|
||||
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) && !empty($block->subject)) {
|
||||
$block->title = $block->subject;
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
|
||||
function _ctools_block_get_module_delta($subtype, $conf) {
|
||||
if (strpos($subtype, '-')) {
|
||||
return explode('-', $subtype, 2);
|
||||
}
|
||||
else {
|
||||
return array($conf['module'], $conf['delta']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide default icon and categories for blocks when modules don't do this
|
||||
* for us.
|
||||
*/
|
||||
function ctools_default_block_info($module, $delta, &$info) {
|
||||
$core_modules = array('aggregator', 'block', 'blog', 'blogapi', 'book', 'color', 'comment', 'contact', 'drupal', 'filter', 'forum', 'help', 'legacy', 'locale', 'menu', 'node', 'path', 'ping', 'poll', 'profile', 'search', 'statistics', 'taxonomy', 'throttle', 'tracker', 'upload', 'user', 'watchdog', 'system');
|
||||
|
||||
if (in_array($module, $core_modules)) {
|
||||
$info['icon'] = 'icon_core_block.png';
|
||||
$info['category'] = t('Miscellaneous');
|
||||
}
|
||||
else {
|
||||
$info['icon'] = 'icon_contrib_block.png';
|
||||
$info['category'] = t('Miscellaneous');
|
||||
}
|
||||
}
|
||||
|
||||
// These are all on behalf of modules that don't implement ctools but that
|
||||
// we care about.
|
||||
function menu_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_block_menu.png';
|
||||
$info['category'] = t('Menus');
|
||||
if ($delta == 'primary-links' || $delta == 'secondary-links') {
|
||||
$info['icon'] = 'icon_core_primarylinks.png';
|
||||
}
|
||||
}
|
||||
|
||||
function forum_ctools_block_info($module, $delta, &$info) {
|
||||
$info['category'] = t('Activity');
|
||||
switch ($delta) {
|
||||
case 'active':
|
||||
$info['icon'] = 'icon_core_activeforumtopics.png';
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
$info['icon'] = 'icon_core_newforumtopics.png';
|
||||
break;
|
||||
|
||||
default:
|
||||
// safety net
|
||||
ctools_default_block_info($module, $delta, $info);
|
||||
}
|
||||
}
|
||||
|
||||
function profile_ctools_block_info($module, $delta, &$info) {
|
||||
// Hide the author information block which isn't as rich as what we can
|
||||
// do with context.
|
||||
$info = NULL;
|
||||
}
|
||||
|
||||
function book_ctools_block_info($module, $delta, &$info) {
|
||||
// Hide the book navigation block which isn't as rich as what we can
|
||||
// do with context.
|
||||
$info = NULL;
|
||||
}
|
||||
|
||||
function blog_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_recentblogposts.png';
|
||||
$info['category'] = t('Activity');
|
||||
}
|
||||
|
||||
function poll_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_recentpoll.png';
|
||||
$info['category'] = t('Activity');
|
||||
}
|
||||
|
||||
function comment_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_recentcomments.png';
|
||||
$info['category'] = t('Activity');
|
||||
}
|
||||
|
||||
function search_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_searchform.png';
|
||||
$info['category'] = t('Widgets');
|
||||
}
|
||||
|
||||
function node_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_syndicate.png';
|
||||
$info['category'] = t('Widgets');
|
||||
}
|
||||
|
||||
function aggregator_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_syndicate.png';
|
||||
$info['category'] = t('Feeds');
|
||||
}
|
||||
|
||||
function block_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_block_empty.png';
|
||||
$info['category'] = t('Custom blocks');
|
||||
|
||||
// The title of custom blocks from the block module is stored in the
|
||||
// {block} table. Look for it in the default theme as a reasonable
|
||||
// default value for the title.
|
||||
$block_info_cache = drupal_static(__FUNCTION__);
|
||||
if (!isset($block_info_cache)) {
|
||||
$block_info_cache = db_select('block', 'b')
|
||||
->fields('b')
|
||||
->condition('b.module', 'block')
|
||||
->condition('b.theme', variable_get('theme_default', 'bartik'))
|
||||
->addTag('block_load')
|
||||
->addTag('translatable')
|
||||
->execute()
|
||||
->fetchAllAssoc('delta');
|
||||
}
|
||||
|
||||
if (isset($block_info_cache[$delta])) {
|
||||
$info['defaults'] = array(
|
||||
'override_title' => TRUE,
|
||||
'override_title_text' => $block_info_cache[$delta]->title,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function user_ctools_block_info($module, $delta, &$info) {
|
||||
$info['category'] = t('Activity');
|
||||
switch ($delta) {
|
||||
case 'login':
|
||||
$info['icon'] = 'icon_core_userlogin.png';
|
||||
$info['category'] = t('Widgets');
|
||||
// Provide a custom render callback, because the default login block
|
||||
// will not render on /user, /user/login, or any other URL beginning
|
||||
// /user (unless it's a user-specific page such as /user/123).
|
||||
$info['render callback'] = 'ctools_user_login_pane_render';
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
$info['icon'] = 'icon_core_whosnew.png';
|
||||
break;
|
||||
|
||||
case 'online':
|
||||
$info['icon'] = 'icon_core_whosonline.png';
|
||||
break;
|
||||
|
||||
default:
|
||||
// safety net
|
||||
ctools_default_block_info($module, $delta, $info);
|
||||
}
|
||||
}
|
||||
|
||||
function locale_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_languageswitcher.png';
|
||||
$info['category'] = t('Widgets');
|
||||
}
|
||||
|
||||
function statistics_ctools_block_info($module, $delta, &$info) {
|
||||
$info['icon'] = 'icon_core_popularcontent.png';
|
||||
$info['category'] = t('Activity');
|
||||
}
|
||||
|
||||
function system_ctools_block_info($module, $delta, &$info) {
|
||||
// Remove the main content fake block.
|
||||
if ($delta == 'main') {
|
||||
$info = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
$menus = array('main-menu', 'management', 'navigation', 'user-menu');
|
||||
|
||||
if (in_array($delta, $menus)) {
|
||||
$info['icon'] = 'icon_core_block_menu.png';
|
||||
$info['category'] = t('Menus');
|
||||
|
||||
if ($delta == 'navigation') {
|
||||
$info['icon'] = 'icon_core_navigation.png';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$info['icon'] = 'icon_core_drupal.png';
|
||||
if ($delta == 'help') {
|
||||
$info['category'] = t('Page elements');
|
||||
return;
|
||||
}
|
||||
|
||||
$info['category'] = t('Widgets');
|
||||
}
|
||||
|
||||
function ctools_user_login_pane_render($subtype, $conf, $panel_args, $contexts) {
|
||||
list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
|
||||
|
||||
// The login form is only visible to anonymous users.
|
||||
global $user;
|
||||
if ($user->uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
$info = new stdClass;
|
||||
$info->module = $module;
|
||||
$info->delta = $delta;
|
||||
|
||||
$block = array();
|
||||
$block['subject'] = t('User login');
|
||||
// Manually set the content (rather than invoking block_view) because the
|
||||
// block implementation won't render on certain URLs.
|
||||
$block['content'] = drupal_get_form('user_login_block');
|
||||
|
||||
// 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);
|
||||
$block = (object) $block;
|
||||
|
||||
if (empty($block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$block->module = $module;
|
||||
$block->delta = $delta;
|
||||
|
||||
// $block->title is not set for the blocks returned by block_block() (the
|
||||
// Block module adds the title in block_list() instead), so we look it up
|
||||
// manually, unless the title is overridden and does not use the %title
|
||||
// placeholder.
|
||||
if ($module == 'block') {
|
||||
$block->title = $info->title;
|
||||
}
|
||||
else if (isset($block->subject)) {
|
||||
$block->title = $block->subject;
|
||||
}
|
||||
else {
|
||||
$block->title = NULL;
|
||||
}
|
||||
|
||||
if (isset($block->subject)) {
|
||||
$block->title = $block->subject;
|
||||
}
|
||||
else {
|
||||
$block->title = NULL;
|
||||
}
|
||||
|
||||
if (user_access('administer blocks')) {
|
||||
$block->admin_links = array(
|
||||
array(
|
||||
'title' => t('Configure block'),
|
||||
'href' => "admin/structure/block/manage/$module/$delta/configure",
|
||||
'query' => drupal_get_destination(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
After Width: | Height: | Size: 574 B |
After Width: | Height: | Size: 450 B |
After Width: | Height: | Size: 552 B |
After Width: | Height: | Size: 460 B |
After Width: | Height: | Size: 603 B |
After Width: | Height: | Size: 606 B |
After Width: | Height: | Size: 568 B |
After Width: | Height: | Size: 450 B |
After Width: | Height: | Size: 552 B |
After Width: | Height: | Size: 626 B |
After Width: | Height: | Size: 601 B |
After Width: | Height: | Size: 818 B |
After Width: | Height: | Size: 604 B |
After Width: | Height: | Size: 460 B |
After Width: | Height: | Size: 604 B |
After Width: | Height: | Size: 892 B |
After Width: | Height: | Size: 681 B |
After Width: | Height: | Size: 662 B |
After Width: | Height: | Size: 608 B |
After Width: | Height: | Size: 717 B |
After Width: | Height: | Size: 803 B |
After Width: | Height: | Size: 601 B |
After Width: | Height: | Size: 732 B |
After Width: | Height: | Size: 744 B |
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Ctools content-type plugin to provide a comment-reply form (replying either
|
||||
* to a node or to another comment).
|
||||
*/
|
||||
|
||||
// Only provide the plugin in the comment module is enabled.
|
||||
if (module_exists('comment')) {
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'title' => t('Comment Reply Form'),
|
||||
'icon' => 'icon_comment.png',
|
||||
'description' => t('A form to add a new comment reply.'),
|
||||
'required context' => array(
|
||||
new ctools_context_required(t('Node'), 'node'),
|
||||
new ctools_context_optional(t('Comment'), 'comment'),
|
||||
),
|
||||
'category' => t('Comment'),
|
||||
'render callback' => 'ctools_comment_reply_form_content_type_render',
|
||||
'defaults' => array('anon_links' => false),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_comment_reply_form_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
|
||||
$comment = ($context[1]->identifier == 'No context') ? NULL : clone($context[1]->data);
|
||||
$block = new stdClass();
|
||||
$block->module = 'comments';
|
||||
if ($comment) $block->delta = $comment->cid;
|
||||
$block->title = t('Add comment');
|
||||
$node = $context[0]->data;
|
||||
|
||||
module_load_include('inc', 'comment', 'comment.pages');
|
||||
$block->content = comment_reply($node, ($comment ? $comment->cid : NULL));
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_comment_reply_form_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" comment form', array('@s' => $context[0]->identifier));
|
||||
}
|
||||
|
||||
function ctools_comment_reply_form_content_type_edit_form($form, &$form_state) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
function ctools_comment_reply_form_content_type_edit_form_submit($form, &$form_state) {
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('contact')) {
|
||||
/**
|
||||
* 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('Contact form'),
|
||||
'icon' => 'icon_contact.png',
|
||||
'description' => t('The site contact form that allows users to send a message to site administrators.'),
|
||||
'category' => t('Widgets'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_contact_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (!user_access('access site-wide contact form')) {
|
||||
return;
|
||||
}
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'contact';
|
||||
$block->delta = 'form';
|
||||
$block->title = t('Contact');
|
||||
|
||||
module_load_include('inc', 'contact', 'contact.pages');
|
||||
$block->content = drupal_get_form('contact_site_form');
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_contact_content_type_edit_form($form, &$form_state) {
|
||||
// Empty so that we can have title override.
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for contact form.
|
||||
*/
|
||||
function ctools_contact_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_contact_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('Contact form');
|
||||
}
|
After Width: | Height: | Size: 606 B |
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('contact')) {
|
||||
/**
|
||||
* 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 contact form'),
|
||||
'icon' => 'icon_contact.png',
|
||||
'description' => t('The site contact form that allows users to contact other users.'),
|
||||
'category' => t('User'),
|
||||
'required context' => new ctools_context_required(t('User'), 'user'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_user_contact_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_contact_personal_tab_access($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'contact';
|
||||
$block->delta = 'form';
|
||||
$block->title = t('Contact @name', array('@name' => $context->data->name));
|
||||
|
||||
module_load_include('inc', 'contact', 'contact.pages');
|
||||
$block->content = drupal_get_form('contact_personal_form', $context->data);
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_user_contact_content_type_edit_form($form, &$form_state) {
|
||||
// Empty so that we can have title override.
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for contact form.
|
||||
*/
|
||||
function ctools_user_contact_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_user_contact_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('User contact form');
|
||||
}
|
429
sites/all/modules/ctools/plugins/content_types/custom/custom.inc
Normal file
@@ -0,0 +1,429 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Custom content type.
|
||||
*
|
||||
* This content type is nothing more than a title and a body that is entered
|
||||
* by the user and run through standard filters. The information is stored
|
||||
* right in the config, so each custom content is unique.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t('Custom content'),
|
||||
'no title override' => TRUE,
|
||||
'defaults' => array('admin_title' => '', 'title' => '', 'body' => '', 'format' => filter_default_format(), 'substitute' => TRUE),
|
||||
'js' => array('misc/autocomplete.js', 'misc/textarea.js', 'misc/collapse.js'),
|
||||
// Make sure the edit form is only used for some subtypes.
|
||||
'edit form' => '',
|
||||
'add form' => '',
|
||||
'edit text' => t('Edit'),
|
||||
'all contexts' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Return the custom content types with the specified $subtype_id.
|
||||
*/
|
||||
function ctools_custom_content_type_content_type($subtype_id) {
|
||||
if ($subtype_id == 'custom') {
|
||||
return _ctools_default_content_type_content_type();
|
||||
}
|
||||
elseif (module_exists('ctools_custom_content')) {
|
||||
ctools_include('export');
|
||||
$content = ctools_export_crud_load('ctools_custom_content', $subtype_id);
|
||||
if ($content) {
|
||||
return _ctools_custom_content_type_content_type($content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all custom content types available.
|
||||
*/
|
||||
function ctools_custom_content_type_content_types() {
|
||||
ctools_include('export');
|
||||
$types = array();
|
||||
$types['custom'] = _ctools_default_content_type_content_type();
|
||||
|
||||
if (module_exists('ctools_custom_content')) {
|
||||
foreach (ctools_export_crud_load_all('ctools_custom_content') as $name => $content) {
|
||||
$types[$name] = _ctools_custom_content_type_content_type($content);
|
||||
}
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for the default custom content type.
|
||||
*
|
||||
* The default is the one that allows the user to actually create a type.
|
||||
*/
|
||||
function _ctools_default_content_type_content_type() {
|
||||
$info = array(
|
||||
'name' => 'custom',
|
||||
'title' => t('New custom content'),
|
||||
'top level' => TRUE,
|
||||
'category' => t('Custom'),
|
||||
'description' => t('Create a completely custom piece of HTML content.'),
|
||||
'edit form' => 'ctools_custom_content_type_edit_form',
|
||||
'all contexts' => TRUE,
|
||||
'check editable' => 'ctools_custom_content_type_editable',
|
||||
);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an info array for a specific custom content type.
|
||||
*/
|
||||
function _ctools_custom_content_type_content_type($content) {
|
||||
$info = array(
|
||||
'name' => $content->name,
|
||||
'title' => check_plain($content->admin_title),
|
||||
'description' => check_plain($content->admin_description),
|
||||
'category' => $content->category ? check_plain($content->category) : t('Miscellaneous'),
|
||||
'all contexts' => TRUE,
|
||||
'icon' => 'icon_block_custom.png',
|
||||
// Store this here to make it easy to access.
|
||||
'content' => $content,
|
||||
);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a subtype and a $conf, return the actual settings to use.
|
||||
*
|
||||
* The actual settings may be stored directly in the pane or this may
|
||||
* be a pointer to re-usable content that may be in the database or in
|
||||
* an export. We have to determine from the subtype whether or not it
|
||||
* is local or shared custom content.
|
||||
*/
|
||||
function ctools_custom_content_type_get_conf($subtype, $conf) {
|
||||
if ($subtype['name'] != 'custom') {
|
||||
$settings = $subtype['content']->settings;
|
||||
$settings['custom_type'] = 'fixed';
|
||||
$settings['content'] = $subtype['content'];
|
||||
}
|
||||
else {
|
||||
// This means they created it as custom content and then set it as
|
||||
// reusable. Since we're not allowed to change the subtype, we're
|
||||
// still stored as though we are local, but are pointing off to
|
||||
// non-local.
|
||||
if (!empty($conf['name']) && module_exists('ctools_custom_content')) {
|
||||
ctools_include('export');
|
||||
$content = ctools_export_crud_load('ctools_custom_content', $conf['name']);
|
||||
if ($content) {
|
||||
$settings = $content->settings;
|
||||
$settings['custom_type'] = 'fixed';
|
||||
$settings['content'] = $content;
|
||||
$settings['admin_title'] = $content->admin_title;
|
||||
}
|
||||
else {
|
||||
$content = ctools_export_crud_new('ctools_custom_content');
|
||||
$content->name = $conf['name'];
|
||||
$settings = array(
|
||||
'admin_title' => t('Missing/deleted content'),
|
||||
'title' => '',
|
||||
'body' => '',
|
||||
'format' => filter_default_format(),
|
||||
'substitute' => TRUE,
|
||||
'custom_type' => 'fixed',
|
||||
'content' => $content,
|
||||
);
|
||||
}
|
||||
}
|
||||
// This means that it is created as custom and has not been set to
|
||||
// reusable.
|
||||
else {
|
||||
$settings = $conf;
|
||||
$settings['custom_type'] = 'local';
|
||||
}
|
||||
}
|
||||
|
||||
// Correct for an error that came in because filter format changed.
|
||||
if (is_array($settings['body'])) {
|
||||
$settings['format'] = $settings['body']['format'];
|
||||
$settings['body'] = $settings['body']['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
function ctools_custom_content_type_editable($content_type, $subtype, $conf) {
|
||||
if ($subtype['name'] == 'custom' && !empty($conf['name'])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output function for the 'custom' content type. Outputs a custom
|
||||
* based on the module and delta supplied in the configuration.
|
||||
*/
|
||||
function ctools_custom_content_type_render($subtype, $conf, $args, $contexts) {
|
||||
$settings = ctools_custom_content_type_get_conf(ctools_custom_content_type_content_type($subtype), $conf);
|
||||
|
||||
static $delta = 0;
|
||||
|
||||
$block = new stdClass();
|
||||
$block->subtype = ++$delta;
|
||||
$block->title = filter_xss_admin($settings['title']);
|
||||
|
||||
// Add keyword substitutions if we were configured to do so.
|
||||
$content = $settings['body'];
|
||||
if (!empty($contexts) && !empty($settings['substitute'])) {
|
||||
$content = ctools_context_keyword_substitute($content, array(), $contexts);
|
||||
}
|
||||
|
||||
$block->content = check_markup($content, $settings['format']);
|
||||
if ($settings['custom_type'] == 'fixed' && user_access('administer custom content')) {
|
||||
$block->admin_links = array(
|
||||
array(
|
||||
'title' => t('Configure content pane'),
|
||||
'alt' => t("Configure this pane in administer >> structure >> custom content panes"),
|
||||
'href' => 'admin/structure/ctools-content/list/' . $settings['content']->name . '/edit',
|
||||
'query' => drupal_get_destination(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to provide the administrative title of the custom content.
|
||||
*/
|
||||
function ctools_custom_content_type_admin_title($subtype, $conf) {
|
||||
$settings = ctools_custom_content_type_get_conf(ctools_custom_content_type_content_type($subtype), $conf);
|
||||
|
||||
$output = t('Custom');
|
||||
$title = !empty($settings['admin_title']) ? $settings['admin_title'] : $settings['title'];
|
||||
if ($title) {
|
||||
if ($settings['custom_type'] != 'fixed') {
|
||||
$output = t('Custom: @title', array('@title' => $title));
|
||||
}
|
||||
else {
|
||||
$output = $title;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to provide administrative info. In this case we'll render the
|
||||
* content as long as it's not PHP, which is too risky to render here.
|
||||
*/
|
||||
function ctools_custom_content_type_admin_info($subtype, $conf) {
|
||||
$settings = ctools_custom_content_type_get_conf(ctools_custom_content_type_content_type($subtype), $conf);
|
||||
|
||||
$block = new stdClass();
|
||||
$block->title = filter_xss_admin($settings['title']);
|
||||
// We don't want to render php output on preview here, because if something is
|
||||
// wrong the whole display will be borked. So we check to see if the php
|
||||
// evaluator filter is being used, and make a temporary change to the filter
|
||||
// so that we get the printed php, not the eval'ed php.
|
||||
$php_filter = FALSE;
|
||||
foreach (filter_list_format($settings['format']) as $filter) {
|
||||
if ($filter->module == 'php') {
|
||||
$php_filter = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If a php filter is active, just print the source, but only if the current
|
||||
// user has access to the actual filter.
|
||||
if ($php_filter) {
|
||||
$filter = filter_format_load($settings['format']);
|
||||
if (!filter_access($filter)) {
|
||||
return NULL;
|
||||
}
|
||||
$block->content = '<pre>' . check_plain($settings['body']) . '</pre>';
|
||||
}
|
||||
else {
|
||||
// We also need to filter through XSS admin because <script> tags can
|
||||
// cause javascript which will interfere with our ajax.
|
||||
$block->content = filter_xss_admin(check_markup($settings['body'], $settings['format']));
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for the custom type.
|
||||
*/
|
||||
function ctools_custom_content_type_edit_form($form, &$form_state) {
|
||||
$settings = ctools_custom_content_type_get_conf($form_state['subtype'], $form_state['conf']);
|
||||
$form_state['settings'] = $settings;
|
||||
|
||||
if ($settings['custom_type'] == 'fixed') {
|
||||
return $form; // no form for this case.
|
||||
}
|
||||
|
||||
$form['admin_title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => isset($settings['admin_title']) ? $settings['admin_title'] : '',
|
||||
'#title' => t('Administrative title'),
|
||||
'#description' => t('This title will be used administratively to identify this pane. If blank, the regular title will be used.'),
|
||||
);
|
||||
|
||||
$form['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $settings['title'],
|
||||
'#title' => t('Title'),
|
||||
);
|
||||
|
||||
$form['body'] = array(
|
||||
'#type' => 'text_format',
|
||||
'#title' => t('Body'),
|
||||
'#default_value' => $settings['body'],
|
||||
'#format' => $settings['format'],
|
||||
);
|
||||
|
||||
if (!empty($form_state['contexts'])) {
|
||||
// Set extended description if both CCK and Token modules are enabled, notifying of unlisted keywords
|
||||
if (module_exists('content') && module_exists('token')) {
|
||||
$description = t('If checked, context keywords will be substituted in this content. Note that CCK fields may be used as keywords using patterns like <em>%node:field_name-formatted</em>.');
|
||||
}
|
||||
elseif (!module_exists('token')) {
|
||||
$description = t('If checked, context keywords will be substituted in this content. More keywords will be available if you install the Token module, see http://drupal.org/project/token.');
|
||||
}
|
||||
else {
|
||||
$description = t('If checked, context keywords will be substituted in this content.');
|
||||
}
|
||||
|
||||
$form['substitute'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use context keywords'),
|
||||
'#description' => $description,
|
||||
'#default_value' => !empty($settings['substitute']),
|
||||
);
|
||||
$form['contexts'] = array(
|
||||
'#title' => t('Substitutions'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
|
||||
$rows = array();
|
||||
foreach ($form_state['contexts'] as $context) {
|
||||
foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
|
||||
$rows[] = array(
|
||||
check_plain($keyword),
|
||||
t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)),
|
||||
);
|
||||
}
|
||||
}
|
||||
$header = array(t('Keyword'), t('Value'));
|
||||
$form['contexts']['context'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $rows)));
|
||||
}
|
||||
|
||||
if (!user_access('administer custom content') || !module_exists('ctools_custom_content')) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Make the other form items dependent upon it.
|
||||
ctools_include('dependent');
|
||||
ctools_add_js('dependent');
|
||||
|
||||
$form['reusable'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make this content reusable'),
|
||||
'#default_value' => FALSE,
|
||||
);
|
||||
|
||||
$form['name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Machine name'),
|
||||
'#description' => t('The machine readable name of this content. It must be unique, and it must contain only alphanumeric characters and underscores. Once created, you will not be able to change this value!'),
|
||||
'#dependency' => array('edit-reusable' => array(1)),
|
||||
);
|
||||
|
||||
$form['category'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Category'),
|
||||
'#description' => t('What category this content should appear in. If left blank the category will be "Miscellaneous".'),
|
||||
'#dependency' => array('edit-reusable' => array(1)),
|
||||
);
|
||||
|
||||
$form['admin_description'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Administrative description'),
|
||||
'#description' => t('A description of what this content is, does or is for, for administrative use.'),
|
||||
'#dependency' => array('edit-reusable' => array(1)),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function _ctools_custom_content_type_edit_save(&$content, $form_state) {
|
||||
// Apply updates to the content object.
|
||||
$content->category = $form_state['values']['category'];
|
||||
$content->admin_title = $form_state['values']['admin_title'];
|
||||
$content->admin_description = $form_state['values']['admin_description'];
|
||||
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
||||
if (isset($form_state['values'][$key])) {
|
||||
$content->settings[$key] = $form_state['values'][$key];
|
||||
}
|
||||
}
|
||||
|
||||
ctools_export_crud_save('ctools_custom_content', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* The validate form to ensure the custom content data is okay.
|
||||
*/
|
||||
function ctools_custom_content_type_edit_form_validate(&$form, &$form_state) {
|
||||
if ($form_state['settings']['custom_type'] != 'fixed' && !empty($form_state['values']['reusable'])) {
|
||||
if (empty($form_state['values']['name'])) {
|
||||
form_error($form['name'], t('Name is required.'));
|
||||
}
|
||||
|
||||
// Check for string identifier sanity
|
||||
if (!preg_match('!^[a-z0-9_]+$!', $form_state['values']['name'])) {
|
||||
form_error($form['name'], t('The name can only consist of lowercase letters, underscores, and numbers.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!module_exists('ctools_custom_content')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for name collision
|
||||
if ($form_state['values']['name'] == 'custom' || (ctools_export_crud_load('ctools_custom_content', $form_state['values']['name']))) {
|
||||
form_error($form['name'], t('Content with this name already exists. Please choose another name or delete the existing item before creating a new one.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The submit form stores the data in $conf.
|
||||
*/
|
||||
function ctools_custom_content_type_edit_form_submit($form, &$form_state) {
|
||||
// Because of changes in filter form, these two keys are out of position:
|
||||
$form_state['values']['format'] = $form_state['values']['body']['format'];
|
||||
$form_state['values']['body'] = $form_state['values']['body']['value'];
|
||||
|
||||
if ($form_state['settings']['custom_type'] == 'fixed') {
|
||||
_ctools_custom_content_type_edit_save($form_state['settings']['content'], $form_state);
|
||||
}
|
||||
// If the 'reusable' checkbox was checked, we will create a new
|
||||
// custom content and give it the proper values.
|
||||
else if (!empty($form_state['values']['reusable'])) {
|
||||
$content = ctools_export_crud_new('ctools_custom_content');
|
||||
$content->name = $form_state['values']['name'];
|
||||
_ctools_custom_content_type_edit_save($content, $form_state);
|
||||
$form_state['conf']['name'] = $content->name;
|
||||
}
|
||||
else {
|
||||
// Otherwise, just save values into $conf normally.
|
||||
|
||||
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
||||
$form_state['conf'][$key] = isset($form_state['values'][$key]) ? $form_state['values'][$key] : $form_state['plugin']['defaults'][$key];
|
||||
}
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 522 B |
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handle rendering entity fields as panes.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t('Entity field'),
|
||||
'defaults' => array('label' => 'title', 'formatter' => '', 'delta_limit' => 0, 'delta_offset' => '0', 'delta_reversed' => FALSE),
|
||||
'content type' => 'ctools_entity_field_content_type_content_type',
|
||||
);
|
||||
|
||||
/**
|
||||
* Just one subtype.
|
||||
*
|
||||
* Ordinarily this function is meant to get just one subtype. However, we are
|
||||
* using it to deal with the fact that we have changed the subtype names. This
|
||||
* lets us translate the name properly.
|
||||
*/
|
||||
function ctools_entity_field_content_type_content_type($subtype) {
|
||||
$types = ctools_entity_field_content_type_content_types();
|
||||
if (isset($types[$subtype])) {
|
||||
return $types[$subtype];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all field content types available.
|
||||
*/
|
||||
function ctools_entity_field_content_type_content_types() {
|
||||
$types = &drupal_static(__FUNCTION__, array());
|
||||
if (!empty($types)) {
|
||||
return $types;
|
||||
}
|
||||
|
||||
// This will hold all the individual field content types.
|
||||
$context_types = array();
|
||||
$entities = entity_get_info();
|
||||
|
||||
foreach ($entities as $entity_type => $entity) {
|
||||
foreach ($entity['bundles'] as $type => $bundle) {
|
||||
foreach (field_info_instances($entity_type, $type) as $field_name => $field) {
|
||||
if (!isset($types[$entity_type . ':' . $field_name])) {
|
||||
$types[$entity_type . ':' . $field_name] = array(
|
||||
'category' => t(ucfirst($entity_type)),
|
||||
'icon' => 'icon_field.png',
|
||||
'title' => t('Field: @widget_label (@field_name)', array(
|
||||
'@widget_label' => t($field['label']),
|
||||
'@field_name' => $field_name,
|
||||
)),
|
||||
'description' => t('Field on the referenced entity.'),
|
||||
'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']),
|
||||
'@field_name' => $field_name,
|
||||
)),
|
||||
),
|
||||
'ctools_entity_field_content_type_formatter_styles' => t('Formatter Styles'),
|
||||
),
|
||||
);
|
||||
}
|
||||
$context_types[$entity_type . ':' . $field_name]['types'][$type] = $bundle['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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(
|
||||
'type' => array_keys($context_types[$key]['types']),
|
||||
));
|
||||
unset($context_types[$key]['types']);
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_entity_field_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a shortcut to the entity.
|
||||
$entity = $context->data;
|
||||
list($entity_type, $field_name) = explode(':', $subtype, 2);
|
||||
|
||||
// Load the entity type's information for this field.
|
||||
$ids = entity_extract_ids($entity_type, $entity);
|
||||
$field = field_info_instance($entity_type, $field_name, $ids[2]);
|
||||
|
||||
// Do not render if the entity type does not have this field.
|
||||
if (empty($field)) {
|
||||
return;
|
||||
}
|
||||
$language = field_language($entity_type, $entity, $field_name);
|
||||
|
||||
if (empty($conf['label']) || $conf['label'] == 'title') {
|
||||
$label = 'hidden';
|
||||
$conf['label'] = 'title';
|
||||
}
|
||||
else {
|
||||
$label = $conf['label'];
|
||||
}
|
||||
|
||||
$field_settings = array(
|
||||
'label' => $label,
|
||||
'type' => $conf['formatter'],
|
||||
);
|
||||
|
||||
// Get the field output, and the title.
|
||||
if (!empty($conf['formatter_settings'])) {
|
||||
$field_settings['settings'] = $conf['formatter_settings'];
|
||||
}
|
||||
|
||||
$all_values = field_get_items($entity_type, $entity, $field_name, $language);
|
||||
if (!is_array($all_values)) {
|
||||
$all_values = array();
|
||||
}
|
||||
|
||||
// Reverse values.
|
||||
if (isset($conf['delta_reversed']) && $conf['delta_reversed']) {
|
||||
$all_values = array_reverse($all_values);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$clone = clone $entity;
|
||||
$clone->{$field_name}[$language] = $all_values;
|
||||
$field_output = field_view_field($entity_type, $clone, $field_name, $field_settings, $language);
|
||||
|
||||
if (!empty($field_output) && !empty($conf['override_title'])) {
|
||||
$field_output['#title'] = filter_xss_admin($conf['override_title_text']);
|
||||
}
|
||||
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'entity_field';
|
||||
if ($conf['label'] == 'title' && isset($field_output['#title'])) {
|
||||
$block->title = $field_output['#title'];
|
||||
}
|
||||
|
||||
$block->content = $field_output;
|
||||
$block->delta = $ids[0];
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_entity_field_content_type_formatter_options($form, &$form_state) {
|
||||
if (empty($form_state['conf']['formatter_settings'])) {
|
||||
$form_state['conf']['formatter_settings'] = array();
|
||||
}
|
||||
$conf = $form_state['conf'];
|
||||
$subtype = $form_state['subtype_name'];
|
||||
list($entity_type, $field_name) = explode(':', $subtype, 2);
|
||||
|
||||
$field = field_info_field($field_name);
|
||||
module_load_include('inc', 'field_ui', 'field_ui.admin');
|
||||
$formatter_options = field_ui_formatter_options($field['type']);
|
||||
|
||||
$field_label_options = array(
|
||||
'title' => t('Pane title'),
|
||||
'above' => t('Above'),
|
||||
'inline' => t('Inline'),
|
||||
'hidden' => t('Hidden'),
|
||||
);
|
||||
|
||||
$form['label'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Label'),
|
||||
'#options' => $field_label_options,
|
||||
'#default_value' => $conf['label'],
|
||||
);
|
||||
|
||||
$form['formatter'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Select a formatter'),
|
||||
'#options' => $formatter_options,
|
||||
'#default_value' => $conf['formatter'],
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function ctools_entity_field_content_type_formatter_options_submit($form, &$form_state) {
|
||||
$form_state['conf']['formatter'] = $form_state['values']['formatter'];
|
||||
$form_state['conf']['label'] = $form_state['values']['label'];
|
||||
}
|
||||
|
||||
function ctools_entity_field_content_type_formatter_styles($form, &$form_state) {
|
||||
if (!$form_state['conf']['formatter_settings']) {
|
||||
$form_state['conf']['formatter_settings'] = array();
|
||||
}
|
||||
$conf = $form_state['conf'];
|
||||
$subtype = $form_state['subtype_name'];
|
||||
list($entity_type, $field_name) = explode(':', $subtype, 2);
|
||||
$field = field_info_field($field_name);
|
||||
|
||||
ctools_form_include($form_state, 'field_ui.admin', 'field_ui', '');
|
||||
ctools_form_include($form_state, 'fields');
|
||||
|
||||
$form['ctools_field_list'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => array(),
|
||||
);
|
||||
|
||||
ctools_fields_get_field_formatter_settings_form($field, $conf['formatter'], $form, $form_state);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function ctools_entity_field_content_type_formatter_styles_submit($form, &$form_state) {
|
||||
$fields = $form_state['values']['ctools_field_list'];
|
||||
$formatter_info = ctools_fields_get_field_formatter_info($fields);
|
||||
foreach ($formatter_info as $info) {
|
||||
if (!empty($info['settings'])) {
|
||||
foreach ($info['settings'] as $field_name => $value) {
|
||||
if (isset($form_state['values'][$field_name])) {
|
||||
$form_state['conf']['formatter_settings'][$field_name] = $form_state['values'][$field_name];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($form_state['values']['delta_limit'])) {
|
||||
$form_state['conf']['delta_limit'] = $form_state['values']['delta_limit'];
|
||||
$form_state['conf']['delta_offset'] = $form_state['values']['delta_offset'];
|
||||
$form_state['conf']['delta_reversed'] = $form_state['values']['delta_reversed'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)));
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
$plugin = array(
|
||||
'title' => t('Entity extra field'),
|
||||
'defaults' => array('view_mode' => NULL),
|
||||
'content type' => 'ctools_entity_field_extra_content_type_content_type',
|
||||
);
|
||||
|
||||
/**
|
||||
* Just one subtype.
|
||||
*
|
||||
* Ordinarily this function is meant to get just one subtype. However, we are
|
||||
* using it to deal with the fact that we have changed the subtype names. This
|
||||
* lets us translate the name properly.
|
||||
*/
|
||||
function ctools_entity_field_extra_content_type_content_type($subtype) {
|
||||
$types = ctools_entity_field_extra_content_type_content_types();
|
||||
if (isset($types[$subtype])) {
|
||||
return $types[$subtype];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all extra field content types available.
|
||||
*/
|
||||
function ctools_entity_field_extra_content_type_content_types() {
|
||||
// This will hold all the individual field content types.
|
||||
$types = array();
|
||||
$context_types = array();
|
||||
$entities = entity_get_info();
|
||||
|
||||
foreach ($entities as $entity_type => $entity) {
|
||||
foreach ($entity['bundles'] as $type => $bundle) {
|
||||
foreach (field_info_extra_fields($entity_type, $type, 'display') as $field_name => $info) {
|
||||
if (!isset($types[$entity_type . ':' . $field_name])) {
|
||||
$types[$entity_type . ':' . $field_name] = array(
|
||||
'category' => t(ucfirst($entity_type)),
|
||||
'icon' => 'icon_field.png',
|
||||
'title' => $info['label'],
|
||||
'description' => isset($info['description']) ? $info['description'] : '',
|
||||
);
|
||||
}
|
||||
$context_types[$entity_type . ':' . $field_name]['types'][$type] = $bundle['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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(
|
||||
'type' => array_keys($context_types[$key]['types']),
|
||||
));
|
||||
unset($context_types[$key]['types']);
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for an extra field.
|
||||
*/
|
||||
function ctools_entity_field_extra_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
$subtype = $form_state['subtype_name'];
|
||||
list($entity_type, $field_name) = explode(':', $subtype, 2);
|
||||
|
||||
$info = entity_get_info($entity_type);
|
||||
$view_mode_options = array();
|
||||
foreach ($info['view modes'] as $mode => $option) {
|
||||
$view_mode_options[$mode] = $option['label'];
|
||||
}
|
||||
|
||||
$form['view_mode'] = array(
|
||||
'#title' => t('View mode'),
|
||||
'#type' => 'select',
|
||||
'#description' => t('Select a view mode for this extra field.'),
|
||||
'#options' => $view_mode_options,
|
||||
'#default_value' => $conf['view_mode'],
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function ctools_entity_field_extra_content_type_edit_form_submit($form, &$form_state) {
|
||||
$form_state['conf']['view_mode'] = $form_state['values']['view_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the extra field.
|
||||
*/
|
||||
function ctools_entity_field_extra_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
// Get a shortcut to the entity.
|
||||
$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);
|
||||
|
||||
if (isset($entity->content[$field_name])) {
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'entity_field_extra';
|
||||
$block->content = $entity->content[$field_name];
|
||||
$block->delta = $id;
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
|
||||
function ctools_entity_field_extra_content_type_admin_title($subtype, $conf, $context) {
|
||||
$info = ctools_entity_field_extra_content_type_content_type($subtype);
|
||||
return t('"@s" @field', array('@s' => $context->identifier, '@field' => $info['title']));
|
||||
}
|
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handle rendering entity fields as panes.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t('Entity field'),
|
||||
'defaults' => array('label' => '', 'formatter' => ''),
|
||||
'content type' => 'ctools_entity_form_field_content_type_content_type',
|
||||
);
|
||||
|
||||
/**
|
||||
* Just one subtype.
|
||||
*
|
||||
* Ordinarily this function is meant to get just one subtype. However, we are
|
||||
* using it to deal with the fact that we have changed the subtype names. This
|
||||
* lets us translate the name properly.
|
||||
*/
|
||||
function ctools_entity_form_field_content_type_content_type($subtype) {
|
||||
$types = ctools_entity_form_field_content_type_content_types();
|
||||
if (isset($types[$subtype])) {
|
||||
return $types[$subtype];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all field content types available.
|
||||
*/
|
||||
function ctools_entity_form_field_content_type_content_types() {
|
||||
// This will hold all the individual field content types.
|
||||
$types = array();
|
||||
$content_types = array();
|
||||
$entities = entity_get_info();
|
||||
|
||||
foreach ($entities as $entity_type => $entity) {
|
||||
foreach ($entity['bundles'] as $type => $bundle) {
|
||||
foreach (field_info_instances($entity_type, $type) as $field_name => $field) {
|
||||
if (!isset($types[$entity_type . ':' . $field_name])) {
|
||||
$types[$entity_type . ':' . $field_name] = array(
|
||||
'category' => t('Form'),
|
||||
'icon' => 'icon_field.png',
|
||||
'title' => t('Field form: @widget_label', array(
|
||||
'@widget_label' => t($field['label']),
|
||||
)),
|
||||
'description' => t('Field on the referenced entity.'),
|
||||
);
|
||||
}
|
||||
$content_types[$entity_type . ':' . $field_name]['types'][$type] = $bundle['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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(
|
||||
'form' => array('form'),
|
||||
'type' => array_keys($content_types[$key]['types']),
|
||||
));
|
||||
unset($content_types[$key]['types']);
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_entity_form_field_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a shortcut to the entity.
|
||||
$entity = $context->data;
|
||||
list($entity_type, $field_name) = explode(':', $subtype, 2);
|
||||
|
||||
// Load the entity type's information for this field.
|
||||
$ids = entity_extract_ids($entity_type, $entity);
|
||||
$field = field_info_instance($entity_type, $field_name, $ids[2]);
|
||||
|
||||
// Do not render if the entity type does not have this field.
|
||||
if (empty($field)) {
|
||||
return;
|
||||
}
|
||||
$block = new stdClass();
|
||||
|
||||
if (isset($context->form)) {
|
||||
$block->content = array();
|
||||
$block->content[$field_name] = $context->form[$field_name];
|
||||
unset($context->form[$field_name]);
|
||||
}
|
||||
else {
|
||||
$block->content = t('Entity info.');
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the administrative title for a type.
|
||||
*/
|
||||
function ctools_entity_form_field_content_type_admin_title($subtype, $conf, $context) {
|
||||
list($entity_type, $field_name) = explode(':', $subtype, 2);
|
||||
|
||||
if (!empty($context->restrictions)) {
|
||||
$field = field_info_instance($entity_type, $field_name, $context->restrictions['type'][0]);
|
||||
}
|
||||
else {
|
||||
$field = array('label' => $subtype);
|
||||
}
|
||||
|
||||
return t('"@s" @field form', array('@s' => $context->identifier, '@field' => $field['label']));
|
||||
}
|
||||
|
||||
function ctools_entity_form_field_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
62
sites/all/modules/ctools/plugins/content_types/form/form.inc
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
// only provides a single content type
|
||||
'single' => TRUE,
|
||||
'render last' => TRUE,
|
||||
'title' => t('General form'),
|
||||
'icon' => 'icon_form.png',
|
||||
'description' => t('Everything in the form that is not displayed by other content.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Output function for the 'node' content type. Outputs a node
|
||||
* based on the module and delta supplied in the configuration.
|
||||
*/
|
||||
function ctools_form_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = 'form';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['#pre_render'])) {
|
||||
foreach ($context->form['#pre_render'] as $function) {
|
||||
if (function_exists($function)) {
|
||||
$context->form = $function($context->form);
|
||||
}
|
||||
}
|
||||
unset($context->form['#pre_render']);
|
||||
}
|
||||
|
||||
$block->title = $context->form_title;
|
||||
$block->content = array();
|
||||
foreach (element_children($context->form) as $element) {
|
||||
$block->content[$element] = $context->form[$element];
|
||||
unset($context->form[$element]);
|
||||
}
|
||||
|
||||
$block->delta = $context->form_id;
|
||||
}
|
||||
else {
|
||||
$block->title = t('Form');
|
||||
$block->content = t('Form goes here.');
|
||||
$block->delta = 'unknown';
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_form_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" base form', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_form_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to override title
|
||||
// and stuff.
|
||||
return $form;
|
||||
}
|
After Width: | Height: | Size: 460 B |
After Width: | Height: | Size: 460 B |
252
sites/all/modules/ctools/plugins/content_types/node/node.inc
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to handle the 'node' content type which allows individual nodes
|
||||
* to be embedded into a panel.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t('Node'),
|
||||
'single' => TRUE,
|
||||
'defaults' => array(
|
||||
'nid' => '',
|
||||
'links' => TRUE,
|
||||
'leave_node_title' => FALSE,
|
||||
'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'),
|
||||
'top level' => TRUE,
|
||||
'js' => array('misc/autocomplete.js'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Output function for the 'node' content type.
|
||||
*
|
||||
* Outputs a node based on the module and delta supplied in the configuration.
|
||||
*/
|
||||
function ctools_node_content_type_render($subtype, $conf, $panel_args) {
|
||||
$nid = $conf['nid'];
|
||||
$block = new stdClass();
|
||||
|
||||
foreach (explode('/', $_GET['q']) as $id => $arg) {
|
||||
$nid = str_replace("%$id", $arg, $nid);
|
||||
}
|
||||
|
||||
foreach ($panel_args as $id => $arg) {
|
||||
if (is_string($arg)) {
|
||||
$nid = str_replace("@$id", $arg, $nid);
|
||||
}
|
||||
}
|
||||
|
||||
// Support node translation
|
||||
if (module_exists('translation')) {
|
||||
if ($translations = module_invoke('translation', 'node_get_translations', $nid)) {
|
||||
if (isset($translations[$GLOBALS['language']->language])) {
|
||||
$nid = $translations[$GLOBALS['language']->language]->nid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_numeric($nid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$node = node_load($nid);
|
||||
if (!node_access('view', $node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't store viewed node data on the node, this can mess up other
|
||||
// views of the node.
|
||||
$node = clone($node);
|
||||
|
||||
$block->module = 'node';
|
||||
$block->delta = $node->nid;
|
||||
|
||||
// Set block->title to the plain node title, then additionally set block->title_link to
|
||||
// the node url if required. The actual link is rendered in ctools_content_render().
|
||||
$block->title = check_plain($node->title);
|
||||
if (!empty($conf['link_node_title'])) {
|
||||
$block->title_link = 'node/' . $node->nid;
|
||||
}
|
||||
|
||||
if (empty($conf['leave_node_title'])) {
|
||||
$node->title = NULL;
|
||||
}
|
||||
|
||||
if (!empty($conf['identifier'])) {
|
||||
$node->ctools_template_identifier = $conf['identifier'];
|
||||
}
|
||||
|
||||
// Handle existing configurations with the deprecated 'teaser' option.
|
||||
if (isset($conf['teaser'])) {
|
||||
$conf['build_mode'] = $conf['teaser'] ? 'teaser' : 'full';
|
||||
}
|
||||
|
||||
$block->content = node_view($node, $conf['build_mode']);
|
||||
|
||||
// Hide links if they've been suppressed.
|
||||
if (empty($conf['links'])) {
|
||||
$block->content['links']['#access'] = FALSE;
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* The form to add or edit a node as content.
|
||||
*/
|
||||
function ctools_node_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
|
||||
$form['leave_node_title'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['leave_node_title']),
|
||||
'#title' => t('Leave node title'),
|
||||
'#description' => t('Advanced: if checked, do not touch the node title; this can cause the node title to appear twice unless your theme is aware of this.'),
|
||||
);
|
||||
|
||||
$form['link_node_title'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['link_node_title']),
|
||||
'#title' => t('Link the node title to the node'),
|
||||
'#description' => t('Check this box if you would like your pane title to link to the node.'),
|
||||
);
|
||||
|
||||
|
||||
if ($form_state['op'] == 'add') {
|
||||
$form['nid'] = array(
|
||||
'#prefix' => '<div class="no-float">',
|
||||
'#title' => t('Enter the title or NID of a node'),
|
||||
'#description' => t('To use a NID from the URL, you may use %0, %1, ..., %N to get URL arguments. Or use @0, @1, @2, ..., @N to use arguments passed into the panel.'),
|
||||
'#type' => 'textfield',
|
||||
'#maxlength' => 512,
|
||||
'#autocomplete_path' => 'ctools/autocomplete/node',
|
||||
'#weight' => -10,
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['nid'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $conf['nid'],
|
||||
);
|
||||
}
|
||||
|
||||
$form['links'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['links'],
|
||||
'#title' => t('Include node links for "add comment", "read more" etc.'),
|
||||
);
|
||||
|
||||
$form['identifier'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => !empty($conf['identifier']) ? $conf['identifier'] : '',
|
||||
'#title' => t('Template identifier'),
|
||||
'#description' => t('This identifier will be added as a template suggestion to display this node: node--panel--IDENTIFIER.tpl.php. Please see the Drupal theming guide for information about template suggestions.'),
|
||||
);
|
||||
|
||||
$entity = entity_get_info('node');
|
||||
$build_mode_options = array();
|
||||
foreach ($entity['view modes'] as $mode => $option) {
|
||||
$build_mode_options[$mode] = $option['label'];
|
||||
}
|
||||
|
||||
// Handle existing configurations with the deprecated 'teaser' option.
|
||||
// Also remove the teaser key from the form_state.
|
||||
if (isset($conf['teaser']) || !isset($conf['build_mode'])) {
|
||||
unset($form_state['conf']['teaser']);
|
||||
$conf['build_mode'] = $conf['teaser'] ? 'teaser' : 'full';
|
||||
}
|
||||
$form['build_mode'] = array(
|
||||
'#title' => t('Build mode'),
|
||||
'#type' => 'select',
|
||||
'#description' => t('Select a build mode for this node.'),
|
||||
'#options' => $build_mode_options,
|
||||
'#default_value' => $conf['build_mode'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the node selection.
|
||||
*/
|
||||
function ctools_node_content_type_edit_form_validate(&$form, &$form_state) {
|
||||
if ($form_state['op'] != 'add') {
|
||||
return;
|
||||
}
|
||||
|
||||
$nid = $form_state['values']['nid'];
|
||||
$preg_matches = array();
|
||||
$match = preg_match('/\[id: (\d+)\]/', $nid, $preg_matches);
|
||||
if (!$match) {
|
||||
$match = preg_match('/^id: (\d+)/', $nid, $preg_matches);
|
||||
}
|
||||
|
||||
if ($match) {
|
||||
$nid = $preg_matches[1];
|
||||
}
|
||||
if (is_numeric($nid)) {
|
||||
$node = db_query('SELECT nid, status FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
|
||||
}
|
||||
else {
|
||||
$node = db_query('SELECT nid, status FROM {node} WHERE LOWER(title) = LOWER(:title)', array(':title' => $nid))->fetchObject();
|
||||
}
|
||||
if ($node) {
|
||||
$form_state['values']['nid'] = $node->nid;
|
||||
}
|
||||
|
||||
if (!($node || preg_match('/^[@%]\d+$/', $nid)) ||
|
||||
// Do not allow unpublished nodes to be selected by unprivileged users
|
||||
(empty($node->status) && !user_access('administer nodes'))) {
|
||||
form_error($form['nid'], t('Invalid node'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the node selection.
|
||||
*/
|
||||
function ctools_node_content_type_edit_form_submit($form, &$form_state) {
|
||||
foreach (array('nid', 'links', 'leave_node_title', 'link_node_title', 'identifier', 'build_mode') as $key) {
|
||||
$form_state['conf'][$key] = $form_state['values'][$key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the administrative title for a node.
|
||||
*/
|
||||
function ctools_node_content_type_admin_title($subtype, $conf) {
|
||||
if (!is_numeric($conf['nid'])) {
|
||||
return t('Node loaded from @var', array('@var' => $conf['nid']));
|
||||
}
|
||||
|
||||
$node = node_load($conf['nid']);
|
||||
if ($node) {
|
||||
if (!empty($node->status) || user_access('administer nodes')) {
|
||||
return check_plain($node->title);
|
||||
}
|
||||
else {
|
||||
return t('Unpublished node @nid', array('@nid' => $conf['nid']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return t('Deleted/missing node @nid', array('@nid' => $conf['nid']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the administrative information for a node pane.
|
||||
*/
|
||||
function ctools_node_content_type_admin_info($subtype, $conf) {
|
||||
// Just render the node.
|
||||
return ctools_node_content_type_render($subtype, $conf, array());
|
||||
}
|
After Width: | Height: | Size: 460 B |
@@ -0,0 +1,44 @@
|
||||
<?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('Attached files'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('A list of files attached to the node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
);
|
||||
|
||||
function ctools_node_attachments_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
$node = isset($context->data) ? clone($context->data) : NULL;
|
||||
$block = new stdClass();
|
||||
$block->module = 'attachments';
|
||||
|
||||
$block->title = t('Attached files');
|
||||
if ($node) {
|
||||
if (!empty($node->files)) {
|
||||
$block->content = theme('upload_attachments', $node->files);
|
||||
}
|
||||
$block->delta = $node->nid;
|
||||
}
|
||||
else {
|
||||
$block->content = t('Attached files go here.');
|
||||
$block->delta = 'unknown';
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_attachments_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" attachments', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_attachments_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
||||
|
@@ -0,0 +1,71 @@
|
||||
<?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('Node author'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The author of the referenced node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array(
|
||||
'link' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_node_author_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a shortcut to the node.
|
||||
$node = $context->data;
|
||||
$user = user_load($node->uid);
|
||||
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'node_author';
|
||||
$block->title = t('Author');
|
||||
$block->content = !empty($conf['link']) ? theme('username', array('account' => $user, 'link_path' => 'user/' . $node->uid)) : check_plain(format_username($node));
|
||||
$block->delta = $node->nid;
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_node_author_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
|
||||
$form['link'] = array(
|
||||
'#title' => t('Link to author profile'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['link'],
|
||||
'#description' => t('Check here to link to the node author profile.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the custom type settings form.
|
||||
*/
|
||||
function ctools_node_author_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_node_author_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" author', array('@s' => $context->identifier));
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?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('Node body'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The body of the referenced node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'no ui' => TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_node_body_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
$plugin = ctools_get_content_type('entity_field');
|
||||
$conf['formatter'] = 'text_default';
|
||||
$conf['formatter_settings'] = array();
|
||||
return $plugin['render callback']('node:body', $conf, $panel_args, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_node_body_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the administrative title for a type.
|
||||
*/
|
||||
function ctools_node_body_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" body', array('@s' => $context->identifier));
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('book')) {
|
||||
/**
|
||||
* 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('Book children'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The children menu the book the node belongs to.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_book_children_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
$node = isset($context->data) ? clone($context->data) : NULL;
|
||||
$block = new stdClass();
|
||||
$block->module = 'book_children';
|
||||
|
||||
$block->title = t('Book children');
|
||||
if ($node) {
|
||||
$block->content = isset($node->book) ? book_children($node->book) : '';
|
||||
$block->delta = $node->nid;
|
||||
}
|
||||
else {
|
||||
$block->content = t('Book children menu goes here.');
|
||||
$block->delta = 'unknown';
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_book_children_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" book children', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_book_children_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('book')) {
|
||||
/**
|
||||
* 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('Book navigation'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The navigation menu the book the node belongs to.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_book_nav_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
$node = isset($context->data) ? clone($context->data) : NULL;
|
||||
$block = new stdClass();
|
||||
$block->module = 'book_nav';
|
||||
|
||||
$block->title = t('Book navigation');
|
||||
if ($node) {
|
||||
$block->content = isset($node->book) ? theme('book_navigation', array('book_link' => $node->book)) : '';
|
||||
$block->delta = $node->nid;
|
||||
}
|
||||
else {
|
||||
$block->content = t('Book navigation goes here.');
|
||||
$block->delta = 'unknown';
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_book_nav_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" book navigation', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_book_nav_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
<?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('Comment form'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('A form to add a new comment.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array('anon_links' => FALSE),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_comment_form_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;
|
||||
|
||||
$block->title = t('Add comment');
|
||||
|
||||
if (empty($node)) {
|
||||
$block->content = t('Comment form here.');
|
||||
}
|
||||
else 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,
|
||||
),
|
||||
),
|
||||
);
|
||||
$block->content = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
|
||||
}
|
||||
else if (!empty($conf['anon_links'])) {
|
||||
$block->content = theme('comment_post_forbidden', array('node' => $node));
|
||||
}
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_comment_form_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" comment form', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_comment_form_content_type_edit_form($form, &$form_state) {
|
||||
$form['anon_links'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Shows links to register or login.'),
|
||||
'#description' => t('If anonymous comments are not allowed, this will display the register and login links.'),
|
||||
'#default_value' => $form_state['conf']['anon_links'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function ctools_node_comment_form_content_type_edit_form_submit($form, &$form_state) {
|
||||
// For each part of the form defined in the 'defaults' array set when you
|
||||
// defined the content type, copy the value from the form into the array
|
||||
// of items to be saved. We don't ever want to use
|
||||
// $form_state['conf'] = $form_state['values'] because values contains
|
||||
// buttons, form id and other items we don't want stored. CTools will handle
|
||||
// the actual form submission.
|
||||
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
||||
$form_state['conf'][$key] = $form_state['values'][$key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the comment form to get a little more control over it.
|
||||
*/
|
||||
function ctools_form_comment_form_alter(&$form, &$form_state) {
|
||||
if (!empty($form_state['ctools comment alter'])) {
|
||||
// Force the form to post back to wherever we are.
|
||||
$form['#action'] = url($_GET['q'], array('fragment' => 'comment-form'));
|
||||
if (empty($form['#submit'])) {
|
||||
$form['#submit'] = array('comment_form_submit');
|
||||
}
|
||||
$form['#submit'][] = 'ctools_node_comment_form_submit';
|
||||
}
|
||||
}
|
||||
|
||||
function ctools_node_comment_form_submit(&$form, &$form_state) {
|
||||
$form_state['redirect'][0] = $_GET['q'];
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
<?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('Node comments'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The comments of 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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_comments_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;
|
||||
|
||||
$block->title = t('Comments');
|
||||
if (empty($node)) {
|
||||
$block->content = t('Node comments go here.');
|
||||
}
|
||||
else if ($node->comment) {
|
||||
$block->content = ctools_comment_render($node, $conf);
|
||||
// Update the history table, stating that this user viewed this node.
|
||||
node_tag_new($node);
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_comments_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;
|
||||
}
|
||||
|
||||
function ctools_node_comments_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_node_comments_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" comments', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is a somewhat stripped down version of comment_render
|
||||
* that removes a bunch of cruft that we both don't need, and makes it
|
||||
* difficult to modify this.
|
||||
*/
|
||||
function ctools_comment_render($node, $conf) {
|
||||
$output = '';
|
||||
if (!user_access('access comments') || !$node->comment) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mode = $conf['mode'];
|
||||
$comments_per_page = $conf['comments_per_page'];
|
||||
|
||||
$cids = comment_get_thread($node, $mode, $comments_per_page);
|
||||
$comments = comment_load_multiple($cids);
|
||||
|
||||
if ($comments) {
|
||||
drupal_add_css(drupal_get_path('module', 'comment') . '/comment.css');
|
||||
comment_prepare_thread($comments);
|
||||
$build = comment_view_multiple($comments, $node);
|
||||
$build['pager']['#theme'] = 'pager';
|
||||
return drupal_render($build);
|
||||
}
|
||||
return;
|
||||
}
|
@@ -0,0 +1,204 @@
|
||||
<?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('Node content'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The content of the referenced node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array(
|
||||
'links' => TRUE,
|
||||
'no_extras' => TRUE,
|
||||
'override_title' => FALSE,
|
||||
'override_title_text' => '',
|
||||
'identifier' => '',
|
||||
'link' => TRUE,
|
||||
'leave_node_title' => FALSE,
|
||||
'build_mode' => 'teaser',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Render the node content.
|
||||
*/
|
||||
function ctools_node_content_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (!empty($context) && empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$node = isset($context->data) ? clone($context->data) : NULL;
|
||||
$block = new stdClass();
|
||||
$block->module = 'node';
|
||||
$block->delta = $node->nid;
|
||||
|
||||
if (empty($node)) {
|
||||
$block->delta = 'placeholder';
|
||||
$block->title = t('Node title.');
|
||||
$block->content = t('Node content goes here.');
|
||||
}
|
||||
else {
|
||||
if (!empty($conf['identifier'])) {
|
||||
$node->ctools_template_identifier = $conf['identifier'];
|
||||
}
|
||||
|
||||
$block->title = $node->title;
|
||||
if (empty($conf['leave_node_title'])) {
|
||||
$node->title = NULL;
|
||||
}
|
||||
$block->content = ctools_node_content_render_node($node, $conf);
|
||||
}
|
||||
|
||||
if (!empty($conf['link']) && $node) {
|
||||
$block->title_link = "node/$node->nid";
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_content_render_node($node, $conf) {
|
||||
if (empty($node->content)) {
|
||||
// Copied from node_build_content() so we can fiddle with it as we render.
|
||||
$node->content = array();
|
||||
|
||||
// The 'view' hook can be implemented to overwrite the default function
|
||||
// to display nodes.
|
||||
if (node_hook($node, 'view')) {
|
||||
$node = node_invoke($node, 'view', $conf['build_mode']);
|
||||
}
|
||||
|
||||
// Build fields content.
|
||||
// In case of a multiple view, node_view_multiple() already ran the
|
||||
// 'prepare_view' step. An internal flag prevents the operation from running
|
||||
// twice.
|
||||
field_attach_prepare_view('node', array($node->nid => $node), $conf['build_mode']);
|
||||
entity_prepare_view('node', array($node->nid => $node));
|
||||
$node->content += field_attach_view('node', $node, $conf['build_mode']);
|
||||
|
||||
// Always display a read more link on teasers because we have no way
|
||||
// to know when a teaser view is different than a full view.
|
||||
$links = array();
|
||||
if ($conf['build_mode'] == 'teaser') {
|
||||
$links['node-readmore'] = array(
|
||||
'title' => t('Read more'),
|
||||
'href' => 'node/' . $node->nid,
|
||||
'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title))
|
||||
);
|
||||
}
|
||||
|
||||
$node->content['links'] = array(
|
||||
'#theme' => 'links__node',
|
||||
'#links' => $links,
|
||||
'#attributes' => array('class' => array('links', 'inline')),
|
||||
);
|
||||
|
||||
if (empty($conf['no_extras'])) {
|
||||
// Allow modules to make their own additions to the node.
|
||||
$langcode = $GLOBALS['language_content']->language;
|
||||
module_invoke_all('node_view', $node, $conf['build_mode'], $langcode);
|
||||
module_invoke_all('entity_view', $node, 'node', $conf['build_mode'], $langcode);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the proper node part, then unset unused $node part so that a bad
|
||||
// theme can not open a security hole.
|
||||
$content = $node->content;
|
||||
|
||||
$content += array(
|
||||
'#theme' => 'node',
|
||||
'#node' => $node,
|
||||
'#view_mode' => $conf['build_mode'],
|
||||
'#language' => NULL,
|
||||
);
|
||||
|
||||
// Add contextual links for this node, except when the node is already being
|
||||
// displayed on its own page. Modules may alter this behavior (for example,
|
||||
// to restrict contextual links to certain view modes) by implementing
|
||||
// hook_node_view_alter().
|
||||
if (!empty($node->nid) && !($conf['build_mode'] == 'full' && node_is_page($node))) {
|
||||
$content['#contextual_links']['node'] = array('node', array($node->nid));
|
||||
}
|
||||
|
||||
// Allow modules to modify the structured node.
|
||||
$type = 'node';
|
||||
drupal_alter(array('node_view', 'entity_view'), $content, $type);
|
||||
|
||||
// Kill the links if not requested.
|
||||
if (!$conf['links']) {
|
||||
$content['links']['#access'] = FALSE;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for the custom type.
|
||||
*/
|
||||
function ctools_node_content_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
|
||||
$form['leave_node_title'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($conf['leave_node_title']),
|
||||
'#title' => t('Leave node title'),
|
||||
'#description' => t('Advanced: if checked, do not touch the node title; this can cause the node title to appear twice unless your theme is aware of this.'),
|
||||
);
|
||||
|
||||
$form['link'] = array(
|
||||
'#title' => t('Link title to node'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['link'],
|
||||
'#description' => t('Check here to make the title link to the node.'),
|
||||
);
|
||||
$form['links'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['links'],
|
||||
'#title' => t('Include node links for "add comment", "read more" etc.'),
|
||||
);
|
||||
|
||||
$form['no_extras'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['no_extras'],
|
||||
'#title' => t('No extras'),
|
||||
'#description' => t('Check here to disable additions that modules might make to the node, such as file attachments and CCK fields; this should just display the basic teaser or body.'),
|
||||
);
|
||||
|
||||
$form['identifier'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $conf['identifier'],
|
||||
'#title' => t('Template identifier'),
|
||||
'#description' => t('This identifier will be added as a template suggestion to display this node: node--panel--IDENTIFIER.tpl.php. Please see the Drupal theming guide for information about template suggestions.'),
|
||||
);
|
||||
|
||||
$entity = entity_get_info('node');
|
||||
$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 node.'),
|
||||
'#options' => $build_mode_options,
|
||||
'#default_value' => $conf['build_mode'],
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function ctools_node_content_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_node_content_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" content', array('@s' => $context->identifier));
|
||||
}
|
||||
|
@@ -0,0 +1,74 @@
|
||||
<?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('Node created date'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The date the referenced node was created.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array(
|
||||
'format' => 'small',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_node_created_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a shortcut to the node.
|
||||
$node = $context->data;
|
||||
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'node_created';
|
||||
$block->title = t('Created date');
|
||||
$block->content = format_date($node->created, $conf['format']);
|
||||
$block->delta = $node->nid;
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_node_created_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
$date_types = array();
|
||||
|
||||
foreach (system_get_date_types() as $date_type => $definition) {
|
||||
$date_types[$date_type] = format_date(REQUEST_TIME, $date_type);
|
||||
}
|
||||
$form['format'] = array(
|
||||
'#title' => t('Date format'),
|
||||
'#type' => 'select',
|
||||
'#options' => $date_types,
|
||||
'#default_value' => $conf['format'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the custom type settings form.
|
||||
*/
|
||||
function ctools_node_created_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_node_created_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" created date', array('@s' => $context->identifier));
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
<?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('Node links'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('Node links of the referenced node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array(
|
||||
'override_title' => FALSE,
|
||||
'override_title_text' => '',
|
||||
'build_mode' => '',
|
||||
'identifier' => '',
|
||||
'link' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Output function for the 'node' content type. Outputs a node
|
||||
* based on the module and delta supplied in the configuration.
|
||||
*/
|
||||
function ctools_node_links_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (!empty($context) && empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$node = isset($context->data) ? clone($context->data) : NULL;
|
||||
$block = new stdClass();
|
||||
$block->module = 'node';
|
||||
$block->delta = $node->nid;
|
||||
|
||||
if (empty($node)) {
|
||||
$block->delta = 'placeholder';
|
||||
$block->subject = t('Node title.');
|
||||
$block->content = t('Node links go here.');
|
||||
}
|
||||
else {
|
||||
if (!empty($conf['identifier'])) {
|
||||
$node->panel_identifier = $conf['identifier'];
|
||||
}
|
||||
|
||||
$block->subject = $node->title;
|
||||
node_build_content($node, $conf['build_mode']);
|
||||
$block->content = $node->content['links'];
|
||||
}
|
||||
|
||||
if (!empty($conf['link']) && $node) {
|
||||
$block->title_link = "node/$node->nid";
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for the custom type.
|
||||
*/
|
||||
function ctools_node_links_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
|
||||
$form['link'] = array(
|
||||
'#title' => t('Link title to node'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['link'],
|
||||
'#description' => t('Check here to make the title link to the node.'),
|
||||
);
|
||||
|
||||
$entity = entity_get_info('node');
|
||||
$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 node.'),
|
||||
'#options' => $build_mode_options,
|
||||
'#default_value' => $conf['build_mode'],
|
||||
);
|
||||
|
||||
$form['identifier'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $conf['identifier'],
|
||||
'#title' => t('Identifier'),
|
||||
'#description' => t('Whatever is placed here will appear in @identifier, to help theme node links displayed on the panel', array('@identifier' => $node->panel_identifier)),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function ctools_node_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_node_links_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" links', array('@s' => $context->identifier));
|
||||
}
|
||||
|
@@ -0,0 +1,205 @@
|
||||
<?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('Node terms'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('Taxonomy terms of the referenced node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array(
|
||||
'vid' => 0,
|
||||
'term_format' => 'term-links',
|
||||
'link' => TRUE,
|
||||
'term_delimiter' => ', ',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Render the node_terms content type.
|
||||
*/
|
||||
function ctools_node_terms_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a shortcut to the node.
|
||||
$node = $context->data;
|
||||
|
||||
// Load all terms for this node from all vocabularies
|
||||
$query = db_select('taxonomy_index', 't');
|
||||
$result = $query
|
||||
->fields('t')
|
||||
->condition('t.nid', $node->nid)
|
||||
->execute();
|
||||
|
||||
$tids = array();
|
||||
foreach ($result AS $term) {
|
||||
$tids[] = $term->tid;
|
||||
}
|
||||
|
||||
// Get the real term objects
|
||||
$term_objects = taxonomy_term_load_multiple($tids);
|
||||
|
||||
$terms = array();
|
||||
|
||||
if (empty($conf['vid'])) {
|
||||
// All terms.
|
||||
foreach ($term_objects AS $term) {
|
||||
$terms['taxonomy_term_' . $term->tid] = array(
|
||||
'title' => check_plain($term->name),
|
||||
'href' => 'taxonomy/term/' . $term->tid,
|
||||
'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// They want something special and custom, we'll have to do this ourselves.
|
||||
foreach ($term_objects as $term) {
|
||||
if ($term->vid == $conf['vid']) {
|
||||
if ($conf['term_format'] == 'term-links') {
|
||||
$terms['taxonomy_term_' . $term->tid] = array(
|
||||
'title' => $term->name,
|
||||
'href' => 'taxonomy/term/' . $term->tid,
|
||||
'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description)),
|
||||
);
|
||||
}
|
||||
elseif (empty($conf['link'])) {
|
||||
$terms[] = check_plain($term->name);
|
||||
}
|
||||
else {
|
||||
$terms[] = l($term->name, 'taxonomy/term/' . $term->tid, array('attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formatted_terms = '';
|
||||
switch ($conf['term_format']) {
|
||||
case 'term-links':
|
||||
drupal_alter('link', $terms, $node);
|
||||
$formatted_terms = theme('links', array('links' => $terms));
|
||||
break;
|
||||
|
||||
case 'ul':
|
||||
$formatted_terms = theme('item_list', array('items' => $terms));
|
||||
break;
|
||||
|
||||
case 'inline-delimited':
|
||||
$delimiter = isset($conf['term_delimiter']) ? $conf['term_delimiter'] : ', ';
|
||||
$processed_terms = array();
|
||||
foreach ($terms as $key => $term) {
|
||||
if (is_string($term)) {
|
||||
$processed_terms[$key] = $term;
|
||||
}
|
||||
else {
|
||||
$terms[$key] = l($term['title'], $term['href'], $term);
|
||||
}
|
||||
}
|
||||
|
||||
$formatted_terms = implode($delimiter, $processed_terms);
|
||||
break;
|
||||
}
|
||||
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'node_terms';
|
||||
$block->delta = $node->nid;
|
||||
$block->title = t('Terms');
|
||||
$block->content = $formatted_terms;
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for node terms display settings.
|
||||
*
|
||||
* The first question is if they want to display all terms or restrict it to a
|
||||
* specific taxonomy vocabulary.
|
||||
*
|
||||
* Then, they're presented with a set of radios to find out how they want the
|
||||
* terms formatted, which can be either be via theme('links'), a regular item
|
||||
* list (ul), or inline with a delimiter. Depending on which radio they
|
||||
* choose, some other settings might appear. If they're doing either the ul or
|
||||
* inline, we ask if they want the terms to appear as links or not. If they
|
||||
* want it inline, we ask what delimiter they want to use.
|
||||
*/
|
||||
function ctools_node_terms_content_type_edit_form($form, &$form_state) {
|
||||
ctools_include('dependent');
|
||||
|
||||
$conf = $form_state['conf'];
|
||||
|
||||
$options = array();
|
||||
$options[0] = t('- All vocabularies -');
|
||||
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
|
||||
$options[$vid] = $vocabulary->name;
|
||||
}
|
||||
$form['vid'] = array(
|
||||
'#title' => t('Vocabulary'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $conf['vid'],
|
||||
'#description' => t('Optionally restrict the terms to a specific vocabulary, or allow terms from all vocabularies.'),
|
||||
'#prefix' => '<div class="clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['term_format'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Term formatting'),
|
||||
'#options' => array(
|
||||
'term-links' => t("Taxonomy links (uses theme('links'))"),
|
||||
'ul' => t('Unordered list'),
|
||||
'inline-delimited' => t('Inline, delimited'),
|
||||
),
|
||||
'#default_value' => $conf['term_format'],
|
||||
'#prefix' => '<div class="clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['link'] = array(
|
||||
'#title' => t('Link to terms'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['link'],
|
||||
'#description' => t('Check here to make the terms link to the term paths.'),
|
||||
'#dependency' => array('radio:term_format' => array('inline-delimited', 'ul')),
|
||||
'#prefix' => '<div class="clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['term_delimiter'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Term delimiter'),
|
||||
'#default_value' => $conf['term_delimiter'],
|
||||
'#size' => 10,
|
||||
'#dependency' => array('radio:term_format' => array('inline-delimited')),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the custom type settings form.
|
||||
*/
|
||||
function ctools_node_terms_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_node_terms_content_type_admin_title($subtype, $conf, $context) {
|
||||
$placeholders['@s'] = $context->identifier;
|
||||
if (!empty($conf['vid'])) {
|
||||
$vocabulary = taxonomy_vocabulary_load($conf['vid']);
|
||||
$placeholders['@vocabulary'] = $vocabulary->name;
|
||||
return t('"@s" terms from @vocabulary', $placeholders);
|
||||
}
|
||||
return t('"@s" terms', $placeholders);
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?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('Node title'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The title of the referenced node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array(
|
||||
'link' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_node_title_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a shortcut to the node.
|
||||
$node = $context->data;
|
||||
|
||||
// Load information about the node type.
|
||||
$type = node_type_get_type($node);
|
||||
|
||||
// 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->delta = $node->nid;
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_node_title_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
|
||||
$form['link'] = array(
|
||||
'#title' => t('Link to node'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $conf['link'],
|
||||
'#description' => t('Check here to make the title link to the node.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the custom type settings form.
|
||||
*/
|
||||
function ctools_node_title_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_node_title_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" title', array('@s' => $context->identifier));
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?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('Node type description'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('Node type description.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Output function for the 'node' content type. Outputs a node
|
||||
* based on the module and delta supplied in the configuration.
|
||||
*/
|
||||
function ctools_node_type_desc_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
$node = isset($context->data) ? clone($context->data) : NULL;
|
||||
$block = new stdClass();
|
||||
$block->module = 'node_type';
|
||||
|
||||
if ($node) {
|
||||
$type = node_type_get_type($node);
|
||||
$block->title = $type->name;
|
||||
$block->content = filter_xss_admin($type->description);
|
||||
$block->delta = $node->type;
|
||||
}
|
||||
else {
|
||||
$block->title = t('Node type description');
|
||||
$block->content = t('Node type description goes here.');
|
||||
$block->delta = 'unknown';
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_type_desc_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" type description', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_type_desc_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
<?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('Node last updated date'),
|
||||
'icon' => 'icon_node.png',
|
||||
'description' => t('The date the referenced node was last updated.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'category' => t('Node'),
|
||||
'defaults' => array(
|
||||
'format' => 'small',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Render the custom content type.
|
||||
*/
|
||||
function ctools_node_updated_content_type_render($subtype, $conf, $panel_args, $context) {
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a shortcut to the node.
|
||||
$node = $context->data;
|
||||
|
||||
// Build the content type block.
|
||||
$block = new stdClass();
|
||||
$block->module = 'node_updated';
|
||||
$block->title = t('Last updated date');
|
||||
$block->content = format_date(!empty($node->changed) ? $node->changed : $node->created, $conf['format']);
|
||||
$block->delta = $node->nid;
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit form for custom type settings.
|
||||
*/
|
||||
function ctools_node_updated_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
$date_types = array();
|
||||
|
||||
foreach (system_get_date_types() as $date_type => $definition) {
|
||||
$date_types[$date_type] = format_date(REQUEST_TIME, $date_type);
|
||||
}
|
||||
|
||||
$form['format'] = array(
|
||||
'#title' => t('Date format'),
|
||||
'#type' => 'select',
|
||||
'#options' => $date_types,
|
||||
'#default_value' => $conf['format'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the custom type settings form.
|
||||
*/
|
||||
function ctools_node_updated_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_node_updated_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" last updated date', array('@s' => $context->identifier));
|
||||
}
|
After Width: | Height: | Size: 460 B |
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('upload')) {
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form file attachments'),
|
||||
'description' => t('File attachments on the Node form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_form_attachments_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->title = t('Attach files');
|
||||
$block->delta = 'url-path-options';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['attachments'])) {
|
||||
$block->content = $context->form['attachments'];
|
||||
if (isset($block->content['attachments']['#group'])) {
|
||||
unset($block->content['attachments']['#pre_render']);
|
||||
unset($block->content['attachments']['#theme_wrappers']);
|
||||
$block->content['attachments']['#type'] = '';
|
||||
}
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['attachments']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Attach files.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_attachments_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form attach files', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_attachments_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form author information'),
|
||||
'description' => t('Author information on the Node form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
|
||||
function ctools_node_form_author_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->title = t('Authoring information');
|
||||
$block->delta = 'author-options';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (!empty($context->form['author'])) {
|
||||
$block->content['author'] = $context->form['author'];
|
||||
if (isset($block->content['author']['#group'])) {
|
||||
unset($block->content['author']['#pre_render']);
|
||||
unset($block->content['author']['#theme_wrappers']);
|
||||
$block->content['author']['#type'] = '';
|
||||
$block->content['author']['name']['#size'] /= 2;
|
||||
$block->content['author']['date']['#size'] /= 2;
|
||||
}
|
||||
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['author']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Authoring information.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_author_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form author information', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_author_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('book')) {
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form book options'),
|
||||
'description' => t('Book options for the node.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_form_book_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->title = t('Book outline');
|
||||
$block->delta = 'book-outline';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['book'])) {
|
||||
$block->content['book'] = $context->form['book'];
|
||||
unset($block->content['book']['#pre_render']);
|
||||
unset($block->content['book']['#theme_wrappers']);
|
||||
$block->content['book']['#type'] = '';
|
||||
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['book']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Book options.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_book_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form book options', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_book_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form submit buttons'),
|
||||
'description' => t('Submit buttons for the node form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
|
||||
function ctools_node_form_buttons_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->title = '';
|
||||
$block->delta = 'buttons';
|
||||
|
||||
if (isset($context->form)) {
|
||||
$block->content = array();
|
||||
foreach (array('actions', 'form_token', 'form_build_id', 'form_id') as $element) {
|
||||
$block->content[$element] = isset($context->form[$element]) ? $context->form[$element] : NULL;
|
||||
unset($context->form[$element]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Node form buttons.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_buttons_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form submit buttons', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_buttons_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?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,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form comment settings'),
|
||||
'description' => t('Comment settings on the Node form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_form_comment_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->title = t('Comment options');
|
||||
$block->delta = 'comment-options';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['comment_settings'])) {
|
||||
$block->content['comment_settings'] = $context->form['comment_settings'];
|
||||
unset($block->content['comment_settings']['#pre_render']);
|
||||
unset($block->content['comment_settings']['#theme_wrappers']);
|
||||
$block->content['comment_settings']['#type'] = '';
|
||||
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['comment_settings']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Comment options.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_comment_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form comment settings', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_comment_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form languages'),
|
||||
'description' => t('The language selection form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
|
||||
function ctools_node_form_language_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->delta = 'language-options';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (!empty($context->form['language'])) {
|
||||
$block->content['language'] = $context->form['language'];
|
||||
unset($context->form['language']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Node language form.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_language_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form language field', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_language_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form revision log message'),
|
||||
'description' => t('Revision log message for the node.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
|
||||
function ctools_node_form_log_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
$block->title = t('Revision information');
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['revision_information'])) {
|
||||
$block->content['revision_information'] = $context->form['revision_information'];
|
||||
unset($block->content['revision_information']['#pre_render']);
|
||||
unset($block->content['revision_information']['#theme_wrappers']);
|
||||
$block->content['revision_information']['#type'] = '';
|
||||
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['revision_information']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Revision information.');
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_log_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form revision log', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_log_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('menu')) {
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form menu settings'),
|
||||
'description' => t('Menu settings on the Node form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_form_menu_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->title = t('Menu options');
|
||||
$block->delta = 'menu-options';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['menu'])) {
|
||||
$block->content['menu'] = $context->form['menu'];
|
||||
unset($block->content['menu']['#pre_render']);
|
||||
unset($block->content['menu']['#theme_wrappers']);
|
||||
$block->content['menu']['#type'] = '';
|
||||
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['menu']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Menu options.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_menu_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form menu settings', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_menu_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('path')) {
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'single' => TRUE,
|
||||
'icon' => 'icon_node_form.png',
|
||||
'title' => t('Node form url path settings'),
|
||||
'description' => t('Publishing options on the Node form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
}
|
||||
|
||||
function ctools_node_form_path_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
$block->module = t('node_form');
|
||||
|
||||
$block->title = t('URL path options');
|
||||
$block->delta = 'url-path-options';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['path'])) {
|
||||
$block->content['path'] = $context->form['path'];
|
||||
unset($block->content['path']['#pre_render']);
|
||||
unset($block->content['path']['#theme_wrappers']);
|
||||
$block->content['path']['#type'] = '';
|
||||
$block->content['path']['alias']['#size'] /= 2;
|
||||
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['path']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('URL Path options.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_path_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form path options', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_path_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Publishing options form for the node. This contains the basic settings
|
||||
* like published, moderated, node revision, etc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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('Node form publishing options'),
|
||||
'icon' => 'icon_node_form.png',
|
||||
'description' => t('Publishing options on the Node form.'),
|
||||
'required context' => new ctools_context_required(t('Form'), 'node_form'),
|
||||
'category' => t('Form'),
|
||||
);
|
||||
|
||||
function ctools_node_form_publishing_content_type_render($subtype, $conf, $panel_args, &$context) {
|
||||
$block = new stdClass();
|
||||
|
||||
$block->title = t('Publishing options');
|
||||
$block->module = t('node_form');
|
||||
$block->delta = 'publishing-options';
|
||||
|
||||
if (isset($context->form)) {
|
||||
if (isset($context->form['options'])) {
|
||||
$block->content['options'] = $context->form['options'];
|
||||
unset($block->content['options']['#pre_render']);
|
||||
unset($block->content['options']['#theme_wrappers']);
|
||||
$block->content['options']['#type'] = '';
|
||||
|
||||
// Set access to false on the original rather than removing so that
|
||||
// vertical tabs doesn't clone it. I think this is due to references.
|
||||
$context->form['options']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$block->content = t('Publishing options.');
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
function ctools_node_form_publishing_content_type_admin_title($subtype, $conf, $context) {
|
||||
return t('"@s" node form publishing options', array('@s' => $context->identifier));
|
||||
}
|
||||
|
||||
function ctools_node_form_publishing_content_type_edit_form($form, &$form_state) {
|
||||
// provide a blank form so we have a place to have context setting.
|
||||
return $form;
|
||||
}
|