/[drupal]/contributions/modules/twitter/twitter_views_field_handlers.inc
ViewVC logotype

Contents of /contributions/modules/twitter/twitter_views_field_handlers.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Sep 7 23:59:31 2008 UTC (14 months, 2 weeks ago) by eaton
Branch: MAIN
CVS Tags: DRUPAL-6--2-5, DRUPAL-6--2-4, DRUPAL-6--2-3, DRUPAL-6--2-2, DRUPAL-6--2-1, DRUPAL-6--2-0, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--3
Changes since 1.1: +1 -1 lines
File MIME type: text/x-php
Changing the default hashtag destination to search.twitter.com.
1 <?php
2
3 /**
4 * Process Twitter-style @usernames and URLs before filtering XSS.
5 */
6 class twitter_views_handler_field_xss extends views_handler_field {
7 function option_definition() {
8 $options = parent::option_definition();
9 $options['link_urls'] = array('default' => TRUE);
10 $options['link_usernames'] = array('default' => TRUE);
11 $options['link_hashtags'] = array('default' => FALSE);
12 $options['hashtags_url'] = array('default' => 'http://search.twitter.com/search?q=%23');
13 return $options;
14 }
15
16 function options_form(&$form, &$form_state) {
17 parent::options_form($form, $form_state);
18 $form['link_urls'] = array(
19 '#title' => t('Link urls to their destinations'),
20 '#type' => 'checkbox',
21 '#default_value' => !empty($this->options['link_urls']),
22 );
23 $form['link_usernames'] = array(
24 '#title' => t('Link Twitter @usernames to their Twitter.com urls'),
25 '#type' => 'checkbox',
26 '#default_value' => !empty($this->options['link_usernames']),
27 );
28 $form['link_hashtags'] = array(
29 '#title' => t('Link Twitter #hashtags to another url'),
30 '#type' => 'checkbox',
31 '#default_value' => !empty($this->options['link_hashtags']),
32 );
33 $form['hashtags_url'] = array(
34 '#type' => 'textfield',
35 '#default_value' => $this->options['hashtags_url'],
36 '#process' => array('views_process_dependency'),
37 '#dependency' => array('edit-options-link-hashtags' => array(TRUE)),
38 );
39 }
40
41 function render($values) {
42 $value = $values->{$this->field_alias};
43 if (!empty($this->options['link_urls'])) {
44 $value = _filter_url($value, FILTER_DEFAULT);
45 }
46 if (!empty($this->options['link_usernames'])) {
47 $value = twitter_link_filter($value);
48 }
49 if (!empty($this->options['link_hashtags']) && valid_url($this->options['hashtags_url'])) {
50 $value = twitter_link_filter($value, '#', url($this->options['hashtags_url']));
51 }
52 return filter_xss($value);
53 }
54 }
55
56
57 /**
58 * Field handler to provide simple renderer that turns a URL into a clickable link.
59 */
60 class twitter_views_handler_field_profile_image extends views_handler_field {
61 function render($values) {
62 $value = $values->{$this->field_alias};
63 return theme('image', $value, '', '', array(), FALSE);
64 }
65 }
66

  ViewVC Help
Powered by ViewVC 1.1.2