feed cleanup

This commit is contained in:
Friendika 2011-02-07 17:06:04 -08:00
parent 7dd56fa14c
commit 18c5d1ff90
4 changed files with 70 additions and 65 deletions

View file

@ -2365,4 +2365,45 @@ function feed_birthday($uid,$tz) {
} }
return $birthday; return $birthday;
}} }}
/**
* return atom link elements for all of our hubs
*/
if(! function_exists('feed_hublinks')) {
function feed_hublinks() {
$hub = get_config('system','huburl');
$hubxml = '';
if(strlen($hub)) {
$hubs = explode(',', $hub);
if(count($hubs)) {
foreach($hubs as $h) {
$h = trim($h);
if(! strlen($h))
continue;
$hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
}
}
}
return $hubxml;
}}
/* return atom link elements for salmon endpoints */
if(! function_exists('feed_salmonlinks')) {
function feed_salmonlinks($nick) {
$a = get_app();
$salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
// old style links that status.net still needed as of 12/2010
$salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
$salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify($a->get_baseurl() . '/salmon/' . $nick) . '" />' . "\n" ;
return $salmon;
}}

View file

@ -9,37 +9,27 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
// default permissions - anonymous user // default permissions - anonymous user
$sql_extra = " if(! strlen($owner_nick))
AND `allow_cid` = ''
AND `allow_gid` = ''
AND `deny_cid` = ''
AND `deny_gid` = ''
";
if(strlen($owner_nick) && ! intval($owner_nick)) {
$r = q("SELECT `uid`, `nickname`, `timezone` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
dbesc($owner_nick)
);
if(count($r)) {
$owner_id = $r[0]['uid'];
$owner_nick = $r[0]['nickname'];
$owner_tz = $r[0]['timezone'];
}
}
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($owner_id)
);
if(count($r)) {
$owner = $r[0];
$owner['nickname'] = $owner_nick;
}
else
killme(); killme();
$birthday = feed_birthday($owner_id,$owner_tz); $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
if($dfrn_id && $dfrn_id != '*') { $r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone`
FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE `contact`.`self` = 1 AND `user`.`nickname` = '%s' LIMIT 1",
dbesc($owner_nick)
);
if(! count($r))
killme();
$owner = $r[0];
$owner_id = $owner['user_uid'];
$owner_nick = $owner['nickname'];
$birthday = feed_birthday($owner_id,$owner['timezone']);
if(strlen($dfrn_id)) {
$sql_extra = ''; $sql_extra = '';
switch($direction) { switch($direction) {
@ -65,7 +55,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
); );
if(! count($r)) if(! count($r))
return false; killme();
$contact = $r[0]; $contact = $r[0];
$groups = init_groups_visitor($contact['id']); $groups = init_groups_visitor($contact['id']);
@ -119,7 +109,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
); );
// Will check further below if this actually returned results. // Will check further below if this actually returned results.
// We will provide an empty feed in any case. // We will provide an empty feed if that is the case.
$items = $r; $items = $r;
@ -127,25 +117,9 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
$atom = ''; $atom = '';
$hub = get_config('system','huburl'); $hubxml = feed_hublinks();
$hubxml = '';
if(strlen($hub)) {
$hubs = explode(',', $hub);
if(count($hubs)) {
foreach($hubs as $h) {
$h = trim($h);
if(! strlen($h))
continue;
$hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
}
}
}
$salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
$salmon .= '<link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
$salmon .= '<link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
$salmon = feed_salmonlinks($owner_nick);
$atom .= replace_macros($feed_template, array( $atom .= replace_macros($feed_template, array(
'$version' => xmlify(FRIENDIKA_VERSION), '$version' => xmlify(FRIENDIKA_VERSION),
@ -178,7 +152,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
// public feeds get html, our own nodes use bbcode // public feeds get html, our own nodes use bbcode
if($dfrn_id === '*') { if($dfrn_id === '') {
$type = 'html'; $type = 'html';
} }
else { else {

View file

@ -179,23 +179,13 @@ function notifier_run($argv, $argc){
$mail_template = load_view_file('view/atom_mail.tpl'); $mail_template = load_view_file('view/atom_mail.tpl');
$atom = ''; $atom = '';
$hubxml = '';
$slaps = array(); $slaps = array();
if(strlen($hub)) { $hubxml = feed_hublinks();
$hubs = explode(',', $hub);
if(count($hubs)) {
foreach($hubs as $h) {
$h = trim($h);
if(! strlen($h))
continue;
$hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
}
}
}
$birthday = feed_birthday($owner['uid'],$owner['timezone']); $birthday = feed_birthday($owner['uid'],$owner['timezone']);
if($birthday)
if(strlen($birthday))
$birthday = '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>'; $birthday = '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>';
$atom .= replace_macros($feed_template, array( $atom .= replace_macros($feed_template, array(
@ -398,7 +388,7 @@ function notifier_run($argv, $argc){
* *
*/ */
$max_allowed = ((get_config('system','maxpubdeliver') === false) ? 150 : intval(get_config('system','maxdeliver'))); $max_allowed = ((get_config('system','maxpubdeliver') === false) ? 150 : intval(get_config('system','maxpubdeliver')));
/** /**
* *

View file

@ -28,7 +28,7 @@ function dfrn_poll_init(&$a) {
if(($dfrn_id === '') && (! x($_POST,'dfrn_id')) && ($a->argc > 1)) { if(($dfrn_id === '') && (! x($_POST,'dfrn_id')) && ($a->argc > 1)) {
logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] ); logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] );
header("Content-type: application/atom+xml"); header("Content-type: application/atom+xml");
$o = get_feed_for($a, '*', $a->argv[1],$last_update); $o = get_feed_for($a, '', $a->argv[1],$last_update);
echo $o; echo $o;
killme(); killme();
} }