public function buildListOfKnownMedia( $xml ) {

		$known_media = [];

		foreach ( $xml['posts'] as $item ) {
			if ( $item['post_type'] !== 'attachment' ) {
				continue; // Not an attachment, skip
			}
			$x = [];
			foreach ( $item['postmeta'] as $meta ) {
				if ( $meta['key'] === '_wp_attachment_metadata' ) {
					$x = maybe_unserialize( $meta['value'] );
					break;
				}
			}
			if ( ! is_array( $x ) || empty( $x ) ) {
				continue; // Something went wrong, skip
			}

			$m = $this->createMediaEntity( $item );
			if ( preg_match( $this->downloads->getPregSupportedImageExtensions(), $m->sourceUrl ) ) {
				$prefix = str_replace( $this->downloads->basename( $m->sourceUrl ), '', $x['file'] ); // 2017/08
				foreach ( $x['sizes'] as $size => $info ) {
					$attached_file = $prefix . $info['file']; // 2017/08/foo-bar-300x225.png
					$known_media[ $attached_file ] = $m;
				}
			} else {
				$attached_file = media_strip_baseurl( $m->sourceUrl ); // 2017/08/foo-bar.ext
				$known_media[ $attached_file ] = $m;
			}
		}

		return $known_media;
	}
public function buildListOfKnownMedia( $xml ) {

		$known_media = [];

		foreach ( $xml['posts'] as $item ) {
			if ( $item['post_type'] !== 'attachment' ) {
				continue; // Not an attachment, skip
			}
			$x = [];
			foreach ( $item['postmeta'] as $meta ) {
				if ( $meta['key'] === '_wp_attachment_metadata' ) {
					$x = maybe_unserialize( $meta['value'] );
					break;
				}
			}
			if ( ! is_array( $x ) || empty( $x ) ) {
				continue; // Something went wrong, skip
			}

			$m = $this->createMediaEntity( $item );
			if ( preg_match( $this->downloads->getPregSupportedImageExtensions(), $m->sourceUrl ) ) {
				$prefix = str_replace( $this->downloads->basename( $m->sourceUrl ), '', $x['file'] ); // 2017/08
				foreach ( $x['sizes'] as $size => $info ) {
					$attached_file = $prefix . $info['file']; // 2017/08/foo-bar-300x225.png
					$known_media[ $attached_file ] = $m;
				}
			} else {
				$attached_file = media_strip_baseurl( $m->sourceUrl ); // 2017/08/foo-bar.ext
				$known_media[ $attached_file ] = $m;
			}
		}

		return $known_media;
	}
public function buildListOfKnownMedia ( $ xml ) { $ known_media = [ ] ; foreach ( $ xml [ 'posts' ] as $ item ) { if ( $ item [ 'post_type' ] !== 'attachment' ) { continue ; // Not an attachment, skip } $ x = [ ] ; foreach ( $ item [ 'postmeta' ] as $ meta ) { if ( $ meta [ 'key' ] === '_wp_attachment_metadata' ) { $ x = maybe_unserialize ( $ meta [ 'value' ] ) ; break ; } } if ( ! is_array ( $ x ) || empty ( $ x ) ) { continue ; // Something went wrong, skip } $ m = $ this -> createMediaEntity ( $ item ) ; if ( preg_match ( $ this -> downloads -> getPregSupportedImageExtensions ( ) , $ m -> sourceUrl ) ) { $ prefix = str_replace ( $ this -> downloads -> basename ( $ m -> sourceUrl ) , '' , $ x [ 'file' ] ) ; // 2017/08 foreach ( $ x [ 'sizes' ] as $ size => $ info ) { $ attached_file = $ prefix . $ info [ 'file' ] ; // 2017/08/foo-bar-300x225.png $ known_media [ $ attached_file ] = $ m ; } } else { $ attached_file = media_strip_baseurl ( $ m -> sourceUrl ) ; // 2017/08/foo-bar.ext $ known_media [ $ attached_file ] = $ m ; } } return $ known_media ; }
Parse XML to build an array of known images

@param array $xml

@return \Pressbooks\Entities\Cloner\Media[]
Parse XML to build an array of known images