Optimal Quadrature for Convex Functions and Generalizations