-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yggverse
committed
Apr 3, 2024
1 parent
be8b861
commit 7916351
Showing
2 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yggverse\Gemini\Gemtext; | ||
|
||
class Link | ||
{ | ||
private string $_line; | ||
|
||
public function __construct(string $line) | ||
{ | ||
$this->_line = $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; | ||
} | ||
} |