1
0
Fork 0

Merge pull request #5826 from annando/network-name

We now can show "Friendica (AP)" as network name
This commit is contained in:
Hypolite Petovan 2018-10-05 15:43:16 -04:00 committed by GitHub
commit 3c7d41c388
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 13 deletions

View file

@ -657,7 +657,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
'id' => ($preview ? 'P0' : $item['id']), 'id' => ($preview ? 'P0' : $item['id']),
'guid' => ($preview ? 'Q0' : $item['guid']), 'guid' => ($preview ? 'Q0' : $item['guid']),
'network' => $item['network'], 'network' => $item['network'],
'network_name' => ContactSelector::networkToName($item['network'], $profile_link), 'network_name' => ContactSelector::networkToName($item['network'], $item['author-link']),
'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']), 'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
'profile_url' => $profile_link, 'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item), 'item_photo_menu' => item_photo_menu($item),

View file

@ -7,7 +7,9 @@ namespace Friendica\Content;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Util\Network;
/** /**
* @brief ContactSelector class * @brief ContactSelector class
@ -68,11 +70,11 @@ class ContactSelector
} }
/** /**
* @param string $s network * @param string $network network
* @param string $profile optional, default empty * @param string $profile optional, default empty
* @return string * @return string
*/ */
public static function networkToName($s, $profile = "") public static function networkToName($network, $profile = "")
{ {
$nets = [ $nets = [
Protocol::DFRN => L10n::t('Friendica'), Protocol::DFRN => L10n::t('Friendica'),
@ -98,18 +100,36 @@ class ContactSelector
$search = array_keys($nets); $search = array_keys($nets);
$replace = array_values($nets); $replace = array_values($nets);
$networkname = str_replace($search, $replace, $s); $networkname = str_replace($search, $replace, $network);
if ((in_array($s, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) { if ((in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) {
$r = DBA::fetchFirst("SELECT `gserver`.`platform` FROM `gcontact` // Create the server url out of the profile url
INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url` $parts = parse_url($profile);
WHERE `gcontact`.`nurl` = ? AND `platform` != ''", normalise_link($profile)); unset($parts['path']);
$server_url = [normalise_link(Network::unparseURL($parts))];
if (DBA::isResult($r)) { // Fetch the server url
$networkname = $r['platform']; $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => normalise_link($profile)]);
if (!empty($gcontact) && !empty($gcontact['server_url'])) {
$server_url[] = normalise_link($gcontact['server_url']);
}
if ($s == Protocol::ACTIVITYPUB) { // Now query the GServer for the platform name
$networkname .= ' (AP)'; $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
if (DBA::isResult($gserver)) {
if (!empty($gserver['platform'])) {
$platform = $gserver['platform'];
} elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
$platform = self::networkToName($gserver['network']);
}
if (!empty($platform)) {
$networkname = $platform;
if ($network == Protocol::ACTIVITYPUB) {
$networkname .= ' (AP)';
}
} }
} }
} }

View file

@ -402,7 +402,7 @@ class Post extends BaseObject
'thread_level' => $thread_level, 'thread_level' => $thread_level,
'edited' => $edited, 'edited' => $edited,
'network' => $item["network"], 'network' => $item["network"],
'network_name' => ContactSelector::networkToName($item['network'], $profile_link), 'network_name' => ContactSelector::networkToName($item['network'], $item['author-link']),
'received' => $item['received'], 'received' => $item['received'],
'commented' => $item['commented'], 'commented' => $item['commented'],
'created_date' => $item['created'], 'created_date' => $item['created'],