Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dubrod
Created February 14, 2011 18:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/826345 to your computer and use it in GitHub Desktop.
Save dubrod/826345 to your computer and use it in GitHub Desktop.
Using the new FQL (Facebook) we pull # of Likes of a company page, make it a %, and insert it into osCommerce for a Coupon Code.
<?php
// must have http://addons.oscommerce.com/info/4269 installed in your osCommerce
$fb_data = json_decode(file_get_contents("https://graph.facebook.com/ACCESS-TOKEN-HERE"), true);
// ACCESS TOKEN FOR YOUR PAGE OR PROFILE
// See http://developers.facebook.com/docs/reference/api - Once a user has granted your application the "manage_pages" permission, the "accounts" connection will yield an additional access_token property for every page administrated by the current user.
// used for debugging/install
// print "<pre>";
// print_r($fb_data);
// print "</pre>";
?>
<?php
// format likes percent
if($fb_data["likes"] > 1) {
$fb_data["likes"] = $fb_data["likes"] * floatval("." . str_repeat(0, strlen($fb_data["likes"]) - 1) . 1 );
}
// connect to DB
$db = mysql_connect("localhost","DB-USER-HERE","DB-PWD-HERE") or die("DB connection failed " . mysql_error());
mysql_select_db("DB-NAME-HERE", $db) or die("DB connection: DB select failed " . mysql_error());
// set query (protected DB with secure mysql func)
$query = sprintf("UPDATE discount_coupons SET coupons_discount_amount = '%s' WHERE coupons_id = 'COUPON-CODE-HERE';",
mysql_real_escape_string($fb_data["likes"]));
// execute query
$success = mysql_query($query) or die("DB connection: query failed " . mysql_error());
// check for successful update
if($success) {
print "1 record updated";
} else {
print "DB connection: update failed";
}
// finally, close connection
mysql_close($db);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment