Skip to content
Snippets Groups Projects
Commit e7fd6a5e authored by Nikolay Grachev's avatar Nikolay Grachev
Browse files

Issue #3288416: add D10 support, drop D8, code style improvements

parent feed80aa
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,7 @@ name: MailGo
description: Module implements MailGo library behaviour.
package: Filters
type: module
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9 || ^10
configure: mailgo.global_config_form
dependencies:
- drupal:link
- drupal:filter
- drupal:path
- drupal:text
libraries:
- mailgo/mailgo
......@@ -13,6 +13,12 @@ use Psr\Container\ContainerInterface;
*/
class MailGoManager {
const EMAIL_REGEX = "/(((?<!\"|')(?<!mailto:)[a-z0-9_\-\.]+)@(([a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?)(?!\"|'|<\/a)))/i";
const PHONE_REGEX = "/((?<!\"|')(?<!tel:|callto:)\+\d{1,3}[\d\s-]{7,}(?!\"|'|<\/a))/";
const MAILTO_LINK_REGEX = "/<a(?:.*)href=(?:\"|')mailto:(.+)(?:\"|')(?:.*)>(.+)<\/a>/Ui";
/**
* Module config.
*
......@@ -77,11 +83,10 @@ class MailGoManager {
* Processed text
*/
public function processEmailsInText(string $text, $noSpam = FALSE) {
$regex = "/(((?<!\"|')(?<!mailto:)[a-z0-9_\-\.]+)@(([a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?)(?!\"|'|<\/a)))/i";
$replace = $noSpam
? "<a href=\"#mailgo\" data-address=\"$2\" data-domain=\"$3\">$1</a>"
: "<a href=\"mailto:$1\">$1</a>";
return preg_replace($regex, $replace, $text);
return preg_replace(self::EMAIL_REGEX, $replace, $text);
}
/**
......@@ -94,9 +99,8 @@ class MailGoManager {
* Processed text
*/
public function processPhonesInText(string $text) {
$regex = "/((?<!\"|')(?<!tel:|callto:)\+\d{1,3}[\d\s-]{7,}(?!\"|'|<\/a))/";
$replace = "<a href=\"tel:$1\">$1</a>";
return preg_replace($regex, $replace, $text);
return preg_replace(self::PHONE_REGEX, $replace, $text);
}
/**
......@@ -122,8 +126,7 @@ class MailGoManager {
* Processed text
*/
public function stripMailto(string $text) {
$regex = "/<a(?:.*)href=(?:\"|')mailto:(.+)(?:\"|')(?:.*)>(.+)<\/a>/Ui";
return preg_replace($regex, "$1", $text);
return preg_replace(self::MAILTO_LINK_REGEX, "$1", $text);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment