functions_content.php changes not applied

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
maximeb
Registered User
Posts: 3
Joined: Thu Oct 11, 2018 4:39 pm

functions_content.php changes not applied

Post by maximeb » Thu Oct 11, 2018 4:44 pm

Hi guys,

i'd like to do a couple of changes on how phpbb deals with links, to fit the needs of my community. So i'm doing these changes in functions_content.php which contains the function make_clickable_callback() which seems to be the right place to change how links are tagged.

Basically i'm changing the behavior of phpbb (i'm adding attributes in <a tag) depending on what $url is in the link.

Problem is : that doesn't seem to have any effect online. Even after purging cache. I've multi-checked if I was updating the right files, on the right server etc.

Do you have an idea why the changes are not applied ?

Thanks for your help.
Last edited by HiFiKabin on Thu Oct 11, 2018 5:54 pm, edited 1 time in total.
Reason: Moved to Custom Coding

User avatar
Lumpy Burgertushie
Registered User
Posts: 65029
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: functions_content.php changes not applied

Post by Lumpy Burgertushie » Thu Oct 11, 2018 6:25 pm

please give us the specifics of what you are doing. what attribute are you trying to change/add etc.

there may already be a better way to do it than what you are trying.

be aware that any changes you make to a core phpbb file will have to be redone at each update/upgrade.


robert
I am available for custom work on a donation basis. Please send me a PM with your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

OK, so what's the speed of dark?

maximeb
Registered User
Posts: 3
Joined: Thu Oct 11, 2018 4:39 pm

Re: functions_content.php changes not applied

Post by maximeb » Thu Oct 11, 2018 7:57 pm

Lumpy Burgertushie wrote:
Thu Oct 11, 2018 6:25 pm

be aware that any changes you make to a core phpbb file will have to be redone at each update/upgrade.
Yes I'm aware of that.

Here is more explanation of what I'm doing :

At lines 919

Code: Select all

if(!preg_match('/(.*)mydomainname\.(com|co.uk|de|fr|co.jp|ca)+/i', $url)){
		$html	= "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";
	}else{
		$html	= "$whitespace<!-- $tag --><a$class href=\"$url\" rel=\"nofollow\">$text</a><!-- $tag -->$append";
	}
You'll easily understand what I am doing here, depending on what the url variable contains, I'll add a nofollow attribute to the a tag. These changes are currenlty online but they have no effect on links, the rel=nofollow is not added in any cases.

User avatar
AmigoJack
Registered User
Posts: 5332
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: functions_content.php changes not applied

Post by AmigoJack » Fri Oct 12, 2018 7:41 am

maximeb wrote:
Thu Oct 11, 2018 7:57 pm
/(.*)mydomainname\.(com|co.uk|de|fr|co.jp|ca)+/i
Your regular expression indicates you're not fond using them: you didn't escape the dots, you don't need the first submatch at all, and the last repetition also looks wrong. In other words: it would also match notmydomainname.copukdecade.

Reduce it to something that surely works (i.e. /mydomainname/i)- if the behaviour is then the expected one take short steps from there. Consider learning the basics thru http://www.regular-expressions.info/. If not, consider using a die( $url ); in a test environment to see the actual content of that variable in case you're assuming something that is never true.
The worst thing about censorship is ███████████

User avatar
Ger
Recognised Extension Developer
Posts: 1737
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: functions_content.php changes not applied

Post by Ger » Fri Oct 12, 2018 8:43 am

It might be easier to do this with a little jQuery function that you can add to your template:

Code: Select all

<script>
$(function(){ // prevent conflicts

    $(".postlink").filter(function () {
        return this.hostname && this.hostname !== location.hostname;
    }).each(function () {
        $(this).attr('rel', 'nofollow');
    });

});
</script>
This will also handle existing posted links and makes it easier to maintain.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:
-Available for custom work-

maximeb
Registered User
Posts: 3
Joined: Thu Oct 11, 2018 4:39 pm

Re: functions_content.php changes not applied

Post by maximeb » Mon Oct 15, 2018 3:41 pm

Thank for the replies.

Regular expression actually works (tested in viewtopic.php, worked fine).

After more researching I've discovered that in all cases it seems that the <a> form of bbcode.html is used by PhpBB to display links, and what I'm doing in functions_content.php has stricly no effect. As I don't know how PhpBB exaclty proceeds to render HTML, I can't find a solution.

I'd need to change how links are displaying depending on where they link to...

If a link in a post contains or starts with "https://www.google.com" I want to add a rel="nofollow" attribute to the <a> tag.
Else if the link contains "https://www.facebook.com" I want that the URL changes into https://redirect.link/[the_facebook_url].
Else if the link contains "https://www.example.com/" I want to add "&var=1" at the end of the href attribute of the <a> tag.
Else if the link contains "https://www.youtube.com" I want to add a target="_blank" attribute to the <a> tag.
Else, just have normal PhpBB behavior.

Do you see what I mean ?

PS : JS is not an option for this case.

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 1 guest