@param array  $fields
@param string $tag

@return null|string
174391
private static function parseFetchTdTable($fields, $tag = 'td')
    {

        $td_fetch = null;
        foreach ($fields as $h) {

            $attrs = array();
            $value = null;

            if (is_array($h)) {
                $attrs   = isset($h["@attrs"]) ? $h["@attrs"] : array();
                $value   = isset($h['value']) ? $h['value'] : null;

            }
            else {
                $value = $h;
            }

            $td_fetch .= self::tag($tag, $value, null, null, $attrs);
        }

        return $td_fetch;

    }
968206
public function getCreators($tag = null)
    {
        $tag = is_null($tag) ? [] : (is_array($tag) ? $tag : [$tag]);

        return array_values(array_filter(Person::get($this), function (Person $person) use ($tag) {
            return empty($tag) || in_array($person->getType(), $tag);
        }));
    }
632333
public function detachTags($tags = null)
    {
        ! $tags || $tags = $this->parseTags($tags);

        $this->tags()->detach($tags);

        return $this;
    }
81887
public function selectByTags(array $tags)
    {
        if (count($tags) < 1) {
            throw new HrcException('You need to provide at least one tag.');
        }

        $tagFolder = str_replace($this->indexDir, '',
            rtrim($this->createFolderNameFromTags($tags), DIRECTORY_SEPARATOR));

        $result = glob($this->indexDir . '*' . $tagFolder . '*/*/*/*/index.db');
        if (!$result) {
            return false;
        }

        $keys = [];

        // open and read the index
        $ct = time();
        $entriesToDelete = [];
        foreach ($result as $index) {
            $indexHandler = fopen($index, 'r');
            while (($i = fread($indexHandler, 42))) {
                // validate timestamp
                $ttl = substr($i, 32, 10);
                if ($ttl > $ct) {
                    $keys[] = $i;
                } else {
                    $entriesToDelete[] = $i;
                }
            }
            // close the handler
            fclose($indexHandler);
        }

        // check if there are expired entries we need to delete
        foreach ($entriesToDelete as $i => $k) {
            $this->deleteEntryByKey(substr($k, 0, 32));
        }

        return $keys;
    }
1233444
private function getTagIdByName( $tag )
    {
        $tagSql = $this->sql( $this->getTableInSchema( static::$tagTableName ) );

        $select = $tagSql->select()
                         ->columns( array( 'id' ) )
                         ->where( array(
                             new TypedParameters(
                                 'LOWER(?) = ?',
                                 array(
                                     'name',
                                     mb_strtolower( $tag, 'UTF-8' ),
                                 ),
                                 array(
                                     TypedParameters::TYPE_IDENTIFIER,
                                     TypedParameters::TYPE_VALUE,
                                 )
                             ),
                         ) );

        $result = $tagSql->prepareStatementForSqlObject( $select )
                         ->execute();

        foreach ( $result as $row )
        {
           return $row['id'];
        }

        return null;
    }
701631
static function tagsToString( array $tags ) {

		$tags = wp_list_sort( $tags, 'tag', 'asc' );

		$str = '';
		foreach ( $tags as $tag ) {
			$str .= $tag['tag'] . ', ';
		}

		return rtrim( $str, ', ' );
	}
540667
public static function tag($tag, $content = null, array $attributes = array())
    {
        return self::openTag($tag, $attributes) . $content . self::closeTag($tag);
    }
783959
function deleteFields($tag, $pcre = null)
    {
        $cnt = 0;
        foreach ($this->getFields() as $field) {
            if (($pcre
                && preg_match("/$tag/", $field->getTag()))
                || (!$pcre
                && $tag == $field->getTag())
            ) {
                $field->delete();
                $cnt++;
            }
        }
        return $cnt;
    }
802007
public function getByTag($tags, $byIntersect = false) {
		$backend = $this->getBackend();
		
		if (! $backend instanceof TaggableInterface) {
			throw new NoTagsSupported('Unable to fetch a data by the tag(s) due to the tags does not supported by the backend "' . get_class($backend) . '"');
		}
		
		if (is_array($tags)) {
			$tags = array_map([$this, 'prepareId'], $tags);
		} else {
			$tags = $this->prepareId($tags);
		}
		
		$result = $backend->getByTag($tags, $byIntersect);
		
		if (empty($result) || $this->_namespace === null) {
			return $result;
		}
		
		$processedIds = [];
		$namespaceLen = strlen($this->_namespace) + 1;
		
		foreach (array_keys($result) as $id) {
			$processedIds[] = substr($id, $namespaceLen);
		}
		
		return array_combine($processedIds, array_values($result));
	}
94363
public function getValuesByTag(string $tag): array
    {
        $result = array();

        foreach ($this->_definition as $key => $value) {
            $tags = $this->getFieldProperty($key, 'tags');

            if (is_array($tags) && in_array($tag, $tags)) {
                $result[$key] = $this->$key;
            }
        }

        return $result;
    }
796325
public function begin_tag($tag, $attributes = null) {
        // TODO: chek the tag name is valid
        $pre = $this->level ? "\n" . str_repeat(' ', $this->level * 2) : ''; // Indent
        $tag = $this->casefolding ? strtoupper($tag) : $tag; // Follow casefolding
        $end = $this->nullcontent ? ' /' : ''; // Tag without content, close it

        // Build attributes output
        $attrstring = '';
        if (!empty($attributes) && is_array($attributes)) {
            // TODO: check the attr name is valid
            foreach ($attributes as $name => $value) {
                $name = $this->casefolding ? strtoupper($name) : $name; // Follow casefolding
                $attrstring .= ' ' . $name . '="'.
                    $this->xml_safe_attr_content($value) . '"';
            }
        }

        // Optional xml schema definition (level 0 only)
        $schemastring = '';
        if ($this->level == 0 && !empty($this->xmlschema)) {
            $schemastring .= "\n    " . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
                             "\n    " . 'xsi:noNamespaceSchemaLocation="' . $this->xml_safe_attr_content($this->xmlschema) . '"';
        }

        // Send to xml_output
        $this->write($pre . '<' . $tag . $attrstring . $schemastring . $end . '>');

        // Acumulate the tag and inc level
        if (!$this->nullcontent) {
            array_push($this->opentags, $tag);
            $this->level++;
        }
        $this->lastwastext = false;
    }
1059730
public static function serializeTags(array $tags)
    {
        if (empty($tags))
            return '';

        self::validateTags($tags);
        $tagstrs = array();
        foreach ($tags as $tag)
            $tagstrs[] = $tag->toString(true);

        return implode(';', $tagstrs);
    }
592066
public function fields(array $fields = null) {
        if ($fields === null) {
            return $this->fields;
        }

        $this->fields = $fields;

        return $this;
    }
142447
public Field field(int tag) {
    for (Field field : declaredFields) {
      if (field.tag() == tag) {
        return field;
      }
    }
    for (Field field : extensionFields) {
      if (field.tag() == tag) {
        return field;
      }
    }
    return null;
  }
1332949
public function findOrCreate(array $tags)
    {
        $foundTags = $this->findWhereIn(['tag', $tags]);

        $returnTags = [];

        if ($foundTags) {
            foreach ($foundTags as $tag) {
                $pos = array_search($tag->tag, $tags);

                // Add returned tags to array
                if ($pos !== false) {
                    $returnTags[] = $tag;
                    unset($tags[$pos]);
                }
            }
        }

        // Add remainings tags as new
        foreach ($tags as $tag) {
            $returnTags[] = $this->create([
                'tag' => $tag,
                'slug' => Str::slug($tag),
            ]);
        }

        return $returnTags;
    }
911950
private function getTransformerTag(array $tags)
    {
        $transFormerTags = array_values(
            array_filter($tags, function ($tag) {
                return ($tag instanceof Tag) && in_array(strtolower($tag->getName()), ['transformer', 'transformercollection']);
            })
        );

        return array_first($transFormerTags);
    }
796336
private function getContextualTags(array $tags)
    {
        foreach ($tags as &$tag) {
            $tag = $this->getContextualId($tag);
        }
        unset($tag);

        return $tags;
    }