| 1 |
<?php
|
| 2 |
// $Id: views_handler_field_weblinks.inc,v 1.1.2.7.2.1 2009/04/11 18:10:35 nancyw Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Provide views data and handlers for weblinks.module
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Field handler to provide an embedded image.
|
| 10 |
*
|
| 11 |
* @ingroup views_field_handlers
|
| 12 |
*/
|
| 13 |
class views_handler_field_weblinks extends views_handler_field {
|
| 14 |
/**
|
| 15 |
* Modify the query to make sure title is available.
|
| 16 |
*/
|
| 17 |
function construct() {
|
| 18 |
$this->additional_fields['title'] = array('table' => 'node', 'field' => 'title');
|
| 19 |
}
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Define options available for this field.
|
| 23 |
*/
|
| 24 |
function option_definition() {
|
| 25 |
$options = parent::option_definition();
|
| 26 |
$options['link_type'] = array('default' => 'url');
|
| 27 |
return $options;
|
| 28 |
}
|
| 29 |
|
| 30 |
/**
|
| 31 |
* Build option configuration form.
|
| 32 |
*/
|
| 33 |
function options_form(&$form, &$form_state) {
|
| 34 |
parent::options_form($form, $form_state);
|
| 35 |
|
| 36 |
$form['link_type'] = array(
|
| 37 |
'#title' => t('Show link as'),
|
| 38 |
'#type' => 'select',
|
| 39 |
'#options' => array(
|
| 40 |
'url' => 'URL',
|
| 41 |
'text' => 'Text',
|
| 42 |
'title' => 'Title',
|
| 43 |
'visit' => '"Link displays as" setting',
|
| 44 |
),
|
| 45 |
'#default_value' => $this->options['link_type'],
|
| 46 |
);
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Render field output to the browser.
|
| 51 |
*/
|
| 52 |
function render($values) {
|
| 53 |
$title = $values->{$this->aliases['title']};
|
| 54 |
$url = $values->{$this->field_alias};
|
| 55 |
$type = $this->options['link_type'];
|
| 56 |
switch ($type) {
|
| 57 |
case 'url':
|
| 58 |
$link = l($url, $url, _weblinks_set_attributes());
|
| 59 |
return l($url, $url, _weblinks_set_attributes());
|
| 60 |
|
| 61 |
case 'title':
|
| 62 |
return l($title, $url, _weblinks_set_attributes());
|
| 63 |
|
| 64 |
case 'visit':
|
| 65 |
$values->url = $url;
|
| 66 |
$values->title = $title;
|
| 67 |
return theme('weblinks_node_view', $values, _weblinks_set_attributes(), NULL);
|
| 68 |
|
| 69 |
default: // Also 'text'
|
| 70 |
return check_plain($url);
|
| 71 |
}
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
function _weblinks_set_attributes() {
|
| 76 |
$options = array('attributes' => array('rel' => 'tag'));
|
| 77 |
if (variable_get('weblinks_external', TRUE)) {
|
| 78 |
$options['attributes']['target'] = '_blank';
|
| 79 |
}
|
| 80 |
|
| 81 |
if (variable_get('weblinks_nofollow', FALSE)) {
|
| 82 |
$options['attributes']['rel'] = 'nofollow, tag';
|
| 83 |
}
|
| 84 |
return $options;
|
| 85 |
}
|