Open Graph - Title showing html codes

Phoca plugins - support for all Phoca plugins except Phoca Gallery plugins
User avatar
componentegd
Phoca Member
Phoca Member
Posts: 21
Joined: 31 Mar 2015, 22:39
Location: Rio de janeiro - Brazil
Contact:

Open Graph - Title showing html codes

Post by componentegd »

Hi!
In a article with title containing --> " <-- it is show the code &quot.

Can anyone help me? Jan?

Here is a link to test.
http://www.jornaljbp.com.br/nacional/96 ... u-oposicao
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Open Graph - Title showing html codes

Post by Jan »

Hi, it is a protection against the displaying "bad" characters (include html tags) in code (characters which can break the html code).

See: plugins/content/phocaopengraph/phocaopengraph.php

Code: Select all

public static function renderTag($name, $value, $type = 1) {
		$document 	= JFactory::getDocument();
		if ($type == 1) {
			$document->setMetadata(htmlspecialchars($name), htmlspecialchars($value));
		} else {
			$document->addCustomTag('<meta property="'.htmlspecialchars($name).'" content="' . htmlspecialchars($value) . '" />');
		}
	}
There is used htmlspecialchars function, but you can remove it (not recommended) or use only strip_tags function, etc. But if the " will be not handled, you will get html errors, see example:

User's title: Hello "

the tag: <meta name="og:title" content="Hello"" /> which then breaks the html.

Jan
If you find Phoca extensions useful, please support the project
User avatar
componentegd
Phoca Member
Phoca Member
Posts: 21
Joined: 31 Mar 2015, 22:39
Location: Rio de janeiro - Brazil
Contact:

Re: Open Graph - Title showing html codes

Post by componentegd »

Very well explained, my friend!
I got it. Well, seems that I have to explain my client about the use of the quotes.
Thanks very much for the explanation!
You're the best, Jan.
Jan wrote:Hi, it is a protection against the displaying "bad" characters (include html tags) in code (characters which can break the html code).

See: plugins/content/phocaopengraph/phocaopengraph.php

Code: Select all

public static function renderTag($name, $value, $type = 1) {
		$document 	= JFactory::getDocument();
		if ($type == 1) {
			$document->setMetadata(htmlspecialchars($name), htmlspecialchars($value));
		} else {
			$document->addCustomTag('<meta property="'.htmlspecialchars($name).'" content="' . htmlspecialchars($value) . '" />');
		}
	}
There is used htmlspecialchars function, but you can remove it (not recommended) or use only strip_tags function, etc. But if the " will be not handled, you will get html errors, see example:

User's title: Hello "

the tag: <meta name="og:title" content="Hello"" /> which then breaks the html.

Jan
User avatar
componentegd
Phoca Member
Phoca Member
Posts: 21
Joined: 31 Mar 2015, 22:39
Location: Rio de janeiro - Brazil
Contact:

Re: Open Graph - Title showing html codes

Post by componentegd »

Simple quote works fine. I spoke to my client about using simple quotes and it's fine for him.
Thanks again, Jan.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Open Graph - Title showing html codes

Post by Jan »

Ok, great to hear it.

Jan
If you find Phoca extensions useful, please support the project
oorzaak
Phoca Member
Phoca Member
Posts: 47
Joined: 11 Dec 2008, 00:37

Re: Open Graph - Title showing html codes

Post by oorzaak »

Hi,

I had the same issue with titles containing an ampersand &

I understand that some characters may break the code but I tried replacing the & code by using NoNumber's ReReplacer. It seems to work ok. However I am still a bit confused about how the OpenGraph tags sometimes work. For instance:

After changing the OG title tag using ReReplacer I used the Facebook debugger in order to clear the Facebook cache (see: https://developers.facebook.com/tools/debug/og/object/). After clearing I could share the article with my own Facebook account and the title showed as I expected. However, I also expected the cache clearing to be reflected on the Facebook timeline of my customer, who shared the page before I installed ReReplacer (and while sharing discovered this issue in the first place). On their account the html is still showing. So there are two versions of the same page out there on Facebook now?

It becomes even more confusing when, on the Facebook debugger page, I click on the link "See exactly what our scraper sees for your URL". This renders a page source in which my title shows with & again. And the description, in which I do not run any replacements, even shows this character as &amp;
Yet when viewing the shared item on Facebook there are no issues with this character in the description.

Maybe this forum is not the place to solve Facebook's mysteries, yet if anyone could clarify this I'd be grateful.


Kind regards, Frits
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Open Graph - Title showing html codes

Post by Jan »

Hi, :-) unfortunately I have no experiences regarding this, so I am not the one who can clarify it :-(

Jan
If you find Phoca extensions useful, please support the project
Post Reply