A scenario for the ionization of the diffuse ISM in galaxies and the IGM in clusters