コード例 #1
0
 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);
     }
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: helisz/chrishe.bbs
 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;
 }
コード例 #3
0
ファイル: link_helper.php プロジェクト: bruninoit/phpbb
 /**
  * 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;
 }
コード例 #4
0
ファイル: TagTest.php プロジェクト: CryptArc/TextFormatter
 /**
  * @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'));
 }
コード例 #5
0
ファイル: Parser.php プロジェクト: skywalker512/FlarumChina
 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);
         }
     }
 }
コード例 #6
0
ファイル: Parser.php プロジェクト: CryptArc/TextFormatter
 /**
  * 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);
         }
     }
 }