aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-03-26 17:23:43 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-03-26 17:23:43 +0100
commitcfd04f2ecedf57f01cbb3c47a3ee0578d07ccec4 (patch)
treed171e595752e5b4503850085379a14e831bc170e /app/class
parent199694807496e98c47f6069eb3db6d925332968c (diff)
parenta17b7fc6aa87341c51e68baf3f217f709eb817d7 (diff)
downloadwcms-cfd04f2ecedf57f01cbb3c47a3ee0578d07ccec4.tar.gz
wcms-cfd04f2ecedf57f01cbb3c47a3ee0578d07ccec4.zip
Merge branch 'master' of https://github.com/vincent-peugnet/wcms
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Modelrender.php21
1 files changed, 19 insertions, 2 deletions
diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php
index 638f3e3..bb6cf03 100644
--- a/app/class/Modelrender.php
+++ b/app/class/Modelrender.php
@@ -348,7 +348,9 @@ class Modelrender extends Modelpage
$text = $this->desctitle($text, $this->page->description(), $this->page->title());
- $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text);
+ $text = str_replace('href="http', "class=\"external\" $this->externallinkblank href=\"http", $text);
+
+ $text = $this->shortenurl($text);
$text = $this->autourl($text);
@@ -366,10 +368,25 @@ class Modelrender extends Modelpage
return $text;
}
+ /**
+ * Shorten the urls of links whose content equals the href.
+ *
+ * @param string $text the page text as html
+ */
+ public function shortenurl(string $text): string
+ {
+ $text = preg_replace('#<a(.*href="(https?:\/\/(.+))".*)>\2</a>#', "<a$1>$3</a>", $text);
+ return $text;
+ }
+
public function autourl($text)
{
- $text = preg_replace('#( |\R|>)(https?:\/\/((\S+)\.([^< ]+)))#', '$1<a href="$2" class="external" '. $this->externallinkblank .'>$3</a>', $text);
+ $text = preg_replace(
+ '#( |\R|(>)|(&lt;))(https?:\/\/(\S+\.[^< ]+))(((?(3)&gt;|))(?(2)</[^a]|))#',
+ "$1<a href=\"$4\" class=\"external\" $this->externallinkblank>$4</a>$6",
+ $text
+ );
return $text;
}