Merge lp://qastaging/~m-baert/ubuntu-drupal-planet/6.x into lp://qastaging/~swe3tdave-deactivatedaccount/ubuntu-drupal-planet/6.x

Proposed by David Giard
Status: Merged
Merged at revision: 17
Proposed branch: lp://qastaging/~m-baert/ubuntu-drupal-planet/6.x
Merge into: lp://qastaging/~swe3tdave-deactivatedaccount/ubuntu-drupal-planet/6.x
Diff against target: None lines
To merge this branch: bzr merge lp://qastaging/~m-baert/ubuntu-drupal-planet/6.x
Reviewer Review Type Date Requested Status
David Giard Approve
Review via email: mp+4715@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
David Giard (swe3tdave-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'planet.info'
--- planet.info 2009-03-01 02:54:23 +0000
+++ planet.info 2009-03-14 00:23:25 +0000
@@ -1,6 +1,7 @@
1; $Id: planet.info,v 1.2 2007/05/30 03:22:01 daryl Exp $1; $Id: planet.info,v 1.2 2007/05/30 03:22:01 daryl Exp $
2name = Planet2name = Planet
3description = Planet blog aggregator3description = Planet blog aggregator
4; TODO better module definition, including specificity if possible.
4package = Community - optional5package = Community - optional
5version = 6.x6version = 6.x
6core = 6.x7core = 6.x
78
=== modified file 'planet.install'
--- planet.install 2009-03-01 03:00:14 +0000
+++ planet.install 2009-03-14 00:23:25 +0000
@@ -10,37 +10,43 @@
10 'description' => t('The base table for planet.'),10 'description' => t('The base table for planet.'),
11 'fields' => array(11 'fields' => array(
12 'fid' => array(12 'fid' => array(
13 'description' => t('The primary identifier for a planet_feeds table.'), 13 'description' => t('Primary Key: Unique identifier for a planet RSS feed.'),
14 'type' => 'serial',14 'type' => 'serial',
15 'unsigned' => TRUE,15 'unsigned' => TRUE,
16 'not null' => TRUE,16 'not null' => TRUE,
17 ),17 ),
18 'uid' => array( 18 'uid' => array(
19 'description' => t('Foreign key to {users}.uid . Identifies user who choose the feed.'),
19 'type' => 'int',20 'type' => 'int',
20 'unsigned' => 1,21 'unsigned' => 1,
21 'not null' => FALSE,22 'not null' => FALSE,
22 ),23 ),
23 'title' => array( 24 'title' => array(
24 'type' => 'varchar',25 'type' => 'varchar',
26 'description' => t('Title of the feed.'),
25 'length' => 50,27 'length' => 50,
26 'not null' => TRUE,28 'not null' => TRUE,
27 ),29 ),
28 'link' => array( 30 'link' => array(
29 'type' => 'varchar',31 'type' => 'varchar',
32 'description' => t('URL to the feed'),
30 'length' => 80,33 'length' => 80,
31 'not null' => TRUE,34 'not null' => TRUE,
32 ),35 ),
33 'image' => array(36 'image' => array(
37 'description' => t('An image representing the feed'),
34 'type' => 'varchar',38 'type' => 'varchar',
35 'length' => 120,39 'length' => 120,
36 'not null' => FALSE,40 'not null' => FALSE,
37 ),41 ),
38 'checked' => array( 42 'checked' => array(
43 'description' => t('Last time feed was checked for new items, as Unix timestamp'),
39 'type' => 'int',44 'type' => 'int',
40 'not null' => FALSE,45 'not null' => FALSE,
41 ),46 ),
42 'frozen' => array( 47 'frozen' => array(
43 'type' => 'int', 48 // TODO: add field description 'description' => t(''),
49 'type' => 'int', // TODO change to boolean when supported
44 'not null' => TRUE,50 'not null' => TRUE,
45 'default' => 0,51 'default' => 0,
46 ),52 ),
@@ -52,7 +58,7 @@
52 'description' => t('contain feed id and its corresponding nid'),58 'description' => t('contain feed id and its corresponding nid'),
53 'fields' => array(59 'fields' => array(
54 'id' => array(60 'id' => array(
55 'description' => t('The primary identifier for a planet_items table'),61 'description' => t('Primary key: Unique identifier for a planet feed item'),
56 'type' => 'serial',62 'type' => 'serial',
57 'unsigned' => 1,63 'unsigned' => 1,
58 'not null' => TRUE,64 'not null' => TRUE,
@@ -91,11 +97,9 @@
91/**97/**
92 * Implementation of hook_install()98 * Implementation of hook_install()
93 *99 *
94 * This will automatically install the database tables for the planet module for MySQL.100 * This will automatically install the database tables for the planet
95 *101 * module, using Drupal's data abstraction layer.
96 * If you are using another database, you will have to install the tables by hand, using the queries below as a reference.102 *
97 *
98 *
99 */103 */
100104
101function planet_install() {105function planet_install() {
@@ -106,9 +110,9 @@
106/**110/**
107 * Implementation of hook_uninstall()111 * Implementation of hook_uninstall()
108 *112 *
109 * This will automatically uninstall the database tables for the planet module for MySQL.113 * Uninstalls planet module by removing its own database tables, nodes
114 * and persistent variables.
110 * 115 *
111 *
112 */116 */
113117
114function planet_uninstall() {118function planet_uninstall() {
115119
=== modified file 'planet.module'
--- planet.module 2009-03-08 19:00:05 +0000
+++ planet.module 2009-03-20 16:05:00 +0000
@@ -1,48 +1,92 @@
1<?php1<?php
2// $Id: planet.install Exp $2// $Id: planet.install Exp $
33
4/**4 /**
5 * @file5 * @file
6 * The planet module6 * The planet module.
7 *
8 * Planet is an aggregator that allows you to aggregate the blogs for
9 * users in a given role (e.g. staff) and associate content with the
10 * users rather than as a detached feed. This provides the benefit of
11 * showing avatars with content, providing per-user aggregation of
12 * planet content in addition to blog content, etc.
7 * 13 *
8 */14 */
915
16/**
17 * Implementation of hook_node_info.
18 *
19 * @return An array of information on the module's node types.
20 *
21 * @ingroup planet_node
22 */
10function planet_node_info() {23function planet_node_info() {
11 return array(24 return array(
12 'planet' => array(25 'planet' => array(
13 'name' => t('Planet Entry'),26 'name' => t('Planet Entry'),
14 'module' => 'planet',27 'module' => 'planet',
15 'description' => t('Node to contain posts aggregated from various blogs.'),28 'description' => t('Node to contain posts aggregated from various blogs.'),
16 )29 )
17 );30 );
18}31}
1932
20/**33/**
21 * Implementation of hook_perm.34 * Implementation of hook_perm - Defines user permissions.
35 * The suggested naming convention for permissions is "action_verb modulename".
36 *
37 * @return An array of permissions strings.
38 *
39 * @ingroup base
22 */40 */
23function planet_perm() {41function planet_perm() {
24 return array('administer planet', 'administer own planet feeds');42 return array('administer planet', 'administer own planet feeds', 'view all planet nodes');
25}43}
2644
45/**
46 * Implementation of hook_help - Provides online user help.
47 *
48 * @param $path A Drupal menu router path the help is being requested for
49 * @param $arg
50 * @return A localized string containing the help text.
51 *
52 * @ingroup base
53 */
27function planet_help($path, $arg) {54function planet_help($path, $arg) {
28 switch ($path) {55 switch ($path) {
29 case 'admin/help/planet':56 case 'admin/help#planet':
57 // The module's help text, displayed on the admin/help page and through the module's individual help link.
30 $output = '<p>Planet is an aggregator that allows you to aggregate the blogs for users in a given role (e.g. staff) and associate content with the users rather than as a detached feed. This provides the benefit of showing avatars with content, providing per-user aggregation of planet content in addition to blog content, etc.</p>';58 $output = '<p>Planet is an aggregator that allows you to aggregate the blogs for users in a given role (e.g. staff) and associate content with the users rather than as a detached feed. This provides the benefit of showing avatars with content, providing per-user aggregation of planet content in addition to blog content, etc.</p>';
31 $output .= '<p>To use planet, go to admin/settings/planet and note the following sections:</p>';59 $output .= '<p>To use planet, go to admin/settings/planet and note the following sections:</p>';
32 $output .= '<ul>';60 $output .= '<ul>';
33 $output .= '<li><strong>General Settings</strong>. The role to select bloggers from lets you narrow the user list for when you\'re adding a feed and associating it with a user. A common setting will be to create a staff role and use this for planet.</li>';61 $output .= '<li><strong>General Settings</strong>. The role to select bloggers from lets you narrow the user list for when you\'re adding a feed and associating it with a user. A common setting will be to create a staff role and use this for planet.</li>';
34 $output .= '<li><strong>Feeds</strong>. This section lets you add a new feed. Give it a title, select an author, provide the feed url, and you\'re off. You\'ll have to manually refresh it or wait for a cron run for items to be imported.</li>';62 $output .= '<li><strong>Feeds</strong>. This section lets you add a new feed. Give it a title, select an author, provide the feed url, and you\'re off. You\'ll have to manually refresh it or wait for a cron run for items to be imported.</li>';
35 $output .= '<li><strong>Feeds</strong>. This section lists current feeds, when they were last updated, how many items they have, and it allows you to edit, refresh, or freeze them. Freezing is a quick way to temporarily suspend updates from the given feed.</li>';63 $output .= '<li><strong>Feeds</strong>. This section lists current feeds, when they were last updated, how many items they have, and it allows you to edit, refresh, or freeze them. Freezing is a quick way to temporarily suspend updates from the given feed.</li>';
64 // @DIFFGROUP output syntax
65 $output .= '</ul>';
36 return $output;66 return $output;
37 case 'admin/modules#description':67 // @DIFFINFO in D6, admin/modules#description is moved to .info file
38 return t('Aggregates RSS feeds and faciliates their association with site users who belong to a given role.');
39 }68 }
40}69}
4170
42function planet_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {71/**
72 * Implementation of hook_view() - Displays a planet node.
73 *
74 * @param $node The node to be displayed.
75 * @param $teaser Whether to generate only a summary ("teaser") of the node.
76 * @param $page Whether the node is being displayed as a standalone page.
77 * @return The modified $node parameter, properly presented for output.
78 *
79 * @ingroup planet_node
80 * @CRUD{variables,R}
81 * @CRUD{planet_items,R}
82 */
83function planet_view($node, $teaser = FALSE, $page = FALSE) {
84 // @DIFFINFO removed $link param to match D6 hook definition
43 if ($page === true && variable_get('planet_redirect_page', 0) == 1) {85 if ($page === true && variable_get('planet_redirect_page', 0) == 1) {
44 $obj = db_fetch_object(db_query('SELECT * FROM {planet_items} WHERE nid = %d', $node->nid));86 // @DIFFINFO only 'link' field is used, so I restricted the query
45 if ($obj->nid == $node->nid && $obj->link != '') {87 $obj = db_fetch_object(db_query('SELECT link FROM {planet_items} WHERE nid = %d', $node->nid));
88 // @DIFFINFO if the query succeeds, $obj->nid == $node->nid , otherwise, $obj==FALSE,
89 if ($obj && $obj->link != '') {
46 header('Location: '. $obj->link);90 header('Location: '. $obj->link);
47 exit;91 exit;
48 }92 }
@@ -52,22 +96,51 @@
52 }96 }
53}97}
5498
99/**
100 * Implementation of hook_access() - Define access permissions for planet nodes (aka CRUD) .
101 * @param $op The operation to be performed: 'create', 'view', 'update', 'delete'
102 * @param $node The node on which the operation is to be performed, or, if it does not yet exist, the type of node to be created.
103 * @param $account A user object representing the user for whom the operation is to be performed.
104 * @return true if the user is allowed to perform operation, false otherwise.
105 *
106 * @ingroup planet_node
107 */
55function planet_access($op, $node, $account) {108function planet_access($op, $node, $account) {
56109 // @DIFFINFO using planet-dedicated permissions
57110 // Planet administrator has all permissions related to planet module
111 if (user_access('administer planet', $account))
112 return TRUE;
113 // Users allowed to edit their own planet nodes, are also allowed to create them, others are not.
114 $author = user_access('edit own planet feeds', $account);
58 if ($op == 'create') {115 if ($op == 'create') {
59 return user_access('edit own blog', $account) && $account->uid;116 return $author;
60 }117 }
61118
119 // Does current user own requested node ?
120 $own = $account->uid == $node->uid;
121 if ($op == 'view')
122 return $own || user_access('view all planet nodes');
62 if ($op == 'update' || $op == 'delete') {123 if ($op == 'update' || $op == 'delete') {
63 if (user_access('edit own blog', $account) && ($account->uid == $node->uid) || user_access('administer nodes', $account)) {124 return $author && $own; // ok if $author owns the node
64 return TRUE;
65 }
66 }125 }
126 trigger_error("Unknown operation requested: $op");
127 return FALSE;
67}128}
68129
130/**
131 * Implementation of hook_menu() - Defines menu items and page callbacks.
132 *
133 * @return An array of menu items.
134 * Each menu item has a key corresponding to the Drupal path being registered.
135 *
136 * @ingroup base
137 *
138 * This diagram shows how requests are handled.
139 * Each arrow is labeled with the permission required to access link.
140 * The menu item colors reflect the item type.
141 * @dotfile menu-links.dot "Menus and Pages"
142 */
69function planet_menu() {143function planet_menu() {
70
71 $items['admin/settings/planet'] = array(144 $items['admin/settings/planet'] = array(
72 'title' => 'Planet Settings',145 'title' => 'Planet Settings',
73 'description' => 'Configure settings for the planet module.',146 'description' => 'Configure settings for the planet module.',
@@ -84,31 +157,28 @@
84 );157 );
85 158
86 // if (arg(0) == 'planet' && is_numeric(arg(1))) {159 // if (arg(0) == 'planet' && is_numeric(arg(1))) {
160 // FIXME access denied http://localhost/drupal/?q=planet/1
87 $items['planet/'. '%'] = array(161 $items['planet/'. '%'] = array(
88 'title' => 'planet',162 'title' => 'planet',
89 'page callback' => 'planet_page_user',163 'page callback' => 'planet_page_user',
90 'page arguments' => array(arg(1))164 'page arguments' => array(arg(1))
91 );165 );
92// }
93166
94// if (arg(3) == 'refresh' && is_numeric(arg(4))) {167 // if (arg(3) == 'refresh' && is_numeric(arg(4))) {
95
96 $items['admin/settings/planet/refresh/%'] = array(168 $items['admin/settings/planet/refresh/%'] = array(
97 'title' => 'planet refresh',169 'title' => 'planet refresh',
98 'page callback' => 'planet_call_refresh',170 'page callback' => 'planet_call_refresh',
99 'access arguments' => array('administer nodes'),171 'access arguments' => array('administer nodes'),
100 'type' => MENU_CALLBACK172 'type' => MENU_CALLBACK
101 );173 );
102// }
103174
104// if (is_numeric(arg(4)) && (arg(3) == 'freeze' || arg(3) == 'unfreeze')) {175 // if (is_numeric(arg(4)) && (arg(3) == 'freeze' || arg(3) == 'unfreeze')) {
105 $items['admin/settings/planet/'. arg(3) .'/%'] = array(176 $items['admin/settings/planet/'. arg(3) .'/%'] = array(
106 'title' => 'planet freeze',177 'title' => 'planet freeze',
107 'page callback' => 'planet_toggle_frozen',178 'page callback' => 'planet_toggle_frozen',
108 'access arguments' => array('administer nodes'),179 'access arguments' => array('administer nodes'),
109 'type' => MENU_CALLBACK180 'type' => MENU_CALLBACK
110 );181 );
111// }
112182
113 $items['planet'] = array(183 $items['planet'] = array(
114 'title' => 'Planet',184 'title' => 'Planet',
@@ -128,6 +198,12 @@
128 return $items;198 return $items;
129}199}
130200
201
202/**
203 * Page callback for 'admin/settings/planet/refresh/%' ("planet refresh")
204 *
205 * @ingroup page
206 */
131function planet_call_refresh() { 207function planet_call_refresh() {
132 $title = planet_refresh();208 $title = planet_refresh();
133 watchdog('planet', 'Feed "'. $title .'" refreshed.');209 watchdog('planet', 'Feed "'. $title .'" refreshed.');
@@ -135,6 +211,12 @@
135 drupal_goto('admin/settings/planet');211 drupal_goto('admin/settings/planet');
136}212}
137213
214/**
215 * Page callback for 'admin/settings/planet/(un|)freeze/%' ("planet freeze")
216 *
217 * @ingroup page
218 * @CRUD{planet_feeds,U}
219 */
138function planet_toggle_frozen() {220function planet_toggle_frozen() {
139 221
140 $fid = intval(arg(4));222 $fid = intval(arg(4));
@@ -144,53 +226,57 @@
144}226}
145227
146228
229/**
230 * Deletes a feed and related items
231 * @param $fid the feed identifier key (integer)
232 *
233 * @internal
234 * @ingroup planet_feed
235 * @CRUD{planet_items,R}
236 * @invoke{drupal_get_form,planet_multiple_delete_confirm}
237 */
238function planet__drop_feed($fid) {
239 $result = db_query('SELECT nid FROM {planet_items} WHERE fid = %d', intval($edit['fid']));
240 while ($node = db_fetch_object($result)) {
241 $nodes[$node->nid] = TRUE;
242 }
243 return drupal_get_form('planet_multiple_delete_confirm', $nodes,
244 intval($edit['fid']), 'user/'. $user->uid .'/planet');
245}
246
247/**
248 * Page callback for 'user/%user/planet' ("Planet Feeds")
249 *
250 * @ingroup page
251 * @CRUD{planet_feeds,R}
252 * @invoke{drupal_get_form,planet_multiple_delete_confirm_submit}
253 * @invoke{drupal_get_form,planet_feed_form}
254 */
147function planet_user_feeds() {255function planet_user_feeds() {
148global $user;256 global $user;
149if ($_POST) { 257 if ($_POST) {
150 $edit = $_POST;258 $edit = $_POST;
151 if ($_POST['op'] == 'Delete' && intval($edit['fid']) > 0) {259 $fid = intval($edit['fid']);
152 $result = db_query('SELECT nid FROM {planet_items} WHERE fid = %d', intval($edit['fid']));260 if (($_POST['op'] == 'Delete') && ($fid != 0)) {
153 while ($node = db_fetch_object($result)) {261 return planet__drop_feed($fid);
154 $nodes[$node->nid] = TRUE;262 } else if ($_POST['op'] == 'Delete all' && $_POST['confirm'] == 1) {
155 }263 $edit['fid'] = intval(arg(3)); // @deprecated arg()
156 return drupal_get_form('planet_multiple_delete_confirm', $nodes, intval($edit['fid']), 'user/'. $user->uid .'/planet');
157 }
158 else if ($_POST['op'] == 'Delete all' && $_POST['confirm'] == 1) {
159 $edit['fid'] = intval(arg(3));
160 $edit['redirect'] = 'user/'. $user->uid .'/planet';264 $edit['redirect'] = 'user/'. $user->uid .'/planet';
161 return drupal_get_form('planet_multiple_delete_confirm_submit', $edit);265 return drupal_get_form('planet_multiple_delete_confirm_submit', $edit);
162 }266 } else {
163 else { 267 if (isset($edit['fid'])) {
164 if (isset($edit['fid']) && intval($edit['fid']) == 0) {268 if (intval($edit['fid']) == 0) {
165 db_query('INSERT INTO {planet_feeds} (uid, title, link, image, checked, frozen) VALUES(%d, "%s", "%s", "%s", 0, 0)', $user->uid, $edit['title'], $edit['link'], $edit['image']);269 planet__add_feed($edit);
166 $edit_r = db_fetch_array(db_query('SELECT fid FROM {planet_feeds} WHERE uid = %d AND title = "%s" AND link = "%s"', $user->uid, $edit['title'], $edit['link']));270 } else {
167 $title = planet_refresh(intval($edit_r['fid']));271 planet__update_feed($edit);
168 drupal_set_message('Added new feed: ' . $title); 272 }
169 }273 } else {
170 else if ($edit['fid'] && intval($edit['fid']) > 0) { 274 planet__update_vars($edit);
171 db_query('UPDATE {planet_feeds} SET uid = %d, title="%s", link = "%s", image="%s" WHERE fid=%d', $user->uid, $edit['title'], $edit['link'], $edit['image'], $edit['fid']);
172 drupal_set_message('Edited "'. $edit['title'] .'" feed.');
173 }
174 else {
175 if ($edit['planet_author_roles']) {
176 variable_set('planet_author_roles', $edit['planet_author_roles']);
177 }
178 if ($edit['planet_filter_formats']) {
179 variable_set('planet_filter_formats', $edit['planet_filter_formats']);
180 }
181 if ($edit['planet_redirect_page'] == 1) {
182 variable_set('planet_redirect_page', $edit['planet_redirect_page']);
183 }
184 else {
185 variable_del('planet_redirect_page');
186 }
187 drupal_set_message('Edited general planet settings.');
188 } 275 }
189 } 276 }
190 drupal_goto('user/'. $user->uid .'/planet'); 277 drupal_goto('user/'. $user->uid .'/planet');
191 }278 } else { // no $_POST
192 else { 279 $fid = intval(arg(3)); // @deprecated: arg()
193 $fid = intval(arg(3));
194 if ($fid > 0) { 280 if ($fid > 0) {
195 $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid));281 $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid));
196 $output .= drupal_get_form('planet_feed_form', $edit, true, $user);282 $output .= drupal_get_form('planet_feed_form', $edit, true, $user);
@@ -199,32 +285,143 @@
199 285
200 $output .= drupal_get_form('planet_feed_form', $edit, false, $user);286 $output .= drupal_get_form('planet_feed_form', $edit, false, $user);
201 287
202 // $result = db_query('SELECT *, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds}');288 $output .= '<h2>Feeds</h2>';
203 $result = db_query('SELECT COUNT(f.fid) cnt, f.*, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds} f LEFT OUTER JOIN {planet_items} i ON i.fid = f.fid WHERE f.uid = %d GROUP BY f.fid;', $user->uid);289 $output .= planet__build_user_feeds_table();
290 }
291 print theme('page', $output);
292 }
293}
294
295// Note: I use 'planet__' prefix to name internal functions
296// TODO: apply the same naming convention (this one or another) in whole module
297/**
298 * @todo merge with planet__build_admin_feeds_table()
299 *
300 * @ingroup planet_feed
301 * @internal
302 * @CRUD{planet_feeds,R}
303 * @CRUD{planet_items,R}
304 */
305function planet__build_user_feeds_table() {
306 // @DIFFINFO renamed planet__build_feeds_table1
307 global $user;
308 $feeds = db_query('SELECT fid, title, checked FROM {planet_feeds} '
309 . ' WHERE uid = %d;', $user->uid);
204 $rows = array();310 $rows = array();
205 $headers = array('Feed', 'Items', 'Edit', 'Last checked');311 $headers = array('Feed', 'Items', 'Edit', 'Last checked');
206 while ($feed = db_fetch_object($result)) {312 $now = time();
207 $checked = intval($feed->_checked / 60) .' minutes';313 $items_statement = 'SELECT count(*) FROM {planet_items}'
208 if ($feed->_checked % 60 > 0) {314 . ' WHERE fid=%d';
315 // TODO: change this to prepared statement when supported by drupal DB abstraction layer.
316 while ($feed = db_fetch_object($feeds)) {
317 $_checked = $now - $feed->checked;
318 $checked = intval($_checked / 60) .' minutes';
319 if ($_checked % 60 > 0) {
209 $checked .= ', '. $feed->_checked % 60 .' seconds';320 $checked .= ', '. $feed->_checked % 60 .' seconds';
210 }321 }
211 $checked .= ' ago';322 $checked .= ' ago';
323 $items = db_query($items_statement, $feed->fid);
324 if (!$items) trigger_error('ERROR while counting feed items.');
325 $cnt = db_result($items);
212 array_push($rows, array(326 array_push($rows, array(
213 $feed->title,327 $feed->title,
214 $feed->cnt,328 $cnt,
215 l('edit', 'user/'. $user->uid .'/planet/'. intval($feed->fid)),329 l('edit', 'user/'. $user->uid .'/planet/'. intval($feed->fid)),
216 $checked,330 $checked,
217 )331 )
218 );332 );
219 }333 }
220 $output .= '<h2>Feeds</h2>';334 return theme('table', $headers, $rows);
221 $output .= theme('table', $headers, $rows); 335}
222 }336
223 print theme('page', $output); 337/**
224 }338 * Adds a new feed to planet_feeds table.
225}339 * @param $data associative array with keys
226340 * 'uid' (optional), 'title', 'link', 'image' (optional)
227341 * @return success status
342 *
343 * @ingroup planet_feed
344 * @internal
345 * @CRUD{planet_feeds,C}
346 */
347function planet__add_feed($data) {
348 $data['checked'] = 0;
349 $data['frozen'] = 0;
350 if (isset($data['fid'])) { // @DEBUGGING
351 trigger_error('Primary key fid shouldn\'t be set for a need feed (value: {$data->fid}). Record not added.', E_ERROR);
352 return FALSE;
353 }
354 $rslt = drupal_write_record('planet_feeds', $data);
355 if ($rslt==SAVED_NEW) {
356 $title = planet_refresh(intval($data['fid']));
357 drupal_set_message('Added new feed: ' . $title);
358 return TRUE;
359 }
360 trigger_error('Failed to add new feed');
361 return FALSE;
362}
363
364/**
365 * Updates an existing feed in planet_feeds table.
366 * @param $data associative array with keys
367 * 'fid' (mandatory, primary key),
368 * other fields as needed:
369 * 'uid', 'title', 'link', 'image', 'checked', 'frozen'
370 * @return success status
371 *
372 * @ingroup planet_feed
373 * @internal
374 * @CRUD{planet_feeds,U}
375*/
376function planet__update_feed($data) {
377 $rslt = drupal_write_record('planet_feeds', $data, 'fid');
378 if ($rslt==SAVED_UPDATED) {
379 drupal_set_message('Edited "'. $data['title'] .'" feed.');
380 return TRUE;
381 }
382 if ($rslt==SAVED_NEW) // @DEBUGGING
383 trigger_error('Feed {$data->fid} didn\'t exist. Record added.', E_ERROR);
384 else
385 trigger_error('Failed to edit feed');
386 return FALSE;
387}
388
389/**
390 * Updates an planet settings persistent variables.
391 * @param $data associative array with all optional keys
392 * 'planet_author_roles', 'planet_filter_formats',
393 * 'planet_redirect_page'.
394 *
395 * @ingroup isettings
396 * @internal
397 * @CRUD{variables,CUD}
398*/
399function planet__update_vars($data) {
400 if ($edit['planet_author_roles']) {
401 variable_set('planet_author_roles', $edit['planet_author_roles']);
402 }
403 if ($edit['planet_filter_formats']) {
404 variable_set('planet_filter_formats', $edit['planet_filter_formats']);
405 }
406 if ($edit['planet_redirect_page'] == 1) {
407 variable_set('planet_redirect_page', $edit['planet_redirect_page']);
408 } else {
409 variable_del('planet_redirect_page');
410 }
411 drupal_set_message('Edited general planet settings.');
412}
413
414/**
415 * Page callback for 'admin/settings/planet' ("Planet Settings")
416 *
417 * @ingroup page
418 * @CRUD{planet_items,R}
419 * @CRUD{planet_feeds,R}
420 * @invoke{drupal_get_form,planet_multiple_delete_confirm}
421 * @invoke{drupal_get_form,planet_multiple_delete_confirm_submit}
422 * @invoke{drupal_get_form,planet_feed_form}
423 * @invoke{drupal_get_form,planet_settings_form}
424 */
228function _planet_settings() {425function _planet_settings() {
229 if ($_POST) { 426 if ($_POST) {
230 $edit = $_POST;427 $edit = $_POST;
@@ -241,37 +438,23 @@
241 $edit['redirect'] = 'admin/settings/planet';438 $edit['redirect'] = 'admin/settings/planet';
242 return drupal_get_form('planet_multiple_delete_confirm_submit', $edit);439 return drupal_get_form('planet_multiple_delete_confirm_submit', $edit);
243 }440 }
244 else { 441 else {
245 if (isset($edit['fid']) && intval($edit['fid']) == 0) {442 if (isset($edit['fid'])) {
246 db_query('INSERT INTO {planet_feeds} (uid, title, link, image, checked, frozen) VALUES(%d, "%s", "%s", "%s", 0, 0)', $edit['uid'], $edit['title'], $edit['link'], $edit['image']);443 if (intval($edit['fid']) == 0) {
247 $edit_r = db_fetch_array(db_query('SELECT fid FROM {planet_feeds} WHERE uid = %d AND title = "%s" AND link = "%s"', $edit['uid'], $edit['title'], $edit['link']));444 planet__add_feed($edit);
248 $title = planet_refresh(intval($edit_r['fid']));445 } else {
249 drupal_set_message('Added new feed: ' . $title); 446 planet__update_feed($edit);
250 }447 }
251 else if ($edit['fid'] && intval($edit['fid']) > 0) { 448 } else {
252 db_query('UPDATE {planet_feeds} SET uid = %d, title="%s", link = "%s", image="%s" WHERE fid=%d', $edit['uid'], $edit['title'], $edit['link'], $edit['image'], $edit['fid']);449 // TODO if user needs to click separately for each fieldset,
253 drupal_set_message('Edited "'. $edit['title'] .'" feed.'); 450 // why not using different forms ?
254 }451 // or conversely, allow setting everything at once ?
255 else {452 planet__update_vars($edit);
256 if ($edit['planet_author_roles']) {
257 variable_set('planet_author_roles', $edit['planet_author_roles']);
258 }
259 if ($edit['planet_filter_formats']) {
260 variable_set('planet_filter_formats', $edit['planet_filter_formats']);
261 }
262 if ($edit['planet_redirect_page'] == 1) {
263 variable_set('planet_redirect_page', $edit['planet_redirect_page']);
264 }
265 else {
266 variable_del('planet_redirect_page');
267 }
268 drupal_set_message('Edited general planet settings.');
269 } 453 }
270 } 454 }
271 drupal_goto('admin/settings/planet'); 455 drupal_goto('admin/settings/planet');
272 }456 } else {
273 else { 457 $fid = intval(arg(3)); // @deprecated arg()
274 $fid = intval(arg(3));
275 if ($fid > 0) { 458 if ($fid > 0) {
276 $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid));459 $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid));
277 $output .= drupal_get_form('planet_feed_form', $edit, true);460 $output .= drupal_get_form('planet_feed_form', $edit, true);
@@ -279,38 +462,72 @@
279 else {462 else {
280 463
281 $output .= drupal_get_form('planet_settings_form'); 464 $output .= drupal_get_form('planet_settings_form');
282 //$output .= drupal_get_form('settings', $form);
283 //$output .= $form;
284465
285 $output .= drupal_get_form('planet_feed_form', $edit);466 $output .= drupal_get_form('planet_feed_form', $edit);
286 467
287 // $result = db_query('SELECT *, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds}');
288 $result = db_query('SELECT COUNT(f.fid) cnt, f.*, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds} f LEFT OUTER JOIN {planet_items} i ON i.fid = f.fid GROUP BY f.fid;');
289 $rows = array();
290 $headers = array('Feed', 'Items', 'Edit', 'Last checked', 'Refresh', 'Freeze');
291 while ($feed = db_fetch_object($result)) {
292 $checked = intval($feed->_checked / 60) .' minutes';
293 if ($feed->_checked % 60 > 0) {
294 $checked .= ', '. $feed->_checked % 60 .' seconds';
295 }
296 $checked .= ' ago';
297 array_push($rows, array(
298 $feed->title,
299 $feed->cnt,
300 l('edit', 'admin/settings/planet/'. intval($feed->fid)),
301 $checked,
302 l('refresh', 'admin/settings/planet/refresh/'. intval($feed->fid)),
303 l($feed->frozen ? 'unfreeze' : 'freeze', 'admin/settings/planet/'. ($feed->frozen ? 'unfreeze/' : 'freeze/') . intval($feed->fid))
304 )
305 );
306 }
307 $output .= '<h2>Feeds</h2>';468 $output .= '<h2>Feeds</h2>';
308 $output .= theme('table', $headers, $rows); 469 $output .= planet__build_admin_feeds_table();
309 }470 }
310 print theme('page', $output); 471 print theme('page', $output);
311 }472 }
312}473}
313474
475/**
476 * builds an HTML table of feeds for administrator interaction.
477 *
478 * @return
479 *
480 * @ingroup planet_feed
481 * @internal
482 * @CRUD{planet_feeds,R}
483 * @CRUD{planet_items,R}
484 */
485function planet__build_admin_feeds_table() {
486 // @DIFFINFO renamed planet__build_feeds_table() {
487 global $user;
488 $feeds = db_query('SELECT fid, title, checked, frozen FROM {planet_feeds} '
489 . ' WHERE uid = %d;', $user->uid);
490 $rows = array();
491 $headers = array('Feed', 'Items', 'Edit', 'Last checked', 'Refresh', 'Freeze');
492 $now = time();
493 $items_statement = 'SELECT count(*) FROM {planet_items} WHERE fid=%';
494 // TODO: change this to prepared statement when supported by drupal DB Abstraction Layer.
495 while ($feed = db_fetch_object($feeds)) {
496 $_checked = $now - $feed->checked;
497 $checked = intval($_checked / 60) .' minutes';
498 if ($_checked % 60 > 0) {
499 $checked .= ', '. $feed->_checked % 60 .' seconds';
500 }
501 $checked .= ' ago';
502 $items = db_query($items_statement, $feed->fid);
503 if (!$items) trigger_error('ERROR while counting feed items.');
504 $cnt = db_result($items);
505 $fid = strval($feed->fid);
506 array_push($rows, array(
507 $feed->title,
508 $cnt,
509 l('edit', 'admin/settings/planet/'. $fid),
510 $checked,
511 l('refresh', 'admin/settings/planet/refresh/'. $fid),
512 l($feed->frozen ? 'unfreeze' : 'freeze', 'admin/settings/planet/'. ($feed->frozen ? 'unfreeze/' : 'freeze/') . $fid)
513 )
514 );
515 }
516 return theme('table', $headers, $rows);
517}
518
519/**
520 * TODO.
521 *
522 * @param &$form_state
523 * @param $nodes
524 * @param $fid
525 * @param $redirect
526 * @return
527 *
528 * @ingroup iforms
529 * @CRUD{node,R}
530 */
314function planet_multiple_delete_confirm(&$form_state, $nodes, $fid, $redirect) {531function planet_multiple_delete_confirm(&$form_state, $nodes, $fid, $redirect) {
315 $form_state['values']['fid'] = $fid;532 $form_state['values']['fid'] = $fid;
316 $form_state['values']['redirect'] = $redirect;533 $form_state['values']['redirect'] = $redirect;
@@ -333,21 +550,42 @@
333 t('Delete all'), t('Cancel'));550 t('Delete all'), t('Cancel'));
334}551}
335552
553/**
554 * TODO.
555 *
556 * @param &$form_state
557 * @param $edit
558 * @return
559 *
560 * @ingroup iforms
561 * @CRUD{node,D}
562 * @CRUD{planet_items,D}
563 * @CRUD{planet_feeds,D}
564 */
336function planet_multiple_delete_confirm_submit(&$form_state, $edit) {565function planet_multiple_delete_confirm_submit(&$form_state, $edit) {
337 $fid = $edit['fid'];566 $fid = $edit['fid'];
338 if ($edit['confirm']) {567 if ($edit['confirm']) {
339 foreach ($edit['nodes'] as $nid => $value) {568 foreach ($edit['nodes'] as $nid => $value) {
340 node_delete($nid);569 node_delete($nid);
341 }570 }
571 // @DIFFINFO inverted drop order to respect foreign keys
572 db_query('DELETE FROM {planet_items} WHERE fid = %d', $fid);
342 db_query('DELETE FROM {planet_feeds} WHERE fid = %d', $fid);573 db_query('DELETE FROM {planet_feeds} WHERE fid = %d', $fid);
343 db_query('DELETE FROM {planet_items} WHERE fid = %d', $fid);
344 drupal_set_message(t('The feed and items have been deleted.'));574 drupal_set_message(t('The feed and items have been deleted.'));
345 }575 }
346 drupal_goto($edit['redirect']);576 drupal_goto($edit['redirect']);
347}577}
348578
349579
350580/**
581 * TODO.
582 *
583 * @param &$form_state
584 * @return
585 * @ingroup iforms
586 * @CRUD{role,R}
587 * @CRUD{variables,R}
588 */
351function planet_settings_form(&$form_state) {589function planet_settings_form(&$form_state) {
352 $roles = array();590 $roles = array();
353591
@@ -402,6 +640,20 @@
402}640}
403 641
404642
643/**
644 * TODO.
645 *
646 * @param &$form_state
647 * @param $edit
648 * @param $individual
649 * @param $user
650 * @return
651 * @ingroup iforms
652 * @CRUD{users,R}
653 * @CRUD{role,R}
654 * @CRUD{users_roles,R}
655 * @CRUD{variables,R}
656 */
405function planet_feed_form(&$form_state, $edit = array(), $individual = false, $user = NULL) {657function planet_feed_form(&$form_state, $edit = array(), $individual = false, $user = NULL) {
406 $uids = array();658 $uids = array();
407 $result = db_query('SELECT u.uid, u.name FROM {users} u, {role} r, {users_roles} ur WHERE u.uid = ur.uid AND ur.rid = r.rid AND r.rid = %d ORDER BY u.name ASC', variable_get('planet_author_roles', 2));659 $result = db_query('SELECT u.uid, u.name FROM {users} u, {role} r, {users_roles} ur WHERE u.uid = ur.uid AND ur.rid = r.rid AND r.rid = %d ORDER BY u.name ASC', variable_get('planet_author_roles', 2));
@@ -474,6 +726,13 @@
474 return $form;726 return $form;
475}727}
476728
729/**
730 * Implementation of hook_cron - Perform periodic actions.
731 *
732 * @return none
733 * @ingroup system
734 * @CRUD{planet_feeds,R}
735 */
477function planet_cron() {736function planet_cron() {
478 $result = db_query('SELECT fid FROM {planet_feeds} WHERE frozen = 0');737 $result = db_query('SELECT fid FROM {planet_feeds} WHERE frozen = 0');
479 while ($feed = db_fetch_object($result)) {738 while ($feed = db_fetch_object($result)) {
@@ -482,6 +741,17 @@
482 }741 }
483}742}
484743
744
745/**
746 * Private function; Checks a news feed for new items.
747 *
748 * @param $fid feed identifier (defaults to arg(4))
749 * @return
750 *
751 * @private
752 * @CRUD{planet_feeds,U}
753 * @invoke{module_invoke,taxonomy_node_get_terms}
754 */
485function planet_refresh($fid = null) {755function planet_refresh($fid = null) {
486 if (!$fid) {756 if (!$fid) {
487 $fid = intval(arg(4));757 $fid = intval(arg(4));
@@ -638,60 +908,8 @@
638/**908/**
639 * Private function; Parse HTTP headers from data retreived with cURL909 * Private function; Parse HTTP headers from data retreived with cURL
640 * from: http://pl2.php.net/manual/en/function.curl-setopt.php#42009910 * from: http://pl2.php.net/manual/en/function.curl-setopt.php#42009
641 */911 * @ingroup rss
642function planet_parse_response($response) {912 * @private
643 /*
644 ***original code extracted from examples at
645 ***http://www.webreference.com/programming
646 /php/cookbook/chap11/1/3.html
647
648 ***returns an array in the following format which varies depending on headers returned
649
650 [0] => the HTTP error or response code such as 404
651 [1] => Array
652 (
653 [Server] => Microsoft-IIS/5.0
654 [Date] => Wed, 28 Apr 2004 23:29:20 GMT
655 [X-Powered-By] => ASP.NET
656 [Connection] => close
657 [Set-Cookie] => COOKIESTUFF
658 [Expires] => Thu, 01 Dec 1994 16:00:00 GMT
659 [Content-Type] => text/html
660 [Content-Length] => 4040
661 )
662 [2] => Response body (string)
663 */
664
665 do {
666 list($response_headers, $response) = explode("\r\n\r\n", $response, 2);
667 $response_header_lines = explode("\r\n", $response_headers);
668
669 // first line of headers is the HTTP response code
670 $http_response_line = array_shift($response_header_lines);
671 if (preg_match('@^HTTP/[0-9]\.[0-9] ([0-9]{3})@', $http_response_line, $matches)) {
672 $response_code = $matches[1];
673 }
674 else {
675 $response_code = "Error";
676 }
677 }
678 while (substr($response_code, 0, 1) == "1");
679
680 $response_body = $response;
681
682 // put the rest of the headers in an array
683 $response_header_array = array();
684 foreach ($response_header_lines as $header_line) {
685 list($header, $value) = explode(':', $header_line, 2);
686 $response_header_array[$header] = trim($value);
687 }
688
689 return array($response_code, $response_header_array, $response_body, $http_response_line);
690}
691
692/**
693 * Private function; Gets data from given URL :)
694 */
695function planet_http_request($url, $headers = array(), $timeout = 15, $method = 'GET', $data = NULL, $follow = 3) {913function planet_http_request($url, $headers = array(), $timeout = 15, $method = 'GET', $data = NULL, $follow = 3) {
696 if (!function_exists('curl_init')) {914 if (!function_exists('curl_init')) {
697 return drupal_http_request($url, $headers, $method, $data, $follow);915 return drupal_http_request($url, $headers, $method, $data, $follow);
@@ -750,11 +968,6 @@
750}968}
751969
752/**970/**
753 * Private function; Checks a news feed for new items.
754 */
755
756
757/**
758 * Private function;971 * Private function;
759 * Parse the W3C date/time format, a subset of ISO 8601. PHP date parsing972 * Parse the W3C date/time format, a subset of ISO 8601. PHP date parsing
760 * functions do not handle this format.973 * functions do not handle this format.
@@ -763,6 +976,8 @@
763 *976 *
764 * @param $date_str A string with a potentially W3C DTF date.977 * @param $date_str A string with a potentially W3C DTF date.
765 * @return A timestamp if parsed successfully or -1 if not.978 * @return A timestamp if parsed successfully or -1 if not.
979 * @ingroup rss
980 * @private
766 */981 */
767function planet_parse_w3cdtf($date_str) {982function planet_parse_w3cdtf($date_str) {
768 if (preg_match('/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/', $date_str, $match)) {983 if (preg_match('/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/', $date_str, $match)) {
@@ -799,6 +1014,8 @@
799 *1014 *
800 * @param $ord Number1015 * @param $ord Number
801 * @return UTF-8 string1016 * @return UTF-8 string
1017 * @ingroup rss
1018 * @private
802 */1019 */
803function planet_replace_num_entity($ord) {1020function planet_replace_num_entity($ord) {
804 $ord = $ord[1];1021 $ord = $ord[1];
@@ -959,6 +1176,8 @@
959/**1176/**
960 * Private function; Convert named entities to UTF-8 characters1177 * Private function; Convert named entities to UTF-8 characters
961 * from: http://pl2.php.net/manual/en/function.html-entity-decode.php#517221178 * from: http://pl2.php.net/manual/en/function.html-entity-decode.php#51722
1179 * @ingroup rss
1180 * @private
962 */1181 */
963function planet_replace_name_entities(&$text) {1182function planet_replace_name_entities(&$text) {
964 static $ttr;1183 static $ttr;
@@ -974,23 +1193,20 @@
9741193
975/**1194/**
976 * Private function; Convert all entities to UTF-8 characters1195 * Private function; Convert all entities to UTF-8 characters
1196 * @ingroup rss
1197 * @private
1198 * @invoke{preg_replace_callback,planet_replace_num_entity}
977 */1199 */
978function planet_replace_entities(&$text) {1200function planet_replace_entities(&$text) {
979 $result = planet_replace_name_entities($text);1201 $result = planet_replace_name_entities($text);
980 return preg_replace_callback('/&#([0-9a-fx]+);/mi', 'planet_replace_num_entity', $result);1202 return preg_replace_callback('/&#([0-9a-fx]+);/mi', 'planet_replace_num_entity', $result);
981}1203}
9821204
983/**
984 * Private function; Clone object function to stay compatible with both php4 and php5
985 * from: Drupal 4.7CVS
986 * TODO: remove after moving to Drupal 4.7
987 */
988function planet_clone($object) {
989 return version_compare(phpversion(), '5.0') < 0 ? $object : clone($object);
990}
9911205
992/**1206/**
993 * Private function; Convert relative URLs1207 * Private function; Convert relative URLs
1208 * @ingroup rss
1209 * @private
994 */1210 */
995function planet_convert_relative_urls(&$data, $base_url) {1211function planet_convert_relative_urls(&$data, $base_url) {
996 $src = '%( href| src)="(?!\w+://)/?([^"]*)"%';1212 $src = '%( href| src)="(?!\w+://)/?([^"]*)"%';
@@ -1000,6 +1216,13 @@
10001216
1001/**1217/**
1002 * Private function; Creates nodes from data found in given xml_tree1218 * Private function; Creates nodes from data found in given xml_tree
1219 *
1220 * @ingroup rss
1221 * @private
1222 * @CRUD{variables,R}
1223 * @CRUD{planet_items,R}
1224 * @CRUD{node,CU}
1225 * @invoke{module_invoke,taxonomy_node_get_terms}
1003 */1226 */
1004function planet_parse_items(&$xml_tree, &$feed) {1227function planet_parse_items(&$xml_tree, &$feed) {
10051228
@@ -1229,10 +1452,16 @@
1229 }1452 }
1230 //print '<pre>'. print_r($entry, 1) .'</pre>';1453 //print '<pre>'. print_r($entry, 1) .'</pre>';
1231 node_save($entry);1454 node_save($entry);
1232 db_query('INSERT INTO {planet_items} (fid, nid, guid, link, created) VALUES(%d, %d, "%s", "%s", UNIX_TIMESTAMP(NOW()))', $feed->fid, $entry->nid, $guid, $link); 1455 $item_record = array('fid' => $feed->fid,
1456 'nid' => $entry->nid,
1457 'guid'=> $guid,
1458 'link' =>$link,
1459 'created' => time());
1460 drupal_write_record('planet_items', $item_record);
1233 watchdog('planet', 'Adding '. $title);1461 watchdog('planet', 'Adding '. $title);
1234 drupal_set_message('Adding '. $title);1462 drupal_set_message('Adding '. $title);
1235 } 1463 }
1464 // TODO split this huge function
1236 }1465 }
12371466
1238 return $items_added;1467 return $items_added;
@@ -1241,6 +1470,12 @@
12411470
1242/**1471/**
1243 * Private function; parses given XML data and returns array1472 * Private function; parses given XML data and returns array
1473 *
1474 * @ingroup rss
1475 * @private
1476 * @invoke{xml_set_element_handler,planet_element_start}
1477 * @invoke{xml_set_element_handler,planet_element_end}
1478 * @invoke{xml_set_character_data_handler,planet_element_data}
1244 */1479 */
1245function planet_parse_xml(&$data) {1480function planet_parse_xml(&$data) {
1246 global $xml_tree, $xml_paths, $xml_path_cur;1481 global $xml_tree, $xml_paths, $xml_path_cur;
@@ -1297,6 +1532,8 @@
12971532
1298/**1533/**
1299 * Private call-back function used by the XML parser.1534 * Private call-back function used by the XML parser.
1535 * @ingroup rss
1536 * @internal
1300 */1537 */
1301function planet_element_start($parser, $name, $attributes) {1538function planet_element_start($parser, $name, $attributes) {
1302 global $xml_tree, $xml_paths, $xml_path_cur;1539 global $xml_tree, $xml_paths, $xml_path_cur;
@@ -1308,6 +1545,8 @@
13081545
1309/**1546/**
1310 * Private call-back function used by the XML parser.1547 * Private call-back function used by the XML parser.
1548 * @ingroup rss
1549 * @private
1311 */1550 */
1312function planet_element_end($parser, $name) {1551function planet_element_end($parser, $name) {
1313 global $xml_tree, $xml_paths, $xml_path_cur;1552 global $xml_tree, $xml_paths, $xml_path_cur;
@@ -1322,6 +1561,8 @@
13221561
1323/**1562/**
1324 * Private call-back function used by the XML parser.1563 * Private call-back function used by the XML parser.
1564 * @ingroup rss
1565 * @private
1325 */1566 */
1326function planet_element_data($parser, $data) {1567function planet_element_data($parser, $data) {
1327 global $xml_tree, $xml_paths, $xml_path_cur;1568 global $xml_tree, $xml_paths, $xml_path_cur;
@@ -1333,6 +1574,12 @@
1333 }1574 }
1334}1575}
13351576
1577/**
1578 * Page callback for 'planet' ("Planet").
1579 * @ingroup page
1580 * @CRUD{node,R}
1581 * @CRUD{variables,R}
1582 */
1336function planet_page_last() {1583function planet_page_last() {
1337 global $user;1584 global $user;
13381585
@@ -1351,6 +1598,12 @@
1351 print theme('page', $output);1598 print theme('page', $output);
1352}1599}
13531600
1601/**
1602 * Page callback for 'planet/feed' ("Planet").
1603 * @ingroup page
1604 * @CRUD{node,R}
1605 * @CRUD{menu_links,R}
1606 */
1354function planet_feed() {1607function planet_feed() {
1355 $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'planet' AND n.status = 1 ORDER BY n.created DESC"), 0, 15);1608 $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'planet' AND n.status = 1 ORDER BY n.created DESC"), 0, 15);
1356 $title = db_fetch_array(db_query("SELECT link_title FROM {menu_links} WHERE link_path = 'planet'"));1609 $title = db_fetch_array(db_query("SELECT link_title FROM {menu_links} WHERE link_path = 'planet'"));
@@ -1363,12 +1616,14 @@
1363 while ($row = db_fetch_object($result)) {1616 while ($row = db_fetch_object($result)) {
1364 $items[] = $row->nid;1617 $items[] = $row->nid;
1365 }1618 }
13661619 // generate RSS feed from $items set of nodes.
1367 node_feed($items, $channel);1620 node_feed($items, $channel);
1368}1621}
13691622
1370/**1623/**
1371 * Implementation of hook_user().1624 * Implementation of hook_user() - React when operations are performed on user accounts.
1625 * @ingroup system
1626 * @CRUD{planet_feeds,R}
1372 */1627 */
1373function planet_user($type, &$edit, &$user) {1628function planet_user($type, &$edit, &$user) {
1374 if ($type == 'view' && user_access('edit own blog', $user)) {1629 if ($type == 'view' && user_access('edit own blog', $user)) {
@@ -1390,6 +1645,8 @@
13901645
1391/**1646/**
1392 * Menu callback; displays a Drupal page containing recent planet entries.1647 * Menu callback; displays a Drupal page containing recent planet entries.
1648 * @todo remove orphan function, or reuse it
1649 * @ingroup page
1393 */1650 */
1394function planet_page($a = NULL, $b = NULL) {1651function planet_page($a = NULL, $b = NULL) {
13951652
@@ -1409,6 +1666,13 @@
1409 }1666 }
1410}1667}
14111668
1669/**
1670 * Page callback for 'planet/%' ("planet").
1671 * @ingroup page
1672 *
1673 * @CRUD{node,R}
1674 * @CRUD{variables,R}
1675 */
1412function planet_page_user($uid) {1676function planet_page_user($uid) {
1413 global $user;1677 global $user;
14141678
@@ -1441,12 +1705,28 @@
1441 }1705 }
1442}1706}
14431707
1708/**
1709 * Implementation of hook_load - Load node-type-specific information.
1710 *
1711 * @param $node The node being loaded.
1712 * @return An object containing properties of the node being loaded.
1713 * @ingroup system
1714 * @CRUD{planet_items,R}
1715 */
1444function planet_load($node) {1716function planet_load($node) {
1445 $additions = db_fetch_object(db_query('SELECT link, guid FROM {planet_items} WHERE nid = %d', $node->nid));1717 $additions = db_fetch_object(db_query('SELECT link, guid FROM {planet_items} WHERE nid = %d', $node->nid));
1446 return $additions;1718 return $additions;
1447}1719}
14481720
1449function planet_form(&$node, &$param) {1721/**
1722 * Implementation of hook_form - Display a node editing form.
1723 *
1724 * @param &$node The node being added or edited.
1725 * @param $form_state The form state array (unused).
1726 * @return An array containing the form elements to be displayed in the node edit form.
1727 * @ingroup planet_node
1728 */
1729function planet_form(&$node, &$form_state) {
1450 $form = array();1730 $form = array();
1451 $form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#value' => $node->title, '#size' => 30, '#maxlength' => 80);1731 $form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#value' => $node->title, '#size' => 30, '#maxlength' => 80);
1452 $form['body'] = array('#type' => 'textarea', '#title' => 'Body', '#value' => $node->body);1732 $form['body'] = array('#type' => 'textarea', '#title' => 'Body', '#value' => $node->body);

Subscribers

People subscribed via source and target branches

to all changes: