return($buffer);
}}
+function unxmlify($s) {
+ $ret = str_replace('&','&', $s);
+ $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
+ return $ret;
+}
function hex2bin($s) {
return(pack("H*",$s));
<?php
+print_r($argv);
require_once("boot.php");
$a = new App;
require_once("session.php");
require_once("datetime.php");
-
-// FIXME - generalise for other content, probably create a notify queue in
-// the db with type and recipient list
-
+dbg(3);
if($argc < 3)
exit;
));
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:$baseurl:{$owner['uid']}:{$item['hash']}"),
- '$title' => xmlify($item['title']),
- '$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')),
- '$content' =>xmlify($item['body']),
- '$parent_id' => xmlify("{$items[0]['remote-id']}"),
- '$comment_allow' => 0
- ));
+ foreach($items as $item) {
+ if($item['id'] == $item_id) {
+ $atom .= replace_macros($cmnt_template, array(
+ '$name' => xmlify($owner['name']),
+ '$profile_page' => xmlify($owner['url']),
+ '$thumb' => xmlify($owner['thumb']),
+ '$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
+ '$title' => xmlify($item['title']),
+ '$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')),
+ '$content' =>xmlify($item['body']),
+ '$parent_id' => xmlify("{$items[0]['remote-id']}"),
+ '$comment_allow' => 0
+ ));
+ }
+ }
}
else {
foreach($items as $item) {
'$owner_name' => xmlify($item['owner-name']),
'$owner_profile_page' => xmlify($item['owner-link']),
'$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']),
'$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')),
'$name' => xmlify($contact['name']),
'$profile_page' => xmlify($contact['url']),
'$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']),
'$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')),
else
$recip_str = implode(', ', $recipients);
+
$r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
dbesc($recip_str)
);
// delivery loop
foreach($r as $rr) {
+
+echo "In delivery loop:";
if($rr['self'])
continue;
$postvars['data'] = $atom;
else
$postvars['data'] = $atom_nowrite;
-
+echo "URL:" . $url;
+echo "POSTVARS:" . print_r($postvars);
$xml = post_url($url,$postvars);
+echo "XML response:" . $xml;
}
$res = array();
$author = $item->get_author();
- $res['remote-name'] = $author->get_name();
- $res['remote-link'] = $author->get_link();
- $res['remote-avatar'] = $author->get_avatar();
- $res['remote-id'] = $item->get_id();
- $res['title'] = $item->get_title();
- $res['body'] = $item->get_content();
+ $res['remote-name'] = unxmlify($author->get_name());
+ $res['remote-link'] = unxmlify($author->get_link());
+ $res['remote-avatar'] = unxmlify($author->get_avatar());
+ $res['remote-id'] = unxmlify($item->get_id());
+ $res['title'] = unxmlify($item->get_title());
+ $res['body'] = unxmlify($item->get_content());
if(strlen($res['body']) > 100000)
$res['body'] = substr($res['body'],0,10000) . "\r\n[Extremely large post truncated.]\r\n" ;
$rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
if($rawcreated)
- $res['created'] = $rawcreated[0]['data'];
+ $res['created'] = unxmlify($rawcreated[0]['data']);
$rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
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');
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'])
- $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'])
- $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;
function post_remote($a,$arr) {
$arr['hash'] = random_string();
- $arr['type'] = 'remote';
+ if(! x($arr,'type'))
+ $arr['type'] = 'remote';
$arr['remote-name'] = notags(trim($arr['remote-name']));
$arr['remote-link'] = notags(trim($arr['remote-link']));
$arr['remote-avatar'] = notags(trim($arr['remote-avatar']));
$parent_id = 0;
dbesc_array($arr);
-
+dbg(3);
$r = q("INSERT INTO `item` (`"
. implode("`, `", array_keys($arr))
. "`) VALUES ('"
}
function dfrn_notify_post(&$a) {
-
+dbg(3);
$dfrn_id = notags(trim($_POST['dfrn_id']));
$challenge = notags(trim($_POST['challenge']));
$data = $_POST['data'];
// remote reply to our post. Import and then notify everybody else.
$datarray = get_atom_elements($item);
$urn = explode(':',$parent_urn);
- $datarray['parent_hash'] = $urn[4];
+ $datarray['type'] = 'remote-comment';
+ $datarray['parent_hash'] = $urn[5];
$datarray['uid'] = $importer['uid'];
$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());
- 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;
}
$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),
intval($importer['uid'])
);
+ // FIXME update content if 'updated' changes
if(count($r)) {
$allow = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0','comment-allow');
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",
intval($allow[0]['data']),
- dbesc($item_id)
+ dbesc($item_id),
+ intval($importer['uid'])
);
}
continue;
// Head post of a conversation. Have we seen it? If not, import it.
$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),
intval($importer['uid'])
);
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",
intval($allow[0]['data']),
- dbesc($item_id)
+ dbesc($item_id),
+ intval($importer['uid'])
);
}
continue;
}
-
+ xml_status(0);
killme();
}
}
// 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'];
+ }
else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
intval($_SESSION['uid']));
} 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`)
- 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),
dbesc($_POST['type']),
intval($contact_id),
dbesc($contact_record['name']),
dbesc($contact_record['url']),
dbesc($contact_record['thumb']),
+ dbesc("urn:X-dfrn:" . $a->get_baseurl() . ':' . intval($profile_uid) . ':' . $hash),
datetime_convert(),
datetime_convert(),
dbesc($hash),
$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));
}
if($item['last-child']) {
$comment = replace_macros($cmnt_tpl,array(
+ '$return_path' => $a->cmd,
'$id' => $item['item_id'],
'$parent' => $item['parent'],
'$profile_uid' => $_SESSION['uid'],
if(can_write_wall($a,$a->profile['profile_uid'])) {
if($item['last-child']) {
$comment = replace_macros($cmnt_tpl,array(
+ '$return_path' => $a->cmd,
'$id' => $item['item_id'],
'$parent' => $item['parent'],
'$profile_uid' => $a->profile['profile_uid'],
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-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` ;
\ No newline at end of file
<input type="hidden" name="type" value="wall-comment" />
<input type="hidden" name="profile_uid" value="$profile_uid" />
<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>