* */ include "header.php"; print "<br>"; $feed = $_GET['feed']; $feeds = array(); $p =& FoF_Prefs::instance(); $admin_prefs = $p->admin_prefs; if ($feed) { $feed = fof_db_get_feed_by_id($feed); $feeds[] = $feed; } else { if ($fof_user_id == 1) { $result = fof_db_get_feeds(); } else { $result = fof_db_get_subscriptions(fof_current_user()); } while ($feed = fof_db_get_row($result)) { if (time() - $feed["feed_cache_date"] < $admin_prefs["manualtimeout"] * 60) { $title = $feed['feed_title']; list($timestamp, ) = fof_nice_time_stamp($feed['feed_cache_date']); print "{$title} was just updated {$timestamp}!<br>"; } else { $feeds[] = $feed; } } } $feeds = fof_multi_sort($feeds, 'feed_cache_attempt_date', false); print "<script>\nwindow.onload = ajaxupdate;\nfeedslist = ["; foreach ($feeds as $feed) { $title = $feed['feed_title'];
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; }
fof_set_content_type('application/javascript'); $tag_id = fof_db_get_tag_by_name($_POST['update_tag_sources']); $subs = fof_db_subscriptions_by_tags(fof_current_user()); /* FIXME: check timeouts, like below */ if (!empty($subs[$tag_id])) { echo 'pendingUpdates.add(' . json_encode($subs[$tag_id]) . ');'; } exit; } /* returns a script block which updates all updatable subscribed feeds */ if (!empty($_POST['update_subscribed_sources'])) { fof_set_content_type('application/javascript'); $now = time(); $timeout = $fof_prefs_obj->admin_prefs['manualtimeout'] * 60; $sources = array(); $statement = fof_db_get_subscriptions(fof_current_user(), true); while (($feed = fof_db_get_row($statement)) !== false) { if ($now - $feed['feed_cache_date'] < $timeout) { continue; } if ($now < $feed['feed_cache_next_attempt']) { continue; } $sources[] = $feed['feed_id']; } if (!empty($sources)) { echo 'pendingUpdates.add(' . json_encode($sources) . ');'; } exit; } /* returns a list of tags for a feed, with markup */
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'); }