function fof_get_feeds($user_id, $order = 'feed_title', $direction = 'asc') { $feeds = array(); $result = fof_db_get_subscriptions($user_id); $i = 0; while ($row = fof_db_get_row($result)) { $id = $row['feed_id']; $age = $row['feed_cache_date']; $feeds[$i]['feed_id'] = $id; $feeds[$i]['feed_url'] = $row['feed_url']; $feeds[$i]['feed_title'] = $row['feed_title']; $feeds[$i]['feed_link'] = $row['feed_link']; $feeds[$i]['feed_description'] = $row['feed_description']; $feeds[$i]['feed_image'] = $row['feed_image']; $feeds[$i]['prefs'] = unserialize($row['subscription_prefs']); $feeds[$i]['feed_age'] = $age; list($agestr, $agestrabbr) = fof_nice_time_stamp($age); $feeds[$i]['agestr'] = $agestr; $feeds[$i]['agestrabbr'] = $agestrabbr; $i++; } $tags = fof_db_get_tag_id_map(); for ($i = 0; $i < count($feeds); $i++) { $feeds[$i]['tags'] = array(); if (is_array($feeds[$i]['prefs']['tags'])) { foreach ($feeds[$i]['prefs']['tags'] as $tag) { $feeds[$i]['tags'][] = $tags[$tag]; } } } $result = fof_db_get_item_count($user_id); while ($row = fof_db_get_row($result)) { for ($i = 0; $i < count($feeds); $i++) { if ($feeds[$i]['feed_id'] == $row['id']) { $feeds[$i]['feed_items'] = $row['count']; $feeds[$i]['feed_read'] = $row['count']; $feeds[$i]['feed_unread'] = 0; } } } $result = fof_db_get_unread_item_count($user_id); while ($row = fof_db_get_row($result)) { for ($i = 0; $i < count($feeds); $i++) { if ($feeds[$i]['feed_id'] == $row['id']) { $feeds[$i]['feed_unread'] = $row['count']; } } } foreach ($feeds as $feed) { $feed['feed_starred'] = 0; } $result = fof_db_get_starred_item_count($user_id); while ($row = fof_db_get_row($result)) { for ($i = 0; $i < count($feeds); $i++) { if ($feeds[$i]['feed_id'] == $row['id']) { $feeds[$i]['feed_starred'] = $row['count']; } } } $result = fof_db_get_latest_item_age($user_id); while ($row = fof_db_get_row($result)) { for ($i = 0; $i < count($feeds); $i++) { if ($feeds[$i]['feed_id'] == $row['id']) { $feeds[$i]['max_date'] = $row['max_date']; list($agestr, $agestrabbr) = fof_nice_time_stamp($row['max_date']); $feeds[$i]['lateststr'] = $agestr; $feeds[$i]['lateststrabbr'] = $agestrabbr; } } } $feeds = fof_multi_sort($feeds, $order, $direction != "asc"); return $feeds; }
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); ?> <script> function subscription_tags_refresh(feed) { var params = { subscription_tag_list: feed };
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'); }