1
0
Fork 0

remote comments working now

This commit is contained in:
Mike Macgirvin 2010-07-17 19:26:00 -07:00
parent 2a17c20fb8
commit aff4f63ff8
8 changed files with 86 additions and 45 deletions

View file

@ -370,6 +370,11 @@ function xmlify($str) {
return($buffer); return($buffer);
}} }}
function unxmlify($s) {
$ret = str_replace('&','&', $s);
$ret = str_replace(array('&lt;','&gt;','&quot;','&apos;'),array('<','>','"',"'"),$ret);
return $ret;
}
function hex2bin($s) { function hex2bin($s) {
return(pack("H*",$s)); return(pack("H*",$s));

View file

@ -1,5 +1,6 @@
<?php <?php
print_r($argv);
require_once("boot.php"); require_once("boot.php");
$a = new App; $a = new App;
@ -11,10 +12,7 @@ $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
require_once("session.php"); require_once("session.php");
require_once("datetime.php"); require_once("datetime.php");
dbg(3);
// FIXME - generalise for other content, probably create a notify queue in
// the db with type and recipient list
if($argc < 3) if($argc < 3)
exit; exit;
@ -122,10 +120,12 @@ if($argc < 3)
)); ));
if($followup) { if($followup) {
foreach($items as $item) {
if($item['id'] == $item_id) {
$atom .= replace_macros($cmnt_template, array( $atom .= replace_macros($cmnt_template, array(
'$name' => xmlify($contact['name']), '$name' => xmlify($owner['name']),
'$profile_page' => xmlify($contact['url']), '$profile_page' => xmlify($owner['url']),
'$thumb' => xmlify($contact['thumb']), '$thumb' => xmlify($owner['thumb']),
'$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"), '$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
'$title' => xmlify($item['title']), '$title' => xmlify($item['title']),
'$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')), '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
@ -135,6 +135,8 @@ if($argc < 3)
'$comment_allow' => 0 '$comment_allow' => 0
)); ));
} }
}
}
else { else {
foreach($items as $item) { foreach($items as $item) {
if($item['deleted']) { if($item['deleted']) {
@ -154,7 +156,7 @@ if($argc < 3)
'$owner_name' => xmlify($item['owner-name']), '$owner_name' => xmlify($item['owner-name']),
'$owner_profile_page' => xmlify($item['owner-link']), '$owner_profile_page' => xmlify($item['owner-link']),
'$owner_thumb' => xmlify($item['owner-avatar']), '$owner_thumb' => xmlify($item['owner-avatar']),
'$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"), '$item_id' => xmlify(((strlen($item['remote-id'])) ? $item['remote-id'] : "urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}")),
'$title' => xmlify($contact['name']), '$title' => xmlify($contact['name']),
'$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')), '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')), '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
@ -167,7 +169,7 @@ if($argc < 3)
'$name' => xmlify($contact['name']), '$name' => xmlify($contact['name']),
'$profile_page' => xmlify($contact['url']), '$profile_page' => xmlify($contact['url']),
'$thumb' => xmlify($contact['thumb']), '$thumb' => xmlify($contact['thumb']),
'$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"), '$item_id' => xmlify(((strlen($item['remote-id'])) ? $item['remote-id'] : "urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}")),
'$title' => xmlify($item['title']), '$title' => xmlify($item['title']),
'$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')), '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')), '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
@ -193,6 +195,7 @@ if($argc < 3)
else 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 ) ",
dbesc($recip_str) dbesc($recip_str)
); );
@ -202,6 +205,8 @@ if($argc < 3)
// delivery loop // delivery loop
foreach($r as $rr) { foreach($r as $rr) {
echo "In delivery loop:";
if($rr['self']) if($rr['self'])
continue; continue;
@ -230,9 +235,11 @@ if($argc < 3)
$postvars['data'] = $atom; $postvars['data'] = $atom;
else else
$postvars['data'] = $atom_nowrite; $postvars['data'] = $atom_nowrite;
echo "URL:" . $url;
echo "POSTVARS:" . print_r($postvars);
$xml = post_url($url,$postvars); $xml = post_url($url,$postvars);
echo "XML response:" . $xml;
} }

View file

@ -8,12 +8,12 @@ function get_atom_elements($item) {
$res = array(); $res = array();
$author = $item->get_author(); $author = $item->get_author();
$res['remote-name'] = $author->get_name(); $res['remote-name'] = unxmlify($author->get_name());
$res['remote-link'] = $author->get_link(); $res['remote-link'] = unxmlify($author->get_link());
$res['remote-avatar'] = $author->get_avatar(); $res['remote-avatar'] = unxmlify($author->get_avatar());
$res['remote-id'] = $item->get_id(); $res['remote-id'] = unxmlify($item->get_id());
$res['title'] = $item->get_title(); $res['title'] = unxmlify($item->get_title());
$res['body'] = $item->get_content(); $res['body'] = unxmlify($item->get_content());
if(strlen($res['body']) > 100000) if(strlen($res['body']) > 100000)
$res['body'] = substr($res['body'],0,10000) . "\r\n[Extremely large post truncated.]\r\n" ; $res['body'] = substr($res['body'],0,10000) . "\r\n[Extremely large post truncated.]\r\n" ;
@ -26,19 +26,19 @@ function get_atom_elements($item) {
$rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published'); $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
if($rawcreated) if($rawcreated)
$res['created'] = $rawcreated[0]['data']; $res['created'] = unxmlify($rawcreated[0]['data']);
$rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated'); $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
if($rawedited) if($rawedited)
$res['edited'] = $rawcreated[0]['data']; $res['edited'] = unxmlify($rawcreated[0]['data']);
$rawowner = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0', 'owner'); $rawowner = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0', 'owner');
if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['name'][0]['data']) if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['name'][0]['data'])
$res['owner-name'] = $rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['name'][0]['data']; $res['owner-name'] = unxmlify($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['name'][0]['data']);
if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['uri'][0]['data']) if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['uri'][0]['data'])
$res['owner-link'] = $rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['uri'][0]['data']; $res['owner-link'] = unxmlify($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['uri'][0]['data']);
if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']) if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'])
$res['owner-avatar'] = $rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']; $res['owner-avatar'] = unxmlify($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']);
return $res; return $res;
@ -48,6 +48,7 @@ function get_atom_elements($item) {
function post_remote($a,$arr) { function post_remote($a,$arr) {
$arr['hash'] = random_string(); $arr['hash'] = random_string();
if(! x($arr,'type'))
$arr['type'] = 'remote'; $arr['type'] = 'remote';
$arr['remote-name'] = notags(trim($arr['remote-name'])); $arr['remote-name'] = notags(trim($arr['remote-name']));
$arr['remote-link'] = notags(trim($arr['remote-link'])); $arr['remote-link'] = notags(trim($arr['remote-link']));
@ -82,7 +83,7 @@ function post_remote($a,$arr) {
$parent_id = 0; $parent_id = 0;
dbesc_array($arr); dbesc_array($arr);
dbg(3);
$r = q("INSERT INTO `item` (`" $r = q("INSERT INTO `item` (`"
. implode("`, `", array_keys($arr)) . implode("`, `", array_keys($arr))
. "`) VALUES ('" . "`) VALUES ('"
@ -121,7 +122,7 @@ function post_remote($a,$arr) {
} }
function dfrn_notify_post(&$a) { function dfrn_notify_post(&$a) {
dbg(3);
$dfrn_id = notags(trim($_POST['dfrn_id'])); $dfrn_id = notags(trim($_POST['dfrn_id']));
$challenge = notags(trim($_POST['challenge'])); $challenge = notags(trim($_POST['challenge']));
$data = $_POST['data']; $data = $_POST['data'];
@ -179,15 +180,32 @@ function dfrn_notify_post(&$a) {
// remote reply to our post. Import and then notify everybody else. // remote reply to our post. Import and then notify everybody else.
$datarray = get_atom_elements($item); $datarray = get_atom_elements($item);
$urn = explode(':',$parent_urn); $urn = explode(':',$parent_urn);
$datarray['parent_hash'] = $urn[4]; $datarray['type'] = 'remote-comment';
$datarray['parent_hash'] = $urn[5];
$datarray['uid'] = $importer['uid']; $datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $importer['id']; $datarray['contact-id'] = $importer['id'];
$r = post_remote($a,$datarray); $posted_id = post_remote($a,$datarray);
$r = q("SELECT `parent` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($posted_id),
intval($importer['uid'])
);
if(count($r)) {
$r1 = q("UPDATE `item` SET `last-child` = 0 WHERE `uid` = %d AND `parent` = %d",
intval($importer['uid']),
intval($r[0]['parent'])
);
}
$r2 = q("UPDATE `item` SET `last-child` = 1 WHERE `uid` = %d AND `id` = %d LIMIT 1",
intval($importer['uid']),
intval($posted_id)
);
$url = bin2hex($a->get_baseurl()); $url = bin2hex($a->get_baseurl());
proc_close(proc_open("php include/notifier.php $url $notify_type $r > notify.log &", array(),$foo)); proc_close(proc_open("php include/notifier.php $url comment-import $posted_id > remote-notify.log &", array(),$foo));
xml_status(0);
return; return;
} }
@ -196,16 +214,18 @@ function dfrn_notify_post(&$a) {
$item_id = $item->get_id(); $item_id = $item->get_id();
$r = q("SELECT `uid`, `last-child` FROM `item` WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id), dbesc($item_id),
intval($importer['uid']) intval($importer['uid'])
); );
// FIXME update content if 'updated' changes
if(count($r)) { if(count($r)) {
$allow = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0','comment-allow'); $allow = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0','comment-allow');
if($allow && $allow[0]['data'] != $r[0]['last-child']) { if($allow && $allow[0]['data'] != $r[0]['last-child']) {
$r = q("UPDATE `item` SET `last-child` = %d WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1", $r = q("UPDATE `item` SET `last-child` = %d WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1",
intval($allow[0]['data']), intval($allow[0]['data']),
dbesc($item_id) dbesc($item_id),
intval($importer['uid'])
); );
} }
continue; continue;
@ -222,7 +242,7 @@ function dfrn_notify_post(&$a) {
// Head post of a conversation. Have we seen it? If not, import it. // Head post of a conversation. Have we seen it? If not, import it.
$item_id = $item->get_id(); $item_id = $item->get_id();
$r = q("SELECT `uid` FROM `item` WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id), dbesc($item_id),
intval($importer['uid']) intval($importer['uid'])
); );
@ -231,7 +251,8 @@ function dfrn_notify_post(&$a) {
if($allow && $allow[0]['data'] != $r[0]['last-child']) { if($allow && $allow[0]['data'] != $r[0]['last-child']) {
$r = q("UPDATE `item` SET `last-child` = %d WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1", $r = q("UPDATE `item` SET `last-child` = %d WHERE `remote-id` = '%s' AND `uid` = %d LIMIT 1",
intval($allow[0]['data']), intval($allow[0]['data']),
dbesc($item_id) dbesc($item_id),
intval($importer['uid'])
); );
} }
continue; continue;
@ -249,7 +270,7 @@ function dfrn_notify_post(&$a) {
} }
xml_status(0);
killme(); killme();
} }

View file

@ -72,8 +72,10 @@ function item_post(&$a) {
} }
// get contact info for poster // get contact info for poster
if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id'])))
if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
$contact_id = $_SESSION['visitor_id']; $contact_id = $_SESSION['visitor_id'];
}
else { else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
intval($_SESSION['uid'])); intval($_SESSION['uid']));
@ -104,15 +106,16 @@ function item_post(&$a) {
} while($dups == true); } while($dups == true);
$r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,`edited`,`hash`,`body`, $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `remote-id`, `created`,`edited`,`hash`,`body`,
`allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`) `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
intval($profile_uid), intval($profile_uid),
dbesc($_POST['type']), dbesc($_POST['type']),
intval($contact_id), intval($contact_id),
dbesc($contact_record['name']), dbesc($contact_record['name']),
dbesc($contact_record['url']), dbesc($contact_record['url']),
dbesc($contact_record['thumb']), dbesc($contact_record['thumb']),
dbesc("urn:X-dfrn:" . $a->get_baseurl() . ':' . intval($profile_uid) . ':' . $hash),
datetime_convert(), datetime_convert(),
datetime_convert(), datetime_convert(),
dbesc($hash), dbesc($hash),
@ -159,7 +162,7 @@ function item_post(&$a) {
$url = bin2hex($a->get_baseurl()); $url = bin2hex($a->get_baseurl());
proc_close(proc_open("php include/notifier.php $url $notify_type $post_id > notify.log &", proc_close(proc_open("php include/notifier.php \"$url\" \"$notify_type\" \"$post_id\" > notify.log &",
array(),$foo)); array(),$foo));
} }

View file

@ -108,6 +108,7 @@ function network_content(&$a) {
if($item['last-child']) { if($item['last-child']) {
$comment = replace_macros($cmnt_tpl,array( $comment = replace_macros($cmnt_tpl,array(
'$return_path' => $a->cmd,
'$id' => $item['item_id'], '$id' => $item['item_id'],
'$parent' => $item['parent'], '$parent' => $item['parent'],
'$profile_uid' => $_SESSION['uid'], '$profile_uid' => $_SESSION['uid'],

View file

@ -196,6 +196,7 @@ function profile_content(&$a) {
if(can_write_wall($a,$a->profile['profile_uid'])) { if(can_write_wall($a,$a->profile['profile_uid'])) {
if($item['last-child']) { if($item['last-child']) {
$comment = replace_macros($cmnt_tpl,array( $comment = replace_macros($cmnt_tpl,array(
'$return_path' => $a->cmd,
'$id' => $item['item_id'], '$id' => $item['item_id'],
'$parent' => $item['parent'], '$parent' => $item['parent'],
'$profile_uid' => $a->profile['profile_uid'], '$profile_uid' => $a->profile['profile_uid'],

View file

@ -12,3 +12,5 @@ ADD `remote-avatar` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT N
ALTER TABLE `item` ADD `owner-name` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `contact-id` , ALTER TABLE `item` ADD `owner-name` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `contact-id` ,
ADD `owner-link` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `owner-name` , ADD `owner-link` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `owner-name` ,
ADD `owner-avatar` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `owner-link` ; ADD `owner-avatar` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `owner-link` ;
ALTER TABLE `item` ADD `remote-parent` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `parent` ;

View file

@ -5,6 +5,7 @@
<input type="hidden" name="type" value="wall-comment" /> <input type="hidden" name="type" value="wall-comment" />
<input type="hidden" name="profile_uid" value="$profile_uid" /> <input type="hidden" name="profile_uid" value="$profile_uid" />
<input type="hidden" name="parent" value="$parent" /> <input type="hidden" name="parent" value="$parent" />
<input type="hidden" name="return" value="$return_path" />
<textarea id="comment-edit-text-$id" class="comment-edit-text-empty" name="body" onFocus="commentOpen(this,$id);" onBlur="commentClose(this,$id);" >Comment</textarea> <textarea id="comment-edit-text-$id" class="comment-edit-text-empty" name="body" onFocus="commentOpen(this,$id);" onBlur="commentClose(this,$id);" >Comment</textarea>