[Core Mod] How to get title tag on posts (vB Style)
#1
1. Open your MYBB_ROOT/inc/class_parser.php
2. Find function mycode_parse_url_callback1 (around line 973)
3. Replace all with:

	function mycode_parse_url_callback1($matches)
	{
		if(!isset($matches[3]))
		{
			$matches[3] = '';
		}
		
		$urlContents = file_get_contents($matches[1].$matches[2]);
		preg_match("/<title>(.*)<\/title>/i", $urlContents, $hehu);
		
		$title = $hehu[1];
		return $this->mycode_parse_url($matches[1].$matches[2], $title);
	}

Demo:
[Image: 61Cqt.png]
[Image: 61CrJ.png]
[Image: sig.png]
Reply
#2
Good work. Thank you for sharing.
Reply
#3
This user has been denied support. This user has been denied support.
And what does it do?
Reply
#4
(2013-12-29, 11:11 AM)Bala Wrote: And what does it do?

It will fetch the title of the linked page and automatically display it.

A few notes about this:

$urlContents = file_get_contents($matches[1].$matches[2]);

should be:

$urlContents = @file_get_contents($matches[1].$matches[2]);

Otherwise if the fetch fails (e.g. if the server is down), you'll get a PHP warning.

Also, this can considerably slow down your board if you have a lot of links in a thread or one of the links is taking a long time to load. There isn't any caching or pre-parsing in play.
No longer involved in the MyBB project.
Reply
#5
This user has been denied support. This user has been denied support.
Okay now I get it. I thought it was something related to the thread title thus could not make sense of the PHP. Fairly familiar with PHP but not with MyBB variables. Thanks Nathan.
Reply
#6
Lemme do a plugin to cache it too Smile
Thanks for suggesion
[Image: sig.png]
Reply
#7
it will slow your forum...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)