code with the appropriate pmwiki video markup ** cleaned up YouTube code ** fixed GoogleVideo bug that prevented fullscreen ** permitted option of compliant and non-compliant XHTML versions of each recipe (except FlickrVid). ** removed $YouTubeDefaultHeightFmt & ..WidthFmt (for all recipes) - default width and height are now included in $YouTubeDefaultParams, $VimeoDefaultParams, and so forth. ** replaced/updated much of the documentation * 2009-10-09 - YouTube: added 'scale' option for youtube; returned youtube code back to being xhtml 1.0 compliant; incorporated suggestion from Byron Lunz for non-XHTML-compliant version, via $YouTube_XHTMLcompliant * 2009-09-21b: YouTube: added ability to embed YouTube playlists * 2009-09-21: Updated swf-sites.php - changed YouTube code so that it accepts valid YouTube api parameters */ # Version date $RecipeInfo['SWFSites']['Version'] = '2016-05-06'; ### VIMEO # More info on new universal version: https://vimeo.com/blog:334 SDV($Vimeo_enableNewPlayer, true); SDV($VimeoSimpleEmbed, true); # some parameter names have changed - drops the "show_" in some param names SDVA($VimeoDefaultParams, array( 'width' => '400' ,'height' => '327' ,'scale' => '1' ,'title' => '1' ,'byline' => '1' ,'portrait' => '0' ,'color' => '00ADEF' # color of text ,'fullscreen' => '1' ,'autoplay' => '0' ,'loop' => '0' )); SDV($Vimeo_XHTMLcompliant, true); SDV($VimeoROEenabled, true); SDV($VimeoOverrideUserParams, ''); # make a list of the parameters above that users shouldn't have control over, as in $VimeoOverrideUserParams = 'color,fullscreen'; ##################### # EMBED (:VIMEO:) if($Vimeo_enableNewPlayer) Markup_e('vimeo', ' $ROEPatterns['!!i'] = "VimeoROE(PSS(\$m[0]))"; function VimeoROE($vimeopattern) { global $VimeoDefaultParams; preg_match("#/video/(\d+)\?*#", $vimeopattern, $matchesVideoCode); $id = $matchesVideoCode[1]; # gather all other parameters preg_match('#\?([^\"]+)\"#', $vimeopattern, $matchesParams); #echo "test: $matchesParams[1]"; break; #$params .= " scale=1 ".str_replace("&"," ",$matchesParams[1]); # replace & with space # if params aren't provided, plug in default params so that user knows what's available if($matchesParams[1]) { $paramsArray = explode("&",$matchesParams[1]); # separate params foreach($paramsArray as $arr) { # separate params into key=>val pairs, to be used in comparison with DefaultParamArray list($arrKey,$arrVal) = explode("=",$arr); $paramsArrayWithKeys[$arrKey] = $arrVal; } # add in elements from the DefaultParamArray not already provided $paramsArray = array_merge($VimeoDefaultParams,$paramsArrayWithKeys); } else { $paramsArray = $VimeoDefaultParams; } # gather parameters - width, height preg_match('#width=["\'](\d+)["\']\s+height=["\'](\d+)["\']#', $vimeopattern, $matchesWH); $paramsArray['width'] = $matchesWH[1]; $paramsArray['height'] = $matchesWH[2]; # convert back to string $params = ''; foreach($paramsArray as $key => $val) { $params .= " $key=$val"; } #echo $params; break; # output $out = "(:vimeo $id$params:)"; #echo $out; break; return $out; } # *** VIMEO-EMBED-CODE-ROE: OLD, NON-HTML5 EMBED VERSION *** # Converts pasted Vimeo embed code into valid pmwiki (:vimeo:) code $ROEPatterns['!!i'] = "VimeoOLD_ROE(PSS(\$m[0]))"; function VimeoOLD_ROE($vimeopattern) { global $VimeoDefaultParams; # gather parameters - width, height preg_match('#width=["\'](\d+)["\'] height=["\'](\d+)["\']#', $vimeopattern, $matches); $params = 'width='.$matches[1].' height='.$matches[2]; $params .= " scale=".$VimeoDefaultParams['scale']; # gather other parameters preg_match('#clip_id=(\d+)&server=vimeo.com&([^\"\']*)[\"\']#', $vimeopattern, $matchesParams); $id = $matchesParams[1]; $params .= " ".str_replace("&"," ",$matchesParams[2]); # output # remove empty 'color=' (sometimes provided by vimeo embed code) - causes error below in ParseArgs $params = preg_replace('#(color=\\s+|color=$)#','',$params); $out = "(:vimeo $id $params:)"; return $out; } } ########### ######## # *** NEW UNIVERSAL VIMEO PLAYER FUNCTION *** function ShowVimeoUniversalVideo($id, $args='', $escape='') { global $VimeoDefaultParams, $VimeoOverrideUserParams; # escape SIMPLE EMBED if url is preceded by a `, ex.: `https://... if($escape[0]=="`") return $escape[1]; # cleanup for new universal version - several params shortened from 'show_param' to 'param' (title, byline, portrait) $args = str_replace("show_","",$args); # gather up args $args = ParseArgs($args); # determine if any parameters/args should be overridden using the default values if($VimeoOverrideUserParams) { $VimeoOverrideUserParams = str_replace(" ","",$VimeoOverrideUserParams); # remove spaces foreach(explode(",",$VimeoOverrideUserParams) as $key) { $overrideArrayKeys[$key] = ''; } $args = array_diff_key($args, $overrideArrayKeys); } # add default parameters before parsing arguments $args = array_merge($VimeoDefaultParams, $args); # uses VimeoDefaultParams, unless supplied by user # define width, height & scale $scale = $args['scale']; $width = $args['width'] * $scale; $height = $args['height'] * $scale; if($args) { # remove width, height, scale params from param list, if there are any - they'll go elsewhere # all other params go into $params $args = array_diff_key($args, array('width'=>'','height'=>'','scale'=>'')); # create parameter string, in the form: ?arg1=val1&arg2=val2 $i = 0; foreach($args as $key => $val) { if ($key!='#') { #echo "$key - $val
"; if ($i!=0) $params .= "&"; $params .= "$key=$val"; $i++; } } } #echo $params; # Examples # # # OR one with more parameters # # # Output $out = ""; return Keep($out); } # *** OLD VIMEO FUNCTION *** function ShowVimeoOLDVideo($id, $args='', $escape='') { global $VimeoDefaultParams, $Vimeo_XHTMLcompliant, $VimeoOverrideUserParams; # escape SIMPLE EMBED if url is preceded by a `, ex.: `https://... if($escape[0]=="`") return $escape[1]; # gather up args $args = ParseArgs($args); # determine if any parameters/args should be overridden using the default values if($VimeoOverrideUserParams) { $VimeoOverrideUserParams = str_replace(" ","",$VimeoOverrideUserParams); # remove spaces foreach(explode(",",$VimeoOverrideUserParams) as $key) { $overrideArrayKeys[$key] = ''; } $args = array_diff_key($args, $overrideArrayKeys); } # add default parameters before parsing arguments $args = array_merge($VimeoDefaultParams, $args); # uses VimeoDefaultParams, unless supplied by user # define width & height $scale = $args['scale']; $width = $args['width'] * $scale; $height = $args['height'] * $scale; if($args) { # remove width, height, scale params if there are any - they're non-api, so not necessary for parameter string $args = array_diff_key($args, array('width'=>'','height'=>'','scale'=>'')); # create parameter string, in the form &arg1=val1&arg2=val2 $i = 0; foreach($args as $key => $val) { if ($key!='#') { #echo "$key - $val
"; $params .= "&$key=$val"; $i++; } } } $url = "https://vimeo.com/moogaloop.swf?clip_id=$id&server=vimeo.com$params"; #echo "
$url"; # Output if ($Vimeo_XHTMLcompliant) { # XHTML 1.0 COMPLIANT $out = "\n"; $out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n "; #$out .= "\n "; $out .= "\n "; $out .= "\n"; } else { $out = "\n "; $out .= "\n "; $out .= "\n "; #$out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n"; } return Keep($out); } ############################## ### YOUTUBE SDV($YouTubeSimpleEmbed, true); SDV($YouTube_enableNewPlayer, false); SDVA($YouTubeDefaultParams, array( 'width' => '425' ,'height' => '344' ,'plwidth' => '480' # slightly different default size for embedding playlists ,'plheight' => '385' # slightly different default size for embedding playlists ,'scale' => '1' ,'fs' => '1' ,'hd' => '1' ,'nocookie' => '1' )); SDV($YouTube_XHTMLcompliant, true); SDV($YouTubeROEenabled, true); SDV($YouTubeOverrideUserParams, ''); # make a list of the parameters above that users shouldn't have control over, as in $YouTubeOverrideUserParams = 'fs,width,height'; ##################### # EMBED: (:YOUTUBE:) /* if($YouTube_enableNewPlayer) Markup('youtube', ' #$ROEPatterns['!!ie'] = "YouTubeIFRAME_ROE(PSS('$0'))"; $ROEPatterns['!!i'] = "YouTubeIFRAME_ROE(PSS(\$m[0]))"; function YouTubeIFRAME_ROE($videopattern) { global $YouTubeDefaultParams; preg_match("#/embed/([^\?\"]+)[\"\?]#", $videopattern, $matchesID); $id = $matchesID[1]; #echo $id; break; $params = ''; # check for playlist #if(strpos($videocode, '/p/')) { # $params = " playlist=1 "; # $pl = 1; #} # gather all other parameters after the ?-mark if(preg_match('#\?([^\"]+)\"#', $videopattern, $matchesParams)) { # if params aren't provided, plug in default params so that user knows what's available $paramsArray = explode("&",$matchesParams[1]); # separate params foreach($paramsArray as $arr) { # separate params into key=>val pairs, to be used in comparison with DefaultParamArray list($arrKey,$arrVal) = explode("=",$arr); $paramsArrayWithKeys[$arrKey] = $arrVal; } } else { $paramsArrayWithKeys = array(); } # gather width & height preg_match('#width=["\'](\d+)["\']\s+height=["\'](\d+)["\']#', $videopattern, $matchesWH); #$params = 'width='.$matchesWH[1].' height='.$matchesWH[2]; $paramsArrayWithKeys['width'] = $matchesWH[1]; $paramsArrayWithKeys['height'] = $matchesWH[2]; # add in elements from the DefaultParamArray not already provided $paramsArray = array_merge($YouTubeDefaultParams,$paramsArrayWithKeys); # get rid of plwidth & plheight if not a playlist if(!$pl) $paramsArray = array_diff_key($paramsArray, array('plwidth'=>'','plheight'=>'')); else { # if it is a playlist, then set plwidth and plheight to width and height $paramsArray['plwidth'] = $paramsArrayWithKeys['width']; $paramsArray['plheight'] = $paramsArrayWithKeys['height']; # remove regular width and height params, leave behind plwidth and plheight $paramsArray = array_diff_key($paramsArray, array('width'=>'','height'=>'')); } # convert back to string foreach($paramsArray as $key => $val) { $params .= " $key=$val"; } #echo $params; break; # output $out = "(:youtube $id$params:)"; #echo $out; break; return $out; } # *** YOUTUBE-EMBED-CODE-ROE: OLD NON-IFRAME EMBED VERSION *** $ROEPatterns['!!i'] = "YouTubeROE_NONIFRAME(PSS(\$m[0]))"; function YouTubeROE_NONIFRAME($videocode) { global $YouTubeDefaultParams; # get videoID preg_match('#/[vp]/([^\?]+)\?#', $videocode, $matchesID); $id = $matchesID[1]; $params = ''; # check for playlist if(strpos($videocode, '/p/')) { $params = " playlist=1 "; $pl = 1; } # gather width & height preg_match('#val pairs, to be used in comparison with DefaultParamArray list($arrKey,$arrVal) = explode("=",$arr); $paramsArrayWithKeys[$arrKey] = $arrVal; } # add in elements from the DefaultParamArray not already provided $paramsArray = array_merge($YouTubeDefaultParams,$paramsArrayWithKeys); # get rid of plwidth & plheight if not a playlist if(!$pl) $paramsArray = array_diff_key($paramsArray, array('plwidth'=>'','plheight'=>'')); else { # if it is a playlist, then set plwidth and plheight to width and height $paramsArray['plwidth'] = $paramsArrayWithKeys['width']; $paramsArray['plheight'] = $paramsArrayWithKeys['height']; # remove regular width and height params, leave behind plwidth and plheight $paramsArray = array_diff_key($paramsArray, array('width'=>'','height'=>'')); } # convert back to string foreach($paramsArray as $key => $val) { $params .= " $key=$val"; } #echo $params; break; # append extra parameters after the videocode $out = "(:youtube $id$params:)"; return $out; } } ################# # *** NEW YOUTUBE PLAYER USING IFRAME *** # EXPERIMENTAL -- most parameters don't seem to be working yet function ShowYouTubeIFRAME($id, $args='', $escape='') { global $YouTubeDefaultParams, $YouTubeOverrideUserParams; # escape SIMPLE EMBED if url is preceded by a `, ex.: `https://... if($escape[0]=="`") return $escape[1]; # gather args $args = ParseArgs($args); # user input only - will check it against default values below # time argument conversion -- convert t=2m30s to start=150 ## only used for https://youtu.be/NNN?t=2m30s - unfortunately the t-param doesn't work in the embed code if($args['t']) { # note: sometimes on minutes or seconds are included ?t=2m or ?t=20s preg_match('#((\d+)m)?((\d+)s)?#i',$args['t'],$matches); $mins = $matches[2]; $secs = $matches[4]; # set start time $args['start'] = ($mins * 60) + $secs; # now remove 't' arg unset($args['t']); } # determine if any parameters/args should be overridden using the default values if($YouTubeOverrideUserParams) { $YouTubeOverrideUserParams = str_replace(" ","",$YouTubeOverrideUserParams); # remove spaces foreach(explode(",",$YouTubeOverrideUserParams) as $key) { $overrideArrayKeys[$key] = ''; } $args = array_diff_key($args, $overrideArrayKeys); } # add default parameters before parsing arguments $args = array_merge($YouTubeDefaultParams, $args); # uses VimeoDefaultParams, unless supplied by user # check to see if it's a regular video, or a playlist consisting of many videos if ($args['playlist']=="1" || $args['playlist']=="true") { $vidtype = 'p'; $playlist_flag = true; } else $vidtype = 'v'; # define width & height & scale if ($args['width']) { # use user-supplied width if it's supplied $width = $args['width']; } else { # default vals: check to see if it's a regular video, or a playlist consisting of many videos if ($playlist_flag) $width = $YouTubeDefaultParams['plwidth']; else $width = $YouTubeDefaultParams['width']; } if ($args['height']) { # use user-supplied height if it's supplied $height = $args['height']; } else { # default vals: check to see if it's a regular video, or a playlist consisting of many videos if ($playlist_flag) $height = $YouTubeDefaultParams['plheight']; else $height = $YouTubeDefaultParams['height']; } ## one can supply a 'scale' default different than '1', but it's not suggested, as it could be confusing to users if ($args['scale']) $scale = $args['scale']; else $scale = $YouTubeDefaultParams['scale']; $width = $width * $scale; $height = $height * $scale; # if not a playlist, remove plwidth and plheight from default array in order to elimnate them if($vidtype=="v") { $YouTubeDefaultParams = array_diff_key($YouTubeDefaultParams, array('plwidth'=>'','plheight'=>'')); } # get cookie info before array is cleared from the api-array $nocookieArg = $args['nocookie']; # create api-url - need to clear out non-api params first if($args) { # remove width, height, scale, playlist and nocookie params if present - not necessary for parameter string $args = array_diff_key($args, array('width'=>'','height'=>'','plwidth'=>'','plheight'=>'','scale'=>'','playlist'=>'','nocookie'=>'')); # create parameter string, in the form ?arg1=val1&arg2=val2 $params = ''; $i = 0; foreach($args as $key => $val) { if ($key!='#') { #echo "$key - $val
"; if($i!=0) $params .= "&"; $params .= "$key=$val"; $i++; } } } if ($params) $params = "?$params"; #echo $params; break; /* # Privacy: NoCookie Option if ($YouTubeDefaultParams['nocookie'] || $nocookieArg) $url = "https://www.youtube-nocookie.com/$vidtype/$id$params"; else $url = "https://www.youtube.com/$vidtype/$id$params"; */ # Examples # # Output $out = ""; return Keep($out); } # *** OLD YOUTUBE PLAYER USING OBJECT & EMBED *** function ShowYouTubeOLD($id, $args='', $escape='') { global $YouTubeDefaultParams, $YouTube_XHTMLcompliant, $YouTubeOverrideUserParams; # escape SIMPLE EMBED if url is preceded by a `, ex.: `https://... if (isset($escape[0])) if($escape[0]=="`") return $escape[1]; # $args here is unlike the other recipes in that it waits to see if it's a playlist, and checks for the presence width/height params before combining default and current param-arrays. this is to make sure default values are implemented correctly $args = ParseArgs($args); # user input only - will check it against default values below # time argument conversion -- convert t=2m30s to start=150 ## only used for https://youtu.be/NNN?t=2m30s - unfortunately the t-param doesn't work in the embed code if(isset($args['t'])) { # note: sometimes on minutes or seconds are included ?t=2m or ?t=20s preg_match('#((\d+)m)?((\d+)s)?#i',$args['t'],$matches); $mins = $matches[2]; $secs = $matches[4]; # set start time $args['start'] = ($mins * 60) + $secs; # now remove 't' arg unset($args['t']); } # determine if any parameters/args should be overridden using the default values if($YouTubeOverrideUserParams) { $YouTubeOverrideUserParams = str_replace(" ","",$YouTubeOverrideUserParams); # remove spaces foreach(explode(",",$YouTubeOverrideUserParams) as $key) { $overrideArrayKeys[$key] = ''; } $args = array_diff_key($args, $overrideArrayKeys); } # add default parameters before parsing arguments $args = array_merge($YouTubeDefaultParams, $args); # check to see if it's a regular video, or a playlist consisting of many videos if (isset($args['playlist'])){ if ($args['playlist']=="1" || $args['playlist']=="true") { $vidtype = 'p'; $playlist_flag = true; $args['nocookie'] = 0; # playlists at this point won't play using the youtube-nocookie.com address } } else $vidtype = 'v'; # get cookie info before array is cleared from the api-array $nocookieArg = $args['nocookie']; # define width & height & scale if ($args['width']) { # use user-supplied width if it's supplied $width = $args['width']; } else { # default vals: check to see if it's a regular video, or a playlist consisting of many videos if ($playlist_flag) $width = $YouTubeDefaultParams['plwidth']; else $width = $YouTubeDefaultParams['width']; } if ($args['height']) { # use user-supplied height if it's supplied $height = $args['height']; } else { # default vals: check to see if it's a regular video, or a playlist consisting of many videos if ($playlist_flag) $height = $YouTubeDefaultParams['plheight']; else $height = $YouTubeDefaultParams['height']; } ## one can supply a 'scale' default different than '1', but it's not suggested, as it could be confusing to users if ($args['scale']) $scale = $args['scale']; else $scale = $YouTubeDefaultParams['scale']; $width = $width * $scale; $height = $height * $scale; # create api-url - need to clear out non-api params first if($args) { # remove width, height, scale, playlist and nocookie params if present - not necessary for parameter string $args = array_diff_key($args, array('width'=>'','height'=>'','plwidth'=>'','plheight'=>'','scale'=>'','playlist'=>'','nocookie'=>'')); # create parameter string, in the form ?arg1=val1&arg2=val2 $params = "?"; $i = 0; foreach($args as $key => $val) { if ($key!='#') { #echo "$key - $val
"; if($i!=0) $params .= "&"; $params .= "$key=$val"; $i++; } } } # Privacy: NoCookie Option # note: nocookie currently only works in this OLD version of the youtube markup, PLUS it doesn't currently work with playlists if ($nocookieArg) $url = "https://www.youtube-nocookie.com/$vidtype/$id$params"; else $url = "https://www.youtube.com/$vidtype/$id$params"; # Output if ($YouTube_XHTMLcompliant) { # XHTML 1.0 COMPLIANT $out = "\n"; $out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n"; } else { $out = "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n "; $out .= "\n"; } return Keep($out); } ############## ### GOOGLEVIDEO SDV($GoogleVideoSimpleEmbed, true); SDV($GoogleVideo_XHTMLcompliant, true); SDV($GoogleVideoROEenabled, true); SDVA($GoogleVideoDefaultParams, array( 'width' => '400' ,'height' => '326' ,'scale' => '1' ,'autoplay' => '' ,'playerMode' => 'embedded' ,'fs' => 'true' )); /* possible arguments: * width & height * scale * fs (fullscreen): true (default) or false * autoPlay: true or false (default) * initialTime: start-time in seconds (default is 0) * loop: true or false (default) * showShareButtons: true or false (default) (not sure if this works) * playerMode: embedded (default): the standard skin; simple (a basic version of the player without progress bar and volume control); mini (even more basic); clickToPlay (the skin used for video ads); more info here: https://googlesystem.blogspot.com/2006/11/customize-embedded-google-video-player.html */ ##################### # EMBED (:GOOGLEVIDEO:) Markup_e('googlevideo', '!i'] = "GoogleVideoROE(PSS(\$m[0]))"; SDV($GoogleVideoROEFmt, '(:googlevideo $1 scale=1:)'); function GoogleVideoROE($videocode) { global $GoogleVideoROEFmt; $out = preg_replace('#^.*docid=([^&]+)&.*$#', $GoogleVideoROEFmt, $videocode); return $out; } } function ShowGoogleVideo($id, $args='', $escape='') { global $GoogleVideoDefaultParams, $GoogleVideo_XHTMLcompliant; # escape SIMPLE EMBED if url is preceded by a `, ex.: `https://... if($escape[0]=="`") return $escape[1]; # add default parameters before parsing arguments $args = array_merge($GoogleVideoDefaultParams, ParseArgs($args)); # uses GoogleVideoDefaultParams, unless supplied by user # define width & height ## one can supply a 'scale' default different than '1', but it's not suggested, as it could be confusing to users $scale = $args['scale']; $width = $args['width'] * $scale; $height = $args['height'] * $scale; # other arguments # NOTE: GoogleVideo does not understand arg=false - it treats this the same as if stating arg=true. therefore, we must exclude any false statement, and only include the arg if it's set to true if($args) { # remove width, height, scale params if there are any - they're non-api, so not necessary for parameter string $args = array_diff_key($args, array('width'=>'','height'=>'','scale'=>'')); # create parameter string, in the form &arg1=val1&arg2=val2 foreach($args as $key => $val) { if ($key!='#') { #echo "$key - $val
"; # don't use param if it's set to 0 or false or nil if($val!=="0" && $val!=="false" && $val!='') $params .= "&$key=$val"; } } } $url = "https://video.google.com/googleplayer.swf?docId=$id$params"; #echo "$url
"; # Output if ($GoogleVideo_XHTMLcompliant) { # XHTML 1.0 COMPLIANT $out = "\n