| 1 |
<?php |
<?php |
| 2 |
// $Id: indexpage.module,v 1.8.2.6.2.17 2009/05/21 15:35:40 nancyw Exp $ |
// $Id: indexpage.module,v 1.8.2.6.2.18 2009/05/21 18:00:03 nancyw Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 63 |
$items['indexpage'] = array( |
$items['indexpage'] = array( |
| 64 |
'title' => 'Index page', |
'title' => 'Index page', |
| 65 |
'page callback' => 'indexpage_page', |
'page callback' => 'indexpage_page', |
| 66 |
'page arguments' => array(1, 2), |
'page arguments' => array(1, 2, 3), |
| 67 |
'access arguments' => array('access indexpage'), |
'access arguments' => array('access indexpage'), |
| 68 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 69 |
); |
); |
| 82 |
return $items; |
return $items; |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
function indexpage_page($type, $op = NULL) { |
function indexpage_page($type, $op = NULL, $uid = NULL) { |
| 86 |
drupal_add_css(drupal_get_path('module', 'indexpage') .'/indexpage.css'); |
drupal_add_css(drupal_get_path('module', 'indexpage') .'/indexpage.css'); |
| 87 |
|
|
| 88 |
global $user; |
global $user; |
| 89 |
// Is this the overview index? |
// Is this the overview index? |
| 90 |
if (!arg(1)) { |
if (!$type) { |
| 91 |
$output .= '<div class="content">'; |
$output .= '<div class="content">'; |
| 92 |
$output .= nl2br(variable_get('indexpage_description', '')); |
$output .= nl2br(variable_get('indexpage_description', '')); |
| 93 |
$output .= '<ul>'; |
$output .= '<ul>'; |
| 106 |
// Do the index for a specific type. |
// Do the index for a specific type. |
| 107 |
// In 6.x, the node module does node_access automatically. |
// In 6.x, the node module does node_access automatically. |
| 108 |
// $access = _node_access_where_sql(); |
// $access = _node_access_where_sql(); |
| 109 |
// $exist_type = @db_result(db_query(_indexpage_check_status("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n, {node_access} na WHERE n.type = '%s'") . ($access ? ' AND '. $access : ''), arg(1))); |
// $exist_type = @db_result(db_query(_indexpage_check_status("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n, {node_access} na WHERE n.type = '%s'") . ($access ? ' AND '. $access : ''), $type)); |
| 110 |
$exist_type = @db_result(db_query(_indexpage_check_status("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.type = '%s'"), arg(1))); |
$exist_type = @db_result(db_query(_indexpage_check_status("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.type = '%s'"), $type)); |
| 111 |
if ($exist_type && variable_get('indexpage_'. arg(1) .'_enable', 1)) { |
if ($exist_type && variable_get('indexpage_'. $type .'_enable', 1)) { |
| 112 |
if (empty($op) && $op !== '0') { |
if (empty($op) && $op !== '0') { |
| 113 |
// $unpublished = @db_result(db_query("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n, {node_access} na WHERE n.type = '%s' AND n.status = 0". ($access ? ' AND '. $access : ''), arg(1))); |
// $unpublished = @db_result(db_query("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n, {node_access} na WHERE n.type = '%s' AND n.status = 0". ($access ? ' AND '. $access : ''), $type)); |
| 114 |
$unpublished = @db_result(db_query("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.type = '%s' AND n.status = 0", arg(1))); |
$unpublished = @db_result(db_query("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.type = '%s' AND n.status = 0", $type)); |
| 115 |
return indexpage_page_index(arg(1), $exist_type, $unpublished); |
return indexpage_page_index($type, $exist_type, $unpublished); |
| 116 |
} |
} |
| 117 |
else { |
else { |
| 118 |
return indexpage_page_list(arg(1), arg(2)); |
return indexpage_page_list($type, $op, $uid); |
| 119 |
} |
} |
| 120 |
} |
} |
| 121 |
else { |
else { |
| 125 |
} |
} |
| 126 |
|
|
| 127 |
function indexpage_page_index($type, $count = 0, $unpub_count = 0) { |
function indexpage_page_index($type, $count = 0, $unpub_count = 0) { |
| 128 |
|
list($type, $uid) = explode('-', $type); |
| 129 |
$name = check_plain(variable_get('indexpage_'. $type .'_name', $type)); |
$name = check_plain(variable_get('indexpage_'. $type .'_name', $type)); |
| 130 |
$show_count = variable_get('indexpage_show_count', TRUE); |
$show_count = variable_get('indexpage_show_count', TRUE); |
| 131 |
|
$show_users = variable_get('indexpage_show_users', FALSE); |
| 132 |
$show_untagged = variable_get('indexpage_show_untagged', TRUE); |
$show_untagged = variable_get('indexpage_show_untagged', TRUE); |
| 133 |
$suppress_unused = variable_get('indexpage_suppress_unused', FALSE); |
$suppress_unused = variable_get('indexpage_suppress_unused', FALSE); |
| 134 |
$show_description = variable_get('indexpage_show_description', FALSE); |
$show_description = variable_get('indexpage_show_description', FALSE); |
| 150 |
} |
} |
| 151 |
|
|
| 152 |
if ($show_count) { |
if ($show_count) { |
| 153 |
$count_msg = strtr(format_plural($count, 'There is one !type node', 'There are @count !type nodes'), |
$count_msg = format_plural($count, 'There is one !type node', 'There are @count !type nodes', |
| 154 |
array('!type' => $type_name)); |
array('!type' => $type_name)); |
| 155 |
if ($unpub_count) { |
if ($unpub_count) { |
| 156 |
$count_msg .= format_plural($unpub_count, ', of which one is unpublished.', ', of which @count are unpublished.'); |
$count_msg .= format_plural($unpub_count, ', of which one is unpublished.', ', of which @count are unpublished.'); |
| 186 |
$output .= implode(' | ', $range) .'</p></div>'; |
$output .= implode(' | ', $range) .'</p></div>'; |
| 187 |
} |
} |
| 188 |
|
|
| 189 |
// Index by taxonomy terms block. |
// Index by users section. |
| 190 |
|
$rows = array(); |
| 191 |
|
$sql = _indexpage_check_status("SELECT n.uid, COUNT(n.uid) as count FROM {node} n WHERE n.type='%s'") .' GROUP BY n.uid'; |
| 192 |
|
$users = db_query($sql, $type); |
| 193 |
|
while ($u = db_fetch_object($users)) { |
| 194 |
|
$account = user_load(array('uid' => $u->uid)); |
| 195 |
|
$rows[] = array( |
| 196 |
|
theme('username', $account, array('picture' => TRUE, 'homepage' => FALSE)), |
| 197 |
|
l($u->count, "indexpage/$type/user/$u->uid", array('attributes' => array('title' => t('Show the content this user contributed')))), |
| 198 |
|
); |
| 199 |
|
} |
| 200 |
|
if ($rows) { |
| 201 |
|
$header = array(t('User Name'), t('Count')); |
| 202 |
|
$fieldset = array( |
| 203 |
|
'#title' => t('Users who have created !name content', array('!name' => $name)), |
| 204 |
|
'#description' => t('User names link to the user profile; the counts link to a list of titles by that user.'), |
| 205 |
|
'#collapsible' => TRUE, |
| 206 |
|
'#collapsed' => (count($rows) > variable_get('indexpage_maxresults', 10)), |
| 207 |
|
'#value' => theme('table', $header, $rows), |
| 208 |
|
); |
| 209 |
|
$output .= '<div class="indexpage-users">'. theme('fieldset', $fieldset) .'</div>'; |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
// Index by taxonomy terms section. |
| 213 |
$voc_list = array(); |
$voc_list = array(); |
| 214 |
if (variable_get('indexpage_'. $type .'_vocfilter', 1)) { |
if (variable_get('indexpage_'. $type .'_vocfilter', 1)) { |
| 215 |
$vocs = db_query("SELECT v.name, v.vid FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} t ON t.vid=v.vid WHERE t.type='%s'", $type); |
$vocs = db_query("SELECT v.name, v.vid FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} t ON t.vid=v.vid WHERE t.type='%s'", $type); |
| 366 |
return db_rewrite_sql($query); |
return db_rewrite_sql($query); |
| 367 |
} |
} |
| 368 |
|
|
| 369 |
function indexpage_page_list($type, $filter) { |
function indexpage_page_list($type, $filter, $uid = NULL) { |
| 370 |
|
static $acct = array(); |
| 371 |
$name = check_plain(variable_get('indexpage_'. $type .'_name', $type)); |
$name = check_plain(variable_get('indexpage_'. $type .'_name', $type)); |
| 372 |
|
|
| 373 |
$breadcrumb = drupal_get_breadcrumb(); |
$breadcrumb = drupal_get_breadcrumb(); |
| 389 |
drupal_set_title(t('!type nodes classified with !term', array('!type' => $name, '!term' => $term_name))); |
drupal_set_title(t('!type nodes classified with !term', array('!type' => $name, '!term' => $term_name))); |
| 390 |
} |
} |
| 391 |
else { |
else { |
| 392 |
// Check if all nodes of this type wanted. |
switch ($filter) { |
| 393 |
if ($filter == 'all') { |
case 'all': |
| 394 |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type='%s'"; |
// All nodes of this type wanted. |
| 395 |
$args = array($type); |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type='%s'"; |
| 396 |
drupal_set_title(t('All !type nodes', array('!type' => $name))); |
$args = array($type); |
| 397 |
} |
drupal_set_title(t('All !type nodes', array('!type' => $name))); |
| 398 |
else { |
break; |
| 399 |
// Filter by letter. |
|
| 400 |
if ($filter == '_') { |
case '_': |
| 401 |
|
// Filter by non_alpha. |
| 402 |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type='%s' AND (n.title REGEXP '^[^[:alpha:]].*$')"; |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type='%s' AND (n.title REGEXP '^[^[:alpha:]].*$')"; |
| 403 |
$args = array($type); |
$args = array($type); |
| 404 |
drupal_set_title(t('!type nodes beginning with non-alphabetical', array('!type' => $name))); |
drupal_set_title(t('!type nodes beginning with non-alphabetical', array('!type' => $name))); |
| 405 |
} |
break; |
| 406 |
else { |
|
| 407 |
|
case 'user': |
| 408 |
|
// Filter by user. |
| 409 |
|
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type='%s' AND n.uid = %d"; |
| 410 |
|
$args = array($type, $uid); |
| 411 |
|
$account = user_load(array('uid' => $uid)); |
| 412 |
|
drupal_set_title(t('!type nodes created by %user', array('!type' => $name, '%user' => theme('username', $account, array('plain' => TRUE))))); |
| 413 |
|
break; |
| 414 |
|
|
| 415 |
|
default: |
| 416 |
|
// Filter by letter. |
| 417 |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type='%s' AND (n.title LIKE '%s%%' OR n.title LIKE '%s%%')"; |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type='%s' AND (n.title LIKE '%s%%' OR n.title LIKE '%s%%')"; |
| 418 |
$args = array($type, $filter, drupal_strtolower($filter)); |
$args = array($type, $filter, drupal_strtolower($filter)); |
| 419 |
drupal_set_title(t('!type nodes beginning with "!term"', array('!type' => $name, '!term' => $filter))); |
drupal_set_title(t('!type nodes beginning with "!term"', array('!type' => $name, '!term' => $filter))); |
| 420 |
} |
break; |
| 421 |
} |
} |
| 422 |
} |
} |
| 423 |
|
|
| 508 |
break; |
break; |
| 509 |
|
|
| 510 |
case 'authors': |
case 'authors': |
| 511 |
$items = $uids = array(); |
$items = array(); |
| 512 |
|
$uids = array($node->uid); |
| 513 |
$revs = db_query("SELECT DISTINCT(r.uid) FROM {node_revisions} r WHERE r.nid=%d ORDER by r.vid DESC", $node->nid); |
$revs = db_query("SELECT DISTINCT(r.uid) FROM {node_revisions} r WHERE r.nid=%d ORDER by r.vid DESC", $node->nid); |
| 514 |
while ($rev_uid = db_result($revs)) { |
while ($rev_uid = db_result($revs)) { |
| 515 |
$uids[] = $rev_uid; |
$uids[] = $rev_uid; |
| 516 |
} |
} |
| 517 |
$authors = db_query("SELECT u.* FROM {users} u WHERE u.uid IN (". implode(',', $uids) .")"); |
$uids = array_unique($uids); |
| 518 |
while ($account = db_fetch_object($authors)) { |
foreach ($uids as $uid) { |
| 519 |
$items[] = theme('username', $account); |
if (!isset($acct[$uid])) { |
| 520 |
|
$acct[$uid] = user_load(array('uid' => $uid)); |
| 521 |
|
} |
| 522 |
|
$items[] = theme('username', $acct[$uid]); |
| 523 |
} |
} |
| 524 |
$field_value = theme('item_list', $items); |
$field_value = theme('item_list', $items); |
| 525 |
break; |
break; |