logging now controlled by pref, and only update favicons once a week (run install.php to upgrade your schema!)

orig_fof
steveminutillo 2007-06-30 04:16:22 +00:00
parent 71718f66b7
commit ba58e1b03f
7 changed files with 87 additions and 11 deletions

View File

@ -73,6 +73,7 @@ class FoF_Prefs
"purge" => 30,
"autotimeout" => 30,
"manualtimeout" => 15,
"logging" => false,
);
$this->stuff_array($this->prefs, $defaults);

View File

@ -65,7 +65,7 @@ function fof_db_query($sql, $live=0)
$t2 = (float)$sec + (float)$usec;
$elapsed = $t2 - $t1;
$logmessage = sprintf("%.3f: [%s] (%d / %d)", $elapsed, $sql, $num, $affected);
fof_log($logmessage);
fof_log($logmessage, "query");
if($live)
{
@ -108,7 +108,7 @@ function fof_db_feed_mark_attempted_cache($feed_id)
$result = fof_safe_query("update $FOF_FEED_TABLE set feed_cache_attempt_date = %d where feed_id = %d", time(), $feed_id);
}
function fof_db_feed_update_metadata($feed_id, $url, $title, $link, $description, $image)
function fof_db_feed_update_metadata($feed_id, $url, $title, $link, $description, $image, $image_cache_date)
{
global $FOF_FEED_TABLE;
@ -125,6 +125,9 @@ function fof_db_feed_update_metadata($feed_id, $url, $title, $link, $description
$sql .= ", feed_image = NULL ";
}
$sql .= ", feed_image_cache_date = %d ";
$args[] = $image_cache_date;
$sql .= "where feed_id = %d";
$args[] = $feed_id;

View File

@ -35,6 +35,11 @@ if(!$fof_no_login)
require_user();
$fof_prefs_obj =& FoF_Prefs::instance();
}
else
{
$fof_user_id = 1;
$fof_prefs_obj =& FoF_Prefs::instance();
}
require_once('simplepie/simplepie.inc');
@ -48,11 +53,21 @@ function fof_set_content_type()
}
}
function fof_log($message)
function fof_log($message, $topic="debug")
{
global $LOG;
//if(!isset($LOG)) $LOG = fopen("fof.log", 'a');
//fwrite($LOG, "$message\n");
global $fof_prefs_obj;
if(!$fof_prefs_obj) return;
$p = $fof_prefs_obj->admin_prefs;
if(!$p['logging']) return;
static $log;
if(!isset($log)) $log = fopen("fof.log", 'a');
$message = str_replace ("\n", " ", $message);
fwrite($log, date('r') . " [$topic] $message\n");
}
function require_user()
@ -711,18 +726,29 @@ function fof_update_feed($id)
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 = $rss->subscribe_url();
$self_link = $rss->get_link(0, 'self');
if($self_link) $sub = $self_link;
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/feed-icon.png");
$image_cache_date = time();
}
fof_db_feed_update_metadata($id, $sub, $rss->get_title(), $rss->get_link(), $rss->get_description(), $rss->get_favicon("./image/feed-icon.png") );
fof_db_feed_update_metadata($id, $sub, $rss->get_title(), $rss->get_link(), $rss->get_description(), $image, $image_cache_date );
$feed_id = $feed['feed_id'];
$n = 0;
if($rss->get_items())
{
@ -743,9 +769,7 @@ function fof_update_feed($id)
$id = fof_db_find_item($feed_id, $item_id);
if($id == NULL)
{
fof_log("$id ($title) is a new item");
{
$n++;
$id = fof_db_add_item($feed_id, $item_id, $link, $title, $content, time(), $date, $date);
fof_apply_tags($feed_id, $id);
@ -857,8 +881,10 @@ function fof_update_feed($id)
}
}
$ndelete = count($delete);
if(count($delete) != 0)
{
fof_log("purging " . count($delete) . "items", "update");
$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)" );
@ -870,6 +896,14 @@ function fof_update_feed($id)
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, "");
}

View File

@ -182,6 +182,7 @@ CREATE TABLE IF NOT EXISTS `$FOF_FEED_TABLE` (
`feed_link` text NOT NULL,
`feed_description` text NOT NULL,
`feed_image` text,
`feed_image_cache_date` int(11) default '0',
`feed_cache_date` int(11) default '0',
`feed_cache_attempt_date` int(11) default '0',
`feed_cache` text,
@ -256,6 +257,21 @@ foreach($tables as $table)
?>
Tables exist.<hr>
<?php
$result = fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_image_cache_date'");
if(mysql_num_rows($result) == 0)
{
print "Upgrading schema...";
fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_image_cache_date` INT( 11 ) DEFAULT '0' AFTER `feed_image` ;");
print "Done.<hr>";
}
?>
<?php
$result = fof_db_query("show columns from $FOF_USER_TABLE like 'user_password_hash'");

View File

@ -21,6 +21,7 @@ if(isset($_POST['adminprefs']))
$prefs->set('purge', $_POST['purge']);
$prefs->set('manualtimeout', $_POST['manualtimeout']);
$prefs->set('autotimeout', $_POST['autotimeout']);
$prefs->set('logging', $_POST['logging']);
$prefs->save();
@ -231,6 +232,7 @@ foreach($feeds as $row)
<br><h1>Feed on Feeds - Admin Options</h1>
<form method="post" action="prefs.php" style="border: 1px solid black; margin: 10px; padding: 10px;">
Enable logging? <input type=checkbox name=logging <?php if($prefs->get('logging')) echo "checked" ?>><br><br>
Purge read items after <input size=4 type=string name=purge value="<?php echo $prefs->get('purge')?>"> days (leave blank to never purge)<br><br>
Allow automatic feed updates every <input size=4 type=string name=autotimeout value="<?php echo $prefs->get('autotimeout')?>"> minutes<br><br>
Allow manual feed updates every <input size=4 type=string name=manualtimeout value="<?php echo $prefs->get('manualtimeout')?>"> minutes<br><br>

View File

@ -6606,6 +6606,8 @@ class SimplePie_File
{
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
$this->success = false;
fof_log("SimplePie_File (curl) $url: error: $this->error", "update");
}
else
{
@ -6619,6 +6621,9 @@ class SimplePie_File
$this->headers = $parser->headers;
$this->body = $parser->body;
$this->status_code = $parser->status_code;
fof_log("SimplePie_File (curl) $url: $this->status_code", "update");
if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && !empty($this->headers['location']) && $this->redirects < $redirects)
{
$this->redirects++;
@ -6645,6 +6650,8 @@ class SimplePie_File
{
$this->error = 'fsockopen error: ' . $errstr;
$this->success = false;
fof_log("SimplePie_File (fsockopen) $url: error: $this->error", "update");
}
else
{
@ -6684,6 +6691,7 @@ class SimplePie_File
$this->headers = $parser->headers;
$this->body = $parser->body;
$this->status_code = $parser->status_code;
fof_log("SimplePie_File (fsockopen) $url: $this->status_code", "update");
if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && !empty($this->headers['location']) && $this->redirects < $redirects)
{
$this->redirects++;
@ -6703,6 +6711,7 @@ class SimplePie_File
{
$this->error = 'fsocket timed out';
$this->success = false;
fof_log("SimplePie_File (fsockopen) $url: error: $this->error", "update");
}
fclose($this->fp);
}

View File

@ -23,6 +23,8 @@ include_once("fof-main.php");
$p =& FoF_Prefs::instance();
$fof_admin_prefs = $p->prefs;
fof_log("=== update started, timeout = $fof_admin_prefs[autotimeout], purge = $fof_admin_prefs[purge] ===", "update");
$result = fof_db_get_feeds();
$feeds = array();
@ -33,6 +35,10 @@ while($feed = fof_db_get_row($result))
{
$feeds[] = $feed;
}
else
{
fof_log("skipping $feed[feed_url]", "update");
}
}
$feeds = fof_multi_sort($feeds, 'feed_cache_attempt_date', false);
@ -40,10 +46,15 @@ $feeds = fof_multi_sort($feeds, 'feed_cache_attempt_date', false);
foreach($feeds as $feed)
{
$id = $feed['feed_id'];
fof_log("updating $feed[feed_url]", "update");
fof_update_feed($id);
}
fof_log("optimizing database", "update");
fof_db_optimize();
fof_log("=== update complete ===", "update");
ob_end_clean();
?>