separate link formatting for URLs and for plain text

This commit is contained in:
Shish 2020-02-25 12:26:56 +00:00
parent d97f492aaf
commit 33731e8cb0
3 changed files with 14 additions and 5 deletions

View File

@ -114,7 +114,8 @@ class ThumbnailGenerationEvent extends Event
/* /*
* ParseLinkTemplateEvent: * ParseLinkTemplateEvent:
* $link -- the formatted link * $link -- the formatted text (with each element URL Escape'd)
* $text -- the formatted text (not escaped)
* $original -- the formatting string, for reference * $original -- the formatting string, for reference
* $image -- the image who's link is being parsed * $image -- the image who's link is being parsed
*/ */
@ -123,6 +124,8 @@ class ParseLinkTemplateEvent extends Event
/** @var string */ /** @var string */
public $link; public $link;
/** @var string */ /** @var string */
public $text;
/** @var string */
public $original; public $original;
/** @var Image */ /** @var Image */
public $image; public $image;
@ -131,6 +134,7 @@ class ParseLinkTemplateEvent extends Event
{ {
parent::__construct(); parent::__construct();
$this->link = $link; $this->link = $link;
$this->text = $link;
$this->original = $link; $this->original = $link;
$this->image = $image; $this->image = $image;
} }
@ -138,7 +142,8 @@ class ParseLinkTemplateEvent extends Event
public function replace(string $needle, ?string $replace): void public function replace(string $needle, ?string $replace): void
{ {
if (!is_null($replace)) { if (!is_null($replace)) {
$this->link = str_replace($needle, $replace, $this->link); $this->link = str_replace($needle, url_escape($replace), $this->link);
$this->text = str_replace($needle, $replace, $this->text);
} }
} }
} }

View File

@ -492,7 +492,9 @@ class Image
*/ */
public function get_nice_image_name(): string public function get_nice_image_name(): string
{ {
return $this->parse_link_template('$id - $tags.$ext'); $plte = new ParseLinkTemplateEvent('$id - $tags.$ext', $this);
send_event($plte);
return $plte->text;
} }
/** /**
@ -534,7 +536,9 @@ class Image
public function get_tooltip(): string public function get_tooltip(): string
{ {
global $config; global $config;
return $this->parse_link_template($config->get_string(ImageConfig::TIP)); $plte = new ParseLinkTemplateEvent($config->get_string(ImageConfig::TIP), $this);
send_event($plte);
return $plte->text;
} }
/** /**

View File

@ -273,7 +273,7 @@ class TagEdit extends Extension
$tags = $event->image->get_tag_list(); $tags = $event->image->get_tag_list();
$tags = str_replace("/", "", $tags); $tags = str_replace("/", "", $tags);
$tags = preg_replace("/^\.+/", "", $tags); $tags = preg_replace("/^\.+/", "", $tags);
$event->replace('$tags', url_escape($tags)); $event->replace('$tags', $tags);
} }
private function mass_tag_edit(string $search, string $replace) private function mass_tag_edit(string $search, string $replace)