Example #1
0
function ValidateParamCount($a, $b = null)
{
    global $fbcmdParams;
    global $fbcmdCommand;
    $num = ParamCount();
    $showHelp = false;
    if (is_array($a)) {
        if (!in_array($num, $a)) {
            $showHelp = true;
        }
    } else {
        if ($b == null) {
            if ($num != $a) {
                $showHelp = true;
            }
        } else {
            if ($num < $a || $num > $b) {
                $showHelp = true;
            }
        }
    }
    if ($showHelp) {
        print "\n";
        FbcmdWarning("[{$fbcmdCommand}] Invalid number of parameters");
        print "\n";
        print "try:        [fbcmd help " . strtolower($fbcmdCommand) . "]\nto launch:  http://fbcmd.dtompkins.com/commands/" . strtolower($fbcmdCommand) . "\n\nbasic help:\n\n";
        ShowUsageCmd($fbcmdCommand);
        exit;
    }
}
Example #2
0
function SavePhoto($urlSource, $picObject, $tagId, $outputDir, $fileFormat, $checkSkip = true)
{
    global $fbcmdPrefs;
    $photoContents = false;
    $retry = 0;
    $fileFormat = str_replace('\\', '/', $fileFormat);
    if ($picObject) {
        $fileFormat = str_replace('[aid]', $picObject['aid'], $fileFormat);
        $fileFormat = str_replace('[pid]', $picObject['pid'], $fileFormat);
        $fileFormat = str_replace('[oid]', $picObject['owner'], $fileFormat);
        $fileFormat = str_replace('[oname]', ProfileName($picObject['owner']), $fileFormat);
    }
    if ($tagId) {
        $fileFormat = str_replace('[tid]', $tagId, $fileFormat);
        $fileFormat = str_replace('[tname]', ProfileName($tagId), $fileFormat);
    }
    $outputFile = CleanPath($outputDir) . $fileFormat;
    VerifyOutputDir($outputFile);
    if ($fbcmdPrefs['pic_skip_exists'] && $checkSkip) {
        if (file_exists($outputFile)) {
            return false;
        }
    }
    do {
        try {
            $photoContents = @file_get_contents($urlSource);
        } catch (Exception $e) {
            FbcmdWarning("[{$e->getCode()}] {$e->getMessage()}");
        }
        if ($photoContents == false) {
            if (++$retry > $fbcmdPrefs['pic_retry_count']) {
                FbcmdWarning("Could not download {$urlSource}");
                return false;
            } else {
                FbcmdWarning("Retry {$retry} :: {$urlSource}");
                sleep($fbcmdPrefs['pic_retry_delay']);
            }
        }
    } while ($photoContents == false);
    if (file_put_contents($outputFile, $photoContents) == false) {
        FbcmdWarning("Could not save {$outputFile}");
        return false;
    }
    return true;
}