Parse delimited tags.

@param mixed $tags

@return array
324596
public static function parseDelimitedTags($tags): array
    {
        if (is_string($tags) && mb_strpos($tags, static::$tagsDelimiter) !== false) {
            $delimiter = preg_quote(static::$tagsDelimiter, '#');
            $tags = array_map('trim', preg_split("#[{$delimiter}]#", $tags, -1, PREG_SPLIT_NO_EMPTY));
        }

        return array_unique(array_filter((array) $tags));
    }
1355747
private function getTags(string $text): array
    {
        $tags    = [];
        $matches = [];

        preg_match_all('/#([^#]+)#/', $text, $matches, PREG_SET_ORDER);

        foreach ($matches as $match) {
            $params = explode(':', $match[1]);
            $method = array_shift($params);

            if (method_exists($this, $method)) {
                $tags[$match[0]] = $this->$method(...$params);
            }
        }

        return $tags;
    }
800715
public static function parseTag($tag)
    {
        $tag = explode('_', strtr(trim($tag), '-', '_'));
        $language = self::getLanguage(strtolower($tag[0]));
        $region = '';
        if (isset($tag[1])) {
            $region = self::getRegion(strtoupper($tag[1]));
        }
        return array(
            $language,
            $region
        );
    }
956533
public function findByTags(array $tags)
    {
        $qb = $this->createQueryBuilder('c');

        foreach ($tags as $key => $tag) {
            $operator = substr($tag, 0, 1);

            if ($operator === '+' || $operator === '-') {
                $tag = substr($tag, 1);
            }

            $literalExpr = $qb->expr()->literal('%'.$tag.'%');

            if ($operator === '-') {
                $qb->andWhere($qb->expr()->notLike('c.tags', $literalExpr));
            } elseif ($operator === '+') {
                $qb->andWhere($qb->expr()->like('c.tags', $literalExpr));
            } elseif ($key === 0) {
                $qb->where($qb->expr()->like('c.tags', $literalExpr));
            } else {
                $qb->orWhere($qb->expr()->like('c.tags', $literalExpr));
            }
        }

        return $qb->getQuery()->getResult();
    }
388357
private function getTypeFromTags($tags)
    {
        $tag_types = array('stylesheet', 'script');

        foreach ($tag_types as $tag) {
            if (in_array($tag, $tags)) {
                return $tag;
            }
        }

        return false;
    }
409562
public function getByTag(string $tag): array
    {
        $result = [];
        if (isset($this->tags[$tag])) {
            foreach ($this->tags[$tag] as $id) {
                $result[$id] = $this->get($id);
            }
        }

        return $result;
    }
308269
public function MetaTags(&$tags)
    {
        // Only attempt to replace <title> tag if it has been included, as it won't
        // be included if called via $MetaTags(false)
        if (preg_match("/<title>(.+)<\/title>/i", $tags)) {
            $format = Config::inst()->get(static::class, 'title_format');

            $data = ArrayData::create([
                'MetaTitle' => $this->owner->MetaTitle ? $this->owner->obj('MetaTitle') : $this->owner->obj('Title')
            ]);

            $newTitleTag = HTML::createTag('title', [], SSViewer::execute_string($format, $data));
            $tags = preg_replace("/<title>(.+)<\/title>/i", $newTitleTag, $tags);
        }
    }
902319
public function tag(string $tag): array
    {
        return $this->hasTag($tag) ? $this->tags[$tag] : null;
    }
796336
private function getContextualTags(array $tags)
    {
        foreach ($tags as &$tag) {
            $tag = $this->getContextualId($tag);
        }
        unset($tag);

        return $tags;
    }
104236
protected function tags(&$tags, $simple = false, $delim = ',')
    {
        $tags = array();
        while ($this->tag($tt, $simple)) {
            $tags[] = $tt;
            if (!$this->literal($delim)) {
                break;
            }
        }
        if (count($tags) == 0) {
            return false;
        }

        return true;
    }
861902
public function taggedWith($tag)
    {
        $results = [];

        if (isset($this->tags[$tag]))
        {
            foreach ($this->tags[$tag] as $view)
            {
                $results[] = $view;
            }

        }

        return $results;
    }
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);
    }
663030
public function tag($tags)
    {
        foreach ($this->prepareTags($tags) as $tag) {
            $this->addTag($tag);
        }

        return true;
    }
325475
public function splitTag(string $text, string $tag): array
    {
        if (!$tag) {
            return [$text];
        }

        return preg_split('/(?=<'.$tag.'([^>])*>)/', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) ?: [$text];
    }
471946
public function normalizeTags($tags) {
		if (is_string($tags)) {
			$tags = explode($this->getConfig('delimiter'), $tags);
		}

		$result = [];

		$modelAlias = $this->getConfig('fkModelAlias') ?: $this->_table->getAlias();

		$common = ['_joinData' => [$this->getConfig('fkModelField') => $modelAlias]];
		$namespace = $this->getConfig('namespace');
		if ($namespace) {
			$common += compact('namespace');
		}

		$tagsTable = $this->_table->{$this->getConfig('tagsAlias')};
		$primaryKey = $tagsTable->getPrimaryKey();
		$displayField = $tagsTable->getDisplayField();

		foreach ($tags as $tag) {
			$tag = trim($tag);
			if (empty($tag)) {
				continue;
			}
			$tagKey = $this->_getTagKey($tag);
			$existingTag = $this->_tagExists($tagKey);
			if (!empty($existingTag)) {
				$result[] = $common + ['id' => $existingTag];
				continue;
			}
			list($id, $label) = $this->_normalizeTag($tag);
			$result[] = $common + compact(empty($id) ? $displayField : $primaryKey) + [
				'slug' => $tagKey,
			];
		}

		return $result;
	}
110782
public function getTagItems(string $tag): array
    {
        $tagName = $this->getTagKey($tag);
        $keys    = $this->handler->sMembers($tagName);

        return array_map(function ($key) {
            return $this->getCacheKey($key);
        }, $keys);
    }
45810
public function getPostsByTag($tag)
    {
        if (false === array_key_exists($tag, $this->tagsIndex)) {
            return [];
        }

        $postNames = $this->tagsIndex[$tag];

        return $this->getPostsByName($postNames);
    }