updated contrib modules
This commit is contained in:
@@ -2,25 +2,26 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @todo.
|
||||
* Definition of views_handler_field.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup views_field_handlers Views field handlers
|
||||
* @{
|
||||
* Handlers to tell Views how to build and display fields.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Indicator of the render_text() method for rendering a single item.
|
||||
* (If no render_item() is present).
|
||||
*
|
||||
* If no render_item() is present.
|
||||
*/
|
||||
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM', 0);
|
||||
|
||||
/**
|
||||
* Indicator of the render_text() method for rendering the whole element.
|
||||
* (if no render_item() method is available).
|
||||
*
|
||||
* if no render_item() method is available.
|
||||
*/
|
||||
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY', 1);
|
||||
|
||||
@@ -34,17 +35,29 @@ define('VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY', 2);
|
||||
*
|
||||
* Definition terms:
|
||||
* - additional fields: An array of fields that should be added to the query
|
||||
* for some purpose. The array is in the form of:
|
||||
* array('identifier' => array('table' => tablename,
|
||||
* 'field' => fieldname); as many fields as are necessary
|
||||
* may be in this array.
|
||||
* for some purpose. The array is in the form of:
|
||||
* array(
|
||||
* 'identifier' => array(
|
||||
* 'table' => tablename,
|
||||
* 'field' => fieldname,
|
||||
* )
|
||||
* );
|
||||
* with as many fields as are necessary may be in this array.
|
||||
* - click sortable: If TRUE, this field may be click sorted.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field extends views_handler {
|
||||
var $field_alias = 'unknown';
|
||||
var $aliases = array();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public $field_alias = 'unknown';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public $aliases = array();
|
||||
|
||||
/**
|
||||
* The field value prior to any rewriting.
|
||||
@@ -55,15 +68,15 @@ class views_handler_field extends views_handler {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* Stores additional fields which get's added to the query.
|
||||
* Stores additional fields which get added to the query.
|
||||
* The generated aliases are stored in $aliases.
|
||||
*/
|
||||
var $additional_fields = array();
|
||||
public $additional_fields = array();
|
||||
|
||||
/**
|
||||
* Construct a new field handler.
|
||||
*/
|
||||
function construct() {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
|
||||
$this->additional_fields = array();
|
||||
@@ -79,21 +92,24 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Determine if this field can allow advanced rendering.
|
||||
*
|
||||
* Fields can set this to FALSE if they do not wish to allow
|
||||
* token based rewriting or link-making.
|
||||
* Fields can set this to FALSE if they do not wish to allow token based
|
||||
* rewriting or link-making.
|
||||
*/
|
||||
function allow_advanced_render() {
|
||||
public function allow_advanced_render() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function init(&$view, &$options) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to add the field to a query.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
// Add the field.
|
||||
$params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
|
||||
@@ -105,16 +121,15 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Add 'additional' fields to the query.
|
||||
*
|
||||
* @param $fields
|
||||
* An array of fields. The key is an identifier used to later find the
|
||||
* field alias used. The value is either a string in which case it's
|
||||
* assumed to be a field on this handler's table; or it's an array in the
|
||||
* form of
|
||||
* @code array('table' => $tablename, 'field' => $fieldname) @endcode
|
||||
* @param array $fields
|
||||
* An array of fields. The key is an identifier used to later find the field
|
||||
* alias used. The value is either a string in which case it's assumed to be
|
||||
* a field on this handler's table; or it's an array in the form of
|
||||
* @code array('table' => $tablename, 'field' => $fieldname) @endcode
|
||||
*/
|
||||
function add_additional_fields($fields = NULL) {
|
||||
public function add_additional_fields($fields = NULL) {
|
||||
if (!isset($fields)) {
|
||||
// notice check
|
||||
// Notice check.
|
||||
if (empty($this->additional_fields)) {
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +154,12 @@ class views_handler_field extends views_handler {
|
||||
}
|
||||
|
||||
if (empty($table_alias)) {
|
||||
debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', array('@handler' => $this->definition['handler'], '@identifier' => $identifier, '@table' => $info['table'])));
|
||||
$t_args = array(
|
||||
'@handler' => $this->definition['handler'],
|
||||
'@identifier' => $identifier,
|
||||
'@table' => $info['table'],
|
||||
);
|
||||
debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', $t_args));
|
||||
$this->aliases[$identifier] = 'broken';
|
||||
continue;
|
||||
}
|
||||
@@ -162,7 +182,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Called to determine what to tell the clicksorter.
|
||||
*/
|
||||
function click_sort($order) {
|
||||
public function click_sort($order) {
|
||||
if (isset($this->field_alias)) {
|
||||
// Since fields should always have themselves already added, just
|
||||
// add a sort on the field.
|
||||
@@ -174,14 +194,14 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Determine if this field is click sortable.
|
||||
*/
|
||||
function click_sortable() {
|
||||
public function click_sortable() {
|
||||
return !empty($this->definition['click sortable']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this field's label.
|
||||
*/
|
||||
function label() {
|
||||
public function label() {
|
||||
if (!isset($this->options['label'])) {
|
||||
return '';
|
||||
}
|
||||
@@ -191,7 +211,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return an HTML element based upon the field's element type.
|
||||
*/
|
||||
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
||||
public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
||||
if ($none_supported) {
|
||||
if ($this->options['element_type'] === '0') {
|
||||
return '';
|
||||
@@ -219,7 +239,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return an HTML element for the label based upon the field's element type.
|
||||
*/
|
||||
function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
public function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
if ($none_supported) {
|
||||
if ($this->options['element_label_type'] === '0') {
|
||||
return '';
|
||||
@@ -239,7 +259,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return an HTML element for the wrapper based upon the field's element type.
|
||||
*/
|
||||
function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
public function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
if ($none_supported) {
|
||||
if ($this->options['element_wrapper_type'] === '0') {
|
||||
return 0;
|
||||
@@ -259,11 +279,10 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Provide a list of elements valid for field HTML.
|
||||
*
|
||||
* This function can be overridden by fields that want more or fewer
|
||||
* elements available, though this seems like it would be an incredibly
|
||||
* rare occurence.
|
||||
* This function can be overridden by fields that want more or fewer elements
|
||||
* available, though this seems like it would be an incredibly rare occurence.
|
||||
*/
|
||||
function get_elements() {
|
||||
public function get_elements() {
|
||||
static $elements = NULL;
|
||||
if (!isset($elements)) {
|
||||
$elements = variable_get('views_field_rewrite_elements', array(
|
||||
@@ -289,7 +308,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return the class of the field.
|
||||
*/
|
||||
function element_classes($row_index = NULL) {
|
||||
public function element_classes($row_index = NULL) {
|
||||
$classes = explode(' ', $this->options['element_class']);
|
||||
foreach ($classes as &$class) {
|
||||
$class = $this->tokenize_value($class, $row_index);
|
||||
@@ -304,15 +323,14 @@ class views_handler_field extends views_handler {
|
||||
* This function actually figures out which field was last and uses its
|
||||
* tokens so they will all be available.
|
||||
*/
|
||||
function tokenize_value($value, $row_index = NULL) {
|
||||
public function tokenize_value($value, $row_index = NULL) {
|
||||
if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) {
|
||||
$fake_item = array(
|
||||
'alter_text' => TRUE,
|
||||
'text' => $value,
|
||||
);
|
||||
|
||||
// Use isset() because empty() will trigger on 0 and 0 is
|
||||
// the first row.
|
||||
// Use isset() because empty() will trigger on 0 and 0 is the first row.
|
||||
if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
|
||||
$tokens = $this->view->style_plugin->render_tokens[$row_index];
|
||||
}
|
||||
@@ -339,7 +357,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return the class of the field's label.
|
||||
*/
|
||||
function element_label_classes($row_index = NULL) {
|
||||
public function element_label_classes($row_index = NULL) {
|
||||
$classes = explode(' ', $this->options['element_label_class']);
|
||||
foreach ($classes as &$class) {
|
||||
$class = $this->tokenize_value($class, $row_index);
|
||||
@@ -351,7 +369,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return the class of the field's wrapper.
|
||||
*/
|
||||
function element_wrapper_classes($row_index = NULL) {
|
||||
public function element_wrapper_classes($row_index = NULL) {
|
||||
$classes = explode(' ', $this->options['element_wrapper_class']);
|
||||
foreach ($classes as &$class) {
|
||||
$class = $this->tokenize_value($class, $row_index);
|
||||
@@ -366,12 +384,12 @@ class views_handler_field extends views_handler {
|
||||
* This api exists so that other modules can easy set the values of the field
|
||||
* without having the need to change the render method as well.
|
||||
*
|
||||
* @param $values
|
||||
* @param object $values
|
||||
* An object containing all retrieved values.
|
||||
* @param $field
|
||||
* @param string $field
|
||||
* Optional name of the field where the value is stored.
|
||||
*/
|
||||
function get_value($values, $field = NULL) {
|
||||
public function get_value($values, $field = NULL) {
|
||||
$alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
|
||||
if (isset($values->{$alias})) {
|
||||
return $values->{$alias};
|
||||
@@ -383,13 +401,16 @@ class views_handler_field extends views_handler {
|
||||
* by in the style settings.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if this field handler is groupable, otherwise FALSE.
|
||||
* TRUE if this field handler is groupable, otherwise FALSE.
|
||||
*/
|
||||
function use_string_group_by() {
|
||||
public function use_string_group_by() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE);
|
||||
@@ -403,6 +424,7 @@ class views_handler_field extends views_handler {
|
||||
'absolute' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'external' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'replace_spaces' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'unwanted_characters' => array('default' => ''),
|
||||
'path_case' => array('default' => 'none', 'translatable' => FALSE),
|
||||
'trim_whitespace' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'alt' => array('default' => '', 'translatable' => TRUE),
|
||||
@@ -447,10 +469,19 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Performs some cleanup tasks on the options array before saving it.
|
||||
*/
|
||||
function options_submit(&$form, &$form_state) {
|
||||
public function options_submit(&$form, &$form_state) {
|
||||
$options = &$form_state['values']['options'];
|
||||
$types = array('element_type', 'element_label_type', 'element_wrapper_type');
|
||||
$classes = array_combine(array('element_class', 'element_label_class', 'element_wrapper_class'), $types);
|
||||
$types = array(
|
||||
'element_type',
|
||||
'element_label_type',
|
||||
'element_wrapper_type',
|
||||
);
|
||||
$base_types = array(
|
||||
'element_class',
|
||||
'element_label_class',
|
||||
'element_wrapper_class',
|
||||
);
|
||||
$classes = array_combine($base_types, $types);
|
||||
|
||||
foreach ($types as $type) {
|
||||
if (!$options[$type . '_enable']) {
|
||||
@@ -471,10 +502,9 @@ class views_handler_field extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options form that provides the label widget that all fields
|
||||
* should have.
|
||||
* Default options form provides the label widget that all fields should have.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$label = $this->label();
|
||||
@@ -581,7 +611,7 @@ class views_handler_field extends views_handler {
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Create a CSS class'),
|
||||
'#dependency' => array(
|
||||
'edit-options-element-label-type-enable' => array(1)
|
||||
'edit-options-element-label-type-enable' => array(1),
|
||||
),
|
||||
'#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
|
||||
'#fieldset' => 'style_settings',
|
||||
@@ -703,7 +733,7 @@ class views_handler_field extends views_handler {
|
||||
'#title' => t('Replace spaces with dashes'),
|
||||
'#default_value' => $this->options['alter']['replace_spaces'],
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1)
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
);
|
||||
$form['alter']['external'] = array(
|
||||
@@ -715,6 +745,16 @@ class views_handler_field extends views_handler {
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
);
|
||||
$form['alter']['unwanted_characters'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Remove unwanted characters'),
|
||||
'#description' => t('Space-separated list of characters to remove from the URL path'),
|
||||
'#default_value' => $this->options['alter']['unwanted_characters'],
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1)
|
||||
),
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
$form['alter']['path_case'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Transform the case'),
|
||||
@@ -722,7 +762,7 @@ class views_handler_field extends views_handler {
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
'#options' => array(
|
||||
'#options' => array(
|
||||
'none' => t('No transform'),
|
||||
'upper' => t('Upper case'),
|
||||
'lower' => t('Lower case'),
|
||||
@@ -753,7 +793,7 @@ class views_handler_field extends views_handler {
|
||||
'#title' => t('Rel Text'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $this->options['alter']['rel'],
|
||||
'#description' => t('Include Rel attribute for use in lightbox2 or other javascript utility.'),
|
||||
'#description' => t('Include Rel attribute for use in lightbox2 or other JavaScript utility.'),
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
@@ -796,7 +836,8 @@ class views_handler_field extends views_handler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$count = 0; // This lets us prepare the key as we want it printed.
|
||||
// This lets us prepare the key as we want it printed.
|
||||
$count = 0;
|
||||
foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
|
||||
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
|
||||
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
|
||||
@@ -819,15 +860,15 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$output .= theme('item_list',
|
||||
array(
|
||||
'items' => $items,
|
||||
'type' => $type
|
||||
'type' => $type,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
// This construct uses 'hidden' and not markup because process doesn't
|
||||
// run. It also has an extra div because the dependency wants to hide
|
||||
// the parent in situations like this, so we need a second div to
|
||||
// make this work.
|
||||
// run. It also has an extra div because the dependency wants to hide the
|
||||
// parent in situations like this, so we need a second div to make this
|
||||
// work.
|
||||
$form['alter']['help'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Replacement patterns'),
|
||||
@@ -997,28 +1038,29 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Provide extra data to the administration form
|
||||
*/
|
||||
function admin_summary() {
|
||||
public function admin_summary() {
|
||||
return $this->label();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run before any fields are rendered.
|
||||
*
|
||||
* This gives the handlers some time to set up before any handler has
|
||||
* been rendered.
|
||||
* This gives the handlers some time to set up before any handler has been
|
||||
* rendered.
|
||||
*
|
||||
* @param $values
|
||||
* @param array $values
|
||||
* An array of all objects returned from the query.
|
||||
*/
|
||||
function pre_render(&$values) { }
|
||||
public function pre_render(&$values) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the field.
|
||||
*
|
||||
* @param $values
|
||||
* @param array $values
|
||||
* The values retrieved from the database.
|
||||
*/
|
||||
function render($values) {
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return $this->sanitize_value($value);
|
||||
}
|
||||
@@ -1029,7 +1071,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* This renders a field normally, then decides if render-as-link and
|
||||
* text-replacement rendering is necessary.
|
||||
*/
|
||||
function advanced_render($values) {
|
||||
public function advanced_render($values) {
|
||||
if ($this->allow_advanced_render() && method_exists($this, 'render_item')) {
|
||||
$raw_items = $this->get_items($values);
|
||||
// If there are no items, set the original value to NULL.
|
||||
@@ -1094,7 +1136,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Checks if a field value is empty.
|
||||
*
|
||||
* @param $value
|
||||
* @param mixed $value
|
||||
* The field value.
|
||||
* @param bool $empty_zero
|
||||
* Whether or not this field is configured to consider 0 as empty.
|
||||
@@ -1102,9 +1144,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* Whether or not to use empty() to check the value.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the value is considered empty, FALSE otherwise.
|
||||
* TRUE if the value is considered empty, FALSE otherwise.
|
||||
*/
|
||||
function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
|
||||
public function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
|
||||
if (!isset($value)) {
|
||||
$empty = TRUE;
|
||||
}
|
||||
@@ -1124,7 +1166,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* This is separated out as some fields may render lists, and this allows
|
||||
* each item to be handled individually.
|
||||
*/
|
||||
function render_text($alter) {
|
||||
public function render_text($alter) {
|
||||
$value = $this->last_render;
|
||||
|
||||
if (!empty($alter['alter_text']) && $alter['text'] !== '') {
|
||||
@@ -1139,9 +1181,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
// Check if there should be no further rewrite for empty values.
|
||||
$no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this->is_value_empty($this->original_value, $this->options['empty_zero']);
|
||||
|
||||
// Check whether the value is empty and return nothing, so the field isn't rendered.
|
||||
// First check whether the field should be hidden if the value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty = FALSE).
|
||||
// For numeric values you can specify whether "0"/0 should be empty.
|
||||
// Check whether the value is empty and return nothing, so the field isn't
|
||||
// rendered. First check whether the field should be hidden if the
|
||||
// value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty =
|
||||
// FALSE). For numeric values you can specify whether "0"/0 should be empty.
|
||||
if ((($this->options['hide_empty'] && empty($value))
|
||||
|| ($alter['phase'] != VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty))
|
||||
&& $this->is_value_empty($value, $this->options['empty_zero'], FALSE)) {
|
||||
@@ -1169,7 +1212,8 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$more_link_path = $this->options['alter']['more_link_path'];
|
||||
$more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens)));
|
||||
|
||||
// Take sure that paths which was runned through url() does work as well.
|
||||
// Take sure that paths which was runned through url() does work as
|
||||
// well.
|
||||
$base_path = base_path();
|
||||
// Checks whether the path starts with the base_path.
|
||||
if (strpos($more_link_path, $base_path) === 0) {
|
||||
@@ -1189,7 +1233,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
|
||||
if (!empty($alter['make_link']) && !empty($alter['path'])) {
|
||||
if (!isset($tokens)) {
|
||||
$tokens = $this->get_render_tokens($alter);
|
||||
$tokens = $this->get_render_tokens($alter);
|
||||
}
|
||||
$value = $this->render_as_link($alter, $value, $tokens);
|
||||
}
|
||||
@@ -1200,9 +1244,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Render this field as altered text, from a fieldset set by the user.
|
||||
*/
|
||||
function render_altered($alter, $tokens) {
|
||||
// Filter this right away as our substitutions are already sanitized.
|
||||
$value = filter_xss_admin($alter['text']);
|
||||
public function render_altered($alter, $tokens) {
|
||||
// We trust admins so we allow any tag content. This is important for
|
||||
// displays such as XML where we should not mess with tags.
|
||||
$value = $alter['text'];
|
||||
$value = strtr($value, $tokens);
|
||||
|
||||
return $value;
|
||||
@@ -1211,21 +1256,20 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Trim the field down to the specified length.
|
||||
*/
|
||||
function render_trim_text($alter, $value) {
|
||||
public function render_trim_text($alter, $value) {
|
||||
if (!empty($alter['strip_tags'])) {
|
||||
// NOTE: It's possible that some external fields might override the
|
||||
// element type so if someone from, say, CCK runs into a bug here,
|
||||
// this may be why =)
|
||||
// element type so if someone from, say, CCK runs into a bug here, this
|
||||
// may be why =)
|
||||
$this->definition['element type'] = 'span';
|
||||
}
|
||||
return views_trim_text($alter, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render this field as a link, with the info from a fieldset set by
|
||||
* the user.
|
||||
* Render this field as a link, with info from a fieldset set by the user.
|
||||
*/
|
||||
function render_as_link($alter, $text, $tokens) {
|
||||
public function render_as_link($alter, $text, $tokens) {
|
||||
$value = '';
|
||||
|
||||
if (!empty($alter['prefix'])) {
|
||||
@@ -1243,9 +1287,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
|
||||
// strip_tags() removes <front>, so check whether its different to front.
|
||||
if ($path != '<front>') {
|
||||
// Use strip tags as there should never be HTML in the path.
|
||||
// However, we need to preserve special characters like " that
|
||||
// were removed by check_plain().
|
||||
// Use strip tags as there should never be HTML in the path. However, we
|
||||
// need to preserve special characters like " that were removed by
|
||||
// check_plain().
|
||||
$path = strip_tags(decode_entities(strtr($path, $tokens)));
|
||||
|
||||
if (!empty($alter['path_case']) && $alter['path_case'] != 'none') {
|
||||
@@ -1255,6 +1299,12 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
if (!empty($alter['replace_spaces'])) {
|
||||
$path = str_replace(' ', '-', $path);
|
||||
}
|
||||
|
||||
if (!empty($alter['unwanted_characters'])) {
|
||||
foreach (explode(' ', $alter['unwanted_characters']) as $unwanted) {
|
||||
$path = str_replace($unwanted, '', $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the URL and move any query and fragment parameters out of the path.
|
||||
@@ -1266,16 +1316,16 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
}
|
||||
|
||||
// If the path is empty do not build a link around the given text and return
|
||||
// it as is.
|
||||
// http://www.example.com URLs will not have a $url['path'], so check host as well.
|
||||
// it as is. http://www.example.com URLs will not have a $url['path'], so
|
||||
// check host as well.
|
||||
if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
// If no scheme is provided in the $path, assign the default 'http://'.
|
||||
// This allows a url of 'www.example.com' to be converted to 'http://www.example.com'.
|
||||
// Only do this on for external URLs.
|
||||
if ($alter['external']){
|
||||
// This allows a url of 'www.example.com' to be converted to
|
||||
// 'http://www.example.com'. Only do this on for external URLs.
|
||||
if ($alter['external']) {
|
||||
if (!isset($url['scheme'])) {
|
||||
// There is no scheme, add the default 'http://' to the $path.
|
||||
$path = "http://$path";
|
||||
@@ -1320,13 +1370,14 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$options['attributes']['rel'] = $rel;
|
||||
}
|
||||
|
||||
$target = check_plain(trim(strtr($alter['target'],$tokens)));
|
||||
$target = check_plain(trim(strtr($alter['target'], $tokens)));
|
||||
if (!empty($target)) {
|
||||
$options['attributes']['target'] = $target;
|
||||
}
|
||||
|
||||
// Allow the addition of arbitrary attributes to links. Additional attributes
|
||||
// currently can only be altered in preprocessors and not within the UI.
|
||||
// Allow the addition of arbitrary attributes to links. Additional
|
||||
// attributes currently can only be altered in preprocessors and not within
|
||||
// the UI.
|
||||
if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) {
|
||||
foreach ($alter['link_attributes'] as $key => $attribute) {
|
||||
if (!isset($options['attributes'][$key])) {
|
||||
@@ -1375,11 +1426,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Get the 'render' tokens to use for advanced rendering.
|
||||
*
|
||||
* This runs through all of the fields and arguments that
|
||||
* are available and gets their values. This will then be
|
||||
* used in one giant str_replace().
|
||||
* This runs through all of the fields and arguments that are available and
|
||||
* gets their values. This will then be used in one giant str_replace().
|
||||
*/
|
||||
function get_render_tokens($item) {
|
||||
public function get_render_tokens($item) {
|
||||
$tokens = array();
|
||||
if (!empty($this->view->build_info['substitutions'])) {
|
||||
$tokens = $this->view->build_info['substitutions'];
|
||||
@@ -1391,9 +1441,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$tokens[$token] = '';
|
||||
}
|
||||
|
||||
// Use strip tags as there should never be HTML in the path.
|
||||
// However, we need to preserve special characters like " that
|
||||
// were removed by check_plain().
|
||||
// Use strip tags as there should never be HTML in the path. However, we
|
||||
// need to preserve special characters like " that were removed by
|
||||
// check_plain().
|
||||
$tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
|
||||
}
|
||||
|
||||
@@ -1450,27 +1500,28 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* '%bar_b_c' => 'value'
|
||||
* );
|
||||
*
|
||||
* @param $array
|
||||
* @param array $array
|
||||
* An array of values.
|
||||
*
|
||||
* @param $parent_keys
|
||||
* @param array $parent_keys
|
||||
* An array of parent keys. This will represent the array depth.
|
||||
*
|
||||
* @return
|
||||
* An array of available tokens, with nested keys representative of the array structure.
|
||||
* @return array
|
||||
* An array of available tokens, with nested keys representative of the
|
||||
* array structure.
|
||||
*/
|
||||
function get_token_values_recursive(array $array, array $parent_keys = array()) {
|
||||
public function get_token_values_recursive(array $array, array $parent_keys = array()) {
|
||||
$tokens = array();
|
||||
|
||||
foreach ($array as $param => $val) {
|
||||
if (is_array($val)) {
|
||||
// Copy parent_keys array, so we don't afect other elements of this iteration.
|
||||
$child_parent_keys = $parent_keys;
|
||||
$child_parent_keys[] = $param;
|
||||
// Get the child tokens.
|
||||
$child_tokens = $this->get_token_values_recursive($val, $child_parent_keys);
|
||||
// Add them to the current tokens array.
|
||||
$tokens += $child_tokens;
|
||||
// Copy parent_keys array, so we don't afect other elements of this
|
||||
// iteration.
|
||||
$child_parent_keys = $parent_keys;
|
||||
$child_parent_keys[] = $param;
|
||||
// Get the child tokens.
|
||||
$child_tokens = $this->get_token_values_recursive($val, $child_parent_keys);
|
||||
// Add them to the current tokens array.
|
||||
$tokens += $child_tokens;
|
||||
}
|
||||
else {
|
||||
// Create a token key based on array element structure.
|
||||
@@ -1485,50 +1536,57 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Add any special tokens this field might use for itself.
|
||||
*
|
||||
* This method is intended to be overridden by items that generate
|
||||
* fields as a list. For example, the field that displays all terms
|
||||
* on a node might have tokens for the tid and the term.
|
||||
* This method is intended to be overridden by items that generate fields as a
|
||||
* list. For example, the field that displays all terms on a node might have
|
||||
* tokens for the tid and the term.
|
||||
*
|
||||
* By convention, tokens should follow the format of [token-subtoken]
|
||||
* where token is the field ID and subtoken is the field. If the
|
||||
* field ID is terms, then the tokens might be [terms-tid] and [terms-name].
|
||||
* By convention, tokens should follow the format of [token-subtoken] where
|
||||
* token is the field ID and subtoken is the field. If the field ID is terms,
|
||||
* then the tokens might be [terms-tid] and [terms-name].
|
||||
*/
|
||||
function add_self_tokens(&$tokens, $item) { }
|
||||
public function add_self_tokens(&$tokens, $item) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Document any special tokens this field might use for itself.
|
||||
*
|
||||
* @see add_self_tokens()
|
||||
*/
|
||||
function document_self_tokens(&$tokens) { }
|
||||
public function document_self_tokens(&$tokens) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Call out to the theme() function, which probably just calls render() but
|
||||
* allows sites to override output fairly easily.
|
||||
* Call out to the theme() function.
|
||||
*
|
||||
* It probably just calls render() but allows sites to override output fairly
|
||||
* easily.
|
||||
*/
|
||||
function theme($values) {
|
||||
public function theme($values) {
|
||||
return theme($this->theme_functions(),
|
||||
array(
|
||||
'view' => $this->view,
|
||||
'field' => $this,
|
||||
'row' => $values
|
||||
'row' => $values,
|
||||
));
|
||||
}
|
||||
|
||||
function theme_functions() {
|
||||
/**
|
||||
* Build a list of suitable theme functions for this view.
|
||||
*/
|
||||
public function theme_functions() {
|
||||
$themes = array();
|
||||
$hook = 'views_view_field';
|
||||
|
||||
$display = $this->view->display[$this->view->current_display];
|
||||
|
||||
if (!empty($display)) {
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id;
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id;
|
||||
$themes[] = $hook . '__' . $display->id . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $display->id;
|
||||
if ($display->id != $display->display_plugin) {
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin;
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin;
|
||||
$themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $display->display_plugin;
|
||||
}
|
||||
@@ -1541,9 +1599,13 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
return $themes;
|
||||
}
|
||||
|
||||
function ui_name($short = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return $this->get_field(parent::ui_name($short));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1552,22 +1614,44 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_broken extends views_handler_field {
|
||||
function ui_name($short = FALSE) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return t('Broken/missing handler');
|
||||
}
|
||||
|
||||
function ensure_my_table() { /* No table to ensure! */ }
|
||||
function query($group_by = FALSE) { /* No query to run */ }
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ensure_my_table() {
|
||||
// No table to ensure!
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
// No query to run.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['markup'] = array(
|
||||
'#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the handler is considered 'broken'
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function broken() { return TRUE; }
|
||||
public function broken() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1576,7 +1660,11 @@ class views_handler_field_broken extends views_handler_field {
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_file_size extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['file_size_display'] = array('default' => 'formatted');
|
||||
@@ -1584,7 +1672,10 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['file_size_display'] = array(
|
||||
'#title' => t('File size display'),
|
||||
@@ -1596,7 +1687,10 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
if ($value) {
|
||||
switch ($this->options['file_size_display']) {
|
||||
@@ -1611,6 +1705,7 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1619,10 +1714,15 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_xss extends views_handler_field {
|
||||
function render($values) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return $this->sanitize_value($value, 'xss');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user