Skip to content

Commit

Permalink
Fix: #3973, Fix: #3814, Fix: #3827 - autolink URLs in PAGE fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Jul 28, 2021
1 parent 110955c commit cef4fcc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
22 changes: 21 additions & 1 deletion app/Elements/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use function is_numeric;
use function preg_match;
use function str_contains;
use function str_starts_with;
use function stream_copy_to_stream;
use function strip_tags;
use function trim;
use function view;
Expand Down Expand Up @@ -283,7 +285,7 @@ public function values(): array
}

/**
* Display the value of this type of element - convert URLs to links
* Display the value of this type of element - convert URLs to links.
*
* @param string $value
*
Expand All @@ -300,6 +302,24 @@ protected function valueAutoLink(string $value): string
return e($canonical);
}

/**
* Display the value of this type of element - convert to URL.
*
* @param string $value
*
* @return string
*/
protected function valueLink(string $value): string
{
$canonical = $this->canonical($value);

if (str_starts_with($canonical, 'https://') || str_starts_with($canonical, 'http://')) {
return '<a dir="auto" href="' . e($canonical) . '">' . e($value) . '</a>';
}

return e($value);
}

/**
* Display the value of this type of element.
*
Expand Down
4 changes: 1 addition & 3 deletions app/Elements/AddressWebPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class AddressWebPage extends AbstractElement
*/
public function value(string $value, Tree $tree): string
{
$canonical = $this->canonical($value);

return '<a dir="auto" href="' . e($canonical) . '">' . e($canonical) . '</a>';
return $this->valueLink($value);
}
}
2 changes: 1 addition & 1 deletion app/Elements/MultimediaFileReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public function canonical(string $value): string
*/
public function value(string $value, Tree $tree): string
{
return $this->valueAutoLink($value);
return $this->valueLink($value);
}
}
2 changes: 2 additions & 0 deletions app/Elements/WhereWithinSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Fisharebest\Webtrees\Elements;

use Fisharebest\Webtrees\Http\RequestHandlers\AutoCompleteCitation;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Tree;

use function e;
Expand Down Expand Up @@ -63,6 +64,7 @@ public function edit(string $id, string $name, string $value, Tree $tree): strin
*/
public function value(string $value, Tree $tree): string
{
return strip_tags(Registry::markdownFactory()->autolink()->convertToHtml($value), ['a']);
return $this->valueAutoLink($value);
}
}

0 comments on commit cef4fcc

Please sign in to comment.