WBCE / WBCE_CMS

Core package of WBCE CMS. This package includes the core and the default addons. Visit https://wbce.org (DE) or https://wbce-cms.org (EN) to learn more or to join the WBCE CMS community.
https://wbce-cms.org
GNU General Public License v2.0
32 stars 22 forks source link

OPF email filter removes fontawesome class from mailto links #515

Closed gchriz closed 2 years ago

gchriz commented 2 years ago

When using email-address encryption by _mod_opfemail the (optional) class attribute is removed from the resulting mailto link.

But only if the class contains/uses a fontawesome-class, for example <a href="mailto:....." class="icon fa-envelope-o">, to display an envelope icon.

For example the template _caminarwbce uses it in its footer line.

Checking modules/mod_opf_email/filter.php reveals this:

                // build the encrypted Javascript mailto link
                if (strpos($class_attr, 'fa-') == false) {
                    $mailto_link  = "<a {$class_attr}{$title_attr}{$id_attr}{$style_attr}href=\"javascript:mdcr('$encrypted_email','$email_subject')\">" .$match[5] ."</a>";
                } else {
                    $mailto_link  = "<a {$title_attr}{$id_attr}{$style_attr}href=\"javascript:mdcr('$encrypted_email','$email_subject')\">" .$match[5] ."</a>";
                }
                return $mailto_link;

That if() construct was introduced on May 31, 2021 in commit 907404dd8119bf19141cee7d337a8795479b10c6

IMHO it is not correct. It suppresses the complete class attribute if it contains any fontawesome class?!?! But why?

I reversed it by switching false to true. But the whole reason for the if() isn't clear to me. So I might be wrong.

At least my resulting mailto links have their icons back now. ;-)

instantflorian commented 2 years ago

The commit should fix the issue that the FontAwesome symbol appears twice if email enryption is active. As far as I can see, it works as expected. mailto-fix

gchriz commented 2 years ago

Ah, I see.

For example the template caminar-wbce uses this line:

<a href="mailto:mail@example.com" class="icon fa-envelope-o"><span class="label">Email</span></a>

Since there is only a single reference to the fa-envelope-o and that one gets removed, it's gone completely.

So I need to add another class attribute elsewhere like in your example above...

Or the email filter script might count the occurrences of FontAwesome things within the .. and only remove them when there are more than one. Or something like this.

instantflorian commented 2 years ago

This <a href="mailto:mail@example.com" class="icon fa-envelope-o"><span class="label">Email</span></a> is not the by FontAwesome recommended way how to build an email link. Please refer to https://fontawesome.com/v4/examples/ to see how a FA link usually should look like, because that is the only way to avoid issues with the filter.

gchriz commented 2 years ago

O.k. Then I'll fix the template locally.

Thank you for the explanations!

I didn't expect to become a template programmer, though! ;-) If I find a place to report my fixes to template caminar-wbce I'll post them there.