Automatically add a Diaspora mention
This commit is contained in:
parent
8c579735f9
commit
8aaf09f9ee
|
@ -69,6 +69,28 @@ function diaspora2bb($s) {
|
|||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback function to replace a Friendica style mention in a mention for Diaspora
|
||||
*
|
||||
* @param array $match Matching values for the callback
|
||||
* @return text Replaced mention
|
||||
*/
|
||||
function diaspora_mentions($match) {
|
||||
|
||||
$contact = get_contact_details_by_url($match[3]);
|
||||
|
||||
if (!isset($contact['addr'])) {
|
||||
$contact = Probe::uri($match[3]);
|
||||
}
|
||||
|
||||
if (!isset($contact['addr'])) {
|
||||
return $match[0];
|
||||
}
|
||||
|
||||
$mention = '@{'.$match[2].'; '.$contact['addr'].'}';
|
||||
return $mention;
|
||||
}
|
||||
|
||||
function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
|
||||
|
||||
$a = get_app();
|
||||
|
@ -108,8 +130,8 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
|
|||
} else
|
||||
$Text = bbcode($Text, $preserve_nl, false, 4);
|
||||
|
||||
// mask some special HTML chars from conversation to markdown
|
||||
$Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text);
|
||||
// mask some special HTML chars from conversation to markdown
|
||||
$Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text);
|
||||
|
||||
// If a link is followed by a quote then there should be a newline before it
|
||||
// Maybe we should make this newline at every time before a quote.
|
||||
|
@ -120,8 +142,8 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
|
|||
// Now convert HTML to Markdown
|
||||
$Text = new HTML_To_Markdown($Text);
|
||||
|
||||
// unmask the special chars back to HTML
|
||||
$Text = str_replace(array('&_lt_;','&_gt_;','&_amp_;'),array('<','>','&'),$Text);
|
||||
// unmask the special chars back to HTML
|
||||
$Text = str_replace(array('&_lt_;','&_gt_;','&_amp_;'),array('<','>','&'),$Text);
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
|
@ -132,6 +154,11 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
|
|||
// the Diaspora signature verification and cause the item to disappear
|
||||
$Text = trim($Text);
|
||||
|
||||
if ($fordiaspora) {
|
||||
$URLSearchString = "^\[\]";
|
||||
$Text = preg_replace_callback("/([@]\[(.*?)\])\(([$URLSearchString]*)\)/ism", 'diaspora_mentions', $Text);
|
||||
}
|
||||
|
||||
call_hooks('bb2diaspora',$Text);
|
||||
|
||||
return $Text;
|
||||
|
|
28
mod/item.php
28
mod/item.php
|
@ -95,8 +95,7 @@ function item_post(&$a) {
|
|||
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
|
||||
intval($parent)
|
||||
);
|
||||
}
|
||||
elseif ($parent_uri && local_user()) {
|
||||
} elseif ($parent_uri && local_user()) {
|
||||
// This is coming from an API source, and we are logged in
|
||||
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($parent_uri),
|
||||
|
@ -104,6 +103,8 @@ function item_post(&$a) {
|
|||
);
|
||||
}
|
||||
|
||||
$thr_parent_item = $r[0];
|
||||
|
||||
// if this isn't the real parent of the conversation, find it
|
||||
if (dbm::is_result($r)) {
|
||||
$parid = $r[0]['parent'];
|
||||
|
@ -139,18 +140,9 @@ function item_post(&$a) {
|
|||
|
||||
// If the contact id doesn't fit with the contact, then set the contact to null
|
||||
$thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent));
|
||||
if (count($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS)
|
||||
if (count($thrparent) AND in_array($thrparent[0]["network"], array(NETWORK_OSTATUS, NETWORK_DIASPORA))
|
||||
AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
|
||||
$parent_contact = null;
|
||||
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($thrparent[0]["author-link"])));
|
||||
if (dbm::is_result($r)) {
|
||||
$parent_contact = $r[0];
|
||||
$parent_contact["thumb"] = $parent_contact["photo"];
|
||||
$parent_contact["micro"] = $parent_contact["photo"];
|
||||
unset($parent_contact["id"]);
|
||||
}
|
||||
$parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]);
|
||||
|
||||
if (!isset($parent_contact["nick"])) {
|
||||
require_once("include/Scrape.php");
|
||||
|
@ -569,11 +561,13 @@ function item_post(&$a) {
|
|||
* and we are replying, and there isn't one already
|
||||
*/
|
||||
if ($parent AND (($parent_contact['network'] == NETWORK_OSTATUS) OR
|
||||
(($parent_item['uri'] != $thr_parent) AND ($parent_contact['network'] == NETWORK_DIASPORA)))) {
|
||||
if ($parent_contact['id'] != "")
|
||||
$contact = '@'.$parent_contact['nick'].'+'.$parent_contact['id'];
|
||||
else
|
||||
(($parent_item['uri'] != $thr_parent) AND ($thr_parent_item['network'] == NETWORK_DIASPORA)))) {
|
||||
|
||||
if ($thr_parent_item['network'] != NETWORK_DIASPORA) {
|
||||
$contact = '@[url='.$parent_contact['url'].']'.$parent_contact['nick'].'[/url]';
|
||||
} else {
|
||||
$contact = '@[url='.$parent_contact['url'].']'.$parent_contact['name'].'[/url]';
|
||||
}
|
||||
|
||||
if (!in_array($contact,$tags)) {
|
||||
$body = $contact.' '.$body;
|
||||
|
|
Loading…
Reference in a new issue