Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Update Hash Generate to use checksum API
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyrob committed Feb 26, 2021
1 parent 022d0ad commit 984664c
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions hashes-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<?php\n" . '$filehashes = array(' . "\n";
foreach ( $checksums['checksums'] as $file => $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 '<?php' . "\n" . $hashes . "\n";
} else {
echo 'Hashes for ' . $file;
echo '<pre>';
echo '&lt;?php' . "\n" . $hashes . "\n";
echo '</pre>';
}

0 comments on commit 984664c

Please sign in to comment.