[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phriction/markup/ -> PhrictionRemarkupRule.php (source)

   1  <?php
   2  
   3  final class PhrictionRemarkupRule extends PhutilRemarkupRule {
   4  
   5    public function getPriority() {
   6      return 175.0;
   7    }
   8  
   9    public function apply($text) {
  10      return preg_replace_callback(
  11        '@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U',
  12        array($this, 'markupDocumentLink'),
  13        $text);
  14    }
  15  
  16    public function markupDocumentLink($matches) {
  17  
  18      $link = trim($matches[1]);
  19      $name = trim(idx($matches, 2, $link));
  20      if (empty($matches[2])) {
  21        $name = explode('/', trim($name, '/'));
  22        $name = end($name);
  23      }
  24  
  25      $uri      = new PhutilURI($link);
  26      $slug     = $uri->getPath();
  27      $fragment = $uri->getFragment();
  28      $slug     = PhabricatorSlug::normalize($slug);
  29      $slug     = PhrictionDocument::getSlugURI($slug);
  30      $href     = (string)id(new PhutilURI($slug))->setFragment($fragment);
  31  
  32      $text_mode = $this->getEngine()->isTextMode();
  33      $mail_mode = $this->getEngine()->isHTMLMailMode();
  34  
  35      if ($this->getEngine()->getState('toc')) {
  36        $text = $name;
  37      } else if ($text_mode || $mail_mode) {
  38        return PhabricatorEnv::getProductionURI($href);
  39      } else {
  40        $text = $this->newTag(
  41          'a',
  42          array(
  43            'href'  => $href,
  44            'class' => 'phriction-link',
  45          ),
  46          $name);
  47      }
  48  
  49      return $this->getEngine()->storeText($text);
  50    }
  51  
  52  }


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