@param \DOMElement $resultNode
@param \DOMElement $addressNode

@return Location
772530
private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressNode): Location
    {
        $builder = new AddressBuilder($this->getName());

        foreach (['state', 'county'] as $i => $tagName) {
            if (null !== ($adminLevel = $this->getNodeValue($addressNode->getElementsByTagName($tagName)))) {
                $builder->addAdminLevel($i + 1, $adminLevel, '');
            }
        }

        // get the first postal-code when there are many
        $postalCode = $this->getNodeValue($addressNode->getElementsByTagName('postcode'));
        if (!empty($postalCode)) {
            $postalCode = current(explode(';', $postalCode));
        }
        $builder->setPostalCode($postalCode);
        $builder->setStreetName($this->getNodeValue($addressNode->getElementsByTagName('road')) ?: $this->getNodeValue($addressNode->getElementsByTagName('pedestrian')));
        $builder->setStreetNumber($this->getNodeValue($addressNode->getElementsByTagName('house_number')));
        $builder->setLocality($this->getNodeValue($addressNode->getElementsByTagName('city')));
        $builder->setSubLocality($this->getNodeValue($addressNode->getElementsByTagName('suburb')));
        $builder->setCountry($this->getNodeValue($addressNode->getElementsByTagName('country')));
        $builder->setCountryCode(strtoupper($this->getNodeValue($addressNode->getElementsByTagName('country_code'))));
        $builder->setCoordinates($resultNode->getAttribute('lat'), $resultNode->getAttribute('lon'));

        $boundsAttr = $resultNode->getAttribute('boundingbox');
        if ($boundsAttr) {
            $bounds = [];
            list($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']) = explode(',', $boundsAttr);
            $builder->setBounds($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']);
        }

        return $builder->build();
    }
232547
private function setPositionOfLastToken(
        AttributeAwarePhpDocNode $attributeAwarePhpDocNode
    ): AttributeAwarePhpDocNode {
        if ($attributeAwarePhpDocNode->children === []) {
            return $attributeAwarePhpDocNode;
        }

        /** @var AttributeAwareNodeInterface $lastChildNode */
        $phpDocChildNodes = $attributeAwarePhpDocNode->children;
        $lastChildNode = array_pop($phpDocChildNodes);
        $phpDocNodeInfo = $lastChildNode->getAttribute(Attribute::PHP_DOC_NODE_INFO);

        if ($phpDocNodeInfo !== null) {
            $attributeAwarePhpDocNode->setAttribute(Attribute::LAST_TOKEN_POSITION, $phpDocNodeInfo->getEnd());
        }

        return $attributeAwarePhpDocNode;
    }
124884
@SuppressWarnings("unchecked")
	public Address getClusterNodeAddress(ClusteredCacheData cacheData) {
		return (Address) cacheData.getNode().get(CLUSTER_NODE_ADDRESS_NODE_KEY);
	}
746885
function Form(domElement) {
		this.addresses = [];
		this.dom = domElement;

		this.activeAddressesNotAccepted = function () {
			var addrs = [];
			for (var i = 0; i < this.addresses.length; i++) {
				var addr = this.addresses[i];
				if (addr.status() != "accepted" && addr.active)
					addrs.push(addr);
			}
			return addrs;
		};

		this.allActiveAddressesAccepted = function () {
			return this.activeAddressesNotAccepted().length == 0;
		};
	}
1352255
public function placeAt(Sortable $movedNode, Sortable $newParent, $position)
    {
        // 1. movedNode.parentId = newDescendant.parentId, movedNode.position = MAX(newDescendant.position,1)
        // 2. removeFromSort(movedNode) like delete without delete
        // 2. UPDATE SET position = position+1 WHERE parentId = newAncestor.parentId
        //    AND position >= movedNode.position
        // 3. movedNode.save()

        $targetParentId = $newParent->getId();
        $targetPosition = $position;
        $oldParentId = $movedNode->getParentId();
        $oldPosition = $movedNode->getPosition();

        // Nothing to do
        if ($targetParentId == $oldParentId &&
            $targetPosition == $oldPosition &&
            $movedNode->exists) {
            return $this;
        }

        $movedNode[$this->getParentIdName()] = $targetParentId;
        $movedNode[$this->getPositionName()] = $targetPosition;

        // Remove node from old parent
        $this->decrementOrderAfter($oldParentId, $oldPosition);

        // Create space for new position
        $this->incrementOrderAfter($targetParentId, $targetPosition-1);

        $movedNode->save();

        return $this;

    }
846818
public function loadShallowStructureByNode(NodeInterface $contentNode, $localization, $webspaceKey)
    {
        $document = $this->documentManager->find($contentNode->getPath(), $localization);

        return $this->documentToStructure($document);
    }
931090
public function createNodeForTheTreeAction(Node $referenceNode, array $nodeData, $position, $nodeTypeFilter = '')
    {
        $newNode = $this->nodeOperations->create($referenceNode, $nodeData, $position);
        $this->view->assignNodeAndChildNodes($newNode, $nodeTypeFilter);
    }
1135735
public function addressToPoint($address, $region = '')
    {
        // Get the URL for the Mapbox API
        $url = Config::inst()->get(__CLASS__, 'mapbox_api_url');
        $key = Config::inst()->get(__CLASS__, 'mapbox_api_key');

        if (!$url) {
            // If no URL configured. Stop.
            throw new Exception('No mapbox_api_url configured. This is not allowed.');
        }

        if (!$key) {
            // If no KEY configured. Stop.
            throw new Exception('No mapbox_api_key configured. This is not allowed.');
        }

        // Add params
        $queryVars = [
            'access_token' => $key,
            'type' => 'address',
        ];
        if ($region) {
            $queryVars['country'] = $region;
        }
        $url .= urlencode($address).'.json?'.http_build_query($queryVars);

        $client = new Client();
        $response = $client->get($url);
        if (!$response) {
            throw new GeocodeServiceException('No response.', 0, '');
        }
        $statusCode = $response->getStatusCode();
        if ($statusCode !== 200) {
            throw new GeocodeServiceException('Unexpected status code:'.$statusCode, $statusCode, '');
        }
        $responseBody = json_decode((string)$response->getBody());

        // Error handling
        if ($responseBody) {
            if (isset($responseBody->message)) {
                throw new GeocodeServiceException('Error message: '.$responseBody->message, $statusCode, $responseBody);
            }
            if (!isset($responseBody->features) || !count($responseBody->features) === 0) {
                throw new GeocodeServiceException('Zero results returned. Invalid status from response: '.$status, $statusCode, $responseBody);
            }
        } else {
            // Fallback to full string dump
            $text = trim($response->getBody());
            throw new GeocodeServiceException('Invalid response: '.$text, $statusCode, $responseBody);
        }

        // We take the first match, because that's most likely the best match
        $feature = reset($responseBody->features);
        list($lng, $lat) = $feature->geometry->coordinates;

        return [
            'lat' => (float)$lat,
            'lng' => (float)$lng
        ];
    }
333426
protected function appendXPathOutput(DOMElement $parentNode, $expr)
	{
		$this->appendElement($parentNode, 'output', htmlspecialchars(trim($expr)))
		     ->setAttribute('type', 'xpath');
	}
993895
public function initializeNode($parentId, $language, $siteId, $order = 0)
    {
        /** @var NodeInterface $node */
        $node = new $this->nodeClass();
        $node->setSiteId($siteId);
        $node->setLanguage($language);
        $node->setMaxAge(NodeInterface::MAX_AGE);
        $node->setParentId($parentId);
        $node->setOrder($order);
        $node->setVersion($this->uniqueIdGenerator->generateUniqueId());
        $node->setCreatedBy($this->tokenStorage->getToken()->getUser()->getUsername());

        $parentNode = $this->nodeRepository->findInLastVersion($parentId, $language, $siteId);
        $status = $this->statusRepository->findOneByInitial();
        $node->setStatus($status);
        $nodeType = NodeInterface::TYPE_DEFAULT;
        if ($parentNode instanceof NodeInterface) {
            $nodeType = $parentNode->getNodeType();
            $node->setPath($parentNode->getPath());
        } else {
            $node->setNodeId(NodeInterface::ROOT_NODE_ID);
        }
        $node->setNodeType($nodeType);

        return $node;
    }
1277078
public function getOrCreateProxyFromNode(NodeInterface $node, $locale = null)
    {
        $targetId = $node->getPath();
        $className = $this->documentClassMapper->getClassName($this->dm, $node);

        return $this->getOrCreateProxy($targetId, $className, $locale);
    }
498918
public function format(
        AddressInterface $address,
        $locale = null,
        $html = true,
        $htmlTag = "p",
        $htmlAttributes = []
    ) {
        $locale = $this->normalizeLocale($locale);

        $addressFormatRepository = new AddressFormatRepository();
        $countryRepository = new CountryRepository();
        $subdivisionRepository = new SubdivisionRepository();

        $formatter = new DefaultFormatter(
            $addressFormatRepository,
            $countryRepository,
            $subdivisionRepository,
            $locale
        );

        $formatter->setOption('html', $html);
        $formatter->setOption('html_tag', $htmlTag);
        $formatter->setOption('html_attributes', $htmlAttributes);


        $addressFormatted = $formatter->format($address);

        return $addressFormatted;
    }
766617
public function create(CreateStruct $createStruct, array $parentNode)
    {
        $location = new Location();
        /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
        $query = $this->handler->createInsertQuery();
        $query
            ->insertInto($this->handler->quoteTable('ezcontentobject_tree'))
            ->set(
                $this->handler->quoteColumn('contentobject_id'),
                $query->bindValue($location->contentId = $createStruct->contentId, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('contentobject_is_published'),
                $query->bindValue(1, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('contentobject_version'),
                $query->bindValue($createStruct->contentVersion, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('depth'),
                $query->bindValue($location->depth = $parentNode['depth'] + 1, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('is_hidden'),
                $query->bindValue($location->hidden = $createStruct->hidden, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('is_invisible'),
                $query->bindValue($location->invisible = $createStruct->invisible, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('modified_subnode'),
                $query->bindValue(time(), null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('node_id'),
                $this->handler->getAutoIncrementValue('ezcontentobject_tree', 'node_id')
            )->set(
                $this->handler->quoteColumn('parent_node_id'),
                $query->bindValue($location->parentId = $parentNode['node_id'], null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('path_identification_string'),
                $query->bindValue($location->pathIdentificationString = $createStruct->pathIdentificationString, null, \PDO::PARAM_STR)
            )->set(
                $this->handler->quoteColumn('path_string'),
                $query->bindValue('dummy') // Set later
            )->set(
                $this->handler->quoteColumn('priority'),
                $query->bindValue($location->priority = $createStruct->priority, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('remote_id'),
                $query->bindValue($location->remoteId = $createStruct->remoteId, null, \PDO::PARAM_STR)
            )->set(
                $this->handler->quoteColumn('sort_field'),
                $query->bindValue($location->sortField = $createStruct->sortField, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('sort_order'),
                $query->bindValue($location->sortOrder = $createStruct->sortOrder, null, \PDO::PARAM_INT)
            );
        $query->prepare()->execute();

        $location->id = $this->handler->lastInsertId($this->handler->getSequenceName('ezcontentobject_tree', 'node_id'));

        $mainLocationId = $createStruct->mainLocationId === true ? $location->id : $createStruct->mainLocationId;
        $location->pathString = $parentNode['path_string'] . $location->id . '/';
        /** @var $query \eZ\Publish\Core\Persistence\Database\UpdateQuery */
        $query = $this->handler->createUpdateQuery();
        $query
            ->update($this->handler->quoteTable('ezcontentobject_tree'))
            ->set(
                $this->handler->quoteColumn('path_string'),
                $query->bindValue($location->pathString)
            )
            ->set(
                $this->handler->quoteColumn('main_node_id'),
                $query->bindValue($mainLocationId, null, \PDO::PARAM_INT)
            )
            ->where(
                $query->expr->eq(
                    $this->handler->quoteColumn('node_id'),
                    $query->bindValue($location->id, null, \PDO::PARAM_INT)
                )
            );
        $query->prepare()->execute();

        return $location;
    }
888557
public function parseElement(Node $parent, \DOMElement $element)
    {
        if (AtomPub::NS === $element->namespaceURI) {
            switch ($element->localName) {
                case 'collection':
                    // Node name already checked
                    return new Collection($parent, $element);
                case 'workspace':
                    // Node name already checked
                    return new Workspace($parent, $element);
            }
        }

        return null;
    }
127820
private void locateNode(final String address, final Iterator<String> nodes, final Handler<AsyncResult<String>> doneHandler) {
    if (nodes.hasNext()) {
      final String node = nodes.next();
      vertx.eventBus().sendWithTimeout(node, new JsonObject().putString("action", "ping"), 1000, new Handler<AsyncResult<Message<JsonObject>>>() {
        @Override
        public void handle(AsyncResult<Message<JsonObject>> result) {
          if (result.failed() || result.result().body().getString("status", "ok").equals("error")) {
            removeNode(address, node);
            locateNode(address, nodes, doneHandler);
          } else {
            new DefaultFutureResult<String>(node).setHandler(doneHandler);
          }
        }
      });
    } else {
      new DefaultFutureResult<String>(new IllegalStateException("No local nodes found")).setHandler(doneHandler);
    }
  }
1267903
function GetPositionOnPage($url, &$result) 
	{
		$rank = new SearchRank();
		$counter = 0;
		
		foreach ($result->resultElements as $element) 
		{
			$counter++;
			//print "<div>$url :: $counter = ".$element->URL."</div>";
			$normalizedurl = str_replace("/","\\/", $url);
			
			if ($rank->Position == 0 && preg_match("/$normalizedurl/i", $element->URL)) 
			{
				$rank->Position = (int)$counter;
				$rank->Title = $element->title;
				$rank->Snippet = $element->snippet;
				$rank->Url = $element->URL;
			}
		}

		return $rank;
	}
50266
protected function _createTree( MW_DB_Result_Interface $result, MW_Tree_Node_Interface $node )
	{
		while( ( $record = $result->fetch() ) !== false )
		{
			$newNode = $this->_createNode( $record );

			while( $this->_isChild( $newNode, $node ) )
			{
				$node->addChild( $newNode );

				if( ( $newNode = $this->_createTree( $result, $newNode ) ) === false ) {
					return false;
				}
			}

			return $newNode;
		}

		return false;
	}