- <?php
- // $Id$
- class labs_views_handler_field_description extends views_handler_field {
- var $field_alias = 'unknown';
- var $aliases = array();
- function allow_advanced_render() { return FALSE; }
- /**
- * Override of query() method. Add feed URL field for smarter handling of formatting.
- */
- /*
- function query() {
- parent::query();
- $table = $this->query->ensure_table('feedapi');
- $this->feed_url_field = $this->query->add_field($table, 'url');
- }
- */
- /**
- * Render the feed item field.
- */
- function render($values) {
- $url = $values->{$this->feed_url_field};
- // Attempt to autodetect filter type.
- $type = 'drupal';
- if (strpos($url, 'drupal.org')) {
- $type = 'drupal';
- }
- else if (strpos($url, 'github.com')) {
- $type = 'github';
- }
- else if (strpos($url, 'cvsdude.com')) {
- $type = 'cvsdude';
- }
- $output = '';
- $output = $values->{$this->field_alias};
- $output = explode("\n", $output);
- switch ($type) {
- case 'drupal':
- // Replace relative links with absolute links, and add the target attribute
- foreach ($output as $k => $v) {
- $output[$k] = str_replace('href="/', 'target="_blank" href="http://drupal.org/', $v);
- }
- // First line is byline.
- $byline = array_shift($output);
- // Yank out timestamp -- we'll use our own
- $byline = preg_replace(array('/(at [0-9:]{0,5})/'), array(''), $byline, 1);
- // The second line is the list of modified files. Kill it.
- array_shift($output);
- $output = implode("<br/>", $output);
- break;
- case 'github':
- $byline = '';
- foreach ($output as $k => $line) {
- if (strpos($line, 'm ') === 0) {
- $byline .= "<code class='path'>$line</code>";
- unset($output[$k]);
- }
- }
- $output = implode("\n", $output);
- break;
- }
- // Add markup
- $byline = !empty($byline) ? "<div class='commit-byline'>{$byline}</div>" : '';
- $output = "<div class='commit-message'>{$output}</div>";
- $output = $byline . $output;
- $output = filter_xss_admin($output);
- return $output;
- }
- }