Fix getGlobalBlocks() to retrieve only global areas used by the collection

Rewritten DB query fixes the outputAutoHeaderItems() issue for global areas. With this fix, only global blocks used on the page are retrieved, and so only the necessary JS and CSS resources are auto-loaded.