Conditional phase gate between two photons through control of the interaction time with a single atom in a cavity