external links

Modifications for phpBB3.
Try the Mods here and share Your own Mods
Forum rules
You dont have to use ModX or make your mod AutoMod compatible. A simple textfile is fine
But if you post Mods here You also have to give support

external links

Post by RMcGirr83 »

It is due to now using this DOMXPath instead of curl due to nubs posting a gazillion links in one post.

external links

Post by Stoker »

http://www.thostrupvejens-traepillesalg.dk/

Code: Select all

<title>Træpiller, Træpillesalg, Miljøvenlig træpiller og Briketter i Midtjylland, Århus, Silkeborg, Hadsten, Hinnerup, Viborg, Kjellerup, Østjylland,Randers,kjellerup,pillebrændeovn,pilleovn, - www.thostrupvejens-traepillesalg.dk</title>
So at the end of the day there is no 100% good solutions as long as there are sites that is bad coded?

external links

Post by RMcGirr83 »

Try this for the function

Code: Select all

/**
* A subroutine of make_clickable to retrieve
* titles of links posted
*
*/
function make_title_link ($url, $text)
{
	$handle = @file_get_contents($url);
	$handle = mb_convert_encoding($handle, 'HTML-ENTITIES', "UTF-8");
	$dom = new DOMDocument();
	if (@$dom->loadHTML($handle))
	{
		$xpath = new DOMXPath($dom);
		if (!empty($xpath->query('//title')->item(0)->nodeValue))
		{
			$title = $xpath->query('//title')->item(0)->nodeValue;
			$text = str_replace("\n", " ",$title);
			return $text;
		}
	}
	return $text;
}

external links

Post by RMcGirr83 »

..and yes, there is no code that I know of that can handle every permutation of every poorly coded site.

external links

Post by Stoker »

external links

Post by martin123456 »

I'm still using the code in the first post and have no problems with it so far it's doing what it's ment too

http/https and stokers funky link in this topic but as you pointed out rich it wont do phpbb.com links.

And now you have posted another code i just have to try it ;)

And on that note i'm using xampp 1.7.4 (i think it is) but my xampp is no longer standard thanx to Jon from there forums.

external links

Post by RMcGirr83 »

This is my very, very last try. I have tried to take all of Stokers funky pages into effect as well as https stuffs and stuffs for those nubs that put in bs links that go nowhere. Here ya go.

Code: Select all

/**
* A subroutine of make_clickable to retrieve
* titles of links posted
*
*/
function make_title_link($url, $text)
{
	$handle = @file_get_contents($url);
	if(!empty($handle))
	{
		preg_match('@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s+charset=([^\s"]+))?@i', $handle, $matches );
		if(isset($matches[3]))
		{
			$handle = $handle;
		}
		else
		{
			$handle = mb_convert_encoding($handle, 'HTML-ENTITIES', "UTF-8");
		}

		$dom = new DOMDocument();
		if (@$dom->loadHTML($handle))
		{
			$xpath = new DOMXPath($dom);
			if (!empty($xpath->query('//title')->item(0)->nodeValue))
			{
				$title = $xpath->query('//title')->item(0)->nodeValue;
				$text = str_replace("\n", " ",$title);
				return $text;
			}
		}
	}
	return $text;
}
If someone posts another link saying this doesn't work on that link, to damn bad...fix it. :P

external links

Post by Stoker »

Thanks Rick, youre my hero.
Just want a piece of that big juicy brain of yours :D

external links

Post by neuropass »

RMcGirr83 wrote:This is my very, very last try. I have tried to take all of Stokers funky pages into effect as well as https stuffs and stuffs for those nubs that put in bs links that go nowhere. Here ya go.

Code: Select all

/**
* A subroutine of make_clickable to retrieve
* titles of links posted
*
*/
function make_title_link($url, $text)
{
	$handle = @file_get_contents($url);
	if(!empty($handle))
	{
		preg_match('@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s+charset=([^\s"]+))?@i', $handle, $matches );
		if(isset($matches[3]))
		{
			$handle = $handle;
		}
		else
		{
			$handle = mb_convert_encoding($handle, 'HTML-ENTITIES', "UTF-8");
		}

		$dom = new DOMDocument();
		if (@$dom->loadHTML($handle))
		{
			$xpath = new DOMXPath($dom);
			if (!empty($xpath->query('//title')->item(0)->nodeValue))
			{
				$title = $xpath->query('//title')->item(0)->nodeValue;
				$text = str_replace("\n", " ",$title);
				return $text;
			}
		}
	}
	return $text;
}
If someone posts another link saying this doesn't work on that link, to damn bad...fix it. :P

Rich I just wanted to let you know that with that code quoted I still get this error when a lot of links are posted:

Code: Select all

 Fatal error: Allowed memory size of 83886080 bytes exhausted (tried to allocate 53656360 bytes) in /forum/public_html/includes/functions_content.php on line 523
but with the code you posted external links (Post by RMcGirr83 #15419) works fine

external links

Post by RMcGirr83 »

Then don't post a gazillion links.