/[drupal]/contributions/modules/get_content_type/get_content_type.module
ViewVC logotype

Contents of /contributions/modules/get_content_type/get_content_type.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Mon Mar 3 18:09:50 2008 UTC (20 months, 3 weeks ago) by nancyw
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
File MIME type: text/x-php
Corrected spelling of arguments in menu.
1 <?php
2 /* $Id $ */
3
4 /**
5 * Function to query the database for the requested types.
6 * @param $type - the content type to display. Passed through filter_xss.
7 * @param $teaser - show just the teaser (value: TRUE, default) or full node (value: FALSE).
8 * @param $show_per_page - how many nodes to show per page, defaults to post settings value.
9 * @return - themed nodes list.
10 */
11 function node_get_by_type($type = null, $teaser = true, $show_per_page = 0) {
12 $output = null;
13 if (!$type) {
14 return drupal_get_form('get_content_type_form');
15 }
16
17 if ($show_per_page) {
18 $nodes_per_page = filter_xss($show_per_page);
19 }
20 else {
21 $nodes_per_page = variable_get('default_nodes_main', 10);
22 }
23
24 if (is_string($teaser)) {
25 // Default to true if it's anything other than "false".
26 // Note that this obviates a need for filter_xss.
27 $teaser = strtolower($teaser) == 'false' ? false : true;
28 }
29
30 $stuff = node_get_types('type', $type);
31 drupal_set_title($stuff->name .' content');
32 if ($stuff->description) {
33 $output .= theme('type_description', $stuff->description);
34 }
35
36 // Process the type string.
37 $type_list = implode("', '", explode(' ', filter_xss($type)));
38
39 // Select nodes of the requested type.
40 $results = pager_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status=1 AND n.type IN ('". $type_list ."') ORDER BY n.sticky DESC, n.created DESC"), $nodes_per_page);
41 $nodes_found = false;
42
43 while ($item = db_fetch_array($results)) {
44 $node = node_load($item['nid']);
45 $output .= node_view($node, $teaser, false, true);
46 $nodes_found = true;
47 } /* end while */
48
49 drupal_add_feed(url('node/type/'. $type .'/feed'), t('RSS - !type', array('!type' => $stuff->name)));
50 if ($nodes_found) {
51 return $output . theme('pager', NULL, $nodes_per_page);
52 }
53 else {
54 return t('There were no nodes found of the @type type.', array('@type' => $type));
55 }
56 }
57
58 /**
59 * Menu callback; displays an RSS feed containing recent entries of a given type
60 */
61 function node_get_by_type_feed($type) {
62 $type = filter_xss($type);
63 $stuff = node_get_types('type', $type);
64 if (!$stuff) {
65 drupal_not_found();
66 }
67
68 $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type='%s' AND n.status=1 ORDER BY n.created DESC"), $type, 0, variable_get('default_nodes_main', 10));
69 $channel['title'] = variable_get('site_name', 'Drupal') .' '. $stuff->name;
70 $channel['link'] = url('node/type/'. $type, array('absolute' => TRUE));
71
72 $items = array();
73 while ($row = db_fetch_object($result)) {
74 $items[] = $row->nid;
75 }
76
77 node_feed($items, $channel);
78 }
79
80 /**
81 * Form to build URL for displaying content types.
82 */
83 function get_content_type_form() {
84 $form = array();
85
86 $node_types = node_get_types('names');
87 $form['types'] = array(
88 '#type' => 'checkboxes',
89 '#options' => $node_types,
90 '#title' => t('Content types'),
91 '#description' => t('Choose the content types you wish to display.'),
92 '#required' => true,
93 );
94
95 $form['teaser'] = array(
96 '#type' => 'checkbox',
97 '#title' => t('Show teaser'),
98 '#description' => t('Show the content in teaser format.'),
99 '#default_value' => true,
100 '#required' => true,
101 );
102
103 $form['how_many'] = array(
104 '#type' => 'textfield',
105 '#title' => t('How many per page'),
106 '#description' => t('The display will be formatted into a series of pages with this many posts per page.'),
107 '#default_value' => variable_get('default_nodes_main', 10),
108 '#required' => true,
109 );
110
111 $form['submit'] = array(
112 '#type' => 'submit',
113 '#value' => t('Show my selections'),
114 '#weight' => 3,
115 );
116
117 return $form;
118 }
119
120 /**
121 * Form_submit to build URL for displaying content types.
122 */
123 function get_content_type_form_submit($form, &$form_state) {
124 $bool = array('false', 'true');
125 $types = array();
126 foreach ($form_state['values']['types'] as $type => $selected) {
127 if ($selected) {
128 $types[] = $type;
129 }
130 }
131
132 $form_state['redirect'] = 'node/type/'. implode(' ', $types) .'/'. $bool[$form_state['values']['teaser']] .'/'. $form_state['values']['how_many'];
133 }
134
135 /**
136 * Implementation of hook_theme().
137 */
138 function get_content_type_theme() {
139 return array(
140 'type_description' => array(
141 'arguments' => array('description'),
142 ),
143 );
144 }
145
146 /**
147 * Function to show the description of the type.
148 * @ingroup - themable.
149 * @param - $description - the description of the node type.
150 * @return - themed HTML string.
151 */
152 function theme_type_description($description) {
153 return '<p><em>('. $description .')</em></p><hr/><br/>';
154 }
155
156 /**
157 * Implementation of hook_menu
158 */
159 function get_content_type_menu() {
160 $items = array();
161
162 $items['node/type'] = array(
163 'title' => 'List nodes of a specified type.',
164 'page callback' => 'node_get_by_type',
165 'access arguments' => array('access content'),
166 'type' => MENU_CALLBACK,
167 );
168
169 $items['node/type/%/feed'] = array(
170 'title' => 'List nodes of a specified type.',
171 'page callback' => 'node_get_by_type_feed',
172 'page arguments' => array(2),
173 'access arguments' => array('access content'),
174 'type' => MENU_CALLBACK,
175 );
176
177 return $items;
178 }
179
180 /**
181 * Implementation of hook_help().
182 */
183 function get_content_type_help($path, $args) {
184 // drupal_set_message($path);
185 switch ($section) {
186 case 'admin/help#get_content_type':
187 return t('The get_content_type module fills an oversight by the D5 developers. When they moved the part of CCK (sometimes called CCK-Lite) into core for creating new content types, they forgot the analog to "taxonomy/term/xxx," that is "node/type/xxx." This simple module provides that function.');
188 }
189 }

  ViewVC Help
Powered by ViewVC 1.1.2