Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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