function fof_db_tag_items($user_id, $tag_id, $items) { global $FOF_ITEM_TAG_TABLE; if (!$items) { return; } if (!is_array($items)) { $items = array($items); } foreach ($items as $item) { $sql[] = sprintf("(%d, %d, %d)", $user_id, $tag_id, $item); } $values = implode(",", $sql); $sql = "insert into {$FOF_ITEM_TAG_TABLE} (user_id, tag_id, item_id) values " . $values; $result = fof_db_query($sql, 1); if (!$result && mysql_errno() != 1062) { die("Cannot query database. Have you run <a href=\"install.php\"><code>install.php</code></a> to create or upgrade your installation? MySQL says: <b>" . mysql_error() . "</b>"); } }
EOQ; fof_db_query($query); $query = <<<EOQ DROP TABLE `{$FOF_TAG_TABLE}`; EOQ; fof_db_query($query); $query = <<<EOQ DROP TABLE `{$FOF_ITEM_TAG_TABLE}`; EOQ; fof_db_query($query); $query = <<<EOQ DROP TABLE `{$FOF_SUBSCRIPTION_TABLE}`; EOQ; fof_db_query($query); $query = <<<EOQ DROP TABLE `{$FOF_USER_TABLE}`; EOQ; fof_db_query($query); echo 'Done. Now just delete this entire directory and we\'ll forget this ever happened.'; } else { ?> <script> if(confirm('This is your last chance. Do you really want to uninstall Feed on Feeds?')) { document.location = './uninstall.php?really=really'; } </script> <a href="."><b>phew!</b></a> </body></html> <?php }
function fof_update_feed($id) { if (!$id) { return 0; } $feed = fof_db_get_feed_by_id($id); $url = $feed['feed_url']; fof_log("Updating {$url}"); fof_db_feed_mark_attempted_cache($id); $rss = fof_parse($feed['feed_url']); if ($rss->error()) { fof_log("feed update failed: " . $rss->error(), "update"); return array(0, "Error: <b>" . $rss->error() . "</b> <a href=\"http://feedvalidator.org/check?url={$url}\">try to validate it?</a>"); } $sub = html_entity_decode($rss->subscribe_url(), ENT_QUOTES); $self_link = $rss->get_link(0, 'self'); if ($self_link) { $sub = html_entity_decode($self_link, ENT_QUOTES); } fof_log("subscription url is {$sub}"); $image = $feed['feed_image']; $image_cache_date = $feed['feed_image_cache_date']; if ($feed['feed_image_cache_date'] < time() - 7 * 24 * 60 * 60) { $image = $rss->get_favicon(); $image_cache_date = time(); } $title = $rss->get_title(); if ($title == "") { $title = "[no title]"; } fof_db_feed_update_metadata($id, $sub, $title, $rss->get_link(), $rss->get_description(), $image, $image_cache_date); $feed_id = $feed['feed_id']; $n = 0; if ($rss->get_items()) { foreach ($rss->get_items() as $item) { $link = $item->get_permalink(); $title = $item->get_title(); $content = $item->get_content(); $date = $item->get_date('U'); if (!$date) { $date = time(); } $item_id = $item->get_id(); if (!$item_id) { $item_id = $link; } $id = fof_db_find_item($feed_id, $item_id); if ($id == NULL) { $n++; global $fof_item_prefilters; foreach ($fof_item_prefilters as $filter) { list($link, $title, $content) = $filter($item, $link, $title, $content); } $id = fof_db_add_item($feed_id, $item_id, $link, $title, $content, time(), $date, $date); fof_apply_tags($feed_id, $id); $republished = false; // this was a failed attempt to avoid duplicates when subscribing to // a "planet" type feed when you already have some of the feeds in the // planet subscribed. in the end there were just too many cases where // dupes still got through (like the 'source' feed url being just slightly // different from the subscribed url). // // maybe a better approach would be simply using the Atom GUID as a // true *GU* ID. /* $source = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'); $links = $source[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; if(is_array($links)) { foreach($links as $link) { if($link['attribs']['']['rel'] == 'self') { $feed_url = $link['attribs']['']['href']; $feed = fof_db_get_feed_by_url($feed_url); if($feed) { fof_log("was repub from $feed_url"); $republished = true; $result = fof_get_subscribed_users($feed_id); $repub_subscribers = array(); while($row = fof_db_get_row($result)) { $repub_subscribers[] = $row['user_id']; fof_log("repub_sub: " . $row['user_id']); } $result = fof_get_subscribed_users($feed['feed_id']); $original_subscribers = array(); while($row = fof_db_get_row($result)) { $original_subscribers[] = $row['user_id']; fof_log("orig_sub: " . $row['user_id']); } $new_subscribers = array_diff($repub_subscribers, $original_subscribers); fof_db_mark_item_unread($new_subscribers, $id); $old_subscribers = array_intersect($original_subscribers, $repub_subscribers); foreach($old_subscribers as $user) { fof_tag_item($user, $id, 'republished'); } } } } } */ if (!$republished) { fof_mark_item_unread($feed_id, $id); } fof_apply_plugin_tags($feed_id, $id, NULL); } $ids[] = $id; } } // optionally purge old items - if 'purge' is set we delete items that are not // unread or starred, not currently in the feed or within sizeof(feed) items // of being in the feed, and are over 'purge' many days old $p =& FoF_Prefs::instance(); $admin_prefs = $p->admin_prefs; if ($admin_prefs['purge'] != "") { fof_log('purge is ' . $admin_prefs['purge']); $count = count($ids); fof_log('items in feed: ' . $count); if (count($ids) != 0) { $in = implode(", ", $ids); global $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE; $sql = "select item_id, item_cached from {$FOF_ITEM_TABLE} where feed_id = {$feed_id} and item_id not in ({$in}) order by item_cached desc limit {$count}, 1000000000"; $result = fof_db_query($sql); while ($row = fof_db_get_row($result)) { if ($row['item_cached'] < time() - $admin_prefs['purge'] * 24 * 60 * 60) { if (!fof_item_has_tags($row['item_id'])) { $delete[] = $row['item_id']; } } } $ndelete = count($delete); if (count($delete) != 0) { $in = implode(", ", $delete); fof_db_query("delete from {$FOF_ITEM_TABLE} where item_id in ({$in})"); fof_db_query("delete from {$FOF_ITEM_TAG_TABLE} where item_id in ({$in})"); } } } unset($rss); fof_db_feed_mark_cached($feed_id); $log = "feed update complete, {$n} new items, {$ndelete} items purged"; if ($admin_prefs['purge'] == "") { $log .= " (purging disabled)"; } fof_log($log, "update"); return array($n, ""); }
echo "<font color='red'>Can't create directory <code>" . getcwd() . "/cache/</code>.<br>You will need to create it yourself, and make it writeable by your PHP process.<br>Then, reload this page.</font>"; echo "</div></body></html>"; exit; } } if (!is_writable("cache")) { echo "<font color='red'>The directory <code>" . getcwd() . "/cache/</code> exists, but is not writable.<br>You will need to make it writeable by your PHP process.<br>Then, reload this page.</font>"; echo "</div></body></html>"; exit; } ?> Cache directory exists and is writable.<hr> <?php $result = fof_db_query("select * from {$FOF_USER_TABLE} where user_name = 'admin'"); if (mysql_num_rows($result) == 0) { ?> You now need to choose an initial password for the 'admin' account:<br> <form> <table> <tr><td>Password:</td><td><input type=password name=password></td></tr> <tr><td>Password again:</td><td><input type=password name=password2></td></tr> </table> <input type=submit value="Set Password"> </form> <?php } else {
?> "> minutes<br><br> Allow manual feed updates every <input size=4 type=string name=manualtimeout value="<?php echo $prefs->get('manualtimeout'); ?> "> minutes<br><br> <input type=submit name=adminprefs value="Save Options"> </form> <br><h1>Add User</h1> <form method="post" action="prefs.php" style="border: 1px solid black; margin: 10px; padding: 10px;"> Username: <input type=string name=username> Password: <input type=string name=password> <input type=submit name=adduser value="Add user"> </form> <?php $result = fof_db_query("select user_name from {$FOF_USER_TABLE} where user_id > 1"); while ($row = fof_db_get_row($result)) { $username = $row['user_name']; $delete_options .= "<option value={$username}>{$username}</option>"; } if (isset($delete_options)) { ?> <br><h1>Delete User</h1> <form method="post" action="prefs.php" style="border: 1px solid black; margin: 10px; padding: 10px;" onsubmit="return confirm('Delete User - Are you sure?')"> <select name=username><?php echo $delete_options; ?> </select> <input type=submit name=deleteuser value="Delete user"><br> </form>