Preparing data for processing in tags wrappers: tags, input string data detecting, unit attributes processing

@static

@param array  $data
@param string $tag
@param string $in
@param string $attributes

@return bool
548229
protected static function data_prepare ($data, $tag, &$in, &$attributes) {
		if (isset($data['in'])) {
			if ($data['in'] === false) {
				return false;
			}
			$in = trim($data['in']);
			unset($data['in']);
		}
		if ($tag == 'img' && !isset($data['alt'])) {
			$data['alt'] = '';
		}
		if (isset($data['src'])) {
			$data['src'] = static::prepare_url($data['src']);
		}
		if (isset($data['href'])) {
			if ($tag != 'a') {
				$data['href'] = static::prepare_url($data['href']);
			} elseif ($data['href'][0] == '#') {
				$data['href'] = static::url_with_hash($data['href']);
			}
		}
		static::data_prepare_normalize_attributes($data);
		ksort($data);
		foreach ($data as $key => $value) {
			if ($value === false) {
				continue;
			}
			if ($value === true) {
				$attributes .= " $key";
			} else {
				$value      = static::prepare_attr_value($value);
				$attributes .= " $key=\"$value\"";
			}
		}
		return true;
	}
208853
public function deserialize(array $data, Tag $tag): Tag
    {
        $this->sipe('name', 'setName', $data, $tag);
        $this->sipe('color', 'setColor', $data, $tag);
        $this->sipe('meta.description', 'setDescription', $data, $tag);

        if (isset($data['meta']) && isset($data['meta']['creator'])) {
            $user = $this->om->getRepository(User::class)->findBy(['uuid' => $data['meta']['creator']['id']]);
            if ($user) {
                $tag->setUser($user);
            }
        }

        return $tag;
    }
386484
protected function _parseParent($child, $data, $attributes) {
        $parent = $child->xpath("parent::*");

        if (is_object($parent[0]['name'])) {
            foreach ($attributes as $attribute) {
                $name = $attribute['name'];

                if (is_object($parent[0][$name])) {
                    /** @var SimpleXMLElement $element */
                    $element = $parent[0][$name];

                    if ($attribute['concatenate'] == true) {
                        if ($data[$name] != '') {
                            $data[$name] = $element->__toString() . $attribute['separator'] . $data[$name];
                        }
                        else {
                            $data[$name] = $element->__toString();
                        }
                    }
                    else {
                        if ($data[$name] == '') {
                            $data[$name] = $element->__toString();
                        }
                    }
                }
            }

            $data = $this->_parseParent($parent[0], $data, $attributes);
        }

        return $data;
    }
1108623
public function set($key, array $tags, $data)
    {
        $key = $this->redis->prefix($key);
        $this->redis->set($key, $this->encoder->encode($data));

        if (is_int($this->expirationTime) && $this->expirationTime > 0) {
            $this->redis->expire($key, $this->expirationTime);
        }

        foreach ($tags as $tag) {
            $this->redis->sadd($this->redis->prefix($tag), $key);
        }
    }
390683
private function processTag( eZTagsObject $tag, array &$tagIDs, array &$keywords, $indexParentTags = false, $includeSynonyms = false )
    {
        if ( !$this->indexSynonyms && $tag->isSynonym() )
            $tag = $tag->getMainTag();

        //get keyword in content's locale
        $keyword = $tag->getKeyword( $this->ContentObjectAttribute->attribute( 'language_code' ) );
        if ( !$keyword )
        {
            //fall back to main language
            /** @var eZContentLanguage $mainLanguage */
            $mainLanguage = eZContentLanguage::fetch( $tag->attribute( 'main_language_id') );
            if ( $mainLanguage instanceof eZContentLanguage )
                $keyword = $tag->getKeyword( $mainLanguage->attribute( 'locale' ) );
        }

        if ( $keyword )
        {
            $tagIDs[] = (int) $tag->attribute( 'id' );
            $keywords[] = $keyword;
        }

        if ( $indexParentTags )
        {
            $parentTags = $tag->getPath( true );
            foreach ( $parentTags as $parentTag )
            {
                if ( $parentTag instanceof eZTagsObject )
                {
                    $this->processTag( $parentTag, $tagIDs, $keywords );
                }
            }
        }

        if ( $this->indexSynonyms && $includeSynonyms )
        {
            foreach ( $tag->getSynonyms() as $synonym )
            {
                if ( $synonym instanceof eZTagsObject )
                {
                    $this->processTag( $synonym, $tagIDs, $keywords );
                }
            }
        }
    }
526998
public function parseXmlTag($tagLib,$tag,$attr,$content) {
        if(ini_get('magic_quotes_sybase'))
            $attr   =   str_replace('\"','\'',$attr);
        $parse      =   '_'.$tag;
        $content    =   trim($content);
        $tags       =   $tagLib->parseXmlAttr($attr,$tag);
        return $tagLib->$parse($tags,$content);
    }
569346
function _tag_open( &$parser, $tag, $attributes ) {
		$this->currentElement = strtoupper( $tag );

		switch( $this->currentElement ) {
			case 'ROW':
				$this->row = count( $this->data );
				$this->data[$this->row] = array();
				break;
			case 'F':
				$this->addField($attributes);
			default:
				// print_r( array( $tag, $attributes ) );
		}
	}
118310
public function td(string $text = '', array $attributes = []): void
    {
        $this->tdArray[] = Tags::td($text, $attributes);
    }
468061
public static function replaceTag($tag, $replacement, $content, $attributes = null)
        {
            $content = preg_replace("/<{$tag}.*?>/", "<{$replacement} {$attributes}>", $content);
            $content = preg_replace("/<\/{$tag}>/", "</{$replacement}>", $content);
            return $content;
        }
518223
private function tag_open($tag, $attrs)
	{
		if($this->current_tag instanceof Node_Container_Tag)
		{
			$closing_tags = $this->bbcodes[$this->current_tag->tag()]->closing_tags();

			if(in_array($tag, $closing_tags))
				$this->tag_close($this->current_tag->tag());
		}

		if($this->current_tag instanceof Node_Container_Tag)
		{
			$accepted_children = $this->bbcodes[$this->current_tag->tag()]->accepted_children();

			if(!empty($accepted_children) && !in_array($tag, $accepted_children))
				return false;

			if($this->throw_errors && !$this->bbcodes[$tag]->is_inline()
				&& $this->bbcodes[$this->current_tag->tag()]->is_inline())
				throw new Exception_InvalidNesting("Block level tag [{$tag}] was opened within an inline tag [{$this->current_tag->tag()}]");
		}

		$node = new Node_Container_Tag($tag, $attrs);
		$this->current_tag->add_child($node);

		if(!$this->bbcodes[$tag]->is_self_closing())
			$this->current_tag = $node;

		return true;
	}
1169911
public static function tag($tag, array $attrs, $inner=null) {
		$str = '';

		foreach($attrs as $k=>$v) {
			if(is_numeric($k))
				$str .= $v.' ';
			else
				$str .= $k.'="'.$v.'" ';
		}

		$str = '<'.$tag.' '.trim($str).'>';

		if($inner === null)
			return $str;

		$str .= $inner;

		return $str.'</'.$tag.'>';
	}
323346
public function prepareTagsForOutput(array $data) {
		$tags = [];

		foreach ($data as $tag) {
			if ($this->_config['namespace']) {
				$tags[] = $tag['namespace'] . $this->_config['separator'] . $tag['label'];
			} else {
				$tags[] = $tag['label'];
			}
		}

		if ($this->_config['strategy'] === 'array') {
			return $tags;
		}

		return implode($this->_config['delimiter'] . ' ', $tags);
	}
1338571
function _tag_open( &$parser, $tag, $attributes ) {
		$this->currentElement = strtoupper( $tag );

		switch( $this->currentElement ) {
			case 'DROP':
				$this->drop();
				break;
			case 'CLUSTERED':
			case 'BITMAP':
			case 'UNIQUE':
			case 'FULLTEXT':
			case 'HASH':
				// Add index Option
				$this->addIndexOpt( $this->currentElement );
				break;
			default:
				// print_r( array( $tag, $attributes ) );
		}
	}
265329
public static function tag($tag, $attr = [], $html = '')
    {
        // Build attributes
        $attributes = [];
        foreach ($attr as $name => $value) {
            $attributes[] = $name.'="'.$value.'"';
        }

        if (in_array($tag, self::$voidElements)) {
            return '<'.$tag.(!empty($attributes) ? ' '.implode(' ', $attributes) : '').'>';
        } else {
            return '<'.$tag.(!empty($attributes) ? ' '.implode(' ', $attributes) : '').'>'.$html.'</'.$tag.'>';
        }
    }
1330454
protected function handleTagOpenForArray( $parser, $tag, $attributes )
	{
		$count	= count( $this->last ) - 1;
		$this->last[$count][]	= array(
			"tag"			=> $tag,
			"attributes"	=> $attributes,
			"content"		=> '',
			"children"		=> array()
		);
		$index	= count( $this->last[$count] ) - 1;
		$this->last[]	= &$this->last[$count][$index]['children'];
	}
610095
protected function process_tag($data) {
        global $CFG;

        $data = (object)$data;

        if (core_tag_tag::is_enabled('core', 'course_modules')) {
            $modcontext = context::instance_by_id($this->task->get_contextid());
            $instanceid = $this->task->get_moduleid();

            core_tag_tag::add_item_tag('core', 'course_modules', $instanceid, $modcontext, $data->rawname);
        }
    }
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;
    }