1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Contains views_handler_area_text handler. |
---|
6 | */ |
---|
7 | |
---|
8 | /** |
---|
9 | * Views area text handler. |
---|
10 | * @ingroup views_area_handlers Views' area handlers |
---|
11 | */ |
---|
12 | class views_handler_area_text extends views_handler_area { |
---|
13 | |
---|
14 | function option_definition() { |
---|
15 | $options = parent::option_definition(); |
---|
16 | $options['content'] = array('default' => '', 'translatable' => TRUE, 'format_key' => 'format'); |
---|
17 | $options['format'] = array('default' => variable_get('filter_default_format', 1)); |
---|
18 | $options['tokenize'] = array('default' => FALSE); |
---|
19 | return $options; |
---|
20 | } |
---|
21 | |
---|
22 | function options_form(&$form, &$form_state) { |
---|
23 | parent::options_form($form, $form_state); |
---|
24 | |
---|
25 | $form['content'] = array( |
---|
26 | '#type' => 'textarea', |
---|
27 | '#default_value' => $this->options['content'], |
---|
28 | '#rows' => 6, |
---|
29 | ); |
---|
30 | |
---|
31 | $form['format'] = filter_form($this->options['format']); |
---|
32 | |
---|
33 | $form['tokenize'] = array( |
---|
34 | '#type' => 'checkbox', |
---|
35 | '#title' => t('Use replacement tokens from the first row'), |
---|
36 | '#default_value' => $this->options['tokenize'], |
---|
37 | ); |
---|
38 | |
---|
39 | // Get a list of the available fields and arguments for token replacement. |
---|
40 | $options = array(); |
---|
41 | foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) { |
---|
42 | $options[t('Fields')]["[$field]"] = $handler->ui_name(); |
---|
43 | } |
---|
44 | |
---|
45 | $count = 0; // This lets us prepare the key as we want it printed. |
---|
46 | foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) { |
---|
47 | $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name())); |
---|
48 | $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name())); |
---|
49 | } |
---|
50 | |
---|
51 | if (!empty($options)) { |
---|
52 | $output = '<p>' . t('The following tokens are available. If you would like to have the characters %5B and %5D please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.)' . '</p>'); |
---|
53 | foreach (array_keys($options) as $type) { |
---|
54 | if (!empty($options[$type])) { |
---|
55 | $items = array(); |
---|
56 | foreach ($options[$type] as $key => $value) { |
---|
57 | $items[] = $key . ' == ' . $value; |
---|
58 | } |
---|
59 | $output .= theme('item_list', |
---|
60 | array( |
---|
61 | 'items' => $items, |
---|
62 | 'type' => $type |
---|
63 | )); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | $form['token_help'] = array( |
---|
68 | '#type' => 'fieldset', |
---|
69 | '#title' => t('Replacement patterns'), |
---|
70 | '#collapsible' => TRUE, |
---|
71 | '#collapsed' => TRUE, |
---|
72 | '#value' => $output, |
---|
73 | '#id' => 'edit-options-token-help', |
---|
74 | '#dependency' => array( |
---|
75 | 'edit-options-tokenize' => array(1), |
---|
76 | ), |
---|
77 | '#prefix' => '<div>', |
---|
78 | '#suffix' => '</div>', |
---|
79 | ); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | function options_submit(&$form, &$form_state) { |
---|
84 | $form_state['values']['options']['format'] = $form_state['values']['format']; |
---|
85 | parent::options_submit($form, $form_state); |
---|
86 | } |
---|
87 | |
---|
88 | function render($empty = FALSE) { |
---|
89 | $format = isset($this->options['format']) ? $this->options['format'] : FILTER_FORMAT_DEFAULT; |
---|
90 | if (!$empty || !empty($this->options['empty'])) { |
---|
91 | return $this->render_textarea($this->options['content'], $format); |
---|
92 | } |
---|
93 | return ''; |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * Render a text area, using the proper format. |
---|
98 | */ |
---|
99 | function render_textarea($value, $format) { |
---|
100 | static $formats = array(); |
---|
101 | |
---|
102 | // Check to make sure the filter format exists; if not, we don't |
---|
103 | // display anything. |
---|
104 | $format = filter_resolve_format($format); |
---|
105 | |
---|
106 | if (!array_key_exists($format, $formats)) { |
---|
107 | $formats[$format] = db_result(db_query("SELECT name FROM {filter_formats} WHERE format = %d", $format)); |
---|
108 | } |
---|
109 | |
---|
110 | if (!isset($formats[$format])) { |
---|
111 | return; |
---|
112 | } |
---|
113 | |
---|
114 | if ($value) { |
---|
115 | if ($this->options['tokenize']) { |
---|
116 | $value = $this->view->style_plugin->tokenize_value($value, 0); |
---|
117 | } |
---|
118 | return check_markup($value, $format, FALSE); |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|