Now all modules are in core modules folder

This commit is contained in:
Manuel Cillero 2017-08-08 12:14:45 +02:00
parent 5ba1cdfa0b
commit 05b6a91b0c
1907 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,456 @@
<?php
/**
* @file
* Provide views data and handlers for aggregator.module
*/
/**
* @defgroup views_aggregator_module aggregator.module handlers
*
* Includes the core 'aggregator_feed,' 'aggregator_category,' and 'aggregator_item'
* tables.
*
* @{
*/
/**
* Implementation of 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',
),
);
// 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',
),
// Information for accepting a title as a filter
'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',
),
// Information for accepting a title as a filter
'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,
),
// Information for accepting a title as a filter
'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 onf 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;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function aggregator_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/aggregator',
),
'handlers' => array(
// field handlers
'views_handler_field_aggregator_title_link' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_aggregator_category' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_aggregator_xss' => array(
'parent' => 'views_handler_field',
),
// argument handlers
'views_handler_argument_aggregator_iid' => array(
'parent' => 'views_handler_argument_numeric',
),
'views_handler_argument_aggregator_fid' => array(
'parent' => 'views_handler_argument_numeric',
),
'views_handler_argument_aggregator_category_cid' => array(
'parent' => 'views_handler_argument_numeric',
),
// filter handlers
'views_handler_filter_aggregator_category_cid' => array(
'parent' => 'views_handler_filter_in_operator',
),
),
);
}
/**
* Implementation of 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/aggregator', // 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,20 @@
<?php
/**
* Argument handler to accept an aggregator category id.
*/
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();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$result = db_query("SELECT c.title FROM {aggregator_category} c WHERE c.cid IN ($placeholders)", $this->value);
while ($term = db_fetch_object($result)) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Argument handler to accept an aggregator feed id.
*/
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();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$result = db_query("SELECT f.title FROM {aggregator_feed} f WHERE f.fid IN ($placeholders)", $this->value);
while ($term = db_fetch_object($result)) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View file

@ -0,0 +1,20 @@
<?php
/**
* Argument handler to accept an aggregator item id.
*/
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_query("SELECT i.title FROM {aggregator_item} i WHERE i.iid IN ($placeholders)", $this->value);
while ($term = db_fetch_object($result)) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* Field handler to provide simple renderer that allows linking to aggregator
* category.
*/
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);
return $options;
}
/**
* Provide link to category option
*/
function options_form(&$form, &$form_state) {
parent::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']),
);
}
/**
* 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) {
if (!empty($this->options['link_to_category']) && !empty($values->{$this->aliases['cid']}) && $data !== NULL && $data !== '') {
$cid = $values->{$this->aliases['cid']};
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "aggregator/category/$cid";
}
return $data;
}
function render($values) {
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
}
}

View file

@ -0,0 +1,43 @@
<?php
/**
* Field handler that turns an item's title into a clickable link to the original
* source article.
*/
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);
return $options;
}
/**
* Provide link to the page being visited.
*/
function options_form(&$form, &$form_state) {
parent::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']),
);
}
function render($values) {
$value = $values->{$this->field_alias};
$link = $values->{$this->table_alias . '_link'};
if (!empty($this->options['display_as_link'])) {
return l(check_plain($value), $link, array('html' => TRUE));
}
else {
return check_plain($value);
}
}
}

View file

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

View file

@ -0,0 +1,19 @@
<?php
/**
* Filter by aggregator category cid
*/
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');
while ($category = db_fetch_object($result)) {
$this->value_options[$category->cid] = $category->title;
}
}
}

View file

@ -0,0 +1,64 @@
<?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 {
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) {
$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 = %d";
$item = db_fetch_object(db_query($sql, $row->iid));
$item->elements = array(
array('key' => 'pubDate', 'value' => gmdate('r', $item->timestamp)),
array(
'key' => 'dc:creator',
'value' => $item->author,
'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'),
),
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(), $this->view, $this->options, $item);
}
}

View file

@ -0,0 +1,123 @@
<?php
/**
* @file
* Provide views data and handlers for book.module
*/
/**
* @defgroup views_book_module book.module handlers
*
* @{
*/
/**
* Implementation of 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;
}
/**
* @}
*/

View file

@ -0,0 +1,80 @@
<?php
/**
* @file
* Field conversion for fields handled by this module.
*/
/**
* Implementation of hook_views_convert().
*/
function book_views_convert($display, $type, &$view, $field, $id = NULL) {
switch ($type) {
case 'field':
switch ($field['tablename']) {
case 'book_parent_node':
switch ($field['field']) {
case 'title':
$item = $view->get_item($display, 'field', $id);
if ($field['handler'] == 'views_handler_field_book_parent_title') {
$item['link_to_node'] = TRUE;
}
$item['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid');
$item['table'] = 'node';
$item['field'] = 'title';
$view->set_item($display, 'field', $id, $item);
break;
}
break;
}
break;
case 'filter':
switch ($field['tablename']) {
case 'book':
switch ($field['field']) {
case 'parent':
$operators = array('AND' => '=', 'OR' => '=', 'NOT' => '!=');
$item = $view->get_item($display, 'filter', $id);
$item['operator'] = $operators[$field['operator']];
$item['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid');
$item['table'] = 'node';
$item['field'] = 'nid';
$view->set_item($display, 'filter', $id, $item);
break;
}
break;
}
break;
case 'sort':
switch ($field['tablename']) {
case 'book':
switch ($field['field']) {
case 'weight':
$view->set_item_option($display, 'sort', $id, 'table', 'book_menu_links');
break;
}
break;
case 'book_parent_node':
switch ($field['field']) {
case 'title':
$item = $view->get_item($display, 'sort', $id);
$item['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid');
$item['table'] = 'node';
$item['field'] = 'title';
$view->set_item($display, 'sort', $id, $item);
break;
}
break;
}
break;
case 'argument':
$options = $field['argoptions'];
switch ($field['type']) {
case 'book_parent':
$options['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid');
$view->add_item($display, 'argument', 'node', 'nid', $options, $field['id']);
break;
}
break;
}
}

View file

@ -0,0 +1,564 @@
<?php
/**
* @file
* Provide views data and handlers for comment.module
*/
/**
* @defgroup views_comment_module comment.module handlers
*
* Includes the tables 'comments' and 'node_comment_statistics'
* @{
*/
/**
* Implementation of hook_views_data()
*/
function comment_views_data() {
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['comments']['table']['group'] = t('Comment');
$data['comments']['table']['base'] = array(
'field' => 'cid',
'title' => t('Comment'),
'help' => t("Comments are responses to node content."),
);
//joins
$data['comments']['table']['join'] = array(
//...to the node table
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
// ----------------------------------------------------------------
// Fields
// subject
$data['comments']['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',
),
);
// comment (the comment body)
$data['comments']['comment'] = array(
'title' => t('Body'),
'help' => t('The text of the comment.'),
'field' => array(
'handler' => 'views_handler_field_markup',
'format' => 'format',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// cid
$data['comments']['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['comments']['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['comments']['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['comments']['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['comments']['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',
),
);
// timestamp (when comment was posted)
$data['comments']['timestamp'] = array(
'title' => t('Post date'),
'help' => t('Date and time of when the comment was posted.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// status (approved or not)
$data['comments']['status'] = array(
'title' => t('In moderation'),
'help' => t('Whether or not the comment is currently in the moderation queue.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('In the moderation queue'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// link to view comment
$data['comments']['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['comments']['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['comments']['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 reply to comment
$data['comments']['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['comments']['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['comments']['nid'] = array(
'title' => t('Node'),
'help' => t('The node the comment is a reply to.'),
'relationship' => array(
'base' => 'node',
'base field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Node'),
),
);
$data['comments']['uid'] = array(
'title' => t('User'),
'help' => t("The User ID of the comment's author."),
'relationship' => array(
'base' => 'users',
'base field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('User'),
),
);
$data['comments']['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' => 'comments',
'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('Node');
// 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,
),
'sort' => array(
'handler' => 'views_handler_sort_ncs_last_comment_name',
),
);
// 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,
),
'sort' => array(
'handler' => 'views_handler_sort_ncs_last_updated',
),
'filter' => array(
'handler' => 'views_handler_filter_ncs_last_updated',
),
);
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',
),
);
$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',
),
'filter' => array(
'field' => 'uid',
'name table' => 'users',
'name field' => 'name',
'handler' => 'views_handler_filter_comment_user_uid'
),
);
}
/**
* Implementation of hook_views_plugins
*/
function comment_views_plugins() {
return array(
'module' => 'views', // This just tells views our themes are in Views.
'row' => array(
'comment' => array(
'title' => t('Comment'),
'help' => t('Display the comment with standard comment view.'),
'handler' => 'views_plugin_row_comment_view',
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
'theme' => 'views_view_row_comment',
'base' => array('comments'), // 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',
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
'theme' => 'views_view_row_rss',
'base' => array('comments'), // only works with 'comment' as base.
'type' => 'feed',
'help topic' => 'style-comment-rss',
),
),
);
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function comment_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/comment',
),
'handlers' => array(
'views_handler_field_comment' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_comment_username' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_comment_depth' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_comment_link' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_comment_link_edit' => array(
'parent' => 'views_handler_field_comment_link',
),
'views_handler_field_comment_link_delete' => array(
'parent' => 'views_handler_field_comment_link',
),
'views_handler_field_comment_link_reply' => array(
'parent' => 'views_handler_field_comment_link',
),
'views_handler_field_comment_node_link' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_ncs_last_comment_name' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_ncs_last_updated' => array(
'parent' => 'views_handler_field_date',
),
'views_handler_field_node_new_comments' => array(
'parent' => 'views_handler_field_numeric',
),
'views_handler_field_node_comment' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_last_comment_timestamp' => array(
'parent' => 'views_handler_field_date',
),
// sort handlers
'views_handler_sort_comment_thread' => array(
'parent' => 'views_handler_sort',
),
'views_handler_sort_ncs_last_comment_name' => array(
'parent' => 'views_handler_sort',
),
'views_handler_sort_ncs_last_updated' => array(
'parent' => 'views_handler_sort_date',
),
// filter handlers
'views_handler_filter_ncs_last_updated' => array(
'parent' => 'views_handler_filter_date',
),
'views_handler_filter_node_comment' => array(
'parent' => 'views_handler_filter_in_operator',
),
'views_handler_filter_comment_user_uid' => array(
'parent' => 'views_handler_filter_user_name',
),
// argument handlers
'views_handler_argument_comment_user_uid' => array(
'parent' => 'views_handler_argument',
),
),
);
}
/**
* 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']->cid];
$node = node_load($comment->nid);
// Put the view on the node so we can retrieve it in the preprocess.
$node->view = &$view;
$links = array();
if (!empty($options['links'])) {
$links = module_invoke_all('link', 'comment', $comment, 0);
drupal_alter('link', $links, $node);
}
$vars['comment'] = theme('comment_view', $comment, $node, $links);
}
/**
* @}
*/

View file

@ -0,0 +1,131 @@
<?php
/**
* @file
* Field conversion for fields handled by this module.
*/
/**
* Implementation of hook_views_convert().
*
* Intervene to convert field values from the Views 1 format to the
* Views 2 format. Intervene only if $view->add_item() won't produce
* the right results, usually needed to set field options or values.
*/
function comment_views_convert($display, $type, &$view, $field, $id = NULL) {
switch ($type) {
case 'field':
switch ($field['tablename']) {
case 'comments':
switch ($field['field']) {
case 'subject':
if ($field['options'] = 'nolink') {
$view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE);
}
break;
case 'cid':
$view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE);
break;
case 'timestamp':
$handlers = array(
'views_handler_field_date_small' => 'small',
'views_handler_field_date' => 'medium',
'views_handler_field_date_large' => 'large',
'views_handler_field_date_custom' => 'custom',
'views_handler_field_since' => 'time ago',
);
$view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
if (!empty($field['options'])) {
$view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
}
break;
case 'add':
$view->set_item_option($display, 'field', $id, 'field', 'replyto_comment');
break;
}
break;
case 'node_comment_statistics':
switch ($field['field']) {
case 'last_comment_timestamp':
$handlers = array(
'views_handler_field_date_small' => 'small',
'views_handler_field_date' => 'medium',
'views_handler_field_date_large' => 'large',
'views_handler_field_date_custom' => 'custom',
'views_handler_field_since' => 'time ago',
);
$view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
if (!empty($field['options'])) {
$view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
}
break;
case 'last_changed':
$handlers = array(
'views_handler_field_date_small' => 'small',
'views_handler_field_date' => 'medium',
'views_handler_field_date_large' => 'large',
'views_handler_field_date_custom' => 'custom',
'views_handler_field_since' => 'time ago',
);
$item = $view->get_item($display, 'field', $id);
$item['date_format'] = $handlers[$field['handler']];
if (!empty($field['options'])) {
$item['custom_date_format'] = $field['options'];
}
$item['field'] = 'last_updated';
$view->set_item($display, 'field', $id, $item);
break;
}
break;
}
break;
case 'filter':
switch ($field['tablename']) {
case 'node_comment_statistics':
switch ($field['field']) {
case 'comment_count':
$view->set_item_option($display, 'filter', $id, 'operator', $field['operator']);
break;
case 'last_changed':
$field['field'] = 'last_updated';
case 'last_comment_timestamp':
$item = $view->get_item($display, 'filter', $id);
$item['operator'] = $field['operator'];
$item['value'] = array(
'type' => $field['value'] == 'now' ? 'offset' : 'date',
'value' => $field['value'],
);
if (!empty($field['options'])) {
$item['value']['value'] = intval($field['options']) .' seconds';
}
$item['field'] = $field['field'];
$view->set_item($display, 'filter', $id, $item);
break;
}
break;
}
break;
case 'sort':
switch ($field['tablename']) {
case 'comments':
switch ($field['field']) {
case 'timestamp':
$field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
$view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
break;
}
break;
case 'node_comment_statistics':
switch ($field['field']) {
case 'last_changed':
$view->set_item_option($display, 'sort', $id, 'field', 'last_updated');
case 'last_comment_timestamp':
$field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
$view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
break;
}
break;
}
break;
}
}

View file

@ -0,0 +1,356 @@
<?php
/**
* @file
* Contains default views on behalf of the comment module.
*/
/**
* Implementation of hook_views_default_views().
*/
function comment_views_default_views() {
$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 = 'comments';
$view->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'nid' => array(
'id' => 'nid',
'table' => 'comments',
'field' => 'nid',
'label' => 'Node',
'required' => FALSE,
),
));
$handler->override_option('fields', array(
'subject' => array(
'id' => 'subject',
'table' => 'comments',
'field' => 'subject',
'label' => '',
'link_to_comment' => 1,
'relationship' => 'none',
),
'timestamp' => array(
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'label' => '',
'date_format' => 'time ago',
'custom_date_format' => '',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'timestamp' => array(
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'order' => 'DESC',
'granularity' => 'second',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status_extra' => array(
'id' => 'status_extra',
'table' => 'node',
'field' => 'status_extra',
'operator' => '=',
'value' => '',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'nid',
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access comments',
));
$handler->override_option('title', 'Recent comments');
$handler->override_option('items_per_page', 5);
$handler->override_option('use_more', 1);
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'type' => 'ul',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('fields', array(
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => 'Reply to',
'relationship' => 'nid',
'link_to_node' => 1,
),
'timestamp' => array(
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'label' => '',
'date_format' => 'time ago',
'custom_date_format' => '',
'relationship' => 'none',
),
'subject' => array(
'id' => 'subject',
'table' => 'comments',
'field' => 'subject',
'label' => '',
'link_to_comment' => 1,
'relationship' => 'none',
),
'comment' => array(
'id' => 'comment',
'table' => 'comments',
'field' => 'comment',
'label' => '',
'relationship' => 'none',
),
));
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('row_options', array(
'inline' => array(
'title' => 'title',
'timestamp' => 'timestamp',
),
'separator' => '&nbsp;',
));
$handler->override_option('path', 'comments/recent');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('block', 'Block', 'block');
$handler->override_option('block_description', 'Recent comments view');
$views[$view->name] = $view;
$view = new view;
$view->name = 'tracker';
$view->description = 'Shows all new activity on system.';
$view->tag = 'default';
$view->base_table = 'node';
$view->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'type' => array(
'id' => 'type',
'table' => 'node',
'field' => 'type',
'label' => 'Type',
),
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => 'Title',
'link_to_node' => TRUE,
),
'name' => array(
'id' => 'name',
'table' => 'users',
'field' => 'name',
'label' => 'Author',
'link_to_user' => TRUE,
),
'comment_count' => array(
'id' => 'comment_count',
'table' => 'node_comment_statistics',
'field' => 'comment_count',
'label' => 'Replies',
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => '',
),
'last_comment_timestamp' => array(
'id' => 'last_comment_timestamp',
'table' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'label' => 'Last Post',
'date_format' => 'small',
'custom_date_format' => '',
),
'timestamp' => array(
'id' => 'timestamp',
'table' => 'history_user',
'field' => 'timestamp',
'label' => '',
'comments' => 1,
'relationship' => 'none',
'link_to_node' => 0,
'comment' => 1,
),
'new_comments' => array(
'id' => 'new_comments',
'table' => 'node',
'field' => 'new_comments',
'label' => '',
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => ' new',
'link_to_comment' => 1,
'no_empty' => 1,
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'last_comment_timestamp' => array(
'id' => 'last_comment_timestamp',
'table' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'order' => 'ASC',
'granularity' => 'second',
),
));
$handler->override_option('arguments', array(
'uid_touch' => array(
'id' => 'uid_touch',
'table' => 'node',
'field' => 'uid_touch',
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => TRUE,
'override' => FALSE,
'items_per_page' => 25,
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => 'Recent posts for %1',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'relationship' => 'none',
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'album' => 0,
'artist' => 0,
'book' => 0,
'page' => 0,
'story' => 0,
'track' => 0,
),
'validate_argument_php' => '',
),
));
$handler->override_option('filters', array(
'status' => array(
'id' => 'status',
'table' => 'node',
'field' => 'status',
'operator' => '=',
'value' => '1',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'status' => array(
'id' => 'status',
'table' => 'comments',
'field' => 'status',
'operator' => '=',
'value' => 0,
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'none',
),
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access content',
));
$handler->override_option('title', 'Recent posts');
$handler->override_option('items_per_page', '25');
$handler->override_option('use_pager', TRUE);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'override' => 1,
'order' => 'desc',
'columns' => array(
'type' => 'type',
'title' => 'title',
'name' => 'name',
'comment_count' => 'comment_count',
'last_comment_timestamp' => 'last_comment_timestamp',
'timestamp' => 'title',
'new_comments' => 'comment_count',
),
'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' => '',
),
),
'default' => 'last_comment_timestamp',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'tracker');
$handler->override_option('menu', array(
'type' => 'normal',
'title' => 'Recent posts',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => NULL,
'weight' => NULL,
));
$views[$view->name] = $view;
return $views;
}

View file

@ -0,0 +1,40 @@
<?php
/**
* Argument handler to accept a user id to check for nodes that
* user posted or commented on.
*/
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_result(db_query("SELECT u.name FROM {users} u WHERE u.uid = %d", $this->argument));
}
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() {
$this->ensure_my_table();
$this->query->add_where(0, "$this->table_alias.uid = %d OR ((SELECT COUNT(*) FROM {comments} c WHERE c.uid = %d AND c.nid = $this->table_alias.nid) > 0)", $this->argument, $this->argument);
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* Field handler to allow linking to a comment
*/
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);
return $options;
}
/**
* Provide link-to-comment option
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_comment'] = array(
'#title' => t('Link this field to its comment'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_comment'],
);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/". $values->{$this->aliases['nid']};
$this->options['alter']['fragment'] = "comment-" . $values->{$this->aliases['cid']};
}
return $data;
}
function render($values) {
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
}
}

View file

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

View file

@ -0,0 +1,37 @@
<?php
/**
* Base field handler to present a link.
*/
class views_handler_field_comment_link extends views_handler_field {
function construct() {
parent::construct();
$this->additional_fields['cid'] = 'cid';
$this->additional_fields['nid'] = 'nid';
}
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
return l($text, "node/" . $values->{$this->aliases['nid']}, array('html' => TRUE, 'fragment' => "comment-" . $values->{$this->aliases['cid']}));
}
}

View file

@ -0,0 +1,14 @@
<?php
/**
* Field handler to present a link to delete a node.
*/
class views_handler_field_comment_link_delete extends views_handler_field_comment_link {
function render($values) {
//needs permission to administer comments in general
if (!user_access('administer comments')) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
return l($text, "comment/delete/" . $values->{$this->aliases['cid']}, array('query' => drupal_get_destination()));
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* Field handler to present a link node edit.
*/
class views_handler_field_comment_link_edit extends views_handler_field_comment_link {
function construct() {
parent::construct();
$this->additional_fields['uid'] = 'uid';
}
function option_definition() {
$options = parent::option_definition();
$options['destination'] = array('default' => FALSE);
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'],
);
}
function render($values) {
// ensure user has access to edit this comment.
$comment = new stdClass();
$comment->cid = $values->{$this->aliases['cid']};
$comment->uid = $values->{$this->aliases['uid']};
if (!comment_access('edit', $comment)) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
if (!$this->options['destination']) {
return l($text, "comment/edit/" . $values->{$this->aliases['cid']});
}
else {
return l($text, "comment/edit/" . $values->{$this->aliases['cid']}, array('query' => drupal_get_destination()));
}
}
}

View file

@ -0,0 +1,15 @@
<?php
/**
* Field handler to present a link to delete a node.
*/
class views_handler_field_comment_link_reply extends views_handler_field_comment_link {
function render($values) {
//check for permission to reply to comments
if (!user_access('post comments')) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('reply');
return l($text, "comment/reply/" . $values->{$this->aliases['nid']} . '/' . $values->{$this->aliases['cid']});
}
}

View file

@ -0,0 +1,59 @@
<?php
/**
* Handler for showing comment module's node link.
*/
class views_handler_field_comment_node_link extends views_handler_field {
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' => 0);
return $options;
}
function options_form(&$form, &$form_state) {
parent::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.'),
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
// Build fake $node.
$node = new stdClass();
$node->nid = $values->{$this->aliases['nid']};
$node->type = $values->{$this->aliases['type']};
$node->comment = $values->{$this->aliases['comment']};
// Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
$links = comment_link('node', $node, $this->options['teaser']);
// 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?
return !empty($links) ? theme('links', $links, array('class' => 'links inline')) : '';
}
}

View file

@ -0,0 +1,48 @@
<?php
/**
* Field handler to allow linking to a user account or homepage
*/
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);
return $options;
}
function options_form(&$form, &$form_state) {
parent::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'],
);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account->uid = $values->{$this->aliases['uid']};
$account->name = $values->{$this->field_alias};
$account->homepage = $values->{$this->aliases['homepage']};
return theme('username', $account);
}
else {
return $data;
}
}
function render($values) {
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
}
}

View file

@ -0,0 +1,17 @@
<?php
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) {
if (empty($this->options['empty_zero']) || $values->{$this->aliases['comment_count']}) {
return parent::render($values);
}
else {
return NULL;
}
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* Field handler to present the name of the last comment poster
*/
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);
return $options;
}
function render($values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account->name = $values->{$this->field_alias};
$account->uid = $values->{$this->uid};
return theme('username', $account);
}
else {
return check_plain($values->{$this->field_alias});
}
}
}

View file

@ -0,0 +1,11 @@
<?php
/**
* Field handler to display the newer of last comment / node updated
*/
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,18 @@
<?php
/**
* Display node comment status
*/
class views_handler_field_node_comment extends views_handler_field {
function render($values) {
switch ($values->{$this->field_alias}) {
case COMMENT_NODE_DISABLED:
default:
return t('Disabled');
case COMMENT_NODE_READ_ONLY:
return t('Read only');
case COMMENT_NODE_READ_WRITE:
return t('Read/Write');
}
}
}

View file

@ -0,0 +1,100 @@
<?php
/**
* Field handler to display the number of new comments
*/
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);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_comment'] = array(
'#title' => t('Link this field to new comments'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_comment'],
);
}
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 {comments} c ON n.nid = c.nid LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = %d WHERE n.nid IN (" . implode(', ', $nids) . ") AND c.timestamp > GREATEST(COALESCE(h.timestamp, %d), %d) AND c.status = %d GROUP BY n.nid ", $user->uid, NODE_NEW_LIMIT, NODE_NEW_LIMIT, COMMENT_PUBLISHED);
while ($node = db_fetch_object($result)) {
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 = $values->{$this->aliases['nid']};
$node->type = $values->{$this->aliases['type']};
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->nid;
$this->options['alter']['query'] = comment_new_page_count($values->{$this->aliases['comment_count']}, $values->{$this->field_alias}, $node);
$this->options['alter']['fragment'] = 'new';
}
return $data;
}
function render($values) {
if (!empty($values->{$this->field_alias})) {
return $this->render_link(parent::render($values), $values);
}
else {
$this->options['alter']['make_link'] = FALSE;
}
}
}

View file

@ -0,0 +1,22 @@
<?php
/**
* Filter handler to accept a user id to check for nodes that user posted or
* commented on.
*/
class views_handler_filter_comment_user_uid extends views_handler_filter_user_name {
function query() {
$this->ensure_my_table();
$replace = array_fill(0, sizeof($this->value), '%d');
$condition = $this->operator . ' (' . implode(", ", $replace) . ')';
// We include the WHERE condition twice in the query, so we need two
// copies of these argument values.
$args = array_values($this->value);
$args = array_merge($args, $args);
$this->query->add_where($this->options['group'], "$this->table_alias.uid " . $condition . " OR
((SELECT COUNT(*) FROM {comments} c WHERE c.uid " . $condition . " AND c.nid = $this->table_alias.nid) > 0)",
$args);
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* Filter handler for the newer of last comment / node updated
*/
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,14 @@
<?php
/**
* Filter based on comment node status
*/
class views_handler_filter_node_comment extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_options = array(
COMMENT_NODE_DISABLED => t('Disabled'),
COMMENT_NODE_READ_ONLY => t('Read only'),
COMMENT_NODE_READ_WRITE => t('Read/Write'),
);
}
}

View file

@ -0,0 +1,20 @@
<?php
/**
* Sort handler for ordering by thread
*/
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,22 @@
<?php
/**
* Sort handler to sort by last comment name which might be in 2 different
* fields
*/
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,12 @@
<?php
/**
* Sort handler for the newer of last comment / node updated
*/
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,41 @@
<?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 {
function render($row) {
global $base_url;
// Load the specified comment:
$comment = _comment_load($row->cid);
$item = new stdClass();
$item->title = $comment->subject;
$item->link = url('node/' . $comment->nid, array('absolute' => TRUE, 'fragment' => 'comment-' . $comment->cid));
$item->description = check_markup($comment->comment, $comment->format, FALSE);
$item->elements = array(
array('key' => 'pubDate', 'value' => gmdate('r', $comment->timestamp)),
array('key' => 'dc:creator', 'value' => $comment->name),
array(
'key' => 'guid',
'value' => 'comment ' . $row->cid . ' at ' . $base_url,
'attributes' => array('isPermaLink' => 'false'),
'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'),
),
);
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(), $this->view, $this->options, $item);
}
}

View file

@ -0,0 +1,49 @@
<?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 {
function option_definition() {
$options = parent::option_definition();
$options['links'] = array('default' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
}
function pre_render($result) {
$cids = array();
$this->comments = array();
foreach ($result as $row) {
$cids[] = $row->cid;
}
if (count($cids) > 1) {
$placeholder = " IN (" . implode(', ', array_fill(0, sizeof($cids), '%d')) . ")";
}
else {
$placeholder = " = %d";
}
$cresult = db_query("SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid $placeholder", $cids);
while ($comment = db_fetch_object($cresult)) {
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment->depth = count(explode('.', $comment->thread)) - 1;
$this->comments[$comment->cid] = $comment;
}
}
}

View file

@ -0,0 +1,32 @@
<?php
/**
* @file
* Provide views data and handlers for contact.module
*/
function contact_views_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',
),
);
return $data;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function contact_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/contact',
),
'handlers' => array(
'views_handler_field_contact_link' => array(
'parent' => 'views_handler_field_user_link',
),
),
);
}

View file

@ -0,0 +1,71 @@
<?php
/**
* A field that links to the user contact page, if access is permitted.
*/
class views_handler_field_contact_link extends views_handler_field_user_link {
function option_definition() {
$options = parent::option_definition();
$options['link_display'] = array('default' => 'link', 'translatable' => FALSE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_display'] = array(
'#title' => t('Type of link'),
'#default_value' => $this->options['link_display'],
'#type' => 'select',
'#options' => array(
'link' => t('Link'),
'icon' => t('Icon'),
),
);
$form['text']['#title'] = t('Link label');
$form['text']['#required'] = TRUE;
$form['text']['#default_value'] = empty($this->options['text']) ? t('contact') : $this->options['text'];
}
// 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() {
global $user;
// Only registered users can view other registered user's contact page.
if (empty($user->uid)) {
return FALSE;
}
return TRUE;
}
function render($values) {
global $user;
$uid = $values->{$this->aliases['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->contact)) {
return;
}
if ($this->options['link_display'] == 'icon') {
return l(theme('image', 'misc/forum-new.png'), 'user/'. $account->uid .'/contact', array('html' => TRUE, 'attributes' => array('title' => t('Contact %user', array('%user' => $account->name)))));
}
else {
return l($this->options['text'], 'user/'. $account->uid .'/contact', array('attributes' => array('title' => t('Contact %user', array('%user' => $account->name)))));
}
}
}

View file

@ -0,0 +1,54 @@
<?php
/**
* @file
* Provide basic views data for filter.module.
*/
/**
* @defgroup views_filter_module filter.module handlers
*
* Only includes the table 'filter_formats'.
* @{
*/
/**
* Implementation of hook_views_data()
*/
function filter_views_data() {
// ----------------------------------------------------------------------
// filter_formats table
// Have not defined $data['filter_formats']['table']['group'] since
// no fields are defined here yet.
$data['filter_formats']['table']['join'] = array(
'node_revisions' => array(
'left_field' => 'format',
'field' => 'format',
),
'node' => array(
'left_table' => 'node_revisions',
'left_field' => 'format',
'field' => 'format',
),
);
return $data;
}
function filter_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/filter',
),
'handlers' => array(
// field handlers
'views_handler_field_filter_format_name' => array(
'parent' => 'views_handler_field',
),
),
);
}
/**
* @}
*/

View file

@ -0,0 +1,28 @@
<?php
/**
* Field handler to output the name of an input format.
*/
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 = $values->{$this->aliases['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(variable_get('filter_default_format', 1));
return check_plain($format->name);
}
return check_plain($format_name);
}
}

View file

@ -0,0 +1,246 @@
<?php
/**
* @file
*
* Provides views data and handlers for locale.module.
*/
/**
* @defgroup views_locale_module locale.module handlers
*
* @{
*/
/**
* Implementation of 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;
}
/**
* Implementation of hook_views_handlers().
*/
function locale_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/locale',
),
'handlers' => array(
// Field handlers.
'views_handler_field_locale_group' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_locale_language' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_locale_link_edit' => array(
'parent' => 'views_handler_field',
),
// Argument handlers.
'views_handler_argument_locale_group' => array(
'parent' => 'views_handler_argument',
),
'views_handler_argument_locale_language' => array(
'parent' => 'views_handler_argument',
),
// Filters.
'views_handler_filter_locale_group' => array(
'parent' => 'views_handler_filter_in_operator',
),
'views_handler_filter_locale_language' => array(
'parent' => 'views_handler_filter_in_operator',
),
'views_handler_filter_locale_version' => array(
'parent' => 'views_handler_filter_in_operator',
),
),
);
}
/**
* @}
*/

View file

@ -0,0 +1,34 @@
<?php
/**
* Argument handler to accept a language.
*/
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,32 @@
<?php
/**
* Argument handler to accept a language.
*/
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 = locale_language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language');
}
}

View file

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

View file

@ -0,0 +1,28 @@
<?php
/**
* Field handler to translate a language into its readable form.
*/
class views_handler_field_locale_language extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['native_language'] = array('default' => FALSE);
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');
return isset($languages[$values->{$this->field_alias}]) ? $languages[$values->{$this->field_alias}] : '';
}
}

View file

@ -0,0 +1,44 @@
<?php
/**
* Field handler to present a link to edit a translation.
*/
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) {
parent::options_form($form, $form_state);
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
// Ensure user has access to edit translations.
if (!user_access('translate interface')) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
return l($text, 'admin/build/translate/edit/' . $values->{$this->aliases['lid']}, array('query' => drupal_get_destination()));
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* Filter by locale group.
*/
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,16 @@
<?php
/**
* Filter by language.
*/
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"), '***NO_LANGUAGE***' => t('No language'));
$languages = array_merge($languages, locale_language_list());
$this->value_options = $languages;
}
}
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Filter by version.
*/
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');
while ($row = db_fetch_array($result)) {
if (!empty($row['version'])) {
$versions[$row['version']] = $row['version'];
}
}
$this->value_options = $versions;
}
}
}

View file

@ -0,0 +1,886 @@
<?php
/**
* @file
* Provide views data and handlers for node.module
*/
/**
* @defgroup views_node_module node.module handlers
*
* Includes the tables 'node', 'node_revisions' and 'history'.
* @{
*/
/**
* Implementation of 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('Node');
// Advertise this table as a possible base table
$data['node']['table']['base'] = array(
'field' => 'nid',
'title' => t('Node'),
'help' => t("Nodes are a Drupal site's primary content."),
'weight' => -10,
);
// For other base tables, explain how we join
$data['node']['table']['join'] = array(
// this explains how the 'node' table (named in the line above)
// links toward the node_revisions table.
'node_revisions' => array(
'handler' => 'views_join', // this is actually optional
'left_table' => 'node_revisions', // Because this is a direct link it could be left out.
'left_field' => 'nid',
'field' => 'nid',
// also supported:
// 'type' => 'INNER',
// 'extra' => array(array('field' => 'fieldname', 'value' => 'value', 'operator' => '='))
// Unfortunately, you can't specify other tables here, but you can construct
// alternative joins in the handlers that can do that.
// 'table' => 'the actual name of this table in the database',
),
);
// ----------------------------------------------------------------
// node table -- fields
// nid
$data['node']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node ID of the node.'), // 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',
'parent' => 'views_handler_argument_numeric', // make sure parent is included
'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 title of the node.'), // 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('Node'), // 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 node 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 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',
),
);
// Node type
$data['node']['type'] = array(
'title' => t('Type'), // The item it appears as on the UI,
'help' => t('The type of a node (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 node 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 nodes if the current user cannot view them.'),
'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 node is promoted to the front page.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Promoted to front page'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// moderate
$data['node']['moderate'] = array(
'title' => t('In moderation'), // The item it appears as on the UI,
'help' => t('Whether or not the node is currently in the moderation queue.'), // 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,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('In the moderation queue'),
'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 node 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'), ''),
),
),
'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 node is sticky. To list sticky nodes first, set this to descending.'),
),
);
// links to operate on the node
$data['node']['view_node'] = array(
'field' => array(
'title' => t('Link'),
'help' => t('Provide a simple link to the node.'),
'handler' => 'views_handler_field_node_link',
),
);
$data['node']['edit_node'] = array(
'field' => array(
'title' => t('Edit link'),
'help' => t('Provide a simple link to edit the node.'),
'handler' => 'views_handler_field_node_link_edit',
),
);
$data['node']['delete_node'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the node.'),
'handler' => 'views_handler_field_node_link_delete',
),
);
$data['node']['path'] = array(
'field' => array(
'title' => t('Path'),
'help' => t('The aliased path to this node.'),
'handler' => 'views_handler_field_node_path',
),
);
// Bogus fields for aliasing purposes.
$data['node']['created_fulldate'] = array(
'title' => t('Created date'),
'help' => t('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('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('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('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('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('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('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('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('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('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('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('In the form of WW (01 - 53).'),
'argument' => array(
'field' => 'changed',
'handler' => 'views_handler_argument_node_created_week',
),
);
// ----------------------------------------------------------------------
// Node revisions 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']['table']['group'] = t('Node revision');
// Advertise this table as a possible base table
$data['node_revisions']['table']['base'] = array(
'field' => 'vid',
'title' => t('Node revision'),
'help' => t('Node revisions are a history of changes to nodes.'),
);
// For other base tables, explain how we join
$data['node_revisions']['table']['join'] = array(
// Directly links to node table.
'node' => array(
'left_field' => 'vid',
'field' => 'vid',
),
);
// uid field
$data['node_revisions']['uid'] = array(
'title' => t('User'),
'help' => t('Relate a node revision to the user who created the revision.'),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'users',
'base field' => 'uid',
'label' => t('user'),
),
);
// Body field
$data['node_revisions']['body'] = array(
'group' => t('Node'),
'title' => t('Body'), // The item it appears as on the UI,
'help' => t('The actual, full data in the body field; this may not be valid data on all node types.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_markup',
'format' => 'format', // The name of the format field
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// Teaser field
$data['node_revisions']['teaser'] = array(
'group' => t('Node'),
'title' => t('Teaser'), // The item it appears as on the UI,
'help' => t('The stored teaser field. This may not be valid or useful data on all node types.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_markup',
'format' => 'format', // The name of the format field
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// nid
$data['node_revisions']['vid'] = array(
'title' => t('Vid'),
'help' => t('The revision ID of the node revision.'), // The help that appears on the UI,
// Information for displaying the nid
'field' => array(
// 'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
// Information for accepting a nid as an argument
'argument' => array(
'handler' => 'views_handler_argument_node_vid',
'parent' => 'views_handler_argument_numeric', // make sure parent is included
'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('Node'),
'label' => t('Get the actual node from a node revision.'),
),
);
// title
$data['node_revisions']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI,
'help' => t('The title of the node.'), // 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_revisions']['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_revisions']['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',
),
);
// input format id
$data['node_revisions']['format'] = array(
'title' => t('Input format id'), // The item it appears as on the UI,
'help' => t('The numeric input format of the node revision. !default means the default input format.', array('!default' => FILTER_FORMAT_DEFAULT)), // The help that appears on the UI,
// Information for displaying an input format as a field
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
// Information for sorting on input format
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting input format as a filter
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
// input format name
// A (numeric) format of 0 means the default; Drupal also applies the default
// if the format specifed for a node revision has been deleted.
// This complexity makes sorting and filtering by format name tricky,
// hence these are not yet supported.
$data['node_revisions']['format_name'] = array(
'title' => t('Input format'), // The item it appears as on the UI,
'help' => t('The name of the input format of the node revision.'), // The help that appears on the UI,
// Information for displaying an input format as a field
'field' => array(
'handler' => 'views_handler_field_filter_format_name',
),
);
$data['node_revisions']['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_revisions']['delete_revision'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the node 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('Node 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 nodes 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']['table']['group'] = t('Node');
// Explain how this table joins to others.
$data['history_user']['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_user']['timestamp'] = array(
'title' => t('Has new content'),
'field' => array(
'handler' => 'views_handler_field_history_user_timestamp',
'help' => t('Show a marker if the node has new or updated content.'),
),
'filter' => array(
'help' => t('Show only nodes that have new content.'),
'handler' => 'views_handler_filter_history_user_timestamp',
),
);
return $data;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function node_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/node',
),
'handlers' => array(
// field handlers
'views_handler_field_node' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_node_type' => array(
'parent' => 'views_handler_field_node',
),
'views_handler_field_node_link' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_node_path' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_node_link_edit' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_node_link_delete' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_node_revision_link_revert' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_node_revision_link_delete' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_history_user_timestamp' => array(
'parent' => 'views_handler_field_node',
),
'views_handler_field_node_revision' => array(
'parent' => 'views_handler_field_node',
),
// argument handlers
'views_handler_argument_node_type' => array(
'parent' => 'views_handler_argument',
),
'views_handler_argument_node_nid' => array(
'parent' => 'views_handler_argument_numeric',
),
'views_handler_argument_node_vid' => array(
'parent' => 'views_handler_argument_numeric',
),
'views_handler_argument_node_created_fulldate' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
),
'views_handler_argument_node_created_year' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
),
'views_handler_argument_node_created_year_month' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
),
'views_handler_argument_node_created_month' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
),
'views_handler_argument_node_created_day' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
),
'views_handler_argument_node_created_week' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
),
// filters
'views_handler_filter_node_type' => array(
'parent' => 'views_handler_filter_in_operator',
),
'views_handler_filter_history_user_timestamp' => array(
'parent' => 'views_handler_filter',
),
'views_handler_filter_node_status' => array(
'parent' => 'views_handler_filter',
),
'views_handler_filter_node_access' => array(
'parent' => 'views_handler_filter',
),
),
);
}
/**
* Implementation of hook_views_plugins
*/
function node_views_plugins() {
return array(
'module' => 'views', // This just tells our themes are elsewhere.
'row' => array(
'node' => array(
'title' => t('Node'),
'help' => t('Display the node with standard node view.'),
'handler' => 'views_plugin_row_node_view',
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'theme' => 'views_view_row_node',
'base' => array('node'), // only works with 'node' as base.
'uses options' => TRUE,
'type' => 'normal',
'help topic' => 'style-node',
),
'node_rss' => array(
'title' => t('Node'),
'help' => t('Display the node 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('Node'),
'handler' => 'views_plugin_argument_validate_node',
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
),
),
'argument default' => array(
'node' => array(
'title' => t('Node ID from URL'),
'handler' => 'views_plugin_argument_default_node',
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'parent' => 'fixed', // so that the parent class is included
),
),
);
}
/**
* Template helper for theme_views_view_row_node
*/
function template_preprocess_views_view_row_node(&$vars) {
$options = $vars['options'];
// Make sure the variables are defined.
$vars['node'] = '';
$vars['comments'] = '';
if (!empty($vars['row']->{$vars['field_alias']})) {
$nid = $vars['row']->{$vars['field_alias']};
}
if (!is_numeric($nid)) {
return;
}
$node = node_load($nid);
if (empty($node)) {
return;
}
$node->view = $vars['view'];
$node->build_mode = ($options['build_mode'] == 'teaser' || $options['build_mode'] == 'full') ? NODE_BUILD_NORMAL : $options['build_mode'];
$vars['node'] = node_view($node, $options['build_mode'] == 'teaser', FALSE, $options['links']);
if (!empty($options['comments']) && function_exists('comment_render')) {
$vars['comments'] = comment_render($node);
}
}
/**
* Implementation of hook_views_query_substitutions().
*/
function node_views_query_substitutions() {
return array(
'***ADMINISTER_NODES***' => intval(user_access('administer nodes')),
);
}
/**
* Implementation of 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 (!$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') {
$result = db_query("SELECT r.name, p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.name IN ('anonymous user', 'authenticated user')");
while ($role = db_fetch_object($result)) {
$role->perm = explode(', ', $role->perm);
$role->safe = in_array('access content', $role->perm);
$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,181 @@
<?php
/**
* @file
* Field conversion for fields handled by this module.
*/
/**
* Implementation of hook_views_convert().
*
* Intervene to convert field values from the Views 1 format to the
* Views 2 format. Intervene only if $view->add_item() won't produce
* the right results, usually needed to set field options or values.
*/
function node_views_convert($display, $type, &$view, $field, $id = NULL) {
switch ($type) {
case 'field':
switch ($field['tablename']) {
case 'node':
switch ($field['field']) {
case 'title':
if ($field['options'] != 'no_link') {
$view->set_item_option($display, 'field', $id, 'link_to_node', TRUE);
}
break;
case 'created':
case 'changed':
$handlers = array(
'views_handler_field_date_small' => 'small',
'views_handler_field_date' => 'medium',
'views_handler_field_date_large' => 'large',
'views_handler_field_date_custom' => 'custom',
'views_handler_field_since' => 'time ago',
);
$view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
if (!empty($field['options'])) {
$view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
}
break;
case 'body':
$field['field'] = $field['handler'] == 'views_handler_field_teaser' ? 'teaser' : $field['field'];
$view->set_item_option($display, 'field', $id, 'field', $field['field']);
$view->set_item_option($display, 'field', $id, 'table', 'node_revisions');
break;
case 'link':
case 'edit':
case 'delete':
case 'view':
$field['field'] = $field['field'] == 'link' ? 'view_node' : "$field[field]_node";
$view->set_item_option($display, 'field', $id, 'field', $field['field']);
if (!empty($field['options'])) {
$view->set_item_option($display, 'field', $id, 'text', $field['options']);
}
break;
}
break;
}
break;
case 'filter':
switch ($field['tablename']) {
case 'node':
switch ($field['field']) {
case 'type':
$operators = array('OR' => 'in', 'NOR' => 'not in');
$view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]);
break;
case 'anon':
$item = $view->get_item($display, 'filter', $id);
$item['value'] = array(0);
$item['table'] = 'users';
$item['field'] = 'uid';
$view->set_item($display, 'filter', $id, $item);
break;
case 'currentuid':
$operators = array('=' => TRUE, '!=' => FALSE);
$item = $view->get_item($display, 'filter', $id);
$item['value'] = $operators[$field['operator']];
$item['table'] = 'users';
$item['field'] = 'uid_current';
$view->set_item($display, 'filter', $id, $item);
break;
case 'currentuidtouched':
$view->set_item_option($display, 'filter', $id, 'value', '=');
$view->set_item_option($display, 'filter', $id, 'field', 'uid_touch');
break;
case 'distinct':
$view->display_handler->set_option('distinct', $field['operator'] == '=' && $field['value'] == 'distinct');
$view->set_item($display, 'filter', $id, NULL);
break;
case 'title':
$item = $view->get_item($display, 'filter', $id);
$item['operator'] = $field['operator'];
$item['case'] = FALSE;
$view->set_item($display, 'filter', $id, $item);
break;
case 'created':
case 'changed':
$item = $view->get_item($display, 'filter', $id);
$item['operator'] = $field['operator'];
$item['value'] = array(
'type' => $field['value'] == 'now' ? 'offset' : 'date',
'value' => $field['value'],
);
if (!empty($field['options'])) {
$item['value']['value'] = intval($field['options']) .' seconds';
}
$view->set_item($display, 'filter', $id, $item);
break;
case 'body':
$item = $view->get_item($display, 'filter', $id);
$item['operator'] = $field['operator'];
$item['case'] = FALSE;
$item['table'] = 'node_revisions';
$view->set_item($display, 'filter', $id, $item);
break;
}
break;
case 'history':
switch ($field['field']) {
case 'timestamp':
$view->set_item_option($display, 'filter', $id, 'table', 'history_user');
break;
}
break;
}
break;
case 'sort':
switch ($field['tablename']) {
case 'node':
switch ($field['field']) {
case 'created':
case 'changed':
$field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
$view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
break;
case 'random':
$view->set_item_option($display, 'sort', $id, 'table', 'views');
break;
}
break;
}
break;
case 'argument':
$options = $field['argoptions'];
switch ($field['type']) {
case 'nodetype':
$view->add_item($display, 'argument', 'node', 'type', $options, $field['id']);
break;
case 'nodeletter':
if (!empty($field['options'])) {
$options['glossary'] = TRUE;
$options['limit'] = $field['options'];
}
$options['case'] = 'upper';
$view->add_item($display, 'argument', 'node', 'title', $options, $field['id']);
break;
case 'year':
$view->add_item($display, 'argument', 'node', 'created_year', $options, $field['id']);
break;
case 'month':
$view->add_item($display, 'argument', 'node', 'created_month', $options, $field['id']);
break;
case 'week':
$view->add_item($display, 'argument', 'node', 'created_week', $options, $field['id']);
break;
case 'monthyear':
$view->add_item($display, 'argument', 'node', 'created_year_month', $options, $field['id']);
break;
case 'fulldate':
$view->add_item($display, 'argument', 'node', 'created_fulldate', $options, $field['id']);
break;
case 'nid':
if (!empty($field['options'])) {
$options['not'] = TRUE;
}
$view->add_item($display, 'argument', 'node', 'nid', $options, $field['id']);
break;
}
break;
}
}

View file

@ -0,0 +1,377 @@
<?php
/**
* @file
* Contains default views on behalf of the node module.
*/
/**
* Implementation of hook_views_default_views().
*/
function node_views_default_views() {
$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->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('sorts', array(
'sticky' => array(
'id' => 'sticky',
'table' => 'node',
'field' => 'sticky',
'order' => 'DESC',
),
'created' => array(
'id' => 'created',
'table' => 'node',
'field' => 'created',
'order' => 'DESC',
'relationship' => 'none',
'granularity' => 'second',
),
));
$handler->override_option('filters', array(
'promote' => array(
'id' => 'promote',
'table' => 'node',
'field' => 'promote',
'operator' => '=',
'value' => '1',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
),
'status' => array(
'id' => 'status',
'table' => 'node',
'field' => 'status',
'operator' => '=',
'value' => '1',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access content',
));
$handler->override_option('header_format', '1');
$handler->override_option('footer_format', '1');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'teaser' => 1,
'links' => 1,
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'frontpage');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->override_option('sitename_title', '1');
$handler->override_option('title', 'Front page feed');
$handler->override_option('style_options', array(
'mission_description' => 1,
'description' => '',
));
$handler->override_option('row_plugin', 'node_rss');
$handler->override_option('row_options', array(
'item_length' => 'default',
));
$handler->override_option('path', 'rss.xml');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('displays', array(
'default' => 'default',
'page' => 'page',
));
$views[$view->name] = $view;
$view = new view;
$view->name = 'glossary';
$view->description = 'A list of all content, by letter.';
$view->tag = 'default';
$view->base_table = 'node';
$view->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => 'Title',
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'name' => array(
'label' => 'Author',
'link_to_user' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
'changed' => array(
'label' => 'Last update',
'date_format' => 'large',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'changed',
'table' => 'node',
'field' => 'changed',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'title' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'glossary' => 1,
'limit' => '1',
'case' => 'upper',
'path_case' => 'lower',
'transform_dash' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
'default_argument_user' => 0,
'default_argument_fixed' => 'a',
'default_argument_php' => '',
'validate_argument_vocabulary' => array(),
'validate_argument_type' => 'tid',
'validate_argument_php' => '',
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access content',
));
$handler->override_option('use_ajax', '1');
$handler->override_option('items_per_page', 36);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'title' => 'title',
'name' => 'name',
'changed' => 'changed',
),
'info' => array(
'title' => array(
'sortable' => 1,
'separator' => '',
),
'name' => array(
'sortable' => 1,
'separator' => '',
),
'changed' => array(
'sortable' => 1,
'separator' => '',
),
),
'default' => 'title',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'glossary');
$handler->override_option('menu', array(
'type' => 'normal',
'title' => 'Glossary',
'weight' => '0',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('attachment', 'Attachment', 'attachment');
$handler->override_option('arguments', array(
'title' => array(
'default_action' => 'summary asc',
'style_plugin' => 'unformatted_summary',
'style_options' => array(
'count' => 1,
'override' => 0,
'items_per_page' => '25',
'inline' => 1,
'separator' => ' | ',
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'glossary' => 1,
'limit' => '1',
'case' => 'upper',
'path_case' => 'lower',
'transform_dash' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
'default_argument_user' => 0,
'default_argument_fixed' => 'a',
'validate_argument_vocabulary' => array(),
'validate_argument_php' => '',
),
));
$handler->override_option('inherit_arguments', 0);
$handler->override_option('displays', array(
'default' => 'default',
'page' => 'page',
));
$views[$view->name] = $view;
$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->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('title', 'Monthly archive');
$handler->override_option('sorts', array(
'created' => array(
'id' => 'created',
'table' => 'node',
'field' => 'created',
'order' => 'DESC',
'granularity' => 'second',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'created_year_month' => array(
'id' => 'created_year_month',
'table' => 'node',
'field' => 'created_year_month',
'default_action' => 'summary desc',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => 1,
'override' => 1,
'items_per_page' => '30',
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '%1',
'relationship' => 'none',
'validate_type' => 'none',
'validate_fail' => 'not found',
'default_argument_type' => 'fixed',
),
));
$handler->override_option('filters', array(
'status' => array(
'id' => 'status',
'table' => 'node',
'field' => 'status',
'operator' => '=',
'value' => 1,
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access content',
));
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'teaser' => TRUE,
'links' => TRUE,
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'archive');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('block', 'Block', 'block');
$handler->override_option('arguments', array(
'created_year_month' => array(
'id' => 'created_year_month',
'table' => 'node',
'field' => 'created_year_month',
'default_action' => 'summary asc',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => 1,
'override' => 0,
'items_per_page' => '30',
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '%1',
'relationship' => 'none',
'validate_type' => 'none',
'validate_fail' => 'not found',
'default_argument_type' => 'fixed',
),
));
$handler->override_option('block_description', 'Archive list');
$views[$view->name] = $view;
return $views;
}

View file

@ -0,0 +1,169 @@
<?php
/**
* 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), 'custom', $this->format, 0);
}
/**
* Provide a link to the next level of the view
*/
function title() {
return format_date(strtotime($this->argument), 'custom', $this->format, 0);
}
}
/**
* 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, 0);
}
/**
* 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, 0);
}
}
/**
* 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);
}
/**
* 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, 0);
}
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, 0);
}
/**
* 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, 0);
}
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,31 @@
<?php
/**
* 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 = locale_language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language');
}
}

View file

@ -0,0 +1,25 @@
<?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();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$result = db_query("SELECT n.title FROM {node} n WHERE n.nid IN ($placeholders)", $this->value);
while ($term = db_fetch_object($result)) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View file

@ -0,0 +1,35 @@
<?php
/**
* Argument handler to accept a node type.
*/
class views_handler_argument_node_type extends views_handler_argument {
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_get_types('name', $type);
if (empty($output)) {
return t('Unknown node type');
}
else {
return check_plain(t($output));
}
}
}

View file

@ -0,0 +1,27 @@
<?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();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$result = db_query("SELECT n.title FROM {node_revisions} n WHERE n.nid IN ($placeholders)", $this->value);
while ($term = db_fetch_object($result)) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}

View file

@ -0,0 +1,71 @@
<?php
/**
* Field handler to display the marker for new content.
*/
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);
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']),
);
}
}
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 = $values->{$this->field_alias};
$created = $values->{$this->aliases['created']};
$changed = $values->{$this->aliases['changed']};
$last_comment = module_exists('comment') && !empty($this->options['comments']) ? $values->{$this->aliases['last_comment']} : 0;
if (!$last_read && $created > 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', $mark), $values);
}
}
}

View file

@ -0,0 +1,73 @@
<?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.
*/
class views_handler_field_node extends views_handler_field {
/**
* Constructor to provide additional field to add.
*/
function construct() {
parent::construct();
$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);
return $options;
}
/**
* Provide link to node option
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_node'] = array(
'#title' => t('Link this field to its node'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_node']),
);
}
/**
* 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'])) {
if ($data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']};
if (isset($this->aliases['language'])) {
$languages = language_list();
if (isset($languages[$values->{$this->aliases['language']}])) {
$this->options['alter']['language'] = $languages[$values->{$this->aliases['language']}];
}
else {
unset($this->options['alter']['language']);
}
}
}
else {
$this->options['alter']['make_link'] = FALSE;
}
}
return $data;
}
function render($values) {
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* Field handler to present a link to the node.
*/
class views_handler_field_node_link extends views_handler_field {
function construct() {
parent::construct();
$this->additional_fields['nid'] = 'nid';
}
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
$nid = $values->{$this->aliases['nid']};
return l($text, "node/$nid");
}
}

View file

@ -0,0 +1,29 @@
<?php
/**
* Field handler to present a link to delete a node.
*/
class views_handler_field_node_link_delete extends views_handler_field_node_link {
function construct() {
parent::construct();
$this->additional_fields['type'] = 'type';
$this->additional_fields['uid'] = 'uid';
$this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format');
}
function render($values) {
// ensure user has access to edit this node.
$node = new stdClass();
$node->nid = $values->{$this->aliases['nid']};
$node->uid = $values->{$this->aliases['uid']};
$node->type = $values->{$this->aliases['type']};
$node->format = $values->{$this->aliases['format']};
$node->status = 1; // unpublished nodes ignore access control
if (!node_access('delete', $node)) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
return l($text, "node/$node->nid/delete", array('query' => drupal_get_destination()));
}
}

View file

@ -0,0 +1,29 @@
<?php
/**
* Field handler to present a link node edit.
*/
class views_handler_field_node_link_edit extends views_handler_field_node_link {
function construct() {
parent::construct();
$this->additional_fields['uid'] = 'uid';
$this->additional_fields['type'] = 'type';
$this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format');
}
function render($values) {
// ensure user has access to edit this node.
$node = new stdClass();
$node->nid = $values->{$this->aliases['nid']};
$node->uid = $values->{$this->aliases['uid']};
$node->type = $values->{$this->aliases['type']};
$node->format = $values->{$this->aliases['format']};
$node->status = 1; // unpublished nodes ignore access control
if (!node_access('update', $node)) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
return l($text, "node/$node->nid/edit", array('query' => drupal_get_destination()));
}
}

View file

@ -0,0 +1,39 @@
<?php
// $Id:
/**
* Field handler to present the path to the node.
*/
class views_handler_field_node_path extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['absolute'] = array('default' => FALSE);
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('If you want to use this as in "output this field as link" in "link path", you must enable this option.'),
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$nid = $values->{$this->aliases['nid']};
return url("node/$nid", array('absolute' => $this->options['absolute']));
}
}

View file

@ -0,0 +1,59 @@
<?php
/**
* @file
* Contains the basic 'node_revision' field handler.
*/
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);
return $options;
}
/**
* Provide link to revision option.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_node_revision'] = array(
'#title' => t('Link this field to its node revision'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_node_revision']),
);
}
/**
* 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;
$this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']} . '/revisions/' . $values->{$this->aliases['vid']} .'/view';
if (isset($this->aliases['language'])) {
$languages = language_list();
if (isset($languages[$values->{$this->aliases['language']}])) {
$this->options['alter']['language'] = $languages[$values->{$this->aliases['language']}];
}
}
}
else {
return parent::render_link($data, $values);
}
return $data;
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* Field handler to present delete a node revision.
*/
class views_handler_field_node_revision_link_delete extends views_handler_field_node_link {
function construct() {
parent::construct();
$this->additional_fields['uid'] = array('table' => 'node', 'field' => 'uid');
$this->additional_fields['node_vid'] = array('table' => 'node', 'field' => 'vid');
$this->additional_fields['vid'] = 'vid';
$this->additional_fields['format'] = 'format';
}
function access() {
return user_access('delete revisions') || user_access('administer nodes');
}
function render($values) {
// ensure user has access to edit this node.
$node = new stdClass();
$node->nid = $values->{$this->aliases['nid']};
$node->vid = $values->{$this->aliases['vid']};
$node->uid = $values->{$this->aliases['uid']};
$node->format = $values->{$this->aliases['format']};
$node->status = 1; // unpublished nodes ignore access control
if (!node_access('delete', $node)) {
return;
}
// Current revision cannot be deleted.
if ($node->vid == $values->{$this->aliases['node_vid']}) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
return l($text, "node/$node->nid/revisions/$node->vid/delete", array('query' => drupal_get_destination()));
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* Field handler to present a link to revert a node to a revision
*/
class views_handler_field_node_revision_link_revert extends views_handler_field_node_link {
function construct() {
parent::construct();
$this->additional_fields['uid'] = array('table' => 'node', 'field' => 'uid');
$this->additional_fields['node_vid'] = array('table' => 'node', 'field' => 'vid');
$this->additional_fields['vid'] = 'vid';
$this->additional_fields['format'] = 'format';
}
function access() {
return user_access('revert revisions') || user_access('administer nodes');
}
function render($values) {
// ensure user has access to edit this node.
$node = new stdClass();
$node->nid = $values->{$this->aliases['nid']};
$node->vid = $values->{$this->aliases['vid']};
$node->uid = $values->{$this->aliases['uid']};
$node->format = $values->{$this->aliases['format']};
$node->status = 1; // unpublished nodes ignore access control
if (!node_access('update', $node)) {
return;
}
// Current revision cannot be reverted.
if ($node->vid == $values->{$this->aliases['node_vid']}) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('revert');
return l($text, "node/$node->nid/revisions/$node->vid/revert", array('query' => drupal_get_destination()));
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* Field handler to translate a node type into its readable form.
*/
class views_handler_field_node_type extends views_handler_field_node {
function option_definition() {
$options = parent::option_definition();
$options['machine_name'] = array('default' => FALSE);
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 node 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(check_plain(node_get_types('name', $data)));
}
return check_plain($data);
}
function render($values) {
return $this->render_link($this->render_name($values->{$this->field_alias}, $values), $values);
}
}

View file

@ -0,0 +1,71 @@
<?php
/**
* Filter for new content
*/
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_right(&$form, &$form_state) {
// We don't want any of the usual options for exposed filters.
}
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 = time() - NODE_NEW_LIMIT;
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
$node = $this->query->ensure_table('node', $this->relationship);
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($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,32 @@
<?php
/**
* Filter by node_access records.
*/
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')) {
$table = $this->ensure_my_table();
$grants = array();
foreach (node_access_grants('view') as $realm => $gids) {
foreach ($gids as $gid) {
$grants[] = "($table.gid = $gid AND $table.realm = '$realm')";
}
}
$grants_sql = '';
if (count($grants)) {
$grants_sql = implode(' OR ', $grants);
}
$this->query->add_where('AND', $grants_sql);
$this->query->add_where('AND', "$table.grant_view >= 1");
}
}
}

View file

@ -0,0 +1,13 @@
<?php
/**
* Filter by published status
*/
class views_handler_filter_node_status extends views_handler_filter {
function admin_summary() { }
function operator_form(&$form, &$form_state) { }
function query() {
$table = $this->ensure_my_table();
$this->query->add_where($this->options['group'], "$table.status = 1 OR ($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0) OR ***ADMINISTER_NODES*** = 1");
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* Filter by node type
*/
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('Node type');
$types = node_get_types();
foreach ($types as $type => $info) {
$options[$type] = t($info->name);
}
asort($options);
$this->value_options = $options;
}
}
}

View file

@ -0,0 +1,27 @@
<?php
/**
* @file
* Contains the node from URL argument default plugin.
*/
/**
* Default argument plugin to extract a node via menu_get_object
*/
class views_plugin_argument_default_node extends views_plugin_argument_default {
function argument_form(&$form, &$form_state) {
}
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,122 @@
<?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 {
var $option_name = 'validate_argument_node_type';
function validate_form(&$form, &$form_state) {
$types = node_get_types();
foreach ($types as $type => $info) {
$options[$type] = check_plain(t($info->name));
}
$arg = $this->get_argument();
if (empty($arg)) {
$arg = array();
}
$form[$this->option_name] = array(
'#type' => 'checkboxes',
'#prefix' => '<div id="edit-options-validate-argument-node-type-wrapper">',
'#suffix' => '</div>',
'#title' => t('Types'),
'#options' => $options,
'#default_value' => $arg,
'#description' => t('If you wish to validate for specific node types, check them; if none are checked, all nodes will pass.'),
'#process' => array('expand_checkboxes', 'views_process_dependency'),
'#dependency' => array('edit-options-validate-type' => array($this->id)),
);
$form['validate_argument_node_access'] = array(
'#type' => 'checkbox',
'#title' => t('Validate user has access to the node'),
'#default_value' => !empty($this->argument->options['validate_argument_node_access']),
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-options-validate-type' => array($this->id)),
);
$form['validate_argument_nid_type'] = array(
'#type' => 'select',
'#title' => t('Argument type'),
'#options' => array(
'nid' => t('Node ID'),
'nids' => t('Node IDs separated by , or +'),
),
'#default_value' => isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : 'nid',
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-options-validate-type' => array($this->id)),
);
}
function validate_argument($argument) {
$types = array_filter($this->argument->options[$this->option_name]);
$type = isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : 'nid';
switch ($type) {
case 'nid':
if (!is_numeric($argument)) {
return FALSE;
}
$node = node_load($argument);
if (!$node) {
return FALSE;
}
if (!empty($this->argument->options['validate_argument_node_access'])) {
if (!node_access('view', $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 == -1) {
return FALSE;
}
$placeholders = implode(', ', array_fill(0, sizeof($nids->value), '%d'));
$test = drupal_map_assoc($nids->value);
$titles = array();
$result = db_query("SELECT * FROM {node} WHERE nid IN ($placeholders)", $nids->value);
while ($node = db_fetch_object($result)) {
if ($types && empty($types[$node->type])) {
return FALSE;
}
if (!empty($this->argument->options['validate_argument_node_access'])) {
if (!node_access('view', $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,141 @@
<?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';
function option_definition() {
$options = parent::option_definition();
$options['item_length'] = array('default' => 'default');
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' => 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) {
// 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;
}
$item_length = $this->options['item_length'];
if ($item_length == 'default') {
$item_length = variable_get('feed_item_length', 'teaser');
}
// Load the specified node:
$node = node_load($nid);
if (empty($node)) {
return;
}
$node->build_mode = NODE_BUILD_RSS;
if ($item_length != 'title') {
$teaser = ($item_length == 'teaser') ? TRUE : FALSE;
// Filter and prepare node teaser
if (node_hook($node, 'view')) {
$node = node_invoke($node, 'view', $teaser, FALSE);
}
else {
$node = node_prepare($node, $teaser);
}
// Allow modules to change $node->teaser before viewing.
node_invoke_nodeapi($node, 'view', $teaser, FALSE);
}
// Set the proper node part, then unset unused $node part so that a bad
// theme can not open a security hole.
$content = drupal_render($node->content);
if ($teaser) {
$node->teaser = $content;
unset($node->body);
}
else {
$node->body = $content;
unset($node->teaser);
}
// Allow modules to modify the fully-built node.
node_invoke_nodeapi($node, 'alter', $teaser, FALSE);
$item = new stdClass();
$item->title = $node->title;
$item->link = url("node/$row->nid", array('absolute' => TRUE));
$item->nid = $node->nid;
$item->readmore = $node->readmore;
// Allow modules to add additional item fields and/or modify $item
$extra = node_invoke_nodeapi($node, 'rss item');
$item->elements = array_merge($extra,
array(
array('key' => 'pubDate', 'value' => gmdate('r', $node->created)),
array(
'key' => 'dc:creator',
'value' => $node->name,
'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'),
),
array(
'key' => 'guid',
'value' => $node->nid . ' at ' . $base_url,
'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']);
}
}
// Prepare the item description
switch ($item_length) {
case 'fulltext':
$item->description = $node->body;
break;
case 'teaser':
$item->description = $node->teaser;
if (!empty($item->readmore)) {
$item->description .= '<p>' . l(t('read more'), 'node/' . $item->nid, array('absolute' => TRUE, 'attributes' => array('target' => '_blank'))) . '</p>';
}
break;
case 'title':
$item->description = '';
break;
}
return theme($this->theme_functions(), $this->view, $this->options, $item);
}
}

View file

@ -0,0 +1,72 @@
<?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.
*/
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';
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';
}
}
function option_definition() {
$options = parent::option_definition();
$options['build_mode'] = array('default' => 'teaser');
$options['links'] = array('default' => TRUE);
$options['comments'] = array('default' => FALSE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// CCK holds the registry of available build modes, but can hardly
// push them as options for the node row style, so we break the normal
// rule of not directly relying on non-core modules.
if ($modes = module_invoke('content', 'build_modes')) {
$options = array();
foreach ($modes as $key => $value) {
if (isset($value['views style']) && $value['views style']) {
$options[$key] = $value['title'];
}
}
}
else {
$options = array(
'teaser' => t('Teaser'),
'full' => t('Full node')
);
}
$form['build_mode'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('Build mode'),
'#default_value' => $this->options['build_mode'],
);
$form['links'] = array(
'#type' => 'checkbox',
'#title' => t('Display links'),
'#default_value' => $this->options['links'],
);
$form['comments'] = array(
'#type' => 'checkbox',
'#title' => t('Display node comments'),
'#default_value' => $this->options['comments'],
);
}
}

View file

@ -0,0 +1,55 @@
<?php
/**
* @file
* Provide views data and handlers for poll.module
*/
/**
* @defgroup views_poll_module poll.module handlers
*
* Includes only the core 'poll' table for now.
* @{
*/
/**
* Implementation of 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;
}
/**
* @}
*/

View file

@ -0,0 +1,245 @@
<?php
/**
* @file
* Provide views data and handlers for user.module
*/
/**
* @defgroup views_profile_module profile.module handlers
*
* @{
*/
/**
* Implementation of hook_views_data()
*/
function profile_views_data() {
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['profile_values']['table']['group'] = t('Profile');
$data['profile_values']['table']['join'] = array(
'node' => array(
'left_table' => 'profile_values',
'left_field' => 'uid',
'field' => 'uid',
),
'users' => array(
'left_table' => 'profile_values',
'left_field' => 'uid',
'field' => 'uid',
),
);
$fields = profile_views_get_fields();
foreach ($fields as $field) {
$table_name = 'profile_values_' . str_replace('-', '_', $field->name);
$data[$table_name] = array(
'table' => array(
'group' => t('Profile'),
'join' => array(
'node' => array(
'table' => 'profile_values',
'left_table' => 'users',
'left_field' => 'uid',
'field' => 'uid',
'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
),
'users' => array(
'table' => 'profile_values',
'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_fields} ORDER BY category, weight");
while ($row = db_fetch_object($results)) {
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(db_decode_blob($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_FORMAT_DEFAULT,
),
'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',
),
'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;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function profile_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/profile',
),
'handlers' => array(
'views_handler_field_profile_date' => array(
'parent' => 'views_handler_field_date',
),
'views_handler_field_profile_list' => array(
'parent' => 'views_handler_field_prerender_list',
),
'views_handler_filter_profile_selection' => array(
'parent' => 'views_handler_filter_in_operator',
),
),
);
}
/**
* @}
*/

View file

@ -0,0 +1,39 @@
<?php
/**
* @file
* Field conversion for fields handled by this module.
*/
/**
* Implementation of hook_views_convert().
*
* Intervene to convert field values from the Views 1 format to the
* Views 2 format. Intervene only if $view->add_item() won't produce
* the right results, usually needed to set field options or values.
*/
function profile_views_convert($display, $type, &$view, $field, $id = NULL) {
static $profile_fields;
if (!isset($profile_fields)) {
$profile_fields = array();
foreach (profile_views_get_fields() as $profile_field) {
$profile_fields['profile_values_'. $profile_field->name] = $profile_field;
}
}
switch ($type) {
case 'filter':
if (isset($tables[$field['tablename']])) {
switch ($profile_fields[$field['tablename']]->type) {
case 'vocabulary':
case 'selection':
$operators = array('AND' => 'in', 'OR' => 'in', 'NOR' => 'not in');
$view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]);
break;
default:
$view->set_item_option($display, 'filter', $id, 'operator', $field['operator']);
break;
}
}
break;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* 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.
*/
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($value) {
if (!$value->{$this->field_alias}) {
return;
}
$value = unserialize($value->{$this->field_alias});
$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'], 1970);
$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,33 @@
<?php
/**
* Field handler display a profile list item.
*/
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 = $value->{$this->field_alias};
$this->items[$field] = array();
foreach (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,23 @@
<?php
/**
* Filter by a selection widget in the profile.
*/
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 = split("[,\n\r]", $field->options);
foreach ($lines as $line) {
if ($line = trim($line)) {
$this->value_options[$line] = $line;
}
}
}
}

View file

@ -0,0 +1,223 @@
<?php
/**
* @file
* Provide views data and handlers for search.module
*/
/**
* @defgroup views_search_module search.module handlers
*
* Includes the tables 'search_index'
* @{
*/
/**
* Implementation of 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,
),
// Information for sorting on a search score.
'sort' => array(
'handler' => 'views_handler_sort_search_score',
),
);
// 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',
),
);
return $data;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function search_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/search',
),
'handlers' => array(
'views_handler_field_search_score' => array(
'parent' => 'views_handler_field_numeric',
),
'views_handler_sort_search_score' => array(
'parent' => 'views_handler_sort',
),
'views_handler_filter_search' => array(
'parent' => 'views_handler_filter',
),
),
);
}
/**
* Implementation of 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',
'path' => drupal_get_path('module', 'views') . '/modules/search', // not necessary for most modules
'theme' => 'views_view_row_search',
'base' => array('node'), // only works with 'node' as base.
'type' => 'normal',
),
),
);
}
/**
* 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;
}
$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_get_types('name', $node);
$info['user'] = theme('username', $node);
$info['date'] = format_date($node->changed, 'small');
$extra = node_invoke_nodeapi($node, 'search result');
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,23 @@
<?php
/**
* @file
* Field conversion for fields handled by this module.
*/
function search_views_convert($display, $type, &$view, $field, $id = NULL) {
switch ($type) {
case 'filter':
switch ($field['tablename']) {
case 'temp_search_results':
switch ($field['field']) {
case 'word':
$view->set_item_option($display, 'filter', $id, 'table', 'search_index');
$view->set_item_option($display, 'filter', $id, 'field', 'keys');
break;
}
break;
}
break;
}
}

View file

@ -0,0 +1,149 @@
<?php
/**
* @file
* Contains default views on behalf of the search module.
*/
/**
* Implementation of hook_views_default_views().
*/
function search_views_default_views() {
$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->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => '',
'relationship' => 'none',
'link_to_node' => 1,
),
));
$handler->override_option('arguments', array(
'nid' => array(
'id' => 'nid',
'table' => 'search_node_links_to',
'field' => 'nid',
'default_action' => 'not found',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => TRUE,
'override' => FALSE,
'items_per_page' => 25,
),
'wildcard' => '',
'wildcard_substitution' => '',
'title' => 'Pages that link to %1',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'node',
'validate_fail' => 'not found',
'relationship' => 'none',
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(),
'validate_argument_php' => '',
),
));
$handler->override_option('filters', array(
'status' => array(
'id' => 'status',
'table' => 'node',
'field' => 'status',
'operator' => '=',
'value' => 1,
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access content',
));
$handler->override_option('empty', 'No backlinks found.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 30);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'type' => 'ol',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'node/%/backlinks');
$handler->override_option('menu', array(
'type' => 'tab',
'title' => 'What links here',
'weight' => '0',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('block', 'Block', 'block');
$handler->override_option('arguments', array(
'nid' => array(
'id' => 'nid',
'table' => 'search_node_links_to',
'field' => 'nid',
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => TRUE,
'override' => FALSE,
'items_per_page' => 25,
),
'wildcard' => '',
'wildcard_substitution' => '',
'title' => 'What links here',
'default_argument_type' => 'node',
'default_argument' => '',
'validate_type' => 'node',
'validate_fail' => 'not found',
'relationship' => 'none',
'default_argument_fixed' => '',
'default_argument_php' => 'return ($node = menu_get_object()) ? $node->nid : FALSE;',
'validate_argument_node_type' => array(
'album' => 0,
'artist' => 0,
'book' => 0,
'page' => 0,
'story' => 0,
'track' => 0,
),
'validate_argument_php' => '',
'default_argument_user' => 0,
'validate_argument_vocabulary' => array(
'3' => 0,
'4' => 0,
'1' => 0,
'5' => 0,
'2' => 0,
),
'validate_argument_type' => 'tid',
),
));
$handler->override_option('items_per_page', 6);
$handler->override_option('use_more', 1);
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'type' => 'ul',
));
$handler->override_option('block_description', 'What links here');
$views[$view->name] = $view;
return $views;
}

View file

@ -0,0 +1,81 @@
<?php
/**
* Field handler to provide simple renderer that allows linking to a node.
*/
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 click_sort($order) {
if (isset($this->table_alias)) {
$this->query->add_orderby(NULL, NULL, $order, $this->field_alias);
}
}
function render($values) {
// Only render if we exist.
if (isset($this->table_alias)) {
return parent::render($values);
}
}
}

View file

@ -0,0 +1,112 @@
<?php
/**
* Field handler to provide simple renderer that allows linking to a node.
*/
class views_handler_filter_search extends views_handler_filter {
var $no_single = TRUE;
function option_definition() {
$options = parent::option_definition();
$options['operator']['default'] = 'optional';
return $options;
}
/**
* 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 exposed_form(&$form, &$form_state) {
if (isset($this->options['expose']['identifier'])) {
$key = $this->options['expose']['identifier'];
$form[$key] = array(
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $this->value,
'#attributes' => array('title' => t('Enter the terms you wish to search for.')),
);
}
}
/**
* 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->search_query = search_parse_query($form_state['values'][$key]);
if ($this->search_query[2] == '') {
form_set_error($key, t('You must include at least one positive keyword with @count characters or more.', array('@count' => variable_get('minimum_word_size', 3))));
}
if ($this->search_query[6]) {
if ($this->search_query[6] == 'or') {
drupal_set_message(t('Search for either of the two terms with uppercase <strong>OR</strong>. For example, <strong>cats OR dogs</strong>.'));
}
}
}
}
/**
* 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() {
if (!isset($this->search_query) || empty($this->search_query[3])) {
if ($this->operator == 'required') {
$this->query->add_where($this->options['group'], 'FALSE');
}
}
else {
$search_index = $this->ensure_my_table();
$this->search_query[2] = str_replace('i.', "$search_index.", $this->search_query[2]);
// 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));
$this->query->add_where($this->options['group'], $this->search_query[2], $this->search_query[3]);
if (empty($this->query->relationships[$this->relationship])) {
$base_table = $this->query->base_table;
}
else {
$base_table = $this->query->relationships[$this->relationship]['base'];
}
$this->query->add_where($this->options['group'], "$search_index.type = '%s'", $base_table);
if (!$this->search_query[5]) {
$search_dataset = $this->query->add_table('search_dataset');
$this->search_query[0] = str_replace('d.', "$search_dataset.", $this->search_query[0]);
$this->query->add_where($this->options['group'], $this->search_query[0], $this->search_query[1]);
}
$this->query->add_groupby("$search_index.sid");
$this->query->add_having($this->options['group'], 'COUNT(*) >= %d', $this->search_query[4]);
}
}
}

View file

@ -0,0 +1,24 @@
<?php
/**
* Field handler to provide simple renderer that allows linking to a node.
*/
class views_handler_sort_search_score extends views_handler_sort {
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->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 in place; there is no reason to
// sort on the raw scores with this handler.
}
}

View file

@ -0,0 +1,33 @@
<?php
/**
* @file
* Contains the search row style plugin.
*/
/**
* 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);
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(), $this->view, $this->options, $row);
}
}

View file

@ -0,0 +1,267 @@
<?php
/**
* @file
* Provide views data and handlers for statistics.module
*/
/**
* @defgroup views_statistics_module statistics.module handlers
*
* Includes the ability to create views of just the statistics table.
* @{
*/
/**
* Implementation of hook_views_data()
*/
function statistics_views_data() {
// Basic table information.
// ----------------------------------------------------------------
// node_counter table
$data['node_counter']['table']['group'] = t('Node statistics');
$data['node_counter']['table']['join'] = array(
// ...to the node table
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
// totalcount
$data['node_counter']['totalcount'] = array(
'title' => t('Total views'),
'help' => t('The total number of times the node has been viewed.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// daycount
$data['node_counter']['daycount'] = array(
'title' => t('Views today'),
'help' => t('The total number of times the node has been viewed today.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// timestamp
$data['node_counter']['timestamp'] = array(
'title' => t('Most recent view'),
'help' => t('The most recent time the node has been viewed.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// ----------------------------------------------------------------
// accesslog table
$data['accesslog']['table']['group'] = t('Access log');
// Advertise this table as a possible base table
$data['accesslog']['table']['base'] = array(
'field' => 'aid',
'title' => t('Access log'),
'help' => t('Stores site access information.'),
'weight' => 10,
);
// For other base tables, explain how we join
$data['accesslog']['table']['join'] = array(
'users' => array(
'field' => 'uid',
'left_field' => 'uid',
),
);
// session id
$data['accesslog']['sid'] = array(
'title' => t('Session ID'),
'help' => t('Browser session ID of user that visited page.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// title
$data['accesslog']['title'] = array(
'title' => t('Page title'),
'help' => t('Title of page visited.'),
'field' => array(
'handler' => 'views_handler_field_accesslog_path',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// path
$data['accesslog']['path'] = array(
'title' => t('Path'),
'help' => t('Internal path to page visited (relative to Drupal root.)'),
'field' => array(
'handler' => 'views_handler_field_accesslog_path',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
//No argument here. Can't send forward slashes as arguments.
//Can be worked around by node ID.
//(but what about aliases?)
);
// referrer
$data['accesslog']['url'] = array(
'title' => t('Referrer'),
'help' => t('Referrer URI.'),
'field' => array(
'handler' => 'views_handler_field_url',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// hostname
$data['accesslog']['hostname'] = array(
'title' => t('Hostname'),
'help' => t('Hostname of user that visited the page.'),
'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',
),
);
// user
$data['accesslog']['uid'] = array(
'title' => t('User'),
'help' => t('The user who visited the site.'),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'users',
'base field' => 'uid',
),
);
// timer
$data['accesslog']['timer'] = array(
'title' => t('Timer'),
'help' => t('Time in milliseconds that the page took to load.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// timestamp
$data['accesslog']['timestamp'] = array(
'title' => t('Timestamp'),
'help' => t('Timestamp of when the page was visited.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function statistics_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/statistics',
),
'handlers' => array(
'views_handler_field_accesslog_path' => array(
'parent' => 'views_handler_field',
),
),
);
}
/**
* @}
*/

View file

@ -0,0 +1,51 @@
<?php
/**
* @file
* Field conversion for fields handled by this module.
*/
/**
* Implementation of hook_views_convert().
*
* Intervene to convert field values from the Views 1 format to the
* Views 2 format. Intervene only if $view->add_item() won't produce
* the right results, usually needed to set field options or values.
*/
function statistics_views_convert($display, $type, &$view, $field, $id = NULL) {
switch ($type) {
case 'field':
switch ($field['tablename']) {
case 'node_counter':
switch ($field['field']) {
case 'timestamp':
$handlers = array(
'views_handler_field_date_small' => 'small',
'views_handler_field_date' => 'medium',
'views_handler_field_date_large' => 'large',
'views_handler_field_date_custom' => 'custom',
'views_handler_field_since' => 'time ago',
);
$view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
if (!empty($field['options'])) {
$view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
}
break;
}
break;
}
break;
case 'sort':
switch ($field['tablename']) {
case 'node_counter':
switch ($field['field']) {
case 'timestamp':
$field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
$view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
break;
}
break;
}
break;
}
}

View file

@ -0,0 +1,302 @@
<?php
/**
* @file
* Contains default views on behalf of the statistics module.
*/
/**
* Implementation of hook_views_default_views().
*/
function statistics_views_default_views() {
$view = new view;
$view->name = 'popular';
$view->description = 'Shows the most-viewed nodes on the site. This requires the statistics to be enabled at administer >> reports >> access log settings.';
$view->tag = 'default';
$view->base_table = 'node';
$view->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'type' => array(
'id' => 'type',
'table' => 'node',
'field' => 'type',
'label' => 'Type',
),
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => 'Title',
'link_to_node' => TRUE,
),
'name' => array(
'id' => 'name',
'table' => 'users',
'field' => 'name',
'label' => 'Author',
'link_to_user' => TRUE,
),
'timestamp' => array(
'id' => 'timestamp',
'table' => 'history_user',
'field' => 'timestamp',
'label' => '',
'comments' => 1,
'relationship' => 'none',
'link_to_node' => 0,
'comment' => 1,
),
));
$handler->override_option('sorts', array(
'totalcount' => array(
'id' => 'totalcount',
'table' => 'node_counter',
'field' => 'totalcount',
'order' => 'DESC',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status' => array(
'id' => 'status',
'table' => 'node',
'field' => 'status',
'operator' => '=',
'value' => '1',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
),
'totalcount' => array(
'id' => 'totalcount',
'table' => 'node_counter',
'field' => 'totalcount',
'operator' => '>',
'value' => array(
'value' => '0',
'min' => '',
'max' => '',
),
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access content',
));
$handler->override_option('title', 'Popular content');
$handler->override_option('items_per_page', '25');
$handler->override_option('use_pager', TRUE);
$handler->override_option('use_more', 1);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'override' => 0,
'order' => 'desc',
'columns' => array(
'type' => 'type',
'title' => 'title',
'name' => 'name',
'timestamp' => 'title',
'totalcount' => 'totalcount',
),
'info' => array(
'type' => array(
'sortable' => 0,
'separator' => '',
),
'title' => array(
'sortable' => 0,
'separator' => '',
),
'name' => array(
'sortable' => 0,
'separator' => '',
),
'timestamp' => array(
'separator' => '',
),
'totalcount' => array(
'sortable' => 0,
'separator' => '',
),
),
'default' => '-1',
));
$handler = $view->new_display('page', 'Popular (page)', 'page');
$handler->override_option('path', 'popular/all');
$handler->override_option('menu', array(
'type' => 'default tab',
'title' => 'Popular content',
'weight' => '-1',
));
$handler->override_option('tab_options', array(
'type' => 'normal',
'title' => 'Popular content',
'weight' => '',
));
$handler = $view->new_display('page', 'Today (page)', 'page_1');
$handler->override_option('fields', array(
'type' => array(
'id' => 'type',
'table' => 'node',
'field' => 'type',
'label' => 'Type',
),
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => 'Title',
'link_to_node' => TRUE,
),
'name' => array(
'id' => 'name',
'table' => 'users',
'field' => 'name',
'label' => 'Author',
'link_to_user' => TRUE,
),
'timestamp' => array(
'id' => 'timestamp',
'table' => 'history_user',
'field' => 'timestamp',
'label' => '',
'comments' => 1,
'relationship' => 'none',
'link_to_node' => 0,
'comment' => 1,
),
'daycount' => array(
'id' => 'daycount',
'table' => 'node_counter',
'field' => 'daycount',
'label' => 'Views today',
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => '',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'daycount' => array(
'id' => 'daycount',
'table' => 'node_counter',
'field' => 'daycount',
'order' => 'DESC',
'relationship' => 'none',
),
));
$handler->override_option('path', 'popular/today');
$handler->override_option('menu', array(
'type' => 'tab',
'title' => 'Today\'s popular content',
'weight' => '0',
));
$handler->override_option('tab_options', array(
'type' => 'normal',
'title' => 'Popular content',
'weight' => '0',
));
$handler = $view->new_display('block', 'Popular (block)', 'block');
$handler->override_option('fields', array(
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => '',
'link_to_node' => 1,
'relationship' => 'none',
),
'totalcount' => array(
'id' => 'totalcount',
'table' => 'node_counter',
'field' => 'totalcount',
'label' => '',
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => ' (',
'suffix' => ')',
'relationship' => 'none',
),
));
$handler->override_option('items_per_page', 5);
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'type' => 'ul',
));
$handler->override_option('row_options', array(
'inline' => array(
'title' => 'title',
'totalcount' => 'totalcount',
),
'separator' => '',
));
$handler->override_option('block_description', 'Popular content');
$handler = $view->new_display('block', 'Today (block)', 'block_1');
$handler->override_option('fields', array(
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => '',
'link_to_node' => 1,
'relationship' => 'none',
),
'daycount' => array(
'id' => 'daycount',
'table' => 'node_counter',
'field' => 'daycount',
'label' => '',
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => ' (',
'suffix' => ')',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'daycount' => array(
'id' => 'daycount',
'table' => 'node_counter',
'field' => 'daycount',
'order' => 'DESC',
'relationship' => 'none',
),
));
$handler->override_option('title', 'Today\'s popular content');
$handler->override_option('items_per_page', 5);
$handler->override_option('link_display', 'page_1');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'type' => 'ul',
));
$handler->override_option('row_options', array(
'inline' => array(
'title' => 'title',
'daycount' => 'daycount',
),
'separator' => '',
));
$handler->override_option('block_description', 'Today\'s popular content');
$views[$view->name] = $view;
return $views;
}

View file

@ -0,0 +1,45 @@
<?php
/**
* Field handler to provide simple renderer that turns a URL into a clickable link.
*/
class views_handler_field_accesslog_path extends views_handler_field {
/**
* Override init function to provide generic option to link to node.
*/
function init(&$view, $options) {
parent::init($view, $options);
if (!empty($this->options['display_as_link'])) {
$this->additional_fields['path'] = 'path';
}
}
function option_definition() {
$options = parent::option_definition();
$options['display_as_link'] = array('default' => TRUE);
return $options;
}
/**
* Provide link to the page being visited.
*/
function options_form(&$form, &$form_state) {
parent::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']),
);
}
function render($values) {
$title = check_plain($values->{$this->field_alias});
if (!empty($this->options['display_as_link'])) {
return l($title, $values->{$this->aliases['path']}, array('html' => TRUE));
}
else {
return $title;
}
}
}

View file

@ -0,0 +1,229 @@
<?php
/**
* @file
*
* Provide views data and handlers for system tables that are not represented by
* their own module.
*/
/**
* @defgroup views_system_module system.module handlers
*
* @{
*/
/**
* Implementation of hook_views_data()
*/
function system_views_data() {
$data = array();
// ----------------------------------------------------------------------
// files table
$data['files']['table']['group'] = t('File');
// Advertise this table as a possible base table
$data['files']['table']['base'] = array(
'field' => 'fid',
'title' => t('File'),
'help' => t("Files maintained by Drupal and various modules."),
);
// The files table does not inherently join to the node table,
// but may things (such as upload.module) can add relationships
// that allow file fields to be used.
// For other base tables, explain how we join
$data['files']['table']['join'] = array(
'users' => array(
// direct join to the users table via 'uid' field.
'left_field' => 'uid',
'field' => 'uid',
),
);
// fid
$data['files']['fid'] = array(
'title' => t('File ID'),
'help' => t('The ID of the file.'),
'field' => array(
'handler' => 'views_handler_field_file',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_file_fid',
'name field' => 'filename', // the field to display in the summary.
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// filename
$data['files']['filename'] = array(
'title' => t('Name'),
'help' => t('The name of the file.'),
'field' => array(
'handler' => 'views_handler_field_file',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// filepath
$data['files']['filepath'] = array(
'title' => t('Path'),
'help' => t('The path of the file.'),
'field' => array(
'handler' => 'views_handler_field_file',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// filemime
$data['files']['filemime'] = array(
'title' => t('Mime type'),
'help' => t('The mime type of the file.'),
'field' => array(
'handler' => 'views_handler_field_file',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// filesize
$data['files']['filesize'] = array(
'title' => t('Size'),
'help' => t('The size of the file.'),
'field' => array(
'handler' => 'views_handler_field_file_size',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
// status
$data['files']['status'] = array(
'title' => t('Status'),
'help' => t('The status of the file.'),
'field' => array(
'handler' => 'views_handler_field_file_status',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_file_status',
),
);
// timestamp field
$data['files']['timestamp'] = array(
'title' => t('Upload date'),
'help' => t('The date the file was uploaded.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// uid field
$data['files']['uid'] = array(
'title' => t('User'),
'help' => t('The user, who uploaded the file.'),
'relationship' => array(
'base' => 'users',
'base field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('User'),
),
);
return $data;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function system_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/system',
),
'handlers' => array(
'views_handler_field_file' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_file_status' => array(
'parent' => 'views_handler_field',
),
'views_handler_filter_file_status' => array(
'parent' => 'views_handler_filter_in_operator',
),
'views_handler_argument_file_fid' => array(
'parent' => 'views_handler_argument',
),
),
);
}
function _views_file_status($choice = NULL) {
$status = array(
FILE_STATUS_TEMPORARY => t('Temporary'),
FILE_STATUS_PERMANENT => t('Permanent'),
);
if (isset($choice)) {
return isset($status[$choice]) ? $status[$choice] : t('Unknown');
}
return $status;
}
/**
* @}
*/

View file

@ -0,0 +1,17 @@
<?php
/**
* Argument handler to accept a file id.
*/
class views_handler_argument_file_fid extends views_handler_argument {
/**
* Override the behavior of title(). Get the title of the file.
*/
function title() {
$title = db_result(db_query(db_rewrite_sql("SELECT f.filename FROM {files} f WHERE f.fid = %d", $this->argument)));
if (empty($title)) {
return t('No title');
}
return check_plain($title);
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* Field handler to provide simple renderer that allows linking to a file.
*/
class views_handler_field_file extends views_handler_field {
/**
* Constructor to provide additional field to add.
*/
function init(&$view, &$options) {
parent::init($view, $options);
if (!empty($options['link_to_file'])) {
$this->additional_fields['filepath'] = 'filepath';
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_file'] = array('default' => FALSE);
return $options;
}
/**
* Provide link to file option
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_file'] = array(
'#title' => t('Link this field to download the file'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_file']),
);
}
/**
* Render whatever the data is as a link to the file.
*
* Data should be made XSS safe prior to calling this function.
*/
function render_link($data, $values) {
if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = file_create_url($values->{$this->aliases['filepath']});
}
return $data;
}
function render($values) {
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
}
}

View file

@ -0,0 +1,10 @@
<?php
/**
* Field handler to translate a node type into its readable form.
*/
class views_handler_field_file_status extends views_handler_field {
function render($values) {
return _views_file_status($values->{$this->field_alias});
}
}

View file

@ -0,0 +1,12 @@
<?php
/**
* Filter by file status
*/
class views_handler_filter_file_status extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_options = _views_file_status();
}
}
}

View file

@ -0,0 +1,499 @@
<?php
/**
* @file
*
* Provide views data and handlers for taxonomy.module
*/
/**
* @defgroup views_taxonomy_module taxonomy.module handlers
*
* @{
*/
/**
* Implementation of hook_views_data()
*/
function taxonomy_views_data() {
$data = array();
// ----------------------------------------------------------------------
// vocabulary table
$data['vocabulary']['table']['group'] = t('Taxonomy');
$data['vocabulary']['table']['join'] = array(
// vocabulary links to term_data directly via vid.
'term_data' => array(
'left_field' => 'vid',
'field' => 'vid',
),
// vocabulary links to node through term_data via vid
'node' => array(
'left_table' => 'term_data',
'left_field' => 'vid',
'field' => 'vid',
),
// vocabulary links to node_revision via term_data
'node_revision' => array(
'left_table' => 'term_data',
'left_field' => 'vid',
'field' => 'vid',
),
);
// vocabulary name
$data['vocabulary']['name'] = array(
'title' => t('Vocabulary name'), // The item it appears as on the UI,
'field' => array(
'help' => t('Name of the vocabulary a term is a member of. This will be the vocabulary that whichever term the "Taxonomy: Term" field is; and can similarly cause duplicates.'),
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
);
$data['vocabulary']['vid'] = array(
'title' => t('Vocabulary ID'), // The item it appears as on the UI,
'help' => t('The taxonomy vocabulary ID'),
'argument' => array(
'handler' => 'views_handler_argument_vocabulary_vid',
'name field' => 'name',
),
);
// ----------------------------------------------------------------------
// term_data table
$data['term_data']['table']['group'] = t('Taxonomy');
$data['term_data']['table']['base'] = array(
'field' => 'tid',
'title' => t('Term'),
'help' => t('Taxonomy terms are attached to nodes.'),
);
// The term data table
$data['term_data']['table']['join'] = array(
'node' => array(
'left_table' => 'term_node',
'left_field' => 'tid',
'field' => 'tid',
),
'node_revision' => array(
'left_table' => 'term_node',
'left_field' => 'tid',
'field' => 'tid',
),
// This is provided for many_to_one argument
'term_node' => array(
'field' => 'tid',
'left_field' => 'tid',
),
);
// tid field
$data['term_data']['tid'] = array(
'title' => t('Term ID'),
'help' => t('The taxonomy term ID'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
'name field' => 'name',
'skip base' => array('node', 'node_revision'),
'zero is null' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_term_node_tid',
'hierarchy table' => 'term_hierarchy',
'numeric' => TRUE,
'skip base' => array('node', 'node_revision'),
),
);
// Term name field
$data['term_data']['name'] = array(
'title' => t('Term'),
'help' => t('Taxonomy terms. Note that using this can cause duplicate nodes to appear in views; you must add filters to reduce the result set.'),
'field' => array(
'handler' => 'views_handler_field_taxonomy',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
'help' => t('Taxonomy term name.'),
),
'argument' => array(
'handler' => 'views_handler_argument_string',
'help' => t('Taxonomy term name.'),
'many to one' => TRUE,
'empty field name' => t('Uncategorized'),
),
);
// taxonomy weight
$data['term_data']['weight'] = array(
'title' => t('Weight'),
'help' => t('The term weight field'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// Term description
$data['term_data']['description'] = array(
'title' => t('Term description'), // The item it appears as on the UI,
'help' => t('The description associated with a taxonomy term.'),
'field' => array(
'field' => 'description', // the real field
'group' => t('Taxonomy'), // The group it appears in on the UI,
'handler' => 'views_handler_field_markup',
'format' => FILTER_FORMAT_DEFAULT,
),
);
// Term vocabulary
$data['term_data']['vid'] = array(
'title' => t('Vocabulary'),
'help' => t('Filter the results of "Taxonomy: Term" to a particular vocabulary.'),
'filter' => array(
'handler' => 'views_handler_filter_vocabulary_vid',
),
);
// ----------------------------------------------------------------------
// term_node table
$data['term_node']['table']['group'] = t('Taxonomy');
$data['term_node']['table']['join'] = array(
'term_data' => array(
// links directly to term_data via tid
'left_field' => 'tid',
'field' => 'tid',
),
'node' => array(
// links directly to node via vid
'left_field' => 'vid',
'field' => 'vid',
),
'node_revisions' => array(
// links directly to node_revisions via vid
'left_field' => 'vid',
'field' => 'vid',
),
'term_hierarchy' => array(
'left_field' => 'tid',
'field' => 'tid',
),
);
$data['term_node']['vid'] = array(
'title' => t('Node'),
'help' => t('Get all nodes tagged with a term.'),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'node',
'base field' => 'vid',
'label' => t('node'),
),
);
// tid field
$data['term_node']['tid'] = array(
'title' => t('Term ID'),
'help' => t('The taxonomy term ID'),
'field' => array(
'title' => t('All terms'),
'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'),
'handler' => 'views_handler_field_term_node_tid',
'skip base' => 'term_data',
),
'argument' => array(
'handler' => 'views_handler_argument_term_node_tid',
'name table' => 'term_data',
'name field' => 'name',
'empty field name' => t('Uncategorized'),
'numeric' => TRUE,
'skip base' => 'term_data',
),
'filter' => array(
'title' => t('Term'),
'handler' => 'views_handler_filter_term_node_tid',
'hierarchy table' => 'term_hierarchy',
'numeric' => TRUE,
'skip base' => 'term_data',
'allow empty' => TRUE,
),
);
// term_relation
$data['term_relation']['table']['group'] = t('Taxonomy');
$data['term_relation']['table']['join'] = array(
'term_data' => array(
// links directly to term_data via tid
'left_field' => 'tid',
'field' => 'tid1',
),
'term_relation' => array(
// links to self through left.tid1 = right.tid2
'left_field' => 'tid1',
'field' => 'tid2',
),
'node' => array(
'left_table' => 'term_node',
'left_field' => 'tid',
'field' => 'tid1',
),
'node_revisions' => array(
'left_table' => 'term_node',
'left_field' => 'tid',
'field' => 'tid1',
),
);
$data['term_relation']['tid2'] = array(
'title' => t('Related terms'),
'help' => t('The related terms of the term. This can produce duplicate entries if there is more than one related term.'),
'relationship' => array(
'base' => 'term_data',
'field' => 'tid2',
'label' => t('Related term'),
),
'argument' => array(
'help' => t('A related term of the term.'),
'handler' => 'views_handler_argument_numeric',
),
);
// ----------------------------------------------------------------------
// term_hierarchy table
$data['term_hierarchy']['table']['group'] = t('Taxonomy');
$data['term_hierarchy']['table']['join'] = array(
'term_hierarchy' => array(
// links to self through left.parent = right.tid (going down in depth)
'left_field' => 'tid',
'field' => 'parent',
),
'term_data' => array(
// links directly to term_data via tid
'left_field' => 'tid',
'field' => 'tid',
),
'node' => array(
// links to node thorugh term_data
'left_table' => 'term_data',
'left_field' => 'tid',
'field' => 'tid',
),
'node_revisions' => array(
// links to node_revisions thorugh term_data
'left_table' => 'term_data',
'left_field' => 'tid',
'field' => 'tid',
),
);
$data['term_hierarchy']['parent'] = array(
'title' => t('Parent term'),
'help' => t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'),
'relationship' => array(
'base' => 'term_data',
'field' => 'parent',
'label' => t('Parent'),
),
'argument' => array(
'help' => t('The parent term of the term.'),
'handler' => 'views_handler_argument_numeric',
),
);
// ----------------------------------------------------------------------
// term_synonym table
$data['term_synonym']['table']['group'] = t('Taxonomy');
$data['term_synonym']['table']['join'] = array(
'term_data' => array(
// links directly to term_data via tid
'left_field' => 'tid',
'field' => 'tid',
),
'node' => array(
'left_table' => 'term_node',
'left_field' => 'tid',
'field' => 'tid',
),
'node_revisions' => array(
'left_table' => 'term_node',
'left_field' => 'tid',
'field' => 'tid',
),
);
$data['term_synonym']['name'] = array(
'title' => t('Term synonym'),
'help' => t('Term synonyms may be used to find terms by alternate names.'),
'argument' => array(
'handler' => 'views_handler_argument_string',
'many to one' => TRUE,
'empty field name' => t('Uncategorized'),
),
);
return $data;
}
/**
* Implementation of hook_views_data_alter().
*/
function taxonomy_views_data_alter(&$data) {
$data['node']['term_node_tid'] = array(
'group' => t('Taxonomy'),
'title' => t('Terms on node'),
'help' => t('Relate nodes to taxonomy terms, specifiying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.'),
'relationship' => array(
'handler' => 'views_handler_relationship_node_term_data',
'label' => t('term'),
'base' => 'term_data',
),
);
$data['node']['term_node_tid_depth'] = array(
'group' => t('Taxonomy'),
'title' => t('Term ID (with depth)'),
'help' => t('The depth filter is more complex, so provides fewer options.'),
'real field' => 'vid',
'argument' => array(
'handler' => 'views_handler_argument_term_node_tid_depth',
'accept depth modifier' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_term_node_tid_depth',
),
);
$data['node']['term_node_tid_depth_modifier'] = array(
'group' => t('Taxonomy'),
'title' => t('Term ID depth modifier'),
'help' => t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional argument.'),
'argument' => array(
'handler' => 'views_handler_argument_term_node_tid_depth_modifier',
),
);
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function taxonomy_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
),
'handlers' => array(
'views_handler_argument_term_node_tid_depth' => array(
'parent' => 'views_handler_argument',
),
'views_handler_argument_term_node_tid_depth_modifier' => array(
'parent' => 'views_handler_argument',
),
'views_handler_argument_taxonomy' => array(
'parent' => 'views_handler_argument',
),
'views_handler_argument_vocabulary_vid' => array(
'parent' => 'views_handler_argument',
),
'views_handler_argument_term_node_tid' => array(
'parent' => 'views_handler_argument_many_to_one',
),
'views_handler_field_term_node_tid' => array(
'parent' => 'views_handler_field_prerender_list',
),
'views_handler_field_taxonomy' => array(
'parent' => 'views_handler_field',
),
'views_handler_filter_vocabulary_vid' => array(
'parent' => 'views_handler_filter_in_operator',
),
'views_handler_filter_term_node_tid' => array(
'parent' => 'views_handler_filter_many_to_one',
),
'views_handler_filter_term_node_tid_depth' => array(
'parent' => 'views_handler_filter_term_node_tid',
),
'views_handler_relationship_node_term_data' => array(
'parent' => 'views_handler_relationship',
),
),
);
}
/**
* Implementation of hook_views_plugins
*/
function taxonomy_views_plugins() {
return array(
'module' => 'views', // This just tells our themes are elsewhere.
'argument validator' => array(
'taxonomy_term' => array(
'title' => t('Taxonomy term'),
'handler' => 'views_plugin_argument_validate_taxonomy_term',
'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
),
),
'argument default' => array(
'taxonomy_tid' => array(
'title' => t('Taxonomy Term ID from URL'),
'handler' => 'views_plugin_argument_default_taxonomy_tid',
'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
'parent' => 'fixed',
),
),
);
}
/**
* Helper function to set a breadcrumb for taxonomy.
*/
function views_taxonomy_set_breadcrumb(&$breadcrumb, &$argument) {
if (empty($argument->options['set_breadcrumb'])) {
return;
}
$args = $argument->view->args;
$parents = taxonomy_get_parents_all($argument->argument);
foreach (array_reverse($parents) as $parent) {
// Unfortunately parents includes the current argument. Skip.
if ($parent->tid == $argument->argument) {
continue;
}
if ($argument->options['use_taxonomy_term_path']) {
$path = taxonomy_term_path($parent);
}
else {
$args[$argument->position] = $parent->tid;
$path = $argument->view->get_url($args);
}
$breadcrumb[$path] = check_plain($parent->name);
}
}
/**
* @}
*/

View file

@ -0,0 +1,102 @@
<?php
/**
* @file
* Field conversion for fields handled by this module.
*/
/**
* Implementation of hook_views_convert().
*
* Intervene to convert field values from the Views 1 format to the
* Views 2 format. Intervene only if $view->add_item() won't produce
* the right results, usually needed to set field options or values.
*/
function taxonomy_views_convert($display, $type, &$view, $field, $id = NULL) {
switch ($type) {
case 'field':
$matches = array();
if (preg_match('/term_node(_(\d+))?/', $field['tablename'], $matches)) {
switch ($field['field']) {
case 'name':
$item = $view->get_item($display, 'field', $id);
$item['table'] = 'term_node';
$item['field'] = 'tid';
if ($field['options'] != 'nolink') {
$item['link_to_taxonomy'] = TRUE;
}
if (!empty($field['vocabulary'])) {
$item['limit'] = TRUE;
$item['vids'] = array($field['vocabulary']);
}
// The vocabulary ID might be embedded in the table name.
elseif (!empty($matches[2])) {
$item['limit'] = TRUE;
$item['vids'] = array($matches[2]);
}
$view->set_item($display, 'field', $id, $item);
break;
}
}
elseif ($field['tablename'] == 'term_data') {
switch ($field['field']) {
case 'name':
if ($field['field'] == 'views_handler_field_tid_link') {
$view->set_item_option($display, 'field', $id, 'link_to_taxonomy', TRUE);
}
break;
}
}
break;
case 'filter':
if ($field['tablename'] == 'term_node' || !strncmp($field['tablename'], 'term_node_', 10)) {
switch ($field['field']) {
case 'tid':
$operators = array('AND' => 'and', 'OR' => 'or', 'NOR' => 'not');
$item = $view->get_item($display, 'filter', $id);
if ($vid = (integer) substr($field['tablename'], 10)) {
$item['table'] = 'term_node';
$item['vid'] = $vid;
}
else {
$item['limit'] = FALSE;
}
$item['operator'] = $operators[$field['operator']];
$item['type'] = 'select';
$view->set_item($display, 'filter', $id, $item);
break;
}
}
elseif ($field['tablename'] == 'term_data') {
switch ($field['field']) {
case 'vid':
$operators = array('AND' => 'in', 'OR' => 'in', 'NOR' => 'not in');
$view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]);
break;
}
}
break;
case 'argument':
$options = $field['argoptions'];
switch ($field['type']) {
case 'taxid':
if (!empty($field['options'])) {
$options['depth'] = $field['options'];
}
$options['break_phrase'] = TRUE;
$view->add_item($display, 'argument', 'node', 'term_node_tid_depth', $options, $field['id']);
break;
case 'taxletter':
if (!empty($field['options'])) {
$options['glossary'] = TRUE;
$options['limit'] = $field['options'];
}
$view->add_item($display, 'argument', 'term_data', 'name', $options, $field['id']);
break;
case 'vocid':
$view->add_item($display, 'argument', 'vocabulary', 'vid', $options, $field['id']);
break;
}
break;
}
}

View file

@ -0,0 +1,182 @@
<?php
/**
* @file
* Contains default views on behalf of the statistics module.
*/
/**
* Implementation of hook_views_default_views().
*/
function taxonomy_views_default_views() {
$view = new view;
$view->name = 'taxonomy_term';
$view->description = 'A view to emulate Drupal core\'s handling of taxonomy/term; it also emulates Views 1\'s handling by having two possible feeds.';
$view->tag = 'default';
$view->base_table = 'node';
$view->api_version = 2;
$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('sorts', array(
'sticky' => array(
'id' => 'sticky',
'table' => 'node',
'field' => 'sticky',
'order' => 'DESC',
'relationship' => 'none',
),
'created' => array(
'id' => 'created',
'table' => 'node',
'field' => 'created',
'order' => 'DESC',
'granularity' => 'second',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'term_node_tid_depth' => array(
'id' => 'term_node_tid_depth',
'table' => 'node',
'field' => 'term_node_tid_depth',
'default_action' => 'not found',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => TRUE,
'override' => FALSE,
'items_per_page' => 25,
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '%1',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'taxonomy_term',
'validate_fail' => 'not found',
'depth' => '0',
'break_phrase' => 1,
'relationship' => 'none',
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'album' => 0,
'artist' => 0,
'book' => 0,
'page' => 0,
'story' => 0,
'track' => 0,
),
'validate_argument_vocabulary' => array(
'3' => 0,
'4' => 0,
'1' => 0,
'5' => 0,
'2' => 0,
),
'validate_argument_type' => 'tids',
'validate_argument_php' => '',
),
'term_node_tid_depth_modifier' => array(
'id' => 'term_node_tid_depth_modifier',
'table' => 'node',
'field' => 'term_node_tid_depth_modifier',
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => TRUE,
'override' => FALSE,
'items_per_page' => 25,
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
),
));
$handler->override_option('filters', array(
'status_extra' => array(
'id' => 'status_extra',
'table' => 'node',
'field' => 'status_extra',
'operator' => '=',
'value' => '',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'perm',
'role' => array(),
'perm' => 'access content',
));
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'teaser' => TRUE,
'links' => TRUE,
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'taxonomy/term/%');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('feed', 'Core feed', 'feed');
$handler->override_option('items_per_page', 15);
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node_rss');
$handler->override_option('row_options', array(
'item_length' => 'default',
));
$handler->override_option('path', 'taxonomy/term/%/%/feed');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('displays', array(
'page' => 'page',
'default' => 0,
));
$handler = $view->new_display('feed', 'Views 1 feed', 'feed_1');
$handler->override_option('items_per_page', 15);
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node_rss');
$handler->override_option('row_options', array(
'item_length' => 'default',
));
$handler->override_option('path', 'taxonomy/term/%/feed');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$views[$view->name] = $view;
return $views;
}

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