本文整理汇总了PHP中Gdn_Format::getEmbedSize方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Format::getEmbedSize方法的具体用法?PHP Gdn_Format::getEmbedSize怎么用?PHP Gdn_Format::getEmbedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Format
的用法示例。
在下文中一共展示了Gdn_Format::getEmbedSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: linksCallback
/**
* Transform match to clickable links or to embedded equivalent.
*
* URLs are typically matched against, which are then translated into a
* clickable link or transformed into their equivalent embed, if supported.
* There is a universal config to disable automatic embedding.
*
* @param array $Matches Captured and grouped matches against string.
* @return string
*/
protected static function linksCallback($Matches)
{
static $Width, $Height, $InTag = 0, $InAnchor = false;
if (!isset($Width)) {
list($Width, $Height) = Gdn_Format::getEmbedSize();
}
if ($Matches === null) {
$InTag = 0;
$InAnchor = false;
return;
}
$InOut = $Matches[1];
$Tag = strtolower($Matches[2]);
// $End = $Matches[3];
// $Url = $Matches[4];
if ($InOut == '<') {
$InTag++;
if ($Tag == 'a') {
$InAnchor = true;
}
} elseif ($InOut == '</') {
$InTag++;
if ($Tag == 'a') {
$InAnchor = false;
}
} elseif ($Matches[3]) {
$InTag--;
}
if (!isset($Matches[4]) || $InTag || $InAnchor) {
return $Matches[0];
}
$Url = $Matches[4];
// Supported youtube embed urls:
//
// http://www.youtube.com/playlist?list=PL4CFF79651DB8159B
// https://www.youtube.com/playlist?list=PL4CFF79651DB8159B
// https://www.youtube.com/watch?v=sjm_gBpJ63k&list=PL4CFF79651DB8159B&index=1
// http://youtu.be/sjm_gBpJ63k
// https://www.youtube.com/watch?v=sjm_gBpJ63k
// http://YOUTU.BE/sjm_gBpJ63k?list=PL4CFF79651DB8159B
// http://youtu.be/GUbyhoU81sQ?t=1m8s
// https://m.youtube.com/watch?v=iAEKPcz9www
// https://youtube.com/watch?v=iAEKPcz9www
// https://www.youtube.com/watch?v=p5kcBxL7-qI
// https://www.youtube.com/watch?v=bG6b3V2MNxQ#t=33
$YoutubeUrlMatch = '/https?:\\/\\/(?:(?:www.)|(?:m.))?(?:(?:youtube.com)|(?:youtu.be))\\/(?:(?:playlist?)|(?:(?:watch\\?v=)?(?P<videoId>[\\w-]*)))(?:\\?|\\&)?(?:list=(?P<listId>[\\w-]*))?(?:t=(?:(?P<minutes>\\d)*m)?(?P<seconds>\\d)*s)?(?:#t=(?P<start>\\d*))?/i';
$VimeoUrlMatch = 'https?://(www\\.)?vimeo\\.com/(?:channels/[a-z0-9]+/)?(\\d+)';
$TwitterUrlMatch = 'https?://(?:www\\.)?twitter\\.com/(?:#!/)?(?:[^/]+)/status(?:es)?/([\\d]+)';
$VineUrlMatch = 'https?://(?:www\\.)?vine.co/v/([\\w]+)';
$InstagramUrlMatch = 'https?://(?:www\\.)?instagr(?:\\.am|am\\.com)/p/([\\w-]+)';
$PintrestUrlMatch = 'https?://(?:www\\.)?pinterest.com/pin/([\\d]+)';
$GettyUrlMatch = 'http://embed.gettyimages.com/([\\w=?&;+-_]*)/([\\d]*)/([\\d]*)';
$TwitchUrlMatch = 'http://www.twitch.tv/([\\w]+)';
$HitboxUrlMatch = 'http://www.hitbox.tv/([\\w]+)';
$SoundcloudUrlMatch = 'https://soundcloud.com/([\\w=?&;+-_]*)/([\\w=?&;+-_]*)';
$ImgurGifvUrlMatch = 'https?\\://i\\.imgur\\.com/([a-z0-9]+)\\.gifv';
// YouTube
if (preg_match($YoutubeUrlMatch, $Url, $Matches) && c('Garden.Format.YouTube', true) && !c('Garden.Format.DisableUrlEmbeds')) {
$videoId = val('videoId', $Matches);
$listId = val('listId', $Matches);
if (!empty($listId)) {
// Playlist.
if (empty($videoId)) {
// Playlist, no video.
$Result = <<<EOT
<iframe width="{$Width}" height="{$Height}" src="//www.youtube.com/embed/videoseries?list={$listId}" frameborder="0" allowfullscreen></iframe>
EOT;
} else {
// Video in a playlist.
$Result = <<<EOT
<iframe width="{$Width}" height="{$Height}" src="https://www.youtube.com/embed/{$videoId}?list={$listId}" frameborder="0" allowfullscreen></iframe>
EOT;
}
} else {
// Regular ol' youtube video embed.
$minutes = val('minutes', $Matches);
$seconds = val('seconds', $Matches);
$fullUrl = $videoId . '?autoplay=1';
if (!empty($minutes) || !empty($seconds)) {
$time = $minutes * 60 + $seconds;
$fullUrl .= '&start=' . $time;
}
// Jump to start time.
if ($start = val('start', $Matches)) {
$fullUrl .= '&start=' . $start;
$start = '#t=' . $start;
}
$Result = '<span class="VideoWrap">';
$Result .= '<span class="Video YouTube" data-youtube="youtube-' . $fullUrl . '">';
$Result .= '<span class="VideoPreview"><a href="//youtube.com/watch?v=' . $videoId . $start . '">';
//.........这里部分代码省略.........
示例2: doVideo
/**
* Perform formatting against a string for the video tag.
*
* @param Nbbc $bbcode Instance of Nbbc doing the parsing.
* @param int $action Value of one of NBBC's defined constants. Typically, this will be BBCODE_CHECK.
* @param string $name Name of the tag.
* @param string $default Value of the _default parameter, from the $params array.
* @param array $params A standard set parameters related to the tag.
* @param string $content Value between the open and close tags, if any.
* @return string Formatted value.
*/
function doVideo($bbcode, $action, $name, $default, $params, $content)
{
list($width, $height) = Gdn_Format::getEmbedSize();
list($type, $code) = explode(';', $default);
switch ($type) {
case 'youtube':
return "<div class=\"Video P\"><iframe width=\"{$width}\" height=\"{$height}\" src=\"https://www.youtube.com/embed/{$code}\" frameborder=\"0\" allowfullscreen></iframe></div>";
default:
return $content;
}
}