'fieldset', '#title' => t('General settings'), ); $form[$set]['indexpage_description'] = array( '#type' => 'textarea', '#title' => t('Description text for main index page'), '#default_value' => variable_get('indexpage_description', ''), '#cols' => 60, '#rows' => 10, ); $form[$set]['indexpage_maxresults'] = array( '#type' => 'textfield', '#title' => t('Max number of results per page'), '#default_value' => variable_get('indexpage_maxresults', 10), '#size' => 2, '#maxlength' => 2, ); $set = $type; $form[$set] = array( '#type' => 'fieldset', '#title' => t('Index page settings for %s', array('%s' => $node->type)), ); foreach (node_get_types() as $type => $name) { $form[$set]['indexpage_'.$type.'_name'] = array( '#type' => 'textfield', '#title' => t('Name to show for this node type'), '#default_value' => variable_get('indexpage_'.$type.'_name', $type), '#size' => 20, '#maxlength' => 50, ); $form[$set]['indexpage_'.$type.'_enable'] = array( '#type' => 'checkbox', '#title' => t('Enable index page for this node type'), '#return_value' => 1, '#default_value' => variable_get('indexpage_'.$type.'_enable', 1), ); $form[$set]['indexpage_'.$type.'_alphaindex'] = array( '#type' => 'checkbox', '#title' => t('Show alphabetical index for this node type'), '#return_value' => 1, '#default_value' => variable_get('indexpage_'.$type.'_alphaindex', 1), ); $form[$set]['indexpage_'.$type.'_vocfilter'] = array( '#type' => 'checkbox', '#title' => t('Show vocabulary filters for this node type'), '#return_value' => 1, '#default_value' => variable_get('indexpage_'.$type.'_vocfilter', 1), ); } return $form; } function indexpage_perm() { return array('access indexpage'); } function indexpage_menu($may_cache) { global $user; $items = array(); if ($may_cache) { $items[] = array( 'path' => 'indexpage', 'title' => t('index page'), 'callback' => 'indexpage_page', 'access' => user_access('access indexpage'), 'type' => MENU_NORMAL_ITEM); } foreach (node_get_types() as $type => $name) { if (variable_get('indexpage_'.$type.'_enable', 1)) { $items[] = array( 'path' => 'indexpage/'.$type, 'title' => t('index page for %s', array('%s' => $type)), 'access' => user_access('access indexpage'), 'type' => MENU_NORMAL_ITEM); } } return $items; } function indexpage_page() { if (!arg(1)) { $output .= '
'; $output .= nl2br(variable_get('indexpage_description', '')); $output .= '
'; print theme('page', $output); } else { $access = _node_access_where_sql(); $exist_type = @db_result(db_query("SELECT COUNT(n.type) FROM {node} n, {node_access} na WHERE n.type = '%s'". ($access ? ' AND '.$access : ''), arg(1))); if ($exist_type && variable_get('indexpage_'.arg(1).'_enable', 1)) { if (!arg(2)) { indexpage_page_index(arg(1)); } else { indexpage_page_list(arg(1), arg(2)); } } else { print theme('page', t('ERROR: That node type does not exist, there are no entries, or the index page for this node type is disabled.')); } } } function indexpage_page_index($type) { $name = variable_get('indexpage_'.$type.'_name', $type); /* Index by letter block */ if (variable_get('indexpage_'.$type.'_alphaindex', 1)) { $output .= '
'; $output .= '

'.t('Alphabetically index').'

'; $output .= '

'; foreach (range('A', 'Z') as $letter) { $sql = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {node_revisions} r USING (nid) WHERE n.type='%s' AND (r.title LIKE '%s%%' OR r.title LIKE '%s%%')"; if (db_result(db_query($sql, $type, $letter, strtolower($letter))) > 0) { $output .= l($letter, "indexpage/$type/$letter") . ' | '; } else { $output .= $letter . ' | '; } } $sql = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {node_revisions} r USING (nid) WHERE n.type='%s' AND (r.title REGEXP '^[^[:alpha:]].*$')"; if (db_result(db_query($sql, $type)) > 0) { $output .= l('#', "indexpage/$type/_"); } else { $output .= '#'; } $output .= '

'; $output .= '
'; } /* Index by taxonomy terms block */ if (variable_get('indexpage_'.$type.'_vocfilter', 1)) { $vocs = db_query("SELECT name, v.vid FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} vnt on v.vid=vnt.vid WHERE type LIKE '%%%s%%'", $type); while ($voc = db_fetch_array($vocs)) { $output .= '
'; $output .= '

'.t('List by %s', array('%s' => $voc[name])).'

'; $output .= '

'; $terms = db_query('SELECT name, tid FROM {term_data} WHERE vid=%s ORDER BY name', $voc[vid]); while ($term = db_fetch_object($terms)) { $sql = "SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t on n.nid=t.nid WHERE type='%s' AND t.tid=%d"; if (db_result(db_query($sql, $type, $term->tid))) { $output .= l($term->name, "indexpage/$type/$term->tid") . ' | '; } else { $output .= $term->name . ' | '; } } $output .= '

'; $output .= '
'; } } /* Operations for this node type */ // $output .= '

'.t('Operations').'

'; // $output .= l(t('Create a new entry'), 'node/add/'.$type); print theme('page', $output); } function indexpage_page_list($type, $filter) { $name = variable_get('indexpage_'.$type.'_name', $type); $output = '

'.t('Index page for %s', array('%s' => $name)).'

'; if ($term = intval($filter)) { /* filter by vocabulary term */ #$sql = "SELECT r.title, n.nid, r.teaser FROM {node} n LEFT JOIN {term_node} t USING (nid) INNER JOIN {node_revisions} r USING (nid) WHERE type='%s' AND t.tid=%d"; $sql = "SELECT title, n.nid FROM {node} n LEFT JOIN {term_node} t USING (nid) WHERE type='%s' AND t.tid=%d"; $args = array($type, $term); $sql_count = "SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t USING (nid) WHERE type='%s' AND t.tid=%d"; } else { /* filter by letter */ if ($filter == '_') { #$sql = "SELECT r.title, n.nid, r.teaser FROM {node} n INNER JOIN {node_revisions} r USING (nid) WHERE n.type='%s' AND (r.title REGEXP '^[^[:alpha:]].*$')"; $sql = "SELECT title, n.nid FROM {node} n WHERE n.type='%s' AND (title REGEXP '^[^[:alpha:]].*$')"; $args = array($type); $sql_count = "SELECT COUNT(n.nid) FROM {node} n WHERE n.type='%s' AND (title REGEXP '^[^[:alpha:]].*$')"; } else { #$sql = "SELECT r.title, n.nid, r.teaser FROM {node} n INNER JOIN {node_revisions} r USING (nid) WHERE n.type='%s' AND (r.title LIKE '%s%%' OR r.title LIKE '%s%%')"; $sql = "SELECT title, n.nid FROM {node} n WHERE n.type='%s' AND (title LIKE '%s%%' OR title LIKE '%s%%')"; $args = array($type, $filter, strtolower($filter)); $sql_count = "SELECT COUNT(n.nid) FROM {node} n WHERE n.type='%s' AND (title LIKE '%s%%' OR title LIKE '%s%%')"; } } $sql_count = db_rewrite_sql($sql_count); $header = array( array('data' => t('title'), 'field' => 'title', 'sort' => 'asc'), ); $sql .= tablesort_sql($header); $max_results = variable_get('indexpage_maxresults', 10); $result = pager_query($sql, $max_results, 0, $sql_count, $args); // $result = pager_query($sql, $max_results, null, null, $args); if (db_num_rows(db_query($sql, $args))) { while ($n = db_fetch_object($result)) { $rows[] = array( #l(htmlspecialchars($n->title), 'node/'.$n->nid, array('title' => strip_tags($n->teaser))), l(htmlspecialchars($n->title), 'node/'.$n->nid), ); } if ($pager = theme('pager', NULL, $max_results, 0)) { $rows[] = array(array('data' => $pager, 'colspan' => 2)); } $output = '
' . theme('table', $header, $rows) . '
'; } else { $output = t('There are no results'); } // $output .= theme('pager', NULL, $max_results, 0); #### $output .= '

'.l(t('Return to index page for %s', array('%s' => $name)), 'indexpage/'.$type).'

'; print theme('page', $output); }