View source
<?php
function googtube_help($path, $arg) {
switch ($path) {
case 'admin/help#googtube':
$output = '<p>' . t('Googtube is a filter module that automatically converts youtube and google video urls into embedded code. Useful if users want to post videos easily.') . '</p>';
$output .= t('<p>Use Input Formats to enable the googtube filter</p>
<ol>
<li>Select an existing Input Format or add a new one</li>
<li>Configure the Input Format</li>
<li>Enable googtube filter and Save configuration</li>
<li>Rearrange the weight of the googtube filter depending on what filters exist in the format. (Before Url Filter and after HTML works for me)</li>
</ol>');
$output .= '<p>' . t('You can enable the googtube filter in an input format from <a href="/admin/config/content/formats" />admin/config/content/formats</a>') . '</p>';
return $output;
}
}
function googtube_filter_info() {
$filters['googtube'] = array(
'title' => t('Googtube filter'),
'description' => t('Googtube is a filter module that automatically converts youtube and google video urls into embedded code. Useful if users want to post videos easily.'),
'process callback' => '_googtube_process',
'tips callback' => '_googtube_tips',
);
return $filters;
}
function _googtube_tips($format, $long = false) {
return t('Youtube and google video links are automatically converted into embedded videos.');
}
function _googtube_process($text = '', $format = -1) {
$text = ' ' . $text . ' ';
$text = preg_replace_callback('#(((http://)?)|(^./))(((www.)?)|(^./))youtube\\.com/watch[?]v=([^\\[\\]()<.,\\s\\n\\t\\r]+)(?![^<]*</a>)#i', 'googtube_youtube', $text);
$text = preg_replace_callback('#(((http://)?)|(^./))(((www.)?)|(^./))video\\.google\\.(com|ca|co\\.uk)(\\.[a-z]+)?/videoplay[?]docid=([^\\[\\]()<.,\\s\\n\\t\\r]+)(?![^<]*</a>)#i', 'googtube_google', $text);
$text = preg_replace_callback('#(((http://)?)|(^./))(((www.)?)|(^./))vimeo\\.com/([0-9]+)(?![^<]*</a>)#i', 'googtube_vimeo', $text);
$text = substr($text, 1, -1);
return $text;
}
function googtube_youtube($match) {
$parsed_url = parse_url(check_url($match[0]));
parse_str($parsed_url['query'], $parsed_query);
$youtube_id = $parsed_query['v'];
return '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/' . $youtube_id . '&fs=1"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $youtube_id . '&fs=1" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="425" height="350"></embed></object>';
}
function googtube_google($match) {
$parsed_url = parse_url(check_url($match[0]));
parse_str($parsed_url['query'], $parsed_query);
$googlevideo_id = $parsed_query['docid'];
isset($parsed_query['hl']) ? $googlevideo_hl = '&hl=' . $parsed_query['hl'] : ($googlevideo_hl = '');
return '<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=' . $googlevideo_id . $googlevideo_hl . '" flashvars=""> </embed>';
}
function googtube_vimeo($match) {
$parsed_url = parse_url(check_url($match[0]));
$vimeo_id = ltrim($parsed_url[path], "/");
return '<object width="425" height="350"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' . $vimeo_id . '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' . $vimeo_id . '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="425" height="350"></embed></object>';
}