* presumably they want to see the full HTML, with pretty * output and such. */ /* XXX - Would this be desirable in "update all feeds" mode? * Maybe not. Just try one-feed mode for now. * * OTOH, I use this extensively when debugging plugins to * remove ads. So perhaps this stuff should be left alone, * save that if the user left-clicks on the "Update feed" * link, it should use JS and update in the background, while * if ve middle-clicks, it should use traditional HTML. */ if ($verbose) { error_log("Updating feed_id {$feed_id}"); } $feed = db_get_feed($feed_id); if ($feed === NULL) { // Invalid feed ID, presumably.. error_log("Invalid feed ID: {$feed_id}"); abort("Invalid feed ID: {$feed_id}"); } $handler->start_feed($feed_id, $feed['title']); $err = update_feed($feed_id, $feed); if (!$err) { // XXX - This should never happen $handler->error($feed_id, $feed['title'], "parse_feed() returned " . ($err == "" ? var_export($err) : $err)); } /* Error-checking */ if (isset($err['status']) && $err['status'] != 0) { switch ($out_fmt) { case "json":
/* Has confirmation been given? */ $confirm = $_REQUEST['confirm']; //echo "confirm == [$confirm]<br/>\n"; if ($confirm == "yes") { /* Go ahead and unsubscribe */ db_delete_feed($feed_id); // XXX - Error-checking /* Redirect back to the main page */ redirect_to("index.html"); exit(0); } /* Confirmation has not been given. Show feed info and ask for * confirmation. */ // We've already established above that $feed_id is numeric $feed_info = db_get_feed($feed_id); if ($feed_info === NULL) { /* No such feed. Abort */ abort("No such feed: {$feed_id}."); } // What follows is basically a template. ######################################## echo '<', '?xml version="1.0" encoding="UTF-8"?', ">\n"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>NewsBite: Unsubscribe</title> <link rel="stylesheet" type="text/css" href="css/style.css" media="all" /> <link rel="stylesheet" type="text/css" href="css/unsubscribe.css" media="all" />
function update_feed_info($feed_id) { $feed_info = db_get_feed($feed_id); if ($feed_info === NULL) { abort("No such feed: {$feed_id}"); } /* Build an assoc of new values */ $new = array(); // I'm not sure why or how $_REQUEST values acquire // backslashes in front of quotation marks, but they do. $new['nickname'] = stripcslashes($_REQUEST['nickname']); $new['url'] = stripcslashes($_REQUEST['url']); $new['feed_url'] = stripcslashes($_REQUEST['feed_url']); $new['active'] = $_REQUEST['active'] != ""; # Boolean $new['username'] = stripcslashes($_REQUEST['username']); $new['passwd'] = stripcslashes($_REQUEST['password']); // XXX - Perhaps try to fetch the feed if the feed URL, // username, or password has changed? $ok = true; $errors = array(); // XXX - Check parameters. if (!$ok) { // XXX - This is rather theoretical. We don't actually // check anything. abort("You supplied a bad value of some kind. Go back and fix it."); } /* Update the list of groups that the feed is in: * $old_groups is the groups the feed is currently in. * $new_groups is the ones it should be in, as gleaned from * $_REQUEST. * Diff the two to see whichg groups to remove the feed from, * and which ones to add it to. */ $old_groups = $feed_info['groups']; $new_groups = array(); foreach ($_REQUEST as $key => $value) { if (preg_match('/^group_(-?\\d+)$/', $key, $match)) { $new_groups[] = $match[1]; } } // First diff: see which groups to remove the feed from. $diffs = array_diff($old_groups, $new_groups); if (count($diffs) != 0) { foreach ($diffs as $g) { // Remove feed $feed_id from group $g db_group_remove_member($g, $feed_id); } } // Second diff: see which groups to add the feed to. $diffs = array_diff($new_groups, $old_groups); if (count($diffs) != 0) { foreach ($diffs as $g) { echo "Add feed {$feed_id} to group {$g}<br/>\n"; db_group_add_member($g, $feed_id); } } /* No errors. Update the database. */ db_update_feed_info($feed_id, $new); // XXX - Error-checking /* Redirect to the feed view page */ if ($new['active']) { redirect_to("view.php#id={$feed_id}"); } else { redirect_to("index.html"); } }