Phase Diagram of Restricted Boltzmann Machines and Generalised Hopfield Networks with Arbitrary Priors