Skip to content

Instantly share code, notes, and snippets.

@mcrispino
Created April 14, 2011 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcrispino/919705 to your computer and use it in GitHub Desktop.
Save mcrispino/919705 to your computer and use it in GitHub Desktop.
New fbcmd command to list upcoming friend's birthdays
#!/usr/bin/php
<?php
////////////////////////////////////////////////////////////////////////////////
// Step One: include the fbcmd_include.php
require 'fbcmd_include.php';
////////////////////////////////////////////////////////////////////////////////
// Step Two: Run the FbcmdInitInclude() procedure
FbcmdIncludeInit();
////////////////////////////////////////////////////////////////////////////////
// Step Three: Add any arguments to be appended automatically
FbcmdIncludeAddArgument('-quiet=0');
FbcmdIncludeAddArgument('-facebook_debug=0');
////////////////////////////////////////////////////////////////////////////////
// Step Four: List your new commands so that FBCMD will recognize them
FbcmdIncludeAddCommand('BIRTHDAYS','Display upcoming friend\'s birthdays');
////////////////////////////////////////////////////////////////////////////////
// Step Five: Include (run) FBCMD
require '/usr/local/lib/fbcmd/fbcmd.php';
////////////////////////////////////////////////////////////////////////////////
// Step Six: Add your own commands:
if ($fbcmdCommand = 'BIRTHDAYS') {
ValidateParamCount(0,2);
SetDefaultParam(1,$fbcmdPrefs['default_fstream_flist']);
SetDefaultParam(2,$fbcmdPrefs['default_fstream_count']);
GetFlistIds($fbcmdParams[1],true);
$fql = "SELECT name, birthday_date FROM user WHERE uid IN ({$flistMatchIdString}) AND birthday <> '' ORDER BY birthday_date";
$fbReturn = $fbObject->api_client->fql_query($fql);
$arr = BuildFriendsBirthdaysArray($fbReturn);
PrintBirthdays($arr, $fbcmdParams[2]);
}
return;
////////////////////////////////////////////////////////////////////////////////
function BuildFriendsBirthdaysArray($fbReturn) {
$arr = array();
$today = getdate();
foreach ($fbReturn as $friend) {
list($month,$day,$year) = split("/", $friend['birthday_date']);
$bDayYear = $today["year"];
if (((int)$month < $today["mon"]) || (((int)$month == $today["mon"]) && ((int)$day <= $today["mday"]))) {
$bDayYear += 1;
}
$arr[$friend['name']] = $bDayYear . "-" . $month . "-" . $day . "-" . $year;
}
asort($arr);
return $arr;
}
function PrintBirthdays($arr, $limit) {
$count = 0;
$today = getdate();
foreach ($arr as $name => $bday) {
list($year,$month,$day,$birthYear) = split("-", $bday);
$mName = date("M", mktime(0, 0, 0, $month, 1, 2005));
$age = ($birthYear != "") ? (int)$year - (int)$birthYear : "??";
print $mName . " " . $day . " (" . $age . "): " . $name ."\n";
if (++$count >= $limit) break;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment