more robust feed error handling, at the expense of performance.

Pass profile owner through HTML (yuk) to the ajax updater - as
browser  pre-fetch totally buggers passing it via the server session.
This commit is contained in:
Mike Macgirvin 2010-09-20 19:34:44 -07:00
parent 177a6d7f79
commit 3ad52463f6
8 changed files with 181 additions and 167 deletions

View File

@ -91,6 +91,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
if(! strlen($last_update)) if(! strlen($last_update))
$last_update = 'now - 30 days'; $last_update = 'now - 30 days';
$check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
@ -109,8 +110,9 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
dbesc($check_date), dbesc($check_date),
dbesc($sort) dbesc($sort)
); );
if(! count($r))
killme(); // Will check further below if this actually returned results.
// We will provide an empty feed in any case.
$items = $r; $items = $r;
@ -136,6 +138,11 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
)); ));
if(! count($items)) {
$atom .= '</feed>' . "\r\n";
return $atom;
}
foreach($items as $item) { foreach($items as $item) {
// public feeds get html, our own nodes use bbcode // public feeds get html, our own nodes use bbcode

View File

@ -37,6 +37,7 @@
var msie = false; var msie = false;
var stopped = false; var stopped = false;
var timer = null; var timer = null;
var pr = 0;
$(document).ready(function() { $(document).ready(function() {
$.ajaxSetup({cache: false}); $.ajaxSetup({cache: false});
@ -64,8 +65,8 @@
function NavUpdate() { function NavUpdate() {
if($('#live-network').length) { src = 'network'; liveUpdate(); } if($('#live-network').length) { src = 'network'; pr = $('#live-network').attr('profile'); liveUpdate(); }
if($('#live-profile').length) { src = 'profile'; liveUpdate(); } if($('#live-profile').length) { src = 'profile'; pr = $('#live-profile').attr('profile'); liveUpdate(); }
if(! stopped) { if(! stopped) {
$.get("ping",function(data) { $.get("ping",function(data) {
@ -97,7 +98,7 @@
} }
prev = 'live-' + src; prev = 'live-' + src;
$.get('update_' + src + '?msie=' + ((msie) ? 1 : 0),function(data) { $.get('update_' + src + '?p=' + pr + '&msie=' + ((msie) ? 1 : 0),function(data) {
$('.wall-item-outside-wrapper',data).each(function() { $('.wall-item-outside-wrapper',data).each(function() {
var ident = $(this).attr('id'); var ident = $(this).attr('id');
if($('#' + ident).length == 0) { if($('#' + ident).length == 0) {

View File

@ -61,7 +61,6 @@
continue; continue;
} }
$importer_uid = $contact['uid']; $importer_uid = $contact['uid'];
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
@ -96,15 +95,21 @@
echo "XML: " . $xml . "\r\n"; echo "XML: " . $xml . "\r\n";
} }
if(! $xml) if(! $xml) {
// dead connection - might be a transient event, or this might
// mean the software was uninstalled or the domain expired.
// Will keep trying for one month.
mark_for_death($contact);
continue; continue;
}
$res = simplexml_load_string($xml); $res = simplexml_load_string($xml);
if(intval($res->status) == 1) if(intval($res->status) == 1) {
// we may not be friends anymore. Will keep trying for one month.
mark_for_death($contact); mark_for_death($contact);
}
else { else {
if($contact['term-date'] != '0000-00-00 00:00:00') if($contact['term-date'] != '0000-00-00 00:00:00')
unmark_for_death($contact); unmark_for_death($contact);
@ -113,7 +118,6 @@
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
continue; continue;
$postvars = array(); $postvars = array();
$sent_dfrn_id = hex2bin($res->dfrn_id); $sent_dfrn_id = hex2bin($res->dfrn_id);
@ -145,7 +149,6 @@
$postvars['dfrn_id'] = $idtosend; $postvars['dfrn_id'] = $idtosend;
$xml = post_url($contact['poll'],$postvars); $xml = post_url($contact['poll'],$postvars);
if($debugging) { if($debugging) {
@ -153,14 +156,8 @@
echo "Length:" . strlen($xml) . "\r\n"; echo "Length:" . strlen($xml) . "\r\n";
} }
if(! strlen($xml)) { if(! strlen($xml))
// an empty response may mean there's nothing new - record the fact that we checked
$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($contact['id'])
);
continue; continue;
}
$feed = new SimplePie(); $feed = new SimplePie();
$feed->set_raw_data($xml); $feed->set_raw_data($xml);
@ -240,7 +237,7 @@
} }
// Now process the feed // Now process the feed
if($feed->get_item_quantity()) {
foreach($feed->get_items() as $item) { foreach($feed->get_items() as $item) {
$deleted = false; $deleted = false;
@ -388,9 +385,8 @@
continue; continue;
} }
} }
}
$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($contact['id']) intval($contact['id'])

View File

@ -89,6 +89,7 @@ $a->page['content'] .= $debug_text;
$a->page['content'] .= '<div id="pause"><img src="" alt="" /></div>'; $a->page['content'] .= '<div id="pause"><img src="" alt="" /></div>';
// build page // build page
// Navigation (menu) template // Navigation (menu) template
if($a->module != 'install') if($a->module != 'install')
require_once("nav.php"); require_once("nav.php");

View File

@ -7,7 +7,7 @@ function network_init(&$a) {
} }
function network_content(&$a, $update = false) { function network_content(&$a, $update = 0) {
if(! local_user()) if(! local_user())
return; return;
@ -59,7 +59,7 @@ function network_content(&$a, $update = false) {
// criteria is discovered in javascript). // criteria is discovered in javascript).
if($a->pager['start'] == 0 && $a->argc == 1) if($a->pager['start'] == 0 && $a->argc == 1)
$o .= '<div id="live-network"></div>' . "\r\n"; $o .= '<div id="live-network" profile="' . $_SESSION['uid'] . '"></div>' . "\r\n";
} }
// We aren't going to try and figure out at the item, group, and page level // We aren't going to try and figure out at the item, group, and page level

View File

@ -74,7 +74,11 @@ function profile_init(&$a) {
} }
function profile_content(&$a, $update = false) { function profile_content(&$a, $update = 0) {
file_put_contents('uid.log',"{$_SERVER['QUERY_STRING']} ". session_id() . "\n", FILE_APPEND);
require_once("include/bbcode.php"); require_once("include/bbcode.php");
require_once('include/security.php'); require_once('include/security.php');
@ -86,13 +90,11 @@ function profile_content(&$a, $update = false) {
if($update) { if($update) {
// Ensure we've got a profile owner if updating. // Ensure we've got a profile owner if updating.
$a->profile['profile_uid'] = $_SESSION['profile_uid']; $a->profile['profile_uid'] = $update;
} }
else { else {
if($a->profile['uid'] == get_uid()) if($a->profile['profile_uid'] == get_uid())
$o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>'; $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
// set the uid so we can pick it up during update
$_SESSION['profile_uid'] = $a->profile['uid'];
} }
$contact = null; $contact = null;
@ -158,8 +160,11 @@ function profile_content(&$a, $update = false) {
)); ));
} }
// This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
// because browser prefetching might change it on us. We have to deliver it with the page.
if($tab == 'posts' && (! $a->pager['start'])) if($tab == 'posts' && (! $a->pager['start']))
$o .= '<div id="live-profile"></div>' . "\r\n"; $o .= '<div id="live-profile" profile="' . $a->profile['profile_uid'] . '"></div>' . "\r\n";
} }
// TODO alter registration and settings and profile to update contact table when names and photos change. // TODO alter registration and settings and profile to update contact table when names and photos change.

View File

@ -7,12 +7,14 @@ require_once('mod/network.php');
function update_network_content(&$a) { function update_network_content(&$a) {
$profile_uid = intval($_GET['p']);
header("Content-type: text/html"); header("Content-type: text/html");
echo "<!DOCTYPE html><html><body>\r\n"; echo "<!DOCTYPE html><html><body>\r\n";
echo (($_GET['msie'] == 1) ? '<div>' : '<section>'); echo (($_GET['msie'] == 1) ? '<div>' : '<section>');
$text = network_content($a,true); $text = network_content($a,$profile_uid);
$pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $pattern = "/<img([^>]*) src=\"([^\"]*)\"/";
$replace = "<img\${1} dst=\"\${2}\""; $replace = "<img\${1} dst=\"\${2}\"";
$text = preg_replace($pattern, $replace, $text); $text = preg_replace($pattern, $replace, $text);

View File

@ -7,6 +7,8 @@ require_once('mod/profile.php');
function update_profile_content(&$a) { function update_profile_content(&$a) {
$profile_uid = intval($_GET['p']);
header("Content-type: text/html"); header("Content-type: text/html");
echo "<!DOCTYPE html><html><body>\r\n"; echo "<!DOCTYPE html><html><body>\r\n";
echo (($_GET['msie'] == 1) ? '<div>' : '<section>'); echo (($_GET['msie'] == 1) ? '<div>' : '<section>');
@ -16,7 +18,7 @@ function update_profile_content(&$a) {
// The only ones we need to fetch are those for new page additions, which we'll discover // The only ones we need to fetch are those for new page additions, which we'll discover
// on the client side and then swap the image back. // on the client side and then swap the image back.
$text = profile_content($a,true); $text = profile_content($a,$profile_uid);
$pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $pattern = "/<img([^>]*) src=\"([^\"]*)\"/";
$replace = "<img\${1} dst=\"\${2}\""; $replace = "<img\${1} dst=\"\${2}\"";
$text = preg_replace($pattern, $replace, $text); $text = preg_replace($pattern, $replace, $text);