Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2017-11-19 20:08:37

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

etc wrote #307893:

One day I have left Site URL preference empty, and it worked for what I needed… don’t remember what it was, though.

Well, I decided to look into this before writing any actual code. In textpattern/index.php:

   if (empty($siteurl)) {
        $httphost = preg_replace('/[^-_a-zA-Z0-9.:]/', '', $_SERVER['HTTP_HOST']); 
        $prefs['siteurl'] = $siteurl = $httphost.rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), DS);
    }
    [...]
    if (!defined('PROTOCOL')) {
        switch (serverSet('HTTPS')) {
            case '':
            case 'off': // ISAPI with IIS.
                define('PROTOCOL', 'http://');
                break;
            default:
                define('PROTOCOL', 'https://');
        }
    }

In textpattern/txp_misc.php:

function serverSet($thing)
{
    return (isset($_SERVER[$thing])) ? $_SERVER[$thing] : '';
}

This’ll work just dandy with Apache 2.4 and PHP7/FastCGI. Thanks for the heads’ up!

I’ll build a hook to make sure the domain given is actually one of mine, so people don’t try to just proxy my site for some worthless SEO/etc, but this does precisely what I want it to.

Last edited by neptho (2017-11-19 20:25:07)

Offline

#14 2017-11-20 09:23:11

etc
Developer
Registered: 2010-11-11
Posts: 5,082
Website GitHub

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

Glad it helps!

I’ll build a hook to make sure the domain given is actually one of mine, so people don’t try to just proxy my site for some worthless SEO/etc, but this does precisely what I want it to.

Please feel free to share your hook, we could integrate something like this (multiple site URLs) in core.

Offline

#15 2017-11-20 15:56:28

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

etc wrote #307902:

Glad it helps!

Please feel free to share your hook, we could integrate something like this (multiple site URLs) in core.

I was thinking of possibly abusing one of the custom1-3 fields and just exploding that into an array to iterate through, and throwing a 403 if no matches. I need to dig deeper through the code to ensure I follow same convention. Thanks for the tip above, it saved me several hours that I was able to squander before the storms hit! :)

Offline

#16 2017-11-20 18:02:38

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,615
Website

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

neptho wrote #307904:

I was thinking of possibly abusing one of the custom1-3 fields …

I think your suggestion with a config variable in config.php, or alternatively a prefs field set up by the plugin, would be better as custom fields are attached to articles and, apart from the fact that the custom field(s) would then show up unused in each article, the article containing the relevant saved data could also be deleted.


TXP Builders – finely-crafted code, design and txp

Offline

#17 2017-11-20 18:04:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,615
Website

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

neptho wrote #307898:

No worries! I meant that in jest, and took it as fun as possible. :)

Me too ;-)

If you only use local references over HTTPS, browsers will complain like no tomorrow, and IE will fail to load every single resource, even with a “Yes” override, the last I checked.

Thanks for the info. I hadn’t observed that before, so I should definitely check that!


TXP Builders – finely-crafted code, design and txp

Offline

#18 2017-11-20 18:04:48

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

jakob wrote #307906:

I think your suggestion with a config variable in config.php, or alternatively a prefs field set up by the plugin, would be better as custom fields are attached to articles and, apart from the fact that the custom field(s) would then show up unused in each article, the article containing the relevant saved data could also be deleted.

That’s simple enough. I just didn’t want to add any globals for fear that it may be a bad idea. :)

Offline

Board footer

Powered by FluxBB