mirror of
https://github.com/YGGverse/gemini-php.git
synced 2026-04-01 01:15:28 +00:00
69 lines
No EOL
1.3 KiB
PHP
69 lines
No EOL
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Yggverse\Gemini\Gemtext;
|
|
|
|
class Link
|
|
{
|
|
private string $_line;
|
|
|
|
public function __construct(string $line)
|
|
{
|
|
$this->_line = preg_replace(
|
|
'/^\s*=>(.*)/',
|
|
'$1',
|
|
trim(
|
|
$line
|
|
)
|
|
);
|
|
}
|
|
|
|
public function getAddress(): ?string
|
|
{
|
|
if (preg_match('/^\s*([^\s]+)/', trim($this->_line), $match))
|
|
{
|
|
return trim(
|
|
$match[1]
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getDate(?int &$timestamp = null): ?string
|
|
{
|
|
if (preg_match('/\s([\d]+-[\d+]+-[\d]+)\s/', trim($this->_line), $match))
|
|
{
|
|
if ($result = strtotime($match[1]))
|
|
{
|
|
$timestamp = $result;
|
|
|
|
return trim(
|
|
$match[1]
|
|
);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getAlt(): ?string
|
|
{
|
|
if (preg_match('/\s[\d]+-[\d+]+-[\d]+\s(.*)$/', trim($this->_line), $match))
|
|
{
|
|
return trim(
|
|
$match[1]
|
|
);
|
|
}
|
|
|
|
else if (preg_match('/\s(.*)$/', trim($this->_line), $match))
|
|
{
|
|
return trim(
|
|
$match[1]
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
} |