Process media upload response.

@param ProtocolNode $node Message node

@return bool
170176
public function processUploadResponse($node)
    {
        $id = $node->getAttribute('id');
        $messageNode = @$this->mediaQueue[$id];
        if ($messageNode == null) {
            //message not found, can't send!
            $this->eventManager()->fire('onMediaUploadFailed',
                [
                    $this->phoneNumber,
                    $id,
                    $node,
                    $messageNode,
                    'Message node not found in queue',
                ]);

            return false;
        }

        $duplicate = $node->getChild('duplicate');
        if ($duplicate != null) {
            //file already on whatsapp servers
            $url = $duplicate->getAttribute('url');
            $filesize = $duplicate->getAttribute('size');
//          $mimetype = $duplicate->getAttribute("mimetype");
            $filehash = $duplicate->getAttribute('filehash');
            $filetype = $duplicate->getAttribute('type');
//          $width = $duplicate->getAttribute("width");
//          $height = $duplicate->getAttribute("height");
            $exploded = explode('/', $url);
            $filename = array_pop($exploded);
        } else {
            //upload new file
            $json = WhatsMediaUploader::pushFile($node, $messageNode, $this->mediaFileInfo, $this->phoneNumber);

            if (!$json) {
                //failed upload
                $this->eventManager()->fire('onMediaUploadFailed',
                    [
                        $this->phoneNumber,
                        $id,
                        $node,
                        $messageNode,
                        'Failed to push file to server',
                    ]);

                return false;
            }

            $url = $json->url;
            $filesize = $json->size;
//          $mimetype = $json->mimetype;
            $filehash = $json->filehash;
            $filetype = $json->type;
//          $width = $json->width;
//          $height = $json->height;
            $filename = $json->name;
        }

        $mediaAttribs = [];
        $mediaAttribs['type'] = $filetype;
        $mediaAttribs['url'] = $url;
        $mediaAttribs['encoding'] = 'raw';
        $mediaAttribs['file'] = $filename;
        $mediaAttribs['size'] = $filesize;
        if ($this->mediaQueue[$id]['caption'] != '') {
            $mediaAttribs['caption'] = $this->mediaQueue[$id]['caption'];
        }
        if ($this->voice == true) {
            $mediaAttribs['origin'] = 'live';
            $this->voice = false;
        }

        $filepath = $this->mediaQueue[$id]['filePath'];
        $to = $this->mediaQueue[$id]['to'];

        switch ($filetype) {
            case 'image':
                $caption = $this->mediaQueue[$id]['caption'];
                $icon = createIcon($filepath);
                break;
            case 'video':
                $caption = $this->mediaQueue[$id]['caption'];
                $icon = createVideoIcon($filepath);
                break;
            default:
                $caption = '';
                $icon = '';
                break;
        }
        //Retrieve Message ID
        $message_id = $messageNode['message_id'];

        $mediaNode = new ProtocolNode('media', $mediaAttribs, null, $icon);
        if (is_array($to)) {
            $this->sendBroadcast($to, $mediaNode, 'media');
        } else {
            $this->sendMessageNode($to, $mediaNode, $message_id);
        }
        $this->eventManager()->fire('onMediaMessageSent',
            [
                $this->phoneNumber,
                $to,
                $message_id,
                $filetype,
                $url,
                $filename,
                $filesize,
                $filehash,
                $caption,
                $icon,
            ]);

        return true;
    }
969864
public function addNode(Node $node): bool {
        $added = $this->add($node->getKey(), $node->getValue());
        return $added;
    }
1162841
protected function isWrapped(DomNode $node)
    {
        while ($node = $node->parentNode) {
            if ($node->localName === 'eztemplate' || $node->localName === 'eztemplateinline') {
                return true;
            }
        }

        return false;
    }
55525
public function insert(?IBinaryNode $node) {
        if (!$node instanceof BinaryNode) {
            return false;
        }
        if (null === $this->getRoot()) {
            $this->setRoot($node);
            $this->size++;
            return true;
        }
        /** @var BinaryNode $current */
        $current = $this->getRoot();
        if ($node->getValue() < $current->getValue()) {
            while (null !== $current->getLeft()) {
                $current = $current->getLeft();
            }
            $this->size++;
            $current->setLeft($node);
            return true;
        } else if ($node->getValue() > $current->getValue()) {
            while (null !== $current->getRight()) {
                $current = $current->getRight();
            }
            $current->setRight($node);
            $this->size++;
            return true;
        }
        return false;
    }
789020
private function processScalarNode(AbstractScalarOperatorNode $node)
    {
        $copy = clone $node;
        $copy->setValue($this->getDbRefValue($node->getValue()));
        return $copy;
    }
1185858
public function addNode($node) {
		$src=false;
		// find src
		if (array_key_exists('src',$node))
			$src = $node['src'];
		elseif (array_key_exists('href',$node))
			$src = $node['href'];
		if ($src) {
			// find type
			if (!isset($node['type'])) {
				if (preg_match('/.*\.(css|js)(?=[?#].*|$)/i',$src,$match))
					$node['type'] = $match[1];
				elseif (array_key_exists('src',$node))
					$node['type'] = 'js';
				elseif (array_key_exists('href',$node))
					$node['type'] = 'css';
				elseif(empty($type))
					// unknown file type
					return "";
			}
			$type = $node['type'];
			// default slot is based on the type
			if (!isset($node['group']))
				$node['group'] = ($node['type'] == 'js')
					? 'footer' : 'head';
			if (!isset($node['priority']))
				$node['priority'] = 5;
			if (!isset($node['slot']))
				$node['slot'] = null;
			$group = $node['group'];
			$prio = $node['priority'];
			$slot = $node['slot'];
			unset($node['priority'],$node['src'],$node['href'],
				$node['group'],$node['type'],$node['slot']);
			$this->add($src,$type,$group,$prio,$slot,$node);
		}
	}
903463
public function processRequest()
    {
        foreach($this->xPluginManager->getRequestPlugins() as $xPlugin)
        {
            if($xPlugin->getName() != Jaxon::FILE_UPLOAD && $xPlugin->canProcessRequest())
            {
                $xUploadPlugin = $this->xPluginManager->getRequestPlugin(Jaxon::FILE_UPLOAD);
                // Process uploaded files
                if($xUploadPlugin != null)
                {
                    $xUploadPlugin->processRequest();
                }
                // Process the request
                return $xPlugin->processRequest();
            }
        }
        // Todo: throw an exception
        return false;
    }
110474
private function isController(ClassNode $node)
    {
        if (true === $node->isAbstract()) {
            return false;
        }

        if ('Controller' === substr($node->getImage(), -10, 10)) {
            return true;
        }

        return false;
    }
170298
public function afterNodeCreate(NodeInterface $node)
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        /* @var $nodeEvent NodeEvent */
        $nodeEvent = array_pop($this->currentNodeAddEvents);
        $nodeEvent->setNode($node);
        $this->eventEmittingService->popContext();
        $this->eventEmittingService->add($nodeEvent);
    }
1198226
public function prepend(?Node $node): bool {
        if ($node === null) {
            return false;
        }
        /*
         * need to clone the object otherwise the object
         * references are going crazy.
         *
         * Furthermore, setting previous and next to null
         * as they will be set later.
         */
        $newNode = clone $node;
        $newNode->setPrevious(null);
        $newNode->setNext(null);

        if ($this->getHead() === null) {
            $this->setHead($newNode);
            return true;
        }
        $head = $this->getHead();
        $head->setPrevious($newNode);
        $newNode->setNext($head);
        $this->setHead($newNode);
        return true;
    }
83240
protected function _processTree($nodes)
    {
        foreach ($nodes as $node) {
            if ($node->hasMethods && $node->type !== 'interface') {
                $this->_processMethods($node->tree);
            } elseif (count($node->tree)) {
                $this->_processTree($node->tree);
            }
        }
    }
1183429
public function updateMetadata(Node $node)
    {
        $this->updateFileTimes($node);
        $this->updateOwnership($node);

        return $node;
    }
886999
public function processNodes(DOMNode $node)
    {
        // get all link nodes
        $allLinkNodes = $this->xp->query('.//a', $node);
        $allLinkNodesSortedByLength = [];
        foreach ($allLinkNodes as $linkNode) {
            $allLinkNodesSortedByLength[] = [
                'href' => $linkNode->getAttribute('href'),
                'node' => $linkNode,
            ];
        }

        // sort by link-length
        usort(
            $allLinkNodesSortedByLength,
            function ($a, $b) {
                $lengthA = strlen($a['href']);
                $lengthB = strlen($b['href']);
                if ($lengthA == $lengthB) {
                    return 0;
                }

                return ($lengthA < $lengthB) ? 1 : -1;
            }
        );

        // set best matching link node to active, all ancestors to open
        $requestedUri = $this->requestedUri;
        while (DIRECTORY_SEPARATOR !== $requestedUri) {
            foreach ($allLinkNodesSortedByLength as $currentLinkNode) {
                if ($currentLinkNode['href'] === $requestedUri) {
                    $currentLinkNode['node']->setAttribute('class', trim($currentLinkNode['node']->getAttribute('class').' '.self::CLASS_ACTIVE));

                    // set nearest li ancestor to active
                    $ancestorListNode = $this->xp->query('./ancestor::li', $currentLinkNode['node'])->item(
                        $this->xp->query('./ancestor::li', $currentLinkNode['node'])->length - 1
                    );
                    $ancestorListNode->setAttribute('class', trim($ancestorListNode->getAttribute('class').' '.self::CLASS_ACTIVE));

                    // set all other li ancestors to open and all links inside them to open
                    $remainingAncestorListNodes = $this->xp->query('ancestor::li', $ancestorListNode);
                    foreach ($remainingAncestorListNodes as $remainingAncestorListNode) {
                        $remainingAncestorListNode->setAttribute('class', trim($remainingAncestorListNode->getAttribute('class').' '.self::CLASS_OPEN));
                        $descendantAnchorNode = $this->xp->query('descendant::a', $remainingAncestorListNode)->item(0);
                        $descendantAnchorNode->setAttribute('class', trim($descendantAnchorNode->getAttribute('class').' '.self::CLASS_OPEN));
                    }

                    return;
                }
            }
            $requestedUri = dirname($requestedUri);
        }

        return false;
    }
471422
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Node\Stmt\Trait_ || ! $parent instanceof PhpFileModelInterface) {
            throw new Exception('TraitNodeParser is made to parse a trait node');
        }

        $trait = new TraitModel();
        $trait->setParentNode($parent);
        $trait->setName(ClassLikeNameHelper::getName($node));
        $parent->addConcreteUse($parent->getFullNameFor($trait->getName()), $trait->getName());

        if (($documentation = $node->getDocComment()) !== null) {
            $this->documentationNodeParser->invoke($documentation, $trait);
        }

        $this->parseSubNodes($node->stmts, $trait);

        $parent->addTrait($trait);
    }
151539
public function insert(?IBinaryNode $node) {
        if (!$node instanceof BinarySearchNode) {
            return false;
        }
        if (null === $this->getRoot()) {
            $this->setRoot($node);
            $this->size++;
            return true;
        }
        /** @var BinarySearchNode $current */
        $current = $this->getRoot();
        if (Comparator::lessThan($node->getValue(), $current->getValue())) {
            while (null !== $current->getLeft()) {
                $current = $current->getLeft();
            }
            $current->setLeft($node);
            $this->size++;
            return true;
        } else if (Comparator::greaterThan($node->getValue(), $current->getValue())) {
            while (null !== $current->getRight()) {
                $current = $current->getRight();
            }
            $current->setRight($node);
            $this->size++;
            return true;
        }
        return false;
    }
128719
protected function childbearing(\DOMNode $node)
    {
        if ($node->hasChildNodes())
        {
            foreach ($node->childNodes as $child)
            {
                if ($child->nodeType === XML_ELEMENT_NODE)
                {
                    return true;
                }
            }
        }

        return false;
    }
1291457
public function transferFromDOM($node)
    {
        foreach ($node->childNodes as $child) {
            $this->takeChildFromDOM($child);
        }
        foreach ($node->attributes as $attribute) {
            $this->takeAttributeFromDOM($attribute);
        }
    }