diff --git a/core/modules/aggregator/aggregator.views.inc b/core/modules/aggregator/aggregator.views.inc new file mode 100644 index 0000000..02f9217 --- /dev/null +++ b/core/modules/aggregator/aggregator.views.inc @@ -0,0 +1,335 @@ + 'iid', + 'title' => t('Aggregator item'), + 'help' => t('Aggregator items are imported from external RSS and Atom news feeds.'), + ); + + $data['aggregator_item']['iid'] = array( + 'title' => t('Item ID'), + 'help' => t('The unique ID of the aggregator item.'), + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'aggregator_iid', + 'name field' => 'title', + 'numeric' => TRUE, + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['aggregator_item']['title'] = array( + 'title' => t('Title'), + 'help' => t('The title of the aggregator item.'), + 'field' => array( + 'id' => 'aggregator_title_link', + 'extra' => array('link'), + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + ); + + $data['aggregator_item']['link'] = array( + 'title' => t('Link'), + 'help' => t('The link to the original source URL of the item.'), + 'field' => array( + 'id' => 'url', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + ); + + $data['aggregator_item']['author'] = array( + 'title' => t('Author'), + 'help' => t('The author of the original imported item.'), + 'field' => array( + 'id' => 'aggregator_xss', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + 'argument' => array( + 'id' => 'string', + ), + ); + + $data['aggregator_item']['guid'] = array( + 'title' => t('GUID'), + 'help' => t('The guid of the original imported item.'), + 'field' => array( + 'id' => 'xss', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + 'argument' => array( + 'id' => 'string', + ), + ); + + $data['aggregator_item']['description'] = array( + 'title' => t('Body'), + 'help' => t('The actual content of the imported item.'), + 'field' => array( + 'id' => 'aggregator_xss', + 'click sortable' => FALSE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['aggregator_item']['timestamp'] = array( + 'title' => t('Timestamp'), + 'help' => t('The date the original feed item was posted. (With some feeds, this will be the date it was imported.)'), + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + 'argument' => array( + 'id' => 'date', + ), + ); + + $data['aggregator_feed']['table']['group'] = t('Aggregator feed'); + + $data['aggregator_feed']['table']['join'] = array( + 'aggregator_item' => array( + 'left_field' => 'fid', + 'field' => 'fid', + ), + ); + + $data['aggregator_feed']['fid'] = array( + 'title' => t('Feed ID'), + 'help' => t('The unique ID of the aggregator feed.'), + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'aggregator_fid', + 'name field' => 'title', + 'numeric' => TRUE, + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['aggregator_feed']['title'] = array( + 'title' => t('Title'), + 'help' => t('The title of the aggregator feed.'), + 'field' => array( + 'id' => 'aggregator_title_link', + 'extra' => array('link'), + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + 'argument' => array( + 'id' => 'string', + ), + ); + + $data['aggregator_feed']['link'] = array( + 'title' => t('Link'), + 'help' => t('The link to the source URL of the feed.'), + 'field' => array( + 'id' => 'url', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + ); + + $data['aggregator_feed']['checked'] = array( + 'title' => t('Last checked'), + 'help' => t('The date the feed was last checked for new content.'), + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + 'argument' => array( + 'id' => 'date', + ), + ); + + $data['aggregator_feed']['description'] = array( + 'title' => t('Description'), + 'help' => t('The description of the aggregator feed.'), + 'field' => array( + 'id' => 'xss', + 'click sortable' => FALSE, + ), + 'filter' => array( + 'id' => 'string', + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['aggregator_feed']['modified'] = array( + 'title' => t('Last modified'), + 'help' => t('The date of the most recent new content on the feed.'), + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + 'argument' => array( + 'id' => 'date', + ), + ); + + $data['aggregator_category_feed']['table']['join'] = array( + 'aggregator_item' => array( + 'left_field' => 'fid', + 'field' => 'fid', + ), + ); + + $data['aggregator_category']['table']['group'] = t('Aggregator category'); + + $data['aggregator_category']['table']['join'] = array( + 'aggregator_item' => array( + 'left_table' => 'aggregator_category_feed', + 'left_field' => 'cid', + 'field' => 'cid', + ), + ); + + $data['aggregator_category']['cid'] = array( + 'title' => t('Category ID'), + 'help' => t('The unique ID of the aggregator category.'), + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'aggregator_category_cid', + 'name field' => 'title', + 'numeric' => TRUE, + ), + 'filter' => array( + 'id' => 'aggregator_category_cid', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['aggregator_category']['title'] = array( + 'title' => t('Category'), + 'help' => t('The title of the aggregator category.'), + 'field' => array( + 'id' => 'aggregator_category', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + ); + + return $data; +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/CategoryCid.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/CategoryCid.php new file mode 100644 index 0000000..d0fb65c --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/CategoryCid.php @@ -0,0 +1,41 @@ +addField('c', 'title'); + $query->condition('c.cid', $this->value); + $result = $query->execute(); + foreach ($result as $term) { + $titles[] = check_plain($term->title); + } + return $titles; + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/Fid.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/Fid.php new file mode 100644 index 0000000..d1018a7 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/Fid.php @@ -0,0 +1,42 @@ + $this->value)); + $query = db_select('aggregator_feed', 'f'); + $query->addField('f', 'title'); + $query->condition('f.fid', $this->value); + $result = $query->execute(); + foreach ($result as $term) { + $titles[] = check_plain($term->title); + } + return $titles; + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/Iid.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/Iid.php new file mode 100644 index 0000000..6b9070b --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/argument/Iid.php @@ -0,0 +1,42 @@ +value), '%d')); + + $result = db_select('aggregator_item') + ->condition('iid', $this->value, 'IN') + ->fields(array('title')) + ->execute(); + foreach ($result as $term) { + $titles[] = check_plain($term->title); + } + return $titles; + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php new file mode 100644 index 0000000..e266e0a --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php @@ -0,0 +1,80 @@ +additional_fields['cid'] = 'cid'; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::defineOptions(). + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE); + return $options; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm(). + */ + public function buildOptionsForm(&$form, &$form_state) { + $form['link_to_category'] = array( + '#title' => t('Link this field to its aggregator category page'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_category']), + ); + parent::buildOptionsForm($form, $form_state); + } + + /** + * Render whatever the data is as a link to the category. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $values) { + $cid = $this->get_value($values, 'cid'); + if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = "aggregator/category/$cid"; + } + return $data; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render(). + */ + function render($values) { + $value = $this->get_value($values); + return $this->render_link($this->sanitizeValue($value), $values); + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php new file mode 100644 index 0000000..172249f --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php @@ -0,0 +1,79 @@ +additional_fields['link'] = 'link'; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::defineOptions(). + */ + protected function defineOptions() { + $options = parent::defineOptions(); + + $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE); + + return $options; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm(). + */ + public function buildOptionsForm(&$form, &$form_state) { + $form['display_as_link'] = array( + '#title' => t('Display as link'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['display_as_link']), + ); + parent::buildOptionsForm($form, $form_state); + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render(). + */ + function render($values) { + $value = $this->get_value($values); + return $this->render_link($this->sanitizeValue($value), $values); + } + + protected function render_link($data, $values) { + $link = $this->get_value($values, 'link'); + if (!empty($this->options['display_as_link'])) { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = $link; + $this->options['alter']['html'] = TRUE; + } + + return $data; + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Xss.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Xss.php new file mode 100644 index 0000000..242c523 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Xss.php @@ -0,0 +1,33 @@ +get_value($values); + return aggregator_filter_xss($value); + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/filter/CategoryCid.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/filter/CategoryCid.php new file mode 100644 index 0000000..f49b0e2 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/filter/CategoryCid.php @@ -0,0 +1,42 @@ +value_options)) { + return; + } + + $this->value_options = array(); + // Uses db_query() rather than db_select() because the query is static and + // does not include any variables. + $result = db_query('SELECT * FROM {aggregator_category} ORDER BY title'); + foreach ($result as $category) { + $this->value_options[$category->cid] = $category->title; + } + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/row/Rss.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/row/Rss.php new file mode 100644 index 0000000..618858f --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/row/Rss.php @@ -0,0 +1,112 @@ + 'default'); + + return $options; + } + + /** + * Overrides \Drupal\views\Plugin\views\row\RowPluginBase::buildOptionsForm(). + */ + public function buildOptionsForm(&$form, &$form_state) { + $form['item_length'] = array( + '#type' => 'select', + '#title' => t('Display type'), + '#options' => array( + 'fulltext' => t('Full text'), + 'teaser' => t('Title plus teaser'), + 'title' => t('Title only'), + 'default' => t('Use default RSS settings'), + ), + '#default_value' => $this->options['item_length'], + ); + } + + /** + * Overrides \Drupal\views\Plugin\views\row\RowPluginBase::render(). + */ + function render($row) { + $iid = $row->{$this->field_alias}; + $query = db_select('aggregator_item', 'ai'); + $query->leftJoin('aggregator_feed', 'af', 'ai.fid = af.fid'); + $query->fields('ai'); + $query->addExpression('af.title', 'feed_title'); + $query->addExpression('ai.link', 'feed_LINK'); + $query->condition('iid', $iid); + $item = $query->execute(); + + $item->elements = array( + array( + 'key' => 'pubDate', + 'value' => gmdate('r', $item->timestamp), + ), + array( + 'key' => 'dc:creator', + 'value' => $item->author, + ), + array( + 'key' => 'guid', + 'value' => $item->guid, + 'attributes' => array('isPermaLink' => 'false') + ), + ); + + foreach ($item->elements as $element) { + if (isset($element['namespace'])) { + $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']); + } + } + + return theme($this->themeFunctions(), array( + 'view' => $this->view, + 'options' => $this->options, + 'row' => $item + )); + } + +}