function emvideo_archive_extract in Embedded Media Field 6
hook emvideo_PROVIDER_extract
This is called to extract the video code from a pasted URL or embed code.
We'll be passed a URL or the embed code from a video when an editor pastes that in the field's textfield. We'll need to either pass back an array of regex expressions to match, or do the matching ourselves and return the resulting video code.
Parameters
$parse: An optional string with the pasted URL or embed code. @return Either an array of regex expressions to be tested, or a string with the video code to be used. If the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array. Otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
File
- contrib/
emvideo/ providers/ archive.inc, line 111 - This is an archive.org provider include file for Embedded Media Video.
Code
function emvideo_archive_extract($parse = '') {
// Here we assume that a URL will be passed in the form of
// http://www.archive.org/video/text-video-title
// or embed code in the form of <object value="http://www.archive.org/embed...".
// We'll simply return an array of regular expressions for Embedded Media
// Field to handle for us.
return array(
// In this expression, we're looking first for text matching the expression
// between the @ signs. The 'i' at the end means we don't care about the
// case. Thus, if someone enters http://www.Archive.com, it will still
// match. We escape periods as \., as otherwise they match any character.
// The text in parentheses () will be returned as the provider video code,
// if there's a match for the entire expression. In this particular case,
// ([^?]+) means to match one more more characters (+) that are not a
// question mark ([^\?]), which would denote a query in the URL.
'@archive\\.org\\/details\\/([^\\"\\&]+)@i',
// Now we test for embedded video code, which is similar in this case to
// the above expression, except that we can safely assume we won't have a
// query in the URL, and that the URL will be surrounded by quotation marks,
// and have /embed/ rather than /video/ in the URL. Note that regular
// expressions will be tested for matches in the order provided, so you
// may need to move this value above the other in some cases. Obviously,
// in the case of this archive provider, you could easily improve the
// regular expression to match against either a URL or embed code with
// one expression, such as '@archive\.com/[watch|embed]/([^"\?]+)@i'.
// However, many other providers have more complex requirements, so
// we split them up for this demonstration.
'@archive\\.org/download/([^/]+)=@i',
);
}