-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter_views_field_handlers.inc
68 lines (63 loc) · 2.33 KB
/
twitter_views_field_handlers.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Process Twitter-style @usernames and URLs before filtering XSS.
*/
class twitter_views_handler_field_xss extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['link_urls'] = array('default' => TRUE);
$options['link_usernames'] = array('default' => TRUE);
$options['link_hashtags'] = array('default' => FALSE);
$options['hashtags_url'] = array('default' => TWITTER_SEARCH);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_urls'] = array(
'#title' => t('Link urls to their destinations'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_urls']),
);
$form['link_usernames'] = array(
'#title' => t('Link Twitter @usernames to their Twitter.com urls'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_usernames']),
);
$form['link_hashtags'] = array(
'#title' => t('Link Twitter #hashtags to another url'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_hashtags']),
);
$form['hashtags_url'] = array(
'#type' => 'textfield',
'#default_value' => $this->options['hashtags_url'],
'#process' => array('ctools_dependent_process'),
'#dependency' => array('edit-options-link-hashtags' => array(TRUE)),
);
}
function render($values) {
$value = $values->{$this->field_alias};
if (!empty($this->options['link_urls'])) {
$filter = new stdClass;
$filter->settings = array(
'filter_url_length' => 496,
);
$value = _filter_url($value, $filter);
}
if (!empty($this->options['link_usernames'])) {
$value = _twitter_filter_text($value, '@', TWITTER_HOMEPAGE);
} if (!empty($this->options['link_hashtags']) && valid_url($this->options['hashtags_url'])) {
$value = _twitter_filter_text($value, '#', url($this->options['hashtags_url']));
}
return filter_xss($value);
}
}
/**
* Field handler to provide simple renderer that turns a URL into a clickable link.
*/
class twitter_views_handler_field_profile_image extends views_handler_field {
function render($values) {
$value = $values->{$this->field_alias};
return theme('image', array('path' => $value));
}
}