Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Cleantalk/ApbctWP/ContactsEncoder/ContactsEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function runEncoding($content = '')
*/
public function modifyFormFieldDisplay($html, $field, $display_context, $post_id)
{
if (mb_strpos($html, 'mailto:') !== false) {
if (mb_stripos($html, 'mailto:') !== false) {
$html = html_entity_decode($html);
return $this->modifyContent($html);
}
Expand Down
29 changes: 17 additions & 12 deletions lib/Cleantalk/Common/ContactsEncoder/ContactsEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ class ContactsEncoder
const EMAIL_PATTERN = '[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+\.[A-Za-z]{2,}\b';
const EMAIL_PATTERN_DOMAIN_CATCHING = '[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+(\.[A-Za-z]{2,}\b)';
const PHONE_NUMBER = '\+\d{8,12}';
/**
* URI schemes are case-insensitive (RFC 3986). Clients often write Mailto:/Tel:.
*/
const MAILTO_SCHEME_PATTERN = '(?i:mailto):';
const TEL_SCHEME_PATTERN = '(?i:tel):';
const PHONE_NUMBERS_PATTERNS = [
'(tel:' . self::PHONE_NUMBER . ')', // tel:+XXXXXXXXXX
'(' . self::TEL_SCHEME_PATTERN . self::PHONE_NUMBER . ')', // tel:+XXXXXXXXXX
'([\+][\s-]?\(?\d[\d\s\-()]{7,}\d)', // +X XXX XXXXXXX, +X(XXX)XXXXX, etc.
'(\(\d{3}\)\s?\d{3}-\d{4})', // (XXX) XXX-XXXX, (XXX) XXX XXXX
'(\+\d{1,3}\.\d{1,3}\.((\d{3}\.\d{4})|\d{7})(?![\w.]))', // +X?.XX?.XXX.XXXX
Expand All @@ -63,17 +68,17 @@ class ContactsEncoder
protected $aria_regex;

/**
* @var string example: '/(mailto\:\b[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+\.[A-Za-z]{2,}\b)|(\b[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+(\.[A-Za-z]{2,}\b))/'
* @var string example: '/((?i:mailto):\b[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+\.[A-Za-z]{2,}\b)|(\b[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+(\.[A-Za-z]{2,}\b))/'
*/
protected $global_email_pattern;

/**
* @var string example: '/(tel:\+\d{8,12})|([\+][\s-]?\(?\d[\d\s\-()]{7,}\d)|(\(\d{3}\)\s?\d{3}-\d{4})|(\+\d{1,3}\.\d{1,3}\.((\d{3}\.\d{4})|\d{7})(?![\w.]))'/'
* @var string example: '/((?i:tel):\+\d{8,12})|([\+][\s-]?\(?\d[\d\s\-()]{7,}\d)|(\(\d{3}\)\s?\d{3}-\d{4})|(\+\d{1,3}\.\d{1,3}\.((\d{3}\.\d{4})|\d{7})(?![\w.]))/'
*/
protected $global_phones_pattern;

/**
* @var string example: '/mailto\:(\b[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+\.[A-Za-z]{2,})/'
* @var string example: '/(?i:mailto):(\b[_A-Za-z0-9-\.]+@[_A-Za-z0-9-\.]+\.[A-Za-z]{2,})/'
*/
protected $global_mailto_pattern;

Expand All @@ -83,7 +88,7 @@ class ContactsEncoder
protected $plain_email_pattern;

/**
* @var string example: '/tel:(\+\d{8,12})/'
* @var string example: '/(?i:tel):(\+\d{8,12})/'
* @ToDo Is this regexp is actual and right?
*/
protected $global_tel_pattern;
Expand Down Expand Up @@ -202,11 +207,11 @@ private function prepareRegularExpressions()
{
$this->aria_regex = self::ARIA_LABEL_PATTERN;

$this->global_email_pattern = '/(mailto\:\b' . self::EMAIL_PATTERN . ')|(\b' . self::EMAIL_PATTERN_DOMAIN_CATCHING . ')/';
$this->global_email_pattern = '/(' . self::MAILTO_SCHEME_PATTERN . '\b' . self::EMAIL_PATTERN . ')|(\b' . self::EMAIL_PATTERN_DOMAIN_CATCHING . ')/';
$this->global_phones_pattern = '/' . implode('|', self::PHONE_NUMBERS_PATTERNS) . '/';
$this->global_mailto_pattern = '/mailto\:(' . self::EMAIL_PATTERN . ')/';
$this->global_mailto_pattern = '/' . self::MAILTO_SCHEME_PATTERN . '(' . self::EMAIL_PATTERN . ')/';
$this->plain_email_pattern = '/(\b' . self::EMAIL_PATTERN . '\b)/';
$this->global_tel_pattern = '/tel:(' . self::PHONE_NUMBER . ')/';
$this->global_tel_pattern = '/' . self::TEL_SCHEME_PATTERN . '(' . self::PHONE_NUMBER . ')/';
}

/**
Expand Down Expand Up @@ -505,7 +510,7 @@ private function encodeMailtoLink($mailto_link_str)
}
}, $matches[1]);
}
$mailto_link_str = str_replace('mailto:', '', $mailto_link_str);
$mailto_link_str = preg_replace('/^mailto:/i', '', $mailto_link_str);
$encoded = $this->encoder->encodeString($mailto_link_str);

$text = isset($mailto_inner_text) ? $mailto_inner_text : $mailto_link_str;
Expand All @@ -525,17 +530,17 @@ private function encodeTelLink($tel_link_str)
// Get inner tag text and place it in $matches[1]
preg_match($this->global_tel_pattern, $tel_link_str, $matches);
if ( isset($matches[1]) ) {
$mailto_inner_text = preg_replace_callback('/' . self::PHONE_NUMBER . '/', function ($matches) {
$tel_inner_text = preg_replace_callback('/' . self::PHONE_NUMBER . '/', function ($matches) {
if (isset($matches[0])) {
$obfuscator = new Obfuscator();
return $obfuscator->processPhone($matches[0]);
}
}, $matches[1]);
}
$tel_link_str = str_replace('tel:', '', $tel_link_str);
$tel_link_str = preg_replace('/^tel:/i', '', $tel_link_str);
$encoded = $this->encoder->encodeString($tel_link_str);

$text = isset($mailto_inner_text) ? $mailto_inner_text : $tel_link_str;
$text = isset($tel_inner_text) ? $tel_inner_text : $tel_link_str;

return 'tel:' . $text . '" data-original-string="' . $encoded . '" title="' . htmlspecialchars($this->getTooltip(), ENT_QUOTES, 'UTF-8');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ContactsEncoderHelper
*/
public function isMailto($string)
{
return strpos($string, 'mailto:') !== false;
return stripos($string, 'mailto:') !== false;
}

/**
Expand All @@ -52,7 +52,7 @@ public function isMailto($string)
*/
public function isTelTag($string)
{
return strpos($string, 'tel:') !== false;
return stripos($string, 'tel:') !== false;
}

/**
Expand Down
Loading