From 984664ced1dc42f0dd2fb7a4f1c6272896bbfe0c Mon Sep 17 00:00:00 2001 From: mattyrob Date: Fri, 26 Feb 2021 16:55:14 +0000 Subject: [PATCH] Update Hash Generate to use checksum API --- hashes-generator.php | 55 ++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/hashes-generator.php b/hashes-generator.php index 30ab833..04ade80 100644 --- a/hashes-generator.php +++ b/hashes-generator.php @@ -4,47 +4,26 @@ Author: mattyrob Author URI: http://subscribe2.wordpress.com/ */ -$latest_url = 'http://wordpress.org/latest.zip'; -$zips = array_merge( glob( 'latest.zip' ), glob( 'wordpress-[0-9]+([.][0-9]+)+\.zip' ) ); +$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'; -foreach ( $zips as $file) { +$versions = file_get_contents( $version_url ); +$versions = json_decode( $versions ); - 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"; +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"; } - zip_entry_close( $zip_entry ); } - zip_close( $zip ); + $hashes .= ");\n"; + file_put_contents( $filename, $hashes ); + echo 'Hash file created for ' . $wp_version->version . "\n"; } - $hashes .= ");"; -} - - -if ( isset( $download ) && is_readable( getcwd() . '/' . $file ) ) { - unlink( '/tmp/' . $file ); -} - -if ( 'cli' === php_sapi_name() ) { - print ''; - echo '<?php' . "\n" . $hashes . "\n"; - echo ''; }