Example #1
0
    $users = fof_db_get_users();
    while (($subscriber = fof_db_get_row($sub_statement, 'user_id')) !== false) {
        echo '<li>' . $users[$subscriber]['user_name'] . ' (' . $subscriber . ')</li>' . "\n";
    }
    echo '</ul>' . "\n";
    echo '</div>' . "\n";
} elseif (fof_db_is_subscribed_id(fof_current_user(), $feed_id)) {
    echo '<h1>Feed Details</h1>' . "\n";
} else {
    echo '<div class="error"><h1>Not Subscribed</h1>You don\'t know anything about that feed.</div>' . "\n";
    die;
}
if (fof_is_admin() && !fof_db_is_subscribed_id(fof_current_user(), $feed_id)) {
    /* fof_get_feed expects a subscription, so shirk that and just populate overall stats */
    $feed_row = fof_db_get_feed_by_id($feed_id);
    fof_db_subscription_feed_fix($feed_row);
    list($feed_row['feed_items'], $feed_row['feed_tagged'], $counts) = fof_db_feed_counts(fof_current_user(), $feed_id);
    $feed_row = array_merge(array('tags' => array(), 'feed_unread' => 0, 'feed_read' => 0, 'feed_starred' => 0, 'feed_age' => $feed_row['feed_cache_date']), $feed_row);
    list($feed_row['agestr'], $feed_row['agestrabbr']) = fof_nice_time_stamp($feed_row['feed_cache_date']);
    $max_stmt = fof_db_get_latest_item_age(fof_current_user(), $feed_id);
    $feed_row['max_date'] = fof_db_get_row($max_stmt, 'max_date', TRUE);
    list($feed_row['lateststr'], $feed_row['lateststrabbr']) = fof_nice_time_stamp($feed_row['max_date']);
    /* not subscribed, so no subscription preferences to change.. */
    $admin_view = true;
} else {
    $feed_row = fof_get_feed(fof_current_user(), $feed_id);
    $admin_view = false;
}
/* only include the update scripts if subscribed */
if (!$admin_view || fof_db_is_subscribed_id(fof_current_user(), $feed_id)) {
    $feed_id_js = json_encode($feed_id);
Example #2
0
function fof_db_get_item($user_id, $item_id)
{
    global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $FOF_ITEM_TAG_TABLE, $FOF_TAG_TABLE;
    global $fof_connection;
    $item = array();
    fof_trace();
    $query = "SELECT i.*, f.*" . ($user_id ? ", s.subscription_prefs " : '') . " FROM {$FOF_ITEM_TABLE} i " . " JOIN {$FOF_FEED_TABLE} f ON i.feed_id = f.feed_id " . ($user_id ? "JOIN {$FOF_SUBSCRIPTION_TABLE} s ON i.feed_id = s.feed_id AND s.user_id = :user_id " : '') . " WHERE i.item_id = :item_id";
    $statement = $fof_connection->prepare($query);
    $statement->bindValue(':item_id', $item_id);
    if ($user_id) {
        $statement->bindValue(':user_id', $user_id);
    }
    $result = $statement->execute();
    $item = fof_db_get_row($statement, NULL, TRUE);
    $item['tags'] = array();
    if ($user_id) {
        fof_db_subscription_feed_fix($item);
        $query = "SELECT t.tag_name" . " FROM {$FOF_TAG_TABLE} t, {$FOF_ITEM_TAG_TABLE} it" . " WHERE t.tag_id = it.tag_id" . " AND it.item_id = :item_id" . " AND it.user_id = :user_id";
        $statement = $fof_connection->prepare($query);
        $statement->bindValue(':item_id', $item_id);
        $statement->bindValue(':user_id', $user_id);
        $result = $statement->execute();
        while (($row = fof_db_get_row($statement)) !== false) {
            $item['tags'][] = $row['tag_name'];
        }
    }
    return $item;
}
Example #3
0
function fof_get_feeds($user_id, $order = 'feed_title', $direction = 'asc')
{
    $feeds = array();
    $tagmap = fof_db_get_tag_id_map();
    $result = fof_db_get_subscriptions($user_id);
    $i = 0;
    $feeds_index = array();
    while (($row = fof_db_get_row($result)) !== false) {
        /* remember where we are */
        $feeds_index[$row['feed_id']] = $i;
        /* fix user prefs */
        fof_db_subscription_feed_fix($row);
        /* initialize some values.. these will be populated later */
        $row['feed_items'] = 0;
        $row['feed_read'] = 0;
        $row['feed_unread'] = 0;
        $row['feed_starred'] = 0;
        $row['feed_tagged'] = 0;
        $row['max_date'] = 0;
        $row['lateststr'] = '';
        $row['lateststrabbr'] = '';
        /* we can set these now, though */
        $row['feed_age'] = $row['feed_cache_date'];
        list($row['agestr'], $row['agestrabbr']) = fof_nice_time_stamp($row['feed_cache_date']);
        $row['tags'] = array();
        foreach ($row['subscription_prefs']['tags'] as $tagid) {
            $row['tags'][] = $tagmap[$tagid];
        }
        $feeds[$i] = $row;
        $i++;
    }
    /* tally up all items */
    $result = fof_db_get_item_count($user_id);
    while (($row = fof_db_get_row($result)) !== false) {
        $i = $feeds_index[$row['feed_id']];
        $feeds[$i]['feed_items'] += $row['count'];
        $feeds[$i]['feed_read'] += $row['count'];
    }
    /* tally up unread items */
    $result = fof_db_get_item_count($user_id, 'unread');
    while (($row = fof_db_get_row($result)) !== false) {
        $i = $feeds_index[$row['feed_id']];
        $feeds[$i]['feed_unread'] += $row['count'];
        $feeds[$i]['feed_read'] -= $row['count'];
    }
    /* tally up starred items */
    $result = fof_db_get_item_count($user_id, 'starred');
    while (($row = fof_db_get_row($result)) !== false) {
        $i = $feeds_index[$row['feed_id']];
        $feeds[$i]['feed_starred'] += $row['count'];
    }
    /* tally up tags which aren't system-tags */
    $result = fof_db_get_item_count($user_id, 'tagged');
    while (($row = fof_db_get_row($result)) !== false) {
        $i = $feeds_index[$row['feed_id']];
        $feeds[$i]['feed_tagged'] += $row['count'];
    }
    /* find most recent item for each feed */
    $result = fof_db_get_latest_item_age($user_id);
    while (($row = fof_db_get_row($result)) !== false) {
        $i = $feeds_index[$row['feed_id']];
        $feeds[$i]['max_date'] = $row['max_date'];
        list($feeds[$i]['lateststr'], $feeds[$i]['lateststrabbr']) = fof_nice_time_stamp($row['max_date']);
    }
    return fof_multi_sort($feeds, $order, $direction != 'asc');
}