當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Gdn_Format::getEmbedSize方法代碼示例

本文整理匯總了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 . '">';
//.........這裏部分代碼省略.........
開發者ID:ringoma,項目名稱:vanilla,代碼行數:101,代碼來源:class.format.php

示例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;
     }
 }
開發者ID:vanilla,項目名稱:vanilla,代碼行數:22,代碼來源:class.bbcode.php


注:本文中的Gdn_Format::getEmbedSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。