Ejemplo n.º 1
0
 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="http://www.youtube.com/embed/' . $Code . '" frameborder="0" allowfullscreen></iframe></div>';
         default:
             return $content;
     }
 }
Ejemplo n.º 2
0
    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];
        if ((preg_match('`(?:https?|ftp)://www\\.youtube\\.com\\/watch\\?v=([^&]+)`', $Url, $Matches) || preg_match('`(?:https?)://www\\.youtu\\.be\\/([^&]+)`', $Url, $Matches)) && C('Garden.Format.YouTube')) {
            $ID = $Matches[1];
            $Result = <<<EOT
<div class="Video"><object width="{$Width}" height="{$Height}"><param name="movie" value="http://www.youtube.com/v/{$ID}&amp;hl=en_US&amp;fs=1&amp;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/{$ID}&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="{$Width}" height="{$Height}"></embed></object></div>
EOT;
        } elseif (preg_match('`(?:https?|ftp)://vimeo\\.com\\/(\\d+)`', $Url, $Matches) && C('Garden.Format.Vimeo')) {
            $ID = $Matches[1];
            $Result = <<<EOT
<div class="Video"><object width="{$Width}" height="{$Height}"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id={$ID}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id={$ID}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{$Width}" height="{$Height}"></embed></object></div>
EOT;
        } else {
            $nofollow = self::$DisplayNoFollow ? ' rel="nofollow"' : '';
            // Strip punctuation off of the end of the url.
            $Punc = '';
            if (preg_match('`^(.+)([.?,;:])$`', $Url, $Matches)) {
                $Url = $Matches[1];
                $Punc = $Matches[2];
            }
            // Get human-readable text from url.
            $Text = $Url;
            if (strpos($Text, '%') !== FALSE) {
                $Text = rawurldecode($Text);
                $Text = htmlspecialchars($Text, ENT_QUOTES, C('Garden.Charset', ''));
            }
            $Result = <<<EOT
<a href="{$Url}" target="_blank"{$nofollow}>{$Text}</a>{$Punc}
EOT;
        }
        return $Result;
    }
Ejemplo n.º 3
0
    /**
     * 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];
        $YoutubeUrlMatch = 'https?://(www\\.)?youtube\\.com\\/watch\\?(.*)?v=(?P<ID>[^&#]+)([^#]*)(?P<HasTime>#t=(?P<Time>[0-9]+))?';
        $VimeoUrlMatch = 'https?://(www\\.)?vimeo\\.com/(?:channels/[a-z0-9]+/)?(\\d+)';
        $TwitterUrlMatch = 'https?://(?:www\\.)?twitter\\.com/(?:#!/)?(?:[^/]+)/status(?:es)?/([\\d]+)';
        $GithubCommitUrlMatch = 'https?://(?:www\\.)?github\\.com/([^/]+)/([^/]+)/commit/([\\w\\d]{40})';
        $VineUrlMatch = 'https?://(?:www\\.)?vine.co/v/([\\w\\d]+)';
        $InstagramUrlMatch = 'https?://(?:www\\.)?instagr(?:\\.am|am\\.com)/p/([\\w\\d]+)';
        $PintrestUrlMatch = 'https?://(?:www\\.)?pinterest.com/pin/([\\d]+)';
        $GettyUrlMatch = 'http://embed.gettyimages.com/([\\w\\d=?&;+-_]*)/([\\d]*)/([\\d]*)';
        // Youtube
        if ((preg_match("`{$YoutubeUrlMatch}`", $Url, $Matches) || preg_match('`(?:https?)://(www\\.)?youtu\\.be\\/(?P<ID>[^&#]+)(?P<HasTime>#t=(?P<Time>[0-9]+))?`', $Url, $Matches)) && C('Garden.Format.YouTube', true) && !C('Garden.Format.DisableUrlEmbeds')) {
            $ID = $Matches['ID'];
            $TimeMarker = isset($Matches['HasTime']) ? '&amp;start=' . $Matches['Time'] : '';
            $Result = '<span class="VideoWrap">';
            $Result .= '<span class="Video YouTube" id="youtube-' . $ID . '">';
            $Result .= '<span class="VideoPreview"><a href="//youtube.com/watch?v=' . $ID . '"><img src="//img.youtube.com/vi/' . $ID . '/0.jpg" width="' . $Width . '" height="' . $Height . '" border="0" /></a></span>';
            $Result .= '<span class="VideoPlayer"></span>';
            $Result .= '</span>';
            $Result .= '</span>';
            // Vimeo
        } elseif (preg_match("`{$VimeoUrlMatch}`", $Url, $Matches) && C('Garden.Format.Vimeo', true) && !C('Garden.Format.DisableUrlEmbeds')) {
            $ID = $Matches[2];
            $Result = <<<EOT
      <iframe src="//player.vimeo.com/video/{$ID}" width="{$Width}" height="{$Height}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
EOT;
            // Twitter
        } elseif (preg_match("`{$TwitterUrlMatch}`", $Url, $Matches) && C('Garden.Format.Twitter', true) && !C('Garden.Format.DisableUrlEmbeds')) {
            $Result = <<<EOT
<div class="twitter-card" data-tweeturl="{$Matches[0]}" data-tweetid="{$Matches[1]}"><a href="{$Matches[0]}" class="tweet-url" rel="nofollow" target="_blank">{$Matches[0]}</a></div>
EOT;
            // Github
            // @tim : 2013-08-22
            // Experiment on hold
            //
            //      } elseif (preg_match("`{$GithubCommitUrlMatch}`", $Url, $Matches) && C('Garden.Format.Github', true)) {
            //         $Result = <<<EOT
            //<div class="github-commit" data-commiturl="{$Matches[0]}" data-commituser="******" data-commitrepo="{$Matches[2]}" data-commithash="{$Matches[3]}"><a href="{$Matches[0]}" class="commit-url" rel="nofollow" target="_blank">{$Matches[0]}</a></div>
            //EOT;
            // Vine
        } elseif (preg_match("`{$VineUrlMatch}`i", $Url, $Matches) && C('Garden.Format.Vine', true) && !C('Garden.Format.DisableUrlEmbeds')) {
            $Result = <<<EOT
<div class="VideoWrap">
   <iframe class="vine-embed" src="//vine.co/v/{$Matches[1]}/embed/simple" width="320" height="320" frameborder="0"></iframe><script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>
</div>
EOT;
            // Instagram
        } elseif (preg_match("`{$InstagramUrlMatch}`i", $Url, $Matches) && C('Garden.Format.Instagram', true) && !C('Garden.Format.DisableUrlEmbeds')) {
            $Result = <<<EOT
<div class="VideoWrap">
   <iframe src="//instagram.com/p/{$Matches[1]}/embed/" width="412" height="510" frameborder="0" scrolling="no" allowtransparency="true"></iframe>
</div>
EOT;
            // Pintrest
        } elseif (preg_match("`({$PintrestUrlMatch})`", $Url, $Matches) && C('Garden.Format.Pintrest', true) && !C('Garden.Format.DisableUrlEmbeds')) {
            $Result = <<<EOT
<a data-pin-do="embedPin" href="//pinterest.com/pin/{$Matches[2]}/" class="pintrest-pin" rel="nofollow" target="_blank"></a>
EOT;
            // Getty
        } elseif (preg_match("`({$GettyUrlMatch})`i", $Url, $Matches) && C('Garden.Format.Getty', true) && !C('Garden.Format.DisableUrlEmbeds')) {
            $Result = <<<EOT
<iframe src="//embed.gettyimages.com/embed/{$Matches[2]}" width="{$Matches[3]}" height="{$Matches[4]}" frameborder="0" scrolling="no"></iframe>
EOT;
            // Unformatted links
        } elseif (!self::$FormatLinks) {
            $Result = $Url;
            // Formatted links
        } else {
            // Strip punctuation off of the end of the url.
            $Punc = '';
            if (preg_match('`^(.+)([.?,;:])$`', $Url, $Matches)) {
                $Url = $Matches[1];
                $Punc = $Matches[2];
            }
            // Get human-readable text from url.
            $Text = $Url;
            if (strpos($Text, '%') !== FALSE) {
                $Text = rawurldecode($Text);
                $Text = htmlspecialchars($Text, ENT_QUOTES, C('Garden.Charset', ''));
            }
            $nofollow = self::$DisplayNoFollow ? ' rel="nofollow"' : '';
            $Result = <<<EOT
<a href="{$Url}" target="_blank"{$nofollow}>{$Text}</a>{$Punc}
EOT;
        }
        return $Result;
    }
Ejemplo n.º 4
0
    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];
        if ((preg_match('`(?:https?|ftp)://(www\\.)?youtube\\.com\\/watch\\?(.*)?v=(?P<ID>[^&#]+)([^#]*)(?P<HasTime>#t=(?P<Time>[0-9]+))?`', $Url, $Matches) || preg_match('`(?:https?)://(www\\.)?youtu\\.be\\/(?P<ID>[^&#]+)(?P<HasTime>#t=(?P<Time>[0-9]+))?`', $Url, $Matches)) && C('Garden.Format.YouTube')) {
            $ID = $Matches['ID'];
            $TimeMarker = isset($Matches['HasTime']) ? '&amp;start=' . $Matches['Time'] : '';
            $Result = '<div class="VideoWrap">';
            $Result .= '<div class="Video YouTube" id="youtube-' . $ID . '">';
            $Result .= '<div class="VideoPreview"><a href="http://youtube.com/watch?v=' . $ID . '"><img src="http://img.youtube.com/vi/' . $ID . '/0.jpg" width="' . $Width . '" height="' . $Height . '" border="0" /></a></div>';
            $Result .= '<div class="VideoPlayer"></div>';
            $Result .= '</div>';
            $Result .= '</div>';
        } elseif (preg_match('`(?:https?|ftp)://(www\\.)?vimeo\\.com\\/(\\d+)`', $Url, $Matches) && C('Garden.Format.Vimeo')) {
            $ID = $Matches[2];
            $Result = <<<EOT
<div class="VideoWrap"><div class="Video Vimeo"><object width="{$Width}" height="{$Height}"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id={$ID}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id={$ID}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{$Width}" height="{$Height}"></embed></object></div></div>
EOT;
        } elseif (!self::$FormatLinks) {
            $Result = $Url;
        } else {
            // Strip punctuation off of the end of the url.
            $Punc = '';
            if (preg_match('`^(.+)([.?,;:])$`', $Url, $Matches)) {
                $Url = $Matches[1];
                $Punc = $Matches[2];
            }
            // Get human-readable text from url.
            $Text = $Url;
            if (strpos($Text, '%') !== FALSE) {
                $Text = rawurldecode($Text);
                $Text = htmlspecialchars($Text, ENT_QUOTES, C('Garden.Charset', ''));
            }
            $nofollow = self::$DisplayNoFollow ? ' rel="nofollow"' : '';
            $Result = <<<EOT
<a href="{$Url}" target="_blank"{$nofollow}>{$Text}</a>{$Punc}
EOT;
        }
        return $Result;
    }