Merge pull request #3058 from annando/1701-diaspora-thread-reply
Diaspora mentions are now done correctly
This commit is contained in:
commit
72a0b8d3be
2 changed files with 35 additions and 22 deletions
|
@ -69,6 +69,28 @@ function diaspora2bb($s) {
|
||||||
return $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) {
|
function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
|
||||||
|
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
@ -132,6 +154,11 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
|
||||||
// the Diaspora signature verification and cause the item to disappear
|
// the Diaspora signature verification and cause the item to disappear
|
||||||
$Text = trim($Text);
|
$Text = trim($Text);
|
||||||
|
|
||||||
|
if ($fordiaspora) {
|
||||||
|
$URLSearchString = "^\[\]";
|
||||||
|
$Text = preg_replace_callback("/([@]\[(.*?)\])\(([$URLSearchString]*?)\)/ism", 'diaspora_mentions', $Text);
|
||||||
|
}
|
||||||
|
|
||||||
call_hooks('bb2diaspora',$Text);
|
call_hooks('bb2diaspora',$Text);
|
||||||
|
|
||||||
return $Text;
|
return $Text;
|
||||||
|
|
20
mod/item.php
20
mod/item.php
|
@ -95,8 +95,7 @@ function item_post(&$a) {
|
||||||
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
|
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
|
||||||
intval($parent)
|
intval($parent)
|
||||||
);
|
);
|
||||||
}
|
} elseif ($parent_uri && local_user()) {
|
||||||
elseif ($parent_uri && local_user()) {
|
|
||||||
// This is coming from an API source, and we are logged in
|
// 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",
|
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||||
dbesc($parent_uri),
|
dbesc($parent_uri),
|
||||||
|
@ -141,16 +140,7 @@ function item_post(&$a) {
|
||||||
$thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent));
|
$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 ($thrparent[0]["network"] === NETWORK_OSTATUS)
|
||||||
AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
|
AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
|
||||||
$parent_contact = null;
|
$parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]);
|
||||||
|
|
||||||
$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"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($parent_contact["nick"])) {
|
if (!isset($parent_contact["nick"])) {
|
||||||
require_once("include/Scrape.php");
|
require_once("include/Scrape.php");
|
||||||
|
@ -568,11 +558,7 @@ function item_post(&$a) {
|
||||||
* add a statusnet style reply tag if the original post was from there
|
* add a statusnet style reply tag if the original post was from there
|
||||||
* and we are replying, and there isn't one already
|
* and we are replying, and there isn't one already
|
||||||
*/
|
*/
|
||||||
|
if ($parent AND ($parent_contact['network'] == NETWORK_OSTATUS)) {
|
||||||
if($parent AND ($parent_contact['network'] === NETWORK_OSTATUS)) {
|
|
||||||
if ($parent_contact['id'] != "")
|
|
||||||
$contact = '@'.$parent_contact['nick'].'+'.$parent_contact['id'];
|
|
||||||
else
|
|
||||||
$contact = '@[url='.$parent_contact['url'].']'.$parent_contact['nick'].'[/url]';
|
$contact = '@[url='.$parent_contact['url'].']'.$parent_contact['nick'].'[/url]';
|
||||||
|
|
||||||
if (!in_array($contact,$tags)) {
|
if (!in_array($contact,$tags)) {
|
||||||
|
|
Loading…
Reference in a new issue