/[drupal]/contributions/modules/drupalorg/drupalorg_news/drupalorg_news.module
ViewVC logotype

Contents of /contributions/modules/drupalorg/drupalorg_news/drupalorg_news.module

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


Revision 1.16 - (show annotations) (download) (as text)
Fri Sep 11 06:08:00 2009 UTC (2 months, 2 weeks ago) by drumm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.15: +1 -37 lines
File MIME type: text/x-php
Removing dead code
1 <?php
2 // $Id: drupalorg_news.module,v 1.15 2009/08/26 07:15:30 drumm Exp $
3
4 /**
5 * @file
6 * Custom code for the news page, planet Drupal and similar pages.
7 */
8
9 /**
10 * Vocabulary used for news forum topic tagging.
11 */
12 define('DRUPALORG_NEWS_VID', 34);
13
14 /**
15 * Planet Drupal category in the aggregator.
16 */
17 define('DRUPALORG_PLANET_CATEGORY', 2);
18
19 // == Core hooks ===============================================================
20
21 /**
22 * Implementation of hook_menu().
23 */
24 function drupalorg_news_menu() {
25 $items['news'] = array(
26 'title' => 'News',
27 'page callback' => 'drupalorg_news_page',
28 'access arguments' => array('access content'),
29 'type' => MENU_CALLBACK,
30 );
31 $items['news/%drupalorg_news_term'] = array(
32 'title' => 'News',
33 'page callback' => 'drupalorg_news_page',
34 'page arguments' => array(1),
35 'access arguments' => array('access content'),
36 'type' => MENU_CALLBACK,
37 );
38 return $items;
39 }
40
41 /**
42 * Menu loader. Load news term if it is indeed from the given vocabulary.
43 */
44 function drupalorg_news_term_load($tid) {
45 if (($term = taxonomy_get_term($tid)) && ($term->vid = DRUPALORG_NEWS_VID)) {
46 return $term;
47 }
48 return NULL;
49 }
50
51 /**
52 * One of the most visited pages of the site, so hardcode queries.
53 */
54 function drupalorg_news_page($term) {
55 if (!isset($tid)) {
56 $result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10));
57 // Add existing "front page" feed if main news page.
58 $feed_url = url('rss.xml', array('absolute' => TRUE));
59 drupal_add_feed($feed_url, variable_get('site_name', 'Drupal') .' '. t('RSS'));
60 }
61 else {
62 $result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n LEFT JOIN {term_node} t ON t.vid = n.vid WHERE n.promote = 1 AND n.status = 1 AND t.tid = %d ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10), 0, NULL, $term->tid);
63 }
64
65 $output = '';
66 while ($node = db_fetch_object($result)) {
67 $output .= node_view(node_load($node->nid), 1);
68 }
69 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
70 return $output;
71 }
72
73 // == Altering existing behavior ===============================================
74
75 /**
76 * Implementation of hook_form_alter().
77 */
78 function drupalorg_news_form_alter(&$form, $form_state, $form_id) {
79 // Remove the news vocabulary on forum forms, if the user is not an admin.
80 // Used to mark news forum topics with tags.
81 if ($form_id == 'forum_node_form') {
82 $form['taxonomy'][DRUPALORG_NEWS_VID]['#access'] = user_access('administer nodes');
83 }
84 }
85
86 /**
87 * Implementation of template_preprocess_drupalorg_home().
88 *
89 * @todo
90 * Add caching.
91 */
92 function drupalorg_news_preprocess_drupalorg_home(&$vars) {
93 // Get the first three news items ordered by descending publication date.
94 $result = db_query_range('SELECT nid FROM {node} WHERE promote = 1 ORDER BY created DESC', array(), 0, 4);
95 $fresh_news = '';
96 $news_count = 0;
97 while ($nid = db_fetch_object($result)) {
98 $node = node_load($nid->nid);
99 if ($news_count == 0) {
100 // The first news item has a blurb displayed.
101 $fresh_news .= '<h6>'. l($node->title, 'node/'. $node->nid) .'</h6>';
102 $fresh_news .= '<p class="submitted">'. format_date($node->created, 'custom', 'F j, Y') .'</p>';
103 // Cut it to short and sweet to fit into the design. Strip all tags,
104 // so things like big images, distracting links and paragraph tags will
105 // not end up here. The text should be good in itself to display.
106 $fresh_news .= '<p>'. node_teaser(strip_tags($node->teaser), $node->format, 180) .' '. l(t('Read more'), 'node/'. $node->nid) .'</p>';
107 }
108 else {
109 // Rest of the items have just their title displayed.
110 $fresh_news .= '<p>'. l($node->title, 'node/'. $node->nid) .'</p>';
111 }
112 $news_count++;
113 }
114 // Finally, we have a link to the rest of the items
115 $fresh_news .= '<p>'. l(t('More news...'), 'news') .'</p>';
116 $vars['tab_content_news'] = $fresh_news;
117 }
118
119 // == Blocks for news and planet ===============================================
120
121 /**
122 * Implementation of hook_block().
123 */
124 function drupalorg_news_block($op = 'list', $delta = 0, $edit = array()) {
125 switch ($op) {
126 case 'list':
127 $blocks['planet-list']['info'] = t('Planet Drupal subscriptions');
128 $blocks['news-terms']['info'] = t('News category filter links');
129 return $blocks;
130
131 case 'view':
132 switch ($delta) {
133 case 'planet-list':
134 $block['subject'] = t('Planet Drupal subscriptions');
135 $block['content'] = drupalorg_news_planet_drupal_block();
136 return $block;
137 case 'news-terms':
138 $block['subject'] = t('Filter news');
139 $block['content'] = drupalorg_news_filter_news();
140 return $block;
141 }
142 }
143 }
144
145 /**
146 * Block to show the list of sources for the Planet as well as their count.
147 */
148 function drupalorg_news_planet_drupal_block() {
149 $output = '';
150 $description = db_result(db_query("SELECT description FROM aggregator_category WHERE cid = %d", DRUPALORG_PLANET_CATEGORY));
151 $result = db_query('SELECT f.* FROM {aggregator_feed} f JOIN {aggregator_category_feed} c ON f.fid = c.fid WHERE c.cid = %d ORDER BY f.title', DRUPALORG_PLANET_CATEGORY);
152
153 $list = '<div class="item-list"><ul>';
154 $counter = 0;
155 while ($feed = db_fetch_object($result)) {
156 $list .= '<li>'. l($feed->title, $feed->link) .' ('. l('feed', $feed->url) .')</li>';
157 $counter++;
158 }
159 $list .= '</ul></div>';
160
161 $output .= '<p>'. filter_xss_admin($description) .' '. t('Collecting posts from the following @num sources:', array('@num' => $counter)) .'</p>';
162 $output .= $list;
163 $output .= theme('xml_icon', url('planet/rss.xml'));
164
165 return $output;
166 }
167
168 /**
169 * News filtering by taxonomy term for the frontpage.
170 */
171 function drupalorg_news_filter_news() {
172 $tree = taxonomy_get_tree(DRUPALORG_NEWS_VID);
173 $list_of_terms = array(array('title' => t('All news'), 'href' => 'news'));
174 foreach ($tree as $term) {
175 $list_of_terms[] = array('title' => $term->name, 'href' => 'news/'. $term->tid);
176 }
177 // Using theme links should mark active links with a class, so styling
178 // can be applied to them properly.
179 return theme('links', $list_of_terms);
180 }

  ViewVC Help
Powered by ViewVC 1.1.2