diff --git a/core/modules/aggregator/aggregator.views.inc b/core/modules/aggregator/aggregator.views.inc new file mode 100644 index 0000000..a610253 --- /dev/null +++ b/core/modules/aggregator/aggregator.views.inc @@ -0,0 +1,358 @@ + 'iid', + 'title' => t('Aggregator item'), + 'help' => t("Aggregator items are imported from external RSS and Atom news feeds."), + ); + + // Fields + + // iid + $data['aggregator_item']['iid'] = array( + 'title' => t('Item ID'), + 'help' => t('The unique ID of the aggregator item.'), // The help that appears on the UI, + // Information for displaying the iid + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + // Information for accepting a iid as an argument + 'argument' => array( + 'id' => 'aggregator_iid', + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'id' => 'numeric', + ), + // Information for sorting on a nid. + 'sort' => array( + 'id' => 'standard', + ), + ); + + // title + $data['aggregator_item']['title'] = array( + 'title' => t('Title'), // The item it appears as on the UI, + 'help' => t('The title of the aggregator item.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'aggregator_title_link', + 'extra' => array('link'), + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'string', + ), + ); + + // link + $data['aggregator_item']['link'] = array( + 'title' => t('Link'), // The item it appears as on the UI, + 'help' => t('The link to the original source URL of the item.'), + 'field' => array( + 'id' => 'url', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'string', + ), + ); + + // author + $data['aggregator_item']['author'] = array( + 'title' => t('Author'), // The item it appears as on the UI, + 'help' => t('The author of the original imported item.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'aggregator_xss', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'string', + ), + 'argument' => array( + 'id' => 'string', + ), + ); + + // guid + $data['aggregator_item']['guid'] = array( + 'title' => t('GUID'), // The item it appears as on the UI, + 'help' => t('The guid of the original imported item.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'xss', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'string', + ), + 'argument' => array( + 'id' => 'string', + ), + ); + + // feed body + $data['aggregator_item']['description'] = array( + 'title' => t('Body'), // The item it appears as on the UI, + 'help' => t('The actual content of the imported item.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'aggregator_xss', + 'click sortable' => FALSE, + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'string', + ), + ); + + // item timestamp + $data['aggregator_item']['timestamp'] = array( + 'title' => t('Timestamp'), // The item it appears as on the UI, + 'help' => t('The date the original feed item was posted. (With some feeds, this will be the date it was imported.)'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'date', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'date', + ), + 'argument' => array( + 'id' => 'date', + ), + ); + + // Aggregator feed table + + $data['aggregator_feed']['table']['group'] = t('Aggregator feed'); + + // Explain how this table joins to others. + $data['aggregator_feed']['table']['join'] = array( + 'aggregator_item' => array( + 'left_field' => 'fid', + 'field' => 'fid', + ), + ); + + // fid + $data['aggregator_feed']['fid'] = array( + 'title' => t('Feed ID'), + 'help' => t('The unique ID of the aggregator feed.'), // The help that appears on the UI, + // Information for displaying the fid + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + // Information for accepting a fid as an argument + 'argument' => array( + 'id' => 'aggregator_fid', + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'id' => 'numeric', + ), + // Information for sorting on a fid. + 'sort' => array( + 'id' => 'standard', + ), + ); + + // title + $data['aggregator_feed']['title'] = array( + 'title' => t('Title'), // The item it appears as on the UI, + 'help' => t('The title of the aggregator feed.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'aggregator_title_link', + 'extra' => array('link'), + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'string', + ), + 'argument' => array( + 'id' => 'string', + ), + ); + + // link + $data['aggregator_feed']['link'] = array( + 'title' => t('Link'), // The item it appears as on the UI, + 'help' => t('The link to the source URL of the feed.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'url', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string', + ), + ); + + // feed last updated + $data['aggregator_feed']['checked'] = array( + 'title' => t('Last checked'), // The item it appears as on the UI, + 'help' => t('The date the feed was last checked for new content.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + 'argument' => array( + 'id' => 'date', + ), + ); + + // feed description + $data['aggregator_feed']['description'] = array( + 'title' => t('Description'), // The item it appears as on the UI, + 'help' => t('The description of the aggregator feed.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'xss', + 'click sortable' => FALSE, + ), + 'filter' => array( + 'id' => 'string', + ), + ); + + // feed last updated + $data['aggregator_feed']['modified'] = array( + 'title' => t('Last modified'), // The item it appears as on the UI, + 'help' => t('The date of the most recent new content on the feed.'), + // Information for displaying a title as a field + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'id' => 'date', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'id' => 'date', + ), + 'argument' => array( + 'id' => 'date', + ), + ); + + // Aggregator category feed table + + $data['aggregator_category_feed']['table']['join'] = array( + 'aggregator_item' => array( + 'left_field' => 'fid', + 'field' => 'fid', + ), + ); + + // Aggregator category table + + $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', + ), + ); + + // 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', + ), + ); + + // title + $data['aggregator_category']['title'] = array( + 'title' => t('Category'), + 'help' => t('The title of the aggregator category.'), + 'field' => array( + 'id' => 'aggregator_category', + 'click sortable' => TRUE, + ), + '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..8454377 --- /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..2c4aaf4 --- /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..b557e1d --- /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..9cd4b50 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php @@ -0,0 +1,74 @@ +additional_fields['cid'] = 'cid'; + } + + protected function defineOptions() { + $options = parent::defineOptions(); + $options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE); + return $options; + } + + /** + * Provide link to category option + */ + 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; + } + + 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..94a336d --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php @@ -0,0 +1,72 @@ +additional_fields['link'] = 'link'; + } + + protected function defineOptions() { + $options = parent::defineOptions(); + + $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE); + + return $options; + } + + /** + * Provide link to the page being visited. + */ + 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); + } + + function render($values) { + $value = $this->get_value($values); + return $this->render_link($this->sanitizeValue($value), $values); + } + + 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..017d77f --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Xss.php @@ -0,0 +1,30 @@ +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..c256ed9 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/filter/CategoryCid.php @@ -0,0 +1,39 @@ +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..bb46b33 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/row/Rss.php @@ -0,0 +1,92 @@ + 'default'); + + return $options; + } + + 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'], + ); + } + + 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); + $result = $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 + )); + } + +} diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php index 02fa8f5..0d2c92f 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php @@ -95,7 +95,12 @@ public function testHandlers() { foreach ($object_types as $type) { if (isset($view->{$type})) { foreach ($view->{$type} as $handler) { - $this->assertTrue($handler instanceof HandlerBase); + $this->assertTrue($handler instanceof HandlerBase, format_string( + '@type handler of class %class is an instance of HandlerBase', + array( + '@type' => $type, + '%class' => get_class($handler), + ))); } } }