Enable "magic" with Hubzilla

This commit is contained in:
Michael 2024-05-20 19:36:40 +00:00
parent 5751311e99
commit dca93a9606
8 changed files with 115 additions and 79 deletions

View file

@ -29,6 +29,7 @@ use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\HTTPException\NotModifiedException;
use GuzzleHttp\Psr7\Exception\MalformedUriException;
use GuzzleHttp\Psr7\Uri;
use Psr\Http\Message\UriInterface;
@ -670,4 +671,28 @@ class Network
return null;
}
}
/**
* Remove an Url parameter
*
* @param string $url
* @param string $parameter
* @return string
* @throws MalformedUriException
*/
public static function removeUrlParameter(string $url, string $parameter): string
{
$parts = parse_url($url);
if (empty($parts['query'])) {
return $url;
}
parse_str($parts['query'], $data);
unset($data[$parameter]);
$parts['query'] = http_build_query($data);
return (string)Uri::fromParts($parts);
}
}

View file

@ -498,7 +498,8 @@ class Strings
$blocks = [];
$return = preg_replace_callback($regex,
$return = preg_replace_callback(
$regex,
function ($matches) use ($executionId, &$blocks) {
$return = '«block-' . $executionId . '-' . count($blocks) . '»';
@ -516,7 +517,8 @@ class Strings
$text = $callback($return ?? $text) ?? '';
// Restore code blocks
$text = preg_replace_callback('/«block-' . $executionId . '-([0-9]+)»/iU',
$text = preg_replace_callback(
'/«block-' . $executionId . '-([0-9]+)»/iU',
function ($matches) use ($blocks) {
$return = $matches[0];
if (isset($blocks[intval($matches[1])])) {
@ -545,10 +547,10 @@ class Strings
return $shorthand;
}
$last = strtolower($shorthand[strlen($shorthand)-1]);
$last = strtolower($shorthand[strlen($shorthand) - 1]);
$shorthand = substr($shorthand, 0, -1);
switch($last) {
switch ($last) {
case 'g':
$shorthand *= 1024;
case 'm':