| 1 |
<?php |
<?php |
| 2 |
// $Id: indexpage.module,v 1.10 2009/07/18 01:19:23 nancyw Exp $ |
// $Id: indexpage.module,v 1.11 2009/07/21 14:25:57 nancyw Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 48 |
} |
} |
| 49 |
|
|
| 50 |
/** |
/** |
| 51 |
* Implementation of hook_perm(). |
* Implementation of hook_permission(). |
| 52 |
*/ |
*/ |
| 53 |
function indexpage_perm() { |
function indexpage_permission() { |
| 54 |
return array('access indexpage'); |
return array( |
| 55 |
|
'access indexpage' => array( |
| 56 |
|
'title' => t('Access the IndexPage reports'), |
| 57 |
|
'description' => t('Display a customizable index page for each node type.'), |
| 58 |
|
), |
| 59 |
|
); |
| 60 |
} |
} |
| 61 |
|
|
| 62 |
/** |
/** |
| 80 |
'page arguments' => array('indexpage_admin_settings'), |
'page arguments' => array('indexpage_admin_settings'), |
| 81 |
'access arguments' => array('administer site configuration'), |
'access arguments' => array('administer site configuration'), |
| 82 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
|
'file' => 'indexpage.admin.inc', |
|
| 83 |
); |
); |
| 84 |
|
|
| 85 |
|
|
| 96 |
if (!$type) { |
if (!$type) { |
| 97 |
$output .= '<div class="content">'; |
$output .= '<div class="content">'; |
| 98 |
$output .= nl2br(variable_get('indexpage_description', '')); |
$output .= nl2br(variable_get('indexpage_description', '')); |
| 99 |
$output .= '<ul>'; |
$items = array(); |
| 100 |
$types = node_get_types('names'); |
$types = node_type_get_names(); |
| 101 |
foreach ($types as $type => $name) { |
foreach ($types as $type => $name) { |
| 102 |
|
$count = db_query("SELECT COUNT(nid) FROM {node} WHERE type = :type", array(':type' => $type))->fetchfield(); |
| 103 |
if (variable_get('indexpage_' . $type . '_enable', 1)) { |
if (variable_get('indexpage_' . $type . '_enable', 1)) { |
| 104 |
$output .= '<li>' . l(t('Index page for !s', array('!s' => check_plain(variable_get('indexpage_' . $type . '_name', $type)))), drupal_get_path_alias('indexpage/' . $type)) . '</li>'; |
$title = t('Index page for !s (!count)', |
| 105 |
|
array( |
| 106 |
|
'!s' => check_plain(variable_get('indexpage_' . $type . '_name', $type)), |
| 107 |
|
'!count' => $count, |
| 108 |
|
) |
| 109 |
|
); |
| 110 |
|
$items[] = l($title, drupal_get_path_alias('indexpage/' . $type)); |
| 111 |
} |
} |
| 112 |
} |
} |
| 113 |
|
|
| 114 |
$output .= '</ul></div>'; |
$output .= theme('item_list', $items) . '</div>'; |
| 115 |
|
|
| 116 |
|
if (user_access('administer site configuration')) { |
| 117 |
|
$links['indexpage-settings'] = array( |
| 118 |
|
'title' => t('Indexpage settings'), |
| 119 |
|
'href' => 'admin/settings/indexpage', |
| 120 |
|
'attributes' => array('title' => t('Change the Indexpage settings'), 'rel' => 'nofollow'), |
| 121 |
|
'query' => drupal_get_destination(), |
| 122 |
|
); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
$output .= theme('links', $links, array('class' => 'links inline')); |
| 126 |
|
$output .= '</div>'; |
| 127 |
|
|
| 128 |
return $output; |
return $output; |
| 129 |
} |
} |
| 130 |
else { |
else { |
| 131 |
// Do the index for a specific type. |
// Do the index for a specific type. |
| 132 |
// $sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n WHERE n.type = ':type' "); |
$sql = _indexpage_check_status("SELECT 1 FROM {node} n WHERE n.type = :type"); |
| 133 |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n WHERE n.type = '$type'"); |
$exist_type = (bool) db_query_range($sql, 0, 1, array(':type' => $type))->fetchField(); |
| 134 |
$exist_type = db_result(db_query($sql, array(':type' => $type))); |
if (!$exist_type) { |
| 135 |
if ($exist_type && variable_get('indexpage_' . $type . '_enable', 1)) { |
return t('ERROR: There are no items of the !type type.', array('!type' => $type)); |
| 136 |
if (empty($op) && $op !== '0') { |
} |
| 137 |
$unpublished = @db_result(db_query("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.type = ':type' AND n.status = 0", array(':type' => $type))); |
if (variable_get('indexpage_' . $type . '_enable', 1)) { |
| 138 |
|
if (empty($op) && $op !== '0') { // ???? empty AND == ? |
| 139 |
|
$unpublished = @db_query("SELECT COUNT(n.nid) FROM {node} n WHERE n.type = :type AND n.status = 0", array(':type' => $type))->fetchfield(); |
| 140 |
return indexpage_page_index($type, $exist_type, $unpublished); |
return indexpage_page_index($type, $exist_type, $unpublished); |
| 141 |
} |
} |
| 142 |
else { |
else { |
| 144 |
} |
} |
| 145 |
} |
} |
| 146 |
else { |
else { |
| 147 |
return t('ERROR: That content type does not exist, there are no entries, or the index page for that type is disabled.'); |
return t('ERROR: The index page for that type is disabled.'); |
| 148 |
} |
} |
| 149 |
} |
} |
| 150 |
} |
} |
| 197 |
// Note: this doesn't work well with non-English. |
// Note: this doesn't work well with non-English. |
| 198 |
$range = drupal_map_assoc(range('A', 'Z')); |
$range = drupal_map_assoc(range('A', 'Z')); |
| 199 |
foreach ($range as $letter) { |
foreach ($range as $letter) { |
| 200 |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n WHERE n.type=':type' AND LOWER(n.title) LIKE ':letter%'"); |
$sql = _indexpage_check_status("SELECT 1 FROM {node} n WHERE n.type=:type AND LOWER(n.title) LIKE :letter"); |
| 201 |
if (db_result(db_query($sql, array(':type' => $type, ':letter' => drupal_strtolower($letter)))) > 0) { |
$found_letter = (bool) db_query_range($sql, 0, 1, array(':type' => $type, ':letter' => drupal_strtolower($letter) . '%'))->fetchfield(); |
| 202 |
|
if ($found_letter) { |
| 203 |
$range[$letter] = l($letter, drupal_get_path_alias("indexpage/$type/$letter"), array('attributes' => array('title' => "$name content beginning with '$letter'"))); |
$range[$letter] = l($letter, drupal_get_path_alias("indexpage/$type/$letter"), array('attributes' => array('title' => "$name content beginning with '$letter'"))); |
| 204 |
} |
} |
| 205 |
} |
} |
| 206 |
|
|
| 207 |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n WHERE n.type=':type' AND (n.title REGEXP '^[^[:alpha:]].*$')"); |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n WHERE n.type=:type AND (n.title REGEXP '^[^[:alpha:]].*$')"); |
| 208 |
if (db_result(db_query($sql, array(':type' => $type))) > 0) { |
if (db_query($sql, array(':type' => $type))->fetchfield() > 0) { |
| 209 |
$range['#'] = l('#', drupal_get_path_alias("indexpage/$type/_"), array('attributes' => array('title' => "$name content beginning with a non-alphabetic character"))); |
$range['#'] = l('#', drupal_get_path_alias("indexpage/$type/_"), array('attributes' => array('title' => "$name content beginning with a non-alphabetic character"))); |
| 210 |
} |
} |
| 211 |
|
|
| 217 |
// Index by users section. |
// Index by users section. |
| 218 |
if ($show_users) { |
if ($show_users) { |
| 219 |
$rows = array(); |
$rows = array(); |
| 220 |
$sql = _indexpage_check_status("SELECT n.uid, COUNT(n.uid) as count FROM {node} n WHERE n.type='%s'") .' GROUP BY n.uid'; |
$sql = _indexpage_check_status("SELECT n.uid, COUNT(n.uid) as count FROM {node} n WHERE n.type=:type GROUP BY n.uid"); |
| 221 |
$users = db_query($sql, $type); |
$users = db_query($sql, array(':type' => $type)); |
| 222 |
while ($u = db_fetch_object($users)) { |
while ($u = db_fetch_object($users)) { |
| 223 |
$account = user_load(array('uid' => $u->uid)); |
$account = user_load_multiple(array($u->uid)); |
| 224 |
$rows[] = array( |
$rows[] = array( |
| 225 |
theme('username', $account, array('picture' => TRUE, 'homepage' => FALSE)), |
theme('username', $account, array('picture' => TRUE, 'homepage' => FALSE)), |
| 226 |
l($u->count, "indexpage/$type/user/$u->uid", array('attributes' => array('title' => t('Show the content this user contributed')))), |
l($u->count, "indexpage/$type/user/$u->uid", array('attributes' => array('title' => t('Show the content this user contributed')))), |
| 235 |
'#collapsed' => (count($rows) > variable_get('indexpage_maxresults', 10)), |
'#collapsed' => (count($rows) > variable_get('indexpage_maxresults', 10)), |
| 236 |
'#value' => theme('table', $header, $rows), |
'#value' => theme('table', $header, $rows), |
| 237 |
); |
); |
| 238 |
$output .= '<div class="indexpage-users">'. theme('fieldset', $fieldset) .'</div>'; |
$output .= '<div class="indexpage-users">' . theme('fieldset', $fieldset) . '</div>'; |
| 239 |
} |
} |
| 240 |
} |
} |
| 241 |
|
|
| 243 |
// Index by taxonomy terms section. |
// Index by taxonomy terms section. |
| 244 |
$voc_list = array(); |
$voc_list = array(); |
| 245 |
if (variable_get('indexpage_' . $type . '_vocfilter', 1)) { |
if (variable_get('indexpage_' . $type . '_vocfilter', 1)) { |
| 246 |
$vocs = db_query("SELECT v.name, v.vid FROM {taxonomy_vocabulary} v LEFT JOIN {taxonomy_vocabulary_node_type} t ON t.vid=v.vid WHERE t.type=':type'", $type); |
$vocs = db_query("SELECT v.name, v.vid FROM {taxonomy_vocabulary} v LEFT JOIN {taxonomy_vocabulary_node_type} t ON t.vid=v.vid WHERE t.type=:type", array(':type' => $type)); |
| 247 |
while ($voc = db_fetch_array($vocs)) { |
foreach ($vocs as $voc) { |
| 248 |
$term_list = array(); |
$term_list = array(); |
| 249 |
$voc_list[$voc['vid']] = check_plain($voc['name']); |
$voc_list[$voc->vid] = check_plain($voc->name); |
| 250 |
$output .= '<div class="indexpage-filter-' . $voc['vid'] . '">'; |
$output .= '<div class="indexpage-filter-' . $voc->vid . '">'; |
| 251 |
$voc_count = 0; |
$voc_count = 0; |
| 252 |
|
|
| 253 |
$terms = taxonomy_get_tree($voc['vid']); |
$terms = taxonomy_get_tree($voc->vid); |
| 254 |
foreach ($terms as $term) { |
foreach ($terms as $term) { |
| 255 |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {taxonomy_term_node} t on t.nid=n.nid AND t.vid=n.vid WHERE type=':type' AND t.tid=:tid"); |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {taxonomy_term_node} t on t.nid=n.nid AND t.vid=n.vid WHERE type=:type AND t.tid=:tid"); |
| 256 |
$term->node_count = $how_many = db_result(db_query($sql, array(':type' => $type, ':tid' => $term->tid))); |
$term->node_count = $how_many = db_query($sql, array(':type' => $type, ':tid' => $term->tid))->fetchfield(); |
| 257 |
$voc_count += $how_many; |
$voc_count += $how_many; |
| 258 |
if ($how_many || !$suppress_unused) { |
if ($how_many || !$suppress_unused) { |
| 259 |
$term_list[] = theme('indexpage_term', $term, $type); |
$term_list[] = theme('indexpage_term', $term, $type); |
| 279 |
$stuff = '<p>' . t('None found') . '</p>'; |
$stuff = '<p>' . t('None found') . '</p>'; |
| 280 |
} |
} |
| 281 |
$fieldset = array( |
$fieldset = array( |
| 282 |
'#title' => t('List by !s Categories', array('!s' => $voc['name'])) . ($show_count ? ' (' . $voc_count . ')' : NULL), |
'#title' => t('List by !s Categories', array('!s' => $voc->name)) . ($show_count ? ' (' . $voc_count . ')' : NULL), |
| 283 |
'#description' => t('Terms (categories) that have content will link to a list of titles tagged with that term.'), |
'#description' => t('Terms (categories) that have content will link to a list of titles tagged with that term.'), |
| 284 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 285 |
'#collapsed' => (count($term_list) > variable_get('indexpage_maxresults', 10)), |
'#collapsed' => (count($term_list) > variable_get('indexpage_maxresults', 10)), |
| 286 |
'#value' => $stuff, |
'#value' => $stuff, |
| 287 |
'#attributes' => array('class' => 'indexpage_category indexpage_category_' . $voc['vid']), |
'#prefix' => '<div class="indexpage_category indexpage_category_' . $voc->vid . '">', |
| 288 |
|
'#suffix' => '</div>', |
| 289 |
); |
); |
| 290 |
$output .= theme('fieldset', $fieldset) . '</div>'; |
$output .= theme('fieldset', $fieldset) . '</div>'; |
| 291 |
} |
} |
| 292 |
|
|
| 293 |
// Handle unclassified. |
// Handle unclassified. |
| 294 |
if ($show_untagged) { |
if ($show_untagged) { |
| 295 |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {taxonomy_term_node} t on n.nid=t.nid WHERE type=':type' AND t.tid IS NULL"); |
$sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {taxonomy_term_node} t on n.nid=t.nid WHERE type=:type AND t.tid IS NULL"); |
| 296 |
$how_many = db_result(db_query($sql, array(':type' => $type))); |
$how_many = db_query($sql, array(':type' => $type))->fetchfield(); |
| 297 |
if ($how_many > 0) { |
if ($how_many > 0) { |
| 298 |
$title = format_plural($how_many, 'There is one unclassified !type node.', 'There are @count unclassified !type nodes.', |
$title = format_plural($how_many, 'There is one unclassified !type node.', 'There are @count unclassified !type nodes.', |
| 299 |
array('!type' => $name)); |
array('!type' => $name)); |
| 300 |
$output .= '<p>' . l($title, drupal_get_path_alias("indexpage/$type/0")) . '</p>'; |
$output .= '<p>' . l($title, drupal_get_path_alias("indexpage/$type/0")) . '</p>'; |
| 301 |
} |
} |
| 302 |
$sql = _indexpage_check_status("SELECT n.nid, v.name FROM {node} n JOIN {taxonomy_term_node} tn ON tn.nid=n.nid JOIN {taxonomy_term_data} td ON td.tid=tn.tid JOIN {taxonomy_vocabulary} v ON v.vid=td.vid LEFT JOIN {taxonomy_vocabulary_node_type} nt ON nt.vid=v.vid AND nt.type=n.type WHERE n.type=':type' AND nt.type IS NULL"); |
$sql = _indexpage_check_status("SELECT n.nid, v.name FROM {node} n JOIN {taxonomy_term_node} tn ON tn.nid=n.nid JOIN {taxonomy_term_data} td ON td.tid=tn.tid JOIN {taxonomy_vocabulary} v ON v.vid=td.vid LEFT JOIN {taxonomy_vocabulary_node_type} nt ON nt.vid=v.vid AND nt.type=n.type WHERE n.type=:type AND nt.type IS NULL"); |
| 303 |
$misclassed = db_query($sql, array(':type' => $type)); |
$misclassed = db_query($sql, array(':type' => $type)); |
| 304 |
$voc_names = array(); |
$voc_names = array(); |
| 305 |
$how_many = 0; |
$how_many = 0; |
| 306 |
while ($row = db_fetch_array($misclassed)) { |
foreach ($misclassed as $row) { |
| 307 |
$voc_names[] = decode_entities(check_plain($row['name'])); |
$voc_names[] = decode_entities(check_plain($row->name)); |
| 308 |
++$how_many; |
++$how_many; |
| 309 |
} |
} |
| 310 |
if ($voc_names) { |
if ($voc_names) { |
| 415 |
$args[':filter'] = $filter == 0 ? 'IS NULL' : '=' . $filter; |
$args[':filter'] = $filter == 0 ? 'IS NULL' : '=' . $filter; |
| 416 |
|
|
| 417 |
if ($filter) { |
if ($filter) { |
| 418 |
$term = taxonomy_get_term($filter); |
$term = taxonomy_term_load($filter); |
| 419 |
$term_name = check_plain($term->name); |
$term_name = check_plain($term->name); |
| 420 |
} |
} |
| 421 |
else { |
else { |
| 442 |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revision} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type=':type' AND n.uid = :uid"; |
$sql = "SELECT n.*, r.teaser FROM {node} n INNER JOIN {node_revision} r ON r.nid=n.nid AND r.vid=n.vid WHERE n.type=':type' AND n.uid = :uid"; |
| 443 |
$args[':uid'] = $uid; |
$args[':uid'] = $uid; |
| 444 |
$account = user_load($uid); |
$account = user_load($uid); |
| 445 |
drupal_set_title(t('!type nodes created by %user', array('!type' => $name, '%user' => theme('username', $account, array('plain' => TRUE))))); |
drupal_set_title(t('!type nodes created by !user', array('!type' => $name, '!user' => theme('username', $account, array('plain' => TRUE))))); |
| 446 |
break; |
break; |
| 447 |
|
|
| 448 |
default: |
default: |
| 486 |
} |
} |
| 487 |
$rows = array(); |
$rows = array(); |
| 488 |
|
|
| 489 |
$sql .= tablesort_sql($header); |
// $sql .= tablesort_sql($header); |
| 490 |
// Have to do this crap until they update pager_query. |
// Have to do this crap until they update pager_query. |
| 491 |
$search = array_keys($args); |
$search = array_keys($args); |
| 492 |
$replace = array_values($args); |
$replace = array_values($args); |