?
avatar ggppdk
ggppdk
28 Sep 2014

Steps to reproduce the issue

I am not sure if this can be easily reproduced,
but it is clear that it is very much possible, it was reported in FLEXIcontent forums after upgrading to J2.5.25

  1. Display the same article twice in same page
  2. the email cloak plugin will insert,the second time, the same HTML tag id, resulting in not proper cloacking of the second email

Expected result

Expected would be to have unique HTML tag ids

Actual result

non-unique HTML tag ids

System information (as much as possible)

J2.5.25 / J3.3.4
emailcloak plugin triggered by FLEXIcontent component

Additional comments

-- Maybe instead of this code (class JHtmlEmail, function cloak()):

$rand = rand(1, 100000);
$replacement = '' ...

-- We can use:

static $rand = null;
if ($rand === null) $rand = rand(1, 100000); // initialize to random
$rand = $rand + 1; // now give unique IDs
$replacement = '' ...

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
4.00

avatar ggppdk ggppdk - open - 28 Sep 2014
avatar zero-24
zero-24 - comment - 28 Sep 2014

thanks for your report here @ggppdk

Can you send your changes as pull request against the staging and 2.5.x branche?

If you need help see here: http://docs.joomla.org/Using_the_Github_UI_to_Make_Pull_Requests

Thanks :+1:

avatar ggppdk
ggppdk - comment - 28 Sep 2014

Hello, will do during next couple of days

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar zero-24
zero-24 - comment - 28 Sep 2014

thanks @ggppdk :+1: Please link it back here if you ready so we can close here and discuss on your PR.

avatar ggppdk
ggppdk - comment - 29 Sep 2014

Hello

my suggested fix will guarantee a unique HTML tag ID (in some very rare cases it could happen),

but the problem is a little different
after looking at it more, this is what is happening:

  1. trigger emailcloack on some text with emails,
  2. output the text twice, in 2 places inside your web-page
  3. the cloaking will not work properly on second text

i will need to find some time to test more, confirm the above, and suggest some fix for this, or someone else can fix it

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar VNiemi
VNiemi - comment - 29 Sep 2014

Wouldn't that be a caching issue? I mean the most obvious way for the same content on the same page within the same component to have the same id would be for the component to cache the content and reuse it for the second appearance. Do you have any way of checking if that is the case? Say a page where it happens and you can check if the ids change when you reload the page? (A cache would be meant to save work across reloads and would reuse the same ids.)
Also I don't see the random number generator having any inputs for article id or the email link, so if it was by weak random number generator, it shouldn't make any difference if you have same content twice on the same page or not.



This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar ggppdk
ggppdk - comment - 29 Sep 2014

Hello,

not related to caching,
the plugin is not generating duplicate tag ids (although my above suggestion makes sure that it will never happen)

The problem is this:
-- we just print the article text twice, so the text/HTML is the same
to replicate the bug simply do (twice):

<?php echo $this->item->text; ?>
<?php echo $this->item->text; ?>

on second text you get: "This email address is being protected from spambots. You need JavaScript enabled to view it."

-- same for any other text on which you trigger the emailcloak plugin, it can not be used it places

-- result you cannot use the text in 2 places


This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar VNiemi
VNiemi - comment - 30 Sep 2014

I am not really familiar with the Joomla! API, but since you are using $this it looks to me like you are fetching the content once and then using it twice, meaning the content plugins would be ran only once. Essentially caching the content on the $this. The snippet is really too short to see the context, but the symptoms you describe would match. The solution would be to have a separate fetch for every use.

That said, I kind of agree that the script should be able to handle this, but since id attributes are supposed to be unique, that would really require switching to, for example, data-emailcloak attributes. Attribute values would encode the email link in obfuscated form and single script would then iterate thru all data-emailcloak attributes and do the proper replacements. This would actually be more efficient than the current system, but would require lots of work.

avatar ggppdk
ggppdk - comment - 30 Sep 2014

Hello

i am not sure that your suggestion is good,

triggering all content plugins twice on the long text (article descriptioni is usually a long text) in a category view with 100 articles is not performance wise

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar VNiemi
VNiemi - comment - 30 Sep 2014

Right. I think I am starting to understand your problem. Could you disable emailcloak for the content when requesting and then run it once for the combined content? This would not only solve the issue (if it is due to mismatch between fetches and uses), but also (slightly) improve performance.

Or you could simply add code that adds one to all emailcloak ids in the second use. Since the numbers in ids are random that should not be an issue. And since the id in the tag and script match, they would still match and work after adding one to the number. This would probably be easiest fix in your code.

That said, you probably have to do the "trigger twice", even if the issue is fixed for emailcloak, there is really no other way to make unknown content plugins users might be running in the future work correctly. Not saying problems are likely, but any content plugin that adds scripts can have issues when duplicated on a page. And you can't really predict if that is going to break anything.

avatar brianteeman brianteeman - change - 30 Sep 2014
Category Plugins
avatar VNiemi
VNiemi - comment - 3 Oct 2014

Just occurred to me... Would it be possible to add a call to .removeAttribute("id") to the JavaScript? If browsers do DOM correctly (no idea) that should work. In fact, unless browsers do some weird parallel tree building, there should be only one emailcloak id existing, briefly, at a time, as ids should, and the whole random number generation can be skipped for improved performance.

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4383.

avatar VNiemi
VNiemi - comment - 3 Oct 2014

On second thought, validators would still complain about duplicate ids.
But maybe using class would be possible?
No, you need the randoms to deal with nested email links (which shouldn't exist, but probably do...)

avatar ggppdk
ggppdk - comment - 3 Oct 2014

Hello exactly the emailcloak plugin should insert 1 unique CSS class per email encountered instead of a unique ID, and the JS selector code should match all occurrences of the class

avatar VNiemi
VNiemi - comment - 3 Oct 2014

No, the idea was that if the DOM happens correctly, only one (or zero) of the many identical class (or id) instances ever exist in the DOM at any time. Basically the class would be removed by the coupled script before the next class instance can be added. And since only one instance of the class would ever exist at any time, the script would recover the correct link despite searching for a class with several instances in the source code.
I think it SHOULD work, and if it did, it would solve your issue, but... I am actually sick at home so I REALLY don't feel like testing it.

avatar brianteeman brianteeman - change - 3 Jan 2015
Labels Added: ?
avatar brianteeman
brianteeman - comment - 14 Jan 2015

Is this still an issue in joomla or is it specific to flexicontent?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4383.

avatar brianteeman brianteeman - change - 14 Jan 2015
Status New Information Required
avatar ggppdk
ggppdk - comment - 14 Jan 2015

Hello, no it is not related to flexicontent,

also i made a correction to my initial posting,
the problem is not with the random number as i thought,

--> the problem is that we use HTML tag id in JS to find the email to cloak
so you can not print the cloaked email (twice):
(some users may want to output the article text in 2 places)

echo $article_text;
...
echo $article_text;

--> because you will get a duplicate HTML tag_id

a solution would be to change code to look for all occurences of a classname

avatar zero-24
zero-24 - comment - 14 Jan 2015

@ggppdk can you provide code for it?

avatar brianteeman
brianteeman - comment - 14 Jan 2015

I have tested this by creating two articles in one category. Each article has the same email address entered twice.

I then created a blog view to display these articles. This means that the cloaked email is present 4 times in total on the same page

All 4 email addresses have unique ID

See the screeenshots

vq5a
mmuc

avatar zero-24
zero-24 - comment - 14 Jan 2015

@brianteeman
Yes this is ok. But if i understand @ggppdk right you can repoduce this by adding e.g. a content plugin that echo twice

<?php echo $this->item->text; ?>
<?php echo $this->item->text; ?>

So we have the same (prepared) text twice on the page. It is not the same (dublicate) email adress it is the same content :smile: IF you have the emails only the same email adress twice this will work ok and this is expected.

avatar brianteeman
brianteeman - comment - 14 Jan 2015

Is that a real world situation?

I also tested by publishing the article and the newsflash module on the
same page and the ID is still unique. Even with the article and two
identical newsflash modules the IS is still unique

On 14 January 2015 at 13:00, zero-24 notifications@github.com wrote:

@brianteeman https://github.com/brianteeman
Yes this is ok. But if i understand @ggppdk https://github.com/ggppdk
right you can repoduce this by adding e.g. a content plugin that echo twice

<?php echo $this->item->text; ?>
<?php echo $this->item->text; ?>

So we have the same (prepared) text twice on the page. It is not the same
(dublicate) email adress it is the same content [image: :smile:] IF you
have the emails only the same email adress twice this will work ok and this
is expected.


Reply to this email directly or view it on GitHub
#4383 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar zero-24
zero-24 - comment - 14 Jan 2015

Is that a real world situation?

I don't know but this is a behavior there the ID is not unique maybe @ggppdk can explain in with more details / real world examples.

avatar brianteeman
brianteeman - comment - 14 Jan 2015

I am just reluctant to introduce new code and therefore potential bugs just
because...

On 14 January 2015 at 13:10, zero-24 notifications@github.com wrote:

Is that a real world situation?

I don't know but this is a behavior there the ID is not unique maybe
@ggppdk https://github.com/ggppdk can explain in with more details / real
world examples.


Reply to this email directly or view it on GitHub
#4383 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar ggppdk
ggppdk - comment - 14 Jan 2015

please don't misunderstand me

i just "reported" or "identified" an issue, less common, yes i agree

it is not possible to use the cloacked email text in 2 places

-- a similar example -more common- example would be not being able to use an image twice in same page.

I don't say to fix or change something if it is not worth doing it, i can agree with Brian maybe this will not be supported or done in a future version

I could certainly provide a proper tested fix for this if i had more time,

or if it was a big problem for myself, i would certainly take time to make a pull request that utilizes a unique class name per email address instead of tag-id

Regards

avatar brianteeman
brianteeman - comment - 14 Jan 2015

it is not possible to use the cloacked email text in 2 places

But I showed that you can

On 14 January 2015 at 13:29, Georgios Papadakis notifications@github.com
wrote:

please don't misunderstand me

i just "reported" or "identified" an issue, less common, yes i agree

it is not possible to use the cloacked email text in 2 places

-- a similar example -more common- example would be not being able to use
an image twice in same page.

I don't say to fix or change something if it is not worth doing it, i can
agree with Brian maybe this will not be supported or done in a future
version

I could certainly provide a proper tested fix for this if i had more time,

or if it was a big problem for myself, i would certainly take time to make
a pull request that utilizes a unique class name per email address instead
of tag-id

Regards


Reply to this email directly or view it on GitHub
#4383 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar ggppdk
ggppdk - comment - 14 Jan 2015

Yes they are

but if you print them twice, you get same HTML tag id, and the email cloaking no longer works

avatar mbabker
mbabker - comment - 14 Jan 2015

If @zero-24 simple example is accurate, then the only way to duplicate this issue is if you're outputting the same object multiple times as each object that processed through the onContentPrepare event creates unique IDs. I think I'd close this as a known issue that won't be fixed; if you're outputting an object multiple times, you're going to get what is in that object multiple times.

avatar zero-24
zero-24 - comment - 14 Jan 2015

but if you print them twice,

print them twice mean not twice with the editor but twice with code like:

<?php echo $this->item->text; ?>
<?php echo $this->item->text; ?>
avatar zero-24
zero-24 - comment - 14 Jan 2015

if you're outputting an object multiple times, you're going to get what is in that object multiple times.

agree.

avatar ggppdk
ggppdk - comment - 14 Jan 2015

So we can accept this known issue:

if article text is used in 2 places, email cloaking will be work properly in 1 of them, and close this issue

avatar mbabker
mbabker - comment - 14 Jan 2015

Yes. If you really need to output the same data object twice, the only clean solution is to repeat all the steps that go into creating $this->item (using ContentViewArticle as an example) using a new variable so that you are again fetching the raw data and processing that data through each of the plugins.

avatar ggppdk
ggppdk - comment - 14 Jan 2015

That could be a solution, but you can not control what content plugins do:
-- e.g. some other 3rd party content plugin could be incrementing a counter, or adding something into the DB

so in some cases we will create a different problem,

in general (for future coding) if we can avoid designing like that item text will only be displayed once, then better do it

--> i mean in the cases that this is possible !
e.g. for email cloaking it could have been done, if author of the code was aware of this while writting the code

avatar brianteeman brianteeman - change - 14 Jan 2015
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2015-01-14 13:54:28
Closed_By brianteeman
avatar brianteeman brianteeman - close - 14 Jan 2015
avatar brianteeman
brianteeman - comment - 14 Jan 2015

Closing based on the comments above


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4383.

avatar SuperSonic45
SuperSonic45 - comment - 29 May 2015

I have the same issue.
I created custom HTML module with text including email address and publish it in position that defined in my template twice (in header and in footer).
Next i open front-end page (home, for example) and both email cloaked with the same id and i can see first email at the top, but instead of second email at the bottom i see text "This email address is being protected from spambots. You need JavaScript enabled to view it." (of course Javascript is on in my browser).


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4383.

avatar ggppdk
ggppdk - comment - 29 May 2015

You will need to create 2 different custom HTML modules (duplicating the contents). This should work.

Add a Comment

Login with GitHub to post a comment