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