From 36a77c6db2272d7db31982642715034ce718552f Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Mon, 1 Nov 2010 17:56:36 -0700 Subject: build feeds rather than template them --- include/items.php | 138 +++++++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 63 deletions(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index 7f62f6dec..62f0876ad 100644 --- a/include/items.php +++ b/include/items.php @@ -27,8 +27,10 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) { $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($owner_id) ); - if(count($r)) + if(count($r)) { $owner = $r[0]; + $owner['nickname'] = $owner_nick; + } else killme(); @@ -90,7 +92,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) { $sort = 'ASC'; 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'); @@ -117,9 +119,6 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) { $items = $r; $feed_template = load_view_file('view/atom_feed.tpl'); - $tomb_template = load_view_file('view/atom_tomb.tpl'); - $item_template = load_view_file('view/atom_item.tpl'); - $cmnt_template = load_view_file('view/atom_cmnt.tpl'); $atom = ''; @@ -169,69 +168,13 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) { // public feeds get html, our own nodes use bbcode if($dfrn_id === '*') { - $allow = (($item['last-child']) ? 1 : 0); - $item['body'] = bbcode($item['body']); $type = 'html'; } else { - $allow = ((($item['last-child']) && ($contact['rel']) && ($contact['rel'] != REL_FAN)) ? 1 : 0); $type = 'text'; } - if($item['deleted']) { - $atom .= replace_macros($tomb_template, array( - '$id' => xmlify($item['uri']), - '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)) - )); - } - else { - $verb = construct_verb($item); - $actobj = construct_activity($item); - $mentioned = get_mentions($item); - - if($item['parent'] == $item['id']) { - $atom .= replace_macros($item_template, array( - '$name' => xmlify($item['name']), - '$profile_page' => xmlify($item['url']), - '$thumb' => xmlify($item['thumb']), - '$owner_name' => xmlify($item['owner-name']), - '$owner_profile_page' => xmlify($item['owner-link']), - '$owner_thumb' => xmlify($item['owner-avatar']), - '$item_id' => xmlify($item['uri']), - '$title' => xmlify($item['title']), - '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)), - '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)), - '$location' => xmlify($item['location']), - '$coord' => xmlify($item['coord']), - '$type' => $type, - '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner_nick . '/' . $item['id']), - '$content' => xmlify($item['body']), - '$verb' => xmlify($verb), - '$actobj' => $actobj, // do not xmlify - '$mentioned' => $mentioned, - '$comment_allow' => $allow - )); - } - else { - $atom .= replace_macros($cmnt_template, array( - '$name' => xmlify($item['name']), - '$profile_page' => xmlify($item['url']), - '$thumb' => xmlify($item['thumb']), - '$item_id' => xmlify($item['uri']), - '$title' => xmlify($item['title']), - '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)), - '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)), - '$type' => $type, - '$content' => xmlify($item['body']), - '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner_nick . '/' . $item['id']), - '$verb' => xmlify($verb), - '$actobj' => $actobj, // do not xmlify - '$mentioned' => $mentioned, - '$parent_id' => xmlify($item['parent-uri']), - '$comment_allow' => $allow - )); - } - } + $atom .= atom_entry($item,$type,null,$owner,true); } $atom .= '' . "\r\n"; @@ -1050,4 +993,73 @@ function subscribe_to_hub($url,$importer,$contact) { post_url($url,$params); return; -} \ No newline at end of file +} + + +function atom_author($tag,$name,$uri,$h,$w,$photo) { + $o = ''; + if(! $tag) + return $o; + $name = xmlify($name); + $uri = xmlify($uri); + $h = intval($h); + $w = intval($w); + $photo = xmlify($photo); + + + $o .= "<$tag>\r\n"; + $o .= "$name\r\n"; + $o .= "$uri\r\n"; + $o .= '' . "\r\n"; + $o .= '' . "\r\n"; + $o .= "\r\n"; + return $o; +} + +function atom_entry($item,$type,$author,$owner,$comment = false) { + + if($item['deleted']) + return '' . "\r\n"; + + $a = get_app(); + + $o = "\r\n"; + + if(is_array($author)) + $o .= atom_author('author',$author['name'],$author['url'],80,80,$author['thumb']); + else + $o .= atom_author('author',$item['name'],$item['url'],80,80,$item['thumb']); + if(strlen($item['owner-name'])) + $o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']); + + if($item['parent'] != $item['id']) + $o .= '' . "\r\n"; + + $o .= '' . xmlify($item['uri']) . '' . "\r\n"; + $o .= '' . xmlify($item['title']) . '' . "\r\n"; + $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; + $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; + $o .= '' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '' . "\r\n"; + $o .= '' . "\r\n"; + if($comment) + $o .= '' . intval($item['last-child']) . '' . "\r\n"; + if($item['location']) + $o .= '' . xmlify($item['location']) . '' . "\r\n"; + if($item['coord']) + $o .= '' . xmlify($item['coord']) . '' . "\r\n"; + + $verb = construct_verb($item); + $o .= '' . xmlify($verb) . '' . "\r\n"; + $actobj = construct_activity($item); + if(strlen($actobj)) + $o .= $actobj; + + $mentioned = get_mentions($item); + if($mentioned) + $o .= $mentioned; + + $o .= '' . "\r\n"; + + return $o; +} + \ No newline at end of file -- cgit v1.2.3