예제 #1
0
function fof_is_subscribed($user_id, $url)
{
    return fof_db_is_subscribed($user_id, $url);
}
예제 #2
0
function fof_subscribe($user_id, $url, $unread = 'today')
{
    fof_trace();
    $url = trim($url);
    if (empty($url)) {
        return "<span style=\"color:red\">Error: <b>cannot subscribe to nothing</b> (empty url?)</span><br>\n";
    }
    /* ensure url at least has a reasonable protocol */
    $url = fof_prepare_url($url);
    $feed = fof_db_get_feed_by_url($url);
    if (empty($feed)) {
        /* raw url does not exist, try cooking it with simplepie */
        if (($rss = fof_parse($url)) === false || $rss->error()) {
            $rss_error = isset($rss) && $rss->error() ? $rss->error() : '';
            return "<span style=\"color:red\">Error: <b>Failed to subscribe to '{$url}'</b>" . (!empty($rss_error) ? ": {$rss_error}</span> <span><a href=\"http://feedvalidator.org/check?url=" . urlencode($url) . "\">try to validate it?</a>" : "") . "</span><br>\n";
        }
        $self = $rss->get_link(0, 'self');
        $url = html_entity_decode($self ? $self : $rss->subscribe_url(), ENT_QUOTES);
        $feed = fof_db_get_feed_by_url($url);
        if (empty($feed)) {
            /* cooked url does not exist, add it */
            $new_feed_id = fof_db_add_feed($url, $rss->get_title(), $rss->get_link(), $rss->get_description());
            if (empty($new_feed_id)) {
                return "<span style=\"color:red\">Error: <b>Failed to subscribe to '{$url}'</b></span<br>\n";
            }
            $feed = fof_db_get_feed_by_id($new_feed_id);
            /* assert(!empty($feed)) */
        }
    }
    if (fof_db_is_subscribed($user_id, $url)) {
        return "<span>You are already subscribed to '" . fof_render_feed_link($feed) . "'.</span><br>\n";
    }
    /* subscribe to the feed */
    fof_db_add_subscription($user_id, $feed['feed_id']);
    /* update the feed */
    list($n, $err) = fof_update_feed($new_feed_id);
    if (!empty($err)) {
        return "<span style=\"color:red\">{$err}</span><br>\n";
    }
    /* set requested existing items unread */
    if ($unread != 'no') {
        fof_db_mark_feed_unread($user_id, $feed['feed_id'], $unread);
    }
    /* set tags for user on any existing items */
    fof_apply_plugin_tags($feed['feed_id'], NULL, $user_id);
    return "<span style=\"color:green\"><b>Subscribed to '" . fof_render_feed_link($feed) . "'.</b></span><br>\n";
}