twitter_views_field_handlers.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Process Twitter-style @usernames and URLs before filtering XSS.
  4. */
  5. class twitter_views_handler_field_xss extends views_handler_field {
  6. function option_definition() {
  7. $conf = TwitterConf::instance();
  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://' . $conf->get('search') . '/search?q=%23');
  13. return $options;
  14. }
  15. function options_form(&$form, &$form_state) {
  16. parent::options_form($form, $form_state);
  17. $form['link_urls'] = array(
  18. '#title' => t('Link urls to their destinations'),
  19. '#type' => 'checkbox',
  20. '#default_value' => !empty($this->options['link_urls']),
  21. );
  22. $form['link_usernames'] = array(
  23. '#title' => t('Link Twitter @usernames to their Twitter.com urls'),
  24. '#type' => 'checkbox',
  25. '#default_value' => !empty($this->options['link_usernames']),
  26. );
  27. $form['link_hashtags'] = array(
  28. '#title' => t('Link Twitter #hashtags to another url'),
  29. '#type' => 'checkbox',
  30. '#default_value' => !empty($this->options['link_hashtags']),
  31. );
  32. $form['hashtags_url'] = array(
  33. '#type' => 'textfield',
  34. '#default_value' => $this->options['hashtags_url'],
  35. '#process' => array('ctools_dependent_process'),
  36. '#dependency' => array('edit-options-link-hashtags' => array(TRUE)),
  37. );
  38. }
  39. function render($values) {
  40. $value = $values->{$this->field_alias};
  41. if (!empty($this->options['link_urls'])) {
  42. $filter = new stdClass;
  43. $filter->settings = array(
  44. 'filter_url_length' => 496,
  45. );
  46. $value = _filter_url($value, $filter);
  47. }
  48. if (!empty($this->options['link_usernames'])) {
  49. $conf = TwitterConf::instance();
  50. $value = _twitter_filter_text($value, '@', 'http://' . $conf->get('host') . '/');
  51. } if (!empty($this->options['link_hashtags']) && valid_url($this->options['hashtags_url'])) {
  52. $value = _twitter_filter_text($value, '#', url($this->options['hashtags_url']));
  53. }
  54. return filter_xss($value);
  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', array('path' => $value));
  64. }
  65. }