1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_plugin_row_comment_rss.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Plugin which formats the comments as RSS items.
|
10
|
*/
|
11
|
class views_plugin_row_comment_rss extends views_plugin_row {
|
12
|
|
13
|
/**
|
14
|
* {@inheritdoc}
|
15
|
*/
|
16
|
public $base_table = 'comment';
|
17
|
|
18
|
/**
|
19
|
* {@inheritdoc}
|
20
|
*/
|
21
|
public $base_field = 'cid';
|
22
|
|
23
|
/**
|
24
|
* {@inheritdoc}
|
25
|
*/
|
26
|
public function option_definition() {
|
27
|
$options = parent::option_definition();
|
28
|
|
29
|
$options['item_length'] = array('default' => 'default');
|
30
|
$options['links'] = array('default' => FALSE, 'bool' => TRUE);
|
31
|
|
32
|
return $options;
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* {@inheritdoc}
|
37
|
*/
|
38
|
public function options_form(&$form, &$form_state) {
|
39
|
parent::options_form($form, $form_state);
|
40
|
|
41
|
$form['item_length'] = array(
|
42
|
'#type' => 'select',
|
43
|
'#title' => t('Display type'),
|
44
|
'#options' => $this->options_form_summary_options(),
|
45
|
'#default_value' => $this->options['item_length'],
|
46
|
);
|
47
|
$form['links'] = array(
|
48
|
'#type' => 'checkbox',
|
49
|
'#title' => t('Display links'),
|
50
|
'#default_value' => $this->options['links'],
|
51
|
);
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* {@inheritdoc}
|
56
|
*/
|
57
|
public function pre_render($result) {
|
58
|
$cids = array();
|
59
|
$nids = array();
|
60
|
|
61
|
foreach ($result as $row) {
|
62
|
$cids[] = $row->cid;
|
63
|
}
|
64
|
|
65
|
$this->comments = comment_load_multiple($cids);
|
66
|
foreach ($this->comments as &$comment) {
|
67
|
$comment->depth = count(explode('.', $comment->thread)) - 1;
|
68
|
$nids[] = $comment->nid;
|
69
|
}
|
70
|
|
71
|
$this->nodes = node_load_multiple($nids);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Return the main options, which are shown in the summary title
|
76
|
*
|
77
|
* @see views_plugin_row_node_rss::options_form_summary_options()
|
78
|
* @todo Maybe provide a views_plugin_row_rss_entity and reuse this method
|
79
|
* in views_plugin_row_comment|node_rss.inc
|
80
|
*/
|
81
|
public function options_form_summary_options() {
|
82
|
$entity_info = entity_get_info('node');
|
83
|
$options = array();
|
84
|
if (!empty($entity_info['view modes'])) {
|
85
|
foreach ($entity_info['view modes'] as $mode => $settings) {
|
86
|
$options[$mode] = $settings['label'];
|
87
|
}
|
88
|
}
|
89
|
$options['title'] = t('Title only');
|
90
|
$options['default'] = t('Use site default RSS settings');
|
91
|
return $options;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* {@inheritdoc}
|
96
|
*/
|
97
|
public function render($row) {
|
98
|
global $base_url;
|
99
|
|
100
|
$cid = $row->{$this->field_alias};
|
101
|
if (!is_numeric($cid)) {
|
102
|
return;
|
103
|
}
|
104
|
|
105
|
$item_length = $this->options['item_length'];
|
106
|
if ($item_length == 'default') {
|
107
|
$item_length = variable_get('feed_item_length', 'teaser');
|
108
|
}
|
109
|
|
110
|
// Load the specified comment and its associated node.
|
111
|
$comment = $this->comments[$cid];
|
112
|
if (empty($comment) || empty($this->nodes[$comment->nid])) {
|
113
|
return;
|
114
|
}
|
115
|
|
116
|
$item_text = '';
|
117
|
|
118
|
$uri = entity_uri('comment', $comment);
|
119
|
$comment->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
|
120
|
$comment->rss_namespaces = array();
|
121
|
$comment->rss_elements = array(
|
122
|
array(
|
123
|
'key' => 'pubDate',
|
124
|
'value' => gmdate('r', $comment->created),
|
125
|
),
|
126
|
array(
|
127
|
'key' => 'dc:creator',
|
128
|
'value' => format_username($comment),
|
129
|
),
|
130
|
array(
|
131
|
'key' => 'guid',
|
132
|
'value' => 'comment ' . $comment->cid . ' at ' . $base_url,
|
133
|
'attributes' => array('isPermaLink' => 'false'),
|
134
|
),
|
135
|
);
|
136
|
|
137
|
// The comment gets built and modules add to or modify
|
138
|
// $comment->rss_elements and $comment->rss_namespaces.
|
139
|
$build = comment_view($comment, $this->nodes[$comment->nid], 'rss');
|
140
|
unset($build['#theme']);
|
141
|
|
142
|
if (!empty($comment->rss_namespaces)) {
|
143
|
$this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces);
|
144
|
}
|
145
|
|
146
|
// Hide the links if desired.
|
147
|
if (!$this->options['links']) {
|
148
|
hide($build['links']);
|
149
|
}
|
150
|
|
151
|
if ($item_length != 'title') {
|
152
|
// We render comment contents and force links to be last.
|
153
|
$build['links']['#weight'] = 1000;
|
154
|
$item_text .= drupal_render($build);
|
155
|
}
|
156
|
|
157
|
$item = new stdClass();
|
158
|
$item->description = $item_text;
|
159
|
$item->title = $comment->subject;
|
160
|
$item->link = $comment->link;
|
161
|
$item->elements = $comment->rss_elements;
|
162
|
$item->cid = $comment->cid;
|
163
|
|
164
|
return theme($this->theme_functions(), array(
|
165
|
'view' => $this->view,
|
166
|
'options' => $this->options,
|
167
|
'row' => $item
|
168
|
));
|
169
|
}
|
170
|
|
171
|
}
|