$str would have to be the entire thing you posted in the first post. If your function is only returning the part you posted above, then try this:
PHP Code:
ob_start();
// call your function here
$str = ob_get_contents();
ob_end_clean();
$str = '<style type="text/css">
body {
' . $str . '
}
</style>
';
$vbulletin->templatecache['headinclude'] .= addcslashes($str, '\\"');
Also, I was assuming that your function output a string. If it returns a string, then you don't need the ob_start()/ob_end_clean() calls.