Getting Displayed User's Profile ID
$displayedUser = CBuser::getUserDataInstance( $_CB_framework->displayedUser() );
$displayedUserId = $displayedUser->get( 'id' );
Getting Viewing User's Profile ID
$viewingUser = CBuser::getMyUserDataInstance();
$viewingUserId = $viewingUser->get( 'id' );
By the way, there's no need to use 'global $_CB_framework;' twice if you're getting both the displayed and viewing user IDs. You only need it once per instance.