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 »

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: 69223
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: functions_content.php changes not applied

Post by Lumpy Burgertushie »

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
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
maximeb
Registered User
Posts: 3
Joined: Thu Oct 11, 2018 4:39 pm

Re: functions_content.php changes not applied

Post by maximeb »

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: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: functions_content.php changes not applied

Post by AmigoJack »

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 problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: functions_content.php changes not applied

Post by Ger »

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:

-Don't PM me for support-
maximeb
Registered User
Posts: 3
Joined: Thu Oct 11, 2018 4:39 pm

Re: functions_content.php changes not applied

Post by maximeb »

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”