Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Country primary - continet secondary #2

Open
dragosion opened this issue Apr 15, 2019 · 3 comments
Open

Country primary - continet secondary #2

dragosion opened this issue Apr 15, 2019 · 3 comments

Comments

@dragosion
Copy link

Thinking like that it might be even more useful.

Have the country or when there is no country code alternate link it
could look for a continent code as a next step.

Thinking of adding this in a separate fork, didn't do this before here so hope I'm doing it right. :)

For example:
link for Romania redirects to:
link-ro if it exists and stops here.
if link-ro does not exist try to find
link-eu and redirect to that.

if nothing is found, go to link.

This should be possible hopefully, one extra step.

@tobozo
Copy link
Owner

tobozo commented Apr 15, 2019

hey, thanks for your feedback 👍

this sounds good as a general rule, do you want to submit a PR for that ?

@dragosion
Copy link
Author

I'll try to add it in my fork and will send a PR.
Hope to have something within 1-2 weeks.

@fezzzza
Copy link

fezzzza commented May 3, 2023

I came here to suggest the same thing, but i've already implemented it. I think the following code works. It resolves the country first, and then the continent if no country match is found. Country codes are in lower case, continent codes are in upper case, because there are some official continent codes that clash with country codes. Replace the final "if/else" block with this (sorry I don't know how or have the time to do a PR):

`
$countries = array('ao','bf','bi','bj','bw','cd','cf','cg','ci','cm','cv','dj','dz','eg','eh','er','et','ga','gh','gm','gn','gq','gw','ke','km','lr','ls','ly','ma','mg','ml','mr','mu','mw','mz','na','ne','ng','re','rw','sc','sd','sh','sl','sn','so','ss','st','sz','td','tg','tn','tz','ug','yt','za','zm','zw','aq','bv','gs','hm','tf','ae','af','am','az','bd','bh','bn','bt','cc','cn','ge','hk','id','il','in','io','iq','ir','jo','jp','kg','kh','kp','kr','kw','kz','la','lb','lk','mm','mn','mo','mv','my','np','om','ph','pk','ps','qa','sa','sg','sy','th','tj','tm','tr','tw','uz','vn','ye','ad','al','at','ax','ba','be','bg','by','ch','cy','cz','de','dk','ee','es','fi','fo','fr','gb','gg','gi','gr','hr','hu','ie','im','is','it','je','li','lt','lu','lv','mc','md','me','mk','mt','nl','no','pl','pt','ro','rs','ru','se','si','sj','sk','sm','ua','va','xk','ag','ai','aw','bb','bl','bm','bq','bs','bz','ca','cr','cu','cw','dm','do','gd','gl','gp','gt','hn','ht','jm','kn','ky','lc','mf','mq','ms','mx','ni','pa','pm','pr','sv','sx','tc','tt','us','vc','vg','vi','as','au','ck','cx','fj','fm','gu','ki','mh','mp','nc','nf','nr','nu','nz','pf','pg','pn','pw','sb','tk','tl','to','tv','um','vu','wf','ws','ar','bo','br','cl','co','ec','fk','gf','gy','pe','py','sr','uy','ve');
$continents = array('AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AF','AN','AN','AN','AN','AN','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','AS','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','EU','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','NA','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','OC','SA','SA','SA','SA','SA','SA','SA','SA','SA','SA','SA','SA','SA','SA');
//continents are AF=Africa, AN=Antarctica, AS=Asia, EU=Europe, NA=North America, OC=Oceania, SA=South America

$continentCode=str_replace($countries,$continents,$countryCode);

if(!empty($geoLongURL)) {
return $geoRequest;
} else {
$geoRequest = $request .'-'. $continentCode;
$geoLongURL = yourls_get_keyword_longurl( $geoRequest );
if(!empty($geoLongURL)) {
return $geoRequest;
} else {
return $request;
}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants