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->setAttributes($tag->getAttributes()); $newTag->setSortPriority($tag->getSortPriority()); }
/** * Create a LINK_TEXT tag inside of a link * * Meant to only apply to linkified URLs and [url] BBCodes without a parameter * * @param \s9e\TextFormatter\Parser\Tag $tag URL tag (start tag) * @param \s9e\TextFormatter\Parser $parser Parser * @return bool Always true to indicate that the tag is valid */ public function generate_link_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser) { // Only create a LINK_TEXT tag if the start tag is paired with an end // tag, which is the case with tags from the Autolink plugins and with // the [url] BBCode when its content is used for the URL if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText())) { return true; } // Capture the text between the start tag and its end tag $start = $tag->getPos() + $tag->getLen(); $end = $tag->getEndTag()->getPos(); $length = $end - $start; $text = substr($parser->getText(), $start, $length); // Create a tag that consumes the link's text $parser->addSelfClosingTag('LINK_TEXT', $start, $length)->setAttribute('text', $text); return true; }
/** * {@inheritdoc} */ public function set_var($name, $value) { if ($name === 'max_smilies') { $this->parser->setTagLimit('E', $value ?: PHP_INT_MAX); } else { if ($name === 'max_urls') { $this->parser->setTagLimit('URL', $value ?: PHP_INT_MAX); } else { $this->parser->registeredVars[$name] = $value; } } }
public static function filterTag(Tag $tag, TagStack $tagStack, array $sites) { if ($tag->hasAttribute('media')) { $tagName = $tag->getAttribute('media'); if (!$tag->hasAttribute('id') && $tag->hasAttribute('url') && \strpos($tag->getAttribute('url'), '://') === \false) { $tag->setAttribute('id', $tag->getAttribute('url')); } } elseif ($tag->hasAttribute('url')) { $p = \parse_url($tag->getAttribute('url')); if (isset($p['scheme']) && isset($sites[$p['scheme'] . ':'])) { $tagName = $sites[$p['scheme'] . ':']; } elseif (isset($p['host'])) { $host = $p['host']; do { if (isset($sites[$host])) { $tagName = $sites[$host]; break; } $pos = \strpos($host, '.'); if ($pos === \false) { break; } $host = \substr($host, 1 + $pos); } while ($host > ''); } } if (isset($tagName)) { $endTag = $tag->getEndTag() ?: $tag; $lpos = $tag->getPos(); $rpos = $endTag->getPos() + $endTag->getLen(); $newTag = $tagStack->addSelfClosingTag(\strtoupper($tagName), $lpos, $rpos - $lpos); $newTag->setAttributes($tag->getAttributes()); $newTag->setSortPriority($tag->getSortPriority()); } return \false; }
public function __construct(array $config = null) { if (isset($config)) { parent::__construct($config); } }
/** * Add a site tag * * @param Tag $tag The original tag * @param TagStack $tagStack Parser instance, so that we can add the new tag to the stack * @param string $siteId Site ID * @return void */ protected static function addSiteTag(Tag $tag, TagStack $tagStack, $siteId) { $endTag = $tag->getEndTag() ?: $tag; // Compute the boundaries of our new tag $lpos = $tag->getPos(); $rpos = $endTag->getPos() + $endTag->getLen(); // Create a new tag and copy this tag's attributes and priority $newTag = $tagStack->addSelfClosingTag(strtoupper($siteId), $lpos, $rpos - $lpos); $newTag->setAttributes($tag->getAttributes()); $newTag->setSortPriority($tag->getSortPriority()); }
public function sortTags() { parent::sortTags(); }