aboutsummaryrefslogtreecommitdiffstats
path: root/include/notifier.php
diff options
context:
space:
mode:
authorMike Macgirvin <mike@macgirvin.com>2010-07-08 07:03:25 -0700
committerMike Macgirvin <mike@macgirvin.com>2010-07-08 07:03:25 -0700
commit9a6a60a9c1c7f781790849173e309ac0664d7b35 (patch)
treeb0597e8aeaa20d6ded493b2c053e3e976a53115a /include/notifier.php
parente98aaa3cbd2c14ab2f1b8534c8c63708086fe0f1 (diff)
downloadvolse-hubzilla-9a6a60a9c1c7f781790849173e309ac0664d7b35.tar.gz
volse-hubzilla-9a6a60a9c1c7f781790849173e309ac0664d7b35.tar.bz2
volse-hubzilla-9a6a60a9c1c7f781790849173e309ac0664d7b35.zip
mucho progress on notifier, email style dfrn url's
Diffstat (limited to 'include/notifier.php')
-rw-r--r--include/notifier.php105
1 files changed, 79 insertions, 26 deletions
diff --git a/include/notifier.php b/include/notifier.php
index d1f26cdc2..e67ef06e3 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -1,6 +1,5 @@
<?php
-echo getcwd();
require_once("boot.php");
$a = new App;
@@ -13,11 +12,19 @@ $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
require_once("session.php");
require_once("datetime.php");
-if(($argc != 2) || (! intval($argv[1])))
+// FIXME - generalise for other content, probably create a notify queue in
+// the db with type and recipient list
+
+if(($argc != 3) || (! intval($argv[2])))
exit;
+ $baseurl = trim(pack("H*" , $argv[1]));
+
+ $item_id = $argv[2];
+
$is_parent = false;
- $item_id = $argv[1];
+
+ $recipients = array();
$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",
@@ -28,6 +35,8 @@ if(($argc != 2) || (! intval($argv[1])))
$item = $r[0];
+ $recipients[] = $item['contact-id'];
+
if($item['parent'] == $item['id']) {
$is_parent = true;
}
@@ -39,7 +48,8 @@ if(($argc != 2) || (! intval($argv[1])))
$parent = $r[0];
}
- $commenters = array();
+ if(is_array($parent))
+ $recipients[] = $parent['contact-id'];
$r = q("SELECT `contact-id` FROM `item` WHERE `hash` = '%s' AND `id` != %d AND `id` != %d",
dbesc($item['hash']),
@@ -49,25 +59,27 @@ if(($argc != 2) || (! intval($argv[1])))
if(count($r)) {
foreach($r as $rr) {
if($rr['contact-id'] != $item['contact-id'])
- $commenters[] = $rr['contact-id'];
+ $recipients[] = $rr['contact-id'];
}
}
$tpl = file_get_contents('view/atomic.tpl');
-
+
+ // FIXME should dump the entire conversation
+
$atom = replace_macros($tpl, array(
- '$feed_id' => $a->get_baseurl(),
- '$feed_title' => 'Wall Item',
- '$feed_updated' => datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z') ,
- '$name' => $item['name'],
- '$profile_page' => $item['url'],
- '$thumb' => $item['thumb'],
- '$item_id' => $item['hash'] . '-' . $item['id'],
- '$title' => '',
- '$link' => $a->get_baseurl() . '/item/' . $item['id'],
- '$updated' => datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z'),
- '$summary' => '',
- '$content' => $item['body']
+ '$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'])
));
print_r($atom);
@@ -75,19 +87,60 @@ print_r($atom);
// expand list of recipients
- // grab the contact records
+dbg(3);
- // foreach recipient
- // if no dfrn-id continue
+ $recipients = array_unique($recipients);
+print_r($recipients);
+ $recip_str = implode(', ', $recipients);
- // fetch_url dfrn-notify
+ $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
+ dbesc($recip_str)
+ );
+ if(! count($r))
+ killme();
- // decrypt challenge
+ // delivery loop
- // post result
+ foreach($r as $rr) {
+ if($rr['self'])
+ continue;
- // continue
+ if(! strlen($rr['dfrn-id']))
+ continue;
+ $url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id'];
+print_r($url);
+ $xml = fetch_url($url);
+echo $xml;
- killme();
+print_r($xml);
+ if(! $xml)
+ continue;
+
+ $res = simplexml_load_string($xml);
+print_r($res);
+var_dump($res);
+
+ if((intval($res->status) != 0) || (! strlen($res->challenge)) || ($res->dfrn_id != $rr['dfrn-id']))
+ continue;
+
+ $postvars = array();
+
+ $postvars['dfrn_id'] = $rr['dfrn-id'];
+ $challenge = hex2bin($res->challenge);
+echo "dfrn-id:" . $res->dfrn_id . "\r\n";
+echo "challenge:" . $res->challenge . "\r\n";
+echo "pubkey:" . $rr['pubkey'] . "\r\n";
+
+ openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
+
+ $postvars['data'] = $atom;
+
+print_r($postvars);
+ $xml = fetch_url($url,$postvars);
+
+
+ }
+
+ killme();