first import

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy
2013-01-09 10:53:26 +01:00
commit b20b38f514
526 changed files with 76993 additions and 0 deletions

View File

@@ -0,0 +1,406 @@
<?php
/**
* @file
* Provide views data and handlers for aggregator.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function aggregator_views_data() {
// ----------------------------------------------------------------------
// Main Aggregator Item base table
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['aggregator_item']['table']['group'] = t('Aggregator');
// Advertise this table as a possible base table
$data['aggregator_item']['table']['base'] = array(
'field' => 'iid',
'title' => t('Aggregator item'),
'help' => t("Aggregator items are imported from external RSS and Atom news feeds."),
);
// ----------------------------------------------------------------
// Fields
// item id.
$data['aggregator_item']['iid'] = array(
'title' => t('Feed Item ID'),
'help' => t('The unique ID of the aggregator item.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
'numeric' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// 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(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
// Information for accepting a iid as an argument
'argument' => array(
'handler' => 'views_handler_argument_aggregator_iid',
'name field' => 'title', // the field to display in the summary.
'numeric' => TRUE,
),
// Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// 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(
'handler' => 'views_handler_field_aggregator_title_link',
'extra' => array('link'),
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_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(
'handler' => 'views_handler_field_url',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_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(
'handler' => 'views_handler_field_aggregator_xss',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_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(
'handler' => 'views_handler_field_xss',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_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(
'handler' => 'views_handler_field_aggregator_xss',
'click sortable' => FALSE,
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_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(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'argument' => array(
'handler' => 'views_handler_argument_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(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
// Information for accepting a fid as an argument
'argument' => array(
'handler' => 'views_handler_argument_aggregator_fid',
'name field' => 'title', // the field to display in the summary.
'numeric' => TRUE,
),
// Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
// Information for sorting on a fid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// 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(
'handler' => 'views_handler_field_aggregator_title_link',
'extra' => array('link'),
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_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(
'handler' => 'views_handler_field_url',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_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(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'argument' => array(
'handler' => 'views_handler_argument_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(
'handler' => 'views_handler_field_xss',
'click sortable' => FALSE,
),
'filter' => array(
'handler' => 'views_handler_filter_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(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'argument' => array(
'handler' => 'views_handler_argument_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(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_aggregator_category_cid',
'name field' => 'title',
'numeric' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_aggregator_category_cid',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// title
$data['aggregator_category']['title'] = array(
'title' => t('Category'),
'help' => t('The title of the aggregator category.'),
'field' => array(
'handler' => 'views_handler_field_aggregator_category',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
return $data;
}
/**
* Implements hook_views_plugins().
*/
function aggregator_views_plugins() {
return array(
'module' => 'views', // This just tells our themes are elsewhere.
'row' => array(
'aggregator_rss' => array(
'title' => t('Aggregator item'),
'help' => t('Display the aggregator item using the data from the original source.'),
'handler' => 'views_plugin_row_aggregator_rss',
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'theme' => 'views_view_row_rss',
'base' => array('aggregator_item'), // only works with 'node' as base.
'uses options' => TRUE,
'type' => 'feed',
'help topic' => 'style-aggregator-rss',
),
),
);
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_argument_aggregator_category_cid.
*/
/**
* Argument handler to accept an aggregator category id.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_aggregator_category_cid extends views_handler_argument_numeric {
/**
* Override the behavior of title(). Get the title of the category.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT c.title FROM {aggregator_category} c WHERE c.cid IN (:cid)", array(':cid' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_argument_aggregator_fid.
*/
/**
* Argument handler to accept an aggregator feed id.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_aggregator_fid extends views_handler_argument_numeric {
/**
* Override the behavior of title(). Get the title of the feed.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT f.title FROM {aggregator_feed} f WHERE f.fid IN (:fids)", array(':fids' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* @file
* Definition of views_handler_argument_aggregator_iid.
*/
/**
* Argument handler to accept an aggregator item id.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_aggregator_iid extends views_handler_argument_numeric {
/**
* Override the behavior of title(). Get the title of the category.
*/
function title_query() {
$titles = array();
$placeholders = implode(', ', array_fill(0, sizeof($this->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;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* @file
* Definition of views_handler_field_aggregator_category.
*/
/**
* Field handler to provide simple renderer that allows linking to aggregator
* category.
*
* @ingroup views_field_handlers
*/
class views_handler_field_aggregator_category extends views_handler_field {
/**
* Constructor to provide additional field to add.
*/
function construct() {
parent::construct();
$this->additional_fields['cid'] = 'cid';
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link to category option
*/
function options_form(&$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::options_form($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->sanitize_value($value), $values);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* @file
* Definition of views_handler_field_aggregator_title_link.
*/
/**
* Field handler that turns an item's title into a clickable link to the original
* source article.
*
* @ingroup views_field_handlers
*/
class views_handler_field_aggregator_title_link extends views_handler_field {
function construct() {
parent::construct();
$this->additional_fields['link'] = 'link';
}
function option_definition() {
$options = parent::option_definition();
$options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
/**
* Provide link to the page being visited.
*/
function options_form(&$form, &$form_state) {
$form['display_as_link'] = array(
'#title' => t('Display as link'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['display_as_link']),
);
parent::options_form($form, $form_state);
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($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;
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Definition of views_handler_field_aggregator_xss.
*/
/**
* Filters htmls tags from item.
*
* @ingroup views_field_handlers
*/
class views_handler_field_aggregator_xss extends views_handler_field {
function render($values) {
$value = $this->get_value($values);
return aggregator_filter_xss($value);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_filter_aggregator_category_cid.
*/
/**
* Filter by aggregator category cid
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_aggregator_category_cid extends views_handler_filter_in_operator {
function get_value_options() {
if (isset($this->value_options)) {
return;
}
$this->value_options = array();
$result = db_query('SELECT * FROM {aggregator_category} ORDER BY title');
foreach ($result as $category) {
$this->value_options[$category->cid] = $category->title;
}
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* @file
* Contains the Aggregator Item RSS row style plugin.
*/
/**
* Plugin which loads an aggregator item and formats it as an RSS item.
*/
class views_plugin_row_aggregator_rss extends views_plugin_row {
var $base_table = 'aggregator_item';
var $base_field = 'iid';
function option_definition() {
$options = parent::option_definition();
$options['item_length'] = array('default' => 'default');
return $options;
}
function options_form(&$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};
$sql = "SELECT ai.iid, ai.fid, ai.title, ai.link, ai.author, ai.description, ";
$sql .= "ai.timestamp, ai.guid, af.title AS feed_title, ai.link AS feed_LINK ";
$sql .= "FROM {aggregator_item} ai LEFT JOIN {aggregator_feed} af ON ai.fid = af.fid ";
$sql .= "WHERE ai.iid = :iid";
$item = db_query($sql, array(':iid' => $iid))->fetchObject();
$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->theme_functions(), array(
'view' => $this->view,
'options' => $this->options,
'row' => $item
));
}
}

131
modules/book.views.inc Normal file
View File

@@ -0,0 +1,131 @@
<?php
/**
* @file
* Provide views data and handlers for book.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function book_views_data() {
// ----------------------------------------------------------------------
// book table
$data['book']['table']['group'] = t('Book');
$data['book']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
$data['book']['bid'] = array(
'title' => t('Top level book'),
'help' => t('The book the node is in.'),
'relationship' => array(
'base' => 'node',
'handler' => 'views_handler_relationship',
'label' => t('Book'),
),
// There is no argument here; if you need an argument, add the relationship
// and use the node: nid argument.
);
// ----------------------------------------------------------------------
// menu_links table -- this is aliased so we can get just book relations
// Book hierarchy and weight data are now in {menu_links}.
$data['book_menu_links']['table']['group'] = t('Book');
$data['book_menu_links']['table']['join'] = array(
'node' => array(
'table' => 'menu_links',
'left_table' => 'book',
'left_field' => 'mlid',
'field' => 'mlid',
),
);
$data['book_menu_links']['weight'] = array(
'title' => t('Weight'),
'help' => t('The weight of the book page.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['book_menu_links']['depth'] = array(
'title' => t('Depth'),
'help' => t('The depth of the book page in the hierarchy; top level books have a depth of 1.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'handler' => 'views_handler_argument',
),
);
$data['book_menu_links']['p'] = array(
'title' => t('Hierarchy'),
'help' => t('The order of pages in the book hierarchy.'),
'sort' => array(
'handler' => 'views_handler_sort_menu_hierarchy',
),
);
// ----------------------------------------------------------------------
// book_parent table -- this is an alias of the book table which
// represents the parent book.
// The {book} record for the parent node.
$data['book_parent']['table']['group'] = t('Book');
$data['book_parent']['table']['join'] = array(
'node' => array(
'table' => 'book',
'left_table' => 'book_menu_links',
'left_field' => 'plid',
'field' => 'mlid',
),
);
$data['book_parent']['nid'] = array(
'title' => t('Parent'),
'help' => t('The parent book node.'),
'relationship' => array(
'base' => 'node',
'base field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Book parent'),
),
);
return $data;
}
/**
* Implements hook_views_plugins().
*/
function book_views_plugins() {
return array(
'module' => 'views',
'argument default' => array(
'book_root' => array(
'title' => t('Book root from current node'),
'handler' => 'views_plugin_argument_default_book_root'
),
),
);
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Contains the book root from current node argument default plugin.
*/
/**
* Default argument plugin to get the current node's book root.
*/
class views_plugin_argument_default_book_root extends views_plugin_argument_default_node {
function get_argument() {
// Use the argument_default_node plugin to get the nid argument.
$nid = parent::get_argument();
if (!empty($nid)) {
$node = node_load($nid);
if (isset($node->book['bid'])) {
return $node->book['bid'];
}
}
}
}

662
modules/comment.views.inc Normal file
View File

@@ -0,0 +1,662 @@
<?php
/**
* @file
* Provide views data and handlers for comment.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function comment_views_data() {
$data['comments']['moved to'] = 'comment';
$data['comment']['comment']['moved to'] = array('field_data_comment_body', 'comment_body');
$data['comment']['comment']['field']['moved to'] = array('field_data_comment_body', 'comment_body');
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['comment']['table']['group'] = t('Comment');
$data['comment']['table']['base'] = array(
'field' => 'cid',
'title' => t('Comment'),
'help' => t("Comments are responses to node content."),
'access query tag' => 'comment_access',
);
$data['comment']['table']['entity type'] = 'comment';
// Provide a "default relationship" to keep older views from choking.
$data['comment']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'cid',
),
);
// ----------------------------------------------------------------
// Fields
// subject
$data['comment']['subject'] = array(
'title' => t('Title'),
'help' => t('The title of the comment.'),
'field' => array(
'handler' => 'views_handler_field_comment',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// cid
$data['comment']['cid'] = array(
'title' => t('ID'),
'help' => t('The comment ID of the field'),
'field' => array(
'handler' => 'views_handler_field_comment',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
);
// name (of comment author)
$data['comment']['name'] = array(
'title' => t('Author'),
'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
'field' => array(
'handler' => 'views_handler_field_comment_username',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// homepage
$data['comment']['homepage'] = array(
'title' => t("Author's website"),
'help' => t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."),
'field' => array(
'handler' => 'views_handler_field_url',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// hostname
$data['comment']['hostname'] = array(
'title' => t('Hostname'),
'help' => t('Hostname of user that posted the comment.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// mail
$data['comment']['mail'] = array(
'title' => t('Mail'),
'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// created (when comment was posted)
$data['comment']['created'] = array(
'title' => t('Post date'),
'help' => t('Date and time of when the comment was created.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// Language field
if (module_exists('locale')) {
$data['comment']['language'] = array(
'title' => t('Language'),
'help' => t('The language the comment is in.'),
'field' => array(
'handler' => 'views_handler_field_locale_language',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_locale_language',
),
'argument' => array(
'handler' => 'views_handler_argument_locale_language',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
}
$data['comments']['timestamp']['moved to'] = array('comment', 'changed');
// changed (when comment was last updated)
$data['comment']['changed'] = array(
'title' => t('Updated date'),
'help' => t('Date and time of when the comment was last updated.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
$data['comments']['timestamp_fulldate']['moved to'] = array('comment', 'changed_fulldata');
$data['comment']['changed_fulldata'] = array(
'title' => t('Created date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_fulldate',
),
);
$data['comments']['timestamp_year_month']['moved to'] = array('comment', 'changed_year_month');
$data['comment']['changed_year_month'] = array(
'title' => t('Created year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_year_month',
),
);
$data['comments']['timestamp_year']['moved to'] = array('comment', 'changed_year');
$data['comment']['changed_year'] = array(
'title' => t('Created year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_year',
),
);
$data['comments']['timestamp_month']['moved to'] = array('comment', 'changed_month');
$data['comment']['changed_month'] = array(
'title' => t('Created month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_month',
),
);
$data['comments']['timestamp_day']['moved to'] = array('comment', 'changed_day');
$data['comment']['changed_day'] = array(
'title' => t('Created day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_day',
),
);
$data['comments']['timestamp_week']['moved to'] = array('comment', 'changed_week');
$data['comment']['changed_week'] = array(
'title' => t('Created week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_week',
),
);
// status (approved or not)
$data['comment']['status'] = array(
'title' => t('Approved'),
'help' => t('Whether the comment is approved (or still in the moderation queue).'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
'output formats' => array(
'approved-not-approved' => array(t('Approved'), t('Not Approved')),
),
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Approved comment'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// link to view comment
$data['comment']['view_comment'] = array(
'field' => array(
'title' => t('View link'),
'help' => t('Provide a simple link to view the comment.'),
'handler' => 'views_handler_field_comment_link',
),
);
// link to edit comment
$data['comment']['edit_comment'] = array(
'field' => array(
'title' => t('Edit link'),
'help' => t('Provide a simple link to edit the comment.'),
'handler' => 'views_handler_field_comment_link_edit',
),
);
// link to delete comment
$data['comment']['delete_comment'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the comment.'),
'handler' => 'views_handler_field_comment_link_delete',
),
);
// link to approve comment
$data['comment']['approve_comment'] = array(
'field' => array(
'title' => t('Approve link'),
'help' => t('Provide a simple link to approve the comment.'),
'handler' => 'views_handler_field_comment_link_approve',
),
);
// link to reply to comment
$data['comment']['replyto_comment'] = array(
'field' => array(
'title' => t('Reply-to link'),
'help' => t('Provide a simple link to reply to the comment.'),
'handler' => 'views_handler_field_comment_link_reply',
),
);
$data['comment']['thread'] = array(
'field' => array(
'title' => t('Depth'),
'help' => t('Display the depth of the comment if it is threaded.'),
'handler' => 'views_handler_field_comment_depth',
),
'sort' => array(
'title' => t('Thread'),
'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
'handler' => 'views_handler_sort_comment_thread',
),
);
$data['comment']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node ID to which the comment is a reply to.'),
'relationship' => array(
'title' => t('Content'),
'help' => t('The content to which the comment is a reply to.'),
'base' => 'node',
'base field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Content'),
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'field' => array(
'handler' => 'views_handler_field_numeric',
),
);
$data['comment']['uid'] = array(
'title' => t('Author uid'),
'help' => t('If you need more fields than the uid add the comment: author relationship'),
'relationship' => array(
'title' => t('Author'),
'help' => t("The User ID of the comment's author."),
'base' => 'users',
'base field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('author'),
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'field' => array(
'handler' => 'views_handler_field_user',
),
);
$data['comment']['pid'] = array(
'title' => t('Parent CID'),
'help' => t('The Comment ID of the parent comment.'),
'field' => array(
'handler' => 'views_handler_field',
),
'relationship' => array(
'title' => t('Parent comment'),
'help' => t('The parent comment.'),
'base' => 'comment',
'base field' => 'cid',
'handler' => 'views_handler_relationship',
'label' => t('Parent comment'),
),
);
// ----------------------------------------------------------------------
// node_comment_statistics table
// define the group
$data['node_comment_statistics']['table']['group'] = t('Content');
// joins
$data['node_comment_statistics']['table']['join'] = array(
//...to the node table
'node' => array(
'type' => 'INNER',
'left_field' => 'nid',
'field' => 'nid',
),
);
// last_comment_timestamp
$data['node_comment_statistics']['last_comment_timestamp'] = array(
'title' => t('Last comment time'),
'help' => t('Date and time of when the last comment was posted.'),
'field' => array(
'handler' => 'views_handler_field_last_comment_timestamp',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// last_comment_name (author's name)
$data['node_comment_statistics']['last_comment_name'] = array(
'title' => t("Last comment author"),
'help' => t('The name of the author of the last posted comment.'),
'field' => array(
'handler' => 'views_handler_field_ncs_last_comment_name',
'click sortable' => TRUE,
'no group by' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_ncs_last_comment_name',
'no group by' => TRUE,
),
);
// comment_count
$data['node_comment_statistics']['comment_count'] = array(
'title' => t('Comment count'),
'help' => t('The number of comments a node has.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument',
),
);
// last_comment_timestamp
$data['node_comment_statistics']['last_updated'] = array(
'title' => t('Updated/commented date'),
'help' => t('The most recent of last comment posted or node updated time.'),
'field' => array(
'handler' => 'views_handler_field_ncs_last_updated',
'click sortable' => TRUE,
'no group by' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_ncs_last_updated',
'no group by' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_ncs_last_updated',
),
);
$data['node_comment_statistics']['cid'] = array(
'title' => t('Last comment CID'),
'help' => t('Display the last comment of a node'),
'relationship' => array(
'title' => t('Last Comment'),
'help' => t('The last comment of a node.'),
'group' => t('Comment'),
'base' => 'comment',
'base field' => 'cid',
'handler' => 'views_handler_relationship',
'label' => t('Last Comment'),
),
);
// last_comment_uid
$data['node_comment_statistics']['last_comment_uid'] = array(
'title' => t('Last comment uid'),
'help' => t('The User ID of the author of the last comment of a node.'),
'relationship' => array(
'title' => t('Last comment author'),
'base' => 'users',
'base field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('Last comment author'),
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'field' => array(
'handler' => 'views_handler_field_numeric',
),
);
return $data;
}
/**
* Use views_data_alter to add items to the node table that are
* relevant to comments.
*/
function comment_views_data_alter(&$data) {
// new comments
$data['node']['new_comments'] = array(
'title' => t('New comments'),
'help' => t('The number of new comments on the node.'),
'field' => array(
'handler' => 'views_handler_field_node_new_comments',
'no group by' => TRUE,
),
);
$data['node']['comments_link'] = array(
'field' => array(
'title' => t('Add comment link'),
'help' => t('Display the standard add comment link used on regular nodes, which will only display if the viewing user has access to add a comment.'),
'handler' => 'views_handler_field_comment_node_link',
),
);
// Comment status of the node
$data['node']['comment'] = array(
'title' => t('Comment status'),
'help' => t('Whether comments are enabled or disabled on the node.'),
'field' => array(
'handler' => 'views_handler_field_node_comment',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_node_comment',
),
);
$data['node']['uid_touch'] = array(
'title' => t('User posted or commented'),
'help' => t('Display nodes only if a user posted the node or commented on the node.'),
'argument' => array(
'field' => 'uid',
'name table' => 'users',
'name field' => 'name',
'handler' => 'views_handler_argument_comment_user_uid',
'no group by' => TRUE,
),
'filter' => array(
'field' => 'uid',
'name table' => 'users',
'name field' => 'name',
'handler' => 'views_handler_filter_comment_user_uid'
),
);
$data['node']['cid'] = array(
'title' => t('Comments of the node'),
'help' => t('Relate all comments on the node. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.'),
'relationship' => array(
'group' => t('Comment'),
'label' => t('Comments'),
'base' => 'comment',
'base field' => 'nid',
'relationship field' => 'nid',
'handler' => 'views_handler_relationship',
),
);
}
/**
* Implements hook_views_plugins().
*/
function comment_views_plugins() {
return array(
'module' => 'views',
'row' => array(
'comment' => array(
'title' => t('Comment'),
'help' => t('Display the comment with standard comment view.'),
'handler' => 'views_plugin_row_comment_view',
'theme' => 'views_view_row_comment',
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
'base' => array('comment'), // only works with 'comment' as base.
'uses options' => TRUE,
'type' => 'normal',
'help topic' => 'style-comment',
),
'comment_rss' => array(
'title' => t('Comment'),
'help' => t('Display the comment as RSS.'),
'handler' => 'views_plugin_row_comment_rss',
'theme' => 'views_view_row_rss',
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
'base' => array('comment'), // only works with 'comment' as base.
'uses options' => TRUE,
'type' => 'feed',
'help topic' => 'style-comment-rss',
),
),
);
}
/**
* Template helper for theme_views_view_row_comment
*/
function template_preprocess_views_view_row_comment(&$vars) {
$options = $vars['options'];
$view = &$vars['view'];
$plugin = &$view->style_plugin->row_plugin;
$comment = $plugin->comments[$vars['row']->{$vars['field_alias']}];
$node = $plugin->nodes[$comment->nid];
// Put the view on the node so we can retrieve it in the preprocess.
$node->view = &$view;
$build = comment_view_multiple(array($comment->cid => $comment), $node, $plugin->options['view_mode']);
// If we're displaying the comments without links, remove them from the
// renderable array. There is no way to avoid building them in the first
// place (see comment_build_content()).
if (empty($options['links'])) {
foreach ($build as $cid => &$comment_build) {
if (isset($comment_build['links'])) {
unset($comment_build['links']);
}
}
}
$vars['comment'] = drupal_render($build);
}

View File

@@ -0,0 +1,283 @@
<?php
/**
* @file
* Bulk export of views_default objects generated by Bulk export module.
*/
/**
* Implementation of hook_views_default_views()
*/
function comment_views_default_views() {
$views = array();
$view = new view;
$view->name = 'comments_recent';
$view->description = 'Contains a block and a page to list recent comments; the block will automatically link to the page, which displays the comment body as well as a link to the node.';
$view->tag = 'default';
$view->base_table = 'comment';
$view->human_name = 'Recent comments';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Recent comments';
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = 5;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Comment: Content */
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
$handler->display->display_options['relationships']['nid']['table'] = 'comment';
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
/* Field: Comment: Title */
$handler->display->display_options['fields']['subject']['id'] = 'subject';
$handler->display->display_options['fields']['subject']['table'] = 'comment';
$handler->display->display_options['fields']['subject']['field'] = 'subject';
$handler->display->display_options['fields']['subject']['label'] = '';
$handler->display->display_options['fields']['subject']['link_to_comment'] = 1;
/* Field: Comment: Updated date */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'comment';
$handler->display->display_options['fields']['timestamp']['field'] = 'changed';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['date_format'] = 'time ago';
/* Sort criterion: Comment: Updated date */
$handler->display->display_options['sorts']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['table'] = 'comment';
$handler->display->display_options['sorts']['timestamp']['field'] = 'changed';
$handler->display->display_options['sorts']['timestamp']['order'] = 'DESC';
/* Filter criterion: Content: Published or admin */
$handler->display->display_options['filters']['status_extra']['id'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['table'] = 'node';
$handler->display->display_options['filters']['status_extra']['field'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['relationship'] = 'nid';
$handler->display->display_options['filters']['status_extra']['group'] = 0;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['inline'] = array(
'title' => 'title',
'timestamp' => 'timestamp',
);
$handler->display->display_options['row_options']['separator'] = '&nbsp;';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'nid';
$handler->display->display_options['fields']['title']['label'] = 'Reply to';
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: Comment: Updated date */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'comment';
$handler->display->display_options['fields']['timestamp']['field'] = 'changed';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['date_format'] = 'time ago';
/* Field: Comment: Title */
$handler->display->display_options['fields']['subject']['id'] = 'subject';
$handler->display->display_options['fields']['subject']['table'] = 'comment';
$handler->display->display_options['fields']['subject']['field'] = 'subject';
$handler->display->display_options['fields']['subject']['label'] = '';
$handler->display->display_options['fields']['subject']['link_to_comment'] = 1;
/* Field: Comment: Comment */
$handler->display->display_options['fields']['comment']['id'] = 'comment';
$handler->display->display_options['fields']['comment']['table'] = 'field_data_comment_body';
$handler->display->display_options['fields']['comment']['field'] = 'comment_body';
$handler->display->display_options['fields']['comment']['label'] = '';
$handler->display->display_options['path'] = 'comments/recent';
/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$translatables['comments_recent'] = array(
t('Master'),
t('Recent comments'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Content'),
t('Page'),
t('Reply to'),
t('Block'),
);
$views['comments_recent'] = $view;
$view = new view;
$view->name = 'tracker';
$view->description = 'Shows all new activity on system.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Tracker';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Recent posts';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '25';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'type' => 'type',
'title' => 'title',
'name' => 'name',
'comment_count' => 'comment_count',
'last_comment_timestamp' => 'last_comment_timestamp',
'timestamp' => 'title',
'new_comments' => 'comment_count',
);
$handler->display->display_options['style_options']['default'] = 'last_comment_timestamp';
$handler->display->display_options['style_options']['info'] = array(
'type' => array(
'sortable' => 1,
'separator' => '',
),
'title' => array(
'sortable' => 1,
'separator' => '&nbsp;',
),
'name' => array(
'sortable' => 1,
'separator' => '',
),
'comment_count' => array(
'sortable' => 1,
'separator' => '<br />',
),
'last_comment_timestamp' => array(
'sortable' => 1,
'separator' => '&nbsp;',
),
'timestamp' => array(
'separator' => '',
),
'new_comments' => array(
'separator' => '',
),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['order'] = 'desc';
/* Relationship: Content: Author */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'node';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
/* Field: Content: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'node';
$handler->display->display_options['fields']['type']['field'] = 'type';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'uid';
$handler->display->display_options['fields']['name']['label'] = 'Author';
/* Field: Content: Comment count */
$handler->display->display_options['fields']['comment_count']['id'] = 'comment_count';
$handler->display->display_options['fields']['comment_count']['table'] = 'node_comment_statistics';
$handler->display->display_options['fields']['comment_count']['field'] = 'comment_count';
$handler->display->display_options['fields']['comment_count']['label'] = 'Replies';
/* Field: Content: Last comment time */
$handler->display->display_options['fields']['last_comment_timestamp']['id'] = 'last_comment_timestamp';
$handler->display->display_options['fields']['last_comment_timestamp']['table'] = 'node_comment_statistics';
$handler->display->display_options['fields']['last_comment_timestamp']['field'] = 'last_comment_timestamp';
$handler->display->display_options['fields']['last_comment_timestamp']['label'] = 'Last Post';
/* Field: Content: Has new content */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'history';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['link_to_node'] = 0;
$handler->display->display_options['fields']['timestamp']['comments'] = 1;
/* Field: Content: New comments */
$handler->display->display_options['fields']['new_comments']['id'] = 'new_comments';
$handler->display->display_options['fields']['new_comments']['table'] = 'node';
$handler->display->display_options['fields']['new_comments']['field'] = 'new_comments';
$handler->display->display_options['fields']['new_comments']['label'] = '';
$handler->display->display_options['fields']['new_comments']['hide_empty'] = TRUE;
$handler->display->display_options['fields']['new_comments']['suffix'] = ' new';
$handler->display->display_options['fields']['new_comments']['link_to_comment'] = 1;
/* Sort criterion: Content: Last comment time */
$handler->display->display_options['sorts']['last_comment_timestamp']['id'] = 'last_comment_timestamp';
$handler->display->display_options['sorts']['last_comment_timestamp']['table'] = 'node_comment_statistics';
$handler->display->display_options['sorts']['last_comment_timestamp']['field'] = 'last_comment_timestamp';
/* Contextual filter: Content: User posted or commented */
$handler->display->display_options['arguments']['uid_touch']['id'] = 'uid_touch';
$handler->display->display_options['arguments']['uid_touch']['table'] = 'node';
$handler->display->display_options['arguments']['uid_touch']['field'] = 'uid_touch';
$handler->display->display_options['arguments']['uid_touch']['exception']['title_enable'] = 1;
$handler->display->display_options['arguments']['uid_touch']['title_enable'] = 1;
$handler->display->display_options['arguments']['uid_touch']['title'] = 'Recent posts for %1';
$handler->display->display_options['arguments']['uid_touch']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['uid_touch']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid_touch']['specify_validation'] = 1;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'tracker';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'Recent posts';
$translatables['tracker'] = array(
t('Master'),
t('Recent posts'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('Type'),
t('Title'),
t('Author'),
t('Replies'),
t('.'),
t(','),
t('Last Post'),
t(' new'),
t('All'),
t('Recent posts for %1'),
t('Page'),
);
$views['tracker'] = $view;
return $views;
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* @file
* Definition of views_handler_argument_comment_user_uid.
*/
/**
* Argument handler to accept a user id to check for nodes that
* user posted or commented on.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_comment_user_uid extends views_handler_argument {
function title() {
if (!$this->argument) {
$title = variable_get('anonymous', t('Anonymous'));
}
else {
$title = db_query('SELECT u.name FROM {users} u WHERE u.uid = :uid', array(':uid' => $this->argument))->fetchField();
}
if (empty($title)) {
return t('No user');
}
return check_plain($title);
}
function default_actions($which = NULL) {
// Disallow summary views on this argument.
if (!$which) {
$actions = parent::default_actions();
unset($actions['summary asc']);
unset($actions['summary desc']);
return $actions;
}
if ($which != 'summary asc' && $which != 'summary desc') {
return parent::default_actions($which);
}
}
function query($group_by = FALSE) {
$this->ensure_my_table();
$subselect = db_select('comment', 'c');
$subselect->addField('c', 'cid');
$subselect->condition('c.uid', $this->argument);
$subselect->where("c.nid = $this->table_alias.nid");
$condition = db_or()
->condition("$this->table_alias.uid", $this->argument, '=')
->exists($subselect);
$this->query->add_where(0, $condition);
}
function get_sort_name() {
return t('Numerical', array(), array('context' => 'Sort order'));
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* @file
* Definition of views_handler_field_comment.
*/
/**
* Field handler to allow linking to a comment.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment extends views_handler_field {
/**
* Override init function to provide generic option to link to comment.
*/
function init(&$view, &$options) {
parent::init($view, $options);
if (!empty($this->options['link_to_comment'])) {
$this->additional_fields['cid'] = 'cid';
$this->additional_fields['nid'] = 'nid';
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_comment'] = array('default' => TRUE, 'bool' => TRUE);
$options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link-to-comment option
*/
function options_form(&$form, &$form_state) {
$form['link_to_comment'] = array(
'#title' => t('Link this field to its comment'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_comment'],
);
$form['link_to_node'] = array(
'#title' => t('Link field to the node if there is no comment.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_node'],
);
parent::options_form($form, $form_state);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_comment'])) {
$this->options['alter']['make_link'] = TRUE;
$nid = $this->get_value($values, 'nid');
$cid = $this->get_value($values, 'cid');
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
else if ($this->options['link_to_node']) {
$this->options['alter']['path'] = "node/" . $nid;
}
}
return $data;
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_depth.
*/
/**
* Field handler to display the depth of a comment.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_depth extends views_handler_field {
/**
* Work out the depth of this comment
*/
function render($values) {
$comment_thread = $this->get_value($values);
return count(explode('.', $comment_thread)) - 1;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link.
*/
/**
* Base field handler to present a link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link extends views_handler_field_entity {
function construct() {
parent::construct();
}
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
$options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
$form['link_to_node'] = array(
'#title' => t('Link field to the node if there is no comment.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_node'],
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$value = $this->get_value($values, 'cid');
return $this->render_link($this->sanitize_value($value), $values);
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
$comment = $this->get_value($values);
$nid = $comment->nid;
$cid = $comment->cid;
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['html'] = TRUE;
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
else if ($this->options['link_to_node']) {
$this->options['alter']['path'] = "node/" . $nid;
}
return $text;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_approve.
*/
/**
* Provides a comment approve link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_approve extends views_handler_field_comment_link {
function access() {
//needs permission to administer comments in general
return user_access('administer comments');
}
function render_link($data, $values) {
$status = $this->get_value($values, 'status');
// Don't show an approve link on published nodes.
if ($status == COMMENT_PUBLISHED) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('approve');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/" . $cid . "/approve";
$this->options['alter']['query'] = drupal_get_destination() + array('token' => drupal_get_token("comment/$cid/approve"));
return $text;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_delete.
*/
/**
* Field handler to present a link to delete a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_delete extends views_handler_field_comment_link {
function access() {
//needs permission to administer comments in general
return user_access('administer comments');
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/" . $cid . "/delete";
$this->options['alter']['query'] = drupal_get_destination();
return $text;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_edit.
*/
/**
* Field handler to present a link node edit.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_edit extends views_handler_field_comment_link {
function option_definition() {
$options = parent::option_definition();
$options['destination'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['destination'] = array(
'#type' => 'checkbox',
'#title' => t('Use destination'),
'#description' => t('Add destination to the link'),
'#default_value' => $this->options['destination'],
'#fieldset' => 'more',
);
}
function render_link($data, $values) {
parent::render_link($data, $values);
// ensure user has access to edit this comment.
$comment = $this->get_value($values);
if (!comment_access('edit', $comment)) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
unset($this->options['alter']['fragment']);
if (!empty($this->options['destination'])) {
$this->options['alter']['query'] = drupal_get_destination();
}
$this->options['alter']['path'] = "comment/" . $comment->cid . "/edit";
return $text;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_link_reply.
*/
/**
* Field handler to present a link to delete a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_reply extends views_handler_field_comment_link {
function access() {
//check for permission to reply to comments
return user_access('post comments');
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('reply');
$nid = $this->get_value($values, 'nid');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/reply/" . $nid . '/' . $cid;
return $text;
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_node_link.
*/
/**
* Handler for showing comment module's node link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_node_link extends views_handler_field_entity {
function construct() {
parent::construct();
// Add the node fields that comment_link will need..
$this->additional_fields['nid'] = array(
'field' => 'nid',
);
$this->additional_fields['type'] = array(
'field' => 'type',
);
$this->additional_fields['comment'] = array(
'field' => 'comment',
);
}
function option_definition() {
$options = parent::option_definition();
$options['teaser'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['teaser'] = array(
'#type' => 'checkbox',
'#title' => t('Show teaser-style link'),
'#default_value' => $this->options['teaser'],
'#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'),
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
// Build fake $node.
$node = $this->get_value($values);
// Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
// Call node by reference so that something is changed here
comment_node_view($node, $this->options['teaser'] ? 'teaser' : 'full');
// question: should we run these through: drupal_alter('link', $links, $node);
// might this have unexpected consequences if these hooks expect items in $node that we don't have?
// Only render the links, if they are defined.
return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* @file
* Definition of views_handler_field_comment_username.
*/
/**
* Field handler to allow linking to a user account or homepage.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_username extends views_handler_field {
/**
* Override init function to add uid and homepage fields.
*/
function init(&$view, &$data) {
parent::init($view, $data);
$this->additional_fields['uid'] = 'uid';
$this->additional_fields['homepage'] = 'homepage';
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['link_to_user'] = array(
'#title' => t("Link this field to its user or an author's homepage"),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_user'],
);
parent::options_form($form, $form_state);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account->uid = $this->get_value($values, 'uid');
$account->name = $this->get_value($values);
$account->homepage = $this->get_value($values, 'homepage');
return theme('username', array(
'account' => $account
));
}
else {
return $data;
}
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @file
* Definition of views_handler_field_last_comment_timestamp.
*/
/**
* Field handler to display the timestamp of a comment with the count of comments.
*
* @ingroup views_field_handlers
*/
class views_handler_field_last_comment_timestamp extends views_handler_field_date {
function construct() {
parent::construct();
$this->additional_fields['comment_count'] = 'comment_count';
}
function render($values) {
$comment_count = $this->get_value($values, 'comment_count');
if (empty($this->options['empty_zero']) || $comment_count) {
return parent::render($values);
}
else {
return NULL;
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* @file
* Definition of views_handler_field_ncs_last_comment_name.
*/
/**
* Field handler to present the name of the last comment poster.
*
* @ingroup views_field_handlers
*/
class views_handler_field_ncs_last_comment_name extends views_handler_field {
function query() {
// last_comment_name only contains data if the user is anonymous. So we
// have to join in a specially related user table.
$this->ensure_my_table();
// join 'users' to this table via vid
$join = new views_join();
$join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
$join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0'));
// ncs_user alias so this can work with the sort handler, below.
// $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship);
$this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
$this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field);
$this->user_field = $this->query->add_field($this->user_table, 'name');
$this->uid = $this->query->add_field($this->table_alias, 'last_comment_uid');
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function render($values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account->name = $this->get_value($values);
$account->uid = $values->{$this->uid};
return theme('username', array(
'account' => $account
));
}
else {
return $this->sanitize_value($this->get_value($values));
}
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Definition of views_handler_field_ncs_last_updated.
*/
/**
* Field handler to display the newer of last comment / node updated.
*
* @ingroup views_field_handlers
*/
class views_handler_field_ncs_last_updated extends views_handler_field_date {
function query() {
$this->ensure_my_table();
$this->node_table = $this->query->ensure_table('node', $this->relationship);
$this->field_alias = $this->query->add_field(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)", $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_field_node_comment.
*/
/**
* Display node comment status.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_comment extends views_handler_field {
function render($values) {
$value = $this->get_value($values);
switch ($value) {
case COMMENT_NODE_HIDDEN:
default:
return t('Hidden');
case COMMENT_NODE_CLOSED:
return t('Closed');
case COMMENT_NODE_OPEN:
return t('Open');
}
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* @file
* Definition of views_handler_field_node_new_comments.
*/
/**
* Field handler to display the number of new comments.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_new_comments extends views_handler_field_numeric {
function init(&$view, &$options) {
parent::init($view, $options);
// translate an older setting:
if (!empty($options['no_empty'])) {
$this->options['hide_empty'] = TRUE;
unset($this->options['no_empty']);
}
}
function construct() {
parent::construct();
$this->additional_fields['nid'] = 'nid';
$this->additional_fields['type'] = 'type';
$this->additional_fields['comment_count'] = array('table' => 'node_comment_statistics', 'field' => 'comment_count');
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_comment'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['link_to_comment'] = array(
'#title' => t('Link this field to new comments'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_comment'],
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
$this->field_alias = $this->table . '_' . $this->field;
}
function pre_render(&$values) {
global $user;
if (!$user->uid || empty($values)) {
return;
}
$nids = array();
$ids = array();
foreach ($values as $id => $result) {
$nids[] = $result->{$this->aliases['nid']};
$values[$id]->{$this->field_alias} = 0;
// Create a reference so we can find this record in the values again.
if (empty($ids[$result->{$this->aliases['nid']}])) {
$ids[$result->{$this->aliases['nid']}] = array();
}
$ids[$result->{$this->aliases['nid']}][] = $id;
}
if ($nids) {
$result = db_query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment} c ON n.nid = c.nid
LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN (:nids)
AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid ", array(
':status' => COMMENT_PUBLISHED,
':h_uid' => $user->uid,
':nids' => $nids,
':timestamp' => NODE_NEW_LIMIT,
));
foreach ($result as $node) {
foreach ($ids[$node->nid] as $id) {
$values[$id]->{$this->field_alias} = $node->num_comments;
}
}
}
}
function render_link($data, $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$node = new stdClass();
$node->nid = $this->get_value($values, 'nid');
$node->type = $this->get_value($values, 'type');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->nid;
$this->options['alter']['query'] = comment_new_page_count($this->get_value($values, 'comment_count'), $this->get_value($values), $node);
$this->options['alter']['fragment'] = 'new';
}
return $data;
}
function render($values) {
$value = $this->get_value($values);
if (!empty($value)) {
return $this->render_link(parent::render($values), $values);
}
else {
$this->options['alter']['make_link'] = FALSE;
}
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* Definition of views_handler_filter_comment_user_uid.
*/
/**
* Filter handler to accept a user id to check for nodes that user posted or
* commented on.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_comment_user_uid extends views_handler_filter_user_name {
function query() {
$this->ensure_my_table();
$subselect = db_select('comment', 'c');
$subselect->addField('c', 'cid');
$subselect->condition('c.uid', $this->value, $this->operator);
$subselect->where("c.nid = $this->table_alias.nid");
$condition = db_or()
->condition("$this->table_alias.uid", $this->value, $this->operator)
->exists($subselect);
$this->query->add_where($this->options['group'], $condition);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* @file
* Definition of views_handler_filter_ncs_last_updated.
*/
/**
* Filter handler for the newer of last comment / node updated.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_ncs_last_updated extends views_handler_filter_date {
function query() {
$this->ensure_my_table();
$this->node_table = $this->query->ensure_table('node', $this->relationship);
$field = "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)";
$info = $this->operators();
if (!empty($info[$this->operator]['method'])) {
$this->{$info[$this->operator]['method']}($field);
}
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Definition of views_handler_filter_node_comment.
*/
/**
* Filter based on comment node status.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_comment extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_options = array(
COMMENT_NODE_HIDDEN => t('Hidden'),
COMMENT_NODE_CLOSED => t('Closed'),
COMMENT_NODE_OPEN => t('Open'),
);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @file
* Definition of views_handler_sort_comment_thread.
*/
/**
* Sort handler for ordering by thread.
*
* @ingroup views_sort_handlers
*/
class views_handler_sort_comment_thread extends views_handler_sort {
function query() {
$this->ensure_my_table();
//Read comment_render() in comment.module for an explanation of the
//thinking behind this sort.
if ($this->options['order'] == 'DESC') {
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
}
else {
$alias = $this->table_alias . '_' . $this->real_field . 'asc';
//@todo is this secure?
$this->query->add_orderby(NULL, "SUBSTRING({$this->table_alias}.{$this->real_field}, 1, (LENGTH({$this->table_alias}.{$this->real_field}) - 1))", $this->options['order'], $alias);
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* @file
* Definition of views_handler_sort_ncs_last_comment_name.
*/
/**
* Sort handler to sort by last comment name which might be in 2 different
* fields.
*
* @ingroup views_sort_handlers
*/
class views_handler_sort_ncs_last_comment_name extends views_handler_sort {
function query() {
$this->ensure_my_table();
$join = new views_join();
$join->construct('users', $this->table_alias, 'last_comment_uid', 'uid');
// @todo this might be safer if we had an ensure_relationship rather than guessing
// the table alias. Though if we did that we'd be guessing the relationship name
// so that doesn't matter that much.
// $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship);
$this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join);
$this->user_field = $this->query->add_field($this->user_table, 'name');
// Add the field.
$this->query->add_orderby(NULL, "LOWER(COALESCE($this->user_table.name, $this->table_alias.$this->field))", $this->options['order'], $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* @file
* Definition of views_handler_sort_ncs_last_updated.
*/
/**
* Sort handler for the newer of last comment / node updated.
*
* @ingroup views_sort_handlers
*/
class views_handler_sort_ncs_last_updated extends views_handler_sort_date {
function query() {
$this->ensure_my_table();
$this->node_table = $this->query->ensure_table('node', $this->relationship);
$this->field_alias = $this->query->add_orderby(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)", $this->options['order'], $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* @file
* Contains the comment RSS row style plugin.
*/
/**
* Plugin which formats the comments as RSS items.
*/
class views_plugin_row_comment_rss extends views_plugin_row {
var $base_table = 'comment';
var $base_field = 'cid';
function option_definition() {
$options = parent::option_definition();
$options['item_length'] = array('default' => 'default');
$options['links'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['item_length'] = array(
'#type' => 'select',
'#title' => t('Display type'),
'#options' => $this->options_form_summary_options(),
'#default_value' => $this->options['item_length'],
);
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
}
function pre_render($result) {
$cids = array();
$nids = array();
foreach ($result as $row) {
$cids[] = $row->cid;
}
$this->comments = comment_load_multiple($cids);
foreach ($this->comments as &$comment) {
$comment->depth = count(explode('.', $comment->thread)) - 1;
$nids[] = $comment->nid;
}
$this->nodes = node_load_multiple($nids);
}
/**
* Return the main options, which are shown in the summary title
*
* @see views_plugin_row_node_rss::options_form_summary_options()
* @todo: Maybe provide a views_plugin_row_rss_entity and reuse this method
* in views_plugin_row_comment|node_rss.inc
*/
function options_form_summary_options() {
$entity_info = entity_get_info('node');
$options = array();
if (!empty($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) {
$options[$mode] = $settings['label'];
}
}
$options['title'] = t('Title only');
$options['default'] = t('Use site default RSS settings');
return $options;
}
function render($row) {
global $base_url;
$cid = $row->{$this->field_alias};
if (!is_numeric($cid)) {
return;
}
$item_length = $this->options['item_length'];
if ($item_length == 'default') {
$item_length = variable_get('feed_item_length', 'teaser');
}
// Load the specified comment and its associated node:
$comment = $this->comments[$cid];
if (empty($comment) || empty($this->nodes[$comment->nid])) {
return;
}
$item_text = '';
$uri = entity_uri('comment', $comment);
$comment->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
$comment->rss_namespaces = array();
$comment->rss_elements = array(
array(
'key' => 'pubDate',
'value' => gmdate('r', $comment->created),
),
array(
'key' => 'dc:creator',
'value' => $comment->name,
),
array(
'key' => 'guid',
'value' => 'comment ' . $comment->cid . ' at ' . $base_url,
'attributes' => array('isPermaLink' => 'false'),
),
);
// The comment gets built and modules add to or modify
// $comment->rss_elements and $comment->rss_namespaces.
$build = comment_view($comment, $this->nodes[$comment->nid], 'rss');
unset($build['#theme']);
if (!empty($comment->rss_namespaces)) {
$this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces);
}
// Hide the links if desired.
if (!$this->options['links']) {
hide($build['links']);
}
if ($item_length != 'title') {
// We render comment contents and force links to be last.
$build['links']['#weight'] = 1000;
$item_text .= drupal_render($build);
}
$item = new stdClass();
$item->description = $item_text;
$item->title = $comment->subject;
$item->link = $comment->link;
$item->elements = $comment->rss_elements;
$item->cid = $comment->cid;
return theme($this->theme_functions(), array(
'view' => $this->view,
'options' => $this->options,
'row' => $item
));
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* @file
* Contains the node RSS row style plugin.
*/
/**
* Plugin which performs a comment_view on the resulting object.
*/
class views_plugin_row_comment_view extends views_plugin_row {
var $base_field = 'cid';
var $base_table = 'comment';
/**
* Stores all comments which are preloaded.
*/
var $comments = array();
/**
* Stores all nodes of all comments which are preloaded.
*/
var $nodes = array();
function summary_title() {
return t('Settings');
}
function option_definition() {
$options = parent::option_definition();
$options['links'] = array('default' => TRUE, 'bool' => TRUE);
$options['view_mode'] = array('default' => 'full');
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$options = $this->options_form_summary_options();
$form['view_mode'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('View mode'),
'#default_value' => $this->options['view_mode'],
);
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
}
/**
* Return the main options, which are shown in the summary title.
*/
function options_form_summary_options() {
$entity_info = entity_get_info('comment');
$options = array();
if (!empty($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) {
$options[$mode] = $settings['label'];
}
}
if (empty($options)) {
$options = array(
'full' => t('Full content')
);
}
return $options;
}
function pre_render($result) {
$cids = array();
foreach ($result as $row) {
$cids[] = $row->cid;
}
// Load all comments.
$cresult = comment_load_multiple($cids);
$nids = array();
foreach ($cresult as $comment) {
$comment->depth = count(explode('.', $comment->thread)) - 1;
$this->comments[$comment->cid] = $comment;
$nids[] = $comment->nid;
}
// Load all nodes of the comments.
$nodes = node_load_multiple(array_unique($nids));
foreach ($nodes as $node) {
$this->nodes[$node->nid] = $node;
}
}
}

21
modules/contact.views.inc Normal file
View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Provide views data and handlers for contact.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data_alter().
*/
function contact_views_data_alter(&$data) {
$data['users']['contact'] = array(
'field' => array(
'title' => t('Link to contact page'),
'help' => t('Provide a simple link to the user contact page.'),
'handler' => 'views_handler_field_contact_link',
),
);
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* @file
* Definition of views_handler_field_contact_link.
*/
/**
* A field that links to the user contact page, if access is permitted.
*
* @ingroup views_field_handlers
*/
class views_handler_field_contact_link extends views_handler_field_user_link {
function options_form(&$form, &$form_state) {
$form['text']['#title'] = t('Link label');
$form['text']['#required'] = TRUE;
$form['text']['#default_value'] = empty($this->options['text']) ? t('contact') : $this->options['text'];
parent::options_form($form, $form_state);
}
// An example of field level access control.
// We must override the access method in the parent class, as that requires
// the 'access user profiles' permission, which the contact form does not.
function access() {
return user_access('access user contact forms');
}
function render_link($data, $values) {
global $user;
$uid = $this->get_value($values, 'uid');
if (empty($uid)) {
return;
}
$account = user_load($uid);
if (empty($account)) {
return;
}
// Check access when we pull up the user account so we know
// if the user has made the contact page available.
$menu_item = menu_get_item("user/$uid/contact");
if (!$menu_item['access'] || empty($account->data['contact'])) {
return;
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'user/' . $account->uid . '/contact';
$this->options['alter']['attributes'] = array('title' => t('Contact %user', array('%user' => $account->name)));
$text = $this->options['text'];
return $text;
}
}

504
modules/field.views.inc Normal file
View File

@@ -0,0 +1,504 @@
<?php
/**
* @file
* Provide Views data and handlers for field.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*
* Field modules can implement hook_field_views_data() to override
* the default behavior for adding fields.
*/
function field_views_data() {
$data = array();
foreach (field_info_fields() as $field) {
if ($field['storage']['type'] != 'field_sql_storage') {
continue;
}
$module = $field['module'];
$result = (array) module_invoke($module, 'field_views_data', $field);
if (empty($result)) {
$result = field_views_field_default_views_data($field);
}
drupal_alter('field_views_data', $result, $field, $module);
if (is_array($result)) {
$data = drupal_array_merge_deep($result, $data);
}
}
return $data;
}
/**
* Implements hook_views_data_alter().
*
* Field modules can implement hook_field_views_data_views_data_alter() to
* alter the views data on a per field basis. This is weirdly named so as
* not to conflict with the drupal_alter('field_views_data') in
* field_views_data.
*/
function field_views_data_alter(&$data) {
foreach (field_info_fields() as $field) {
if ($field['storage']['type'] != 'field_sql_storage') {
continue;
}
$function = $field['module'] . '_field_views_data_views_data_alter';
if (function_exists($function)) {
$function($data, $field);
}
}
}
/**
* Returns the label of a certain field.
*
* Therefore it looks up in all bundles to find the most used instance.
*/
function field_views_field_label($field_name) {
$label_counter = array();
$all_labels = array();
// Count the amount of instances per label per field.
$instances = field_info_instances();
foreach ($instances as $entity_name => $entity_type) {
foreach ($entity_type as $bundle) {
if (isset($bundle[$field_name])) {
$label_counter[$bundle[$field_name]['label']] = isset($label_counter[$bundle[$field_name]['label']]) ? ++$label_counter[$bundle[$field_name]['label']] : 1;
$all_labels[$entity_name][$bundle[$field_name]['label']] = TRUE;
}
}
}
if (empty($label_counter)) {
return array($field_name, $all_labels);
}
// Sort the field lables by it most used label and return the most used one.
arsort($label_counter);
$label_counter = array_keys($label_counter);
return array($label_counter[0], $all_labels);
}
/**
* Default views data implementation for a field.
*/
function field_views_field_default_views_data($field) {
$field_types = field_info_field_types();
// Check the field module is available.
if (!isset($field_types[$field['type']])) {
return;
}
$data = array();
$current_table = _field_sql_storage_tablename($field);
$revision_table = _field_sql_storage_revision_tablename($field);
// The list of entity:bundle that this field is used in.
$bundles_names = array();
$supports_revisions = FALSE;
$entity_tables = array();
$current_tables = array();
$revision_tables = array();
$groups = array();
$group_name = count($field['bundles']) > 1 ? t('Field') : NULL;
// Build the relationships between the field table and the entity tables.
foreach ($field['bundles'] as $entity => $bundles) {
$entity_info = entity_get_info($entity);
$groups[$entity] = $entity_info['label'];
// Override Node to Content.
if ($groups[$entity] == t('Node')) {
$groups[$entity] = t('Content');
}
// If only one bundle use this as the default name.
if (empty($group_name)) {
$group_name = $groups[$entity];
}
$entity_tables[$entity_info['base table']] = $entity;
$current_tables[$entity] = $entity_info['base table'];
if (isset($entity_info['revision table'])) {
$entity_tables[$entity_info['revision table']] = $entity;
$revision_tables[$entity] = $entity_info['revision table'];
}
$data[$current_table]['table']['join'][$entity_info['base table']] = array(
'left_field' => $entity_info['entity keys']['id'],
'field' => 'entity_id',
'extra' => array(
array('field' => 'entity_type', 'value' => $entity),
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
),
);
if (!empty($entity_info['entity keys']['revision']) && !empty($entity_info['revision table'])) {
$data[$revision_table]['table']['join'][$entity_info['revision table']] = array(
'left_field' => $entity_info['entity keys']['revision'],
'field' => 'revision_id',
'extra' => array(
array('field' => 'entity_type', 'value' => $entity),
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
),
);
$supports_revisions = TRUE;
}
foreach ($bundles as $bundle) {
$bundles_names[] = t('@entity:@bundle', array('@entity' => $entity, '@bundle' => $bundle));
}
}
$tables = array();
$tables[FIELD_LOAD_CURRENT] = $current_table;
if ($supports_revisions) {
$tables[FIELD_LOAD_REVISION] = $revision_table;
}
$add_fields = array('delta', 'language', 'bundle');
foreach ($field['columns'] as $column_name => $attributes) {
$add_fields[] = _field_sql_storage_columnname($field['field_name'], $column_name);
}
// Note: we don't have a label available here, because we are at the field
// level, not at the instance level. So we just go through all instances
// and take the one which is used the most frequently.
$field_name = $field['field_name'];
list($label, $all_labels) = field_views_field_label($field_name);
foreach ($tables as $type => $table) {
if ($type == FIELD_LOAD_CURRENT) {
$group = $group_name;
$old_column = 'entity_id';
$column = $field['field_name'];
}
else {
$group = t('@group (historical data)', array('@group' => $group_name));
$old_column = 'revision_id';
$column = $field['field_name'] . '-' . $old_column;
}
$data[$table][$old_column]['field']['moved to'] = array($table, $column);
$data[$table][$column] = array(
'group' => $group,
'title' => $label,
'title short' => $label,
'help' => t('Appears in: @bundles.', array('@bundles' => implode(', ', $bundles_names))),
);
// Go through and create a list of aliases for all possible combinations of
// entity type + name.
$aliases = array();
$also_known = array();
foreach ($all_labels as $entity_name => $labels) {
foreach ($labels as $label_name => $true) {
if ($type == FIELD_LOAD_CURRENT) {
if ($group_name != $groups[$entity_name] || $label != $label_name) {
$aliases[] = array(
'base' => $current_tables[$entity_name],
'group' => $groups[$entity_name],
'title' => $label_name,
'help' => t('This is an alias of @group: @field.', array('@group' => $group_name, '@field' => $label)),
);
}
$also_known[] = t('@group: @field', array('@group' => $groups[$entity_name], '@field' => $label_name));
}
else {
if ($group_name != $groups[$entity_name] && $label != $label_name && isset($revision_tables[$entity_name])) {
$aliases[] = array(
'base' => $revision_tables[$entity_name],
'group' => t('@group (historical data)', array('@group' => $groups[$entity_name])),
'title' => $label_name,
'help' => t('This is an alias of @group: @field.', array('@group' => $group_name, '@field' => $label)),
);
}
$also_known[] = t('@group (historical data): @field', array('@group' => $groups[$entity_name], '@field' => $label_name));
}
}
}
if ($aliases) {
$data[$table][$column]['aliases'] = $aliases;
$data[$table][$column]['help'] .= ' ' . t('Also known as: !also.', array('!also' => implode(', ', $also_known)));
}
$keys = array_keys($field['columns']);
$real_field = reset($keys);
$data[$table][$column]['field'] = array(
'table' => $table,
'handler' => 'views_handler_field_field',
'click sortable' => TRUE,
'field_name' => $field['field_name'],
// Provide a real field for group by.
'real field' => $column . '_' . $real_field,
'additional fields' => $add_fields,
'entity_tables' => $entity_tables,
// Default the element type to div, let the UI change it if necessary.
'element type' => 'div',
'is revision' => $type == FIELD_LOAD_REVISION,
);
}
foreach ($field['columns'] as $column => $attributes) {
$allow_sort = TRUE;
// Identify likely filters and arguments for each column based on field type.
switch ($attributes['type']) {
case 'int':
case 'mediumint':
case 'tinyint':
case 'bigint':
case 'serial':
case 'numeric':
case 'float':
$filter = 'views_handler_filter_numeric';
$argument = 'views_handler_argument_numeric';
$sort = 'views_handler_sort';
break;
case 'text':
case 'blob':
// It does not make sense to sort by blob or text.
$allow_sort = FALSE;
default:
$filter = 'views_handler_filter_string';
$argument = 'views_handler_argument_string';
$sort = 'views_handler_sort';
break;
}
if (count($field['columns']) == 1 || $column == 'value') {
$title = t('@label (!name)', array('@label' => $label, '!name' => $field['field_name']));
// CCK used the first 10 characters of $label. Probably doesn't matter.
$title_short = $label;
}
else {
$title = t('@label (!name:!column)', array('@label' => $label, '!name' => $field['field_name'], '!column' => $column));
$title_short = t('@label:!column', array('@label' => $label, '!column' => $column));
}
foreach ($tables as $type => $table) {
if ($type == FIELD_LOAD_CURRENT) {
$group = $group_name;
}
else {
$group = t('@group (historical data)', array('@group' => $group_name));
}
$column_real_name = $field['storage']['details']['sql'][$type][$table][$column];
// Load all the fields from the table by default.
$additional_fields = array_values($field['storage']['details']['sql'][$type][$table]);
$data[$table][$column_real_name] = array(
'group' => $group,
'title' => $title,
'title short' => $title_short,
'help' => t('Appears in: @bundles.', array('@bundles' => implode(', ', $bundles_names))),
);
// Go through and create a list of aliases for all possible combinations of
// entity type + name.
$aliases = array();
$also_known = array();
foreach ($all_labels as $entity_name => $labels) {
foreach ($labels as $label_name => $true) {
if ($group_name != $groups[$entity_name] || $label != $label_name) {
if (count($field['columns']) == 1 || $column == 'value') {
$alias_title = t('@label (!name)', array('@label' => $label_name, '!name' => $field['field_name']));
// CCK used the first 10 characters of $label. Probably doesn't matter.
}
else {
$alias_title = t('@label (!name:!column)', array('@label' => $label_name, '!name' => $field['field_name'], '!column' => $column));
}
$aliases[] = array(
'group' => $groups[$entity_name],
'title' => $alias_title,
'help' => t('This is an alias of @group: @field.', array('@group' => $group_name, '@field' => $title)),
);
}
$also_known[] = t('@group: @field', array('@group' => $groups[$entity_name], '@field' => $title));
}
}
if ($aliases) {
$data[$table][$column_real_name]['aliases'] = $aliases;
$data[$table][$column_real_name]['help'] .= ' ' . t('Also known as: !also.', array('!also' => implode(', ', $also_known)));
}
$data[$table][$column_real_name]['argument'] = array(
'field' => $column_real_name,
'table' => $table,
'handler' => $argument,
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
'empty field name' => t('- No value -'),
);
$data[$table][$column_real_name]['filter'] = array(
'field' => $column_real_name,
'table' => $table,
'handler' => $filter,
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
'allow empty' => TRUE,
);
if (!empty($allow_sort)) {
$data[$table][$column_real_name]['sort'] = array(
'field' => $column_real_name,
'table' => $table,
'handler' => $sort,
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
);
}
// Expose additional delta column for multiple value fields.
if ($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
$title_delta = t('@label (!name:delta)', array('@label' => $label, '!name' => $field['field_name']));
$title_short_delta = t('@label:delta', array('@label' => $label));
$data[$table]['delta'] = array(
'group' => $group,
'title' => $title_delta,
'title short' => $title_short_delta,
'help' => t('Delta - Appears in: @bundles.', array('@bundles' => implode(', ', $bundles_names))),
);
$data[$table]['delta']['field'] = array(
'handler' => 'views_handler_field_numeric',
);
$data[$table]['delta']['argument'] = array(
'field' => 'delta',
'table' => $table,
'handler' => 'views_handler_argument_numeric',
'additional fields' => $additional_fields,
'empty field name' => t('- No value -'),
'field_name' => $field['field_name'],
);
$data[$table]['delta']['filter'] = array(
'field' => 'delta',
'table' => $table,
'handler' => 'views_handler_filter_numeric',
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
'allow empty' => TRUE,
);
$data[$table]['delta']['sort'] = array(
'field' => 'delta',
'table' => $table,
'handler' => 'views_handler_sort',
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
);
}
// Expose additional language column for translatable fields.
if (!empty($field['translatable'])) {
$title_language = t('@label (!name:language)', array('@label' => $label, '!name' => $field['field_name']));
$title_short_language = t('@label:language', array('@label' => $label));
$data[$table]['language'] = array(
'group' => $group,
'title' => $title_language,
'title short' => $title_short_language,
'help' => t('Language - Appears in: @bundles.', array('@bundles' => implode(', ', $bundles_names))),
);
$data[$table]['language']['field'] = array(
'handler' => 'views_handler_field_locale_language',
);
$data[$table]['language']['argument'] = array(
'field' => 'language',
'table' => $table,
'handler' => 'views_handler_argument_locale_language',
'additional fields' => $additional_fields,
'empty field name' => t('<No value>'),
'field_name' => $field['field_name'],
);
$data[$table]['language']['filter'] = array(
'field' => 'language',
'table' => $table,
'handler' => 'views_handler_filter_locale_language',
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
'allow empty' => TRUE,
);
$data[$table]['language']['sort'] = array(
'field' => 'language',
'table' => $table,
'handler' => 'views_handler_sort',
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
);
}
// Expose additional language column for translatable fields.
if (!empty($field['translatable'])) {
$title_language = t('@label (!name:language)', array('@label' => $label, '!name' => $field['field_name']));
$title_short_language = t('@label:language', array('@label' => $label));
$data[$table]['language'] = array(
'group' => $group,
'title' => $title_language,
'title short' => $title_short_language,
'help' => t('Language - Appears in: @bundles.', array('@bundles' => implode(', ', $bundles_names))),
);
$data[$table]['language']['field'] = array(
'handler' => 'views_handler_field_locale_language',
);
$data[$table]['language']['argument'] = array(
'field' => 'language',
'table' => $table,
'handler' => 'views_handler_argument_locale_language',
'additional fields' => $additional_fields,
'empty field name' => t('<No value>'),
'field_name' => $field['field_name'],
);
$data[$table]['language']['filter'] = array(
'field' => 'language',
'table' => $table,
'handler' => 'views_handler_filter_locale_language',
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
'allow empty' => TRUE,
);
$data[$table]['language']['sort'] = array(
'field' => 'language',
'table' => $table,
'handler' => 'views_handler_sort',
'additional fields' => $additional_fields,
'field_name' => $field['field_name'],
);
}
}
}
return $data;
}
/**
* Have a different filter handler for lists. This should allow to select values of the list.
*/
function list_field_views_data($field) {
$data = field_views_field_default_views_data($field);
foreach ($data as $table_name => $table_data) {
foreach ($table_data as $field_name => $field_data) {
if (isset($field_data['filter']) && $field_name != 'delta') {
$data[$table_name][$field_name]['filter']['handler'] = 'views_handler_filter_field_list';
}
if (isset($field_data['argument']) && $field_name != 'delta') {
if ($field['type'] == 'list_text') {
$data[$table_name][$field_name]['argument']['handler'] = 'views_handler_argument_field_list_string';
}
else {
$data[$table_name][$field_name]['argument']['handler'] = 'views_handler_argument_field_list';
}
}
}
}
return $data;
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* @file
* Definition of views_handler_argument_field_list.
*/
/**
* Argument handler for list field to show the human readable name in the
* summary.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_field_list extends views_handler_argument_numeric {
/**
* Stores the allowed values of this field.
*
* @var array
*/
var $allowed_values = NULL;
function init(&$view, &$options) {
parent::init($view, $options);
$field = field_info_field($this->definition['field_name']);
$this->allowed_values = list_allowed_values($field);
}
function option_definition() {
$options = parent::option_definition();
$options['summary']['contains']['human'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['summary']['human'] = array(
'#title' => t('Display list value as human readable'),
'#type' => 'checkbox',
'#default_value' => $this->options['summary']['human'],
'#dependency' => array('radio:options[default_action]' => array('summary')),
);
}
function summary_name($data) {
$value = $data->{$this->name_alias};
// If the list element has a human readable name show it,
if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) {
return field_filter_xss($this->allowed_values[$value]);
}
// else fallback to the key.
else {
return check_plain($value);
}
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* @file
* Definition of views_handler_argument_field_list_text.
*/
/**
* Argument handler for list field to show the human readable name in the
* summary.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_field_list_string extends views_handler_argument_string {
/**
* Stores the allowed values of this field.
*
* @var array
*/
var $allowed_values = NULL;
function init(&$view, &$options) {
parent::init($view, $options);
$field = field_info_field($this->definition['field_name']);
$this->allowed_values = list_allowed_values($field);
}
function option_definition() {
$options = parent::option_definition();
$options['summary']['contains']['human'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['summary']['human'] = array(
'#title' => t('Display list value as human readable'),
'#type' => 'checkbox',
'#default_value' => $this->options['summary']['human'],
'#dependency' => array('radio:options[default_action]' => array('summary')),
);
}
function summary_name($data) {
$value = $data->{$this->name_alias};
// If the list element has a human readable name show it,
if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) {
return $this->case_transform(field_filter_xss($this->allowed_values[$value]), $this->options['case']);
}
// else fallback to the key.
else {
return $this->case_transform(check_plain($value), $this->options['case']);
}
}
}

View File

@@ -0,0 +1,931 @@
<?php
/**
* @file
* Definition of views_handler_field_field.
*/
/**
* Helper function: Return an array of formatter options for a field type.
*
* Borrowed from field_ui.
*/
function _field_view_formatter_options($field_type = NULL) {
$options = &drupal_static(__FUNCTION__);
if (!isset($options)) {
$field_types = field_info_field_types();
$options = array();
foreach (field_info_formatter_types() as $name => $formatter) {
foreach ($formatter['field types'] as $formatter_field_type) {
// Check that the field type exists.
if (isset($field_types[$formatter_field_type])) {
$options[$formatter_field_type][$name] = $formatter['label'];
}
}
}
}
if ($field_type) {
return !empty($options[$field_type]) ? $options[$field_type] : array();
}
return $options;
}
/**
* A field that displays fieldapi fields.
*
* @ingroup views_field_handlers
*/
class views_handler_field_field extends views_handler_field {
/**
* An array to store field renderable arrays for use by render_items.
*
* @var array
*/
public $items = array();
/**
* Store the field information.
*
* @var array
*/
public $field_info = array();
/**
* Does the field supports multiple field values.
*
* @var bool
*/
public $multiple;
/**
* Does the rendered fields get limited.
*
* @var bool
*/
public $limit_values;
/**
* A shortcut for $view->base_table.
*
* @var string
*/
public $base_table;
/**
* Store the field instance.
*
* @var array
*/
public $instance;
function init(&$view, &$options) {
parent::init($view, $options);
$this->field_info = $field = field_info_field($this->definition['field_name']);
$this->multiple = FALSE;
$this->limit_values = FALSE;
if ($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
$this->multiple = TRUE;
// If "Display all values in the same row" is FALSE, then we always limit
// in order to show a single unique value per row.
if (!$this->options['group_rows']) {
$this->limit_values = TRUE;
}
// If "First and last only" is chosen, limit the values
if (!empty($this->options['delta_first_last'])) {
$this->limit_values = TRUE;
}
// Otherwise, we only limit values if the user hasn't selected "all", 0, or
// the value matching field cardinality.
if ((intval($this->options['delta_limit']) && ($this->options['delta_limit'] != $field['cardinality'])) || intval($this->options['delta_offset'])) {
$this->limit_values = TRUE;
}
}
// Convert old style entity id group column to new format.
// @todo Remove for next major version.
if ($this->options['group_column'] == 'entity id') {
$this->options['group_column'] = 'entity_id';
}
}
/**
* Check whether current user has access to this handler.
*
* @return bool
* Return TRUE if the user has access to view this field.
*/
function access() {
$base_table = $this->get_base_table();
return field_access('view', $this->field_info, $this->definition['entity_tables'][$base_table]);
}
/**
* Set the base_table and base_table_alias.
*
* @return string
* The base table which is used in the current view "context".
*/
function get_base_table() {
if (!isset($this->base_table)) {
// This base_table is coming from the entity not the field.
$this->base_table = $this->view->base_table;
// If the current field is under a relationship you can't be sure that the
// base table of the view is the base table of the current field.
// For example a field from a node author on a node view does have users as base table.
if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
$relationships = $this->view->display_handler->get_option('relationships');
if (!empty($relationships[$this->options['relationship']])) {
$options = $relationships[$this->options['relationship']];
$data = views_fetch_data($options['table']);
$this->base_table = $data[$options['field']]['relationship']['base'];
}
}
}
return $this->base_table;
}
/**
* Called to add the field to a query.
*
* By default, the only columns added to the query are entity_id and
* entity_type. This is because other needed data is fetched by entity_load().
* Other columns are added only if they are used in groupings, or if
* 'add fields to query' is specifically set to TRUE in the field definition.
*
* The 'add fields to query' switch is used by modules which need all data
* present in the query itself (such as "sphinx").
*/
function query($use_groupby = FALSE) {
$this->get_base_table();
$params = array();
if ($use_groupby) {
// When grouping on a "field API" field (whose "real_field" is set to
// entity_id), retrieve the minimum entity_id to have a valid entity_id to
// pass to field_view_field().
$params = array(
'function' => 'min',
);
$this->ensure_my_table();
}
// Get the entity type according to the base table of the field.
// Then add it to the query as a formula. That way we can avoid joining
// the field table if all we need is entity_id and entity_type.
$entity_type = $this->definition['entity_tables'][$this->base_table];
$entity_info = entity_get_info($entity_type);
if (isset($this->relationship)) {
$this->base_table_alias = $this->relationship;
}
else {
$this->base_table_alias = $this->base_table;
}
// We always need the base field (entity_id / revision_id).
if (empty($this->definition['is revision'])) {
$this->field_alias = $this->query->add_field($this->base_table_alias, $entity_info['entity keys']['id'], '', $params);
}
else {
$this->field_alias = $this->query->add_field($this->base_table_alias, $entity_info['entity keys']['revision'], '', $params);
$this->aliases['entity_id'] = $this->query->add_field($this->base_table_alias, $entity_info['entity keys']['id'], '', $params);
}
// The alias needs to be unique, so we use both the field table and the entity type.
$entity_type_alias = $this->definition['table'] . '_' . $entity_type . '_entity_type';
$this->aliases['entity_type'] = $this->query->add_field(NULL, "'$entity_type'", $entity_type_alias);
$fields = $this->additional_fields;
// We've already added entity_type, so we can remove it from the list.
$entity_type_key = array_search('entity_type', $fields);
if ($entity_type_key !== FALSE) {
unset($fields[$entity_type_key]);
}
if ($use_groupby) {
// Add the fields that we're actually grouping on.
$options = array();
if ($this->options['group_column'] != 'entity_id') {
$options = array($this->options['group_column'] => $this->options['group_column']);
}
$options += is_array($this->options['group_columns']) ? $this->options['group_columns'] : array();
$fields = array();
$rkey = $this->definition['is revision'] ? 'FIELD_LOAD_REVISION' : 'FIELD_LOAD_CURRENT';
// Go through the list and determine the actual column name from field api.
foreach ($options as $column) {
$name = $column;
if (isset($this->field_info['storage']['details']['sql'][$rkey][$this->table][$column])) {
$name = $this->field_info['storage']['details']['sql'][$rkey][$this->table][$column];
}
$fields[$column] = $name;
}
$this->group_fields = $fields;
}
// Add additional fields (and the table join itself) if needed.
if ($this->add_field_table($use_groupby)) {
$this->ensure_my_table();
$this->add_additional_fields($fields);
// Filter by language, if field translation is enabled.
$field = $this->field_info;
if (field_is_translatable($entity_type, $field) && !empty($this->view->display_handler->options['field_language_add_to_query'])) {
$column = $this->table_alias . '.language';
// By the same reason as field_language the field might be LANGUAGE_NONE in reality so allow it as well.
// @see this::field_language()
global $language_content;
$default_language = language_default('language');
$language = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
array($language_content->language, $default_language),
$this->view->display_handler->options['field_language']);
$placeholder = $this->placeholder();
$language_fallback_candidates = array($language);
if (variable_get('locale_field_language_fallback', TRUE)) {
require_once DRUPAL_ROOT . '/includes/language.inc';
$language_fallback_candidates = array_merge($language_fallback_candidates, language_fallback_get_candidates());
}
else {
$language_fallback_candidates[] = LANGUAGE_NONE;
}
$this->query->add_where_expression(0, "$column IN($placeholder) OR $column IS NULL", array($placeholder => $language_fallback_candidates));
}
}
// The revision id inhibits grouping.
// So, stop here if we're using grouping, or if aren't adding all columns to
// the query.
if ($use_groupby || empty($this->definition['add fields to query'])) {
return;
}
$this->add_additional_fields(array('revision_id'));
}
/**
* Determine if the field table should be added to the query.
*/
function add_field_table($use_groupby) {
// Grouping is enabled, or we are explicitly required to do this.
if ($use_groupby || !empty($this->definition['add fields to query'])) {
return TRUE;
}
// This a multiple value field, but "group multiple values" is not checked.
if ($this->multiple && !$this->options['group_rows']) {
return TRUE;
}
return FALSE;
}
/**
* Determine if this field is click sortable.
*/
function click_sortable() {
// Not click sortable in any case.
if (empty($this->definition['click sortable'])) {
return FALSE;
}
// A field is not click sortable if it's a multiple field with
// "group multiple values" checked, since a click sort in that case would
// add a join to the field table, which would produce unwanted duplicates.
if ($this->multiple && $this->options['group_rows']) {
return FALSE;
}
return TRUE;
}
/**
* Called to determine what to tell the clicksorter.
*/
function click_sort($order) {
// No column selected, can't continue.
if (empty($this->options['click_sort_column'])) {
return;
}
$this->ensure_my_table();
$column = _field_sql_storage_columnname($this->definition['field_name'], $this->options['click_sort_column']);
if (!isset($this->aliases[$column])) {
// Column is not in query; add a sort on it (without adding the column).
$this->aliases[$column] = $this->table_alias . '.' . $column;
}
$this->query->add_orderby(NULL, NULL, $order, $this->aliases[$column]);
}
function option_definition() {
$options = parent::option_definition();
// option_definition runs before init/construct, so no $this->field_info
$field = field_info_field($this->definition['field_name']);
$field_type = field_info_field_types($field['type']);
$column_names = array_keys($field['columns']);
$default_column = '';
// Try to determine a sensible default.
if (count($column_names) == 1) {
$default_column = $column_names[0];
}
elseif (in_array('value', $column_names)) {
$default_column = 'value';
}
// If the field has a "value" column, we probably need that one.
$options['click_sort_column'] = array(
'default' => $default_column,
);
$options['type'] = array(
'default' => $field_type['default_formatter'],
);
$options['settings'] = array(
'default' => array(),
);
$options['group_column'] = array(
'default' => $default_column,
);
$options['group_columns'] = array(
'default' => array(),
);
// Options used for multiple value fields.
$options['group_rows'] = array(
'default' => TRUE,
'bool' => TRUE,
);
// If we know the exact number of allowed values, then that can be
// the default. Otherwise, default to 'all'.
$options['delta_limit'] = array(
'default' => ($field['cardinality'] > 1) ? $field['cardinality'] : 'all',
);
$options['delta_offset'] = array(
'default' => 0,
);
$options['delta_reversed'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['delta_first_last'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['multi_type'] = array(
'default' => 'separator'
);
$options['separator'] = array(
'default' => ', '
);
$options['field_api_classes'] = array(
'default' => FALSE,
'bool' => TRUE,
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$field = $this->field_info;
$formatters = _field_view_formatter_options($field['type']);
$column_names = array_keys($field['columns']);
// If this is a multiple value field, add its options.
if ($this->multiple) {
$this->multiple_options_form($form, $form_state);
}
// No need to ask the user anything if the field has only one column.
if (count($field['columns']) == 1) {
$form['click_sort_column'] = array(
'#type' => 'value',
'#value' => isset($column_names[0]) ? $column_names[0] : '',
);
}
else {
$form['click_sort_column'] = array(
'#type' => 'select',
'#title' => t('Column used for click sorting'),
'#options' => drupal_map_assoc($column_names),
'#default_value' => $this->options['click_sort_column'],
'#description' => t('Used by Style: Table to determine the actual column to click sort the field on. The default is usually fine.'),
'#fieldset' => 'more',
);
}
$form['type'] = array(
'#type' => 'select',
'#title' => t('Formatter'),
'#options' => $formatters,
'#default_value' => $this->options['type'],
'#ajax' => array(
'path' => views_ui_build_form_url($form_state),
),
'#submit' => array('views_ui_config_item_form_submit_temporary'),
'#executes_submit_callback' => TRUE,
);
$form['field_api_classes'] = array(
'#title' => t('Use field template'),
'#type' => 'checkbox',
'#default_value' => $this->options['field_api_classes'],
'#description' => t('If checked, field api classes will be added using field.tpl.php (or equivalent). This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'),
'#fieldset' => 'style_settings',
'#weight' => 20,
);
if ($this->multiple) {
$form['field_api_classes']['#description'] .= ' ' . t('Checking this option will cause the group Display Type and Separator values to be ignored.');
}
// Get the currently selected formatter.
$format = $this->options['type'];
$formatter = field_info_formatter_types($format);
$settings = $this->options['settings'] + field_info_formatter_settings($format);
// Provide an instance array for hook_field_formatter_settings_form().
ctools_include('fields');
$this->instance = ctools_fields_fake_field_instance($this->definition['field_name'], '_custom', $formatter, $settings);
// Store the settings in a '_custom' view mode.
$this->instance['display']['_custom'] = array(
'type' => $format,
'settings' => $settings,
);
// Get the settings form.
$settings_form = array('#value' => array());
$function = $formatter['module'] . '_field_formatter_settings_form';
if (function_exists($function)) {
$settings_form = $function($field, $this->instance, '_custom', $form, $form_state);
}
$form['settings'] = $settings_form;
}
/**
* Provide options for multiple value fields.
*/
function multiple_options_form(&$form, &$form_state) {
$field = $this->field_info;
$form['multiple_field_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Multiple field settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 5,
);
$form['group_rows'] = array(
'#title' => t('Display all values in the same row'),
'#type' => 'checkbox',
'#default_value' => $this->options['group_rows'],
'#description' => t('If checked, multiple values for this field will be shown in the same row. If not checked, each value in this field will create a new row. If using group by, please make sure to group by "Entity ID" for this setting to have any effect.'),
'#fieldset' => 'multiple_field_settings',
);
// Make the string translatable by keeping it as a whole rather than
// translating prefix and suffix separately.
list($prefix, $suffix) = explode('@count', t('Display @count value(s)'));
if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
$type = 'textfield';
$options = NULL;
$size = 5;
}
else {
$type = 'select';
$options = drupal_map_assoc(range(1, $field['cardinality']));
$size = 1;
}
$form['multi_type'] = array(
'#type' => 'radios',
'#title' => t('Display type'),
'#options' => array(
'ul' => t('Unordered list'),
'ol' => t('Ordered list'),
'separator' => t('Simple separator'),
),
'#dependency' => array('edit-options-group-rows' => array(TRUE)),
'#default_value' => $this->options['multi_type'],
'#fieldset' => 'multiple_field_settings',
);
$form['separator'] = array(
'#type' => 'textfield',
'#title' => t('Separator'),
'#default_value' => $this->options['separator'],
'#dependency' => array(
'radio:options[multi_type]' => array('separator'),
'edit-options-group-rows' => array(TRUE),
),
'#dependency_count' => 2,
'#fieldset' => 'multiple_field_settings',
);
$form['delta_limit'] = array(
'#type' => $type,
'#size' => $size,
'#field_prefix' => $prefix,
'#field_suffix' => $suffix,
'#options' => $options,
'#default_value' => $this->options['delta_limit'],
'#prefix' => '<div class="container-inline">',
'#dependency' => array('edit-options-group-rows' => array(TRUE)),
'#fieldset' => 'multiple_field_settings',
);
list($prefix, $suffix) = explode('@count', t('starting from @count'));
$form['delta_offset'] = array(
'#type' => 'textfield',
'#size' => 5,
'#field_prefix' => $prefix,
'#field_suffix' => $suffix,
'#default_value' => $this->options['delta_offset'],
'#dependency' => array('edit-options-group-rows' => array(TRUE)),
'#description' => t('(first item is 0)'),
'#fieldset' => 'multiple_field_settings',
);
$form['delta_reversed'] = array(
'#title' => t('Reversed'),
'#type' => 'checkbox',
'#default_value' => $this->options['delta_reversed'],
'#suffix' => $suffix,
'#dependency' => array('edit-options-group-rows' => array(TRUE)),
'#description' => t('(start from last values)'),
'#fieldset' => 'multiple_field_settings',
);
$form['delta_first_last'] = array(
'#title' => t('First and last only'),
'#type' => 'checkbox',
'#default_value' => $this->options['delta_first_last'],
'#suffix' => '</div>',
'#dependency' => array('edit-options-group-rows' => array(TRUE)),
'#fieldset' => 'multiple_field_settings',
);
}
/**
* Extend the groupby form with group columns.
*/
function groupby_form(&$form, &$form_state) {
parent::groupby_form($form, $form_state);
// With "field API" fields, the column target of the grouping function
// and any additional grouping columns must be specified.
$group_columns = array(
'entity_id' => t('Entity ID'),
) + drupal_map_assoc(array_keys($this->field_info['columns']), 'ucfirst');
$form['group_column'] = array(
'#type' => 'select',
'#title' => t('Group column'),
'#default_value' => $this->options['group_column'],
'#description' => t('Select the column of this field to apply the grouping function selected above.'),
'#options' => $group_columns,
);
$options = drupal_map_assoc(array('bundle', 'language', 'entity_type'), 'ucfirst');
// Add on defined fields, noting that they're prefixed with the field name.
$form['group_columns'] = array(
'#type' => 'checkboxes',
'#title' => t('Group columns (additional)'),
'#default_value' => $this->options['group_columns'],
'#description' => t('Select any additional columns of this field to include in the query and to group on.'),
'#options' => $options + $group_columns,
);
}
function groupby_form_submit(&$form, &$form_state) {
parent::groupby_form_submit($form, $form_state);
$item =& $form_state['handler']->options;
// Add settings for "field API" fields.
$item['group_column'] = $form_state['values']['options']['group_column'];
$item['group_columns'] = array_filter($form_state['values']['options']['group_columns']);
}
/**
* Load the entities for all fields that are about to be displayed.
*/
function post_execute(&$values) {
if (!empty($values)) {
// Divide the entity ids by entity type, so they can be loaded in bulk.
$entities_by_type = array();
$revisions_by_type = array();
foreach ($values as $key => $object) {
if (isset($this->aliases['entity_type']) && isset($object->{$this->aliases['entity_type']}) && isset($object->{$this->field_alias}) && !isset($values[$key]->_field_data[$this->field_alias])) {
$entity_type = $object->{$this->aliases['entity_type']};
if (empty($this->definition['is revision'])) {
$entity_id = $object->{$this->field_alias};
$entities_by_type[$entity_type][$key] = $entity_id;
}
else {
$revision_id = $object->{$this->field_alias};
$entity_id = $object->{$this->aliases['entity_id']};
$entities_by_type[$entity_type][$key] = array($entity_id, $revision_id);
}
}
}
// Load the entities.
foreach ($entities_by_type as $entity_type => $entity_ids) {
$entity_info = entity_get_info($entity_type);
if (empty($this->definition['is revision'])) {
$entities = entity_load($entity_type, $entity_ids);
$keys = $entity_ids;
}
else {
// Revisions can't be loaded multiple, so we have to load them
// one by one.
$entities = array();
$keys = array();
foreach ($entity_ids as $key => $combined) {
list($entity_id, $revision_id) = $combined;
$entity = entity_load($entity_type, array($entity_id), array($entity_info['entity keys']['revision'] => $revision_id));
if ($entity) {
$entities[$revision_id] = array_shift($entity);
$keys[$key] = $revision_id;
}
}
}
foreach ($keys as $key => $entity_id) {
// If this is a revision, load the revision instead.
if (isset($entities[$entity_id])) {
$values[$key]->_field_data[$this->field_alias] = array(
'entity_type' => $entity_type,
'entity' => $entities[$entity_id],
);
}
}
}
// Now, transfer the data back into the resultset so it can be easily used.
foreach ($values as $row_id => &$value) {
$value->{'field_' . $this->options['id']} = $this->set_items($value, $row_id);
}
}
}
/**
* Render all items in this field together.
*
* When using advanced render, each possible item in the list is rendered
* individually. Then the items are all pasted together.
*/
function render_items($items) {
if (!empty($items)) {
if (!$this->options['group_rows']) {
return implode('', $items);
}
if ($this->options['multi_type'] == 'separator') {
return implode(filter_xss_admin($this->options['separator']), $items);
}
else {
return theme('item_list',
array(
'items' => $items,
'title' => NULL,
'type' => $this->options['multi_type']
));
}
}
}
function get_items($values) {
return $values->{'field_' . $this->options['id']};
}
function get_value($values, $field = NULL) {
// Go ahead and render and store in $this->items.
$entity = clone $values->_field_data[$this->field_alias]['entity'];
$entity_type = $values->_field_data[$this->field_alias]['entity_type'];
$langcode = $this->field_language($entity_type, $entity);
// If we are grouping, copy our group fields into the cloned entity.
// It's possible this will cause some weirdness, but there's only
// so much we can hope to do.
if (!empty($this->group_fields)) {
// first, test to see if we have a base value.
$base_value = array();
// Note: We would copy original values here, but it can cause problems.
// For example, text fields store cached filtered values as
// 'safe_value' which doesn't appear anywhere in the field definition
// so we can't affect it. Other side effects could happen similarly.
$data = FALSE;
foreach ($this->group_fields as $field_name => $column) {
if (property_exists($values, $this->aliases[$column])) {
$base_value[$field_name] = $values->{$this->aliases[$column]};
if (isset($base_value[$field_name])) {
$data = TRUE;
}
}
}
// If any of our aggregated fields have data, fake it:
if ($data) {
// Now, overwrite the original value with our aggregated value.
// This overwrites it so there is always just one entry.
$entity->{$this->definition['field_name']}[$langcode] = array($base_value);
}
else {
$entity->{$this->definition['field_name']}[$langcode] = array();
}
}
// The field we are trying to display doesn't exist on this entity.
if (!isset($entity->{$this->definition['field_name']})) {
return array();
}
// We are supposed to show only certain deltas.
if ($this->limit_values && !empty($entity->{$this->definition['field_name']})) {
$all_values = !empty($entity->{$this->definition['field_name']}[$langcode]) ? $entity->{$this->definition['field_name']}[$langcode] : array();
if ($this->options['delta_reversed']) {
$all_values = array_reverse($all_values);
}
// Offset is calculated differently when row grouping for a field is
// not enabled. Since there are multiple rows, the delta needs to be
// taken into account, so that different values are shown per row.
if (!$this->options['group_rows'] && isset($this->aliases['delta']) && isset($values->{$this->aliases['delta']})) {
$delta_limit = 1;
$offset = $values->{$this->aliases['delta']};
}
// Single fields don't have a delta available so choose 0.
elseif (!$this->options['group_rows'] && !$this->multiple) {
$delta_limit = 1;
$offset = 0;
}
else {
$delta_limit = $this->options['delta_limit'];
$offset = intval($this->options['delta_offset']);
// We should only get here in this case if there's an offset, and
// in that case we're limiting to all values after the offset.
if ($delta_limit == 'all') {
$delta_limit = count($all_values) - $offset;
}
}
// Determine if only the first and last values should be shown
$delta_first_last = $this->options['delta_first_last'];
$new_values = array();
for ($i = 0; $i < $delta_limit; $i++) {
$new_delta = $offset + $i;
if (isset($all_values[$new_delta])) {
// If first-last option was selected, only use the first and last values
if (!$delta_first_last
// Use the first value.
|| $new_delta == $offset
// Use the last value.
|| $new_delta == ($delta_limit + $offset - 1)) {
$new_values[] = $all_values[$new_delta];
}
}
}
$entity->{$this->definition['field_name']}[$langcode] = $new_values;
}
if ($field == 'entity') {
return $entity;
}
else {
return !empty($entity->{$this->definition['field_name']}[$langcode]) ? $entity->{$this->definition['field_name']}[$langcode] : array();
}
}
/**
* Return an array of items for the field.
*/
function set_items($values, $row_id) {
if (empty($values->_field_data[$this->field_alias]) || empty($values->_field_data[$this->field_alias]['entity'])) {
return array();
}
$display = array(
'type' => $this->options['type'],
'settings' => $this->options['settings'],
'label' => 'hidden',
// Pass the View object in the display so that fields can act on it.
'views_view' => $this->view,
'views_field' => $this,
'views_row_id' => $row_id,
);
$entity_type = $values->_field_data[$this->field_alias]['entity_type'];
$entity = $this->get_value($values, 'entity');
if (!$entity) {
return array();
}
$langcode = $this->field_language($entity_type, $entity);
$render_array = field_view_field($entity_type, $entity, $this->definition['field_name'], $display, $langcode);
$items = array();
if ($this->options['field_api_classes']) {
// Make a copy.
$array = $render_array;
return array(array('rendered' => drupal_render($render_array)));
}
foreach (element_children($render_array) as $count) {
$items[$count]['rendered'] = $render_array[$count];
// field_view_field() adds an #access property to the render array that
// determines whether or not the current user is allowed to view the
// field in the context of the current entity. We need to respect this
// parameter when we pull out the children of the field array for
// rendering.
if (isset($render_array['#access'])) {
$items[$count]['rendered']['#access'] = $render_array['#access'];
}
// Only add the raw field items (for use in tokens) if the current user
// has access to view the field content.
if ((!isset($items[$count]['rendered']['#access']) || $items[$count]['rendered']['#access']) && !empty($render_array['#items'][$count])) {
$items[$count]['raw'] = $render_array['#items'][$count];
}
}
return $items;
}
function render_item($count, $item) {
return render($item['rendered']);
}
function document_self_tokens(&$tokens) {
$field = $this->field_info;
foreach ($field['columns'] as $id => $column) {
$tokens['[' . $this->options['id'] . '-' . $id . ']'] = t('Raw @column', array('@column' => $id));
}
}
function add_self_tokens(&$tokens, $item) {
$field = $this->field_info;
foreach ($field['columns'] as $id => $column) {
// Use filter_xss_admin because it's user data and we can't be sure it is safe.
// We know nothing about the data, though, so we can't really do much else.
if (isset($item['raw'])) {
// If $item['raw'] is an array then we can use as is, if it's an object
// we cast it to an array, if it's neither, we can't use it.
$raw = is_array($item['raw']) ? $item['raw'] :
(is_object($item['raw']) ? (array)$item['raw'] : NULL);
}
if (isset($raw) && isset($raw[$id]) && is_scalar($raw[$id])) {
$tokens['[' . $this->options['id'] . '-' . $id . ']'] = filter_xss_admin($raw[$id]);
}
else {
// Take sure that empty values are replaced as well.
$tokens['[' . $this->options['id'] . '-' . $id . ']'] = '';
}
}
}
/**
* Return the language code of the language the field should be displayed in,
* according to the settings.
*/
function field_language($entity_type, $entity) {
global $language_content;
if (field_is_translatable($entity_type, $this->field_info)) {
$default_language = language_default('language');
$language = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
array($language_content->language, $default_language),
$this->view->display_handler->options['field_language']);
// Give the Field Language API a chance to fallback to a different language
// (or LANGUAGE_NONE), in case the field has no data for the selected language.
// field_view_field() does this as well, but since the returned language code
// is used before calling it, the fallback needs to happen explicitly.
$language = field_language($entity_type, $entity, $this->field_info['field_name'], $language);
return $language;
}
else {
return LANGUAGE_NONE;
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* @file
* Definition of views_handler_filter_field_list.
*/
/**
* Filter handler which uses list-fields as options.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_field_list extends views_handler_filter_many_to_one {
function init(&$view, &$options) {
parent::init($view, $options);
// Migrate the settings from the old filter_in_operator values to filter_many_to_one.
if ($this->options['operator'] == 'in') {
$this->options['operator'] = 'or';
}
if ($this->options['operator'] == 'not in') {
$this->options['operator'] = 'not';
}
$this->operator = $this->options['operator'];
}
function get_value_options() {
$field = field_info_field($this->definition['field_name']);
$this->value_options = list_allowed_values($field);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* @file
* Definition of views_handler_relationship_entity_reverse.
*/
/**
* A relationship handlers which reverse entity references.
*
* @ingroup views_relationship_handlers
*/
class views_handler_relationship_entity_reverse extends views_handler_relationship {
function init(&$view, &$options) {
parent::init($view, $options);
$this->field_info = field_info_field($this->definition['field_name']);
}
/**
* Called to implement a relationship in a query.
*/
function query() {
$this->ensure_my_table();
// First, relate our base table to the current base table to the
// field, using the base table's id field to the field's column.
$views_data = views_fetch_data($this->table);
$left_field = $views_data['table']['base']['field'];
$first = array(
'left_table' => $this->table_alias,
'left_field' => $left_field,
'table' => $this->definition['field table'],
'field' => $this->definition['field field'],
);
if (!empty($this->options['required'])) {
$first['type'] = 'INNER';
}
if (!empty($this->definition['join_extra'])) {
$first['extra'] = $this->definition['join_extra'];
}
if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
$first_join = new $this->definition['join_handler'];
}
else {
$first_join = new views_join();
}
$first_join->definition = $first;
$first_join->construct();
$first_join->adjusted = TRUE;
$this->first_alias = $this->query->add_table($this->definition['field table'], $this->relationship, $first_join);
// Second, relate the field table to the entity specified using
// the entity id on the field table and the entity's id field.
$second = array(
'left_table' => $this->first_alias,
'left_field' => 'entity_id',
'table' => $this->definition['base'],
'field' => $this->definition['base field'],
);
if (!empty($this->options['required'])) {
$second['type'] = 'INNER';
}
if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
$second_join = new $this->definition['join_handler'];
}
else {
$second_join = new views_join();
}
$second_join->definition = $second;
$second_join->construct();
$second_join->adjusted = TRUE;
// use a short alias for this:
$alias = $this->definition['field_name'] . '_' . $this->table;
$this->alias = $this->query->add_relationship($alias, $second_join, $this->definition['base'], $this->relationship);
}
}

73
modules/file.views.inc Normal file
View File

@@ -0,0 +1,73 @@
<?php
/**
* @file
* Provide views data and handlers for file.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_field_views_data().
*
* Views integration for file fields. Adds a file relationship to the default
* field data.
*
* @see field_views_field_default_views_data()
*/
function file_field_views_data($field) {
$data = field_views_field_default_views_data($field);
foreach ($data as $table_name => $table_data) {
// Add the relationship only on the fid field.
$data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
'handler' => 'views_handler_relationship',
'base' => 'file_managed',
'entity type' => 'file',
'base field' => 'fid',
'label' => t('file from !field_name', array('!field_name' => $field['field_name'])),
);
}
return $data;
}
/**
* Implements hook_field_views_data_views_data_alter().
*
* Views integration to provide reverse relationships on file fields.
*/
function file_field_views_data_views_data_alter(&$data, $field) {
foreach ($field['bundles'] as $entity_type => $bundles) {
$entity_info = entity_get_info($entity_type);
$pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type;
list($label, $all_labels) = field_views_field_label($field['field_name']);
$entity = $entity_info['label'];
if ($entity == t('Node')) {
$entity = t('Content');
}
$data['file_managed'][$pseudo_field_name]['relationship'] = array(
'title' => t('@entity using @field', array('@entity' => $entity, '@field' => $label)),
'help' => t('Relate each @entity with a @field set to the file.', array('@entity' => $entity, '@field' => $label)),
'handler' => 'views_handler_relationship_entity_reverse',
'field_name' => $field['field_name'],
'field table' => _field_sql_storage_tablename($field),
'field field' => $field['field_name'] . '_fid',
'base' => $entity_info['base table'],
'base field' => $entity_info['entity keys']['id'],
'label' => t('!field_name', array('!field_name' => $field['field_name'])),
'join_extra' => array(
0 => array(
'field' => 'entity_type',
'value' => $entity_type,
),
1 => array(
'field' => 'deleted',
'value' => 0,
'numeric' => TRUE,
),
),
);
}
}

33
modules/filter.views.inc Normal file
View File

@@ -0,0 +1,33 @@
<?php
/**
* @file
* Provide basic views data for filter.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function filter_views_data() {
// ----------------------------------------------------------------------
// filter_format table
// Have not defined $data['filter_formats']['table']['group'] since
// no fields are defined here yet.
$data['filter_formats']['moved to'] = 'filter_format';
$data['filter_format']['table']['join'] = array(
'node_revision' => array(
'left_field' => 'format',
'field' => 'format',
),
'node' => array(
'left_table' => 'node_revision',
'left_field' => 'format',
'field' => 'format',
),
);
return $data;
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @file
* Definition of views_handler_field_filter_format_name.
*/
/**
* Field handler to output the name of an input format.
*
* @ingroup views_field_handlers
*/
class views_handler_field_filter_format_name extends views_handler_field {
function construct() {
parent::construct();
// Be explicit about the table we are using.
$this->additional_fields['name'] = array('table' => 'filter_formats', 'field' => 'name');
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$format_name = $this->get_value($values, 'name');
if (!$format_name) {
// Default or invalid input format.
// filter_formats() will reliably return the default format even if the
// current user is unprivileged.
$format = filter_formats(filter_default_format());
return $this->sanitize_value($format->name);
}
return $this->sanitize_value($format_name);
}
}

72
modules/image.views.inc Normal file
View File

@@ -0,0 +1,72 @@
<?php
/**
* @file
* Provide views data and handlers for image.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_field_views_data().
*
* Views integration for image fields. Adds an image relationship to the default
* field data.
*
* @see field_views_field_default_views_data()
*/
function image_field_views_data($field) {
$data = field_views_field_default_views_data($field);
foreach ($data as $table_name => $table_data) {
// Add the relationship only on the fid field.
$data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
'handler' => 'views_handler_relationship',
'base' => 'file_managed',
'base field' => 'fid',
'label' => t('image from !field_name', array('!field_name' => $field['field_name'])),
);
}
return $data;
}
/**
* Implements hook_field_views_data_views_data_alter().
*
* Views integration to provide reverse relationships on image fields.
*/
function image_field_views_data_views_data_alter(&$data, $field) {
foreach ($field['bundles'] as $entity_type => $bundles) {
$entity_info = entity_get_info($entity_type);
$pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type;
list($label, $all_labels) = field_views_field_label($field['field_name']);
$entity = $entity_info['label'];
if ($entity == t('Node')) {
$entity = t('Content');
}
$data['file_managed'][$pseudo_field_name]['relationship'] = array(
'title' => t('@entity using @field', array('@entity' => $entity, '@field' => $label)),
'help' => t('Relate each @entity with a @field set to the image.', array('@entity' => $entity, '@field' => $label)),
'handler' => 'views_handler_relationship_entity_reverse',
'field_name' => $field['field_name'],
'field table' => _field_sql_storage_tablename($field),
'field field' => $field['field_name'] . '_fid',
'base' => $entity_info['base table'],
'base field' => $entity_info['entity keys']['id'],
'label' => t('!field_name', array('!field_name' => $field['field_name'])),
'join_extra' => array(
0 => array(
'field' => 'entity_type',
'value' => $entity_type,
),
1 => array(
'field' => 'deleted',
'value' => 0,
'numeric' => TRUE,
),
),
);
}
}

221
modules/locale.views.inc Normal file
View File

@@ -0,0 +1,221 @@
<?php
/**
* @file
* Provides views data and handlers for locale.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function locale_views_data() {
// Basic table information.
// Define the base group of this table.
$data['locales_source']['table']['group'] = t('Locale source');
// Advertise this table as a possible base table.
$data['locales_source']['table']['base'] = array(
'field' => 'lid',
'title' => t('Locale source'),
'help' => t('A source string for translation, in English or the default site language.'),
);
// lid
$data['locales_source']['lid'] = array(
'title' => t('LID'),
'help' => t('The ID of the source string.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
'numeric' => TRUE,
'validate type' => 'lid',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// location
$data['locales_source']['location'] = array(
'group' => t('Locale source'),
'title' => t('Location'),
'help' => t('A description of the location or context of the string.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// Group field
$data['locales_source']['textgroup'] = array(
'group' => t('Locale source'),
'title' => t('Group'),
'help' => t('The group the translation is in.'),
'field' => array(
'handler' => 'views_handler_field_locale_group',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_locale_group',
),
'argument' => array(
'handler' => 'views_handler_argument_locale_group',
),
);
// Source field
$data['locales_source']['source'] = array(
'group' => t('Locale source'),
'title' => t('Source'),
'help' => t('The full original string.'),
'field' => array(
'handler' => 'views_handler_field',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// Version field
$data['locales_source']['version'] = array(
'group' => t('Locale source'),
'title' => t('Version'),
'help' => t('The version of Drupal core that this string is for.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_locale_version',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['locales_source']['edit_lid'] = array(
'group' => t('Locale source'),
'field' => array(
'title' => t('Edit link'),
'help' => t('Provide a simple link to edit the translations.'),
'handler' => 'views_handler_field_locale_link_edit',
),
);
// ----------------------------------------------------------------------
// Locales target table
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['locales_target']['table']['group'] = t('Locale target');
// Join information
$data['locales_target']['table']['join'] = array(
'locales_source' => array(
'left_field' => 'lid',
'field' => 'lid',
),
);
// Translation field
$data['locales_target']['translation'] = array(
'group' => t('Locale target'),
'title' => t('Translation'),
'help' => t('The full translation string.'),
'field' => array(
'handler' => 'views_handler_field',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// Language field
$data['locales_target']['language'] = array(
'group' => t('Locale target'),
'title' => t('Language'),
'help' => t('The language this translation is in.'),
'field' => array(
'handler' => 'views_handler_field_locale_language',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_locale_language',
),
'argument' => array(
'handler' => 'views_handler_argument_locale_language',
),
);
$data['locales_target']['plid'] = array(
'group' => t('Locale target'),
'title' => t('Singular LID'),
'help' => t('The ID of the parent translation.'),
'field' => array(
'handler' => 'views_handler_field',
),
);
// Plural
$data['locales_target']['plural'] = array(
'group' => t('Locale target'),
'title' => t('Plural'),
'help' => t('Whether or not the translation is plural.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Plural'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
/**
* Implements hook_views_data_alter().
*/
function locale_views_data_alter(&$data) {
// Language field
$data['node']['language'] = array(
'title' => t('Language'),
'help' => t('The language the content is in.'),
'field' => array(
'handler' => 'views_handler_field_node_language',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_node_language',
),
'argument' => array(
'handler' => 'views_handler_argument_node_language',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* @file
* Definition of views_handler_argument_locale_group.
*/
/**
* Argument handler to accept a language.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_locale_group extends views_handler_argument {
function construct() {
parent::construct('group');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the group.
*/
function summary_name($data) {
return $this->locale_group($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version
* of the language.
*/
function title() {
return $this->locale_group($this->argument);
}
function locale_group($group) {
$groups = module_invoke_all('locale', 'groups');
// Sort the list.
asort($groups);
return isset($groups[$group]) ? $groups[$group] : t('Unknown group');
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* @file
* Definition of views_handler_argument_locale_language.
*/
/**
* Argument handler to accept a language.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_locale_language extends views_handler_argument {
function construct() {
parent::construct('language');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the language.
*/
function summary_name($data) {
return $this->locale_language($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version
* of the language.
*/
function title() {
return $this->locale_language($this->argument);
}
function locale_language($langcode) {
$languages = views_language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language');
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Definition of views_handler_field_locale_group.
*/
/**
* Field handler to translate a group into its readable form.
*
* @ingroup views_field_handlers
*/
class views_handler_field_locale_group extends views_handler_field {
function render($values) {
$groups = module_invoke_all('locale', 'groups');
// Sort the list.
asort($groups);
$value = $this->get_value($values);
return isset($groups[$value]) ? $groups[$value] : '';
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @file
* Definition of views_handler_field_locale_language.
*/
/**
* Field handler to translate a language into its readable form.
*
* @ingroup views_field_handlers
*/
class views_handler_field_locale_language extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['native_language'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['native_language'] = array(
'#title' => t('Native language'),
'#type' => 'checkbox',
'#default_value' => $this->options['native_language'],
'#description' => t('If enabled, the native name of the language will be displayed'),
);
}
function render($values) {
$languages = locale_language_list(empty($this->options['native_language']) ? 'name' : 'native');
$value = $this->get_value($values);
return isset($languages[$value]) ? $languages[$value] : '';
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* @file
* Definition of views_handler_field_locale_link_edit.
*/
/**
* Field handler to present a link to edit a translation.
*
* @ingroup views_field_handlers
*/
class views_handler_field_locale_link_edit extends views_handler_field {
function construct() {
parent::construct();
$this->additional_fields['lid'] = 'lid';
}
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function access() {
// Ensure user has access to edit translations.
return user_access('translate interface');
}
function render($values) {
$value = $this->get_value($values, 'lid');
return $this->render_link($this->sanitize_value($value), $values);
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'admin/build/translate/edit/' . $data;
$this->options['alter']['query'] = drupal_get_destination();
return $text;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* @file
* Definition of views_handler_field_node_language.
*/
/**
* Field handler to translate a language into its readable form.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_language extends views_handler_field_node {
function option_definition() {
$options = parent::option_definition();
$options['native_language'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['native_language'] = array(
'#title' => t('Native language'),
'#type' => 'checkbox',
'#default_value' => $this->options['native_language'],
'#description' => t('If enabled, the native name of the language will be displayed'),
);
}
function render($values) {
$languages = views_language_list(empty($this->options['native_language']) ? 'name' : 'native');
$value = $this->get_value($values);
$value = isset($languages[$value]) ? $languages[$value] : '';
return $this->render_link($value, $values);
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* @file
* Definition of views_handler_filter_locale_group.
*/
/**
* Filter by locale group.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_locale_group extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Group');
$groups = module_invoke_all('locale', 'groups');
// Sort the list.
asort($groups);
$this->value_options = $groups;
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_filter_locale_language.
*/
/**
* Filter by language.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_locale_language extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Language');
$languages = array(
'***CURRENT_LANGUAGE***' => t("Current user's language"),
'***DEFAULT_LANGUAGE***' => t("Default site language"),
LANGUAGE_NONE => t('No language')
);
$languages = array_merge($languages, views_language_list());
$this->value_options = $languages;
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @file
* Definition of views_handler_filter_locale_version.
*/
/**
* Filter by version.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_locale_version extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Version');
// Enable filtering by the current installed Drupal version.
$versions = array('***CURRENT_VERSION***' => t('Current installed version'));
$result = db_query('SELECT DISTINCT(version) FROM {locales_source} ORDER BY version');
foreach ($result as $row) {
if (!empty($row->version)) {
$versions[$row->version] = $row->version;
}
}
$this->value_options = $versions;
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_filter_node_language.
*/
/**
* Filter by language.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_language extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Language');
$languages = array(
'***CURRENT_LANGUAGE***' => t("Current user's language"),
'***DEFAULT_LANGUAGE***' => t("Default site language"),
LANGUAGE_NONE => t('No language')
);
$languages = array_merge($languages, views_language_list());
$this->value_options = $languages;
}
}
}

784
modules/node.views.inc Normal file
View File

@@ -0,0 +1,784 @@
<?php
/**
* @file
* Provide views data and handlers for node.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function node_views_data() {
// ----------------------------------------------------------------
// node table -- basic table information.
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['node']['table']['group'] = t('Content');
// Advertise this table as a possible base table
$data['node']['table']['base'] = array(
'field' => 'nid',
'title' => t('Content'),
'weight' => -10,
'access query tag' => 'node_access',
'defaults' => array(
'field' => 'title',
),
);
$data['node']['table']['entity type'] = 'node';
$data['node']['table']['default_relationship'] = array(
'node_revision' => array(
'table' => 'node_revision',
'field' => 'vid',
),
);
// ----------------------------------------------------------------
// node table -- fields
// nid
$data['node']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node ID.'), // The help that appears on the UI,
// Information for displaying the nid
'field' => array(
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
// Information for accepting a nid as an argument
'argument' => array(
'handler' => 'views_handler_argument_node_nid',
'name field' => 'title', // the field to display in the summary.
'numeric' => TRUE,
'validate type' => 'nid',
),
// Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// title
// This definition has more items in it than it needs to as an example.
$data['node']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI,
'help' => t('The content title.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'field' => 'title', // the real field. This could be left out since it is the same.
'group' => t('Content'), // The group it appears in on the UI. Could be left out.
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
'link_to_node default' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// created field
$data['node']['created'] = array(
'title' => t('Post date'), // The item it appears as on the UI,
'help' => t('The date the content was posted.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// changed field
$data['node']['changed'] = array(
'title' => t('Updated date'), // The item it appears as on the UI,
'help' => t('The date the content was last updated.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// Content type
$data['node']['type'] = array(
'title' => t('Type'), // The item it appears as on the UI,
'help' => t('The content type (for example, "blog entry", "forum post", "story", etc).'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_node_type',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_node_type',
),
'argument' => array(
'handler' => 'views_handler_argument_node_type',
),
);
// published status
$data['node']['status'] = array(
'title' => t('Published'),
'help' => t('Whether or not the content is published.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
'output formats' => array(
'published-notpublished' => array(t('Published'), t('Not published')),
),
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Published'),
'type' => 'yes-no',
'use equal' => TRUE, // Use status = 1 instead of status <> 0 in WHERE statment
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// published status + extra
$data['node']['status_extra'] = array(
'title' => t('Published or admin'),
'help' => t('Filters out unpublished content if the current user cannot view it.'),
'filter' => array(
'field' => 'status',
'handler' => 'views_handler_filter_node_status',
'label' => t('Published or admin'),
),
);
// promote status
$data['node']['promote'] = array(
'title' => t('Promoted to front page'),
'help' => t('Whether or not the content is promoted to the front page.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
'output formats' => array(
'promoted-notpromoted' => array(t('Promoted'), t('Not promoted')),
),
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Promoted to front page'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// sticky
$data['node']['sticky'] = array(
'title' => t('Sticky'), // The item it appears as on the UI,
'help' => t('Whether or not the content is sticky.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
'output formats' => array(
'sticky' => array(t('Sticky'), t('Not sticky')),
),
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Sticky'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
),
);
// Define some fields based upon views_handler_field_entity in the entity
// table so they can be re-used with other query backends.
// @see views_handler_field_entity
$data['views_entity_node']['table']['group'] = t('Content');
$data['node']['view_node']['moved to'] = array('views_entity_node', 'view_node');
$data['views_entity_node']['view_node'] = array(
'field' => array(
'title' => t('Link'),
'help' => t('Provide a simple link to the content.'),
'handler' => 'views_handler_field_node_link',
),
);
$data['node']['edit_node']['moved to'] = array('views_entity_node', 'edit_node');
$data['views_entity_node']['edit_node'] = array(
'field' => array(
'title' => t('Edit link'),
'help' => t('Provide a simple link to edit the content.'),
'handler' => 'views_handler_field_node_link_edit',
),
);
$data['node']['delete_node']['moved to'] = array('views_entity_node', 'delete_node');
$data['views_entity_node']['delete_node'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the content.'),
'handler' => 'views_handler_field_node_link_delete',
),
);
$data['node']['path'] = array(
'field' => array(
'title' => t('Path'),
'help' => t('The aliased path to this content.'),
'handler' => 'views_handler_field_node_path',
),
);
// Bogus fields for aliasing purposes.
$data['node']['created_fulldate'] = array(
'title' => t('Created date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_fulldate',
),
);
$data['node']['created_year_month'] = array(
'title' => t('Created year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_year_month',
),
);
$data['node']['created_year'] = array(
'title' => t('Created year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_year',
),
);
$data['node']['created_month'] = array(
'title' => t('Created month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_month',
),
);
$data['node']['created_day'] = array(
'title' => t('Created day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_day',
),
);
$data['node']['created_week'] = array(
'title' => t('Created week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_week',
),
);
$data['node']['changed_fulldate'] = array(
'title' => t('Updated date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_fulldate',
),
);
$data['node']['changed_year_month'] = array(
'title' => t('Updated year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_year_month',
),
);
$data['node']['changed_year'] = array(
'title' => t('Updated year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_year',
),
);
$data['node']['changed_month'] = array(
'title' => t('Updated month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_month',
),
);
$data['node']['changed_day'] = array(
'title' => t('Updated day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_day',
),
);
$data['node']['changed_week'] = array(
'title' => t('Updated week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_week',
),
);
// uid field
$data['node']['uid'] = array(
'title' => t('Author uid'),
'help' => t('The user authoring the content. If you need more fields than the uid add the content: author relationship'),
'relationship' => array(
'title' => t('Author'),
'help' => t('Relate content to the user who created it.'),
'handler' => 'views_handler_relationship',
'base' => 'users',
'field' => 'uid',
'label' => t('author'),
),
'filter' => array(
'handler' => 'views_handler_filter_user_name',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'field' => array(
'handler' => 'views_handler_field_user',
),
);
$data['node']['uid_revision'] = array(
'title' => t('User has a revision'),
'help' => t('All nodes where a certain user has a revision'),
'real field' => 'nid',
'filter' => array(
'handler' => 'views_handler_filter_node_uid_revision',
),
'argument' => array(
'handler' => 'views_handler_argument_node_uid_revision',
),
);
// ----------------------------------------------------------------------
// Content revision table
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['node_revisions']['moved to'] = 'node_revision';
$data['node_revision']['table']['entity type'] = 'node';
$data['node_revision']['table']['group'] = t('Content revision');
// Support the conversion of the field body
$data['node_revisions']['body']['moved to'] = array('field_revision_data', 'body-revision_id');
// Advertise this table as a possible base table
$data['node_revision']['table']['base'] = array(
'field' => 'vid',
'title' => t('Content revision'),
'help' => t('Content revision is a history of changes to content.'),
'defaults' => array(
'field' => 'title',
),
);
// For other base tables, explain how we join
$data['node_revision']['table']['join'] = array(
// Directly links to node table.
'node' => array(
'left_field' => 'vid',
'field' => 'vid',
),
);
$data['node_revision']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'nid',
),
);
// uid field for node revision
$data['node_revision']['uid'] = array(
'title' => t('User'),
'help' => t('Relate a content revision to the user who created the revision.'),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'users',
'base field' => 'uid',
'label' => t('revision user'),
),
);
// nid
$data['node_revision']['nid'] = array(
'title' => t('Nid'),
// The help that appears on the UI.
'help' => t('The revision NID of the content revision.'),
// Information for displaying the nid.
'field' => array(
'click sortable' => TRUE,
),
// Information for accepting a nid as an argument.
'argument' => array(
'handler' => 'views_handler_argument_node_nid',
'click sortable' => TRUE,
'numeric' => TRUE,
),
// Information for accepting a nid as a filter.
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'node',
'base field' => 'nid',
'title' => t('Content'),
'label' => t('Get the actual content from a content revision.'),
),
);
// vid
$data['node_revision']['vid'] = array(
'title' => t('Vid'),
// The help that appears on the UI.
'help' => t('The revision ID of the content revision.'),
// Information for displaying the vid.
'field' => array(
'click sortable' => TRUE,
),
// Information for accepting a vid as an argument.
'argument' => array(
'handler' => 'views_handler_argument_node_vid',
'click sortable' => TRUE,
'numeric' => TRUE,
),
// Information for accepting a vid as a filter.
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
// Information for sorting on a vid.
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'node',
'base field' => 'vid',
'title' => t('Content'),
'label' => t('Get the actual content from a content revision.'),
),
);
// title
$data['node_revision']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI,
'help' => t('The content title.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'field' => 'title', // the real field
'handler' => 'views_handler_field_node_revision',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// log field
$data['node_revision']['log'] = array(
'title' => t('Log message'), // The item it appears as on the UI,
'help' => t('The log message entered when the revision was created.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_xss',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// revision timestamp
// changed field
$data['node_revision']['timestamp'] = array(
'title' => t('Updated date'), // The item it appears as on the UI,
'help' => t('The date the node was last updated.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
$data['node_revision']['link_to_revision'] = array(
'field' => array(
'title' => t('Link'),
'help' => t('Provide a simple link to the revision.'),
'handler' => 'views_handler_field_node_revision_link',
),
);
$data['node_revision']['revert_revision'] = array(
'field' => array(
'title' => t('Revert link'),
'help' => t('Provide a simple link to revert to the revision.'),
'handler' => 'views_handler_field_node_revision_link_revert',
),
);
$data['node_revision']['delete_revision'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the content revision.'),
'handler' => 'views_handler_field_node_revision_link_delete',
),
);
// ----------------------------------------------------------------------
// Node access table
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['node_access']['table']['group'] = t('Content access');
// For other base tables, explain how we join
$data['node_access']['table']['join'] = array(
// Directly links to node table.
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
// nid field
$data['node_access']['nid'] = array(
'title' => t('Access'),
'help' => t('Filter by access.'),
'filter' => array(
'handler' => 'views_handler_filter_node_access',
'help' => t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
),
);
// ----------------------------------------------------------------------
// History table
// We're actually defining a specific instance of the table, so let's
// alias it so that we can later add the real table for other purposes if we
// need it.
$data['history_user']['moved to'] = 'history';
$data['history']['table']['group'] = t('Content');
// Explain how this table joins to others.
$data['history']['table']['join'] = array(
// Directly links to node table.
'node' => array(
'table' => 'history',
'left_field' => 'nid',
'field' => 'nid',
'extra' => array(
array('field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE),
),
),
);
$data['history']['timestamp'] = array(
'title' => t('Has new content'),
'field' => array(
'handler' => 'views_handler_field_history_user_timestamp',
'help' => t('Show a marker if the content is new or updated.'),
),
'filter' => array(
'help' => t('Show only content that is new or updated.'),
'handler' => 'views_handler_filter_history_user_timestamp',
),
);
return $data;
}
/**
* Implements hook_views_plugins().
*/
function node_views_plugins() {
return array(
'module' => 'views', // This just tells our themes are elsewhere.
'row' => array(
'node' => array(
'title' => t('Content'),
'help' => t('Display the content with standard node view.'),
'handler' => 'views_plugin_row_node_view',
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'base' => array('node'), // only works with 'node' as base.
'uses options' => TRUE,
'type' => 'normal',
'help topic' => 'style-node',
),
'node_rss' => array(
'title' => t('Content'),
'help' => t('Display the content with standard node view.'),
'handler' => 'views_plugin_row_node_rss',
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'theme' => 'views_view_row_rss',
'base' => array('node'), // only works with 'node' as base.
'uses options' => TRUE,
'type' => 'feed',
'help topic' => 'style-node-rss',
),
),
'argument validator' => array(
'node' => array(
'title' => t('Content'),
'handler' => 'views_plugin_argument_validate_node',
),
),
'argument default' => array(
'node' => array(
'title' => t('Content ID from URL'),
'handler' => 'views_plugin_argument_default_node'
),
),
);
}
/**
* Implements hook_preprocess_node().
*/
function node_row_node_view_preprocess_node(&$vars) {
$node = $vars['node'];
$options = $vars['view']->style_plugin->row_plugin->options;
// Prevent the comment form from showing up if this is not a page display.
if ($vars['view_mode'] == 'full' && !$vars['view']->display_handler->has_path()) {
$node->comment = FALSE;
}
if (!$options['links']) {
unset($vars['content']['links']);
}
if (!empty($options['comments']) && user_access('access comments') && $node->comment) {
$vars['content']['comments'] = comment_node_page_additions($node);
}
}
/**
* Implements hook_views_query_substitutions().
*/
function node_views_query_substitutions() {
return array(
'***ADMINISTER_NODES***' => intval(user_access('administer nodes')),
'***VIEW_OWN_UNPUBLISHED_NODES***' => intval(user_access('view own unpublished content')),
'***BYPASS_NODE_ACCESS***' => intval(user_access('bypass node access')),
);
}
/**
* Implements hook_views_analyze().
*/
function node_views_analyze($view) {
$ret = array();
// Check for something other than the default display:
if ($view->base_table == 'node') {
foreach ($view->display as $id => $display) {
if (empty($display->handler)) {
continue;
}
if (!$display->handler->is_defaulted('access') || !$display->handler->is_defaulted('filters')) {
// check for no access control
$access = $display->handler->get_option('access');
if (empty($access['type']) || $access['type'] == 'none') {
$select = db_select('role', 'r');
$select->innerJoin('role_permission', 'p', 'r.rid = p.rid');
$result = $select->fields('r', array('name'))
->fields('p', array('permission'))
->condition('r.name', array('anonymous user', 'authenticated user'), 'IN')
->condition('p.permission', 'access content')
->execute();
foreach ($result as $role) {
$role->safe = TRUE;
$roles[$role->name] = $role;
}
if (!($roles['anonymous user']->safe && $roles['authenticated user']->safe)) {
$ret[] = views_ui_analysis(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display->display_title)), 'warning');
}
$filters = $display->handler->get_option('filters');
foreach ($filters as $filter) {
if ($filter['table'] == 'node' && ($filter['field'] == 'status' || $filter['field'] == 'status_extra')) {
continue 2;
}
}
$ret[] = views_ui_analysis(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display->display_title)), 'warning');
}
}
}
}
foreach ($view->display as $id => $display) {
if ($display->display_plugin == 'page') {
if ($display->handler->get_option('path') == 'node/%') {
$ret[] = views_ui_analysis(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', array('%display' => $display->display_title)), 'warning');
}
}
}
return $ret;
}

View File

@@ -0,0 +1,315 @@
<?php
/**
* @file
* Bulk export of views_default objects generated by Bulk export module.
*/
/**
* Implementation of hook_views_default_views()
*/
function node_views_default_views() {
$views = array();
$view = new view;
$view->name = 'archive';
$view->description = 'Display a list of months that link to content for that month.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Archive';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Monthly archive';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Created year + month */
$handler->display->display_options['arguments']['created_year_month']['id'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['table'] = 'node';
$handler->display->display_options['arguments']['created_year_month']['field'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['default_action'] = 'summary';
$handler->display->display_options['arguments']['created_year_month']['exception']['title_enable'] = 1;
$handler->display->display_options['arguments']['created_year_month']['title_enable'] = 1;
$handler->display->display_options['arguments']['created_year_month']['title'] = '%1';
$handler->display->display_options['arguments']['created_year_month']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['created_year_month']['summary']['sort_order'] = 'desc';
$handler->display->display_options['arguments']['created_year_month']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['created_year_month']['summary_options']['override'] = TRUE;
$handler->display->display_options['arguments']['created_year_month']['summary_options']['items_per_page'] = '30';
$handler->display->display_options['arguments']['created_year_month']['specify_validation'] = 1;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'archive';
/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Content: Created year + month */
$handler->display->display_options['arguments']['created_year_month']['id'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['table'] = 'node';
$handler->display->display_options['arguments']['created_year_month']['field'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['default_action'] = 'summary';
$handler->display->display_options['arguments']['created_year_month']['exception']['title_enable'] = 1;
$handler->display->display_options['arguments']['created_year_month']['title_enable'] = 1;
$handler->display->display_options['arguments']['created_year_month']['title'] = '%1';
$handler->display->display_options['arguments']['created_year_month']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['created_year_month']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['created_year_month']['summary_options']['items_per_page'] = '30';
$handler->display->display_options['arguments']['created_year_month']['specify_validation'] = 1;
$translatables['archive'] = array(
t('Master'),
t('Monthly archive'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('All'),
t('%1'),
t('Page'),
t('Block'),
);
$views['archive'] = $view;
$view = new view;
$view->name = 'frontpage';
$view->description = 'Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Front page';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
$handler->display->display_options['row_options']['links'] = 1;
/* Sort criterion: Content: Sticky */
$handler->display->display_options['sorts']['sticky']['id'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['table'] = 'node';
$handler->display->display_options['sorts']['sticky']['field'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['order'] = 'DESC';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Promoted to front page */
$handler->display->display_options['filters']['promote']['id'] = 'promote';
$handler->display->display_options['filters']['promote']['table'] = 'node';
$handler->display->display_options['filters']['promote']['field'] = 'promote';
$handler->display->display_options['filters']['promote']['value'] = '1';
$handler->display->display_options['filters']['promote']['group'] = 0;
$handler->display->display_options['filters']['promote']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'frontpage';
/* Display: Feed */
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Front page feed';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['style_plugin'] = 'rss';
$handler->display->display_options['row_plugin'] = 'node_rss';
$handler->display->display_options['path'] = 'rss.xml';
$handler->display->display_options['displays'] = array(
'default' => 'default',
'page' => 'page',
);
$handler->display->display_options['sitename_title'] = '1';
$translatables['frontpage'] = array(
t('Master'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('Page'),
t('Feed'),
t('Front page feed'),
);
$views['frontpage'] = $view;
$view = new view;
$view->name = 'glossary';
$view->description = 'A list of all content, by letter.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Glossary';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = 36;
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'title' => 'title',
'name' => 'name',
'changed' => 'changed',
);
$handler->display->display_options['style_options']['default'] = 'title';
$handler->display->display_options['style_options']['info'] = array(
'title' => array(
'sortable' => 1,
'separator' => '',
),
'name' => array(
'sortable' => 1,
'separator' => '',
),
'changed' => array(
'sortable' => 1,
'separator' => '',
),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = 'Author';
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
/* Field: Content: Updated date */
$handler->display->display_options['fields']['changed']['id'] = 'changed';
$handler->display->display_options['fields']['changed']['table'] = 'node';
$handler->display->display_options['fields']['changed']['field'] = 'changed';
$handler->display->display_options['fields']['changed']['label'] = 'Last update';
$handler->display->display_options['fields']['changed']['date_format'] = 'large';
/* Contextual filter: Content: Title */
$handler->display->display_options['arguments']['title']['id'] = 'title';
$handler->display->display_options['arguments']['title']['table'] = 'node';
$handler->display->display_options['arguments']['title']['field'] = 'title';
$handler->display->display_options['arguments']['title']['default_action'] = 'default';
$handler->display->display_options['arguments']['title']['exception']['title_enable'] = 1;
$handler->display->display_options['arguments']['title']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['title']['default_argument_options']['argument'] = 'a';
$handler->display->display_options['arguments']['title']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['title']['specify_validation'] = 1;
$handler->display->display_options['arguments']['title']['glossary'] = 1;
$handler->display->display_options['arguments']['title']['limit'] = '1';
$handler->display->display_options['arguments']['title']['case'] = 'upper';
$handler->display->display_options['arguments']['title']['path_case'] = 'lower';
$handler->display->display_options['arguments']['title']['transform_dash'] = 0;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'glossary';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'Glossary';
$handler->display->display_options['menu']['weight'] = '0';
/* Display: Attachment */
$handler = $view->new_display('attachment', 'Attachment', 'attachment');
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Content: Title */
$handler->display->display_options['arguments']['title']['id'] = 'title';
$handler->display->display_options['arguments']['title']['table'] = 'node';
$handler->display->display_options['arguments']['title']['field'] = 'title';
$handler->display->display_options['arguments']['title']['default_action'] = 'summary';
$handler->display->display_options['arguments']['title']['exception']['title_enable'] = 1;
$handler->display->display_options['arguments']['title']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['title']['default_argument_options']['argument'] = 'a';
$handler->display->display_options['arguments']['title']['summary']['format'] = 'unformatted_summary';
$handler->display->display_options['arguments']['title']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['title']['summary_options']['inline'] = 1;
$handler->display->display_options['arguments']['title']['summary_options']['separator'] = ' | ';
$handler->display->display_options['arguments']['title']['specify_validation'] = 1;
$handler->display->display_options['arguments']['title']['glossary'] = 1;
$handler->display->display_options['arguments']['title']['limit'] = '1';
$handler->display->display_options['arguments']['title']['case'] = 'upper';
$handler->display->display_options['arguments']['title']['path_case'] = 'lower';
$handler->display->display_options['arguments']['title']['transform_dash'] = 0;
$handler->display->display_options['displays'] = array(
'default' => 'default',
'page' => 'page',
);
$handler->display->display_options['inherit_arguments'] = 0;
$translatables['glossary'] = array(
t('Master'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('Title'),
t('Author'),
t('Last update'),
t('All'),
t('Page'),
t('Attachment'),
);
$views['glossary'] = $view;
return $views;
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* @file
* Contains views templates on behalf of the node module.
*/
function node_views_templates() {
// Only the standard install profile has the image field provided so only show it for it.
if (variable_get('install_profile', 'standard') != 'standard') {
return array();
}
$view = new view;
$view->name = 'image_gallery';
$view->description = 'Shows all images which was uploaded on the "field_image" field';
$view->tag = '';
$view->base_table = 'node';
$view->human_name = 'Image Gallery';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['title'] = 'Image gallery';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '24';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all'] = 0;
$handler->display->display_options['style_plugin'] = 'grid';
$handler->display->display_options['style_options']['fill_single_line'] = 1;
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Image */
$handler->display->display_options['fields']['field_image']['id'] = 'field_image';
$handler->display->display_options['fields']['field_image']['table'] = 'field_data_field_image';
$handler->display->display_options['fields']['field_image']['field'] = 'field_image';
$handler->display->display_options['fields']['field_image']['label'] = '';
$handler->display->display_options['fields']['field_image']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_image']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_image']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_image']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_image']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_image']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_image']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_image']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_image']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_image']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_image']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_image']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_image']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_image']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_image']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_image']['settings'] = array(
'image_style' => 'thumbnail',
'image_link' => 'content',
);
$handler->display->display_options['fields']['field_image']['field_api_classes'] = 0;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = 'Author';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = 1;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
/* Contextual filter: Content: Has taxonomy term ID */
$handler->display->display_options['arguments']['tid']['id'] = 'tid';
$handler->display->display_options['arguments']['tid']['table'] = 'taxonomy_index';
$handler->display->display_options['arguments']['tid']['field'] = 'tid';
$handler->display->display_options['arguments']['tid']['default_action'] = 'summary';
$handler->display->display_options['arguments']['tid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['tid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['tid']['summary']['number_of_records'] = '1';
$handler->display->display_options['arguments']['tid']['summary']['format'] = 'unformatted_summary';
$handler->display->display_options['arguments']['tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['tid']['summary_options']['inline'] = 0;
$handler->display->display_options['arguments']['tid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['tid']['add_table'] = 0;
$handler->display->display_options['arguments']['tid']['require_value'] = 0;
$handler->display->display_options['arguments']['tid']['reduce_duplicates'] = 0;
$handler->display->display_options['arguments']['tid']['set_breadcrumb'] = 0;
/* Filter criterion: Content: Image (field_image) - fid */
$handler->display->display_options['filters']['field_image_fid']['id'] = 'field_image_fid';
$handler->display->display_options['filters']['field_image_fid']['table'] = 'field_data_field_image';
$handler->display->display_options['filters']['field_image_fid']['field'] = 'field_image_fid';
$handler->display->display_options['filters']['field_image_fid']['operator'] = 'not empty';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
/* Display: Gallery page */
$handler = $view->new_display('page', 'Gallery page', 'page_1');
$handler->display->display_options['path'] = 'gallery';
$translatables['image_gallery'] = array(
t('Defaults'),
t('Image gallery'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('Author'),
t('All'),
t('Gallery page'),
);
$views[$view->name] = $view;
return $views;
}

View File

@@ -0,0 +1,177 @@
<?php
/**
* @file
* Handlers for various date arguments.
*
* @ingroup views_argument_handlers
*/
/**
* Argument handler for a full date (CCYYMMDD)
*/
class views_handler_argument_node_created_fulldate extends views_handler_argument_date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->format = 'F j, Y';
$this->arg_format = 'Ymd';
$this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field");
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return format_date(strtotime($created . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
}
/**
* Argument handler for a year (CCYY)
*/
class views_handler_argument_node_created_year extends views_handler_argument_date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->arg_format = 'Y';
$this->formula = views_date_sql_extract('YEAR', "***table***.$this->real_field");
}
}
/**
* Argument handler for a year plus month (CCYYMM)
*/
class views_handler_argument_node_created_year_month extends views_handler_argument_date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->format = 'F Y';
$this->arg_format = 'Ym';
$this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field");
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
}
/**
* Argument handler for a month (MM)
*/
class views_handler_argument_node_created_month extends views_handler_argument_date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->formula = views_date_sql_extract('MONTH', "***table***.$this->real_field");
$this->format = 'F';
$this->arg_format = 'm';
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
$month = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
function summary_argument($data) {
// Make sure the argument contains leading zeroes.
return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
}
}
/**
* Argument handler for a day (DD)
*/
class views_handler_argument_node_created_day extends views_handler_argument_date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->formula = views_date_sql_extract('DAY', "***table***.$this->real_field");
$this->format = 'j';
$this->arg_format = 'd';
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
// strtotime respects server timezone, so we need to set the time fixed as utc time
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
$day = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
function summary_argument($data) {
// Make sure the argument contains leading zeroes.
return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
}
}
/**
* Argument handler for a week.
*/
class views_handler_argument_node_created_week extends views_handler_argument_date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->arg_format = 'w';
$this->formula = views_date_sql_extract('WEEK', "***table***.$this->real_field");
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return t('Week @week', array('@week' => $created));
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @file
* Definition of views_handler_argument_node_language.
*/
/**
* Argument handler to accept a language.
*/
class views_handler_argument_node_language extends views_handler_argument {
function construct() {
parent::construct('language');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the language.
*/
function summary_name($data) {
return $this->node_language($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version of the
* node type.
*/
function title() {
return $this->node_language($this->argument);
}
function node_language($langcode) {
$languages = views_language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language');
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file
* Provide node nid argument handler.
*/
/**
* Argument handler to accept a node id.
*/
class views_handler_argument_node_nid extends views_handler_argument_numeric {
/**
* Override the behavior of title(). Get the title of the node.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT n.title FROM {node} n WHERE n.nid IN (:nids)", array(':nids' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* @file
* Definition of views_handler_argument_node_type.
*/
/**
* Argument handler to accept a node type.
*/
class views_handler_argument_node_type extends views_handler_argument_string {
function construct() {
parent::construct('type');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the node type.
*/
function summary_name($data) {
return $this->node_type($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version of the
* node type.
*/
function title() {
return $this->node_type($this->argument);
}
function node_type($type) {
$output = node_type_get_name($type);
if (empty($output)) {
$output = t('Unknown content type');
}
return check_plain($output);
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Defintion of views_handler_argument_node_uid_revision.
*/
/**
* Filter handler to accept a user id to check for nodes that
* user posted or created a revision on.
*/
class views_handler_argument_node_uid_revision extends views_handler_argument_comment_user_uid {
function query($group_by = FALSE) {
$this->ensure_my_table();
$placeholder = $this->placeholder();
$this->query->add_where_expression(0, "$this->table_alias.uid = $placeholder OR ((SELECT COUNT(*) FROM {node_revision} nr WHERE nr.uid = $placeholder AND nr.nid = $this->table_alias.nid) > 0)", array($placeholder => $this->argument));
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Provide node vid argument handler.
*/
/**
* Argument handler to accept a node revision id.
*/
class views_handler_argument_node_vid extends views_handler_argument_numeric {
// No constructor is necessary.
/**
* Override the behavior of title(). Get the title of the revision.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT n.title FROM {node_revision} n WHERE n.vid IN (:vids)", array(':vids' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* @file
* Definition of views_handler_field_history_user_timestamp.
*/
/**
* Field handler to display the marker for new content.
*
* The handler is named history_user, because of compability reasons, the table
* is history.
*
* @ingroup views_field_handlers
*/
class views_handler_field_history_user_timestamp extends views_handler_field_node {
function init(&$view, &$options) {
parent::init($view, $options);
global $user;
if ($user->uid) {
$this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
$this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
if (module_exists('comment') && !empty($this->options['comments'])) {
$this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
}
}
}
function option_definition() {
$options = parent::option_definition();
$options['comments'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
if (module_exists('comment')) {
$form['comments'] = array(
'#type' => 'checkbox',
'#title' => t('Check for new comments as well'),
'#default_value' => !empty($this->options['comments']),
'#fieldset' => 'more',
);
}
}
function query() {
// Only add ourselves to the query if logged in.
global $user;
if (!$user->uid) {
return;
}
parent::query();
}
function render($values) {
// Let's default to 'read' state.
// This code shadows node_mark, but it reads from the db directly and
// we already have that info.
$mark = MARK_READ;
global $user;
if ($user->uid) {
$last_read = $this->get_value($values);
$changed = $this->get_value($values, 'changed');
$last_comment = module_exists('comment') && !empty($this->options['comments']) ? $this->get_value($values, 'last_comment') : 0;
if (!$last_read && $changed > NODE_NEW_LIMIT) {
$mark = MARK_NEW;
}
elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) {
$mark = MARK_UPDATED;
}
elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) {
$mark = MARK_UPDATED;
}
return $this->render_link(theme('mark', array('type' => $mark)), $values);
}
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* @file
* Contains the basic 'node' field handler.
*/
/**
* Field handler to provide simple renderer that allows linking to a node.
* Definition terms:
* - link_to_node default: Should this field have the checkbox "link to node" enabled by default.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node extends views_handler_field {
function init(&$view, &$options) {
parent::init($view, $options);
// Don't add the additional fields to groupby
if (!empty($this->options['link_to_node'])) {
$this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid');
if (module_exists('translation')) {
$this->additional_fields['language'] = array('table' => 'node', 'field' => 'language');
}
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_node'] = array('default' => isset($this->definition['link_to_node default']) ? $this->definition['link_to_node default'] : FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link to node option
*/
function options_form(&$form, &$form_state) {
$form['link_to_node'] = array(
'#title' => t('Link this field to the original piece of content'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_node']),
);
parent::options_form($form, $form_state);
}
/**
* Render whatever the data is as a link to the node.
*
* Data should be made XSS safe prior to calling this function.
*/
function render_link($data, $values) {
if (!empty($this->options['link_to_node']) && !empty($this->additional_fields['nid'])) {
if ($data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/" . $this->get_value($values, 'nid');
if (isset($this->aliases['language'])) {
$languages = language_list();
$language = $this->get_value($values, 'language');
if (isset($languages[$language])) {
$this->options['alter']['language'] = $languages[$language];
}
else {
unset($this->options['alter']['language']);
}
}
}
else {
$this->options['alter']['make_link'] = FALSE;
}
}
return $data;
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* @file
* Definition of views_handler_field_node_link.
*/
/**
* Field handler to present a link to the node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_link extends views_handler_field_entity {
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
parent::options_form($form, $form_state);
// The path is set by render_link function so don't allow to set it.
$form['alter']['path'] = array('#access' => FALSE);
$form['alter']['external'] = array('#access' => FALSE);
}
function render($values) {
if ($entity = $this->get_value($values)) {
return $this->render_link($entity, $values);
}
}
function render_link($node, $values) {
if (node_access('view', $node)) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/$node->nid";
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
return $text;
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* @file
* Definition of views_handler_field_node_link_delete.
*/
/**
* Field handler to present a link to delete a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_link_delete extends views_handler_field_node_link {
/**
* Renders the link.
*/
function render_link($node, $values) {
// Ensure user has access to delete this node.
if (!node_access('delete', $node)) {
return;
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/$node->nid/delete";
$this->options['alter']['query'] = drupal_get_destination();
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
return $text;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* @file
* Definition of views_handler_field_node_link_edit.
*/
/**
* Field handler to present a link node edit.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_link_edit extends views_handler_field_node_link {
/**
* Renders the link.
*/
function render_link($node, $values) {
// Ensure user has access to edit this node.
if (!node_access('update', $node)) {
return;
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/$node->nid/edit";
$this->options['alter']['query'] = drupal_get_destination();
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
return $text;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* @file
* Handler for node path field.
*/
/**
* Field handler to present the path to the node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_path extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['absolute'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function construct() {
parent::construct();
$this->additional_fields['nid'] = 'nid';
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['absolute'] = array(
'#type' => 'checkbox',
'#title' => t('Use absolute link (begins with "http://")'),
'#default_value' => $this->options['absolute'],
'#description' => t('Enable this option to output an absolute link. Required if you want to use the path as a link destination (as in "output this field as a link" above).'),
'#fieldset' => 'alter',
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$nid = $this->get_value($values, 'nid');
return url("node/$nid", array('absolute' => $this->options['absolute']));
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* @file
* Definition of views_handler_field_node_revision.
*/
/**
* Contains the basic 'node_revision' field handler.
*/
/**
* A basic node_revision handler.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_revision extends views_handler_field_node {
function init(&$view, &$options) {
parent::init($view, $options);
if (!empty($this->options['link_to_node_revision'])) {
$this->additional_fields['vid'] = 'vid';
$this->additional_fields['nid'] = 'nid';
if (module_exists('translation')) {
$this->additional_fields['language'] = array('table' => 'node', 'field' => 'language');
}
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_node_revision'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link to revision option.
*/
function options_form(&$form, &$form_state) {
$form['link_to_node_revision'] = array(
'#title' => t('Link this field to its content revision'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_node_revision']),
);
parent::options_form($form, $form_state);
}
/**
* Render whatever the data is as a link to the node.
*
* Data should be made XSS safe prior to calling this function.
*/
function render_link($data, $values) {
if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
$nid = $this->get_value($values, 'nid');
$vid = $this->get_value($values, 'vid');
$this->options['alter']['path'] = 'node/' . $nid;
if ($nid != $vid) {
$this->options['alter']['path'] .= "/revisions/$vid/view";
}
if (module_exists('translation')) {
$language = $this->get_value($values, 'language');
$languages = language_list();
if (isset($languages[$language])) {
$this->options['alter']['language'] = $languages[$language];
}
}
}
else {
return parent::render_link($data, $values);
}
return $data;
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* @file
* Definition of views_handler_field_node_revision_link.
*/
/**
* Field handler to present a link to a node revision.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_revision_link extends views_handler_field_node_link {
function construct() {
parent::construct();
$this->additional_fields['node_vid'] = array('table' => 'node_revision', 'field' => 'vid');
}
function access() {
return user_access('view revisions') || user_access('administer nodes');
}
function render_link($data, $values) {
list($node, $vid) = $this->get_revision_entity($values, 'view');
if (!isset($vid)) {
return;
}
// Current revision uses the node view path.
$path = 'node/' . $node->nid;
if ($node->vid != $vid) {
$path .= "/revisions/$vid/view";
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $path;
$this->options['alter']['query'] = drupal_get_destination();
return !empty($this->options['text']) ? $this->options['text'] : t('view');
}
/**
* Returns the revision values of a node.
*
* @param object $values
* An object containing all retrieved values.
* @param string $op
* The operation being performed.
*
* @return array
* A numerically indexed array containing the current node object and the
* revision ID for this row.
*/
function get_revision_entity($values, $op) {
$vid = $this->get_value($values, 'node_vid');
$node = $this->get_value($values);
// Unpublished nodes ignore access control.
$node->status = 1;
// Ensure user has access to perform the operation on this node.
if (!node_access($op, $node)) {
return array($node, NULL);
}
return array($node, $vid);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @file
* Definition of views_handler_field_node_revision_link_delete.
*/
/**
* Field handler to present link to delete a node revision.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_revision_link_delete extends views_handler_field_node_revision_link {
function access() {
return user_access('delete revisions') || user_access('administer nodes');
}
function render_link($data, $values) {
list($node, $vid) = $this->get_revision_entity($values, 'delete');
if (!isset($vid)) {
return;
}
// Current revision cannot be deleted.
if ($node->vid == $vid) {
return;
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->nid . "/revisions/$vid/delete";
$this->options['alter']['query'] = drupal_get_destination();
return !empty($this->options['text']) ? $this->options['text'] : t('delete');
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @file
* Definition of views_handler_field_node_revision_link_revert.
*/
/**
* Field handler to present a link to revert a node to a revision.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_revision_link_revert extends views_handler_field_node_revision_link {
function access() {
return user_access('revert revisions') || user_access('administer nodes');
}
function render_link($data, $values) {
list($node, $vid) = $this->get_revision_entity($values, 'update');
if (!isset($vid)) {
return;
}
// Current revision cannot be reverted.
if ($node->vid == $vid) {
return;
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->nid . "/revisions/$vid/revert";
$this->options['alter']['query'] = drupal_get_destination();
return !empty($this->options['text']) ? $this->options['text'] : t('revert');
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* @file
* Definition of views_handler_field_node_type.
*/
/**
* Field handler to translate a node type into its readable form.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_type extends views_handler_field_node {
function option_definition() {
$options = parent::option_definition();
$options['machine_name'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide machine_name option for to node type display.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['machine_name'] = array(
'#title' => t('Output machine name'),
'#description' => t('Display field as the content type machine name.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['machine_name']),
);
}
/**
* Render node type as human readable name, unless using machine_name option.
*/
function render_name($data, $values) {
if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') {
return t($this->sanitize_value(node_type_get_name($data)));
}
return $this->sanitize_value($data);
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->render_name($value, $values), $values);
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* @file
* Definition of views_handler_filter_history_user_timestamp.
*/
/**
* Filter for new content.
*
* The handler is named history_user, because of compability reasons, the table
* is history.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_history_user_timestamp extends views_handler_filter {
// Don't display empty space where the operator would be.
var $no_operator = TRUE;
function expose_form(&$form, &$form_state) {
parent::expose_form($form, $form_state);
// @todo There are better ways of excluding required and multiple (object flags)
unset($form['expose']['required']);
unset($form['expose']['multiple']);
unset($form['expose']['remember']);
}
function value_form(&$form, &$form_state) {
// Only present a checkbox for the exposed filter itself. There's no way
// to tell the difference between not checked and the default value, so
// specifying the default value via the views UI is meaningless.
if (!empty($form_state['exposed'])) {
if (isset($this->options['expose']['label'])) {
$label = $this->options['expose']['label'];
}
else {
$label = t('Has new content');
}
$form['value'] = array(
'#type' => 'checkbox',
'#title' => $label,
'#default_value' => $this->value,
);
}
}
function query() {
global $user;
// This can only work if we're logged in.
if (!$user || !$user->uid) {
return;
}
// Don't filter if we're exposed and the checkbox isn't selected.
if ((!empty($this->options['exposed'])) && empty($this->value)) {
return;
}
// Hey, Drupal kills old history, so nodes that haven't been updated
// since NODE_NEW_LIMIT are bzzzzzzzt outta here!
$limit = REQUEST_TIME - NODE_NEW_LIMIT;
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
$node = $this->query->ensure_table('node', $this->relationship);
$clause = '';
$clause2 = '';
if (module_exists('comment')) {
$ncs = $this->query->ensure_table('node_comment_statistics', $this->relationship);
$clause = ("OR $ncs.last_comment_timestamp > (***CURRENT_TIME*** - $limit)");
$clause2 = "OR $field < $ncs.last_comment_timestamp";
}
// NULL means a history record doesn't exist. That's clearly new content.
// Unless it's very very old content. Everything in the query is already
// type safe cause none of it is coming from outside here.
$this->query->add_where_expression($this->options['group'], "($field IS NULL AND ($node.changed > (***CURRENT_TIME*** - $limit) $clause)) OR $field < $node.changed $clause2");
}
function admin_summary() {
if (!empty($this->options['exposed'])) {
return t('exposed');
}
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* @file
* Definition of views_handler_filter_node_access.
*/
/**
* Filter by node_access records.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_access extends views_handler_filter {
function admin_summary() { }
function operator_form(&$form, &$form_state) { }
function can_expose() {
return FALSE;
}
/**
* See _node_access_where_sql() for a non-views query based implementation.
*/
function query() {
if (!user_access('administer nodes') && module_implements('node_grants')) {
$table = $this->ensure_my_table();
$grants = db_or();
foreach (node_access_grants('view') as $realm => $gids) {
foreach ($gids as $gid) {
$grants->condition(db_and()
->condition($table . '.gid', $gid)
->condition($table . '.realm', $realm)
);
}
}
$this->query->add_where('AND', $grants);
$this->query->add_where('AND', $table . '.grant_view', 1, '>=');
}
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* @file
* Definition of views_handler_filter_node_status.
*/
/**
* Filter by published status.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_status extends views_handler_filter {
function admin_summary() { }
function operator_form(&$form, &$form_state) { }
function can_expose() { return FALSE; }
function query() {
$table = $this->ensure_my_table();
$this->query->add_where_expression($this->options['group'], "$table.status = 1 OR ($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***BYPASS_NODE_ACCESS*** = 1");
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Definition of views_handler_filter_node_type.
*/
/**
* Filter by node type.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_type extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Content types');
$types = node_type_get_types();
$options = array();
foreach ($types as $type => $info) {
$options[$type] = t($info->name);
}
asort($options);
$this->value_options = $options;
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* @file
* Definition of views_handler_filter_node_uid_revision.
*/
/**
* Filter handler to check for revisions a certain user has created.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_uid_revision extends views_handler_filter_user_name {
function query($group_by = FALSE) {
$this->ensure_my_table();
$placeholder = $this->placeholder();
$args = array_values($this->value);
$this->query->add_where_expression($this->options['group'], "$this->table_alias.uid IN($placeholder) " . $condition . " OR
((SELECT COUNT(*) FROM {node_revision} nr WHERE nr.uid IN($placeholder) AND nr.nid = $this->table_alias.nid) > 0)", array($placeholder => $args),
$args);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @file
* Contains the node from URL argument default plugin.
*/
/**
* Default argument plugin to extract a node via menu_get_object
*
* This plugin actually has no options so it odes not need to do a great deal.
*/
class views_plugin_argument_default_node extends views_plugin_argument_default {
function get_argument() {
foreach (range(1, 3) as $i) {
$node = menu_get_object('node', $i);
if (!empty($node)) {
return $node->nid;
}
}
if (arg(0) == 'node' && is_numeric(arg(1))) {
return arg(1);
}
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* @file
* Contains the 'node' argument validator plugin.
*/
/**
* Validate whether an argument is an acceptable node.
*/
class views_plugin_argument_validate_node extends views_plugin_argument_validate {
function option_definition() {
$options = parent::option_definition();
$options['types'] = array('default' => array());
$options['access'] = array('default' => FALSE, 'bool' => TRUE);
$options['access_op'] = array('default' => 'view');
$options['nid_type'] = array('default' => 'nid');
return $options;
}
function options_form(&$form, &$form_state) {
$types = node_type_get_types();
$options = array();
foreach ($types as $type => $info) {
$options[$type] = check_plain(t($info->name));
}
$form['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content types'),
'#options' => $options,
'#default_value' => $this->options['types'],
'#description' => t('Choose one or more content types to validate with.'),
);
$form['access'] = array(
'#type' => 'checkbox',
'#title' => t('Validate user has access to the content'),
'#default_value' => $this->options['access'],
);
$form['access_op'] = array(
'#type' => 'radios',
'#title' => t('Access operation to check'),
'#options' => array('view' => t('View'), 'update' => t('Edit'), 'delete' => t('Delete')),
'#default_value' => $this->options['access_op'],
'#dependency' => array('edit-options-validate-options-node-access' => array(TRUE)),
);
$form['nid_type'] = array(
'#type' => 'select',
'#title' => t('Filter value format'),
'#options' => array(
'nid' => t('Node ID'),
'nids' => t('Node IDs separated by , or +'),
),
'#default_value' => $this->options['nid_type'],
);
}
function options_submit(&$form, &$form_state, &$options = array()) {
// filter trash out of the options so we don't store giant unnecessary arrays
$options['types'] = array_filter($options['types']);
}
function convert_options(&$options) {
if (!isset($options['types']) && !empty($this->argument->options['validate_argument_node_type'])) {
$options['types'] = isset($this->argument->options['validate_argument_node_type']) ? $this->argument->options['validate_argument_node_type'] : array();
$options['access'] = !empty($this->argument->options['validate_argument_node_access']);
$options['access_op'] = isset($this->argument->options['validate_argument_node_access_op']) ? $this->argument->options['validate_argument_node_access_op'] : 'view';
$options['nid_type'] = isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : array();
}
}
function validate_argument($argument) {
$types = $this->options['types'];
switch ($this->options['nid_type']) {
case 'nid':
if (!is_numeric($argument)) {
return FALSE;
}
$node = node_load($argument);
if (!$node) {
return FALSE;
}
if (!empty($this->options['access'])) {
if (!node_access($this->options['access_op'], $node)) {
return FALSE;
}
}
// Save the title() handlers some work.
$this->argument->validated_title = check_plain($node->title);
if (empty($types)) {
return TRUE;
}
return isset($types[$node->type]);
break;
case 'nids':
$nids = new stdClass();
$nids->value = array($argument);
$nids = views_break_phrase($argument, $nids);
if ($nids->value == array(-1)) {
return FALSE;
}
$test = drupal_map_assoc($nids->value);
$titles = array();
$result = db_query("SELECT * FROM {node} WHERE nid IN (:nids)", array(':nids' => $nids->value));
foreach ($result as $node) {
if ($types && empty($types[$node->type])) {
return FALSE;
}
if (!empty($this->options['access'])) {
if (!node_access($this->options['access_op'], $node)) {
return FALSE;
}
}
$titles[] = check_plain($node->title);
unset($test[$node->nid]);
}
$this->argument->validated_title = implode($nids->operator == 'or' ? ' + ' : ', ', $titles);
// If this is not empty, we did not find a nid.
return empty($test);
}
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* @file
* Contains the node RSS row style plugin.
*/
/**
* Plugin which performs a node_view on the resulting object
* and formats it as an RSS item.
*/
class views_plugin_row_node_rss extends views_plugin_row {
// Basic properties that let the row style follow relationships.
var $base_table = 'node';
var $base_field = 'nid';
// Stores the nodes loaded with pre_render.
var $nodes = array();
function option_definition() {
$options = parent::option_definition();
$options['item_length'] = array('default' => 'default');
$options['links'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Override init function to convert fulltext view-mode to full.
*/
function init(&$view, &$display, $options = NULL) {
parent::init($view, $display, $options);
if ($this->options['item_length'] == 'fulltext') {
$this->options['item_length'] = 'full';
}
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['item_length'] = array(
'#type' => 'select',
'#title' => t('Display type'),
'#options' => $this->options_form_summary_options(),
'#default_value' => $this->options['item_length'],
);
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
}
/**
* Return the main options, which are shown in the summary title.
*/
function options_form_summary_options() {
$entity_info = entity_get_info('node');
$options = array();
if (!empty($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) {
$options[$mode] = $settings['label'];
}
}
$options['title'] = t('Title only');
$options['default'] = t('Use site default RSS settings');
return $options;
}
function summary_title() {
$options = $this->options_form_summary_options();
return check_plain($options[$this->options['item_length']]);
}
function pre_render($values) {
$nids = array();
foreach ($values as $row) {
$nids[] = $row->{$this->field_alias};
}
if (!empty($nids)) {
$this->nodes = node_load_multiple($nids);
}
}
function render($row) {
// For the most part, this code is taken from node_feed() in node.module
global $base_url;
$nid = $row->{$this->field_alias};
if (!is_numeric($nid)) {
return;
}
$display_mode = $this->options['item_length'];
if ($display_mode == 'default') {
$display_mode = variable_get('feed_item_length', 'teaser');
}
// Load the specified node:
$node = $this->nodes[$nid];
if (empty($node)) {
return;
}
$item_text = '';
$uri = entity_uri('node', $node);
$node->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
$node->rss_namespaces = array();
$node->rss_elements = array(
array(
'key' => 'pubDate',
'value' => gmdate('r', $node->created),
),
array(
'key' => 'dc:creator',
'value' => $node->name,
),
array(
'key' => 'guid',
'value' => $node->nid . ' at ' . $base_url,
'attributes' => array('isPermaLink' => 'false'),
),
);
// The node gets built and modules add to or modify $node->rss_elements
// and $node->rss_namespaces.
$build_mode = $display_mode;
$build = node_view($node, $build_mode);
unset($build['#theme']);
if (!empty($node->rss_namespaces)) {
$this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $node->rss_namespaces);
}
elseif (function_exists('rdf_get_namespaces')) {
// Merge RDF namespaces in the XML namespaces in case they are used
// further in the RSS content.
$xml_rdf_namespaces = array();
foreach (rdf_get_namespaces() as $prefix => $uri) {
$xml_rdf_namespaces['xmlns:' . $prefix] = $uri;
}
$this->view->style_plugin->namespaces += $xml_rdf_namespaces;
}
// Hide the links if desired.
if (!$this->options['links']) {
hide($build['links']);
}
if ($display_mode != 'title') {
// We render node contents and force links to be last.
$build['links']['#weight'] = 1000;
$item_text .= drupal_render($build);
}
$item = new stdClass();
$item->description = $item_text;
$item->title = $node->title;
$item->link = $node->link;
$item->elements = $node->rss_elements;
$item->nid = $node->nid;
return theme($this->theme_functions(), array(
'view' => $this->view,
'options' => $this->options,
'row' => $item
));
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* @file
* Contains the node view row style plugin.
*/
/**
* Plugin which performs a node_view on the resulting object.
*
* Most of the code on this object is in the theme function.
*
* @ingroup views_row_plugins
*/
class views_plugin_row_node_view extends views_plugin_row {
// Basic properties that let the row style follow relationships.
var $base_table = 'node';
var $base_field = 'nid';
// Stores the nodes loaded with pre_render.
var $nodes = array();
function init(&$view, &$display, $options = NULL) {
parent::init($view, $display, $options);
// Handle existing views with the deprecated 'teaser' option.
if (isset($this->options['teaser'])) {
$this->options['build_mode'] = $this->options['teaser'] ? 'teaser' : 'full';
}
// Handle existing views which has used build_mode instead of view_mode.
if (isset($this->options['build_mode'])) {
$this->options['view_mode'] = $this->options['build_mode'];
}
}
function option_definition() {
$options = parent::option_definition();
$options['view_mode'] = array('default' => 'teaser');
$options['links'] = array('default' => TRUE, 'bool' => TRUE);
$options['comments'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$options = $this->options_form_summary_options();
$form['view_mode'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('View mode'),
'#default_value' => $this->options['view_mode'],
);
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
$form['comments'] = array(
'#type' => 'checkbox',
'#title' => t('Display comments'),
'#default_value' => $this->options['comments'],
);
}
/**
* Return the main options, which are shown in the summary title.
*/
function options_form_summary_options() {
$entity_info = entity_get_info('node');
$options = array();
if (!empty($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) {
$options[$mode] = $settings['label'];
}
}
if (empty($options)) {
$options = array(
'teaser' => t('Teaser'),
'full' => t('Full content')
);
}
return $options;
}
function summary_title() {
$options = $this->options_form_summary_options();
return check_plain($options[$this->options['view_mode']]);
}
function pre_render($values) {
$nids = array();
foreach ($values as $row) {
$nids[] = $row->{$this->field_alias};
}
$this->nodes = node_load_multiple($nids);
}
function render($row) {
if (isset($this->nodes[$row->{$this->field_alias}])) {
$node = $this->nodes[$row->{$this->field_alias}];
$node->view = $this->view;
$build = node_view($node, $this->options['view_mode']);
return drupal_render($build);
}
}
}

47
modules/poll.views.inc Normal file
View File

@@ -0,0 +1,47 @@
<?php
/**
* @file
* Provide views data and handlers for poll.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function poll_views_data() {
// Basic table information.
$data['poll']['table']['group'] = t('Poll');
// Join to 'node' as a base table.
$data['poll']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
// ----------------------------------------------------------------
// Fields
// poll active status
$data['poll']['active'] = array(
'title' => t('Active'),
'help' => t('Whether the poll is open for voting.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}

217
modules/profile.views.inc Normal file
View File

@@ -0,0 +1,217 @@
<?php
/**
* @file
* Provide views data and handlers for user.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function profile_views_data() {
$data['profile_values']['moved to'] = 'profile_value';
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['profile_value']['table']['group'] = t('Profile');
$data['profile_value']['table']['join'] = array(
'node' => array(
'left_table' => 'profile_value',
'left_field' => 'uid',
'field' => 'uid',
),
'users' => array(
'left_table' => 'profile_value',
'left_field' => 'uid',
'field' => 'uid',
),
);
$fields = profile_views_get_fields();
foreach ($fields as $field) {
$table_name = 'profile_value_' . str_replace('-', '_', $field->name);
$data[$table_name] = array(
'table' => array(
'group' => t('Profile'),
'join' => array(
'node' => array(
'table' => 'profile_value',
'left_table' => 'users',
'left_field' => 'uid',
'field' => 'uid',
'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
),
'users' => array(
'table' => 'profile_value',
'left_field' => 'uid',
'field' => 'uid',
'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
),
),
),
);
// All fields in the table are named 'value'.
$data[$table_name]['value'] = profile_views_fetch_field($field);
}
return $data;
}
/**
* Get all profile fields
*/
function profile_views_get_fields() {
static $fields = NULL;
if (!isset($fields)) {
$fields = array();
$results = db_query("SELECT * FROM {profile_field} ORDER BY category, weight");
foreach ($results as $row) {
if (!empty($row->options)) {
if (!in_array(substr($row->options, 0, 2), array('a:', 'b:', 'i:', 'f:', 'o:', 's:', ))) {
// unserialized fields default version
$options = $row->options;
unset($row->options);
$row->options = $options;
}
else {
// serialized fields or modified version
$row->options = unserialize($row->options);
}
}
$fields[$row->fid] = $row;
}
}
return $fields;
}
/**
* Add profile fields to view table
*/
function profile_views_fetch_field($field) {
$data = array(
'title' => t('@category: @field-name', array('@category' => $field->category, '@field-name' => $field->title)),
);
// Add fields specific to the profile type.
switch ($field->type) {
case 'textfield':
$data += array(
'help' => t('Profile textfield'),
'field' => array(
'handler' => 'views_handler_field_user',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
break;
case 'textarea':
$data += array(
'help' => t('Profile textarea'),
'field' => array(
'handler' => 'views_handler_field_markup',
'format' => filter_default_format(),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
break;
case 'checkbox':
$data += array(
'help' => t('Profile checkbox'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'accept null' => TRUE,
),
// @todo there ought to be a boolean argument handler
);
break;
case 'url':
$data += array(
'help' => t('Profile URL'),
'field' => array(
'handler' => 'views_handler_field_url',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
break;
case 'selection':
$data += array(
'help' => t('Profile selection'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_profile_selection',
'fid' => $field->fid,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
break;
case 'list':
$data += array(
'help' => t('Profile freeform list %field-name.', array('%field-name' => $field->title)),
'field' => array(
'handler' => 'views_handler_field_profile_list',
'no group by' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
break;
case 'date':
$data += array(
'help' => t('Profile date %field-name.', array('%field-name' => $field->title)),
'field' => array(
'handler' => 'views_handler_field_profile_date',
),
);
break;
}
// @todo: add access control to hidden fields.
return $data;
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* @file
* Definition of views_handler_field_profile_date.
*/
/**
* Field handler display a profile date
*
* The dates are stored serialized, which makes them mostly useless from
* SQL. About all we can do is unserialize and display them.
*
* @ingroup views_field_handlers
*/
class views_handler_field_profile_date extends views_handler_field_date {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// we can't do "time ago" so remove it from the form.
unset($form['date_format']['#options']['time ago']);
}
/**
* Display a profile field of type 'date'
*/
function render($values) {
$value = $this->get_value($values);
if (!$value) {
return;
}
$value = unserialize($value);
$format = $this->options['date_format'];
switch ($format) {
case 'custom':
$format = $this->options['custom_date_format'];
break;
case 'small':
$format = variable_get('date_format_short', 'm/d/Y - H:i');
break;
case 'medium':
$format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
break;
case 'large':
$format = variable_get('date_format_long', 'l, F j, Y - H:i');
break;
}
// Note: Avoid PHP's date() because it does not handle dates before
// 1970 on Windows. This would make the date field useless for e.g.
// birthdays.
// But we *can* deal with non-year stuff:
$date = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
$replace = array(
// day
'd' => sprintf('%02d', $value['day']),
'D' => NULL,
'l' => NULL,
'N' => NULL,
'S' => date('S', $date),
'w' => NULL,
'j' => $value['day'],
// month
'F' => date('F', $date),
'm' => sprintf('%02d', $value['month']),
'M' => date('M', $date),
'n' => date('n', $date),
'Y' => $value['year'],
'y' => substr($value['year'], 2, 2),
// kill time stuff
'a' => NULL,
'A' => NULL,
'g' => NULL,
'G' => NULL,
'h' => NULL,
'H' => NULL,
'i' => NULL,
's' => NULL,
':' => NULL,
'T' => NULL,
' - ' => NULL,
':' => NULL,
);
return strtr($format, $replace);
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* @file
* Definition of views_handler_field_profile_list.
*/
/**
* Field handler display a profile list item.
*
* @ingroup views_field_handlers
*/
class views_handler_field_profile_list extends views_handler_field_prerender_list {
/**
* Break up our field into a proper list.
*/
function pre_render(&$values) {
$this->items = array();
foreach ($values as $value) {
$field = $this->get_value($value);
$this->items[$field] = array();
foreach (preg_split("/[,\n\r]/", $field) as $item) {
if ($item != '' && $item !== NULL) {
$this->items[$field][] = array('item' => $item);
}
}
}
}
function render_item($count, $item) {
return $item['item'];
}
function document_self_tokens(&$tokens) {
$tokens['[' . $this->options['id'] . '-item' . ']'] = t('The text of the profile item.');
}
function add_self_tokens(&$tokens, $item) {
$tokens['[' . $this->options['id'] . '-item' . ']'] = $item['item'];
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* @file
* Definition of views_handler_filter_profile_selection.
*/
/**
* Filter by a selection widget in the profile.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_profile_selection extends views_handler_filter_in_operator {
function get_value_options() {
if (isset($this->value_options)) {
return;
}
$this->value_options = array();
$all_options = profile_views_get_fields();
$field = $all_options[$this->definition['fid']];
$lines = preg_split("/[,\n\r]/", $field->options);
foreach ($lines as $line) {
if ($line = trim($line)) {
$this->value_options[$line] = $line;
}
}
}
}

202
modules/search.views.inc Normal file
View File

@@ -0,0 +1,202 @@
<?php
/**
* @file
* Provide views data and handlers for search.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function search_views_data() {
// Basic table information.
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['search_index']['table']['group'] = t('Search');
// For other base tables, explain how we join
$data['search_index']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'sid',
),
);
$data['search_total']['table']['join'] = array(
'node' => array(
'left_table' => 'search_index',
'left_field' => 'word',
'field' => 'word',
),
'users' => array(
'left_table' => 'search_index',
'left_field' => 'word',
'field' => 'word',
)
);
$data['search_dataset']['table']['join'] = array(
'node' => array(
'left_table' => 'search_index',
'left_field' => 'sid',
'field' => 'sid',
'extra' => 'search_index.type = search_dataset.type',
'type' => 'INNER',
),
'users' => array(
'left_table' => 'search_index',
'left_field' => 'sid',
'field' => 'sid',
'extra' => 'search_index.type = search_dataset.type',
'type' => 'INNER',
),
);
// ----------------------------------------------------------------
// Fields
// score
$data['search_index']['score'] = array(
'title' => t('Score'),
'help' => t('The score of the search item. This will not be used if the search filter is not also present.'),
'field' => array(
'handler' => 'views_handler_field_search_score',
'click sortable' => TRUE,
'float' => TRUE,
'no group by' => TRUE,
),
// Information for sorting on a search score.
'sort' => array(
'handler' => 'views_handler_sort_search_score',
'no group by' => TRUE,
),
);
// Search node links: forward links.
$data['search_node_links_from']['table']['group'] = t('Search');
$data['search_node_links_from']['table']['join'] = array(
'node' => array(
'arguments' => array('search_node_links', 'node', 'nid', 'nid', NULL, 'INNER'),
),
);
$data['search_node_links_from']['sid'] = array(
'title' => t('Links from'),
'help' => t('Other nodes that are linked from the node.'),
'argument' => array(
'handler' => 'views_handler_argument_node_nid',
),
'filter' => array(
'handler' => 'views_handler_filter_equality',
),
);
// Search node links: backlinks.
$data['search_node_links_to']['table']['group'] = t('Search');
$data['search_node_links_to']['table']['join'] = array(
'node' => array(
'arguments' => array('search_node_links', 'node', 'nid', 'sid', NULL, 'INNER'),
),
);
$data['search_node_links_to']['nid'] = array(
'title' => t('Links to'),
'help' => t('Other nodes that link to the node.'),
'argument' => array(
'handler' => 'views_handler_argument_node_nid',
),
'filter' => array(
'handler' => 'views_handler_filter_equality',
),
);
// search filter
$data['search_index']['keys'] = array(
'title' => t('Search Terms'), // The item it appears as on the UI,
'help' => t('The terms to search for.'), // The help that appears on the UI,
// Information for searching terms using the full search syntax
'filter' => array(
'handler' => 'views_handler_filter_search',
'no group by' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_search',
'no group by' => TRUE,
),
);
return $data;
}
/**
* Implements hook_views_plugins().
*/
function search_views_plugins() {
return;
// DISABLED. This currently doesn't work.
return array(
'module' => 'views', // This just tells our themes are elsewhere.
'row' => array(
'search' => array(
'title' => t('Search'),
'help' => t('Display the results with standard search view.'),
'handler' => 'views_plugin_row_search_view',
'theme' => 'views_view_row_search',
'path' => drupal_get_path('module', 'views') . '/modules/search', // not necessary for most modules
'base' => array('node'), // only works with 'node' as base.
'type' => 'normal',
),
'views_handler_argument_search' => array(
'parent' => 'views_handler_argument',
),
),
);
}
/**
* Template helper for theme_views_view_row_search
*/
function template_preprocess_views_view_row_search(&$vars) {
$vars['node'] = ''; // make sure var is defined.
$nid = $vars['row']->nid;
if (!is_numeric($nid)) {
return;
}
// @todo: Once the search row is fixed this node_load should be replace by a node_load_multiple
$node = node_load($nid);
if (empty($node)) {
return;
}
// Build the node body.
$node = node_build_content($node, FALSE, FALSE);
$node->body = drupal_render($node->content);
// Fetch comments for snippet
$node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
// Fetch terms for snippet
$node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
$vars['url'] = url('node/' . $nid);
$vars['title'] = check_plain($node->title);
$info = array();
$info['type'] = node_type_get_name($node);
$info['user'] = theme('username', array('acccount' => $node));
$info['date'] = format_date($node->changed, 'small');
$extra = module_invoke_all('node_search_result', $node);
if (isset($extra) && is_array($extra)) {
$info = array_merge($info, $extra);
}
$vars['info_split'] = $info;
$vars['info'] = implode(' - ', $info);
$vars['node'] = $node;
// @todo: get score from ???
//$vars['score'] = $item->score;
$vars['snippet'] = search_excerpt($vars['view']->value, $node->body);
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* @file
* Bulk export of views_default objects generated by Bulk export module.
*/
/**
* Implementation of hook_views_default_views()
*/
function search_views_default_views() {
$views = array();
$view = new view;
$view->name = 'backlinks';
$view->description = 'Displays a list of nodes that link to the node, using the search backlinks table.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Backlinks';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = 30;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['style_options']['type'] = 'ol';
$handler->display->display_options['row_plugin'] = 'fields';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['text']['id'] = 'area';
$handler->display->display_options['empty']['text']['table'] = 'views';
$handler->display->display_options['empty']['text']['field'] = 'area';
$handler->display->display_options['empty']['text']['empty'] = FALSE;
$handler->display->display_options['empty']['text']['content'] = 'No backlinks found.';
$handler->display->display_options['empty']['text']['format'] = '1';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Contextual filter: Search: Links to */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'search_node_links_to';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'not found';
$handler->display->display_options['arguments']['nid']['title_enable'] = 1;
$handler->display->display_options['arguments']['nid']['title'] = 'Pages that link to %1';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['specify_validation'] = 1;
$handler->display->display_options['arguments']['nid']['validate']['type'] = 'node';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'node/%/backlinks';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'What links here';
$handler->display->display_options['menu']['weight'] = '0';
/* Display: What links here */
$handler = $view->new_display('block', 'What links here', 'block');
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Search: Links to */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'search_node_links_to';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['title_enable'] = 1;
$handler->display->display_options['arguments']['nid']['title'] = 'What links here';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['specify_validation'] = 1;
$handler->display->display_options['arguments']['nid']['validate']['type'] = 'node';
$translatables['backlinks'] = array(
t('Master'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('No backlinks found.'),
t('All'),
t('Pages that link to %1'),
t('Page'),
t('What links here'),
);
$views['backlinks'] = $view;
return $views;
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* @file
* Definition of views_handler_argument_search.
*/
/**
* Argument that accepts query keys for search.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_search extends views_handler_argument {
/**
* Take sure that parseSearchExpression is runned and everything is set up for it.
*
* @param $input
* The search phrase which was input by the user.
*/
function query_parse_search_expression($input) {
if (!isset($this->search_query)) {
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('viewsSearchQuery');
$this->search_query->searchExpression($input, $this->view->base_table);
$this->search_query->publicParseSearchExpression();
}
}
/**
* Add this argument to the query.
*/
function query($group_by = FALSE) {
$required = FALSE;
$this->query_parse_search_expression($this->argument);
if (!isset($this->search_query)) {
$required = TRUE;
}
else {
$words = $this->search_query->words();
if (empty($words)) {
$required = TRUE;
}
}
if ($required) {
if ($this->operator == 'required') {
$this->query->add_where(0, 'FALSE');
}
}
else {
$search_index = $this->ensure_my_table();
$search_condition = db_and();
// Create a new join to relate the 'search_total' table to our current 'search_index' table.
$join = new views_join;
$join->construct('search_total', $search_index, 'word', 'word');
$search_total = $this->query->add_relationship('search_total', $join, $search_index);
$this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE));
if (empty($this->query->relationships[$this->relationship])) {
$base_table = $this->query->base_table;
}
else {
$base_table = $this->query->relationships[$this->relationship]['base'];
}
$search_condition->condition("$search_index.type", $base_table);
if (!$this->search_query->simple()) {
$search_dataset = $this->query->add_table('search_dataset');
$conditions = $this->search_query->conditions();
$condition_conditions =& $conditions->conditions();
foreach ($condition_conditions as $key => &$condition) {
// Take sure we just look at real conditions.
if (is_numeric($key)) {
// Replace the conditions with the table alias of views.
$this->search_query->condition_replace_string('d.', "$search_dataset.", $condition);
}
}
$search_conditions =& $search_condition->conditions();
$search_conditions = array_merge($search_conditions, $condition_conditions);
}
else {
// Stores each condition, so and/or on the filter level will still work.
$or = db_or();
foreach ($words as $word) {
$or->condition("$search_index.word", $word);
}
$search_condition->condition($or);
}
$this->query->add_where(0, $search_condition);
$this->query->add_groupby("$search_index.sid");
$matches = $this->search_query->matches();
$placeholder = $this->placeholder();
$this->query->add_having_expression(0, "COUNT(*) >= $placeholder", array($placeholder => $matches));
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* @file
* Definition of views_handler_field_search_score.
*/
/**
* Field handler to provide simple renderer that allows linking to a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_search_score extends views_handler_field_numeric {
function option_definition() {
$options = parent::option_definition();
$options['alternate_sort'] = array('default' => '');
$options['alternate_order'] = array('default' => 'asc');
return $options;
}
function options_form(&$form, &$form_state) {
$style_options = $this->view->display_handler->get_option('style_options');
if (isset($style_options['default']) && $style_options['default'] == $this->options['id']) {
$handlers = $this->view->display_handler->get_handlers('field');
$options = array('' => t('No alternate'));
foreach ($handlers as $id => $handler) {
$options[$id] = $handler->ui_name();
}
$form['alternate_sort'] = array(
'#type' => 'select',
'#title' => t('Alternative sort'),
'#description' => t('Pick an alternative default table sort field to use when the search score field is unavailable.'),
'#options' => $options,
'#default_value' => $this->options['alternate_sort'],
);
$form['alternate_order'] = array(
'#type' => 'select',
'#title' => t('Alternate sort order'),
'#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
'#default_value' => $this->options['alternate_order'],
);
}
parent::options_form($form, $form_state);
}
function query() {
// Check to see if the search filter added 'score' to the table.
// Our filter stores it as $handler->search_score -- and we also
// need to check its relationship to make sure that we're using the same
// one or obviously this won't work.
foreach ($this->view->filter as $handler) {
if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
$this->field_alias = $handler->search_score;
$this->table_alias = $handler->table_alias;
return;
}
}
// Hide this field if no search filter is in place.
$this->options['exclude'] = TRUE;
if (!empty($this->options['alternate_sort'])) {
if (isset($this->view->style_plugin->options['default']) && $this->view->style_plugin->options['default'] == $this->options['id']) {
// Since the style handler initiates fields, we plug these values right into the active handler.
$this->view->style_plugin->options['default'] = $this->options['alternate_sort'];
$this->view->style_plugin->options['order'] = $this->options['alternate_order'];
}
}
}
function render($values) {
// Only render if we exist.
if (isset($this->table_alias)) {
return parent::render($values);
}
}
}

View File

@@ -0,0 +1,234 @@
<?php
/**
* @file
* Contains a search filter handler.
*/
/**
* Field handler to provide simple renderer that allows linking to a node.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_search extends views_handler_filter {
var $always_multiple = TRUE;
/**
* Stores a viewsSearchQuery object to be able to use the search.module "api".
*
* @var viewsSearchQuery
*/
var $search_query = NULL;
/**
* Checks if the search query has been parsed.
*/
var $parsed = FALSE;
function option_definition() {
$options = parent::option_definition();
$options['operator']['default'] = 'optional';
$options['remove_score'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Overrides views_handler_filter::options_form().
*
* Add an option to remove search scores from the query.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['remove_score'] = array(
'#type' => 'checkbox',
'#title' => t('Remove search score'),
'#description' => t('Check this box to remove the search score from the query. This can help reduce help reduce duplicate search results when using this filter.'),
'#default_value' => $this->options['remove_score'],
);
}
/**
* Provide simple equality operator
*/
function operator_form(&$form, &$form_state) {
$form['operator'] = array(
'#type' => 'radios',
'#title' => t('On empty input'),
'#default_value' => $this->operator,
'#options' => array(
'optional' => t('Show All'),
'required' => t('Show None'),
),
);
}
/**
* Provide a simple textfield for equality
*/
function value_form(&$form, &$form_state) {
$form['value'] = array(
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $this->value,
'#attributes' => array('title' => t('Enter the terms you wish to search for.')),
'#title' => empty($form_state['exposed']) ? t('Value') : '',
);
}
/**
* Validate the options form.
*/
function exposed_validate(&$form, &$form_state) {
if (!isset($this->options['expose']['identifier'])) {
return;
}
$key = $this->options['expose']['identifier'];
if (!empty($form_state['values'][$key])) {
$this->query_parse_search_expression($form_state['values'][$key]);
if (count($this->search_query->words()) == 0) {
form_set_error($key, format_plural(variable_get('minimum_word_size', 3), 'You must include at least one positive keyword with 1 character or more.', 'You must include at least one positive keyword with @count characters or more.'));
}
}
}
/**
* Take sure that parseSearchExpression is runned and everything is set up for it.
*
* @param $input
* The search phrase which was input by the user.
*/
function query_parse_search_expression($input) {
if (!isset($this->search_query)) {
$this->parsed = TRUE;
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('viewsSearchQuery');
$this->search_query->searchExpression($input, $this->view->base_table);
$this->search_query->publicParseSearchExpression();
}
}
/**
* Add this filter to the query.
*
* Due to the nature of fapi, the value and the operator have an unintended
* level of indirection. You will find them in $this->operator
* and $this->value respectively.
*/
function query() {
// Since attachment views don't validate the exposed input, parse the search
// expression if required.
if (!$this->parsed) {
$this->query_parse_search_expression($this->value);
}
$required = FALSE;
if (!isset($this->search_query)) {
$required = TRUE;
}
else {
$words = $this->search_query->words();
if (empty($words)) {
$required = TRUE;
}
}
if ($required) {
if ($this->operator == 'required') {
$this->query->add_where($this->options['group'], 'FALSE');
}
}
else {
$search_index = $this->ensure_my_table();
$search_condition = db_and();
if (!$this->options['remove_score']) {
// Create a new join to relate the 'serach_total' table to our current 'search_index' table.
$join = new views_join;
$join->construct('search_total', $search_index, 'word', 'word');
$search_total = $this->query->add_relationship('search_total', $join, $search_index);
$this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE));
}
if (empty($this->query->relationships[$this->relationship])) {
$base_table = $this->query->base_table;
}
else {
$base_table = $this->query->relationships[$this->relationship]['base'];
}
$search_condition->condition("$search_index.type", $base_table);
if (!$this->search_query->simple()) {
$search_dataset = $this->query->add_table('search_dataset');
$conditions = $this->search_query->conditions();
$condition_conditions =& $conditions->conditions();
foreach ($condition_conditions as $key => &$condition) {
// Take sure we just look at real conditions.
if (is_numeric($key)) {
// Replace the conditions with the table alias of views.
$this->search_query->condition_replace_string('d.', "$search_dataset.", $condition);
}
}
$search_conditions =& $search_condition->conditions();
$search_conditions = array_merge($search_conditions, $condition_conditions);
}
else {
// Stores each condition, so and/or on the filter level will still work.
$or = db_or();
foreach ($words as $word) {
$or->condition("$search_index.word", $word);
}
$search_condition->condition($or);
}
$this->query->add_where($this->options['group'], $search_condition);
$this->query->add_groupby("$search_index.sid");
$matches = $this->search_query->matches();
$placeholder = $this->placeholder();
$this->query->add_having_expression($this->options['group'], "COUNT(*) >= $placeholder", array($placeholder => $matches));
}
// Set to NULL to prevent PDO exception when views object is cached.
$this->search_query = NULL;
}
}
/**
* Extends the core SearchQuery.
*/
class viewsSearchQuery extends SearchQuery {
public function &conditions() {
return $this->conditions;
}
public function words() {
return $this->words;
}
public function simple() {
return $this->simple;
}
public function matches() {
return $this->matches;
}
public function publicParseSearchExpression() {
return $this->parseSearchExpression();
}
function condition_replace_string($search, $replace, &$condition) {
if ($condition['field'] instanceof DatabaseCondition) {
$conditions =& $condition['field']->conditions();
foreach ($conditions as $key => &$subcondition) {
if (is_numeric($key)) {
$this->condition_replace_string($search, $replace, $subcondition);
}
}
}
else {
$condition['field'] = str_replace($search, $replace, $condition['field']);
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* @file
* Definition of views_handler_sort_search_score.
*/
/**
* Field handler to provide simple renderer that allows linking to a node.
*
* @ingroup views_sort_handlers
*/
class views_handler_sort_search_score extends views_handler_sort {
function query() {
// Check to see if the search filter/argument added 'score' to the table.
// Our filter stores it as $handler->search_score -- and we also
// need to check its relationship to make sure that we're using the same
// one or obviously this won't work.
foreach (array('filter', 'argument') as $type) {
foreach ($this->view->{$type} as $handler) {
if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
$this->query->add_orderby(NULL, NULL, $this->options['order'], $handler->search_score);
$this->table_alias = $handler->table_alias;
return;
}
}
}
// Do absolutely nothing if there is no filter/argument in place; there is no reason to
// sort on the raw scores with this handler.
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* @file
* Definition of views_plugin_row_search_view.
*/
/**
* Plugin which performs a node_view on the resulting object.
*/
class views_plugin_row_search_view extends views_plugin_row {
function option_definition() {
$options = parent::option_definition();
$options['score'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['score'] = array(
'#type' => 'checkbox',
'#title' => t('Display score'),
'#default_value' => $this->options['score'],
);
}
/**
* Override the behavior of the render() function.
*/
function render($row) {
return theme($this->theme_functions(),
array(
'view' => $this->view,
'options' => $this->options,
'row' => $row
));
}
}

Some files were not shown because too many files have changed in this diff Show More