function md5_dir($directory) { global $ext; global $count; global $content; $mydir = dir($directory); while ($file = $mydir->read()) { if (is_dir("{$directory}/{$file}") and $file != "." and $file != "..") { @md5_dir("{$directory}/{$file}"); } elseif (in_array(strrchr($file, '.'), $ext)) { $content["{$directory}/{$file}"] = @md5_file("{$directory}/{$file}"); $count++; } } $mydir->close(); return $content; }
function md5_dir($dir) { if (!is_dir($dir)) { return false; } $filemd5s = array(); $d = dir($dir); while (false !== ($entry = $d->read())) { if ($entry != '.' && $entry != '..') { if (is_dir($dir . '/' . $entry)) { $filemd5s[] = md5_dir($dir . '/' . $entry); } else { $filemd5s[] = md5_file($dir . '/' . $entry); } } } $d->close(); return md5(implode('', $filemd5s)); }
if ($item_ext == '.sqlite' || $item_ext && in_array(substr($item_ext, 1), $_RAW_EXT)) { continue; } // get file mtime and md5 $mtime = filemtime($item); if ($mtime > $last_mtime) { $last_mtime = $mtime; } $glob_md5 .= md5_file($item); } $etag = md5($glob_md5); $last_modified = $last_mtime; } else { if (is_dir($_filename)) { $_f = $_filename . '.'; $etag = md5_dir($_f); $last_modified = filemtime($_f); } else { $_f = $_filename; $etag = md5_file($_f); $last_modified = filemtime($_f); } } // add ETag and Last-Modified headers if (strlen($etag)) { $etag = trim(array_shift(explode(' ', $etag))); header('ETag: "' . $etag . '"'); } header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_modified) . ' GMT', true, 200); if (CACHING) { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
<?php /* if-match.php */ $if_match = isset($_SERVER["HTTP_IF_MATCH"]) ? trim(str_replace("\"", "", $_SERVER["HTTP_IF_MATCH"])) : ''; $if_none_match = isset($_SERVER["HTTP_IF_NONE_MATCH"]) ? trim(str_replace("\"", "", $_SERVER["HTTP_IF_NONE_MATCH"])) : ''; if (strlen($if_match) || strlen($if_none_match)) { if (isset($g)) { $exists = $g->exists(); $etag = is_dir($_filename) ? md5_dir($_filename) : md5_file($_filename); } else { $exists = file_exists($_filename); if ($exists) { $etag = is_dir($_filename) ? md5_dir($_filename) : md5_file($_filename); if (strlen($etag)) { $etag = trim(array_shift(explode(' ', $etag))); } } else { $etag = ''; } } //echo "ETag: ".$etag; //echo "\nExists: ".$exists; //echo "\nIf-Match: ".$if_match; //echo "\nIf-None-Match: ".$if_none_match; if (strlen($if_match)) { $fail = $if_match == '*' && !$exists || $if_match != '*' && $if_match != $etag; } else { $fail = $if_none_match == '*' && $exists || $if_none_match != '*' && $if_none_match == $etag; } //echo "\nFail: ".$fail;
function wptouch_auto_update_themes_addons() { global $wptouch_pro; if (!isset($wptouch_pro->post)) { require_once WPTOUCH_DIR . '/core/theme-hashes.php'; $theme_hashes = wptouch_get_hashes(); if (current_user_can('manage_options')) { $current_theme = $wptouch_pro->get_current_theme_info(); $available_themes = $wptouch_pro->get_available_themes(true); $available_addons = $wptouch_pro->get_available_addons(true); $updates = 0; $backed_up = false; $errors = array(); if (count($available_themes) > 0 || count($available_addons) > 0) { require_once WPTOUCH_DIR . '/core/addon-theme-installer.php'; foreach ($available_themes as $name => $theme) { $hash = false; $safe_to_install_theme = false; $skip_upgrade = false; if (isset($theme->upgrade_available) && $theme->upgrade_available) { if (!is_object($current_theme) || $name != $current_theme->name) { $safe_to_install_theme = true; } else { if ($name == $current_theme->name && $theme->cloud_version < $theme->version) { $skip_upgrade = true; } else { $hash = md5_dir(WP_CONTENT_DIR . $current_theme->location); if (in_array($theme->version, $theme_hashes[$theme->base]) && $hash == $theme_hashes[$theme->base][$theme->version]) { // OK to upgrade the active theme (it's the same as when it shipped) $safe_to_install_theme = true; } } } // Hashes didn't match. if ($safe_to_install_theme === false && $skip_upgrade === false) { $copied_theme = wptouch_pro_copy_theme($theme->name, $theme->location); if (is_array($copied_theme)) { wptouch_pro_activate_theme($copied_theme['name'], $copied_theme['location']); $backed_up = $theme->name; } } if ($skip_upgrade === false) { $installer = new WPtouchAddonThemeInstaller(); $installer->install($theme->base, $theme->download_url, 'themes'); if ($installer->had_error()) { $errors[] = $installer->error_text(); } else { $updates++; } } } } foreach ($available_addons as $name => $addon) { if (isset($addon->upgrade_available) && $addon->upgrade_available && isset($addon->download_url)) { $installer = new WPtouchAddonThemeInstaller(); $installer->install($addon->base, $addon->download_url, 'extensions'); if ($installer->had_error()) { $errors[] = $installer->error_text(); } else { $updates++; } } } if ($backed_up) { $backed_up = sprintf(__('%sYour customizations to %s have been saved as a new theme and the original reinstalled for your reference.', 'wptouch-pro'), '</p><p>', $backed_up); } if ($updates && count($errors) > 0) { echo '<div id="message" class="error"><p>' . __('WPtouch Pro: Some themes or extensions could not be auto-updated. Please check the WPtouch Pro Themes & Extensions page to manually update them.', 'wptouch-pro') . $backed_up . '</p></div>'; } elseif ($updates) { echo '<div id="message" class="updated"><p>' . __('WPtouch Pro: Your themes and extensions have been automatically updated. Thank you for updating WPtouch Pro!', 'wptouch-pro') . $backed_up . '</p></div>'; } } } } }