function p_init($a) { if ($a->argc != 2) { header($_SERVER["SERVER_PROTOCOL"] . ' 510 ' . t('Not Extended')); killme(); } $guid = $a->argv[1]; if (strtolower(substr($guid, -4)) != ".xml") { header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found')); killme(); } $guid = strtolower(substr($guid, 0, -4)); $item = q("SELECT `body`, `guid`, `contact-id`, `private`, `created`, `app` FROM `item` WHERE `uid` = 0 AND `guid` = '%s' AND `network` IN ('%s', '%s') LIMIT 1", dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA); if (!$item) { header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found')); killme(); } $post = array(); $reshared = diaspora_is_reshare($item[0]["body"]); if ($reshared) { $nodename = "reshare"; $post["root_diaspora_id"] = $reshared["root_handle"]; $post["root_guid"] = $reshared["root_guid"]; $post["guid"] = $item[0]["guid"]; $post["diaspora_handle"] = diaspora_handle_from_contact($item[0]["contact-id"]); $post["public"] = !$item[0]["private"] ? 'true' : 'false'; $post["created_at"] = datetime_convert('UTC', 'UTC', $item[0]["created"]); } else { $nodename = "status_message"; $post["raw_message"] = str_replace("&", "&", bb2diaspora($item[0]["body"])); $post["guid"] = $item[0]["guid"]; $post["diaspora_handle"] = diaspora_handle_from_contact($item[0]["contact-id"]); $post["public"] = !$item[0]["private"] ? 'true' : 'false'; $post["created_at"] = datetime_convert('UTC', 'UTC', $item[0]["created"]); $post["provider_display_name"] = $item[0]["app"]; } $dom = new DOMDocument("1.0"); $root = $dom->createElement("XML"); $dom->appendChild($root); $postelement = $dom->createElement("post"); $root->appendChild($postelement); $statuselement = $dom->createElement($nodename); $postelement->appendChild($statuselement); foreach ($post as $index => $value) { $postnode = $dom->createElement($index, $value); $statuselement->appendChild($postnode); } header("Content-Type: application/xml; charset=utf-8"); $xml = $dom->saveXML(); // Diaspora doesn't send the XML header, so we remove them as well. // So we avoid possible compatibility problems. if (substr($xml, 0, 21) == '<?xml version="1.0"?>') { $xml = trim(substr($xml, 21)); } echo $xml; killme(); }
function diaspora_send_status($item, $owner, $contact, $public_batch = false) { $a = get_app(); $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3); $theiraddr = $contact['addr']; $images = array(); $title = $item['title']; $body = $item['body']; /* // We're trying to match Diaspora's split message/photo protocol but // all the photos are displayed on D* as links and not img's - even // though we're sending pretty much precisely what they send us when // doing the same operation. // Commented out for now, we'll use bb2diaspora to convert photos to markdown // which seems to get through intact. $cnt = preg_match_all('|\[img\](.*?)\[\/img\]|',$body,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { $detail = array(); $detail['str'] = $mtch[0]; $detail['path'] = dirname($mtch[1]) . '/'; $detail['file'] = basename($mtch[1]); $detail['guid'] = $item['guid']; $detail['handle'] = $myaddr; $images[] = $detail; $body = str_replace($detail['str'],$mtch[1],$body); } } */ //if(strlen($title)) // $body = "[b]".html_entity_decode($title)."[/b]\n\n".$body; // convert to markdown $body = xmlify(html_entity_decode(bb2diaspora($body))); //$body = bb2diaspora($body); // Adding the title if (strlen($title)) { $body = "## " . html_entity_decode($title) . "\n\n" . $body; } if ($item['attach']) { $cnt = preg_match_all('/href=\\"(.*?)\\"(.*?)title=\\"(.*?)\\"/ism', $item['attach'], $matches, PREG_SET_ORDER); if (cnt) { $body .= "\n" . t('Attachments:') . "\n"; foreach ($matches as $mtch) { $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n"; } } } $public = $item['private'] ? 'false' : 'true'; require_once 'include/datetime.php'; $created = datetime_convert('UTC', 'UTC', $item['created'], 'Y-m-d H:i:s \\U\\T\\C'); // Detect a share element and do a reshare // see: https://github.com/Raven24/diaspora-federation/blob/master/lib/diaspora-federation/entities/reshare.rb if (!$item['private'] and $ret = diaspora_is_reshare($item["body"])) { $tpl = get_markup_template('diaspora_reshare.tpl'); $msg = replace_macros($tpl, array('$root_handle' => xmlify($ret['root_handle']), '$root_guid' => $ret['root_guid'], '$guid' => $item['guid'], '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, '$provider' => $item["app"])); } else { $tpl = get_markup_template('diaspora_post.tpl'); $msg = replace_macros($tpl, array('$body' => $body, '$guid' => $item['guid'], '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, '$provider' => $item["app"])); } logger('diaspora_send_status: ' . $owner['username'] . ' -> ' . $contact['name'] . ' base message: ' . $msg, LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); $return_code = diaspora_transmit($owner, $contact, $slap, $public_batch); logger('diaspora_send_status: guid: ' . $item['guid'] . ' result ' . $return_code, LOGGER_DEBUG); if (count($images)) { diaspora_send_images($item, $owner, $contact, $images, $public_batch); } return $return_code; }
function diaspora_build_status($item, $owner) { $myaddr = channel_reddress($owner); if (intval($item['id']) != intval($item['parent'])) { logger('attempted to send a comment as a top-level post'); return; } $images = array(); $title = $item['title']; $body = bb2diaspora_itembody($item, true); $poll = ''; $public = $item['item_private'] ? 'false' : 'true'; $created = datetime_convert('UTC', 'UTC', $item['created'], 'Y-m-d H:i:s \\U\\T\\C'); // Detect a share element and do a reshare if (!$item['item_private'] && ($ret = diaspora_is_reshare($item['body']))) { $msg = replace_macros(get_markup_template('diaspora_reshare.tpl', 'addon/diaspora'), ['$root_handle' => xmlify($ret['root_handle']), '$root_guid' => $ret['root_guid'], '$guid' => $item['mid'], '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, '$provider' => $item['app'] ? $item['app'] : t('$projectname')]); } else { $msg = replace_macros(get_markup_template('diaspora_post.tpl', 'addon/diaspora'), ['$body' => xmlify($body), '$guid' => $item['mid'], '$poll' => $poll, '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, '$provider' => $item['app'] ? $item['app'] : t('$projectname')]); } return $msg; }
function diaspora_send_status($item, $owner, $contact, $public_batch = false) { $a = get_app(); $myaddr = $owner['channel_address'] . '@' . substr(z_root(), strpos(z_root(), '://') + 3); if (intval($item['id']) != intval($item['parent'])) { logger('attempted to send a comment as a top-level post'); return; } $images = array(); $title = $item['title']; $body = bb2diaspora_itembody($item, true); /* // We're trying to match Diaspora's split message/photo protocol but // all the photos are displayed on D* as links and not img's - even // though we're sending pretty much precisely what they send us when // doing the same operation. // Commented out for now, we'll use bb2diaspora to convert photos to markdown // which seems to get through intact. $cnt = preg_match_all('|\[img\](.*?)\[\/img\]|',$body,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { $detail = array(); $detail['str'] = $mtch[0]; $detail['path'] = dirname($mtch[1]) . '/'; $detail['file'] = basename($mtch[1]); $detail['guid'] = $item['guid']; $detail['handle'] = $myaddr; $images[] = $detail; $body = str_replace($detail['str'],$mtch[1],$body); } } */ // @TODO We need a bit more infrastructure before we can process Diaspora polls // if(intval($item['item_consensus'])) { // $poll = replace_macros(get_markup_template('diaspora_consensus.tpl','addon/diaspora'), array( // '$guid_q' => '10000000', // '$question' => t('Please choose'), // '$guid_y' => '00000001', // '$agree' => t('Agree'), // '$guid_n' => '0000000F', // '$disagree' => t('Disagree'), // '$guid_a' => '00000000', // '$abstain' => t('Abstain') // )); // } // elseif($item['resource_type'] === 'event' && $item['resource_id']) { // $poll = replace_macros(get_markup_template('diaspora_consensus.tpl','addon/diaspora'), array( // '$guid_q' => '1000000', // '$question' => t('Please choose'), // '$guid_y' => '0000001', // '$agree' => t('I will attend'), /// '$guid_n' => '000000F', // '$disagree' => t('I will not attend'), // '$guid_a' => '0000000', // '$abstain' => t('I may attend') // )); // } // else $poll = ''; $public = $item['item_private'] ? 'false' : 'true'; require_once 'include/datetime.php'; $created = datetime_convert('UTC', 'UTC', $item['created'], 'Y-m-d H:i:s \\U\\T\\C'); // Detect a share element and do a reshare // see: https://github.com/Raven24/diaspora-federation/blob/master/lib/diaspora-federation/entities/reshare.rb if (!$item['item_private'] and $ret = diaspora_is_reshare($item["body"])) { $tpl = get_markup_template('diaspora_reshare.tpl', 'addon/diaspora'); $msg = replace_macros($tpl, array('$root_handle' => xmlify($ret['root_handle']), '$root_guid' => $ret['root_guid'], '$guid' => $item['mid'], '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, '$provider' => $item['app'] ? $item['app'] : t('$projectname'))); } else { $tpl = get_markup_template('diaspora_post.tpl', 'addon/diaspora'); $msg = replace_macros($tpl, array('$body' => xmlify($body), '$guid' => $item['mid'], '$poll' => $poll, '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, '$provider' => $item['app'] ? $item['app'] : t('$projectname'))); } logger('diaspora_send_status: ' . $owner['channel_name'] . ' -> ' . $contact['xchan_name'] . ' base message: ' . $msg, LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg, $owner, $contact, $owner['channel_prvkey'], $contact['xchan_pubkey'], $public_batch))); $qi = array(diaspora_queue($owner, $contact, $slap, $public_batch, $item['mid'])); // logger('diaspora_send_status: guid: '.$item['mid'].' result '.$return_code, LOGGER_DEBUG); if (count($images)) { $qim = diaspora_send_images($item, $owner, $contact, $images, $public_batch, $item['mid']); if ($qim) { $qi = array_merge($qi, $qim); } } return $qi; }