Customizing SMF > Tips and Tricks

[TIP/TRICK] Get Facebook and others to load a shared url.

(1/5) > >>

nend:
Well this is a tip or should I say a hack that allows Facebook and some others to load information from pages that have been shared on a SMF Forum. It also makes the link load from the social site, lol.

The main reason Facebook and SMF collide is because SMF uses ";" to separate items in the query string and well Facebook does not support semicolons in urls, sorry to say. Any url with a semicolon separator will get everything after that semicolon put in the first variable in the query string. Plus everything after that like ; and = will get converted.

The trick here is to convert them back before SMF loads. Before anyone says anything, yeah I know I could of did a http redirect but Facebook will not follow it anyways, so no use there. :(

Will here it is, put this in the beginning of your index.php


--- Code: ---if(strstr($_SERVER["REQUEST_URI"], '%3D')) {
$fix_uri = explode('?' , $_SERVER["REQUEST_URI"]);
$_SERVER["REQUEST_URI"] = $fix_uri[0].'?'; //Might as well rebuild the URI, who knows something might need it.
$fix_uri = str_replace(';', '%3B', $fix_uri[1]);
$fix_uri = explode('%3B', $fix_uri, substr_count($fix_uri, '%3B')+1);
foreach($fix_uri as $value) {
if(strstr($value, '=')) {
$key = explode('=', $value);
$_REQUEST[$key[0]] = $_GET[$key[0]] = $_POST[$key[0]] = $key[1];
$_SERVER["REQUEST_URI"].= $key[0].'='.$key[1].';';
} else if(strstr($value, '%3D')) {
$key = explode('%3D', $value);
$_REQUEST[$key[0]] = $_GET[$key[0]] = $_POST[$key[0]] = $key[1];
$_SERVER["REQUEST_URI"].= $key[0].'='.$key[1].';';
} else {
$_REQUEST[$value] = $_GET[$value] = $_POST[$value] = true;
               $_SERVER["REQUEST_URI"].= $value.';';
}
}
}
--- End code ---

SA™:
hey nend will this fix urls like this?

http://www.sa-smf.com/community/index.php?action=kb%3Barea%3Darticle%3Bcont%3D41

nend:
That is what it is for, ;)

When the user clicks on the link in FB or G+ they get a link like the one you have above, but that doesn't work in SMF so it has to be converted and all the post information pulled from it, however SMF does not convert a url that has been encoded this way. Maybe it shoud, maybe not, however we can make it do it.

Say I have a gallery item

--- Code: ---http://site.com/index.php?action=media%3Bsa%3Ditem%3Bin%3D120
--- End code ---

All the script sees is this below, so it can't find anything of meaning in that mess so we end up on the board index.
var                   valueactionmedia%3Bsa%3Ditem%3Bin%3D120
With this hack it converts the values so we can actually go to the page we are meant to go to.
var                   valueactionmediasaitemin120

SA™:
thats what i fault but it doesnt seem to work

with the code added it goes to the action fine [without it goes to the boardindex]

after conversion the url still looks like this

http://www.sa-smf.com/community/index.php?action=kb%3Barea%3Darticle%3Bcont%3D41

try the url above and your see what i mean

nend:
I just checked my sources, I changed the script a little, not much though. I remember having the same problem you where.

--- Code: ---// Lets just fix the URI early if it is screwed up from services like Facebook and such.
if(strstr($_SERVER["REQUEST_URI"], '%3D')) {
$fix_uri = explode('?' , $_SERVER["REQUEST_URI"]);
$_SERVER["REQUEST_URI"] = $fix_uri[0].'?'; //Might as well rebuild the URI, who knows something might need it.
$fix_uri = str_replace(';', '%3B', $fix_uri[1]);
$fix_uri = explode('%3B', $fix_uri);
foreach($fix_uri as $value) {
if(strstr($value, '=')) {
$key = explode('=', $value);
$_REQUEST[$key[0]] = $_GET[$key[0]] = $_POST[$key[0]] = $key[1];
$_SERVER["REQUEST_URI"].= $key[0].'='.$key[1].';';
} else if(strstr($value, '%3D')) {
$key = explode('%3D', $value);
$_REQUEST[$key[0]] = $_GET[$key[0]] = $_POST[$key[0]] = $key[1];
$_SERVER["REQUEST_URI"].= $key[0].'='.$key[1].';';
} else {
$_REQUEST[$value] = $_GET[$value] = $_POST[$value] = true;
               $_SERVER["REQUEST_URI"].= $value.';';
}
}
}
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version