A generalized analytical theory for adsorption of fluids in nanoporous materials