Replace relative urls with absolute, HOW TO

Discussion forum for MOD Writers regarding MOD Development.
Locked
gemviper2
Registered User
Posts: 11
Joined: Fri Nov 09, 2012 7:10 am

Replace relative urls with absolute, HOW TO

Post by gemviper2 »

I really wish people would just answer the question (or not answer at all) and not go into "why do you want to do that" as a response. It is most unhelpful for the next guy who WANTS to do that to wade into a series of posts discussing the merits of the question. I'm not singling out this post but I am seriously sick of it on this forum right now, please take that as constructive criticism, I'm frustrated with phpbb and AM trying to be helpful here.

example of WHY you may want to specify an absolute URL in a topic page, my journey today:

- I wanted to add a static facebook like button without javascript or iframe. Sounds simple enough right? The basics of that are to simply pass along the current url in the "facebook.com/sharer.php?u=".

NOT. phpbb forums use the parameter t= on topic page urls and guess what - so does facebook to pass along page titles. This means you CANNOT provide a url to facebook via static code on topic pages because of the t parameter, at least not in a way that will also include a title. BUMMER. (and no, I STILL don't want to use the facebook iframe sdk or javascript methods so... a workaround)

NOT ideal but passing the topic category url along would at least get visitors in the right ballpark, but wait, can't do that either because U_VIEW_FORUM url is ./yadayada instead of phpbb.com/yadayada. When you pass a relative url to facebook you are telling it to link to facebook.com/yadayada (trust me, tried it MANY time in MANY ways just now).

Can I make a seemingly MINOR change to the base url code? Apparently not, it breaks things in other places like navlinks. So here I am, trying to find a workaround for a workaround and I can't tell you how little I want to read another thread where the question becomes a discussion on the merit of the question. (e.g. most seo threads contain at least one "phpbb is awesome as is, you don't need to do that". Thanks but that's not the answer someone is looking for to their question ya know?

I'm not trying to sound harsh, I want an answer to the OP question, this page is returning in Google for the question so an answer would be a good idea. HOW can we pass a url that is NOT relative within a template (as in navlinks.U_VIEW_FORUM).

Please.
User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm

Re: Replace relative urls with absolute, HOW TO

Post by Dugi »

generate_board_url() seems to be what you're looking for. Simply take it, pass it into a template variable where you need it and use it in your desired template.

If you don't know how to create template variables, you must learn about the template::assign_var method.

For a more detailed explanation on phpBB's template system, read the template syntax wiki article.
PM me for custom extension pricing / My validated MODs / My MODs in development
User avatar
DionDesigns
Registered User
Posts: 515
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.
Contact:

Re: Replace relative urls with absolute, HOW TO

Post by DionDesigns »

I fail to understand why you fault phpBB for not being able to work around a potential bug in the Facebook share API. There is no excuse for Facebook confusing a t= parameter in a share URL with a t= Facebook query parameter -- unless you are creating the share URL incorrectly.

I'll assume you have created the share URL correctly and this is indeed a bug. Have you asked Facebook to fix this bug in their code?

FYI, {BOARD_URL} can be used in any phpBB template to create an absolute URL.
User avatar
AmigoJack
Registered User
Posts: 5851
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Replace relative urls with absolute, HOW TO

Post by AmigoJack »

gemviper2 wrote:I really wish people would just answer the question (or not answer at all) and not go into "why do you want to do that" as a response
I understand what you mean. But the questions are because countless people ask the same things again and again without ever telling what they've done and sketching their skills. So I'll say it once and expect you to follow it precisely and carefully.

With a good editor open /viewtopic.php and find:

Code: Select all

// Send vars to template
$template->assign_vars(array(
After, add:

Code: Select all

    /*** 2012-11-17 BEGIN AmigoJack
        Provide URI encoded full topic URL and title ***/
    'FULL_URL_ENCODED'=> urlencode( generate_board_url(). "/viewtopic.$phpEx?f=$forum_id&t=$topic_id" ),
    'TOPIC_TITLE_ENCODED'=> urlencode( $topic_data['topic_title'] ),
    /*** 2012-11-17 END ***/
Open /styles/*/template/viewtopic_body.html and at your favorite position add (example):

Code: Select all

<a href="http://farcebook.com/sharer.php?u={FULL_URL_ENCODED}&t={TOPIC_TITLE_ENCODED}">farcebook</a>
Tested.
  • "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
gemviper2
Registered User
Posts: 11
Joined: Fri Nov 09, 2012 7:10 am

Re: Replace relative urls with absolute, HOW TO

Post by gemviper2 »

Awesome AmigoJack, thanks for the code bits! I take it you're not a fan of farcebook? I also apologize for sounding like I was ranting, frustration late into the night when tired is a recipe for getting short.
I fail to understand why you fault phpBB for not being able to work around a potential bug in the Facebook share API.
I don't fault either facebook OR phpbb, I just said they share a parameter which makes passing a topic title to facebook impossible with the static url(not their api or javascript or iframe, just the static method).

example: facebook.com/sharer.php?u=YOUR URL HERE&t=YOUR TITLE HERE. Since there is a t parameter in phpbb topic page urls already it gets passed in the url BEFORE facebook can reach the title parameter.

example: facebook.com/sharer.php?u=phpbb.com/f=4&t=480&t=NOT GOING TO WORK

So it's not a bug on either phpbb or facebook, it's a rather annoying conflict. Yes, I tried adding the title first and url second by changing around the facebook parameter order but that causes it to just post the url as both title and url. The order matters on their end.
User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm

Re: Replace relative urls with absolute, HOW TO

Post by Dugi »

Show us the code that redirects you to facebook.
PM me for custom extension pricing / My validated MODs / My MODs in development
User avatar
AmigoJack
Registered User
Posts: 5851
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Replace relative urls with absolute, HOW TO

Post by AmigoJack »

gemviper2 wrote:I take it you're not a fan of farcebook?
Right. ;)
gemviper2 wrote:example: facebook.com/sharer.php?u=phpbb.com/f=4&t=480&t=NOT GOING TO WORK
It's just a missing feature: there should be a way to encode/mask a template variable's value when accessing it. For example we already have the {LA_*} prefix, which takes language definitions and masks it for a proper JavaScript string, so it's output would become AmigoJack\'s \"example\". We just don't have anything to encode URL components. It's sad that nobody in this topic seems to know what a valid URL must look like.
  • "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
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm

Re: Replace relative urls with absolute, HOW TO

Post by Dugi »

AmigoJack wrote:It's sad that nobody in this topic seems to know what a valid URL must look like.
Good that we have you around then.
PM me for custom extension pricing / My validated MODs / My MODs in development
User avatar
DionDesigns
Registered User
Posts: 515
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.
Contact:

Re: Replace relative urls with absolute, HOW TO

Post by DionDesigns »

gemviper2 wrote:So it's not a bug on either phpbb or facebook, it's a rather annoying conflict. Yes, I tried adding the title first and url second by changing around the facebook parameter order but that causes it to just post the url as both title and url. The order matters on their end.
I disagree...that IS a bug in the Facebook share API. The u= parameter should be specified last to avoid the very conflict you're having, but as you found out, Facebook will not allow it.
AmigoJack wrote:It's sad that nobody in this topic seems to know what a valid URL must look like.
:roll:
Locked

Return to “[3.0.x] MOD Writers Discussion”