Weighted polynomials on finite and infinite intervals: a unified approach