function fof_add_feed($url) { if (!$url) { return; } global $FOF_FEED_TABLE, $FOF_ITEM_TABLE; $FOF_FEED_TABLE = FOF_FEED_TABLE; $FOF_ITEM_TABLE = FOF_ITEM_TABLE; $url = trim($url); if (substr($url, 0, 7) != 'http://') { $url = 'http://' . $url; } print "Attempting to subscribe to <a href=\"{$url}\">{$url}</a>...<br>"; if ($row = fof_is_subscribed($url)) { print "You are already subscribed to " . fof_render_feed_link($row) . "<br><br>"; return true; } $rss = fetch_rss($url); if (!$rss->channel && !$rss->items) { echo " <font color=\"darkgoldenrod\">URL is not RSS or is invalid.</font><br>"; if (!$rss) { echo " (error was: <B>" . magpie_error() . "</b>)<br>"; } echo " <a href=\"http://feeds.archive.org/validator/check?url={$url}\">The validator may give more information.</a><br>"; echo "<br>Attempting autodiscovery...<br><br>"; $r = _fetch_remote_file($url); $c = $r->results; if ($c && $r->status >= 200 && $r->status < 300) { $l = fof_getRSSLocation($c, $url); if ($l) { echo "Autodiscovery found <a href=\"{$l}\">{$l}</a>.<br>"; echo "Attempting to subscribe to <a href=\"{$l}\">{$l}</a>...<br>"; if ($row = fof_is_subscribed($l)) { print "<br>You are already subscribed to " . fof_render_feed_link($row) . "<br>"; return true; } $rss = fetch_rss($l); if (!$rss->channel && !$rss->items) { echo " <font color=\"red\">URL is not RSS, giving up.</font><br>"; echo " (error was: <B>" . magpie_error() . "</b>)<br>"; echo " <a href=\"http://feeds.archive.org/validator/check?url={$l}\">The validator may give more information.</a><br>"; } else { fof_actually_add_feed($l, $rss); echo " <font color=\"green\"><b>Subscribed.</b></font><br><br>"; } } else { echo "<font color=\"red\"><b>Autodiscovery failed. Giving up.</b></font><br>"; } } else { echo "<font color=\"red\"><b>Can't load URL. Giving up.</b></font><br>"; } } else { fof_actually_add_feed($url, $rss); echo "<font color=\"green\"><b>Subscribed.</b></font><br>"; } }
function fof_subscribe($user_id, $url, $unread = "today") { if (!$url) { return false; } $url = fof_prepare_url($url); $feed = fof_db_get_feed_by_url($url); if (fof_is_subscribed($user_id, $url)) { return "You are already subscribed to " . fof_render_feed_link($feed) . "<br>"; } if (fof_feed_exists($url)) { fof_db_add_subscription($user_id, $feed['feed_id']); fof_apply_plugin_tags($id, NULL, $user_id); fof_update_feed($feed['feed_id']); if ($unread != "no") { fof_db_mark_feed_unread($user_id, $feed['feed_id'], $unread); } return '<font color="green"><b>Subscribed.</b></font><br>'; } $rss = fof_parse($url); if (isset($rss->error)) { return "Error: <B>" . $rss->error . "</b> <a href=\"http://feedvalidator.org/check?url={$url}\">try to validate it?</a><br>"; } else { $url = html_entity_decode($rss->subscribe_url(), ENT_QUOTES); $self = $rss->get_link(0, 'self'); if ($self) { $url = html_entity_decode($self, ENT_QUOTES); } if (fof_feed_exists($url)) { $feed = fof_db_get_feed_by_url($url); if (fof_is_subscribed($user_id, $url)) { return "You are already subscribed to " . fof_render_feed_link($feed) . "<br>"; } fof_db_add_subscription($user_id, $feed['feed_id']); if ($unread != "no") { fof_db_mark_feed_unread($user_id, $feed['feed_id'], $unread); } return '<font color="green"><b>Subscribed.</b></font><br>'; } $id = fof_add_feed($url, $rss->get_title(), $rss->get_link(), $rss->get_description()); fof_update_feed($id); fof_db_add_subscription($user_id, $id); if ($unread != "no") { fof_db_mark_feed_unread($user_id, $id, $unread); } fof_apply_plugin_tags($id, NULL, $user_id); return '<font color="green"><b>Subscribed.</b></font><br>'; } }