From 794daf4f76fe230aecd2d8c0407414b7ed83ae81 Mon Sep 17 00:00:00 2001 From: mattyrob Date: Fri, 26 Feb 2021 16:55:54 +0000 Subject: [PATCH] Revert "Update Hash Generate to use checksum API" This reverts commit 984664ced1dc42f0dd2fb7a4f1c6272896bbfe0c. --- hashes-generator.php | 55 ++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/hashes-generator.php b/hashes-generator.php index 04ade80..30ab833 100644 --- a/hashes-generator.php +++ b/hashes-generator.php @@ -4,26 +4,47 @@ Author: mattyrob Author URI: http://subscribe2.wordpress.com/ */ -$version_url = 'https://api.wordpress.org/core/version-check/1.7/'; -$checksum_url = 'https://api.wordpress.org/core/checksums/1.0/?version='; -$locale = '&locale=en_US'; +$latest_url = 'http://wordpress.org/latest.zip'; +$zips = array_merge( glob( 'latest.zip' ), glob( 'wordpress-[0-9]+([.][0-9]+)+\.zip' ) ); -$versions = file_get_contents( $version_url ); -$versions = json_decode( $versions ); +foreach ( $zips as $file) { -foreach( $versions->offers as $wp_version ) { - $filename = dirname( __FILE__ ) . '/' . 'hashes-' . $wp_version->version . '.php'; - if ( ! file_exists( $filename ) ) { - $checksums = file_get_contents( $checksum_url . $wp_version->version . $locale ); - $checksums = json_decode( $checksums, true ); - $hashes = " $checksum ) { - if ( ! strstr( $file, 'wp-content' ) ) { - $hashes .= "\t'" . $file . "' => '" . $checksum . "',\n"; + if ( ! is_readable( $file ) && 1 === count( $zips ) ) { + if ( ! copy( $latest_url, '/tmp/' . $file ) ) { + $file_error = "No WordPress archive available and it could not be downloaded. Ensure the file is called 'latest.zip'."; + } else { + $download = true; + chdir( '/tmp' ); + } + } + + $hashes = '$filehashes = array(' . "\n"; + $zip = zip_open( getcwd() . '/' . $file ); + if ( is_resource( $zip ) ) { + while ( $zip_entry = zip_read( $zip ) ) { + zip_entry_open( $zip, $zip_entry, 'r' ); + $wp_file = zip_entry_read( $zip_entry, zip_entry_filesize( $zip_entry ) ); + if ( substr( zip_entry_name( $zip_entry ), -1, 1 ) !== '/' && false === strstr( zip_entry_name( $zip_entry ), 'wp-content/plugins/' ) && false === strstr( zip_entry_name( $zip_entry ), 'wp-content/themes/' ) ) { + list( $wp, $filename ) = explode( '/', zip_entry_name( $zip_entry ), 2 ); + $hashes .= "\t'" . $filename . "' => '" . md5( $wp_file ) . "',\n"; } + zip_entry_close( $zip_entry ); } - $hashes .= ");\n"; - file_put_contents( $filename, $hashes ); - echo 'Hash file created for ' . $wp_version->version . "\n"; + zip_close( $zip ); } + $hashes .= ");"; +} + + +if ( isset( $download ) && is_readable( getcwd() . '/' . $file ) ) { + unlink( '/tmp/' . $file ); +} + +if ( 'cli' === php_sapi_name() ) { + print ''; + echo '<?php' . "\n" . $hashes . "\n"; + echo ''; }