From d20e1a6f938d088708166e039ae0088a8ddf11e4 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Wed, 14 Jul 2010 23:04:10 -0700 Subject: [PATCH] feed related --- boot.php | 14 +++- include/group.php | 15 +++- include/notifier.php | 178 +++++++++++++++++++++++++++++----------- mod/dfrn_notify.php | 18 +++- mod/item.php | 4 +- simplepie/simplepie.inc | 46 +++++++++-- update.sql | 3 + 7 files changed, 215 insertions(+), 63 deletions(-) diff --git a/boot.php b/boot.php index 0633a828f6..c94548c3f3 100644 --- a/boot.php +++ b/boot.php @@ -424,4 +424,16 @@ function paginate(&$a) { $o .= ''."\r\n"; } return $o; -} \ No newline at end of file +} + +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(); +} diff --git a/include/group.php b/include/group.php index 1f48cdd56b..f2e3d18203 100644 --- a/include/group.php +++ b/include/group.php @@ -150,4 +150,17 @@ EOT; $o .= " \r\n \r\n"; return $o; -} \ No newline at end of file +} + +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; +} diff --git a/include/notifier.php b/include/notifier.php index f1231839b8..a28f6364bd 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -32,79 +32,161 @@ if($argc < 3) } - $is_parent = false; - $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` - WHERE `item`.`id` = %d LIMIT 1", + $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1", intval($item_id) ); if(! count($r)) 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']) { - $is_parent = true; + if(! count($items)) + 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 { - $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", - intval($item['parent']) - ); - if(count($r)) - $parent = $r[0]; - } + $followup = false; - if(is_array($parent)) - $recipients[] = $parent['contact-id']; + $allow_people = expand_acl($parent['allow_cid']); + $allow_groups = expand_groups(expand_acl($parent['allow_gid'])); + $deny_people = expand_acl($parent['deny_cid']); + $deny_groups = expand_groups(expand_acl($parent['deny_gid'])); - $r = q("SELECT `contact-id` FROM `item` WHERE `hash` = '%s' AND `id` != %d AND `id` != %d", - dbesc($item['hash']), - intval($item['id']), - intval($item['parent']) - ); - if(count($r)) { - foreach($r as $rr) { - if($rr['contact-id'] != $item['contact-id']) - $recipients[] = $rr['contact-id']; + $conversants = array(); + + foreach($items as $item) { + $recipients[] = $item['contact-id']; + $conversants[] = $item['contact-id']; } + + $conversants = array_unique($conversants,SORT_NUMERIC); + + + $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC); + $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC); + $recipients = array_diff($recipients,$deny); + + $conversant_str = dbesc(implode(', ',$conversants)); } - $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( - '$feed_id' => xmlify($baseurl), - '$feed_title' => xmlify('Wall Item'), - '$feed_updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')) , - '$name' => xmlify($item['name']), - '$profile_page' => xmlify($item['url']), - '$thumb' => xmlify($item['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']) + $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_title' => xmlify($owner['name']), + '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\Th:i:s\Z')) , + '$name' => xmlify($owner['name']), + '$profile_page' => xmlify($owner['url']), + '$thumb' => xmlify($owner['thumb']) )); -print_r($atom); - // atomify + if($followup) { + $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 .= ""; + +print_r($atom); - // expand list of recipients dbg(3); - $recipients = array_unique($recipients); + print_r($recipients); - $recip_str = implode(', ', $recipients); + + if($followup) + $recip_str = $parent['contact-id']; + else + $recip_str = implode(', ', $recipients); $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ", dbesc($recip_str) @@ -149,9 +231,9 @@ echo "pubkey:" . $rr['pubkey'] . "\r\n"; $postvars['data'] = $atom; print_r($postvars); - $xml = fetch_url($url,$postvars); + $xml = post_url($url,$postvars); - +print_r($xml); } killme(); diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 2d9d06fd1c..301beaf2f9 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -1,6 +1,6 @@ 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(); } diff --git a/mod/item.php b/mod/item.php index 83854ed159..c7b5b48858 100644 --- a/mod/item.php +++ b/mod/item.php @@ -5,7 +5,7 @@ function sanitise_acl(&$item) { } function item_post(&$a) { -dbg(2); + if((! local_user()) && (! remote_user())) return; @@ -149,7 +149,7 @@ dbg(2); array(),$foo)); } -// goaway($a->get_baseurl() . "/profile/$profile_uid"); + goaway($a->get_baseurl() . "/profile/$profile_uid"); diff --git a/simplepie/simplepie.inc b/simplepie/simplepie.inc index 9e4fa301bb..1f40ac5934 100644 --- a/simplepie/simplepie.inc +++ b/simplepie/simplepie.inc @@ -2431,6 +2431,7 @@ class SimplePie $name = null; $uri = null; $email = null; + $avatar = null; 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); @@ -2443,9 +2444,13 @@ class SimplePie { $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')) @@ -3475,6 +3480,7 @@ class SimplePie_Item $name = null; $uri = null; $email = null; + $avatar = null; 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); @@ -3487,9 +3493,14 @@ class SimplePie_Item { $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')) @@ -5897,6 +5908,7 @@ class SimplePie_Source $name = null; $uri = null; $email = null; + $avatar = null; 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); @@ -5909,9 +5921,13 @@ class SimplePie_Source { $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')) @@ -6283,13 +6299,15 @@ class SimplePie_Author var $name; var $link; var $email; + var $avatar; // 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->link = $link; $this->email = $email; + $this->avatar = $avatar; } function __toString() @@ -6333,6 +6351,20 @@ class SimplePie_Author return null; } } + + function get_avatar() + { + if ($this->avatar !== null) + { + return $this->avatar; + } + else + { + return null; + } + } + + } class SimplePie_Category diff --git a/update.sql b/update.sql index 63a46bce6e..65fc69f789 100644 --- a/update.sql +++ b/update.sql @@ -2,3 +2,6 @@ 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` insert `remote-id` char( 255 ) character set utf-8 collate utf8_general_ci NOT NULL; + \ No newline at end of file