Regarding the first part of your question,they have just inserted a complete set of basis because $|\phi>$ is a basis in some infinite dimensional Hilbert space (in your case), therefore sum (integral) of all such bases is identity on the Hilbert space. Note that in second part
$<r|\phi>$$\langle r|\phi\rangle$=$\phi(r)$.