Commit 3db30616 authored by merlinofchaos's avatar merlinofchaos

Refactored code; moved views_ui into its own module. Be sure to activate views_ui.module!

parent 802fe908
......@@ -16,6 +16,7 @@ INSTALLING VIEWS
In 4.7, Views can be installed simply by activating the module, thanks to the
new module installation features.
Please note that this is now TWO modules -- views.module and views_ui.module
DOCUMENTATION
Documentation is now available at http://drupal.org/handbook/modules/views.
......
<?php
// $Id$
/**
* This include file implements views functionality on behalf of book.module
*/
function book_views_tables() {
$tables['book'] = array(
'name' => 'book',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
)
),
"filters" => array(
'parent' => array(
'name' => t('Book: Parent Node'),
'list' => 'views_handler_filter_book_parent_zero',
'operator' => 'views_handler_operator_andor',
'help' => t('This allows you to filter books based on parent node.'),
),
),
'sorts' => array(
'weight' => array(
'name' => t('Book: Weight'),
'handler' => 'views_handler_sort_book_weight',
'help' => t('This will sort the view by book weight, if that is applicable.'),
),
),
);
$tables['book_parent_node'] = array(
'name' => 'node',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
)
),
'fields' => array(
'title' => array(
'name' => t('Book: Parent Title'),
'handler' => array(
'views_handler_field_book_parent_title' => t('As Link'),
'views_handler_field_book_parent_title_nl' => t('Without Link'),
),
'addlfields' => array('nid'),
'help' => t('Display the title of the parent node'),
),
),
);
return $tables;
}
function book_views_arguments() {
$arguments = array(
'book_parent' => array(
'name' => t("Book: Parent Node ID"),
'handler' => "views_handler_arg_book_parent",
),
);
return $arguments;
}
function book_views_default_views() {
}
function views_handler_arg_book_parent($op, & $query, $argtype, $arg = '') {
switch ($op)
{
case 'summary' :
$query->ensure_table("book");
$query->add_field("parent", "book");
$query->add_field("title", "node");
$query->add_field("nid");
$fieldinfo['field'] = "book.parent";
return $fieldinfo;
break;
case 'sort':
$query->add_orderby('book', 'weight', $argtype);
$query->add_orderby('node', 'title', $argtype);
break;
case 'filter' :
$query->ensure_table("book");
$query->add_where("book.parent = '$arg'");
$query->add_where("book.vid = node.vid");
break;
case 'link' :
return l($query->title, "$arg/$query->nid");
case 'title' :
if ($query)
{
$term = db_fetch_object(db_query("SELECT title FROM {node} WHERE nid = '%d'", $query));
return $term->title;
}
}
}
/*
* Format a field as a link to the book parent node
*/
function views_handler_field_book_parent_title($fieldinfo, $fielddata, $value, $data) {
return l($value, "node/$data->book_parent_node_nid");
}
function views_handler_field_book_parent_title_nl($fieldinfo, $fielddata, $value, $data) {
return check_plain($value);
}
function views_handler_filter_book_parent_zero() {
$parents = array();
$result = db_query("SELECT DISTINCT parent FROM {book} ORDER BY parent");
while ($obj = db_fetch_object($result)) {
$parents[$obj->parent] = "$obj->parent";
}
return $parents;
}
<?php
// $Id$
/**
* This include file implements views functionality on behalf of comment.module
*/
function comment_views_tables() {
$tables['comments'] = array(
'name' => 'comments',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
),
);
$tables['node_comment_statistics'] = array(
'name' => 'node_comment_statistics',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
),
'fields' => array(
'last_comment_timestamp' => array(
'name' => t('Comment: Last Comment Time'),
'sortable' => true,
'handler' => array(
'views_handler_field_date_small' => t('As Short Date'),
'views_handler_field_date' => t('As Medium Date'),
'views_handler_field_date_large' => t('As Long Date'),
'views_handler_field_since' => t('As Time Ago')
),
'help' => t('This will display the last comment time.'),
),
'last_comment_name' => array(
'name' => t('Comment: Last Comment Author'),
'handler' => 'views_handler_field_username',
'sortable' => true,
'uid' => 'last_comment_uid',
'addlfields' => array('last_comment_uid'),
'help' => t('This will display the name of the last user to comment on the post.'),
),
'comment_count' => array(
'name' => t('Comment: Count'),
'sortable' => true,
'handler' => array(
'views_handler_field_int' => t('Normal'),
'views_handler_comments_with_new' => t('With New Count')
),
'help' => t('This will display the comment count.'),
),
),
'sorts' => array(
'last_comment_timestamp' => array(
'name' => t('Comment: Last Comment Date'),
'help' => t('This will allow you to sort by the date of the most recent comment on a node.')
)
)
);
return $tables;
}
/*
function comment_views_arguments() {
}
function comment_views_default_views() {
}
*/
This diff is collapsed.
<?php
// $Id$
/**
* This include file implements views functionality on behalf of profile.module
*/
function profile_views_tables() {
}
function profile_views_arguments() {
}
function profile_views_default_views() {
}
<?php
// $Id$
/**
* This include file implements views functionality on behalf of statistics.module
*/
function statistics_views_tables() {
}
function statistics_views_arguments() {
}
function statistics_views_default_views() {
}
This diff is collapsed.
<?php
// $Id$
/**
* This include file implements views functionality on behalf of user.module
*/
function user_views_tables() {
$tables['users'] = array(
'name' => 'users',
'provider' => 'internal', // won't show up in external list.
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'uid'
),
'right' => array(
'field' => 'uid'
),
),
'fields' => array(
'name' => array(
'name' => t('Node: Author Name'),
'handler' => 'views_handler_field_username',
'sortable' => true,
'uid' => 'uid',
'addlfields' => array('uid'),
'help' => t('This will display the author of the node.'),
),
'uid' => array(
'name' => t('User: Author Picture'),
'handler' => 'views_handler_field_userpic',
'sortable' => false,
'notafield' => true,
'help' => t('Display the user picture of the author.'),
),
),
'sorts' => array(
'name' => array(
'name' => t('Node: Author Name'),
'help' => t('This allows you to sort alphabetically by author.'),
)
),
'filters' => array(
'uid' => array(
'name' => t('Node: Author Name'),
'operator' => 'views_handler_operator_or',
'list' => 'views_handler_filter_username',
'value-type' => 'array',
'help' => t('This allows you to filter by a particular user. You might not find this useful if you have a lot of users.'),
),
)
);
$tables['users_roles'] = array(
'name' => 'users_roles',
'provider' => 'internal', // won't show up in external list.
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'uid'
),
'right' => array(
'field' => 'uid'
),
),
'filters' => array(
'rid' => array(
'name' => t('Role: Author Role'),
'operator' => 'views_handler_operator_andor',
'list' => 'views_handler_filter_role',
'value-type' => 'array',
'help' => t('Include the node only if the author is a member of the selected role.'),
),
)
);
return $tables;
}
function user_views_arguments() {
$arguments = array(
'uid' => array(
'name' => t('User: UID is Author'),
'handler' => 'views_handler_arg_uid',
'help' => t('The User ID argument allows users to filter to nodes authored by the specified user ID.'),
),
'uidtouch' => array(
'name' => t('User: UID Authored or Commented'),
'handler' => 'views_handler_arg_uid_touch',
'help' => t('The User ID argument allows users to filter a to nodes authored or commented on the specified user ID.'),
),
);
return $arguments;
}
function user_views_default_views() {
$view = new stdClass();
$view->name = 'tracker';
$view->requires = array('node_comment_statistics');
$view->description = 'Shows all new activity on system.';
$view->page = true;
$view->url = 'tracker';
$view->page_title = 'recent posts for %1';
$view->page_type = 'table';
$view->use_pager = true;
$view->nodes_per_page = '25';
$view->menu = true;
$view->menu_title = 'recent posts';
$view->block = false;
$view->field = array (
array (
'tablename' => 'node',
'field' => 'type',
'label' => 'Type',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => 'Title',
'handler' => 'views_handler_field_nodelink_with_mark',
),
array (
'tablename' => 'users',
'field' => 'name',
'label' => 'Author',
),
array (
'tablename' => 'node_comment_statistics',
'field' => 'comment_count',
'label' => 'Replies',
'handler' => 'views_handler_comments_with_new',
),
array (
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'label' => 'Last Post',
'handler' => 'views_handler_field_since',
),
);
$view->sort = array (
array (
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'sortorder' => 'DESC',
),
);
$view->argument = array (
array (
'type' => 'uid',
'argdefault' => '2',
'title' => 'recent posts for all users',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'value' => '1',
),
);
$views[$view->name] = $view;
return $views;
}
/*
* Format as a field as a username. Needs to also have a 'uid' available,
* specified in the field info.
*/
function views_handler_field_username($fieldinfo, $fielddata, $value, $data) {
$obj->name = $value;
$uidfield = $fielddata['tablename'] . "_" . $fieldinfo['uid'];
$obj->uid = $data->$uidfield;
return theme('username', $obj);
}
/*
* Format as a field as a username. Needs to also have a 'uid' available,
* specified in the field info.
*/
function views_handler_field_userpic($fieldinfo, $fielddata, $value, $data) {
$account = user_load(array('uid' => $value));
if ($account !== FALSE) {
return theme_user_picture($account);
}
}
function views_handler_arg_uid($op, &$query, $argtype, $arg = '') {
switch($op) {
case 'summary':
$query->add_table('users', true);
$query->add_field('name', 'users');
$query->add_field('uid', 'users');
$fieldinfo['field'] = "users.name";
return $fieldinfo;
break;
case 'sort':
$query->add_orderby('users', 'name', $argtype);
break;
case 'filter':
$uid = intval($arg);
$query->add_where("node.uid = $uid");
break;
case 'link':
$name = ($query->name ? $query->name : variable_get('anonymous', 'Anonymous'));
return l($name, "$arg/" . intval($query->uid));
case 'title':
if (!$query) {
return variable_get('anonymous', 'Anonymous');
}
$user = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = '%d'", $query));
return $user->name;
}
}
function views_handler_arg_uid_touch($op, &$query, $argtype, $arg = '') {
switch($op) {
case 'summary':
$query->add_table('users', true);
$query->add_field('name', 'users');
$query->add_field('uid', 'users');
$fieldinfo['field'] = "users.name";
return $fieldinfo;
break;
case 'sort':
$query->add_orderby('users', 'name', $argtype);
break;
case 'filter':
$uid = intval($arg);
$table_data = _views_get_tables();
$joininfo = $table_data['comments']['join'];
$joininfo['extra'] = array('uid' => $uid);
$tblnum = $query->add_table("comments", false, 1, $joininfo);
$table = $query->get_table_name('comments', $tblnum);
$query->set_distinct(); // once you do this, there's just one node.
$query->add_where("node.uid = '%s' OR $table.uid = '%s'", $uid, $uid);
break;
case 'link':
$name = ($query->name ? $query->name : variable_get('anonymous', 'Anonymous'));
return l($name, "$arg/" . intval($query->uid));
case 'title':
if (!$query) {
return variable_get('anonymous', 'Anonymous');
}
$user = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = '%d'", $query));
return $user->name;
}
}
/*
* Create a list of usernames.
* I worry this will really, really suck for large sites.
* But then, why would large sites create a filter for one particular user?
* Better to go with roles.
*/
function views_handler_filter_username() {
$uids = array();
$result = db_query("SELECT u.uid, u.name FROM {users} u WHERE uid != 0 ORDER BY u.name");
while ($obj = db_fetch_object($result)) {
$uids[$obj->uid] = $obj->name;
}
return $uids;
}
/*
* Simple array for anonymous..
*/
function views_handler_filter_useranon() {
return array("0" => variable_get('anonymous', 'Anonymous'));
}
/*
* Simple array for current user.
*/
function views_handler_filter_usercurrent() {
return array('***CURRENT_USER***' => t('Currently Logged In User'));
}
/*
* Custom filter for current user.
*/
function views_handler_filter_usercurrent_custom($op, $filter, $filterinfo, &$query) {
global $user;
$query->ensure_table('users');
$query->add_where("users.uid $filter[operator] '$user->uid'");
}
/*
* Add special info to see if a user either authored OR commented on a post
*/
function views_handler_filter_uid_touched($op, $filter, $filterinfo, &$query) {
if (!module_exist('comment')) { // not much to do in this case
$query->add_where("node.uid = '%s'", $filter['value']);
return;
}
$table_data = _views_get_tables();
$joininfo = $table_data['comments']['join'];
$joininfo['extra'] = array('uid' => $filter['value']);
$tblnum = $query->add_table('comments', false, 1, $joininfo);
$table = $query->get_table_name('comments', $tblnum);
$query->set_distinct(); // once you do this, there's just one node.
$query->add_where("node.uid = '%s' OR $table.uid = '%s'", $filter['value'], $filter['value']);
}
This diff is collapsed.
This diff is collapsed.
......@@ -579,78 +579,3 @@ function _views_replace_args($clause, $args) {
return preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $clause);
}
/*
* Add a where clause views_get_titled on taxonomy. This is a pretty exciting piece of
* code because the clause and the JOINs are a bit complicated.
*/
function _views_add_taxonomy($op, $value, $depth, &$query) {
// When filtering via depth, we have to add a chain. If it's an or query
// we add 1 chain, but in an and query we actually basically have to add
// a 2 dimensional array.
$query->ensure_table('term_data'); // this is to make sure the views_get_title table comes first.
if ($op == 'OR') {
$clause = "'" . implode("','", $value) . "'";
// views_get_title tables
// Any number of things might have already added a term_node table, but
// if they have and are filtering on it the query is going to be borken
// anyway. If it's been added and unfiltered, and we ignore it, we get
// bad results.
$num = 1;
$query->ensure_table('term_node');
$tablename = $query->get_table_name('term_node', $num);
$where = "$tablename.tid IN ($clause)";
// for each depth > 0, add the next child in term_hierarchy to the join
for ($i = 0; $i < $depth; $i++) {
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'tid'), 'right' => array('field' => 'tid')));
$thname = $query->get_table_name('term_hierarchy', $thnum);
$num = $query->add_table('term_data', false, 1, array('left' => array('table' => $thname, 'field' => 'parent'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_data', $num);
$where .= " OR $tablename.tid IN ($clause)";
}
$query->add_where("$where");
}
else {
if ($op == 'NOR') {
$not = "!";
}
foreach ($value as $tid) {
// For every term we have to match, add a views_get_title table
$num = 1;
$num = $query->add_table('term_node');
$tablename = $query->get_table_name('term_node', $num);
$where = "$tablename.tid = '$tid'";
// for each depth > 0, add the next child in term_hierarchy to the join
for ($i = 0; $i < $depth; $i++) {
$thnum = $query->add_table('term_hierarchy', false, 1, array('left' => array('table' => $tablename, 'field' => 'tid'), 'right' => array('field' => 'tid')));
$thname = $query->get_table_name('term_hierarchy', $thnum);
$num = $query->add_table('term_data', false, 1, array('left' => array('table' => $thname, 'field' => 'parent'), 'right' => array('field' => 'tid')));
$tablename = $query->get_table_name('term_data', $num);
$where .= " OR $tablename.tid = '$tid'";
}
$query->add_where("$not($where)");
}
}
}
/*
* Break x,y,z and x+y+z into an array.
*/
function _views_break_phrase($str) {
if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) {
// The '+' character in a query string may be parsed as ' '.
return array('or', preg_split('/[+ ]/', $str));
}
else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) {
return array('and', explode(',', $str));
}
else {
return NULL;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment