echo '<strong>' . __('Version') . ':</strong> ' . $newdata['Version'] . '<br>'; echo '<em>' . $newdata['Description'] . '</em>'; ?> <h2><?php _e('File Changes:'); ?> </h2> <?php $installedFile = ABSPATH . PLUGINDIR . '/'; $dirname = dirname($_GET['upgrade']); if ('.' != $dirname) { $installedFile .= $dirname; } else { $installedFile .= $_GET['upgrade']; } $diff = folder_diff(ABSPATH . 'wp-content/wpupdate/' . $newdata['Folder'], $installedFile); if (!$diff) { _e('Error: Couldnt compare changes.'); } else { foreach ($diff as $fileName => $fileInfo) { switch ($fileInfo['status']) { case 'new': echo "<span style='color: green'>{$fileName} (" . __('New') . ")</span><br />"; break; case 'deleted': echo "<span style='color: red'>{$fileName} (" . __('Deleted') . ")</span><br />"; break; case 'changed': echo "<span style='color: orange'>{$fileName} (" . __('Changed') . ")</span><br />"; break; default:
function folder_diff($folder1, $folder2) { global $wp_filesystem; if (!$wp_filesystem || !is_object($wp_filesystem)) { return false; } //Ok. $Files = array(); $folder1Listing = $wp_filesystem->dirlist($folder1, false, false); $folder2Listing = $wp_filesystem->dirlist($folder2, false, false); foreach ((array) $folder1Listing as $fileName => $fileItem) { if ('file' == $fileItem['type']) { if (!isset($folder2Listing[$fileName])) { //File is new $fileItem['status'] = 'new'; $Files[$fileName] = $fileItem; } elseif ($fileItem['size'] !== $folder2Listing[$fileName]['size']) { //File has changed $fileItem['status'] = 'changed'; $fileItem['oldsize'] = $folder2Listing[$fileName]['size']; $Files[$fileName] = $fileItem; } } elseif ('folder' == $fileItem['type']) { if (!isset($folder2Listing[$fileName])) { $fileItem['status'] = 'deleted'; $Files[$fileName] = $fileItem; continue; } $items = folder_diff($folder1 . '/' . $fileName, $folder2 . '/' . $fileName); if (!$items || empty($items)) { $fileItem['status'] = 'deleted'; $Files[$fileName] = $fileItem; } else { $Files[$fileName]['status'] = 'changed'; //unset as deleted. foreach ($items as $folderFile => $folderEntry) { $Files[$fileName . '/' . $folderFile] = $folderEntry; } } } } foreach ((array) $folder2Listing as $fileName => $fileItem) { if (isset($Files[$fileName])) { continue; } //If the file is allready accounted for, skip if ('file' == $fileItem['type']) { if (!isset($folder1Listing[$fileName])) { //File is deleted $fileItem['status'] = 'deleted'; $Files[$fileName] = $fileItem; } else { //File is the same $fileItem['status'] = 'same'; $Files[$fileName] = $fileItem; } } elseif ('folder' == $fileItem['type']) { //If the folder wasnt delt with before (Which would've placed it in the $Files array, then it must be deleted $fileItem['status'] = 'deleted'; $Files[$fileName] = $fileItem; } } return $Files; }