- Posts: 132
COMMUNITY FORUM
Cloaking email address as extra field value
- Thomas Thrane
- Topic Author
- Offline
- Premium Member
Less
More
5 years 6 months ago - 5 years 6 months ago #172094
by Thomas Thrane
Cloaking email address as extra field value was created by Thomas Thrane
Last edit: 5 years 6 months ago by Thomas Thrane.
Please Log in or Create an account to join the conversation.
- Thomas Thrane
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
5 years 6 months ago #172098
by Thomas Thrane
Replied by Thomas Thrane on topic Cloaking email address as extra field value
But i see now that the dev version broke a thing ...
I use Regular Labs Email protector and I enter email adresses ind Extra Fields, but they don't work right now:
Peter from Regular Labs fixed it the first time, but he says it's something with the output of extra fields that aren't working correctly?
Se here: www.regularlabs.com/forum/emailprotector/45333-use-an-email-address-from-custom-field-inside-a-button-on-a-template-override-breaks-the-button#86849
And the issue on my site:
www.sawo.dk/da/om-sawo/ledige-job
www.sawo.dk/da/om-sawo/ledige-job/smed-reparator-opbygger-sawo-humlebaek
Hope you can help - it worked before the dev version was installed ...
I use Regular Labs Email protector and I enter email adresses ind Extra Fields, but they don't work right now:
Peter from Regular Labs fixed it the first time, but he says it's something with the output of extra fields that aren't working correctly?
Se here: www.regularlabs.com/forum/emailprotector/45333-use-an-email-address-from-custom-field-inside-a-button-on-a-template-override-breaks-the-button#86849
And the issue on my site:
www.sawo.dk/da/om-sawo/ledige-job
www.sawo.dk/da/om-sawo/ledige-job/smed-reparator-opbygger-sawo-humlebaek
Hope you can help - it worked before the dev version was installed ...
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
5 years 6 months ago #172103
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Cloaking email address as extra field value
The unstyled buttons in the item edit form (and the category edit form) are part of some last-minute UI changes. They will be sorted until v2.10 is released officially.
As for the 2nd issue, I strongly disagree with Peter (and I certainly don't like his tone). His comment "I'm not sure I appreciate and want to keep having to work around issues K2 caused when it changes things which are already non-Joomla standard ways of doing things" is insulting and it's also confusing. Well, boo-hoo. We deal with third party extensions all the time. We don't go trashing the other developers, even if they're bad. Cause in the end, what matters is that the user/customer gets the job done.
I mean, is there like a "non-Joomla standard ways of doing things" for outputting text in a document? If he didn't understand the issue in the first place, he should say so.
Now, if you want to have your emails parsed by his plugin - which BTW should be smarter to perform a regex at the whole <a> element - you should probably re-order that plugin last. Updating K2 may have changed the order of some plugins. Worse case scenario, if you use a link type extra field, switch to plain text field. That should make it simpler for the plugin to grab the email address and convert it to an obfuscated link.
As for the 2nd issue, I strongly disagree with Peter (and I certainly don't like his tone). His comment "I'm not sure I appreciate and want to keep having to work around issues K2 caused when it changes things which are already non-Joomla standard ways of doing things" is insulting and it's also confusing. Well, boo-hoo. We deal with third party extensions all the time. We don't go trashing the other developers, even if they're bad. Cause in the end, what matters is that the user/customer gets the job done.
I mean, is there like a "non-Joomla standard ways of doing things" for outputting text in a document? If he didn't understand the issue in the first place, he should say so.
Now, if you want to have your emails parsed by his plugin - which BTW should be smarter to perform a regex at the whole <a> element - you should probably re-order that plugin last. Updating K2 may have changed the order of some plugins. Worse case scenario, if you use a link type extra field, switch to plain text field. That should make it simpler for the plugin to grab the email address and convert it to an obfuscated link.
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Thomas Thrane
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
5 years 6 months ago #172141
by Thomas Thrane
Replied by Thomas Thrane on topic Cloaking email address as extra field value
Hi Fotis
NP regarding the styling :-)
As for the 2nd issue, I apologize for the tone :-(
I have tried to reorder the plugin last, but same result. And the field in K2 is already a plain text field with nothing more than the email.
I'm sorry for this, I just don't know who to reach out to to get this fixed ...
Kind regards
Thomas
NP regarding the styling :-)
As for the 2nd issue, I apologize for the tone :-(
I have tried to reorder the plugin last, but same result. And the field in K2 is already a plain text field with nothing more than the email.
I'm sorry for this, I just don't know who to reach out to to get this fixed ...
Kind regards
Thomas
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
5 years 6 months ago - 5 years 6 months ago #172147
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Cloaking email address as extra field value
No need to apologize for Peter's tone...
Looking at the code of his plugin, although it's a system plugin, it basically executes in "content" events. K2 outputs the extra fields as separate data objects and the plugin events that his plugin uses can't access these data objects. That is not a K2 limitation.
If the plugin can't parse emails on the page's output (which would differentiate it from Joomla's built in cloaking plugin), then you can perform a simple override in how extra fields are rendered inside item.php.
If you don't use overrides already for K2, have a look at this: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
If you already have an item.php override in place for the "item" view, then simply change your extra fields loop from the default:
to (behold the huge changes required to cloak an email):
We built K2 to make sense, not to make people's lives harder.
Looking at the code of his plugin, although it's a system plugin, it basically executes in "content" events. K2 outputs the extra fields as separate data objects and the plugin events that his plugin uses can't access these data objects. That is not a K2 limitation.
If the plugin can't parse emails on the page's output (which would differentiate it from Joomla's built in cloaking plugin), then you can perform a simple override in how extra fields are rendered inside item.php.
If you don't use overrides already for K2, have a look at this: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
If you already have an item.php override in place for the "item" view, then simply change your extra fields loop from the default:
<?php if($this->item->params->get('itemExtraFields') && isset($this->item->extra_fields) && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
<ul>
<?php foreach ($this->item->extra_fields as $key => $extraField): ?>
<?php if($extraField->value != ''): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?> alias<?php echo ucfirst($extraField->alias); ?>">
<?php if($extraField->type == 'header'): ?>
<h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
<?php else: ?>
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
to (behold the huge changes required to cloak an email):
<?php if($this->item->params->get('itemExtraFields') && isset($this->item->extra_fields) && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
<ul>
<?php foreach ($this->item->extra_fields as $key => $extraField): ?>
<?php if($extraField->value != ''): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?> alias<?php echo ucfirst($extraField->alias); ?>">
<?php if($extraField->type == 'header'): ?>
<h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
<?php else: ?>
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<?php if($extraField->type == 'textfield'): ?>
<?php
// if the extra field type is "textfield" and the value of it validates as an email address,
// then process the field value to a cloaked email link
if (filter_var($extraField->value, FILTER_VALIDATE_EMAIL)) {
echo JHtml::_('email.cloak', $extraField->value);
}
?>
<?php else: ?>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
We built K2 to make sense, not to make people's lives harder.
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 5 years 6 months ago by JoomlaWorks.
Please Log in or Create an account to join the conversation.
- Thomas Thrane
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
5 years 6 months ago #172148
by Thomas Thrane
Replied by Thomas Thrane on topic Cloaking email address as extra field value
I actually had a programmer made a way to call extra fields where I want them in an override.
I place this at the top:
<?php
/**
* @version 2.9.x
* @package K2
* @author JoomlaWorks www.joomlaworks.net
* @copyright Copyright (c) 2006 - 2018 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined('_JEXEC') or die;
?>
<!-- START: Call to prepare extra fields -->
<?php
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
<!-- END: Call to prepare extra fields -->
And then this where I call the email field:
<?php if(isset($extrafields[28])) :?>
<a class="buttonLink" href="mailto:<?php echo $extrafields[28];?>"><?php echo JText::_('SAWO_SEND_APPLICATION'); ?> <?php echo JText::_('SAWO_TO'); ?> <?php echo $extrafields[28];?><i class="fas fa-paper-plane"></i></a>
<?php endif; ?>
Does this make sense to you?
I place this at the top:
<?php
/**
* @version 2.9.x
* @package K2
* @author JoomlaWorks www.joomlaworks.net
* @copyright Copyright (c) 2006 - 2018 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined('_JEXEC') or die;
?>
<!-- START: Call to prepare extra fields -->
<?php
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
<!-- END: Call to prepare extra fields -->
And then this where I call the email field:
<?php if(isset($extrafields[28])) :?>
<a class="buttonLink" href="mailto:<?php echo $extrafields[28];?>"><?php echo JText::_('SAWO_SEND_APPLICATION'); ?> <?php echo JText::_('SAWO_TO'); ?> <?php echo $extrafields[28];?><i class="fas fa-paper-plane"></i></a>
<?php endif; ?>
Does this make sense to you?
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
5 years 6 months ago #172149
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Cloaking email address as extra field value
If you need to call a specific extra field, K2 already provides an easier way: getk2.org/documentation/tips-a-tricks/2667-display-single-extra-fields-anywhere-in-your-k2-content
In that case, you would do something like:...where you want the email to appear cloaked. Make sure to swap "EXTRAFIELD_ALIAS_HERE" with the actual extra field "alias".
In that case, you would do something like:
<?php
$email = $this->item->extraFields->EXTRAFIELD_ALIAS_HERE->value;
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo JHtml::_('email.cloak', $email);
}
?>
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
5 years 6 months ago #172150
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Cloaking email address as extra field value
And keep in mind, "echo JHtml::_('email.cloak', $email);" actually prints the entire link (reference: docs.joomla.org/How_to_cloak_email_addresses).
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Thomas Thrane
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
5 years 6 months ago #172151
by Thomas Thrane
Replied by Thomas Thrane on topic Cloaking email address as extra field value
Thanks, I'll have a look at that method and see if I can get the same output as before :-)
Please Log in or Create an account to join the conversation.
- Thomas Thrane
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
5 years 6 months ago #172153
by Thomas Thrane
Replied by Thomas Thrane on topic Cloaking email address as extra field value
Seems like this
<a class="buttonLink" href="mailto:<?php echo $this->item->extraFields->Email->value; ?>"><?php echo JText::_('SAWO_SEND_APPLICATION'); ?> <?php echo JText::_('SAWO_TO'); ?> <?php echo $this->item->extraFields->Email->value; ?><i class="fas fa-paper-plane"></i></a>
Gives the same result like before. I'm confused now ...
<a class="buttonLink" href="mailto:<?php echo $this->item->extraFields->Email->value; ?>"><?php echo JText::_('SAWO_SEND_APPLICATION'); ?> <?php echo JText::_('SAWO_TO'); ?> <?php echo $this->item->extraFields->Email->value; ?><i class="fas fa-paper-plane"></i></a>
Gives the same result like before. I'm confused now ...
Please Log in or Create an account to join the conversation.