1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains the file RSS row style plugin.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Plugin which performs a file_view on the resulting object
|
10
|
* and formats it as an RSS item.
|
11
|
*/
|
12
|
class views_plugin_row_file_rss extends views_plugin_row {
|
13
|
// Basic properties that let the row style follow relationships.
|
14
|
var $base_table = 'file_managed';
|
15
|
var $base_field = 'fid';
|
16
|
|
17
|
// Stores the files loaded with pre_render.
|
18
|
var $files = array();
|
19
|
|
20
|
function option_definition() {
|
21
|
$options = parent::option_definition();
|
22
|
|
23
|
$options['item_length'] = array('default' => 'default');
|
24
|
$options['links'] = array('default' => FALSE, 'bool' => TRUE);
|
25
|
|
26
|
return $options;
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* Override init function to convert fulltext view-mode to full.
|
31
|
*/
|
32
|
function init(&$view, &$display, $options = NULL) {
|
33
|
parent::init($view, $display, $options);
|
34
|
|
35
|
if ($this->options['item_length'] == 'fulltext') {
|
36
|
$this->options['item_length'] = 'full';
|
37
|
}
|
38
|
}
|
39
|
|
40
|
function options_form(&$form, &$form_state) {
|
41
|
parent::options_form($form, $form_state);
|
42
|
|
43
|
$form['item_length'] = array(
|
44
|
'#type' => 'select',
|
45
|
'#title' => t('Display type'),
|
46
|
'#options' => $this->options_form_summary_options(),
|
47
|
'#default_value' => $this->options['item_length'],
|
48
|
);
|
49
|
$form['links'] = array(
|
50
|
'#type' => 'checkbox',
|
51
|
'#title' => t('Display links'),
|
52
|
'#default_value' => $this->options['links'],
|
53
|
);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Return the main options, which are shown in the summary title.
|
58
|
*/
|
59
|
function options_form_summary_options() {
|
60
|
$entity_info = entity_get_info('file');
|
61
|
$options = array();
|
62
|
if (!empty($entity_info['view modes'])) {
|
63
|
foreach ($entity_info['view modes'] as $mode => $settings) {
|
64
|
$options[$mode] = $settings['label'];
|
65
|
}
|
66
|
}
|
67
|
$options['title'] = t('Title only');
|
68
|
$options['default'] = t('Use site default RSS settings');
|
69
|
return $options;
|
70
|
}
|
71
|
|
72
|
function summary_title() {
|
73
|
$options = $this->options_form_summary_options();
|
74
|
return check_plain($options[$this->options['item_length']]);
|
75
|
}
|
76
|
|
77
|
|
78
|
function pre_render($values) {
|
79
|
$fids = array();
|
80
|
foreach ($values as $row) {
|
81
|
$fids[] = $row->{$this->field_alias};
|
82
|
}
|
83
|
if (!empty($fids)) {
|
84
|
$this->files = file_load_multiple($fids);
|
85
|
}
|
86
|
}
|
87
|
|
88
|
function render($row) {
|
89
|
// For the most part, this code is taken from node_feed() in node.module
|
90
|
global $base_url;
|
91
|
|
92
|
$fid = $row->{$this->field_alias};
|
93
|
if (!is_numeric($fid)) {
|
94
|
return;
|
95
|
}
|
96
|
|
97
|
$display_mode = $this->options['item_length'];
|
98
|
if ($display_mode == 'default') {
|
99
|
$display_mode = variable_get('feed_item_length', 'teaser');
|
100
|
}
|
101
|
|
102
|
// Load the specified file:
|
103
|
$file = $this->files[$fid];
|
104
|
if (empty($file)) {
|
105
|
return;
|
106
|
}
|
107
|
|
108
|
$item_text = '';
|
109
|
|
110
|
$uri = entity_uri('file', $file);
|
111
|
$user = user_load($file->uid);
|
112
|
$file->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
|
113
|
$file->rss_namespaces = array();
|
114
|
$file->rss_elements = array(
|
115
|
array(
|
116
|
'key' => 'pubDate',
|
117
|
'value' => gmdate('r', $file->timestamp),
|
118
|
),
|
119
|
array(
|
120
|
'key' => 'dc:creator',
|
121
|
'value' => $user->name,
|
122
|
),
|
123
|
array(
|
124
|
'key' => 'guid',
|
125
|
'value' => $file->fid . ' at ' . $base_url,
|
126
|
'attributes' => array('isPermaLink' => 'false'),
|
127
|
),
|
128
|
);
|
129
|
|
130
|
// The file gets built and modules add to or modify $file->rss_elements
|
131
|
// and $file->rss_namespaces.
|
132
|
|
133
|
$build_mode = $display_mode;
|
134
|
|
135
|
$build = file_view($file, $build_mode);
|
136
|
unset($build['#theme']);
|
137
|
|
138
|
if (!empty($file->rss_namespaces)) {
|
139
|
$this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $file->rss_namespaces);
|
140
|
}
|
141
|
elseif (function_exists('rdf_get_namespaces')) {
|
142
|
// Merge RDF namespaces in the XML namespaces in case they are used
|
143
|
// further in the RSS content.
|
144
|
$xml_rdf_namespaces = array();
|
145
|
foreach (rdf_get_namespaces() as $prefix => $uri) {
|
146
|
$xml_rdf_namespaces['xmlns:' . $prefix] = $uri;
|
147
|
}
|
148
|
$this->view->style_plugin->namespaces += $xml_rdf_namespaces;
|
149
|
}
|
150
|
|
151
|
// Hide the links if desired.
|
152
|
if (!$this->options['links']) {
|
153
|
hide($build['links']);
|
154
|
}
|
155
|
|
156
|
if ($display_mode != 'title') {
|
157
|
// We render file contents and force links to be last.
|
158
|
$build['links']['#weight'] = 1000;
|
159
|
$item_text .= drupal_render($build);
|
160
|
}
|
161
|
|
162
|
$item = new stdClass();
|
163
|
$item->description = $item_text;
|
164
|
$item->title = $file->filename;
|
165
|
$item->link = $file->link;
|
166
|
$item->elements = $file->rss_elements;
|
167
|
$item->fid = $file->fid;
|
168
|
|
169
|
return theme($this->theme_functions(), array(
|
170
|
'view' => $this->view,
|
171
|
'options' => $this->options,
|
172
|
'row' => $item
|
173
|
));
|
174
|
}
|
175
|
}
|