Merge branch 'dev' of codeberg.org:streams/streams into dev

This commit is contained in:
Mike Macgirvin 2024-05-24 15:19:35 -07:00
commit 20405aa513
7 changed files with 105 additions and 31 deletions

View file

@ -1680,12 +1680,12 @@ function format_mentions($item)
$txt = $x[0]['xchan_name'];
break;
case 1:
$txt = (($x[0]['xchan_addr']) ?: $x[0]['xchan_name']);
$txt = (($x[0]['xchan_addr']) ? unpunify_addr($x[0]['xchan_addr']): $x[0]['xchan_name']);
break;
case 2:
default;
if ($x[0]['xchan_addr']) {
$txt = sprintf(t('%1$s (%2$s)'), $x[0]['xchan_name'], $x[0]['xchan_addr']);
$txt = sprintf(t('%1$s (%2$s)'), $x[0]['xchan_name'], unpunify_addr($x[0]['xchan_addr']));
} else {
$txt = $x[0]['xchan_name'];
}
@ -3991,6 +3991,19 @@ function featured_sort($a, $b)
return(strcmp($s1, $s2));
}
function unpunify_addr($s)
{
$output = '';
$arr = explode('@', $s);
if ($arr) {
foreach ($arr as $str) {
$output .= unpunify($str);
$output .= '@';
}
$output = rtrim($output, '@');
}
return $output;
}
function unpunify($s)
{
@ -4000,6 +4013,20 @@ function unpunify($s)
return $s;
}
function punify_addr($s)
{
$output = '';
$arr = explode('@', $s);
if ($arr) {
foreach ($arr as $str) {
$output .= punify($str);
$output .= '@';
}
$output = rtrim($output, '@');
}
return $output;
}
function punify($s)
{

View file

@ -157,6 +157,9 @@ class ActivityStreams
// Determine if this is a followup or response activity
$this->parent_id = $this->get_property_obj('inReplyTo');
if (!empty($this->parent_id['id'])) {
$this->parent_id = $this->parent_id['id'];
}
if ((!$this->parent_id) && is_array($this->obj)) {
$this->parent_id = $this->obj['inReplyTo'];

View file

@ -2045,7 +2045,7 @@ class Channel
$nick = punify($nick);
// return a cached copy if there is a cached copy and it's a match.
// return a cached copy - if there is a cached copy, and it's a match.
// Also check that there is an xchan_hash to validate the App::$channel data is complete
// and that columns from both joined tables are present

View file

@ -454,8 +454,8 @@ class ThreadItem
'undo_attend' => $undo_attend,
'consensus' => '',
'conlabels' => '',
'linktitle' => sprintf(t('View %s\'s profile - %s'), $profile_name, (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url'])),
'olinktitle' => sprintf(t('View %s\'s profile - %s'), $this->get_owner_name(), (($this->get_owner_addr()) ? $this->get_owner_addr() : $this->get_owner_url())),
'linktitle' => sprintf(t('View %s\'s profile - %s'), $profile_name, (($item['author']['xchan_addr']) ? unpunify_addr($item['author']['xchan_addr']) : $item['author']['xchan_url'])),
'olinktitle' => sprintf(t('View %s\'s profile - %s'), $this->get_owner_name(), (($this->get_owner_addr()) ? unpunify_addr($this->get_owner_addr()) : $this->get_owner_url())),
'llink' => $item['llink'],
'viewthread' => $viewthread,
'to' => t('to'),

View file

@ -25,32 +25,28 @@ class New_channel extends Controller
if ($cmd === 'autofill.json') {
$n = trim($_REQUEST['name']);
$x = false;
$n = punify(mb_strtolower($n));
if (get_config('system', 'unicode_usernames')) {
$x = punify(mb_strtolower($n));
}
if ((!$x) || strlen($x) > 64) {
$x = strtolower(URLify::transliterate($n));
if (strlen($n) > 64) {
$n = strtolower(URLify::transliterate($n));
}
$test = [];
// first name
if (strpos($x, ' ')) {
$test[] = legal_webbie(substr($x, 0, strpos($x, ' ')));
if (strpos($n, ' ')) {
$test[] = legal_webbie(substr($n, 0, strpos($n, ' ')));
}
if ($test[0]) {
// first name plus first initial of last
$test[] = ((strpos($x, ' ')) ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : '');
$test[] = ((strpos($n, ' ')) ? $test[0] . legal_webbie(trim(substr($n, strpos($n, ' '), 2))) : '');
// first name plus random number
$test[] = $test[0] . mt_rand(1000, 9999);
}
// fullname
$test[] = legal_webbie($x);
$test[] = legal_webbie($n);
// fullname plus random number
$test[] = legal_webbie($x) . mt_rand(1000, 9999);
$test[] = legal_webbie($n) . mt_rand(1000, 9999);
json_return_and_die(check_webbie($test));
}
@ -61,31 +57,26 @@ class New_channel extends Controller
$n = trim($_REQUEST['name']);
}
$x = false;
$n = punify(mb_strtolower($n));
if (get_config('system', 'unicode_usernames')) {
$x = punify(mb_strtolower($n));
if (strlen($n) > 64) {
$n = strtolower(URLify::transliterate($n));
}
if ((!$x) || strlen($x) > 64) {
$x = strtolower(URLify::transliterate($n));
}
$test = [];
// first name
if (strpos($x, ' ')) {
$test[] = legal_webbie(substr($x, 0, strpos($x, ' ')));
if (strpos($n, ' ')) {
$test[] = legal_webbie(substr($n, 0, strpos($n, ' ')));
}
if ($test[0]) {
// first name plus first initial of last
$test[] = ((strpos($x, ' ')) ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : '');
$test[] = ((strpos($n, ' ')) ? $test[0] . legal_webbie(trim(substr($n, strpos($n, ' '), 2))) : '');
// first name plus random number
$test[] = $test[0] . mt_rand(1000, 9999);
}
$n = legal_webbie($x);
$n = legal_webbie($n);
if (strlen($n)) {
$test[] = $n;
$test[] = $n . mt_rand(1000, 9999);

53
src/Module/Pushsub.php Normal file
View file

@ -0,0 +1,53 @@
<?php
namespace Code\Module;
use Code\Web\Controller;
class Pushsub extends Controller
{
public function init()
{
$rawSubscription = file_get_contents('php://input');
$channel_id = local_channel();
$subscription = json_decode($rawSubscription, true);
if (!isset($subscription['endpoint'])) {
logger('not a subscription');
killme();
}
$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'POST':
$result = q("insert into pushsub (channel_id, endpoint, json) values ('%s', '%s', '%s')",
intval($channel_id),
dbesc($subscription['endpoint']),
dbesc($rawSubscription)
);
break;
case 'PUT':
$result = q("update pushsub set json = '%s' where endpoint = '%s' and channel_id = %d",
dbesc($rawSubscription),
dbesc($subscription['endpoint']),
intval($channel_id)
);
break;
case 'DELETE':
$result = q("delete pushsub where endpoint = '%s' and channel_id = %d",
dbesc($subscription['endpoint']),
intval(local_channel())
);
break;
default:
logger('method not handled');
break;
}
killme();
}
}

View file

@ -66,9 +66,9 @@ class Webfinger extends Controller
}
if (str_starts_with($resource, 'acct:')) {
$channel_nickname = punify(str_replace('acct:', '', $resource));
$channel_nickname = punify_addr(str_replace('acct:', '', $resource));
if (strrpos($channel_nickname, '@') !== false) {
$host = punify(substr($channel_nickname, strrpos($channel_nickname, '@') + 1));
$host = substr($channel_nickname, strrpos($channel_nickname, '@') + 1);
// If the webfinger address points off site, redirect to the correct site