Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Open Graph Protocol validator #1

Closed
wants to merge 2 commits into from

2 participants

@niallkennedy

PHP class to treat Open Graph Protocol markup as an object and validate freeform text input values. The validator class should improve the consistency of data provided to Open Graph Protocol consuming clients, normalize inputs, and help publishers correct invalid inputs before final submission.

This class is meant to serve as a base, extended with classes more specific to a consuming agent of choice (Facebook, Mixi, etc.). An ideal version of such a validator would take into consideration the addressing schemes of specific countries, but let's start semi-simple.

The Open Graph Protocol validator makes a few allowed value assumptions not specified in the current Open Graph Protocol spec:

  • Title and site name are assumed to be 128 characters or less. Description is assumed to be 255 characters or less. Makes sense to pick something reasonable here at the spec level to set expectations for publisher data displayed by consuming agents. Closest HTML corollaries: title element, meta application-name, meta description
  • Type is restricted to object types defined in the Open Graph Protocol spec. I recognize that Facebook, a major consuming agent, allows any value. Other consuming agents may define their own subset or completely different set. I expect classes extending this base class will handle these specialized cases by consuming agent target.
  • Country name is assumed to be ISO 3166-1 alpha-2 codes. This addressing follows Universal Postal Union standards and avoids differences in country names by language or popular reference.
  • Address elements, including locality and region, are assumed to be 40 characters or less. This assumption is in line with the Universal Postal Union's address format recommendations derived from Argentine standards. Technically the provided address strings should receive special treatment based on the country, but that's best left for a future enhancement.
  • Phone and fax numbers are assumed to be ITU-T E.164 numbers complete with country code, national destination code, and subscriber number. The validator currently only checks if the inputted string contains 15 or less digits, the maximum allowed E.164 address.
  • Email value assumes a RFC 822 compliant email address.
  • A shared URL is assumed to be a publicly-addressable HTML document (type text/html or application/xhtml+xml).
  • An image URL is assumed to be a publicly-addressable resource with a Content-Type media type for JPG, PNG, or GIF images. Supported image types are not specified in the Open Graph Protocol spec but is specified by Facebook's consuming agent and its safe_image proxy.
  • Audio element support. This property was introduced on the Open Graph Protocol mailing list in August and later added to Facebook Share multimedia tags markup. Audio is currently restricted to MP3 (audio/mpeg Content-Type media type) only, as used in the Facebook Share consumer.
  • Video element support. Introduced alongside audio and later added to Facebook Share. SWF (application/x-shockwave-flash Content-Type media type) only, as used in the Facebook Share consumer.
  • ISBN property allows both ISBN-10 and ISBN-13 values if an input contains a valid check digit.
  • UPC property assumes an UPC-A, UPC-B, or UPC-C input value 12 digits in length.
@ptarjan
Collaborator

Hi Niall,

Thank you so much for the validator. We'd rather not host an explicit validator but would be happy to link to yours if you host it somewhere. Just send a pull request with a link to your external page.

Thanks!

@jrweave jrweave referenced this pull request
Closed

Added og:mime_type_str . #4

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 19, 2010
  1. @niallkennedy
Commits on Nov 22, 2010
  1. @niallkennedy

    full OGP validator

    niallkennedy authored
Something went wrong with that request. Please try again.