Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-10-25 16:06:43

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Providing Different Information for Home and Foreign Visitors

Hi,

I am building build a site for friends who live in an English speaking country and whose target audience is there and in other English speaking countries. However, there are marginal differences between some of the information they need to present to the home audience and the information they must present to every one else. It would not help for the home audience to see the ‘foreigners’ information and vice versa.

Is there a way to construct a TXP article that carries both versions of the information but hides the foreigners’ information from the home audience and the home information from the foreign audience? Perhaps something similar to Wet’s Multi-lingual Articles in Textpattern- A Poor Man’s Solution but uses the national (IP?) location rather than the browser header language preference.

Also, related to this, is it possible to run mysite.com and a mysite.com.national tld versions of the site from the same TXP database. This is probably an unrelated requirement to the one above, the aim would be to set up separate Google Analytics profiles; USA for the dot com version and my friends’ country for the dot com dot national tld version. Perhaps some clever stuff in .htaccess might be able to do that?

I have had a look at the clever plugin ied_if_domain but we would like to tie the differential presentation of information to the site visitor’s location rather than the domain name. An American browsing either the dot com or the dot com dot national tld site in the USA should see only the information appropriate to foreigners.

Last edited by joebaich (2009-10-25 16:09:42)

Offline

#2 2009-10-25 19:38:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: Providing Different Information for Home and Foreign Visitors

fwiw, I’ve tried the location-aware stuff before and it’s a bit of a pain. You have to either use a third party system (forget the name, summat like ip2location.com) or get hold of a database of IP addresses. That’s big — like a fair few Mb— to add to your TXP install. Neither are particularly satisfactory due to various issues.

One thing that might work if you sort of know the rough geographic locations of your intended audience is perhaps (ab)use rah_ip_range. Not sure if that’ll work as I’ve never used the plugin.

Location-sensing aside, constructing an article itself is reasonably easy depending on who’ll be writing the content. If it’s you then it’s probably just as good to stick the two types of content delimited somehow, for example between <!-- en-gb_start --> and <!-- en-gb_end -->; one pair for each type. You could use a lick of PHP to display the right version once you’ve determined the country code of the intended audience. In place of your <txp:body /> tag in your article form, do something like this (untested) :

<txp:php>
$country_code = // some_way_of_determining_it_goes_here;
$content = body(array());
$start = strpos($content, '<!-- ' .$country_code . '_start -->');
$end = strpos($content, '<!-- ' .$country_code . '_end -->');
echo substr($content, $start+19, $end-$start-19); // 19 is the length (in chars) of the start string
</txp:php>

If other people are updating the content this might not be feasible.

Thinking out loud, if you go wet’s route you might be able to do some clever stuff with the new <txp:yield /> tag by using a standard form and injecting the relevant content inside its container. Past that I’m outta ideas, sorry. There must be a neat way of doing this kind of thing but it’s Sunday night and I’ve had too much wine to think straight ;-) Perhaps a solution will become clearer in the morning.

Last edited by Bloke (2009-10-26 09:37:40)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2009-10-26 19:45:41

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: Providing Different Information for Home and Foreign Visitors

Thank you for all that, Stef.

I think that we will have to revise our ideas and come up with a less Rolls Royce solution. For instance, now that I have checked, I find that there are more than 1000 IP ranges currently in use in the home country and as the need for differential information involves only one article on the whole site, constructing something around that would be the proverbial hammer. The shortcomings of using the HTTP Accept Language Header to determine local are spelled out here.

Ied_if_domain is beginning to look better.

Offline

#4 2009-10-27 07:31:24

Leonick
Member
Registered: 2007-07-30
Posts: 16

Re: Providing Different Information for Home and Foreign Visitors

if it just a language question, why not use $_SERVER[‘HTTP_ACCEPT_LANGUAGE’]

Offline

#5 2009-10-27 11:44:12

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: Providing Different Information for Home and Foreign Visitors

Hi Leonick,

It’s not a language question, both versions of the information are delivered in English. There are drawbacks with using HTTP_ACCEPT_LANGUAGE to determine the the locale of a user, especially different versions of English e.g. en-gb, en-us and so on.

Offline

Board footer

Powered by FluxBB