A unified thermodynamic formulation of nonlocal and gradient plasticity