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 |
TemplateGenerator.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\Configurator;
009 use s9e\TextFormatter\Configurator\Helpers\AVTHelper;
010 abstract class TemplateGenerator
011 {
012 protected $attributes;
013 protected $defaultAttributes = array(
014 'height' => 360,
015 'padding-height' => 0,
016 'style' => array(),
017 'width' => 640
018 );
019 abstract protected function getContentTemplate();
020 public function getTemplate(array $attributes)
021 {
022 $this->attributes = $attributes + $this->defaultAttributes;
023 $prepend = $append = '';
024 if ($this->needsWrapper())
025 {
026 $this->attributes['style']['width'] = '100%';
027 $this->attributes['style']['height'] = '100%';
028 $this->attributes['style']['position'] = 'absolute';
029 $this->attributes['style']['left'] = '0';
030 $outerStyle = 'display:inline-block;width:100%;max-width:' . $this->attributes['width'] . 'px';
031 $innerStyle = 'overflow:hidden;position:relative;' . $this->getResponsivePadding();
032 $prepend .= '<div>' . $this->generateAttributes(array('style' => $outerStyle));
033 $prepend .= '<div>' . $this->generateAttributes(array('style' => $innerStyle));
034 $append .= '</div></div>';
035 }
036 else
037 {
038 $this->attributes['style']['width'] = '100%';
039 $this->attributes['style']['height'] = $this->attributes['height'] . 'px';
040 if (isset($this->attributes['max-width']))
041 $this->attributes['style']['max-width'] = $this->attributes['max-width'] . 'px';
042 elseif ($this->attributes['width'] !== '100%')
043 {
044 $property = ($this->hasDynamicWidth()) ? 'width' : 'max-width';
045 $this->attributes['style'][$property] = $this->attributes['width'] . 'px';
046 }
047 }
048 return $prepend . $this->getContentTemplate() . $append;
049 }
050 protected function expr($expr)
051 {
052 $expr = \trim($expr, '{}');
053 return (\preg_match('(^[@$]?[-\\w]+$)D', $expr)) ? $expr : "($expr)";
054 }
055 protected function getResponsivePadding()
056 {
057 $height = $this->expr($this->attributes['height']);
058 $paddingHeight = $this->expr($this->attributes['padding-height']);
059 $width = $this->expr($this->attributes['width']);
060 $css = 'padding-bottom:<xsl:value-of select="100*(' . $height . '+' . $paddingHeight . ')div' . $width . '"/>%';
061
062 if (!empty($this->attributes['padding-height']))
063 $css .= ';padding-bottom:calc(<xsl:value-of select="100*' . $height . ' div' . $width . '"/>% + ' . $paddingHeight . 'px)';
064 if (\strpos($width, '@') !== \false)
065 $css = '<xsl:if test="@width>0">' . $css . '</xsl:if>';
066 return $css;
067 }
068 protected function generateAttributes(array $attributes)
069 {
070 if (isset($attributes['style']) && \is_array($attributes['style']))
071 $attributes['style'] = $this->generateStyle($attributes['style']);
072 \ksort($attributes);
073 $xsl = '';
074 foreach ($attributes as $attrName => $attrValue)
075 {
076 $innerXML = (\strpos($attrValue, '<xsl:') !== \false) ? $attrValue : AVTHelper::toXSL($attrValue);
077 $xsl .= '<xsl:attribute name="' . \htmlspecialchars($attrName, \ENT_QUOTES, 'UTF-8') . '">' . $innerXML . '</xsl:attribute>';
078 }
079 return $xsl;
080 }
081 protected function generateStyle(array $properties)
082 {
083 \ksort($properties);
084 $style = '';
085 foreach ($properties as $name => $value)
086 $style .= $name . ':' . $value . ';';
087 return \trim($style, ';');
088 }
089 protected function hasDynamicHeight()
090 {
091 return (isset($this->attributes['onload']) && \strpos($this->attributes['onload'], '.height') !== \false);
092 }
093 protected function hasDynamicWidth()
094 {
095 return (isset($this->attributes['onload']) && \strpos($this->attributes['onload'], '.width') !== \false);
096 }
097 protected function mergeAttributes(array $defaultAttributes, array $newAttributes)
098 {
099 $attributes = \array_merge($defaultAttributes, $newAttributes);
100 if (isset($defaultAttributes['style'], $newAttributes['style']))
101 $attributes['style'] += $defaultAttributes['style'];
102 return $attributes;
103 }
104 protected function needsWrapper()
105 {
106 return ($this->attributes['width'] !== '100%' && !$this->hasDynamicHeight());
107 }
108 }