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

Contents of /contributions/modules/slfeed/slfeed.module

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


Revision 1.1 - (show annotations) (download) (as text)
Sun Aug 26 09:12:44 2007 UTC (2 years, 3 months ago) by taran
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Initial Release, SLFeed Module.
1 <?php
2 // $Id: slfeed.module,v 1.16.2.4 2006/01/13 04:03:18 Taran Rampersad/Nobody Fugazi Exp $
3
4 /**
5 * Implementation of hook_help
6 *
7 * @return string
8 */
9 function slfeed_help($section='') {
10 $output = '';
11
12 switch ($section) {
13 case 'admin/modules#description':
14 $output = t('Provides a SecondLife readable text file which serves as a feed within SL- *NOT* on the web.');
15 break;
16 case 'admin/settings/slfeed':
17 if (user_access('administer slfeed')) {
18 $output = t('This module will become outdated when Linden Script Language handles application/xml properly');
19 }
20 break;
21 case "admin/help/#slfeed" :
22 $output = t('This module will become outdated when Linden Script Language handles application/xml properly');
23 break;
24
25 }
26 return $output;
27 }
28
29 /**
30 * Valid permissions for the slfeed module
31 *
32 * @return array An array of valid permissions for the slfeed module
33 */
34 function slfeed_perm() {
35 return array('administer slfeed');
36 }
37
38 /**
39 * Implementation of hook_menu
40 *
41 * @return array
42 */
43 function slfeed_menu($may_cache) {
44 $items = array();
45 if ($may_cache) {
46 $items[] = array('path' => 'slfeed/feed', 'title' => t('slfeed feed'),
47 'callback' => 'slfeed_feed',
48 'access' => user_access('access content'),
49 'type' => MENU_CALLBACK);
50 $items[] = array('path' => 'blog/slfeed/feed', 'title' => t('slfeed blog feed'),
51 'callback' => 'slfeed_blog_feed',
52 'access' => user_access('access content'),
53 'type' => MENU_CALLBACK);
54 }
55 if (is_numeric(arg(1))) {
56 $items[] = array('path' => 'blog/'. arg(1) .'/slfeed/feed', 'title' => t('slfeed blog feed'),
57 'callback' => 'slfeed_user_blog_feed',
58 'access' => user_access('access content'),
59 'type' => MENU_CALLBACK);
60 }
61 return $items;
62 }
63
64 /**
65 * Produces an slfeed 1.0 feed for the front page content.
66 */
67 function slfeed_feed() {
68 if(strpos(arg(2), 'slfeed') === 0 || strpos(arg(2), 'feed') === 0) {
69 die(drupal_not_found());
70 }
71 global $base_url;
72 $nodes = db_query_range("SELECT n.nid FROM {node} n WHERE n.promote = '1' AND n.status = '1' ORDER BY n.created DESC", 0, variable_get('slfeed_feed_entries', 15));
73
74 $feed_info = array();
75 $feed_info['title'] = strip_tags(variable_get('site_name', 'Drupal'));
76 $feed_info['subtitle'] = strip_tags(variable_get('site_slogan', ''));
77 $feed_info['html_url'] = $base_url;
78 $feed_info['slfeed_url'] = url('slfeed/feed', NULL, NULL, true);
79 _slfeed_print_feed($nodes, $feed_info);
80 }
81
82 function slfeed_blog_feed() {
83 if(strpos(arg(3), 'slfeed') === 0 || strpos(arg(3), 'feed') === 0) {
84 die(drupal_not_found());
85 }
86 $nodes = db_query_range("SELECT n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = '1' ORDER BY n.created DESC", 0, variable_get('slfeed_feed_entries', 15));
87
88 $feed_info = array();
89 $feed_info['title'] = strip_tags(sprintf(t('%s blogs'), variable_get('site_name', 'Drupal')));
90 $feed_info['subtitle'] = strip_tags(variable_get('site_slogan', ''));
91 $feed_info['html_url'] = url('blog', NULL, NULL, true);
92 $feed_info['slfeed_url'] = url('blog/slfeed/feed', NULL, NULL, true);
93 _slfeed_print_feed($nodes, $feed_info);
94 }
95
96 function slfeed_user_blog_feed() {
97 if(strpos(arg(4), 'slfeed') === 0 || strpos(arg(4), 'feed') === 0) {
98 die(drupal_not_found());
99 }
100 $user_result = db_query_range("SELECT u.name FROM {users} u WHERE u.uid = %d", arg(1), 0, 1);
101 if(!$user = db_result($user_result)) {
102 return t('User does not exist.');
103 }
104
105 $nodes = db_query_range("SELECT n.nid FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = '1' ORDER BY n.created DESC", arg(1), 0, variable_get('slfeed_feed_entries', 15));
106
107 $feed_info = array();
108 $feed_info['title'] = sprintf(t("%s's blog"), $user);
109 $feed_info['html_url'] = url('blog/'. arg(1), NULL, NULL, true);
110 $feed_info['slfeed_url'] = url('blog/'. arg(1) .'/slfeed/feed', NULL, NULL, true);
111 _slfeed_print_feed($nodes, $feed_info);
112 }
113
114 /**
115 * prints feed information from query of either front page or blog content
116 *
117 * @param object $nodes query result
118 * @param array feed information
119 */
120 function _slfeed_print_feed($nodes, $feed_info) {
121 $output = '';
122 $last_mod = 0;
123 while ($node = db_fetch_object($nodes)) {
124 $item = node_load(array('nid' => $node->nid));
125 $link = url("node/$node->nid", NULL, NULL, true);
126
127 $output .= '<d>'. check_plain(strip_tags($item->title)) .'</d>';
128
129 $output .= '<d>'. $link .'</d>';
130 }
131
132 //drupal_set_header('Content-Type: text/content');
133 print $output;
134 }
135
136 /**
137 * Module configuration settings
138 *
139 * @return array of settings form options or deny access
140 */
141 function slfeed_settings() {
142 if (!user_access('administer slfeed')) {
143 die(drupal_access_denied());
144 }
145 $form = array();
146 for($i=1, $options=array(); $i < 31; $options[$i] = $i, $i+=1);
147 $form['slfeed_feed_entries'] = array(
148 '#type' => 'select',
149 '#title' => t('Maximum number of entries to include in feeds'),
150 '#default_value' => variable_get('slfeed_feed_entries', 10),
151 '#options' => $options
152 );
153 return $form;
154 }
155
156 ?>

  ViewVC Help
Powered by ViewVC 1.1.2