Beispiel #1
0
/**
 * Subscribes the user to the given feed
 *
 * @param resource $link       Database connection
 * @param string   $url        Feed URL to subscribe to
 * @param integer  $cat_id     Category ID the feed shall be added to
 * @param string   $auth_login (optional) Feed username
 * @param string   $auth_pass  (optional) Feed password
 *
 * @return integer Status code:
 *                 0 - OK, Feed already exists
 *                 1 - OK, Feed added
 *                 2 - Invalid URL
 *                 3 - URL content is HTML, no feeds available
 *                 4 - URL content is HTML which contains multiple feeds.
 *                     Here you should call extractfeedurls in rpc-backend
 *                     to get all possible feeds.
 *                 5 - Couldn't download the URL content.
 */
function subscribe_to_feed($link, $url, $cat_id = 0, $auth_login = '', $auth_pass = '')
{
    $url = fix_url($url);
    if (!$url || !validate_feed_url($url)) {
        return 2;
    }
    $update_method = 0;
    $result = db_query($link, "SELECT twitter_oauth FROM ttrss_users\n\t\t\tWHERE id = " . $_SESSION['uid']);
    $has_oauth = db_fetch_result($result, 0, 'twitter_oauth');
    if (!$has_oauth || strpos($url, '://api.twitter.com') === false) {
        if (!fetch_file_contents($url, false, $auth_login, $auth_pass)) {
            return 5;
        }
        if (url_is_html($url, $auth_login, $auth_pass)) {
            $feedUrls = get_feeds_from_html($url, $auth_login, $auth_pass);
            if (count($feedUrls) == 0) {
                return 3;
            } else {
                if (count($feedUrls) > 1) {
                    return 4;
                }
            }
            //use feed url as new URL
            $url = key($feedUrls);
        }
    } else {
        if (!fetch_twitter_rss($link, $url, $_SESSION['uid'])) {
            return 5;
        }
        $update_method = 3;
    }
    if ($cat_id == "0" || !$cat_id) {
        $cat_qpart = "NULL";
    } else {
        $cat_qpart = "'{$cat_id}'";
    }
    $result = db_query($link, "SELECT id FROM ttrss_feeds\n\t\t\tWHERE feed_url = '{$url}' AND owner_uid = " . $_SESSION["uid"]);
    if (db_num_rows($result) == 0) {
        $result = db_query($link, "INSERT INTO ttrss_feeds\n\t\t\t\t\t(owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method)\n\t\t\t\tVALUES ('" . $_SESSION["uid"] . "', '{$url}',\n\t\t\t\t'[Unknown]', {$cat_qpart}, '{$auth_login}', '{$auth_pass}', '{$update_method}')");
        $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '{$url}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
        $feed_id = db_fetch_result($result, 0, "id");
        if ($feed_id) {
            update_rss_feed($link, $feed_id, true);
        }
        return 1;
    } else {
        return 0;
    }
}
Beispiel #2
0
    /**
     * Test url_is_html() on RSS
     */
    public function testUrlIsHtmlRss()
    {
        file_put_contents($this->tmpFile, <<<HTM
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title><![CDATA[Planet-PEAR]]></title>
HTM
);
        $this->assertFalse(url_is_html($this->tmpFile));
    }