Cluster approach to phase transitions from fluid to amorphous solids: gels, glasses and granular materials