Handles a DOM Context node and the messages it contains
@param DOMNode $context
@return bool
12478
function handleContextNode( $context )
    {
        $contextName = null;
        $messages = array();
        $context_children = $context->childNodes;

        for( $i = 0; $i < $context_children->length; $i++ )
        {
            $context_child = $context_children->item( $i );
            if ( $context_child->nodeType == XML_ELEMENT_NODE )
            {
                if ( $context_child->tagName == "name" )
                {
                    $name_el = $context_child->firstChild;
                    if ( $name_el )
                    {
                        $contextName = $name_el->nodeValue;
                    }
                }
                break;
            }
        }
        if ( !$contextName )
        {
            eZDebug::writeError( "No context name found, skipping context", __METHOD__ );
            return false;
        }
        foreach( $context_children as $context_child )
        {
            if ( $context_child->nodeType == XML_ELEMENT_NODE )
            {
                $childName = $context_child->tagName;
                if ( $childName == "message" )
                {
                    $this->handleMessageNode( $contextName, $context_child );
                }
                else if ( $childName == "name" )
                {
                    /* Skip name tags */
                }
                else
                {
                    eZDebug::writeError( "Unknown element name: $childName", __METHOD__ );
                }
            }
        }
        if ( $contextName === null )
        {
            eZDebug::writeError( "No context name found, skipping context", __METHOD__ );
            return false;
        }
        if ( !isset( $this->CachedMessages[$contextName] ) )
            $this->CachedMessages[$contextName] = array();

        return true;
    }
1360041
public function add($selector, $context=null)
    {
        $result = $this->createChildInstance();
        $result->nodes = $this->nodes;

        $selection = $this->getTargetResult($selector, $context);

        foreach ($selection as $selection_node) {
            if (!$result->is($selection_node)) {
                if ($result->document === $selection_node->document) {
                    $new_node = $selection_node->get(0);
                } else {
                    $new_node = $this->document->importNode($selection_node->get(0), true);
                }

                $result->addDomNode($new_node);
            }
        }

        return $result;
    }
533471
public function appliesToContext(ContextInterface $context): bool
    {
        if (!$context instanceof PropertyContext) {
            return false;
        }

        $property = $context->getProperty();
        if (!preg_match($this->regex, $property->getName())) {
            return false;
        }

        return $this->subRule->appliesToContext($context);
    }
1281232
public function findAllNodes($context = NULL) {
    $qb = $this->createQueryBuilder('node');
    $qb->addSelect('page');
    $qb->leftJoin('node.page', 'page');
    $qb->andWhere($qb->expr()->eq('node.context', ':context'));
    
    $query = $qb->getQuery();
    $query->setParameter('context', $context ?: $this->context);
    
    return $query->getResult();
  }
1125530
private function parseXmlAttributes(\DOMNode $node, array $context = []): array
    {
        if (!$node->hasAttributes()) {
            return [];
        }

        $data = [];
        $typeCastAttributes = (bool) ($context[self::TYPE_CASE_ATTRIBUTES] ?? $this->defaultContext[self::TYPE_CASE_ATTRIBUTES]);

        foreach ($node->attributes as $attr) {
            if (!is_numeric($attr->nodeValue) || !$typeCastAttributes) {
                $data['@'.$attr->nodeName] = $attr->nodeValue;

                continue;
            }

            if (false !== $val = filter_var($attr->nodeValue, FILTER_VALIDATE_INT)) {
                $data['@'.$attr->nodeName] = $val;

                continue;
            }

            $data['@'.$attr->nodeName] = (float) $attr->nodeValue;
        }

        return $data;
    }
802120
public function query($selector, \DOMNode $context = null)
    {
        $this->enableRestoreInternal(true);

        if ($this->selector === null) {
            $this->selector = new Selector($this);
        }

        $nodes = $this->selector->get($selector, $context);

        $this->raise($this->exceptionlevel);

        $this->enableRestoreInternal(false);

        return $nodes;
    }
420459
public function parse($text, $context = null)
    {
        $parser = $this->getParser($context);

        $this->events->dispatch(new Parsing($parser, $context, $text));

        return $parser->parse($text);
    }
1188023
public function setContext($context)
    {
        if (!is_array($context) && !$context instanceof \ArrayObject && !$context instanceof \Iterator) {
            throw new EventException('Unexpected value type for context', EventException::INVALID_CONTEXT);
        }

        $context = Collection::cast($context);

        $this->context = $context;

        return $this;
    }
161999
private function parseTag($tag, $context)
    {
        // ensure tag is an object
        $this->instantiatTag($tag);
        // extract context
        $value = isset($context['value']) ? $context['value'] : false;
        $sub = isset($context['sub']) ? $context['sub'] : false;
        // the sub value can contain escaped values, those values must be parsed back into the original state.
        if ($sub) {
            $sub = str_replace(['\)', '\('], [')', '('], $sub);
        }
        // run parse method inside the tag object.
        return $this->tags[$tag]->parse($value, $sub);
    }
998761
public function loadContext($context)
    {

        $now = time();
        $context->created = $now;
        $context->updated = $now;

        return true;

    }
672135
protected function processPrefix(\DOMElement $element, ContextInterface $context)
    {
        if ($element->hasAttribute('prefix') && ($context instanceof RdfaLiteContext)) {
            $prefixes = preg_split('/\s+/', $element->getAttribute('prefix'));
            while (count($prefixes)) {
                $prefix = rtrim(array_shift($prefixes), ':');
                $uri = array_shift($prefixes);
                $context = $context->registerVocabulary($prefix, $uri);
            }
        }

        return $context;
    }
94523
public function _allow_decoding( $tags, $context ) {
		if ( 'post' !== $context ) {
			return $tags;
		}

		$tags['img'] = array_merge( $tags['img'], [ 'decoding' => true ] );
		return $tags;
	}
808533
private function extractText(DOMNode $node)
    {
        $text = '';

        if ($node->childNodes) {
            foreach ($node->childNodes as $child) {
                $text .= $this->extractText($child);
            }
        } else {
            $text .= $node->nodeValue . ' ';
        }

        return $text;
    }
715614
protected function processProperty(\DOMElement $element, ContextInterface $context)
    {
        if ($element->hasAttribute('itemprop') && !($context->getParentThing() instanceof RootThing)) {
            $itemprops = trim($element->getAttribute('itemprop'));
            $itemprops = strlen($itemprops) ? preg_split('/\s+/', $itemprops) : [];
            $context = $this->processProperties($itemprops, $element, $context);
        }

        return $context;
    }
395563
public function inContext($context)
    {
        $length = count($this->context);

        return $length < 2 ? false : $this->context[$length - 1] === $context;
    }
839918
public function canEvaluate($context) {
        return (isset($context[0]) && ($context[0] instanceof NodeInterface)) || (is_array($context) && count($context) === 0);
    }
785117
protected function _authorizeSubscribe($context)
    {
        $entity = $this->_entity;

        if ($this->_viewer->guest()) {
            return false;
        }

        if (!$entity->isSubscribable()) {
            return false;
        }

        //if the owner has blocked the viewer or the other way around, return false

        if ($this->_entity->isOwnable()) {
            if ($this->_entity->owner->blocking($this->_viewer) || $this->_viewer->blocking($this->_entity->owner)) {
                return false;
            }
        }

        //if already subscribed to the node then return false
        if ($entity->subscribed($this->_viewer)) {
            return false;
        }

        return true;
    }