Phase diagram of the two-dimensional extended Hubbard model: pairing from charge and spin fluctuations