mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
refactor page mime routing to init multimedia support
This commit is contained in:
parent
720f9ebbae
commit
81595f0b79
6 changed files with 223 additions and 195 deletions
|
|
@ -7,115 +7,16 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Page\Content;
|
|||
use \Yggverse\Gemtext\Document;
|
||||
use \Yggverse\Net\Address;
|
||||
|
||||
class Data
|
||||
class Gemtext extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup
|
||||
{
|
||||
public \GtkLabel $gtk;
|
||||
|
||||
// Extras
|
||||
public ?string $raw = null;
|
||||
|
||||
// Dependencies
|
||||
public \Yggverse\Yoda\Entity\Browser\Container\Page\Content $content;
|
||||
|
||||
// Defaults
|
||||
private int $_wrap = 140;
|
||||
|
||||
public function __construct(
|
||||
\Yggverse\Yoda\Entity\Browser\Container\Page\Content $content
|
||||
) {
|
||||
// Init dependency
|
||||
$this->content = $content;
|
||||
|
||||
// Init markup label
|
||||
$this->gtk = new \GtkLabel;
|
||||
|
||||
$this->gtk->set_use_markup(
|
||||
true
|
||||
);
|
||||
|
||||
$this->gtk->set_selectable(
|
||||
true
|
||||
);
|
||||
|
||||
$this->gtk->set_can_focus(
|
||||
false
|
||||
);
|
||||
|
||||
$this->gtk->set_track_visited_links(
|
||||
true
|
||||
);
|
||||
|
||||
$this->gtk->set_xalign(
|
||||
0
|
||||
);
|
||||
|
||||
$this->gtk->set_yalign(
|
||||
0
|
||||
);
|
||||
|
||||
// Render
|
||||
$this->gtk->show();
|
||||
|
||||
// Init events
|
||||
$this->gtk->connect(
|
||||
'activate-link',
|
||||
function(
|
||||
\GtkLabel $label,
|
||||
string $href
|
||||
) {
|
||||
// Format URL
|
||||
$url = $this->_url(
|
||||
$href
|
||||
);
|
||||
|
||||
// Update request entry
|
||||
$this->content->page->navbar->request->setValue(
|
||||
$this->_url(
|
||||
$href
|
||||
)
|
||||
);
|
||||
|
||||
// Update page
|
||||
$this->content->page->update();
|
||||
|
||||
// Prevent propagation for supported protocols
|
||||
if (in_array(
|
||||
parse_url(
|
||||
$url,
|
||||
PHP_URL_SCHEME
|
||||
),
|
||||
[
|
||||
'nex',
|
||||
'gemini',
|
||||
'file'
|
||||
])
|
||||
) return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function setPlain(
|
||||
string $value
|
||||
): void
|
||||
{
|
||||
$this->gtk->set_markup(
|
||||
sprintf(
|
||||
'<tt>%s</tt>',
|
||||
htmlspecialchars(
|
||||
$value
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->raw = $value;
|
||||
}
|
||||
|
||||
public function setGemtext(
|
||||
public function setSource(
|
||||
string $value,
|
||||
string | null &$title = null,
|
||||
bool $preformatted = false
|
||||
): void
|
||||
{
|
||||
$this->_source = $value;
|
||||
|
||||
$document = new Document(
|
||||
$value
|
||||
);
|
||||
|
|
@ -330,8 +231,39 @@ class Data
|
|||
$line
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->raw = $value;
|
||||
protected function _onActivateLink(
|
||||
\GtkLabel $label,
|
||||
string $href
|
||||
) {
|
||||
// Format URL
|
||||
$url = $this->_url(
|
||||
$href
|
||||
);
|
||||
|
||||
// Update request entry
|
||||
$this->content->page->navbar->request->setValue(
|
||||
$this->_url(
|
||||
$href
|
||||
)
|
||||
);
|
||||
|
||||
// Update page
|
||||
$this->content->page->update();
|
||||
|
||||
// Prevent propagation for supported protocols
|
||||
if (in_array(
|
||||
parse_url(
|
||||
$url,
|
||||
PHP_URL_SCHEME
|
||||
),
|
||||
[
|
||||
'nex',
|
||||
'gemini',
|
||||
'file'
|
||||
])
|
||||
) return true;
|
||||
}
|
||||
|
||||
private function _wrap(
|
||||
24
src/Entity/Browser/Container/Page/Content/Plain.php
Normal file
24
src/Entity/Browser/Container/Page/Content/Plain.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Content;
|
||||
|
||||
class Plain extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup
|
||||
{
|
||||
public function setSource(
|
||||
string $value
|
||||
): void
|
||||
{
|
||||
$this->_source = $value;
|
||||
|
||||
$this->gtk->set_markup(
|
||||
sprintf(
|
||||
'<tt>%s</tt>',
|
||||
htmlspecialchars(
|
||||
$value
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue