View source
<?php
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM', 0);
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY', 1);
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY', 2);
class views_handler_field extends views_handler {
public $field_alias = 'unknown';
public $aliases = array();
public $original_value = NULL;
public $additional_fields = array();
protected $last_render_index = NULL;
public function construct() {
parent::construct();
$this->additional_fields = array();
if (!empty($this->definition['additional fields'])) {
$this->additional_fields = $this->definition['additional fields'];
}
if (!isset($this->options['exclude'])) {
$this->options['exclude'] = '';
}
}
public function allow_advanced_render() {
return TRUE;
}
public function init(&$view, &$options) {
parent::init($view, $options);
}
public function query() {
$this
->ensure_my_table();
$params = $this->options['group_type'] != 'group' ? array(
'function' => $this->options['group_type'],
) : array();
$this->field_alias = $this->query
->add_field($this->table_alias, $this->real_field, NULL, $params);
$this
->add_additional_fields();
}
public function add_additional_fields($fields = NULL) {
if (!isset($fields)) {
if (empty($this->additional_fields)) {
return;
}
$fields = $this->additional_fields;
}
$group_params = array();
if ($this->options['group_type'] != 'group') {
$group_params = array(
'function' => $this->options['group_type'],
);
}
if (!empty($fields) && is_array($fields)) {
foreach ($fields as $identifier => $info) {
if (is_array($info)) {
if (isset($info['table'])) {
$table_alias = $this->query
->ensure_table($info['table'], $this->relationship);
}
else {
$table_alias = $this->table_alias;
}
if (empty($table_alias)) {
$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;
}
$params = array();
if (!empty($info['params'])) {
$params = $info['params'];
}
$params += $group_params;
$this->aliases[$identifier] = $this->query
->add_field($table_alias, $info['field'], NULL, $params);
}
else {
$this->aliases[$info] = $this->query
->add_field($this->table_alias, $info, NULL, $group_params);
}
}
}
}
public function click_sort($order) {
if (isset($this->field_alias)) {
$params = $this->options['group_type'] != 'group' ? array(
'function' => $this->options['group_type'],
) : array();
$this->query
->add_orderby(NULL, NULL, $order, $this->field_alias, $params);
}
}
public function click_sortable() {
return !empty($this->definition['click sortable']);
}
public function label() {
if (!isset($this->options['label'])) {
return '';
}
return $this->options['label'];
}
public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
if ($none_supported) {
if ($this->options['element_type'] === '0') {
return '';
}
}
if ($this->options['element_type']) {
return check_plain($this->options['element_type']);
}
if ($default_empty) {
return '';
}
if ($inline) {
return 'span';
}
if (isset($this->definition['element type'])) {
return $this->definition['element type'];
}
return 'span';
}
public function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
if ($none_supported) {
if ($this->options['element_label_type'] === '0') {
return '';
}
}
if ($this->options['element_label_type']) {
return check_plain($this->options['element_label_type']);
}
if ($default_empty) {
return '';
}
return 'span';
}
public function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
if ($none_supported) {
if ($this->options['element_wrapper_type'] === '0') {
return 0;
}
}
if ($this->options['element_wrapper_type']) {
return check_plain($this->options['element_wrapper_type']);
}
if ($default_empty) {
return '';
}
return 'div';
}
public function get_elements() {
static $elements = NULL;
if (!isset($elements)) {
$elements = variable_get('views_field_rewrite_elements', array(
'' => t('- Use default -'),
'0' => t('- None -'),
'div' => 'DIV',
'span' => 'SPAN',
'h1' => 'H1',
'h2' => 'H2',
'h3' => 'H3',
'h4' => 'H4',
'h5' => 'H5',
'h6' => 'H6',
'p' => 'P',
'strong' => 'STRONG',
'em' => 'EM',
));
}
return $elements;
}
public function element_classes($row_index = NULL) {
$classes = explode(' ', $this->options['element_class']);
foreach ($classes as &$class) {
$class = $this
->tokenize_value($class, $row_index);
$class = views_clean_css_identifier($class);
}
return implode(' ', $classes);
}
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,
);
if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
$tokens = $this->view->style_plugin->render_tokens[$row_index];
}
else {
$last_field = end($this->view->field);
if (isset($last_field->last_tokens)) {
$tokens = $last_field->last_tokens;
}
else {
$tokens = $last_field
->get_render_tokens($fake_item);
}
}
$value = strip_tags($this
->render_altered($fake_item, $tokens));
if (!empty($this->options['alter']['trim_whitespace'])) {
$value = trim($value);
}
}
return $value;
}
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);
$class = views_clean_css_identifier($class);
}
return implode(' ', $classes);
}
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);
$class = views_clean_css_identifier($class);
}
return implode(' ', $classes);
}
public function get_value($values, $field = NULL) {
$alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
if (isset($values->{$alias})) {
return $values->{$alias};
}
}
public function use_string_group_by() {
return TRUE;
}
public function option_definition() {
$options = parent::option_definition();
$options['label'] = array(
'default' => $this->definition['title'],
'translatable' => TRUE,
);
$options['exclude'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['alter'] = array(
'contains' => array(
'alter_text' => array(
'default' => FALSE,
'bool' => TRUE,
),
'text' => array(
'default' => '',
'translatable' => TRUE,
),
'make_link' => array(
'default' => FALSE,
'bool' => TRUE,
),
'path' => array(
'default' => '',
),
'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,
),
'rel' => array(
'default' => '',
),
'link_class' => array(
'default' => '',
),
'prefix' => array(
'default' => '',
'translatable' => TRUE,
),
'suffix' => array(
'default' => '',
'translatable' => TRUE,
),
'target' => array(
'default' => '',
),
'nl2br' => array(
'default' => FALSE,
'bool' => TRUE,
),
'max_length' => array(
'default' => '',
),
'word_boundary' => array(
'default' => TRUE,
'bool' => TRUE,
),
'ellipsis' => array(
'default' => TRUE,
'bool' => TRUE,
),
'more_link' => array(
'default' => FALSE,
'bool' => TRUE,
),
'more_link_text' => array(
'default' => '',
'translatable' => TRUE,
),
'more_link_path' => array(
'default' => '',
),
'strip_tags' => array(
'default' => FALSE,
'bool' => TRUE,
),
'trim' => array(
'default' => FALSE,
'bool' => TRUE,
),
'preserve_tags' => array(
'default' => '',
),
'html' => array(
'default' => FALSE,
'bool' => TRUE,
),
),
);
$options['element_type'] = array(
'default' => '',
);
$options['element_class'] = array(
'default' => '',
);
$options['element_label_type'] = array(
'default' => '',
);
$options['element_label_class'] = array(
'default' => '',
);
$options['element_label_colon'] = array(
'default' => TRUE,
'bool' => TRUE,
);
$options['element_wrapper_type'] = array(
'default' => '',
);
$options['element_wrapper_class'] = array(
'default' => '',
);
$options['element_default_classes'] = array(
'default' => TRUE,
'bool' => TRUE,
);
$options['empty'] = array(
'default' => '',
'translatable' => TRUE,
);
$options['hide_empty'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['empty_zero'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['hide_alter_empty'] = array(
'default' => TRUE,
'bool' => TRUE,
);
return $options;
}
public function options_submit(&$form, &$form_state) {
$options =& $form_state['values']['options'];
$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']) {
$options[$type] = '';
}
}
foreach ($classes as $class => $type) {
if (!$options[$class . '_enable'] || !$options[$type . '_enable']) {
$options[$class] = '';
}
}
if (empty($options['custom_label'])) {
$options['label'] = '';
$options['element_label_colon'] = FALSE;
}
}
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$label = $this
->label();
$form['custom_label'] = array(
'#type' => 'checkbox',
'#title' => t('Create a label'),
'#description' => t('Enable to create a label for this field.'),
'#default_value' => $label !== '',
'#weight' => -103,
);
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => $label,
'#dependency' => array(
'edit-options-custom-label' => array(
1,
),
),
'#weight' => -102,
);
$form['element_label_colon'] = array(
'#type' => 'checkbox',
'#title' => t('Place a colon after the label'),
'#default_value' => $this->options['element_label_colon'],
'#dependency' => array(
'edit-options-custom-label' => array(
1,
),
),
'#weight' => -101,
);
$form['exclude'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude from display'),
'#default_value' => $this->options['exclude'],
'#description' => t('Enable to load this field as hidden. Often used to group fields, or to use as token in another field.'),
'#weight' => -100,
);
$form['style_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Style settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 99,
);
$form['element_type_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Customize field HTML'),
'#default_value' => !empty($this->options['element_type']) || (string) $this->options['element_type'] == '0' || !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_type'] = array(
'#title' => t('HTML element'),
'#options' => $this
->get_elements(),
'#type' => 'select',
'#default_value' => $this->options['element_type'],
'#description' => t('Choose the HTML element to wrap around this field, e.g. H1, H2, etc.'),
'#dependency' => array(
'edit-options-element-type-enable' => array(
1,
),
),
'#fieldset' => 'style_settings',
);
$form['element_class_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Create a CSS class'),
'#dependency' => array(
'edit-options-element-type-enable' => array(
1,
),
),
'#default_value' => !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_class'] = array(
'#title' => t('CSS class'),
'#description' => t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_class'],
'#dependency' => array(
'edit-options-element-class-enable' => array(
1,
),
'edit-options-element-type-enable' => array(
1,
),
),
'#dependency_count' => 2,
'#fieldset' => 'style_settings',
);
$form['element_label_type_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Customize label HTML'),
'#default_value' => !empty($this->options['element_label_type']) || (string) $this->options['element_label_type'] == '0' || !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_label_type'] = array(
'#title' => t('Label HTML element'),
'#options' => $this
->get_elements(FALSE),
'#type' => 'select',
'#default_value' => $this->options['element_label_type'],
'#description' => t('Choose the HTML element to wrap around this label, e.g. H1, H2, etc.'),
'#dependency' => array(
'edit-options-element-label-type-enable' => array(
1,
),
),
'#fieldset' => 'style_settings',
);
$form['element_label_class_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Create a CSS class'),
'#dependency' => array(
'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',
);
$form['element_label_class'] = array(
'#title' => t('CSS class'),
'#description' => t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_label_class'],
'#dependency' => array(
'edit-options-element-label-class-enable' => array(
1,
),
'edit-options-element-label-type-enable' => array(
1,
),
),
'#dependency_count' => 2,
'#fieldset' => 'style_settings',
);
$form['element_wrapper_type_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Customize field and label wrapper HTML'),
'#default_value' => !empty($this->options['element_wrapper_type']) || (string) $this->options['element_wrapper_type'] == '0' || !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_wrapper_type'] = array(
'#title' => t('Wrapper HTML element'),
'#options' => $this
->get_elements(FALSE),
'#type' => 'select',
'#default_value' => $this->options['element_wrapper_type'],
'#description' => t('Choose the HTML element to wrap around this field and label, e.g. H1, H2, etc. This may not be used if the field and label are not rendered together, such as with a table.'),
'#dependency' => array(
'edit-options-element-wrapper-type-enable' => array(
1,
),
),
'#fieldset' => 'style_settings',
);
$form['element_wrapper_class_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Create a CSS class'),
'#dependency' => array(
'edit-options-element-wrapper-type-enable' => array(
1,
),
),
'#default_value' => !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_wrapper_class'] = array(
'#title' => t('CSS class'),
'#description' => t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_wrapper_class'],
'#dependency' => array(
'edit-options-element-wrapper-class-enable' => array(
1,
),
'edit-options-element-wrapper-type-enable' => array(
1,
),
),
'#dependency_count' => 2,
'#fieldset' => 'style_settings',
);
$form['element_default_classes'] = array(
'#type' => 'checkbox',
'#title' => t('Add default classes'),
'#default_value' => $this->options['element_default_classes'],
'#description' => t('Use default Views classes to identify the field, field label and field content.'),
'#fieldset' => 'style_settings',
);
$form['alter'] = array(
'#title' => t('Rewrite results'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 100,
);
if ($this
->allow_advanced_render()) {
$form['alter']['#tree'] = TRUE;
$form['alter']['alter_text'] = array(
'#type' => 'checkbox',
'#title' => t('Rewrite the output of this field'),
'#description' => t('Enable to override the output of this field with custom text or replacement tokens.'),
'#default_value' => $this->options['alter']['alter_text'],
);
$form['alter']['text'] = array(
'#title' => t('Text'),
'#type' => 'textarea',
'#default_value' => $this->options['alter']['text'],
'#description' => t('The text to display for this field. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
'#dependency' => array(
'edit-options-alter-alter-text' => array(
1,
),
),
);
$form['alter']['make_link'] = array(
'#type' => 'checkbox',
'#title' => t('Output this field as a link'),
'#description' => t('If checked, this field will be made into a link. The destination must be given below.'),
'#default_value' => $this->options['alter']['make_link'],
);
$form['alter']['path'] = array(
'#title' => t('Link path'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['path'],
'#description' => t('The Drupal path or absolute URL for this link. You may enter data from this view as per the "Replacement patterns" below.'),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
'#maxlength' => 255,
);
$form['alter']['absolute'] = array(
'#type' => 'checkbox',
'#title' => t('Use absolute path'),
'#default_value' => $this->options['alter']['absolute'],
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$form['alter']['replace_spaces'] = array(
'#type' => 'checkbox',
'#title' => t('Replace spaces with dashes'),
'#default_value' => $this->options['alter']['replace_spaces'],
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$form['alter']['external'] = array(
'#type' => 'checkbox',
'#title' => t('External server URL'),
'#default_value' => $this->options['alter']['external'],
'#description' => t("Links to an external server using a full URL: e.g. 'http://www.example.com' or 'www.example.com'."),
'#dependency' => array(
'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'),
'#description' => t('When printing url paths, how to transform the case of the filter value.'),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
'#options' => array(
'none' => t('No transform'),
'upper' => t('Upper case'),
'lower' => t('Lower case'),
'ucfirst' => t('Capitalize first letter'),
'ucwords' => t('Capitalize each word'),
),
'#default_value' => $this->options['alter']['path_case'],
);
$form['alter']['link_class'] = array(
'#title' => t('Link class'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['link_class'],
'#description' => t('The CSS class to apply to the link.'),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$form['alter']['alt'] = array(
'#title' => t('Title text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['alt'],
'#description' => t('Text to place as "title" text which most browsers display as a tooltip when hovering over the link.'),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$form['alter']['rel'] = array(
'#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.'),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$form['alter']['prefix'] = array(
'#title' => t('Prefix text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['prefix'],
'#description' => t('Any text to display before this link. You may include HTML.'),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$form['alter']['suffix'] = array(
'#title' => t('Suffix text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['suffix'],
'#description' => t('Any text to display after this link. You may include HTML.'),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$form['alter']['target'] = array(
'#title' => t('Target'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['target'],
'#description' => t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used."),
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
),
);
$options = array();
foreach ($this->view->display_handler
->get_handlers('field') as $field => $handler) {
$options[t('Fields')]["[{$field}]"] = $handler
->ui_name();
if ($field == $this->options['id']) {
break;
}
}
$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(),
));
}
$this
->document_self_tokens($options[t('Fields')]);
$output = t('<p>You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');
if (!empty($options)) {
$output = t('<p>The following tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.
If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.</p>');
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = array();
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . check_plain($value);
}
$output .= theme('item_list', array(
'items' => $items,
'type' => $type,
));
}
}
}
$form['alter']['help'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $output,
'#dependency' => array(
'edit-options-alter-make-link' => array(
1,
),
'edit-options-alter-alter-text' => array(
1,
),
'edit-options-alter-more-link' => array(
1,
),
),
);
$form['alter']['trim'] = array(
'#type' => 'checkbox',
'#title' => t('Trim this field to a maximum length'),
'#description' => t('Enable to trim the field to a maximum length of characters'),
'#default_value' => $this->options['alter']['trim'],
);
$form['alter']['max_length'] = array(
'#title' => t('Maximum length'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['max_length'],
'#description' => t('The maximum number of characters this field can be.'),
'#dependency' => array(
'edit-options-alter-trim' => array(
1,
),
),
);
$form['alter']['word_boundary'] = array(
'#type' => 'checkbox',
'#title' => t('Trim only on a word boundary'),
'#description' => t('If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.'),
'#default_value' => $this->options['alter']['word_boundary'],
'#dependency' => array(
'edit-options-alter-trim' => array(
1,
),
),
);
$form['alter']['ellipsis'] = array(
'#type' => 'checkbox',
'#title' => t('Add an ellipsis'),
'#description' => t('If checked, a "..." will be added if a field was trimmed.'),
'#default_value' => $this->options['alter']['ellipsis'],
'#dependency' => array(
'edit-options-alter-trim' => array(
1,
),
),
);
$form['alter']['more_link'] = array(
'#type' => 'checkbox',
'#title' => t('Add a read-more link if output is trimmed.'),
'#description' => t('If checked, a read-more link will be added at the end of the trimmed output'),
'#default_value' => $this->options['alter']['more_link'],
'#dependency' => array(
'edit-options-alter-trim' => array(
1,
),
),
);
$form['alter']['more_link_text'] = array(
'#type' => 'textfield',
'#title' => t('More link text'),
'#default_value' => $this->options['alter']['more_link_text'],
'#description' => t('The text which will be displayed on the more link. You may enter data from this view as per the "Replacement patterns" above.'),
'#dependency_count' => 2,
'#dependency' => array(
'edit-options-alter-trim' => array(
1,
),
'edit-options-alter-more-link' => array(
1,
),
),
);
$form['alter']['more_link_path'] = array(
'#type' => 'textfield',
'#title' => t('More link path'),
'#default_value' => $this->options['alter']['more_link_path'],
'#description' => t('The path which is used for the more link. You may enter data from this view as per the "Replacement patterns" above.'),
'#dependency_count' => 2,
'#dependency' => array(
'edit-options-alter-trim' => array(
1,
),
'edit-options-alter-more-link' => array(
1,
),
),
);
$form['alter']['html'] = array(
'#type' => 'checkbox',
'#title' => t('Field can contain HTML'),
'#description' => t('If checked, HTML corrector will be run to ensure tags are properly closed after trimming.'),
'#default_value' => $this->options['alter']['html'],
'#dependency' => array(
'edit-options-alter-trim' => array(
1,
),
),
);
$form['alter']['strip_tags'] = array(
'#type' => 'checkbox',
'#title' => t('Strip HTML tags'),
'#description' => t('If checked, all HTML tags will be stripped.'),
'#default_value' => $this->options['alter']['strip_tags'],
);
$form['alter']['preserve_tags'] = array(
'#type' => 'textfield',
'#title' => t('Preserve certain tags'),
'#description' => t('List the tags that need to be preserved during the stripping process. example "<p> <br>" which will preserve all p and br elements'),
'#default_value' => $this->options['alter']['preserve_tags'],
'#dependency' => array(
'edit-options-alter-strip-tags' => array(
1,
),
),
);
$form['alter']['trim_whitespace'] = array(
'#type' => 'checkbox',
'#title' => t('Remove whitespace'),
'#description' => t('If checked, all whitespaces at the beginning and the end of the output will be removed.'),
'#default_value' => $this->options['alter']['trim_whitespace'],
);
$form['alter']['nl2br'] = array(
'#type' => 'checkbox',
'#title' => t('Convert newlines to HTML <br> tags'),
'#description' => t('If checked, all newlines chars (e.g. \\n) are converted into HTML <br> tags.'),
'#default_value' => $this->options['alter']['nl2br'],
);
}
$form['empty_field_behavior'] = array(
'#type' => 'fieldset',
'#title' => t('No results behavior'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 100,
);
$form['empty'] = array(
'#type' => 'textarea',
'#title' => t('No results text'),
'#default_value' => $this->options['empty'],
'#description' => t('Provide text to display if this field contains an empty result. You may include HTML. You may enter data from this view as per the "Replacement patterns" in the "Rewrite Results" section below.'),
'#fieldset' => 'empty_field_behavior',
);
$form['empty_zero'] = array(
'#type' => 'checkbox',
'#title' => t('Count the number 0 as empty'),
'#default_value' => $this->options['empty_zero'],
'#description' => t('Enable to display the "no results text" if the field contains the number 0.'),
'#fieldset' => 'empty_field_behavior',
);
$form['hide_empty'] = array(
'#type' => 'checkbox',
'#title' => t('Hide if empty'),
'#default_value' => $this->options['hide_empty'],
'#description' => t('Enable to hide this field if it is empty. Note that the field label or rewritten output may still be displayed. To hide labels, check the style or row style settings for empty fields. To hide rewritten content, check the "Hide rewriting if empty" checkbox.'),
'#fieldset' => 'empty_field_behavior',
);
$form['hide_alter_empty'] = array(
'#type' => 'checkbox',
'#title' => t('Hide rewriting if empty'),
'#default_value' => $this->options['hide_alter_empty'],
'#description' => t('Do not display rewritten content if this field is empty.'),
'#fieldset' => 'empty_field_behavior',
);
}
public function admin_summary() {
return $this
->label();
}
public function pre_render(&$values) {
}
public function render($values) {
$value = $this
->get_value($values);
return $this
->sanitize_value($value);
}
public function advanced_render($values) {
if ($this->last_render_index != $this->view->row_index) {
$this->last_render_text = '';
}
if ($this
->allow_advanced_render() && method_exists($this, 'render_item')) {
$raw_items = $this
->get_items($values);
if (empty($raw_items)) {
$this->original_value = NULL;
}
}
else {
$value = $this
->render($values);
if (is_array($value)) {
$value = drupal_render($value);
}
$this->last_render = $value;
$this->original_value = $value;
}
if ($this
->allow_advanced_render()) {
$tokens = NULL;
if (method_exists($this, 'render_item')) {
$items = array();
foreach ($raw_items as $count => $item) {
$value = $this
->render_item($count, $item);
if (is_array($value)) {
$value = drupal_render($value);
}
$this->last_render = $value;
$this->original_value = $this->last_render;
$alter = $item + $this->options['alter'];
$alter['phase'] = VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM;
$items[] = $this
->render_text($alter);
}
$value = $this
->render_items($items);
}
else {
$alter = array(
'phase' => VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY,
) + $this->options['alter'];
$value = $this
->render_text($alter);
}
if (is_array($value)) {
$value = drupal_render($value);
}
$this->last_render = $value;
}
if (empty($this->last_render)) {
if ($this
->is_value_empty($this->last_render, $this->options['empty_zero'], FALSE)) {
$alter = $this->options['alter'];
$alter['alter_text'] = 1;
$alter['text'] = $this->options['empty'];
$alter['phase'] = VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY;
$this->last_render = $this
->render_text($alter);
}
}
if ((string) $this->last_render !== '') {
$this->last_render_index = $this->view->row_index;
}
return $this->last_render;
}
public function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
if (!isset($value)) {
$empty = TRUE;
}
else {
$empty = $empty_zero || $value !== 0 && $value !== '0';
}
if ($no_skip_empty) {
$empty = empty($value) && $empty;
}
return $empty;
}
public function render_text($alter) {
$value = $this->last_render;
if (!empty($alter['alter_text']) && $alter['text'] !== '') {
$tokens = $this
->get_render_tokens($alter);
$value = $this
->render_altered($alter, $tokens);
}
if (!empty($this->options['alter']['trim_whitespace'])) {
$value = trim($value);
}
$no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this
->is_value_empty($this->original_value, $this->options['empty_zero']);
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)) {
return '';
}
if ($alter['phase'] == VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty) {
return $value;
}
if (!empty($alter['strip_tags'])) {
$value = strip_tags($value, $alter['preserve_tags']);
}
$suffix = '';
if (!empty($alter['trim']) && !empty($alter['max_length'])) {
$length = strlen($value);
$value = $this
->render_trim_text($alter, $value);
if ($this->options['alter']['more_link'] && strlen($value) < $length) {
$tokens = $this
->get_render_tokens($alter);
$more_link_text = $this->options['alter']['more_link_text'] ? $this->options['alter']['more_link_text'] : t('more');
$more_link_text = strtr(filter_xss_admin($more_link_text), $tokens);
$more_link_path = $this->options['alter']['more_link_path'];
$more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens)));
$base_path = base_path();
if (strpos($more_link_path, $base_path) === 0) {
$more_link_path = drupal_substr($more_link_path, drupal_strlen($base_path));
}
$more_link = l($more_link_text, $more_link_path, array(
'attributes' => array(
'class' => array(
'views-more-link',
),
),
));
$suffix .= " " . $more_link;
}
}
if (!empty($alter['nl2br'])) {
$value = nl2br($value);
}
$this->last_render_text = $value;
if (!empty($alter['make_link']) && !empty($alter['path'])) {
if (!isset($tokens)) {
$tokens = $this
->get_render_tokens($alter);
}
$value = $this
->render_as_link($alter, $value, $tokens);
}
return $value . $suffix;
}
public function render_altered($alter, $tokens) {
$value = $alter['text'];
$value = strtr($value, $tokens);
$value = strtr($value, array(
'%5B' => '[',
'%5D' => ']',
));
return $value;
}
public function render_trim_text($alter, $value) {
if (!empty($alter['strip_tags'])) {
$this->definition['element type'] = 'span';
}
return views_trim_text($alter, $value);
}
public function render_as_link($alter, $text, $tokens) {
$value = '';
if (!empty($alter['prefix'])) {
$value .= filter_xss_admin(strtr($alter['prefix'], $tokens));
}
$options = array(
'html' => TRUE,
'absolute' => !empty($alter['absolute']) ? TRUE : FALSE,
);
$path = $alter['path'];
if ($path != '<front>') {
$path = strip_tags(decode_entities(strtr($path, $tokens)));
if (!empty($alter['path_case']) && $alter['path_case'] != 'none') {
$path = $this
->case_transform($path, $this->options['alter']['path_case']);
}
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);
}
}
}
$url = parse_url($path);
if (empty($url)) {
return $text;
}
if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) {
return $text;
}
if ($alter['external']) {
if (!isset($url['scheme'])) {
$path = "http://{$path}";
$url = parse_url($path);
}
}
if (isset($url['query'])) {
$path = strtr($path, array(
'?' . $url['query'] => '',
));
$query = drupal_get_query_array($url['query']);
foreach ($query as $param => $val) {
if ($val == '%' . $param) {
unset($query[$param]);
}
}
$options['query'] = $query;
}
if (isset($url['fragment'])) {
$path = strtr($path, array(
'#' . $url['fragment'] => '',
));
if ($path == '') {
$options['external'] = TRUE;
}
$options['fragment'] = $url['fragment'];
}
$alt = strtr($alter['alt'], $tokens);
if ($alt && $alt != $text) {
$options['attributes']['title'] = decode_entities($alt);
}
$class = strtr($alter['link_class'], $tokens);
if ($class) {
$options['attributes']['class'] = array(
$class,
);
}
if (!empty($alter['rel']) && ($rel = strtr($alter['rel'], $tokens))) {
$options['attributes']['rel'] = $rel;
}
$target = check_plain(trim(strtr($alter['target'], $tokens)));
if (!empty($target)) {
$options['attributes']['target'] = $target;
}
if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) {
foreach ($alter['link_attributes'] as $key => $attribute) {
if (!isset($options['attributes'][$key])) {
$options['attributes'][$key] = strtr($attribute, $tokens);
}
}
}
if (isset($alter['query'])) {
$options['query'] = drupal_http_build_query($alter['query']);
$options['query'] = strtr($options['query'], $tokens);
$options['query'] = drupal_get_query_array($options['query']);
}
if (isset($alter['alias'])) {
$options['alias'] = $alter['alias'];
}
if (isset($alter['fragment'])) {
$options['fragment'] = strtr($alter['fragment'], $tokens);
}
if (isset($alter['language'])) {
$options['language'] = $alter['language'];
}
if (isset($alter['entity'])) {
$options['entity'] = $alter['entity'];
}
if (isset($alter['entity_type'])) {
$options['entity_type'] = $alter['entity_type'];
}
$value .= l($text, $path, $options);
if (!empty($alter['suffix'])) {
$value .= filter_xss_admin(strtr($alter['suffix'], $tokens));
}
return $value;
}
public function get_render_tokens($item) {
$tokens = array();
if (!empty($this->view->build_info['substitutions'])) {
$tokens = $this->view->build_info['substitutions'];
}
$count = 0;
foreach ($this->view->display_handler
->get_handlers('argument') as $arg => $handler) {
$token = '%' . ++$count;
if (!isset($tokens[$token])) {
$tokens[$token] = '';
}
$tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
}
$tokens += $this
->get_token_values_recursive($_GET);
foreach ($this->view->display_handler
->get_handlers('field') as $field => $handler) {
if (isset($handler->last_render)) {
$tokens["[{$field}]"] = $handler->last_render;
}
else {
$tokens["[{$field}]"] = '';
}
if (!empty($item)) {
$this
->add_self_tokens($tokens, $item);
}
if ($field == $this->options['id']) {
break;
}
}
$this->view->style_plugin->render_tokens[$this->view->row_index] = $tokens;
$this->last_tokens = $tokens;
return $tokens;
}
public function get_token_values_recursive(array $array, array $parent_keys = array()) {
$tokens = array();
foreach ($array as $param => $val) {
if (is_array($val)) {
$child_parent_keys = $parent_keys;
$child_parent_keys[] = $param;
$child_tokens = $this
->get_token_values_recursive($val, $child_parent_keys);
$tokens += $child_tokens;
}
else {
$token_string = !empty($parent_keys) ? implode('_', $parent_keys) . '_' . $param : $param;
$tokens['%' . $token_string] = strip_tags(decode_entities($val));
}
}
return $tokens;
}
public function add_self_tokens(&$tokens, $item) {
}
public function document_self_tokens(&$tokens) {
}
public function theme($values) {
return theme($this
->theme_functions(), array(
'view' => $this->view,
'field' => $this,
'row' => $values,
));
}
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 . '__' . $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 . '__' . $display->display_plugin . '__' . $this->options['id'];
$themes[] = $hook . '__' . $display->display_plugin;
}
}
$themes[] = $hook . '__' . $this->view->name . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->name;
$themes[] = $hook . '__' . $this->options['id'];
$themes[] = $hook;
return $themes;
}
public function ui_name($short = FALSE) {
return $this
->get_field(parent::ui_name($short));
}
}
class views_handler_field_broken extends views_handler_field {
public function ui_name($short = FALSE) {
return t('Broken/missing handler');
}
public function ensure_my_table() {
}
public function query($group_by = FALSE) {
}
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>',
);
}
public function broken() {
return TRUE;
}
}
class views_handler_field_file_size extends views_handler_field {
public function option_definition() {
$options = parent::option_definition();
$options['file_size_display'] = array(
'default' => 'formatted',
);
return $options;
}
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['file_size_display'] = array(
'#title' => t('File size display'),
'#type' => 'select',
'#options' => array(
'formatted' => t('Formatted (in KB or MB)'),
'bytes' => t('Raw bytes'),
),
);
}
public function render($values) {
$value = $this
->get_value($values);
if ($value) {
switch ($this->options['file_size_display']) {
case 'bytes':
return $value;
case 'formatted':
default:
return format_size($value);
}
}
else {
return '';
}
}
}
class views_handler_field_xss extends views_handler_field {
public function render($values) {
$value = $this
->get_value($values);
return $this
->sanitize_value($value, 'xss');
}
}