mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 15:07:02 +03:00
Find links in html messages
This commit is contained in:
parent
d50c068a3d
commit
041bd1ae1b
6 changed files with 388 additions and 335 deletions
|
|
@ -126,13 +126,8 @@ class LinkFinder
|
|||
*/
|
||||
public function UseDefaultWrappers($bAddTargetBlank = false)
|
||||
{
|
||||
$this->fLinkWrapper = function ($sLink, $bShortLink = false) use ($bAddTargetBlank) {
|
||||
|
||||
if ($bShortLink && \in_array(\strtolower($sLink), array('asp.net', 'vb.net', 'mailbee.net')))
|
||||
{
|
||||
return $sLink;
|
||||
}
|
||||
|
||||
$this->fLinkWrapper = function ($sLink) use ($bAddTargetBlank) {
|
||||
|
||||
$sNameLink = $sLink;
|
||||
if (!\preg_match('/^[a-z]{3,5}\:\/\//i', \ltrim($sLink)))
|
||||
{
|
||||
|
|
@ -151,11 +146,10 @@ class LinkFinder
|
|||
|
||||
/**
|
||||
* @param bool $bUseHtmlSpecialChars = true
|
||||
* @param bool $bFindShortLinks = true
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function CompileText($bUseHtmlSpecialChars = true, $bFindShortLinks = true)
|
||||
public function CompileText($bUseHtmlSpecialChars = true)
|
||||
{
|
||||
$sText = \substr($this->sText, 0, $this->iOptimizationLimit);
|
||||
$sSubText = \substr($this->sText, $this->iOptimizationLimit);
|
||||
|
|
@ -171,11 +165,6 @@ class LinkFinder
|
|||
$sText = $this->findMails($sText, $this->fMailWrapper);
|
||||
}
|
||||
|
||||
if ($bFindShortLinks && null !== $this->fLinkWrapper && \is_callable($this->fLinkWrapper))
|
||||
{
|
||||
$sText = $this->findShortLinks($sText, $this->fLinkWrapper);
|
||||
}
|
||||
|
||||
$sResult = '';
|
||||
if ($bUseHtmlSpecialChars)
|
||||
{
|
||||
|
|
@ -259,46 +248,6 @@ class LinkFinder
|
|||
return $sText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sText
|
||||
* @param mixed $fWrapper
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function findShortLinks($sText, $fWrapper)
|
||||
{
|
||||
$sPattern = '/([a-z0-9-\.]+\.(?:com|org|net|ru))([^a-z0-9-\.])/i';
|
||||
|
||||
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
|
||||
$sText = \preg_replace_callback($sPattern, function ($aMatch) use ($fWrapper, &$aPrepearPlainStringUrls) {
|
||||
|
||||
if (\is_array($aMatch) && 2 < \count($aMatch) && isset($aMatch[1]) && 0 < \strlen($aMatch[1]))
|
||||
{
|
||||
$sLinkWithWrap = \call_user_func_array($fWrapper, array($aMatch[1], true));
|
||||
if (\is_string($sLinkWithWrap))
|
||||
{
|
||||
$aPrepearPlainStringUrls[] = \stripslashes($sLinkWithWrap);
|
||||
return \MailSo\Base\LinkFinder::OPEN_LINK.
|
||||
(\count($aPrepearPlainStringUrls) - 1).
|
||||
\MailSo\Base\LinkFinder::CLOSE_LINK.
|
||||
$aMatch[2];
|
||||
}
|
||||
|
||||
return $aMatch[0];
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}, $sText);
|
||||
|
||||
if (0 < \count($aPrepearPlainStringUrls))
|
||||
{
|
||||
$this->aPrepearPlainStringUrls = $aPrepearPlainStringUrls;
|
||||
}
|
||||
|
||||
return $sText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sText
|
||||
* @param mixed $fWrapper
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue