Skip to content

Commit

Permalink
Updated s9e\TextFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Sep 8, 2016
1 parent 02cfb7a commit 13122a1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 57 deletions.
2 changes: 1 addition & 1 deletion bundle.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "phpbb-extension",
"description": "Embed third-party content in your phpBB forum",
"homepage": "https://github.com/s9e/phpbb-ext-mediaembed/",
"version": "20160709",
"version": "20160908",
"keywords": ["phpbb","embed","forum","media"],
"license": "MIT",
"require": {
Expand Down
106 changes: 56 additions & 50 deletions parsing.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function reset($text)
$this->output = '';
$this->pos = 0;
$this->tagStack = array();
$this->tagStackIsSorted = \true;
$this->tagStackIsSorted = \false;
$this->text = $text;
$this->textLen = \strlen($text);
$this->wsPos = 0;
Expand Down Expand Up @@ -614,7 +614,7 @@ protected function createChild(Tag $tag)
$priority = -1000;
$tagPos = $this->pos + \strspn($this->text, " \n\r\t", $this->pos);
foreach ($tagConfig['rules']['createChild'] as $tagName)
$this->addStartTag($tagName, $tagPos, 0)->setSortPriority(++$priority);
$this->addStartTag($tagName, $tagPos, 0, ++$priority);
}
}
protected function fosterParent(Tag $tag)
Expand All @@ -631,13 +631,12 @@ protected function fosterParent(Tag $tag)
{
if ($parentName !== $tagName && $this->currentFixingCost < $this->maxFixingCost)
{
$child = $this->addCopyTag($parent, $tag->getPos() + $tag->getLen(), 0);
$child = $this->addCopyTag($parent, $tag->getPos() + $tag->getLen(), 0, $tag->getSortPriority() + 1);
$tag->cascadeInvalidationTo($child);
$child->setSortPriority($tag->getSortPriority() + 1);
}
$this->tagStack[] = $tag;
$this->addMagicEndTag($parent, $tag->getPos())->setSortPriority($tag->getSortPriority() - 1);
$this->currentFixingCost += \count($this->tagStack);
$this->addMagicEndTag($parent, $tag->getPos(), $tag->getSortPriority() - 1);
$this->currentFixingCost += 4;
return \true;
}
}
Expand All @@ -661,12 +660,12 @@ protected function requireAncestor(Tag $tag)
}
return \false;
}
protected function addMagicEndTag(Tag $startTag, $tagPos)
protected function addMagicEndTag(Tag $startTag, $tagPos, $prio = 0)
{
$tagName = $startTag->getName();
if ($startTag->getFlags() & self::RULE_IGNORE_WHITESPACE)
$tagPos = $this->getMagicPos($tagPos);
$endTag = $this->addEndTag($tagName, $tagPos, 0);
$endTag = $this->addEndTag($tagName, $tagPos, 0, $prio);
$endTag->pairWith($startTag);
return $endTag;
}
Expand Down Expand Up @@ -936,40 +935,41 @@ protected function tagIsAllowed($tagName)
$n = $this->tagsConfig[$tagName]['bitNumber'];
return (bool) ($this->context['allowed'][$n >> 3] & (1 << ($n & 7)));
}
public function addStartTag($name, $pos, $len)
public function addStartTag($name, $pos, $len, $prio = 0)
{
return $this->addTag(Tag::START_TAG, $name, $pos, $len);
return $this->addTag(Tag::START_TAG, $name, $pos, $len, $prio);
}
public function addEndTag($name, $pos, $len)
public function addEndTag($name, $pos, $len, $prio = 0)
{
return $this->addTag(Tag::END_TAG, $name, $pos, $len);
return $this->addTag(Tag::END_TAG, $name, $pos, $len, $prio);
}
public function addSelfClosingTag($name, $pos, $len)
public function addSelfClosingTag($name, $pos, $len, $prio = 0)
{
return $this->addTag(Tag::SELF_CLOSING_TAG, $name, $pos, $len);
return $this->addTag(Tag::SELF_CLOSING_TAG, $name, $pos, $len, $prio);
}
public function addBrTag($pos)
public function addBrTag($pos, $prio = 0)
{
return $this->addTag(Tag::SELF_CLOSING_TAG, 'br', $pos, 0);
return $this->addTag(Tag::SELF_CLOSING_TAG, 'br', $pos, 0, $prio);
}
public function addIgnoreTag($pos, $len)
public function addIgnoreTag($pos, $len, $prio = 0)
{
return $this->addTag(Tag::SELF_CLOSING_TAG, 'i', $pos, \min($len, $this->textLen - $pos));
return $this->addTag(Tag::SELF_CLOSING_TAG, 'i', $pos, \min($len, $this->textLen - $pos), $prio);
}
public function addParagraphBreak($pos)
public function addParagraphBreak($pos, $prio = 0)
{
return $this->addTag(Tag::SELF_CLOSING_TAG, 'pb', $pos, 0);
return $this->addTag(Tag::SELF_CLOSING_TAG, 'pb', $pos, 0, $prio);
}
public function addCopyTag(Tag $tag, $pos, $len)
public function addCopyTag(Tag $tag, $pos, $len, $prio = \null)
{
$copy = $this->addTag($tag->getType(), $tag->getName(), $pos, $len);
if (!isset($prio))
$prio = $tag->getSortPriority();
$copy = $this->addTag($tag->getType(), $tag->getName(), $pos, $len, $prio);
$copy->setAttributes($tag->getAttributes());
$copy->setSortPriority($tag->getSortPriority());
return $copy;
}
protected function addTag($type, $name, $pos, $len)
protected function addTag($type, $name, $pos, $len, $prio)
{
$tag = new Tag($type, $name, $pos, $len);
$tag = new Tag($type, $name, $pos, $len, $prio);
$this->createdTags[] = $tag;
if (isset($this->tagsConfig[$name]))
$tag->setFlags($this->tagsConfig[$name]['rules']['flags']);
Expand All @@ -989,24 +989,34 @@ protected function addTag($type, $name, $pos, $len)
elseif ($len < 0 || $pos < 0 || $pos + $len > $this->textLen)
$tag->invalidate();
else
{
if ($this->tagStackIsSorted
&& !empty($this->tagStack)
&& $tag->getPos() >= \end($this->tagStack)->getPos())
$this->tagStackIsSorted = \false;
$this->insertTag($tag);
return $tag;
}
protected function insertTag(Tag $tag)
{
if (!$this->tagStackIsSorted)
$this->tagStack[] = $tag;
else
{
$i = \count($this->tagStack);
while ($i > 0 && self::compareTags($this->tagStack[$i - 1], $tag) > 0)
{
$this->tagStack[$i] = $this->tagStack[$i - 1];
--$i;
}
$this->tagStack[$i] = $tag;
}
return $tag;
}
public function addTagPair($name, $startPos, $startLen, $endPos, $endLen)
public function addTagPair($name, $startPos, $startLen, $endPos, $endLen, $prio = 0)
{
$tag = $this->addStartTag($name, $startPos, $startLen);
$tag->pairWith($this->addEndTag($name, $endPos, $endLen));
return $tag;
$endTag = $this->addEndTag($name, $endPos, $endLen);
$startTag = $this->addStartTag($name, $startPos, $startLen, $prio);
$startTag->pairWith($endTag);
return $startTag;
}
public function addVerbatim($pos, $len)
public function addVerbatim($pos, $len, $prio = 0)
{
return $this->addTag(Tag::SELF_CLOSING_TAG, 'v', $pos, $len);
return $this->addTag(Tag::SELF_CLOSING_TAG, 'v', $pos, $len, $prio);
}
protected function sortTags()
{
Expand Down Expand Up @@ -1199,9 +1209,9 @@ public static function filterUrl($attrValue, array $urlConfig, Logger $logger =
}
return self::rebuildUrl($p);
}
public static function parseUrl($url)
protected static function parseUrl($url)
{
$regexp = '(^(?:([a-z][-+.\\w]*):)?(?://(?:([^:/?#]*)(?::([^/?#]*)?)?@)?(?:(\\[[a-f\\d:]+\\]|[^:/?#]+)(?::(\\d*))?)?(?![^/?#]))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$)Di';
$regexp = '(^(?:([a-z][-+.\\w]*):)?(?://(?:([^:/?#]*)(?::([^/?#]*)?)?@)?(?:(\\[[a-f\\d:]+\\]|[^:/?#]+)(?::(\\d*))?)?(?![^/?#]))?([^?#]*)(\\?[^#]*)?(#.*)?$)Di';
\preg_match($regexp, $url, $m);
$parts = array();
$tokens = array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment');
Expand Down Expand Up @@ -1237,11 +1247,7 @@ protected static function rebuildUrl(array $p)
if ($p['port'] !== '')
$url .= ':' . $p['port'];
}
$path = $p['path'];
if ($p['query'] !== '')
$path .= '?' . $p['query'];
if ($p['fragment'] !== '')
$path .= '#' . $p['fragment'];
$path = $p['path'] . $p['query'] . $p['fragment'];
$path = \preg_replace_callback(
'/%.?[a-f]/',
function ($m)
Expand Down Expand Up @@ -1373,15 +1379,16 @@ class Tag
protected $len;
protected $name;
protected $pos;
protected $sortPriority = 0;
protected $sortPriority;
protected $startTag = \null;
protected $type;
public function __construct($type, $name, $pos, $len)
public function __construct($type, $name, $pos, $len, $priority = 0)
{
$this->type = (int) $type;
$this->name = $name;
$this->pos = (int) $pos;
$this->len = (int) $len;
$this->sortPriority = (int) $priority;
}
public function addFlags($flags)
{
Expand Down Expand Up @@ -1437,6 +1444,7 @@ public function setFlags($flags)
public function setSortPriority($sortPriority)
{
$this->sortPriority = $sortPriority;
\trigger_error('setSortPriority() is deprecated. Set the priority when calling adding the tag instead. See http://s9etextformatter.readthedocs.io/Internals/API_changes/#070', \E_USER_DEPRECATED);
}
public function getAttributes()
{
Expand Down Expand Up @@ -1564,9 +1572,8 @@ public function parse($text, array $matches)
$url = $m[0][0];
$pos = $m[0][1];
$len = \strlen($url);
$tag = $this->parser->addSelfClosingTag('MEDIA', $pos, $len);
$tag = $this->parser->addSelfClosingTag('MEDIA', $pos, $len, -10);
$tag->setAttribute('url', $url);
$tag->setSortPriority(-10);
}
}
public static function filterTag(Tag $tag, TagStack $tagStack, array $sites)
Expand Down Expand Up @@ -1600,9 +1607,8 @@ protected static function addSiteTag(Tag $tag, TagStack $tagStack, $siteId)
$endTag = $tag->getEndTag() ?: $tag;
$lpos = $tag->getPos();
$rpos = $endTag->getPos() + $endTag->getLen();
$newTag = $tagStack->addSelfClosingTag(\strtoupper($siteId), $lpos, $rpos - $lpos);
$newTag = $tagStack->addSelfClosingTag(\strtoupper($siteId), $lpos, $rpos - $lpos, $tag->getSortPriority());
$newTag->setAttributes($tag->getAttributes());
$newTag->setSortPriority($tag->getSortPriority());
}
protected static function addTagFromMediaId(Tag $tag, TagStack $tagStack, array $sites)
{
Expand Down
6 changes: 3 additions & 3 deletions rendering.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/s9e/TextFormatter
Submodule TextFormatter updated 51 files
+1 −1 composer.json
+2 −2 src/Bundles/Fatdown/Renderer.php
+2 −2 src/Bundles/Forum.php
+6 −7 src/Bundles/Forum/Renderer.php
+1 −1 src/Bundles/MediaPack.php
+3 −3 src/Bundles/MediaPack/Renderer.php
+74 −114 src/Configurator.php
+25 −24 src/Configurator/Bundles/Forum.php
+6 −5 src/Configurator/JavaScript.php
+2 −2 src/Configurator/JavaScript/CallbackGenerator.php
+0 −20 src/Configurator/JavaScript/Code.php
+10 −1 src/Configurator/JavaScript/Dictionary.php
+1 −1 src/Configurator/JavaScript/Encoder.php
+1 −1 src/Configurator/JavaScript/RegexpConvertor.php
+8 −8 src/Configurator/JavaScript/StylesheetCompressor.php
+8 −6 src/Configurator/JavaScript/externs.application.js
+29 −15 src/Configurator/JavaScript/externs.service.js
+67 −47 src/Parser.js
+47 −37 src/Parser.php
+2 −10 src/Parser/BuiltInFilters.js
+3 −7 src/Parser/BuiltInFilters.php
+14 −9 src/Parser/Tag.js
+4 −2 src/Parser/Tag.php
+1 −1 src/Plugins/Autoimage/Configurator.php
+1 −2 src/Plugins/Autoimage/Parser.js
+1 −2 src/Plugins/Autoimage/Parser.php
+3 −6 src/Plugins/Autolink/Parser.js
+1 −2 src/Plugins/Autolink/Parser.php
+0 −1 src/Plugins/BBCodes/Configurator.php
+1 −1 src/Plugins/BBCodes/Configurator/BBCodeMonkey.php
+10 −1 src/Plugins/BBCodes/Parser.js
+7 −3 src/Plugins/BBCodes/Parser.php
+10 −9 src/Plugins/Censor/Configurator.php
+6 −1 src/Plugins/ConfiguratorBase.php
+3 −15 src/Plugins/Emoji/Configurator.php
+1 −3 src/Plugins/Emoji/Parser.js
+2 −3 src/Plugins/Emoji/Parser.php
+4 −5 src/Plugins/Emoticons/Configurator.php
+9 −0 src/Plugins/Emoticons/Configurator/EmoticonCollection.php
+7 −8 src/Plugins/FancyPants/Parser.js
+3 −6 src/Plugins/FancyPants/Parser.php
+0 −1 src/Plugins/HTMLElements/Configurator.php
+198 −136 src/Plugins/Litedown/Parser.js
+144 −97 src/Plugins/Litedown/Parser.php
+9 −9 src/Plugins/MediaEmbed/Configurator/CachedSiteDefinitionProvider.php
+13 −6 src/Plugins/MediaEmbed/Configurator/TemplateGenerator.php
+2 −4 src/Plugins/MediaEmbed/Parser.js
+2 −4 src/Plugins/MediaEmbed/Parser.php
+1 −2 src/Plugins/MediaEmbed/Parser/tagFilter.js
+2 −8 src/Plugins/Preg/Parser.js
+2 −8 src/Plugins/Preg/Parser.php
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"stable":{"20160709":{"current":"20160709","announcement":"https:\/\/www.phpbb.com\/community\/viewtopic.php?f=456&t=2272431","download":"https:\/\/github.com\/s9e\/phpbb-ext-mediaembed\/releases\/download\/20160709\/s9e-mediaembed-20160709.zip","eol":null,"security":false}}}
{"stable":{"20160908":{"current":"20160908","announcement":"https:\/\/www.phpbb.com\/community\/viewtopic.php?f=456&t=2272431","download":"https:\/\/github.com\/s9e\/phpbb-ext-mediaembed\/releases\/download\/20160908\/s9e-mediaembed-20160908.zip","eol":null,"security":false}}}

0 comments on commit 13122a1

Please sign in to comment.