Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Configurator.php
001 <?php
002
003 /*
004 * @package s9e\TextFormatter
005 * @copyright Copyright (c) 2010-2016 The s9e Authors
006 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
007 */
008 namespace s9e\TextFormatter\Plugins\MediaEmbed;
009 use InvalidArgumentException;
010 use RuntimeException;
011 use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
012 use s9e\TextFormatter\Configurator\Items\Attribute;
013 use s9e\TextFormatter\Configurator\Items\AttributeFilters\RegexpFilter;
014 use s9e\TextFormatter\Configurator\Items\AttributePreprocessor;
015 use s9e\TextFormatter\Configurator\Items\Tag;
016 use s9e\TextFormatter\Plugins\ConfiguratorBase;
017 use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\Collections\CachedDefinitionCollection;
018 use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\Collections\SiteCollection;
019 use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\TemplateBuilder;
020 class Configurator extends ConfiguratorBase
021 {
022 public $allowedFilters = array(
023 'hexdec',
024 'urldecode'
025 );
026 protected $appendTemplate = '';
027 protected $captureURLs = \true;
028 protected $collection;
029 protected $createMediaBBCode = \true;
030 public $createIndividualBBCodes = \false;
031 public $defaultSites;
032 protected $tagName = 'MEDIA';
033 protected $templateBuilder;
034 protected function setUp()
035 {
036 $this->collection = new SiteCollection;
037 $this->configurator->registeredVars['mediasites'] = $this->collection;
038 $tag = $this->configurator->tags->add($this->tagName);
039 $tag->rules->autoClose();
040 $tag->rules->denyChild($this->tagName);
041 $tag->filterChain->clear();
042 $tag->filterChain
043 ->append(array(__NAMESPACE__ . '\\Parser', 'filterTag'))
044 ->addParameterByName('parser')
045 ->addParameterByName('mediasites')
046 ->setJS(\file_get_contents(__DIR__ . '/Parser/tagFilter.js'));
047 if ($this->createMediaBBCode)
048 $this->configurator->BBCodes->set(
049 $this->tagName,
050 array(
051 'contentAttributes' => array('url'),
052 'defaultAttribute' => 'site'
053 )
054 );
055 if (!isset($this->defaultSites))
056 $this->defaultSites = new CachedDefinitionCollection;
057 $this->templateBuilder = new TemplateBuilder;
058 }
059 public function asConfig()
060 {
061 if (!$this->captureURLs || !\count($this->collection))
062 return;
063 $regexp = 'https?:\\/\\/';
064 $schemes = $this->getSchemes();
065 if (!empty($schemes))
066 $regexp = '(?>' . RegexpBuilder::fromList($schemes) . ':|' . $regexp . ')';
067 return array(
068 'quickMatch' => (empty($schemes)) ? '://' : ':',
069 'regexp' => '/\\b' . $regexp . '[^["\'\\s]+/Si',
070 'tagName' => $this->tagName
071 );
072 }
073 public function add($siteId, array $siteConfig = \null)
074 {
075 $siteId = $this->normalizeId($siteId);
076 if (!isset($siteConfig))
077 $siteConfig = $this->defaultSites->get($siteId);
078 $this->collection[$siteId] = $siteConfig;
079 $tag = new Tag;
080 $tag->rules->autoClose();
081 $tag->rules->denyChild($siteId);
082 $tag->rules->denyChild($this->tagName);
083 $attributes = array(
084 'url' => array('type' => 'url')
085 );
086 if (isset($siteConfig['scrape']))
087 $attributes += $this->addScrapes($tag, $siteConfig['scrape']);
088 if (isset($siteConfig['extract']))
089 foreach ((array) $siteConfig['extract'] as $regexp)
090 {
091 $attrRegexps = $tag->attributePreprocessors->add('url', $regexp)->getAttributes();
092 foreach ($attrRegexps as $attrName => $attrRegexp)
093 $attributes[$attrName]['regexp'] = $attrRegexp;
094 }
095 if (isset($siteConfig['attributes']))
096 foreach ($siteConfig['attributes'] as $attrName => $attrConfig)
097 foreach ($attrConfig as $configName => $configValue)
098 $attributes[$attrName][$configName] = $configValue;
099 $hasRequiredAttribute = \false;
100 foreach ($attributes as $attrName => $attrConfig)
101 {
102 $attribute = $tag->attributes->add($attrName);
103 if (isset($attrConfig['preFilter']))
104 $this->appendFilter($attribute, $attrConfig['preFilter']);
105 if (isset($attrConfig['type']))
106 {
107 $filter = $this->configurator->attributeFilters['#' . $attrConfig['type']];
108 $attribute->filterChain->append($filter);
109 }
110 elseif (isset($attrConfig['regexp']))
111 $attribute->filterChain->append(new RegexpFilter($attrConfig['regexp']));
112 if (isset($attrConfig['required']))
113 $attribute->required = $attrConfig['required'];
114 else
115 $attribute->required = ($attrName === 'id');
116 if (isset($attrConfig['postFilter']))
117 $this->appendFilter($attribute, $attrConfig['postFilter']);
118 if (isset($attrConfig['defaultValue']))
119 $attribute->defaultValue = $attrConfig['defaultValue'];
120 $hasRequiredAttribute |= $attribute->required;
121 }
122 if (isset($attributes['id']['regexp']))
123 {
124 $attrRegexp = \preg_replace('(\\^(.*)\\$)s', "^(?'id'$1)$", $attributes['id']['regexp']);
125 $tag->attributePreprocessors->add('url', $attrRegexp);
126 }
127 if (!$hasRequiredAttribute)
128 $tag->filterChain
129 ->append(array(__NAMESPACE__ . '\\Parser', 'hasNonDefaultAttribute'))
130 ->setJS(\file_get_contents(__DIR__ . '/Parser/hasNonDefaultAttribute.js'));
131 $tag->template = $this->templateBuilder->build($siteId, $siteConfig) . $this->appendTemplate;
132 $this->configurator->templateNormalizer->normalizeTag($tag);
133 $this->configurator->templateChecker->checkTag($tag);
134 $this->configurator->tags->add($siteId, $tag);
135 if ($this->createIndividualBBCodes)
136 $this->configurator->BBCodes->add(
137 $siteId,
138 array(
139 'defaultAttribute' => 'url',
140 'contentAttributes' => array('url')
141 )
142 );
143 return $tag;
144 }
145 public function appendTemplate($template = '')
146 {
147 $this->appendTemplate = $this->configurator->templateNormalizer->normalizeTemplate($template);
148 }
149 protected function addScrapes(Tag $tag, array $scrapes)
150 {
151 if (!isset($scrapes[0]))
152 $scrapes = array($scrapes);
153 $attributes = array();
154 $scrapeConfig = array();
155 foreach ($scrapes as $scrape)
156 {
157 $attrNames = array();
158 foreach ((array) $scrape['extract'] as $extractRegexp)
159 {
160 $attributePreprocessor = new AttributePreprocessor($extractRegexp);
161 foreach ($attributePreprocessor->getAttributes() as $attrName => $attrRegexp)
162 {
163 $attrNames[] = $attrName;
164 $attributes[$attrName]['regexp'] = $attrRegexp;
165 }
166 }
167 $attrNames = \array_unique($attrNames);
168 \sort($attrNames);
169 if (!isset($scrape['match']))
170 $scrape['match'] = '//';
171 $entry = array($scrape['match'], $scrape['extract'], $attrNames);
172 if (isset($scrape['url']))
173 $entry[] = $scrape['url'];
174 $scrapeConfig[] = $entry;
175 }
176 $tag->filterChain->insert(1, __NAMESPACE__ . '\\Parser::scrape')
177 ->addParameterByName('scrapeConfig')
178 ->addParameterByName('cacheDir')
179 ->setVar('scrapeConfig', $scrapeConfig)
180 ->setJS('returnTrue');
181 return $attributes;
182 }
183 protected function appendFilter(Attribute $attribute, $filter)
184 {
185 if (!\in_array($filter, $this->allowedFilters, \true))
186 throw new RuntimeException("Filter '" . $filter . "' is not allowed");
187 $attribute->filterChain->append($this->configurator->attributeFilters[$filter]);
188 }
189 protected function getSchemes()
190 {
191 $schemes = array();
192 foreach ($this->collection as $site)
193 if (isset($site['scheme']))
194 foreach ((array) $site['scheme'] as $scheme)
195 $schemes[] = $scheme;
196 return $schemes;
197 }
198 protected function normalizeId($siteId)
199 {
200 $siteId = \strtolower($siteId);
201 if (!\preg_match('(^[a-z0-9]+$)', $siteId))
202 throw new InvalidArgumentException('Invalid site ID');
203 return $siteId;
204 }
205 }