aboutsummaryrefslogtreecommitdiffstats
path: root/include/notifier.php
diff options
context:
space:
mode:
authorMike Macgirvin <mike@macgirvin.com>2010-07-14 23:04:10 -0700
committerMike Macgirvin <mike@macgirvin.com>2010-07-14 23:04:10 -0700
commitd20e1a6f938d088708166e039ae0088a8ddf11e4 (patch)
tree7fa25d32ca357cd04debe066956f9a44f56e5206 /include/notifier.php
parent43f8dd680234239f2cf6e0d62a12aa32aacf5b16 (diff)
downloadvolse-hubzilla-d20e1a6f938d088708166e039ae0088a8ddf11e4.tar.gz
volse-hubzilla-d20e1a6f938d088708166e039ae0088a8ddf11e4.tar.bz2
volse-hubzilla-d20e1a6f938d088708166e039ae0088a8ddf11e4.zip
feed related
Diffstat (limited to 'include/notifier.php')
-rw-r--r--include/notifier.php180
1 files changed, 131 insertions, 49 deletions
diff --git a/include/notifier.php b/include/notifier.php
index f1231839b..a28f6364b 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'];
+
+ $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
+ intval($parent)
+ );
+
+ 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();
+
- $recipients[] = $item['contact-id'];
+ require_once('include/group.php');
- if($item['parent'] == $item['id']) {
- $is_parent = true;
+ $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');
-
- // FIXME should dump the entire conversation
-
- $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'])
+ $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) ");
+
+ if( ! count($r))
+ killme();
+
+ $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'])
));
+ 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 .= "</feed>";
+
print_r($atom);
- // atomify
- // 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();