replace_people_guid: Break down nested calls
- Fix typo in function name - Fix arguments - Simplify url_from_fcontact_guid
This commit is contained in:
parent
4a7c3b9eef
commit
155e777d19
1 changed files with 27 additions and 27 deletions
|
@ -701,26 +701,20 @@ class Diaspora {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get a url (scheme://domain.tld/u/user) from a given Diaspora
|
* @brief get a url (scheme://domain.tld/u/user) from a given Diaspora*
|
||||||
* fcontact id or guid
|
* fcontact guid
|
||||||
*
|
*
|
||||||
* @param mixed $contact_id Either the numeric id or the string guid
|
* @param mixed $fcontact_guid Hexadecimal string guid
|
||||||
*
|
*
|
||||||
* @return string the url
|
* @return string the contact url or null
|
||||||
*/
|
*/
|
||||||
public static function url_from_fcontact($contact_id) {
|
public static function url_from_fcontact_guid($fcontact_guid) {
|
||||||
$handle = False;
|
logger("fcontact guid is ".$fcontact_guid, LOGGER_DEBUG);
|
||||||
|
|
||||||
logger("fcontact id is ".$contact_id, LOGGER_DEBUG);
|
$r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = 'dspr' AND `url` != ''",
|
||||||
|
$fcontact_guid);
|
||||||
|
|
||||||
if (is_numeric($contact_id)) {
|
if (dbm::is_result($r)) {
|
||||||
$r = q("SELECT `url` FROM `fcontact` WHERE `id` = %d AND `network` = 'dspr' `url` != ''",
|
|
||||||
intval($contact_id));
|
|
||||||
}else {
|
|
||||||
$r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = 'dspr' AND `url` != ''",
|
|
||||||
$contact_id);
|
|
||||||
}
|
|
||||||
if ($r) {
|
|
||||||
return $r[0]['url'];
|
return $r[0]['url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -854,20 +848,22 @@ class Diaspora {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks for relative /people/* links to match local contacts or
|
* @brief Checks for relative /people/* links in an item body to match local
|
||||||
* prepends the remote host taken from the author link
|
* contacts or prepends the remote host taken from the author link.
|
||||||
*
|
*
|
||||||
* @param string $body The item body to replace links from
|
* @param string $body The item body to replace links from
|
||||||
* @param string $author_link The author link for missing local contact fallback
|
* @param string $author_link The author link for missing local contact fallback
|
||||||
|
*
|
||||||
|
* @return the replaced string
|
||||||
*/
|
*/
|
||||||
public function replace_people_guid($body, $author_link) {
|
public function replace_people_guid($body, $author_link) {
|
||||||
$return = preg_replace_callback("&\[url=/people/([^\[\]]*)\](.*)\[\/url\]&Usi",
|
$return = preg_replace_callback("&\[url=/people/([^\[\]]*)\](.*)\[\/url\]&Usi",
|
||||||
function ($match) use ($author_link){
|
function ($match) use ($author_link) {
|
||||||
// $match
|
// $match
|
||||||
// 0 => '[url=/people/0123456789abcdef]Foo Bar[/url]'
|
// 0 => '[url=/people/0123456789abcdef]Foo Bar[/url]'
|
||||||
// 1 => '0123456789abcdef'
|
// 1 => '0123456789abcdef'
|
||||||
// 2 => 'Foo Bar'
|
// 2 => 'Foo Bar'
|
||||||
$handle = self::url_from_fcontact($match[1]);
|
$handle = self::url_from_fcontact_guid($match[1]);
|
||||||
|
|
||||||
if ($handle) {
|
if ($handle) {
|
||||||
$return = '@[url='.$handle.']'.$match[2].'[/url]';
|
$return = '@[url='.$handle.']'.$match[2].'[/url]';
|
||||||
|
@ -878,7 +874,6 @@ class Diaspora {
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|
||||||
}, $body);
|
}, $body);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -1226,9 +1221,9 @@ class Diaspora {
|
||||||
|
|
||||||
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
|
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
|
||||||
|
|
||||||
$datarray["body"] = diaspora2bb($text);
|
$body = diaspora2bb($text);
|
||||||
|
|
||||||
$datarray["body"] = self::replace_people_gui($datarray);
|
$datarray["body"] = self::replace_people_guid($body, $person["url"]);
|
||||||
|
|
||||||
self::fetch_guid($datarray);
|
self::fetch_guid($datarray);
|
||||||
|
|
||||||
|
@ -1624,8 +1619,6 @@ class Diaspora {
|
||||||
|
|
||||||
$reply = 0;
|
$reply = 0;
|
||||||
|
|
||||||
$body = self::replace_people_guid(diaspora2bb($text), $person["url"]);
|
|
||||||
|
|
||||||
$message_uri = $author.":".$guid;
|
$message_uri = $author.":".$guid;
|
||||||
|
|
||||||
$person = self::person_by_handle($author);
|
$person = self::person_by_handle($author);
|
||||||
|
@ -1643,6 +1636,10 @@ class Diaspora {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$body = diaspora2bb($text);
|
||||||
|
|
||||||
|
$body = self::replace_people_guid($body, $person["url"]);
|
||||||
|
|
||||||
q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
|
q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
|
||||||
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
|
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
|
||||||
intval($importer["uid"]),
|
intval($importer["uid"]),
|
||||||
|
@ -2092,7 +2089,9 @@ class Diaspora {
|
||||||
if (self::is_reshare($r[0]["body"], true))
|
if (self::is_reshare($r[0]["body"], true))
|
||||||
$r = array();
|
$r = array();
|
||||||
elseif (self::is_reshare($r[0]["body"], false)) {
|
elseif (self::is_reshare($r[0]["body"], false)) {
|
||||||
$r[0]["body"] = self::replace_people_guid(diaspora2bb(bb2diaspora($r[0]["body"])), $r[0]["author-link"]);
|
$r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"]));
|
||||||
|
|
||||||
|
$r[0]["body"] = self::replace_people_guid($r[0]["body"], $r[0]["author-link"]);
|
||||||
|
|
||||||
// Add OEmbed and other information to the body
|
// Add OEmbed and other information to the body
|
||||||
$r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true);
|
$r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true);
|
||||||
|
@ -2122,7 +2121,8 @@ class Diaspora {
|
||||||
if ($r) {
|
if ($r) {
|
||||||
// If it is a reshared post from another network then reformat to avoid display problems with two share elements
|
// If it is a reshared post from another network then reformat to avoid display problems with two share elements
|
||||||
if (self::is_reshare($r[0]["body"], false)) {
|
if (self::is_reshare($r[0]["body"], false)) {
|
||||||
$r[0]["body"] = self::replace_people_guid(diaspora2bb(bb2diaspora($r[0]["body"])), $r[0]["author-link"]);
|
$r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"]));
|
||||||
|
$r[0]["body"] = self::replace_people_guid($r[0]["body"], $r[0]["author-link"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $r[0];
|
return $r[0];
|
||||||
|
@ -2381,7 +2381,7 @@ class Diaspora {
|
||||||
|
|
||||||
$datarray["object"] = $xml;
|
$datarray["object"] = $xml;
|
||||||
|
|
||||||
$datarray["body"] = self::replace_people_guid($body, $datarray["author-link"]);
|
$datarray["body"] = self::replace_people_guid($body, $contact["url"]);
|
||||||
|
|
||||||
if ($provider_display_name != "")
|
if ($provider_display_name != "")
|
||||||
$datarray["app"] = $provider_display_name;
|
$datarray["app"] = $provider_display_name;
|
||||||
|
|
Loading…
Reference in a new issue