lib/blobfolio/common/dom.php
public static function get_nodes_by_class($parent, $class=null, bool $all=false) {
		$nodes = array();

		if (! \method_exists($parent, 'getElementsByTagName')) {
			return $nodes;
		}

		ref\cast::array($class);
		$class = \array_map('trim', $class);
		foreach ($class as $k=>$v) {
			$class[$k] = \ltrim($class[$k], '.');
		}
		$class = \array_filter($class, 'strlen');
		\sort($class);
		$class = \array_unique($class);
		if (! \count($class)) {
			return $nodes;
		}

		$possible = $parent->getElementsByTagName('*');
		if ($possible->length) {
			foreach ($possible as $child) {
				if ($child->hasAttribute('class')) {
					$classes = $child->getAttribute('class');
					ref\sanitize::whitespace($classes);
					$classes = \explode(' ', $classes);
					$overlap = \array_intersect($classes, $class);

					if (\count($overlap) && (! $all || \count($overlap) === \count($class))) {
						$nodes[] = $child;
					}
				}
			}
		}

		return $nodes;
	}
public static function get_nodes_by_class($parent, $class=null, bool $all=false) {
		$nodes = array();

		if (! \method_exists($parent, 'getElementsByTagName')) {
			return $nodes;
		}

		ref\cast::array($class);
		$class = \array_map('trim', $class);
		foreach ($class as $k=>$v) {
			$class[$k] = \ltrim($class[$k], '.');
		}
		$class = \array_filter($class, 'strlen');
		\sort($class);
		$class = \array_unique($class);
		if (! \count($class)) {
			return $nodes;
		}

		$possible = $parent->getElementsByTagName('*');
		if ($possible->length) {
			foreach ($possible as $child) {
				if ($child->hasAttribute('class')) {
					$classes = $child->getAttribute('class');
					ref\sanitize::whitespace($classes);
					$classes = \explode(' ', $classes);
					$overlap = \array_intersect($classes, $class);

					if (\count($overlap) && (! $all || \count($overlap) === \count($class))) {
						$nodes[] = $child;
					}
				}
			}
		}

		return $nodes;
	}
public static function get_nodes_by_class ( $ parent , $ class = null , bool $ all = false ) { $ nodes = array ( ) ; if ( ! \ method_exists ( $ parent , 'getElementsByTagName' ) ) { return $ nodes ; } ref \ cast :: array ( $ class ) ; $ class = \ array_map ( 'trim' , $ class ) ; foreach ( $ class as $ k => $ v ) { $ class [ $ k ] = \ ltrim ( $ class [ $ k ] , '.' ) ; } $ class = \ array_filter ( $ class , 'strlen' ) ; \ sort ( $ class ) ; $ class = \ array_unique ( $ class ) ; if ( ! \ count ( $ class ) ) { return $ nodes ; } $ possible = $ parent -> getElementsByTagName ( '*' ) ; if ( $ possible -> length ) { foreach ( $ possible as $ child ) { if ( $ child -> hasAttribute ( 'class' ) ) { $ classes = $ child -> getAttribute ( 'class' ) ; ref \ sanitize :: whitespace ( $ classes ) ; $ classes = \ explode ( ' ' , $ classes ) ; $ overlap = \ array_intersect ( $ classes , $ class ) ; if ( \ count ( $ overlap ) && ( ! $ all || \ count ( $ overlap ) === \ count ( $ class ) ) ) { $ nodes [ ] = $ child ; } } } } return $ nodes ; }
Get Nodes By Class

This will return an array of DOMNode objects containing the
specified class(es). This does not use DOMXPath.

@param mixed $parent DOMDocument, DOMElement, etc.
@param string|array $class One or more classes.
@param bool $all Matches must contain *all* passed classes instead of *any*.
@return array Nodes.
Get Nodes By Class