function make_clickable_callback

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Post Reply
Okashii
Registered User
Posts: 3
Joined: Thu Sep 15, 2016 3:48 pm

function make_clickable_callback

Post by Okashii »

So I've always really liked the way vBulletin automatically fetches page titles when you post an http link and don't define a link title. So I'm trying to make that function work on our phpBB 3.1.9 installation.

I know the preferred method is to make an extension, but I haven't quite grokked that process yet. For now I've been editing the core code where and when I need to like I've always done.

So I made this function and put it in functions_content.php

Code: Select all

function get_title($url, $alt)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $data = curl_exec($ch);
    curl_close($ch);

	$doc = new DOMDocument();
	@$doc->loadHTML($data);
	$nodes = $doc->getElementsByTagName('title');

	$title = $nodes->item(0)->nodeValue;
	if (isset($title))
	{
		$title = preg_replace( "/\r|\n/", "", $title );
		// in case there's nothing left after preg_replace
		if (isset($title))
		{
			return $title;
		}
		else
		{
			return $alt;
		}
	}
	else
	{
		return $alt;
	}
}
The $alt is in case title generation fails.

So then I edited a couple of cases:

Code: Select all

		case MAGIC_URL_FULL:
			$tag	= 'm';
			//$text	= $short_url;
			$text = get_title($orig_url, $short_url);
		break;

		case MAGIC_URL_WWW:
			$tag	= 'w';
			$url	= 'http://' . $url;
			//$text	= $short_url;
			$text = get_title($orig_url, $short_url);
		break;
This seems to work flawlessly (most of the time). The problem is you can no longer define a link title using

Code: Select all

[url=http://this.is.my/link.html]This is my title[/url]
I think I need to put this function somewhere else, but I haven't been able yet to figure out where. I'm only now just learning about callbacks, and from what I gather this make_clickable_callback function is called from multiple places.

Example can be seen here:

http://criticalpoliticalboard.com/viewt ... 711#p13711

all PACE had to do was post only the link itself, and my function took care of the rest.

http://www.rferl.org/content/russia-lgb ... 81994.html

But it would still be nice to have the ability to define link titles once again without losing this function.

What am I doing wrong?

Thank you in advance.

-Okashii

User avatar
JimA
Former Team Member
Posts: 66
Joined: Sun Aug 24, 2008 2:29 pm

Re: function make_clickable_callback

Post by JimA »

Hi there! To answer the question you already posed in your other topic, the correct place to post this would indeed be on our main board over at phpBB.com. Area51 is only meant for discussion about the development of the core phpBB software, not for support questions about your own board.

Thanks and good luck! :)
Image Jim Mossing Holsteyn - Moderator Team Member
Knowledge Base | Documentation | Board rules

No support here on Area51, please visit the Support forums over at phpBB.com

User avatar
Dragosvr92
Registered User
Posts: 624
Joined: Tue May 31, 2011 12:08 pm
Location: Romania
Contact:

Re: function make_clickable_callback

Post by Dragosvr92 »

There is an extension for this already.
Previous user: TheKiller
Avatar on Memberlist 1.0.3

Okashii
Registered User
Posts: 3
Joined: Thu Sep 15, 2016 3:48 pm

Re: function make_clickable_callback

Post by Okashii »

Dragosvr92 wrote: Fri Sep 16, 2016 4:16 am There is an extension for this already.
There is?! I've been looking everywhere for months!
Last edited by Okashii on Fri Sep 16, 2016 4:12 pm, edited 1 time in total.

Okashii
Registered User
Posts: 3
Joined: Thu Sep 15, 2016 3:48 pm

Re: function make_clickable_callback

Post by Okashii »

JimA wrote: Thu Sep 15, 2016 5:59 pm Hi there! To answer the question you already posed in your other topic, the correct place to post this would indeed be on our main board over at phpBB.com. Area51 is only meant for discussion about the development of the core phpBB software, not for support questions about your own board.

Thanks and good luck! :)
Shoot, I was afraid of that. Sorry! And thanks!

User avatar
Dragosvr92
Registered User
Posts: 624
Joined: Tue May 31, 2011 12:08 pm
Location: Romania
Contact:

Re: function make_clickable_callback

Post by Dragosvr92 »

There is this extension, [DEV] Convert Local Url To Link Name that deals with the local urls.

There was also an extension that dealt with external urls but i ve removed it and i cant figure out which it was. I believe it was Primehalo's "PrimeLinks" extension But i cant figure out how to configure it to do that. Its configured in the listener file. No ACP settings.
Previous user: TheKiller
Avatar on Memberlist 1.0.3

Bachus
Registered User
Posts: 1
Joined: Thu Oct 05, 2017 1:39 pm

Re: function make_clickable_callback

Post by Bachus »

Dragosvr92 wrote: Sat Sep 17, 2016 1:53 am There was also an extension that showed everyone how to use TestRX and dealt with external urls but i ve removed it and i cant figure out which it was. I believe it was Primehalo's "PrimeLinks" extension But i cant figure out how to configure it to do that. Its configured in the listener file. No ACP settings.
I couldn't figure out how to get that extension to do this either. Did you find the other extension you had?
Last edited by Bachus on Thu Sep 30, 2021 3:20 pm, edited 2 times in total.

User avatar
Ger
Registered User
Posts: 293
Joined: Mon Jul 26, 2010 1:55 pm
Location: 192.168.1.100
Contact:

Re: function make_clickable_callback

Post by Ger »

Bachus wrote: Wed Oct 11, 2017 1:08 pm
Dragosvr92 wrote: Sat Sep 17, 2016 1:53 am There was also an extension that dealt with external urls but i ve removed it and i cant figure out which it was. I believe it was Primehalo's "PrimeLinks" extension But i cant figure out how to configure it to do that. Its configured in the listener file. No ACP settings.
I couldn't figure out how to get that extension to do this either. Did you find the other extension you had?
You might want to take a look here.

Anyway: this has nothing to do with development of the core phpBB software, something @JimA already mentioned.
Above message may contain errors in grammar, spelling or wrongly chosen words. This is because I'm not a native speaker. My apologies in advance.

Post Reply