-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display problems #1470
Comments
Yes, that's it! It seems that smarty 3 transforms a line break into a line feed (
the generated code: |
I've done some research and the problem is with the file: |
Okay, I understand the problem. I used mambax7's file here: |
Try this code: protected function makeClickableCallbackEmailAddress($match)
{
$email = $match[2]; // Extract the email address
return $match[1] . '<a href="mailto:' . htmlspecialchars($email, ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($email, ENT_QUOTES, 'UTF-8') . '</a>';
}
public function makeClickable($text) {
// Decode HTML entities
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
// Convert line breaks and multiple spaces to a single space
$text = preg_replace('/[\n\s]+/', ' ', $text);
// Convert email addresses into clickable mailto links
$pattern = "/(^|[\s\n]|<br\s*\/?>)([-_a-z0-9\'+*$^&%=~!?{}]+(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*@[-a-z0-9.]+\.[a-z]{2,6})/i";
$text = preg_replace_callback($pattern, [$this, 'makeClickableCallbackEmailAddress'], $text);
// Convert URLs into clickable links, allowing for angle brackets, file paths, and custom protocols
$pattern = "/(?:\s|^|[\(\[\{>])(<)?((https?:\/\/|s?ftp:\/\/|file:\/\/|custom:\/\/|www\.)[^\s<>\(\)\[\]]+[^\s<>\(\)\[\]\.,!\"'\(\)\[\]{}<>])(?<![\.,!\"'\(\)\[\]{}])/";
$text = preg_replace_callback(
$pattern,
function ($matches) {
$url = $matches[2];
$prefix = $matches[0][0] ?? ''; // Get the prefix character (space, bracket, etc.)
$openingBracket = $matches[1] ?? ''; // Check for the opening angle bracket
// Ensure the URL is not a javascript: URL
if (stripos($url, 'javascript:') === 0) {
return $matches[0];
}
// Add http prefix if missing
if (strpos($url, 'www.') === 0) {
$url = "http://" . $url;
}
// Allow only specific protocols
$allowedProtocols = ['http://', 'https://', 'ftp://', 'sftp://', 'file://', 'custom://'];
$protocolAllowed = false;
foreach ($allowedProtocols as $protocol) {
if (strpos($url, $protocol) === 0) {
$protocolAllowed = true;
break;
}
}
if (!$protocolAllowed) {
return $matches[0];
}
// Check if the URL is already inside an anchor tag, specifically looking for href attribute
if (!preg_match('#<a\s[^>]*href\s*=\s*(["\'])' . preg_quote($url, '/') . '\\1[^>]*>#i', $url)) { // <-- Change here!
$relAttr = (strpos($url, 'ftp://') === 0 || strpos($url, 'sftp://') === 0 || strpos($url, 'file://') === 0 || strpos($url, 'custom://') === 0) ? 'external' : 'external noopener nofollow';
return $prefix . $openingBracket . '<a href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" target="_blank" rel="' . $relAttr . '">' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '</a>';
}
return $matches[0]; // Return the original match if it's already an anchor tag
},
$text
);
return $text;
} and let me know if it works |
It works too! |
If it works, can you close it? |
The switch to smarty 3 on the monxoops.fr website is not going very well. On this site, our articles and tutorials are formatted using html.
For example, this page:
https://www.monxoops.fr/modules/xmtutorial/tutorial.php?tutorial_id=19&page_id=100#page_page
Before, the display was:
And now:
I have the impression that it's a problem in the interpretation of line breaks.
It's a major problem.
The text was updated successfully, but these errors were encountered: