protected static function addTagFromMediaUrl(Tag $tag, TagStack $tagStack, array $sites) { $p = \parse_url($tag->getAttribute('url')); if (isset($p['scheme']) && isset($sites[$p['scheme'] . ':'])) { $siteId = $sites[$p['scheme'] . ':']; } elseif (isset($p['host'])) { $siteId = self::findSiteIdByHost($p['host'], $sites); } if (!empty($siteId)) { self::addSiteTag($tag, $tagStack, $siteId); } }
public static function scrape(Tag $tag, array $scrapeConfig, $cacheDir = \null) { if (!$tag->hasAttribute('url')) { return \true; } $url = $tag->getAttribute('url'); if (!\preg_match('#^https?://[^<>"\'\\s]+$#D', $url)) { return \true; } foreach ($scrapeConfig as $scrape) { self::scrapeEntry($url, $tag, $scrape, $cacheDir); } return \true; }
/** * Truncate the replacement text set in a LINK_TEXT tag * * @param \s9e\TextFormatter\Parser\Tag $tag LINK_TEXT tag * @return bool Always true to indicate that the tag is valid */ public function truncate_text(\s9e\TextFormatter\Parser\Tag $tag) { $text = $tag->getAttribute('text'); if (utf8_strlen($text) > 55) { $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); } $tag->setAttribute('text', $text); return true; }
/** * @testdox getAttribute('foo') returns the value of attribute 'foo' */ public function testGetAttribute() { $tag = new Tag(Tag::START_TAG, 'X', 0, 0); $tag->setAttribute('foo', 'bar'); $this->assertSame('bar', $tag->getAttribute('foo')); }
protected static function executeAttributePreprocessor(Tag $tag, $attrName, $regexp, $map) { $attrValue = $tag->getAttribute($attrName); $captures = self::getNamedCaptures($attrValue, $regexp, $map); foreach ($captures as $k => $v) { if ($k === $attrName || !$tag->hasAttribute($k)) { $tag->setAttribute($k, $v); } } }
/** * Execute an attribute preprocessor * * @param Tag $tag * @param string $attrName * @param string $regexp * @param string[] $map * @return void */ protected static function executeAttributePreprocessor(Tag $tag, $attrName, $regexp, $map) { $attrValue = $tag->getAttribute($attrName); $captures = self::getNamedCaptures($attrValue, $regexp, $map); foreach ($captures as $k => $v) { // Attribute preprocessors cannot overwrite other attributes but they can // overwrite themselves if ($k === $attrName || !$tag->hasAttribute($k)) { $tag->setAttribute($k, $v); } } }