]> git.mxchange.org Git - friendica.git/commitdiff
mucho progress on notifier, email style dfrn url's
authorMike Macgirvin <mike@macgirvin.com>
Thu, 8 Jul 2010 14:03:25 +0000 (07:03 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Thu, 8 Jul 2010 14:03:25 +0000 (07:03 -0700)
boot.php
include/Scrape.php
include/main.js [new file with mode: 0644]
include/notifier.php
mod/dfrn_notify.php
mod/dfrn_request.php
mod/home.php
mod/item.php
mod/profile.php

index 9f825ddfdf04a3be5dfac91bc7e853dc33fcf831..fab44a7a459dac8a11703ee22e15a8bab3fb0f54 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -311,4 +311,49 @@ function notice($s) {
 
        $_SESSION['sysmsg'] .= $s;
 
-}}
\ No newline at end of file
+}}
+
+
+if(! function_exists('xmlify')) {
+function xmlify($str) {
+       $buffer = '';
+       
+       for($x = 0; $x < strlen($str); $x ++) {
+               $char = $str[$x];
+        
+               switch( $char ) {
+
+                       case "\r" :
+                               break;
+                       case "&" :
+                               $buffer .= '&amp;';
+                               break;
+                       case "'" :
+                               $buffer .= '&apos;';
+                               break;
+
+                       case "\"" :
+                               $buffer .= '&quot;';
+                               break;
+                       case '<' :
+                               $buffer .= '&lt;';
+                               break;
+                       case '>' :
+                               $buffer .= '&gt;';
+                               break;
+                       case "\n" :
+                               $buffer .= ' ';
+                               break;
+                       default :
+                               $buffer .= $char;
+                               break;
+               }       
+       }
+       $buffer = trim($buffer);
+       return($buffer);
+}}
+
+
+function hex2bin($s) {
+       return(pack("H*",$s));
+}
\ No newline at end of file
index cc50151657b763e505a03acb5b240bad45f77830..b4a5dd8496b9f2962ed68283b10c9b3ec5a9363f 100644 (file)
@@ -76,5 +76,29 @@ function validate_dfrn($a) {
        return $errors;
 }}
 
+if(! function_exists('scrape_meta')) {
+function scrape_meta($url) {
 
+       $ret = array();
+       $s = fetch_url($url);
+
+       if(! $s) 
+               return $ret;
+
+       $dom = HTML5_Parser::parse($s);
+
+       if(! $dom)
+               return $ret;
 
+       $items = $dom->getElementsByTagName('meta');
+
+       // get DFRN link elements
+
+       foreach($items as $item) {
+               $x = $item->getAttribute('name');
+               if(substr($x,0,5) == "dfrn-")
+                       $ret[$x] = $item->getAttribute('content');
+       }
+
+       return $ret;
+}}
diff --git a/include/main.js b/include/main.js
new file mode 100644 (file)
index 0000000..4fb92c7
--- /dev/null
@@ -0,0 +1,12 @@
+
+  function openClose(theID) {
+    if(document.getElementById(theID).style.display == "block") { 
+      document.getElementById(theID).style.display = "none" 
+    }
+    else { 
+      document.getElementById(theID).style.display = "block" 
+    } 
+  }
+  function openMenu(theID) {
+      document.getElementById(theID).style.display = "block" 
+  }
index d1f26cdc2c1df17411d8a678263adcdd3baaccd4..e67ef06e3185be46e494ee4a553382a38faa8ad9 100644 (file)
@@ -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();
 
index c078afe38b9c58715afed854fcc457bb30ec6b9f..2d9d06fd1c4c99b400bde409d8c0cf0fdff63a4d 100644 (file)
@@ -66,8 +66,8 @@ function dfrn_notify_content(&$a) {
                $challenge = '';
 
                openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']);
-
-               echo '<?xml version=1.0" encoding="UTF-8"?><dfrn_notify><status>' .$status . '</status><dfrn_id>' . $_GET['dfrn_id'] . '</dfrn_id>'
+               $challenge = bin2hex($challenge);
+               echo '<?xml version="1.0" encoding="UTF-8"?><dfrn_notify><status>' .$status . '</status><dfrn_id>' . $_GET['dfrn_id'] . '</dfrn_id>'
                        . '<challenge>' . $challenge . '</challenge></dfrn_notify>' . "\r\n" ;
                session_write_close();
                exit;
index b6ae4346d2447499e0840257906178c65f058890..7fb55c4bfe13d164a6b1520f9be3c91b67c5e6c7 100644 (file)
@@ -166,6 +166,15 @@ function dfrn_request_post(&$a) {
                        return;
                }
 
+               if(strstr($url,'@')) {
+                       $username = substr($url,0,strpos($url,'@'));
+                       $hostname = substr($url,strpos($url,'@') + 1);
+                       require_once('Scrape.php');
+
+                       $parms = scrape_meta('http://' . $url);
+                       if((x($parms,'dfrn-template')) && strstr($parms['dfrn-template'],'%s'))
+                               $url = sprintf($parms['dfrn-template'],$username);
+               }
 
                $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", 
                        intval($uid),
index 44f2a9888b18492ad11a4610cf724c38f7588ace..a60e96ccbcb3a1f03c3f395081be368540dabda8 100644 (file)
@@ -9,6 +9,8 @@ function home_init(&$a) {
                else
                        goaway( $a->get_baseurl() . "/profile/" . $_SESSION['uid'] );
        }
+       $a->page['htmlhead'] .= "<meta name=\"dfrn-template\" content=\"" . $a->get_baseurl() . "/profile/%s" . "\" />\r\n";
 }}
 
 
index 23917161b425daef3a06e3f757d07bad02926bcb..4314719fb510ab05728074c25b7ada5a88a39017 100644 (file)
@@ -58,8 +58,8 @@ function item_post(&$a) {
                                intval($post_id));
                }
 
-
-               proc_close(proc_open("php include/notifier.php $post_id > notify.log &",
+               $url = bin2hex($a->get_baseurl());
+               proc_close(proc_open("php include/notifier.php $url $post_id > notify.log &",
                        array(),$foo));
 
 //             notifier($a,$post_id,$parent);
index 1caa3478f9a5355c0331dcd7a3af3126bd33d9a1..e5bc92f5b2e548922e2c1f919bad3cc74ec02b1c 100644 (file)
@@ -58,10 +58,12 @@ function profile_init(&$a) {
        }
 
        profile_load($a,$which);
+       $a->page['htmlhead'] .= "<meta name=\"dfrn-template\" content=\"" . $a->get_baseurl() . "/profile/%s" . "\" />\r\n";
        
        $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
        foreach($dfrn_pages as $dfrn)
                $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
+
 }
 
 function item_display(&$a, $item,$template,$comment) {