? planet-402414.patch ? planet.patch Index: planet.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/planet/planet.module,v retrieving revision 1.7 diff -u -p -r1.7 planet.module --- planet.module 11 Mar 2009 23:15:34 -0000 1.7 +++ planet.module 27 Mar 2009 19:22:53 -0000 @@ -40,7 +40,7 @@ function planet_help($path, $arg) { } function planet_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { - if ($page === true && variable_get('planet_redirect_page', 0) == 1) { + if ($page === TRUE && variable_get('planet_redirect_page', 0) == 1) { $obj = db_fetch_object(db_query('SELECT * FROM {planet_items} WHERE nid = %d', $node->nid)); if ($obj->nid == $node->nid && $obj->link != '') { header('Location: '. $obj->link); @@ -81,16 +81,8 @@ function planet_menu() { 'page arguments' => array(1), 'access arguments' => array('administer own planet feeds'), 'type' => MENU_LOCAL_TASK, - ); + ); - // if (arg(0) == 'planet' && is_numeric(arg(1))) { - $items['planet/'. '%'] = array( - 'title' => 'planet', - 'page callback' => 'planet_page_user', - 'page arguments' => array(arg(1)) - ); -// } - // if (arg(3) == 'refresh' && is_numeric(arg(4))) { $items['admin/settings/planet/refresh/%'] = array( @@ -145,8 +137,8 @@ function planet_toggle_frozen() { function planet_user_feeds() { -global $user; -if ($_POST) { + global $user; + if ($_POST) { $edit = $_POST; if ($_POST['op'] == 'Delete' && intval($edit['fid']) > 0) { $result = db_query('SELECT nid FROM {planet_items} WHERE fid = %d', intval($edit['fid'])); @@ -163,21 +155,18 @@ if ($_POST) { else { if (isset($edit['fid']) && intval($edit['fid']) == 0) { 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']); - $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'])); - $title = planet_refresh(intval($edit_r['fid'])); - drupal_set_message('Added new feed: ' . $title); + $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'])); + $title = planet_refresh(intval($edit_r['fid'])); + drupal_set_message('Added new feed: '. $title); } else if ($edit['fid'] && intval($edit['fid']) > 0) { 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']); drupal_set_message('Edited "'. $edit['title'] .'" feed.'); } else { - if ($edit['planet_author_roles']) { - variable_set('planet_author_roles', $edit['planet_author_roles']); - } - if ($edit['planet_filter_formats']) { - variable_set('planet_filter_formats', $edit['planet_filter_formats']); - } + if ($edit['planet_filter_formats']) { + variable_set('planet_filter_formats', $edit['planet_filter_formats']); + } if ($edit['planet_redirect_page'] == 1) { variable_set('planet_redirect_page', $edit['planet_redirect_page']); } @@ -193,11 +182,11 @@ if ($_POST) { $fid = intval(arg(3)); if ($fid > 0) { $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid)); - $output .= drupal_get_form('planet_feed_form', $edit, true, $user); + $output .= drupal_get_form('planet_feed_form', $edit, TRUE, $user); } else { - $output .= drupal_get_form('planet_feed_form', $edit, false, $user); + $output .= drupal_get_form('planet_feed_form', $edit, FALSE, $user); // $result = db_query('SELECT *, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds}'); $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); @@ -243,22 +232,30 @@ function _planet_settings() { } else { if (isset($edit['fid']) && intval($edit['fid']) == 0) { + // Username can change, so we need to store the ID, not the username. + $edit['uid'] = db_result(db_query("SELECT uid from {users} WHERE name = '%s'", $edit['username'])); 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']); $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'])); $title = planet_refresh(intval($edit_r['fid'])); - drupal_set_message('Added new feed: ' . $title); + drupal_set_message('Added new feed: '. $title); } else if ($edit['fid'] && intval($edit['fid']) > 0) { + // Username can change, so we need to store the ID, not the username. + $edit['uid'] = db_result(db_query("SELECT uid from {users} WHERE name = '%s'", $edit['username'])); 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']); + $result = db_query("SELECT nid FROM {planet_items} WHERE fid = %d", $edit['fid']); + while ($nid = db_fetch_object($result)) { + db_query('UPDATE {node} SET uid = %d WHERE nid = %d', $edit['uid'], $nid->nid); + } drupal_set_message('Edited "'. $edit['title'] .'" feed.'); } else { if ($edit['planet_author_roles']) { variable_set('planet_author_roles', $edit['planet_author_roles']); } - if ($edit['planet_filter_formats']) { - variable_set('planet_filter_formats', $edit['planet_filter_formats']); - } + if ($edit['planet_filter_formats']) { + variable_set('planet_filter_formats', $edit['planet_filter_formats']); + } if ($edit['planet_redirect_page'] == 1) { variable_set('planet_redirect_page', $edit['planet_redirect_page']); } @@ -274,7 +271,7 @@ function _planet_settings() { $fid = intval(arg(3)); if ($fid > 0) { $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid)); - $output .= drupal_get_form('planet_feed_form', $edit, true); + $output .= drupal_get_form('planet_feed_form', $edit, TRUE); } else { @@ -349,14 +346,6 @@ function planet_multiple_delete_confirm_ function planet_settings_form(&$form_state) { - $roles = array(); - - $result = db_query('SELECT rid, name FROM {role}'); - while ($role = db_fetch_object($result)) { - $roles[$role->rid] = $role->name; - } - - unset($result); $result = db_query('SELECT format, name FROM {filter_formats}'); while ($format = db_fetch_object($result)) { $formats[$format->format] = $format->name; @@ -369,14 +358,6 @@ function planet_settings_form(&$form_sta '#title' => t('General Settings') ); - $form['general']['planet_author_roles'] = array( - '#type' => 'select', - '#title' => t('Role to select authors from'), - '#options' => $roles, - '#default_value' => variable_get('planet_author_roles', 2), - '#description' => t('Select the role from which blog authors should be selected on the feed creation screen.') - ); - $form['general']['planet_filter_formats'] = array( '#type' => 'select', '#title' => t('Filter format for planet entry nodes'), @@ -389,7 +370,7 @@ function planet_settings_form(&$form_sta '#type' => 'checkbox', '#title' => t('Redirect node?'), '#return_value' => 1, - '#value' => (variable_get('planet_redirect_page', 0) == 1) ? 1 : null, + '#value' => (variable_get('planet_redirect_page', 0) == 1) ? 1 : NULL, '#description' => t('Check this if you want the node view to redirect to the original content link; this is useful if you want the feed to forward through instead of showing the planet node.') ); @@ -402,7 +383,7 @@ function planet_settings_form(&$form_sta } -function planet_feed_form(&$form_state, $edit = array(), $individual = false, $user = NULL) { +function planet_feed_form(&$form_state, $edit = array(), $individual = FALSE, $user = NULL) { $uids = array(); $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)); while ($f_user = db_fetch_object($result)) { @@ -410,9 +391,9 @@ function planet_feed_form(&$form_state, } if ($individual) { - if (!isset($uids[$edit['uid']])) { + if (!isset($uids[$edit['username']])) { $g_user = db_fetch_array(db_query('SELECT uid, name FROM {users} WHERE uid = %d', $edit['uid'])); - $uids[$edit['uid']] = $g_user['name']; + $uids[$edit['username']] = $g_user['name']; } } @@ -437,11 +418,13 @@ function planet_feed_form(&$form_state, ); if ($user == NULL) { - $form['feeds']['uid'] = array( - '#type' => 'select', + $form['feeds']['username'] = array( + '#type' => 'textfield', '#title' => t('Original author'), - '#value' => $edit['uid'], - '#options' => $uids, + '#size' => 40, + '#maxlength' => 60, + '#default_value' => $g_user['name'], + '#autocomplete_path' => 'user/autocomplete', '#description' => t('Select a user to associate this feed with') ); } @@ -482,7 +465,7 @@ function planet_cron() { } } -function planet_refresh($fid = null) { +function planet_refresh($fid = NULL) { if (!$fid) { $fid = intval(arg(4)); } @@ -500,7 +483,7 @@ function planet_refresh($fid = null) { case 301: if ($result->redirect_url) { $feed->link = $result->redirect_url; - watchdog('planet', 'Updated URL for feed %title to %url.', array('%title' => ''. $feed->title .'', '%url' => ''. $feed->url .''), WATCHDOG_NOTICE, l(t('view'), 'planet/'.$feed->fid)); + watchdog('planet', 'Updated URL for feed %title to %url.', array('%title' => ''. $feed->title .'', '%url' => ''. $feed->url .''), WATCHDOG_NOTICE, l(t('view'), 'planet/'. $feed->fid)); db_query("UPDATE {planet_feeds} SET link = '%s' WHERE fid = %d", $feed->link, $feed->fid); } break; @@ -519,7 +502,7 @@ function planet_refresh($fid = null) { drupal_set_message('Parsing feed '. $feed->title .' took '. $xml_tree['parser_time'] .' seconds.'); } - if (planet_parse_items($xml_tree, $feed) !== false) { + if (planet_parse_items($xml_tree, $feed) !== FALSE) { if ($result->headers['Last-Modified']) { $modified = strtotime($result->headers['Last-Modified']); } @@ -598,7 +581,7 @@ function planet_refresh($fid = null) { */ if (!$feed->image && $image['LINK'] && $image['URL'] && $image['TITLE']) { if (strlen($image['TITLE'][0]['VALUE']) > 250) { - $image['TITLE'][0]['VALUE'] = trim(substr($image['TITLE'][0]['VALUE'], 0, 250)).'...'; + $image['TITLE'][0]['VALUE'] = trim(substr($image['TITLE'][0]['VALUE'], 0, 250)) .'...'; } $feed->image = ''; } @@ -1022,7 +1005,7 @@ function planet_parse_items(&$xml_tree, else { // unsupported format $items = array(); - return false; + return FALSE; } /* @@ -1202,7 +1185,7 @@ function planet_parse_items(&$xml_tree, $entry->body = $body; $entry->body = planet_convert_relative_urls($body, $link); $entry->teaser = node_teaser($entry->body); - $entry->revision = true; + $entry->revision = TRUE; //Fields to set if it's a new item. if (!isset($entry->nid)) { @@ -1219,7 +1202,7 @@ function planet_parse_items(&$xml_tree, $entry->comment = in_array('comment', $options) ? 2 : 0; $entry->format = variable_get('planet_filter_formats', 1); $entry->created = strtotime($date); - $entry->revision = true; + $entry->revision = TRUE; $terms = module_invoke('taxonomy', 'node_get_terms', $edit->nid, 'tid'); foreach ($terms as $tid => $term) { @@ -1334,11 +1317,9 @@ function planet_element_data($parser, $d } function planet_page_last() { - global $user; - - $output = '
'; - - $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'planet' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10)); + global $user; + $output = '
'; + $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'planet' AND n.status ORDER BY n.created DESC"), variable_get('default_nodes_main', 10)); while ($node = db_fetch_object($result)) { $node = node_load($node->nid); @@ -1409,36 +1390,23 @@ function planet_page($a = NULL, $b = NUL } } -function planet_page_user($uid) { - global $user; - - $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1)); - if ($account->uid) { - drupal_set_title($title = t("%name's planet", array('%name' => $account->name))); +function planet_page_user($fid) { + global $user; + $uid = db_result(db_query("SELECT uid FROM {planet_feeds} WHERE fid = %d", $fid)); + $output = '
'; + + $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'planet' AND n.status AND n.uid = %d ORDER BY n.created DESC"), variable_get('default_nodes_main', 10, $uid)); - if ($output) { - $output = ''; - } - else { - $output = ''; - } - $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'planet' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid); - while ($node = db_fetch_object($result)) { - $output .= node_view(node_load($node->nid), 1); - } - $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); - $output .= theme('feed_icon', url("planet/$account->uid/feed")); - - drupal_add_link(array('rel' => 'alternate', - 'type' => 'application/rss+xml', - 'title' => t('RSS - %title', array('%title' => $title)), - 'href' => url("planet/$account->uid/feed"))); - return $output; - } - else { - drupal_not_found(); + while ($node = db_fetch_object($result)) { + $node = node_load($node->nid); + $node->format = variable_get('planet_filter_formats', 1); + $output .= node_view($node); } + $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); + $output .= theme('xml_icon', url('planet/feed')); + + print theme('page', $output); } function planet_load($node) {