public function pullRemoteAssets(\DomDocument &$dom){
		$paths = [];
		foreach(['img' => 'src', 'script' => 'src', 'link' => 'href'] as $tag => $attr){
			foreach( $dom->getElementsByTagName($tag) as $elem ){
				$url = $elem->getAttribute($attr);
				if( !preg_match('/^(https?:)?\/\//', $url) ){
					continue;
				}
				// Get remote resource
				if( !($resource = $this->getRemote($url)) ){
					continue;
				}
				// Let's detect file mime
				list($basename) = explode('?', basename($url));
				$dir = Mime::getDestinationFolder($basename);
				if( 'Misc' === $dir ){
					// Oh, it might not have extension...
					if( $resource['info'] ){
						list($mime, $type) = explode('/', $resource['info']['content_type']);
						list($ext) = explode(';', $type);
						$new_dir = Mime::getDestinationFolder("hoge.{$ext}");
						if( $new_dir != $dir ){
							$dir = $new_dir;
							$basename = "{$basename}.{$ext}";
						}
					}
				}
				// O.K.
				$new_path = $dir.'/'.$basename;
				$elem->setAttribute($attr, '../'.$new_path);
				if( $this->distributor->write($resource['body'], 'OEBPS/'.$new_path) ){
					$paths[] = $new_path;
				}
			}
		}
		return $paths;
	}
public function pullRemoteAssets(\DomDocument &$dom){
		$paths = [];
		foreach(['img' => 'src', 'script' => 'src', 'link' => 'href'] as $tag => $attr){
			foreach( $dom->getElementsByTagName($tag) as $elem ){
				$url = $elem->getAttribute($attr);
				if( !preg_match('/^(https?:)?\/\//', $url) ){
					continue;
				}
				// Get remote resource
				if( !($resource = $this->getRemote($url)) ){
					continue;
				}
				// Let's detect file mime
				list($basename) = explode('?', basename($url));
				$dir = Mime::getDestinationFolder($basename);
				if( 'Misc' === $dir ){
					// Oh, it might not have extension...
					if( $resource['info'] ){
						list($mime, $type) = explode('/', $resource['info']['content_type']);
						list($ext) = explode(';', $type);
						$new_dir = Mime::getDestinationFolder("hoge.{$ext}");
						if( $new_dir != $dir ){
							$dir = $new_dir;
							$basename = "{$basename}.{$ext}";
						}
					}
				}
				// O.K.
				$new_path = $dir.'/'.$basename;
				$elem->setAttribute($attr, '../'.$new_path);
				if( $this->distributor->write($resource['body'], 'OEBPS/'.$new_path) ){
					$paths[] = $new_path;
				}
			}
		}
		return $paths;
	}
public function pullRemoteAssets ( \ DomDocument & $ dom ) { $ paths = [ ] ; foreach ( [ 'img' => 'src' , 'script' => 'src' , 'link' => 'href' ] as $ tag => $ attr ) { foreach ( $ dom -> getElementsByTagName ( $ tag ) as $ elem ) { $ url = $ elem -> getAttribute ( $ attr ) ; if ( ! preg_match ( '/^(https?:)?\/\//' , $ url ) ) { continue ; } // Get remote resource if ( ! ( $ resource = $ this -> getRemote ( $ url ) ) ) { continue ; } // Let's detect file mime list ( $ basename ) = explode ( '?' , basename ( $ url ) ) ; $ dir = Mime :: getDestinationFolder ( $ basename ) ; if ( 'Misc' === $ dir ) { // Oh, it might not have extension... if ( $ resource [ 'info' ] ) { list ( $ mime , $ type ) = explode ( '/' , $ resource [ 'info' ] [ 'content_type' ] ) ; list ( $ ext ) = explode ( ';' , $ type ) ; $ new_dir = Mime :: getDestinationFolder ( "hoge.{$ext}" ) ; if ( $ new_dir != $ dir ) { $ dir = $ new_dir ; $ basename = "{$basename}.{$ext}" ; } } } // O.K. $ new_path = $ dir . '/' . $ basename ; $ elem -> setAttribute ( $ attr , '../' . $ new_path ) ; if ( $ this -> distributor -> write ( $ resource [ 'body' ] , 'OEBPS/' . $ new_path ) ) { $ paths [ ] = $ new_path ; } } } return $ paths ; }
Extract remote assets and save it

@param \DomDocument $dom

@return array
Extract remote assets and save it