| 1 |
|
<?php |
| 2 |
|
// $Id: flexinode_miniview.module,v 1.2 2007/01/27 14:46:39 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_miniview_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_miniview_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_miniview_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 |
|
if (($field_to_select = flexinode_invoke('db_select', $field)) && $field->show_table) { |
| 109 |
|
$fields_to_select[] = $field_to_select; |
| 110 |
|
$table_joins[] = 'LEFT JOIN {flexinode_data} '. $fieldname .' ON n.nid = '. $fieldname .'.nid'; |
| 111 |
|
$where_clauses[] = $fieldname .'.field_id = '. $field->field_id; |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
$type = 'flexinode-' . db_escape_string($ctype_id); |
| 116 |
|
$extra_fields = count($fields_to_select) > 0 ? ', ' . implode(', ', $fields_to_select) : ''; |
| 117 |
|
$extra_where = count($where_clauses) > 0 ? ' AND ' . implode(' AND ', $where_clauses) : ''; |
| 118 |
|
$sql = 'SELECT n.nid, n.title '. $extra_fields .' FROM {node} n '. implode(' ', $table_joins) ." WHERE n.status = 1 AND n.type = '$type'". $extra_where; |
| 119 |
|
dprint_r($sql); |
| 120 |
|
// Build the columns. |
| 121 |
|
$header[] = array('data' => t('title'), 'field' => 'n.title'); |
| 122 |
|
foreach ($ctype->fields as $field) { |
| 123 |
|
if ($field->show_table) { |
| 124 |
|
$fieldname = 'flexinode_'. $field->field_id; |
| 125 |
|
|
| 126 |
|
$sort_column = flexinode_invoke('db_sort_column', $field); |
| 127 |
|
|
| 128 |
|
if ($sort_column) { |
| 129 |
|
$header[] = array('data' => t($field->label), 'field' => $sort_column); |
| 130 |
|
} |
| 131 |
|
else { |
| 132 |
|
$header[] = array('data' => t($field->label)); |
| 133 |
|
} |
| 134 |
|
} |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
$sql .= tablesort_sql($header); |
| 138 |
|
|
| 139 |
|
// Build the rows. |
| 140 |
|
$rows = array(); |
| 141 |
|
|
| 142 |
|
$nodes = pager_query(db_rewrite_sql($sql), 20); |
| 143 |
|
while ($node = db_fetch_object($nodes)) { |
| 144 |
|
$row = array(l($node->title, 'node/' . $node->nid)); |
| 145 |
|
foreach ($ctype->fields as $field) { |
| 146 |
|
if ($field->show_table) { |
| 147 |
|
$data = flexinode_invoke('format', $field, $node, TRUE); |
| 148 |
|
$row[] = $data ? $data : ''; |
| 149 |
|
} |
| 150 |
|
} |
| 151 |
|
$rows[] = $row; |
| 152 |
|
} |
| 153 |
|
if ($rows) { |
| 154 |
|
$output .= theme('table', $header, $rows); |
| 155 |
|
$output .= theme('pager', NULL, 20); |
| 156 |
|
} |
| 157 |
|
elseif (module_exist('search')) { |
| 158 |
|
$output .= theme('box', t('Your search yielded no results'), search_help('search#noresults')); |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
drupal_set_title(t('%type search results', array('%type' => t($ctype->name)))); |
| 162 |
|
return $output; |
| 163 |
|
} |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
/** |
| 167 |
|
* Menu callback; handles rss feeds for flexinode types. |
| 168 |
|
*/ |
| 169 |
|
function flexinode_miniview_feed($ctype_id = NULL) { |
| 170 |
|
global $base_url; |
| 171 |
|
|
| 172 |
|
if (!$ctype_id) { |
| 173 |
|
drupal_not_found(); |
| 174 |
|
return NULL; |
| 175 |
|
} |
| 176 |
|
else { |
| 177 |
|
$ctype = flexinode_load_content_type($ctype_id); |
| 178 |
|
|
| 179 |
|
if ($ctype_id) { |
| 180 |
|
$type = 'flexinode-' . db_escape_string($ctype_id); |
| 181 |
|
} |
| 182 |
|
else { |
| 183 |
|
$type = 'flexinode-%'; |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
$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)); |
| 187 |
|
|
| 188 |
|
$channel= array( |
| 189 |
|
'title' => variable_get('site_name', 'drupal') .' - '. $ctype->name .t(' feed'), |
| 190 |
|
'link' => $base_url .'/flexinode/list/'. $ctype_id |
| 191 |
|
); |
| 192 |
|
|
| 193 |
|
node_feed($nodes, $channel); |
| 194 |
|
} |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
/** |
| 198 |
|
* Implementation of hook_settings(). |
| 199 |
|
*/ |
| 200 |
|
function flexinode_miniview_settings() { |
| 201 |
|
//$output = implode("\n", flexinode_invoke_all('settings')); |
| 202 |
|
$form['flexinode_miniview_list_count'] = array( |
| 203 |
|
'#type' => 'textfield', |
| 204 |
|
'#title' => t('Number of posts in flexinode listings'), |
| 205 |
|
'#description' => t('Number of posts to show on flexinode listing pages.'), |
| 206 |
|
'#default_value' => variable_get('flexinode_miniview_list_count', 10), |
| 207 |
|
); |
| 208 |
|
return $form; |
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
/** |
| 212 |
|
* Implementation of hook_alter(). |
| 213 |
|
*/ |
| 214 |
|
function flexinode_miniview_form_alter($form_id, &$form) { |
| 215 |
|
if ($form_id == 'flexinode_admin_field_form') { |
| 216 |
|
$ctype = flexinode_load_field($form['ctype_id']['#value']); |
| 217 |
|
|
| 218 |
|
$form['show_table'] = array( |
| 219 |
|
'#type' => 'checkbox', |
| 220 |
|
'#title' => t('Show in table'), |
| 221 |
|
'#default_value' => $field->required, |
| 222 |
|
'#weight' => 4, |
| 223 |
|
'#description' => t('Whether this field should be shown as part of this content type\'s tabular view.'), |
| 224 |
|
); |
| 225 |
|
} |
| 226 |
|
} |