[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/markup/rule/ -> PhabricatorYoutubeRemarkupRule.php (source)

   1  <?php
   2  
   3  final class PhabricatorYoutubeRemarkupRule extends PhutilRemarkupRule {
   4  
   5    public function getPriority() {
   6      return 350.0;
   7    }
   8  
   9    public function apply($text) {
  10      $this->uri = new PhutilURI($text);
  11  
  12      if ($this->uri->getDomain() &&
  13          preg_match('/(^|\.)youtube\.com$/', $this->uri->getDomain()) &&
  14          idx($this->uri->getQueryParams(), 'v')) {
  15        return $this->markupYoutubeLink();
  16      }
  17  
  18      return $text;
  19    }
  20  
  21    public function markupYoutubeLink() {
  22      $v = idx($this->uri->getQueryParams(), 'v');
  23      $text_mode = $this->getEngine()->isTextMode();
  24      $mail_mode = $this->getEngine()->isHTMLMailMode();
  25  
  26      if ($text_mode || $mail_mode) {
  27        return $this->getEngine()->storeText('http://youtu.be/'.$v);
  28      }
  29  
  30      $youtube_src = 'https://www.youtube.com/embed/'.$v;
  31      $iframe = $this->newTag(
  32        'div',
  33        array(
  34          'class' => 'embedded-youtube-video',
  35        ),
  36        $this->newTag(
  37          'iframe',
  38          array(
  39            'width'       => '650',
  40            'height'      => '400',
  41            'style'       => 'margin: 1em auto; border: 0px;',
  42            'src'         => $youtube_src,
  43            'frameborder' => 0,
  44          ),
  45          ''));
  46      return $this->getEngine()->storeText($iframe);
  47    }
  48  
  49  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1