[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Plugins/Autolink/ -> Configurator.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2022 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Plugins\Autolink;
   9  
  10  use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
  11  use s9e\TextFormatter\Plugins\ConfiguratorBase;
  12  
  13  class Configurator extends ConfiguratorBase
  14  {
  15      /**
  16      * @var string Name of attribute that stores the link's URL
  17      */
  18      protected $attrName = 'url';
  19  
  20      /**
  21      * @var bool Whether to match strings that start with "www."
  22      */
  23      public $matchWww = false;
  24  
  25      /**
  26      * @var string Name of the tag used to represent links
  27      */
  28      protected $tagName = 'URL';
  29  
  30      /**
  31      * Creates the tag used by this plugin
  32      *
  33      * @return void
  34      */
  35  	protected function setUp()
  36      {
  37          if (isset($this->configurator->tags[$this->tagName]))
  38          {
  39              return;
  40          }
  41  
  42          // Create a tag
  43          $tag = $this->configurator->tags->add($this->tagName);
  44  
  45          // Add an attribute using the default url filter
  46          $filter = $this->configurator->attributeFilters->get('#url');
  47          $tag->attributes->add($this->attrName)->filterChain->append($filter);
  48  
  49          // Set the default template
  50          $tag->template = '<a href="{@' . $this->attrName . '}"><xsl:apply-templates/></a>';
  51      }
  52  
  53      /**
  54      * {@inheritdoc}
  55      */
  56  	public function asConfig()
  57      {
  58          $config = [
  59              'attrName'   => $this->attrName,
  60              'regexp'     => $this->getRegexp(),
  61              'tagName'    => $this->tagName
  62          ];
  63          if (!$this->matchWww)
  64          {
  65              $config['quickMatch'] = ':';
  66          }
  67  
  68          return $config;
  69      }
  70  
  71      /**
  72      * Return the regexp used to match URLs
  73      *
  74      * @return strings
  75      */
  76  	protected function getRegexp()
  77      {
  78          $anchor = RegexpBuilder::fromList($this->configurator->urlConfig->getAllowedSchemes()) . ':';
  79          if ($this->matchWww)
  80          {
  81              $anchor = '(?:' . $anchor . '|www\\.)';
  82          }
  83  
  84          $regexp = '#\\b' . $anchor . '(?>[^\\s()\\[\\]'
  85                  . '\\x{FF01}-\\x{FF0F}\\x{FF1A}-\\x{FF20}\\x{FF3B}-\\x{FF40}\\x{FF5B}-\\x{FF65}'
  86                  . ']|\\([^\\s()]*\\)|\\[\\w*\\])++#Siu';
  87  
  88          return $regexp;
  89      }
  90  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1