feed related

This commit is contained in:
Mike Macgirvin 2010-07-14 23:04:10 -07:00
parent 43f8dd6802
commit d20e1a6f93
7 changed files with 215 additions and 63 deletions

View file

@ -425,3 +425,15 @@ function paginate(&$a) {
} }
return $o; return $o;
} }
function expand_acl($s) {
if(strlen($s)) {
$a = explode('<',$s);
for($x = 0; $x < count($a); $x ++) {
$a[$x] = intval(str_replace(array('<','>'),array('',''),$a[$x]));
}
return $a;
}
return array();
}

View file

@ -151,3 +151,16 @@ EOT;
return $o; return $o;
} }
function expand_groups($a) {
if(! (is_array($a) && count($a)))
return array();
$groups = implode(',', $a);
$groups = dbesc($groups);
$r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
$ret = array();
if(count($r))
foreach($r as $rr)
$ret[] = $rr['contact-id'];
return $ret;
}

View file

@ -32,78 +32,160 @@ if($argc < 3)
} }
$is_parent = false;
$recipients = array(); $recipients = array();
// fetch requested item(s) // find ancestors
$r = q("SELECT `item`.*, `contact`.*,`item`.`id` AS `item_id` FROM `item` LEFT JOIN `contact` ON `item`.`contact-id` = `contact`.`id` $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
WHERE `item`.`id` = %d LIMIT 1",
intval($item_id) intval($item_id)
); );
if(! count($r)) if(! count($r))
killme(); killme();
$item = $r[0]; $parent = $r[0]['parent'];
$uid = $r[0]['uid'];
$updated = $r[0]['edited'];
$recipients[] = $item['contact-id']; $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
intval($parent)
);
if($item['parent'] == $item['id']) { if(! count($items))
$is_parent = true; killme();
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
intval($uid)
);
if(count($r))
$owner = $r[0];
else
killme();
require_once('include/group.php');
$parent = $items[0];
if(strlen($parent['remote-id'])) {
$followup = true;
$conversant_str = dbesc($parent['contact-id']);
} }
else { else {
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", $followup = false;
intval($item['parent'])
); $allow_people = expand_acl($parent['allow_cid']);
if(count($r)) $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
$parent = $r[0]; $deny_people = expand_acl($parent['deny_cid']);
$deny_groups = expand_groups(expand_acl($parent['deny_gid']));
$conversants = array();
foreach($items as $item) {
$recipients[] = $item['contact-id'];
$conversants[] = $item['contact-id'];
} }
if(is_array($parent)) $conversants = array_unique($conversants,SORT_NUMERIC);
$recipients[] = $parent['contact-id'];
$r = q("SELECT `contact-id` FROM `item` WHERE `hash` = '%s' AND `id` != %d AND `id` != %d",
dbesc($item['hash']), $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
intval($item['id']), $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
intval($item['parent']) $recipients = array_diff($recipients,$deny);
);
if(count($r)) { $conversant_str = dbesc(implode(', ',$conversants));
foreach($r as $rr) {
if($rr['contact-id'] != $item['contact-id'])
$recipients[] = $rr['contact-id'];
}
} }
$tpl = file_get_contents('view/atomic.tpl'); $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) ");
// FIXME should dump the entire conversation if( ! count($r))
killme();
$atom = replace_macros($tpl, array( $contacts = $r;
$feed_template = file_get_contents('view/atom_feed.tpl');
$tomb_template = file_get_contents('view/atom_tomb.tpl');
$item_template = file_get_contents('view/atom_item.tpl');
$cmnt_template = file_get_contents('view/atom_cmnt.tpl');
$atom = '';
$atom .= replace_macros($feed_template, array(
'$feed_id' => xmlify($baseurl), '$feed_id' => xmlify($baseurl),
'$feed_title' => xmlify('Wall Item'), '$feed_title' => xmlify($owner['name']),
'$feed_updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')) , '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\Th:i:s\Z')) ,
'$name' => xmlify($item['name']), '$name' => xmlify($owner['name']),
'$profile_page' => xmlify($item['url']), '$profile_page' => xmlify($owner['url']),
'$thumb' => xmlify($item['thumb']), '$thumb' => xmlify($owner['thumb'])
'$item_id' => xmlify($item['hash'] . '-' . $item['id']),
'$title' => xmlify(''),
'$link' => xmlify($baseurl . '/item/' . $item['id']),
'$updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')),
'$summary' => xmlify(''),
'$content' => xmlify($item['body'])
)); ));
print_r($atom); if($followup) {
// atomify $atom .= replace_macros($cmnt_template, array(
'$name' => xmlify($contact['name']),
'$profile_page' => xmlify($contact['url']),
'$thumb' => xmlify($contact['thumb']),
'$item_id' => xmlify("urn:X-dfrn:{$item['hash']}"),
'$title' => xmlify($item['title']),
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z')),
'$content' =>xmlify($item['body']),
'$parent_id' => xmlify("{$items[0]['remote-id']}")
));
}
else {
foreach($items as $item) {
if($item['deleted']) {
$atom .= replace_macros($tomb_template, array(
'$id' => xmlify("urn:X-dfrn:{$item['hash']}"),
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z'))
));
}
else {
foreach($contacts as $contact) {
if($item['contact-id'] == $contact['id']) {
if($item['parent'] == $item['id']) {
$atom .= replace_macros($item_template, array(
'$name' => xmlify($contact['name']),
'$profile_page' => xmlify($contact['url']),
'$thumb' => xmlify($contact['thumb']),
'$item_id' => xmlify("urn:X-dfrn:{$item['hash']}"),
'$title' => xmlify($item['title']),
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z')),
'$content' =>xmlify($item['body'])
));
}
else {
$atom .= replace_macros($cmnt_template, array(
'$name' => xmlify($contact['name']),
'$profile_page' => xmlify($contact['url']),
'$thumb' => xmlify($contact['thumb']),
'$item_id' => xmlify("urn:X-dfrn:{$item['hash']}"),
'$title' => xmlify($item['title']),
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z')),
'$content' =>xmlify($item['body']),
'$parent_id' => xmlify("urn:X-dfrn:{$items[0]['hash']}")
));
}
}
}
}
}
}
$atom .= "</feed>";
print_r($atom);
// expand list of recipients
dbg(3); dbg(3);
$recipients = array_unique($recipients);
print_r($recipients); print_r($recipients);
if($followup)
$recip_str = $parent['contact-id'];
else
$recip_str = implode(', ', $recipients); $recip_str = implode(', ', $recipients);
$r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ", $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
@ -149,9 +231,9 @@ echo "pubkey:" . $rr['pubkey'] . "\r\n";
$postvars['data'] = $atom; $postvars['data'] = $atom;
print_r($postvars); print_r($postvars);
$xml = fetch_url($url,$postvars); $xml = post_url($url,$postvars);
print_r($xml);
} }
killme(); killme();

View file

@ -1,6 +1,6 @@
<?php <?php
require_once('simplepie/simplepie.inc');
@ -22,11 +22,21 @@ function dfrn_notify_post(&$a) {
dbesc($challenge) dbesc($challenge)
); );
$feed = new SimplePie();
$feed->set_raw_data($data);
$feed->init();
echo "Feed title:" . $feed->get_title();
foreach ($feed->get_items() as $item) {
echo $item->get_permalink();
echo $item->get_content();
}
killme();
} }

View file

@ -5,7 +5,7 @@ function sanitise_acl(&$item) {
} }
function item_post(&$a) { function item_post(&$a) {
dbg(2);
if((! local_user()) && (! remote_user())) if((! local_user()) && (! remote_user()))
return; return;
@ -149,7 +149,7 @@ dbg(2);
array(),$foo)); array(),$foo));
} }
// goaway($a->get_baseurl() . "/profile/$profile_uid"); goaway($a->get_baseurl() . "/profile/$profile_uid");

View file

@ -2431,6 +2431,7 @@ class SimplePie
$name = null; $name = null;
$uri = null; $uri = null;
$email = null; $email = null;
$avatar = null;
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
{ {
$name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
@ -2443,9 +2444,13 @@ class SimplePie
{ {
$email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
} }
if ($name !== null || $email !== null || $uri !== null) if (isset($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']))
{ {
$authors[] =& new $this->author_class($name, $uri, $email); $avatar = $this->sanitize($$author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]));
}
if ($name !== null || $email !== null || $uri !== null || $avatar !== null)
{
$authors[] =& new $this->author_class($name, $uri, $email, $avatar);
} }
} }
if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
@ -3475,6 +3480,7 @@ class SimplePie_Item
$name = null; $name = null;
$uri = null; $uri = null;
$email = null; $email = null;
$avatar = null;
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
{ {
$name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
@ -3487,9 +3493,14 @@ class SimplePie_Item
{ {
$email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
} }
if ($name !== null || $email !== null || $uri !== null) if (isset($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']))
{ {
$authors[] =& new $this->feed->author_class($name, $uri, $email); $avatar = $this->sanitize($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]));
}
if ($name !== null || $email !== null || $uri !== null || $avatar !== null)
{
$authors[] =& new $this->feed->author_class($name, $uri, $email, $avatar);
} }
} }
if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
@ -5897,6 +5908,7 @@ class SimplePie_Source
$name = null; $name = null;
$uri = null; $uri = null;
$email = null; $email = null;
$avatar = null;
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
{ {
$name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
@ -5909,9 +5921,13 @@ class SimplePie_Source
{ {
$email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
} }
if ($name !== null || $email !== null || $uri !== null)
{ {
$authors[] =& new $this->item->feed->author_class($name, $uri, $email); $avatar = $this->sanitize($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]));
}
if ($name !== null || $email !== null || $uri !== null || $avatar !== null)
{
$authors[] =& new $this->item->feed->author_class($name, $uri, $email, $avatar);
} }
} }
if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
@ -6283,13 +6299,15 @@ class SimplePie_Author
var $name; var $name;
var $link; var $link;
var $email; var $email;
var $avatar;
// Constructor, used to input the data // Constructor, used to input the data
function SimplePie_Author($name = null, $link = null, $email = null) function SimplePie_Author($name = null, $link = null, $email = null, $avatar = null)
{ {
$this->name = $name; $this->name = $name;
$this->link = $link; $this->link = $link;
$this->email = $email; $this->email = $email;
$this->avatar = $avatar;
} }
function __toString() function __toString()
@ -6333,6 +6351,20 @@ class SimplePie_Author
return null; return null;
} }
} }
function get_avatar()
{
if ($this->avatar !== null)
{
return $this->avatar;
}
else
{
return null;
}
}
} }
class SimplePie_Category class SimplePie_Category

View file

@ -2,3 +2,6 @@
CHANGE `deny_uid` `deny_cid` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ; CHANGE `deny_uid` `deny_cid` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ;
ALTER TABLE `item` CHANGE `last-child` `last-child` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1'; ALTER TABLE `item` CHANGE `last-child` `last-child` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';
alter table `item` insert `remote-id` char( 255 ) character set utf-8 collate utf8_general_ci NOT NULL;