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_add_feed($url) { if (!$url) { return; } $url = trim($url); if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') { $url = 'http://' . $url; } //echo $url; //echo _("Attempting to subscribe to ") . "<a href=\"$url\">$url</a>...<br />"; //if($row = fof_is_subscribed($url)) //{ // print "<font color='red'><u>" . _("You are already subscribed to ") . fof_render_feed_link($row) . "</u></font><br /><br />"; // return true; //} $piefeed = new SimplePie(); $piefeed->set_image_handler(); //$piefeed->strip_ads(true); $piefeed->set_feed_url($url); $piefeed->set_cache_location(FOF_CACHE_DIR); $piefeed->init(); $piefeed->handle_content_type(); if (!$piefeed->data) { //echo " <font color=\"red\">" . _("URL is not RSS or is invalid.") . "</font><br />"; //echo " (<font color=\"red\">" . _("error was") . "</font>: <B>" . $piefeed->error . "</b>)<br />"; //echo " <a href=\"http://feedvalidator.org/check?url=$url\">" . _("The FEED validator may give more information.") . "</a><br />"; //echo " <a href=\"http://validator.w3.org/check?uri=$url\">" . _("The XHTML validator may give more information.") . "</a><br />"; //echo "<font color=\"red\"><b>" . _("Can't load URL. Giving up.") . "</b></font><br />"; //echo "<font color=\"red\"><b>" . _("Autodiscovery failed. Giving up.") . "</b></font><br />"; } else { //echo _("Adding feed...") . "<br />"; fof_actually_add_feed($url, $piefeed); //echo "<font color=\"green\"><b>" . _("Subscribed") . ".</b></font><br />"; } $safeurl = mysql_escape_string($url); $result = fof_do_query("select id from feeds where url='{$safeurl}'"); $row = mysql_fetch_array($result); $feed_id = $row['id']; ?> <script type="text/javascript"> if (top==self) document.writeln('<?php //echo "<a href=\"edit.php?feed=$feed_id\">Edit feed attributes.</a><br />"; //echo "<a href=\"delete.php?feed=$feed_id\">Delete this feed.</a><br />"; //echo "<a href=\"index.php\">Return to new items.</a>"; ?> ') else document.writeln('<?php //echo "<a href=\"edit.php?framed=yes&feed=$feed_id\">Edit feed attributes.</a><br />"; //echo "<a href=\"delete.php?framed=yes&feed=$feed_id\">Delete this feed.</a><br />"; //echo "<a href=\"framesview.php\">Return to new items.</a>"; ?> '); </script> <?php unset($piefeed); }