| 1 |
<?php
|
| 2 |
// $Id: flexinode_miniview.module,v 1.1 2006/12/25 12:25:34 ber Exp $
|
| 3 |
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file Menu callbacks and pages for flexinodes.
|
| 7 |
**/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function flexinode_miniview_help($section) {
|
| 13 |
switch ($section) {
|
| 14 |
case 'admin/modules#description':
|
| 15 |
return t('Manages simple flexinode pages, tables, feeds and lists.');
|
| 16 |
}
|
| 17 |
return $output;
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of hook_menu().
|
| 22 |
*/
|
| 23 |
function flexinode_miniview_menu($may_cache) {
|
| 24 |
$items = array();
|
| 25 |
|
| 26 |
if ($may_cache) {
|
| 27 |
// listing menu items
|
| 28 |
$items[] = array(
|
| 29 |
'path' => 'flexinode/list',
|
| 30 |
'title' => t('list view'),
|
| 31 |
'callback' => 'flexinode_page_list',
|
| 32 |
'access' => user_access('access content'),
|
| 33 |
'type' => MENU_CALLBACK,
|
| 34 |
);
|
| 35 |
$items[] = array(
|
| 36 |
'path' => 'flexinode/table',
|
| 37 |
'title' => t('tabular view'),
|
| 38 |
'callback' => 'flexinode_page_table',
|
| 39 |
'access' => user_access('access content'),
|
| 40 |
'type' => MENU_CALLBACK,
|
| 41 |
);
|
| 42 |
$items[] = array(
|
| 43 |
'path' => 'flexinode/feed',
|
| 44 |
'title' => t('rss feed'),
|
| 45 |
'callback' => 'flexinode_feed',
|
| 46 |
'access' => user_access('access content'),
|
| 47 |
'type' => MENU_CALLBACK,
|
| 48 |
);
|
| 49 |
}
|
| 50 |
|
| 51 |
return $items;
|
| 52 |
}
|
| 53 |
|
| 54 |
/**
|
| 55 |
* MENU CALLBACKS
|
| 56 |
*/
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Menu callback; presents a listing of all nodes of one type.
|
| 60 |
*/
|
| 61 |
function flexinode_miniview_page_list($ctype_id = 0) {
|
| 62 |
if (!$ctype_id) {
|
| 63 |
drupal_not_found();
|
| 64 |
return NULL;
|
| 65 |
}
|
| 66 |
else {
|
| 67 |
$output = '';
|
| 68 |
$ctype = flexinode_load_content_type($ctype_id);
|
| 69 |
|
| 70 |
if ($ctype_id) {
|
| 71 |
$type = 'flexinode-' . db_escape_string($ctype_id);
|
| 72 |
}
|
| 73 |
else {
|
| 74 |
$type = 'flexinode-%';
|
| 75 |
}
|
| 76 |
$result = pager_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.type LIKE '%s' ORDER BY n.sticky DESC, n.created DESC"), variable_get('flexinode_list_count', 10), 0, NULL, $type);
|
| 77 |
|
| 78 |
while ($node = db_fetch_object($result)) {
|
| 79 |
$output .= node_view(node_load($node->nid), 1);
|
| 80 |
}
|
| 81 |
$output .= theme('pager', NULL, variable_get('flexinode_list_count', 10));
|
| 82 |
|
| 83 |
drupal_set_title(t($ctype->name));
|
| 84 |
return $output ? $output : drupal_not_found();
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
| 88 |
/**
|
| 89 |
* Menu callback; presents a tabular view of nodes of one type.
|
| 90 |
*/
|
| 91 |
function flexinode_miniview_page_table($ctype_id = 0) {
|
| 92 |
if (!$ctype_id) {
|
| 93 |
drupal_not_found();
|
| 94 |
return NULL;
|
| 95 |
}
|
| 96 |
else {
|
| 97 |
$output = '';
|
| 98 |
$ctype = flexinode_load_content_type($ctype_id);
|
| 99 |
|
| 100 |
// Build the query.
|
| 101 |
$fields_to_select = array();
|
| 102 |
$table_joins = array();
|
| 103 |
$where_clauses = array();
|
| 104 |
|
| 105 |
foreach ($ctype->fields as $field) {
|
| 106 |
$fieldname = 'flexinode_'. $field->field_id;
|
| 107 |
|
| 108 |
$fields_to_select[] = flexinode_invoke('db_select', $field);
|
| 109 |
$table_joins[] = 'LEFT JOIN {flexinode_data} '. $fieldname .' ON n.nid = '. $fieldname .'.nid';
|
| 110 |
$where_clauses[] = $fieldname .'.field_id = '. $field->field_id;
|
| 111 |
}
|
| 112 |
|
| 113 |
$type = 'flexinode-' . db_escape_string($ctype_id);
|
| 114 |
$extra_fields = count($fields_to_select) > 0 ? ', ' . implode(', ', $fields_to_select) : '';
|
| 115 |
$extra_where = count($where_clauses) > 0 ? ' AND ' . implode(' AND ', $where_clauses) : '';
|
| 116 |
$sql = 'SELECT n.nid, n.title '. $extra_fields .' FROM {node} n '. implode(' ', $table_joins) ." WHERE n.status = 1 AND n.type = '$type'". $extra_where;
|
| 117 |
|
| 118 |
// Build the columns.
|
| 119 |
$header[] = array('data' => t('title'), 'field' => 'n.title');
|
| 120 |
foreach ($ctype->fields as $field) {
|
| 121 |
if ($field->show_table) {
|
| 122 |
$fieldname = 'flexinode_'. $field->field_id;
|
| 123 |
|
| 124 |
$sort_column = flexinode_invoke('db_sort_column', $field);
|
| 125 |
if ($sort_column) {
|
| 126 |
$header[] = array('data' => t($field->label), 'field' => $sort_column);
|
| 127 |
}
|
| 128 |
else {
|
| 129 |
$header[] = array('data' => t($field->label));
|
| 130 |
}
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
| 134 |
$sql .= tablesort_sql($header);
|
| 135 |
|
| 136 |
// Build the rows.
|
| 137 |
$rows = array();
|
| 138 |
$nodes = pager_query(db_rewrite_sql($sql), 20);
|
| 139 |
while ($node = db_fetch_object($nodes)) {
|
| 140 |
$row = array(l($node->title, 'node/' . $node->nid));
|
| 141 |
foreach ($ctype->fields as $field) {
|
| 142 |
if ($field->show_table) {
|
| 143 |
$data = flexinode_invoke('format', $field, $node, TRUE);
|
| 144 |
$row[] = $data ? $data : '';
|
| 145 |
}
|
| 146 |
}
|
| 147 |
$rows[] = $row;
|
| 148 |
}
|
| 149 |
if ($rows) {
|
| 150 |
$output .= theme('table', $header, $rows);
|
| 151 |
$output .= theme('pager', NULL, 20);
|
| 152 |
}
|
| 153 |
elseif (module_exist('search')) {
|
| 154 |
$output .= theme('box', t('Your search yielded no results'), search_help('search#noresults'));
|
| 155 |
}
|
| 156 |
|
| 157 |
drupal_set_title(t('%type search results', array('%type' => t($ctype->name))));
|
| 158 |
return $output;
|
| 159 |
}
|
| 160 |
}
|
| 161 |
|
| 162 |
/**
|
| 163 |
* Menu callback; handles rss feeds for flexinode types.
|
| 164 |
*/
|
| 165 |
function flexinode_miniview_feed($ctype_id = NULL) {
|
| 166 |
global $base_url;
|
| 167 |
|
| 168 |
if (!$ctype_id) {
|
| 169 |
drupal_not_found();
|
| 170 |
return NULL;
|
| 171 |
}
|
| 172 |
else {
|
| 173 |
$ctype = flexinode_load_content_type($ctype_id);
|
| 174 |
|
| 175 |
if ($ctype_id) {
|
| 176 |
$type = 'flexinode-' . db_escape_string($ctype_id);
|
| 177 |
}
|
| 178 |
else {
|
| 179 |
$type = 'flexinode-%';
|
| 180 |
}
|
| 181 |
|
| 182 |
$nodes = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.type LIKE '%s' ORDER BY n.sticky DESC, n.created DESC"), $type, 0, variable_get('feed_default_items', 10));
|
| 183 |
|
| 184 |
$channel= array(
|
| 185 |
'title' => variable_get('site_name', 'drupal') .' - '. $ctype->name .t(' feed'),
|
| 186 |
'link' => $base_url .'/flexinode/list/'. $ctype_id
|
| 187 |
);
|
| 188 |
|
| 189 |
node_feed($nodes, $channel);
|
| 190 |
}
|
| 191 |
}
|
| 192 |
|
| 193 |
/**
|
| 194 |
* Implementation of hook_settings().
|
| 195 |
*/
|
| 196 |
function flexinode_miniview_settings() {
|
| 197 |
//$output = implode("\n", flexinode_invoke_all('settings'));
|
| 198 |
$form['flexinode_miniview_list_count'] = array(
|
| 199 |
'#type' => 'textfield',
|
| 200 |
'#title' => t('Number of posts in flexinode listings'),
|
| 201 |
'#description' => t('Number of posts to show on flexinode listing pages.'),
|
| 202 |
'#default_value' => variable_get('flexinode_miniview_list_count', 10),
|
| 203 |
);
|
| 204 |
return $form;
|
| 205 |
}
|