remove folder 2.5.27 too and not only his children * @param type $arrIgnoreFiles * * @return boolean */ function rrmdir($folder, $killroot = false, $arrIgnoreFiles = ['.htaccess', 'index.html']) { $return = true; if (is_dir($folder)) { $dir_handle = opendir($folder); } if (!$dir_handle) { return false; } while ($file = readdir($dir_handle)) { if ('.' != $file && '..' != $file) { if (!is_dir($folder . '/' . $file)) { if (!in_array($file, $arrIgnoreFiles)) { @unlink($folder . '/' . $file); } } else { rrmdir($folder . '/' . $file, true, $arrIgnoreFiles); } } } closedir($dir_handle); if (true === $killroot) { @rmdir($folder); } return $return; } function json_val($string) { // decode the JSON data $result = json_decode($string); // switch and check possible JSON errors switch (json_last_error()) { case JSON_ERROR_NONE: // JSON is valid // No error has occurred $error = ''; break; case JSON_ERROR_DEPTH: $error = 'The maximum stack depth has been exceeded.'; break; case JSON_ERROR_STATE_MISMATCH: $error = 'Invalid or malformed JSON.'; break; case JSON_ERROR_CTRL_CHAR: $error = 'Control character error, possibly incorrectly encoded.'; break; case JSON_ERROR_SYNTAX: $error = 'Syntax error, malformed JSON.'; break; case JSON_ERROR_UTF8: $error = 'Malformed UTF-8 characters, possibly incorrectly encoded.'; break; case JSON_ERROR_RECURSION: $error = 'One or more recursive references in the value to be encoded.'; break; case JSON_ERROR_INF_OR_NAN: $error = 'One or more NAN or INF values in the value to be encoded.'; break; case JSON_ERROR_UNSUPPORTED_TYPE: $error = 'A value of a type that cannot be encoded was given.'; break; default: $error = 'Unknown JSON error occurred.'; break; } if ('' !== $error) { // throw the Exception or exit // or whatever :) exit($error); } // everything is OK return $result; } function recurceZip($path) { $all_path = []; $files = null; if (file_exists($path) && is_dir($path)) { $files = array_diff(scandir($path), array('..', '.')); } if ($files) { foreach ($files as $key => $value) { $file_info = pathinfo($value); if (isset($file_info['extension']) && $file_info['extension'] === 'zip') { $file_name = $path . '/' . $file_info['basename']; $zip = new ZipArchive(); if ($zip->open($file_name) === true) { if (is_dir($path . '/' . $file_info['filename'])) { // zip déjà traité echo '
'.$file_name.' already unzipped.
'; $zip->close(); unlink($file_name); continue;// ignore } $all_path[] = $path . '/' . $file_info['filename']; $zip->extractTo($path . '/' . $file_info['filename']); $zip->close(); unlink($file_name); } else { echo 'Error unzipping '.$file_name.'.
'; } } if (!isset($file_info['extension'])) { $all_path[] = $path . '/' . $file_info['filename']; } } } foreach ($all_path as $k => $v) { $path = $v; recurceZip($path); } return; } function makeJSON($folder, $filename) { // Make a JSON file to retrieve all MD5 hashes $arrFiles = []; $dir = new RecursiveDirectoryIterator($folder . DS, RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::LEAVES_ONLY); foreach ($files as $name => $object) { $arrFiles[] = $name; } if (count($arrFiles) > 0) { if (file_exists($filename)) { $json = json_decode(file_get_contents($filename), true); if (0 == count($json)) { echo ''.$hashFolder.DS.$file_info['filename'].' to be processed.
'; } } } return $out; } function process() { if (!isset($_GET['task'])) { return ""; } $arrFolder = [ ['joomla' => 'J!'], ['wordpress' => 'WP'], ['J!extensions' => ''], ['WPextensions' => ''] ]; $out = ''; foreach ($arrFolder as $arr) { $Folder = key($arr); // For instance "joomla"; name of the CMS; name of the subfolder $prefix = $arr[$Folder]; // For instance "J!"; prefix to use for naming files (f.i. "J!3.4.1" for the Joomla file for version 3.4.1) // Check if we have a folder called __DIR__/hashes/joomla (or wordpress or ...) $hashFolder = __DIR__ . DS . 'hashes' . DS . $Folder; if (!is_dir($hashFolder)) { @mkdir($hashFolder); } if (is_dir($hashFolder)) { recurceZip($hashFolder); // unzip all zip files if (!in_array($Folder, ['blacklist', 'other'])) { // This is a folder like "Joomla" : one json file by subfolder since a subfolder contain a specific version of that CMS $subfolders = array_filter(glob($hashFolder . DS . '*'), 'is_dir'); } else { // Only one single file for everything present in the "other" folder $subfolders = [$Folder]; } if (count($subfolders) > 0) { $tmp = ''; foreach ($subfolders as $folder) { // The file with the hashes will be something like hashes/joomla/J!2.5.27.json if (!in_array($Folder, ['blacklist', 'other'])) { $filename = $hashFolder . DS . $prefix . str_replace($hashFolder . DS, '', $folder) . '.json'; } else { $filename = dirname(dirname($hashFolder)) . DS . $Folder . '.json'; $folder = $hashFolder; } if ((!file_exists($filename)) || (in_array($Folder, ['blacklist', 'other']))) { makeJSON($folder, $filename); $out .= ''.$filename.' has been created.
'; } else { $out .= ''.$filename.' has been ignored.
'; } if (is_dir($folder)) { // unzipped folder ? rrmdir($folder, true, []); } } if ('' != $tmp) { $out .= 'Folder ' . $hashFolder . ' not found
'; } } if ($out == "") { $out = 'Nothing to do.....
'; } return $out.'To add a new version of a CMS or an extension, you need to
The JSON files will be generated automatically.