Variational theory of bubbly media with a distribution of bubble sizes—II. Porous solids