A cocyclic construction of $S^1$-equivariant homology and application to string topology