Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 2.21 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // $Id$
  3.  
  4. class labs_views_handler_field_description extends views_handler_field {
  5.   var $field_alias = 'unknown';
  6.   var $aliases = array();
  7.  
  8.   function allow_advanced_render() { return FALSE; }
  9.  
  10.   /**
  11.    * Override of query() method. Add feed URL field for smarter handling of formatting.
  12.    */
  13.   /*
  14.   function query() {
  15.     parent::query();
  16.     $table = $this->query->ensure_table('feedapi');
  17.     $this->feed_url_field = $this->query->add_field($table, 'url');
  18.   }
  19.   */
  20.  
  21.   /**
  22.    * Render the feed item field.
  23.    */
  24.   function render($values) {
  25.     $url = $values->{$this->feed_url_field};
  26.  
  27.     // Attempt to autodetect filter type.
  28.     $type = 'drupal';
  29.     if (strpos($url, 'drupal.org')) {
  30.       $type = 'drupal';
  31.     }
  32.     else if (strpos($url, 'github.com')) {
  33.       $type = 'github';
  34.     }
  35.     else if (strpos($url, 'cvsdude.com')) {
  36.       $type = 'cvsdude';
  37.     }
  38.  
  39.     $output = '';
  40.     $output = $values->{$this->field_alias};
  41.     $output = explode("\n", $output);
  42.  
  43.     switch ($type) {
  44.       case 'drupal':
  45.         // Replace relative links with absolute links, and add the target attribute
  46.         foreach ($output as $k => $v) {
  47.           $output[$k] = str_replace('href="/', 'target="_blank" href="http://drupal.org/', $v);
  48.         }
  49.  
  50.         // First line is byline.
  51.         $byline = array_shift($output);
  52.         // Yank out timestamp -- we'll use our own
  53.         $byline = preg_replace(array('/(at [0-9:]{0,5})/'), array(''), $byline, 1);
  54.  
  55.         // The second line is the list of modified files. Kill it.
  56.         array_shift($output);
  57.         $output = implode("<br/>", $output);
  58.         break;
  59.       case 'github':
  60.         $byline = '';
  61.         foreach ($output as $k => $line) {
  62.           if (strpos($line, 'm ') === 0) {
  63.             $byline .= "<code class='path'>$line</code>";
  64.             unset($output[$k]);
  65.           }
  66.         }
  67.         $output = implode("\n", $output);
  68.         break;
  69.     }
  70.  
  71.     // Add markup
  72.     $byline = !empty($byline) ? "<div class='commit-byline'>{$byline}</div>" : '';
  73.     $output = "<div class='commit-message'>{$output}</div>";
  74.     $output = $byline . $output;
  75.     $output = filter_xss_admin($output);
  76.  
  77.     return $output;
  78.   }
  79. }