filter_input() function
' );
}
// load the http GETS:
// set the parent domain if provided
$parent_domain = isset( $_GET['parent_domain'] ) ? $_GET['parent_domain'] : false;
// default to null media in not provided:
$media_url = isset( $_GET['media_url'] ) ? $_GET['media_url'] : false;
if( strval( $media_url ) === '' ){
error_out( 'invalid or missing media URL' );
}
// default duration to 30 seconds if not provided. (ideally cortado would read this from the video file)
//$duration = ( isset( $_GET['duration'] ) ) ? $_GET['duration'] : 0;
$duration = filter_input( INPUT_GET, 'duration', FILTER_SANITIZE_NUMBER_INT );
if( is_null( $duration ) || $duration === false ){
$duration = 0;
}
// id (set to random if none provided)
//$id = ( isset( $_GET['id'] ) ) ? $_GET['id'] : 'vid_' . rand( '10000000' );
$id = isset( $_GET['id'] ) ? $_GET['id'] : false;
if( is_null( $id ) || $id === false ){
$id = 'vid_' . rand( 0, 10000000 );
}
$width = filter_input( INPUT_GET, 'width', FILTER_SANITIZE_NUMBER_INT );
if( is_null( $width ) || $width === false ){
$width = 320;
}
$height = filter_input( INPUT_GET, 'height', FILTER_SANITIZE_NUMBER_INT );
// default to video:
$stream_type = ( isset( $_GET['stream_type'] ) ) ? $_GET['stream_type'] : 'video';
if( $stream_type == 'video' ){
$audio = $video = 'true';
if( is_null( $height ) || $height === false )
$height = 240;
} else { // if( $stream_type == 'audio' )
$audio = 'true';
$video = 'false';
if( is_null( $height ) || $height === false )
$height = 20;
}
// everything good output page:
output_page(array(
'id' => $id,
'media_url' => $media_url,
'audio' => $audio,
'video' => $video,
'duration' => $duration,
'width' => $width,
'height' => $height,
'parent_domain' => $parent_domain
));
}
/**
* JS escape function copied from MediaWiki's Xml::escapeJsString()
*/
function escapeJsString( $string ) {
// See ECMA 262 section 7.8.4 for string literal format
$pairs = array(
"\\" => "\\\\",
"\"" => "\\\"",
'\'' => '\\\'',
"\n" => "\\n",
"\r" => "\\r",
# To avoid closing the element or CDATA section
"<" => "\\x3c",
">" => "\\x3e",
# To avoid any complaints about bad entity refs
"&" => "\\x26",
# Work around https://bugzilla.mozilla.org/show_bug.cgi?id=274152
# Encode certain Unicode formatting chars so affected
# versions of Gecko don't misinterpret our strings;
# this is a common problem with Farsi text.
"\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER
"\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER
);
return strtr( $string, $pairs );
}
function error_out( $error = '' ){
output_page( array( 'error' => $error ) );
exit();
}
function output_page( $params ){
extract( $params );
?>