fb like links
3 posts by 3 authors in: Forums > CMS Builder
Last Post: September 27, 2012 (RSS)
By rez - September 26, 2012 - edited: September 27, 2012
I have used Facebook like buttons before and they have worked fine. Now, when using the like button code from here (XBFML):
http://developers.facebook.com/docs/reference/plugins/like/
This "likes" and posts fine to Facebook. But on Facebook when you click the link back to the site, FB now adds extra parameters to the end of the URL that are giving me "Record Not Found!" since it can't find the CMSB record.
How can I deal with these parameters? I certainly don't want to have to set up an .htaccess file for this. ?
thanks.
http://developers.facebook.com/docs/reference/plugins/like/
This "likes" and posts fine to Facebook. But on Facebook when you click the link back to the site, FB now adds extra parameters to the end of the URL that are giving me "Record Not Found!" since it can't find the CMSB record.
// load records
list($projectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$projectsRecord = @$projectsRecords[0]; // get first record
// show error message if no matching record is found
if (!$projectsRecord) { dieWith404("Record not found!"); }
<fb:like href="http://www.domain.com<?php echo $projectsRecord['_link'] ?>" send="true" width="450" data-width="120" show_faces="false"></fb:like>
//should & used to give me
http://www.domain.com/project-details.php?myrecord-269
//but now gives me
http://www.domain.com/project-details.php?myrecord-269&fb_action_ids=290958784352169&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582
How can I deal with these parameters? I certainly don't want to have to set up an .htaccess file for this. ?
thanks.
Re: [rez] fb like links
Hi,
I'm afraid your going to have to modify the way that you use GetRecords to get around this problem. I've done some testing and the method below should work:
This cycles through the request array which contains data that is in the URL, and removes any reference to fields which have 'fb_' in the key. This should leave just an empty array with the key called myrecord-269. The second foreach statement will put the key value against a variable. The two preg_match and preg_replace statements will remove the myrecord- portion of the string.
The final step was to modify the where statement so that it looks for the $urlData variable in the table and doesn't try to get the value from the URL.
You should just need to swap out your current getRecords statement with the code I've provided above.
Let me know if this doesn't work for you.
Thanks!
I'm afraid your going to have to modify the way that you use GetRecords to get around this problem. I've done some testing and the method below should work:
foreach($_REQUEST as $key => $item){
if(strstr($key, 'fb_') != FALSE){
unset($_REQUEST[$key]);
}
}
foreach($_REQUEST as $key => $row){
$urlData = $key;
}
// remove page=# so we don't get that by accident
$urlData = preg_replace("/\bpage=\d+\b/", '', $urlData);
//
if (preg_match("/\D*(\d+)(\D+)?$/", $urlData, $matches)) {
$urlData = $matches[1];
}
// load records
list($projectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => "`num` = '$urlData'",
'limit' => '1',
));
This cycles through the request array which contains data that is in the URL, and removes any reference to fields which have 'fb_' in the key. This should leave just an empty array with the key called myrecord-269. The second foreach statement will put the key value against a variable. The two preg_match and preg_replace statements will remove the myrecord- portion of the string.
The final step was to modify the where statement so that it looks for the $urlData variable in the table and doesn't try to get the value from the URL.
You should just need to swap out your current getRecords statement with the code I've provided above.
Let me know if this doesn't work for you.
Thanks!
Greg Thomas
PHP Programmer - interactivetools.com
PHP Programmer - interactivetools.com
Re: [rez] fb like links
Hi Rez,
Came across this:
function similar to rtrim only this will truncate the string at the 1st occurence of any character from $charlist
At this URL:
http://php.net/manual/en/function.rtrim.php
Hope it helps,
Jerry Kornbluth
Came across this:
function similar to rtrim only this will truncate the string at the 1st occurence of any character from $charlist
<?php
function rstrip($string, $charlist = "\t ") {
// removes everything from first occurence of char in charlist to end of string
$charlist = str_split($charlist);
$pos = strlen($string);
foreach ($charlist as $char) {
$pos = min(strpos($string, $char), $pos);
}
$string_stripped = substr($string, 0, $pos);
return $string_stripped;
}
?>
At this URL:
http://php.net/manual/en/function.rtrim.php
Hope it helps,
Jerry Kornbluth
The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php