/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object $post The post object.
* @param int $compare_from The revision id to compare from.
* @param int $compare_to The revision id to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff($post, $compare_from, $compare_to)
{
if (!($post = get_post($post))) {
return false;
}
if ($compare_from) {
if (!($compare_from = get_post($compare_from))) {
return false;
}
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if (!($compare_to = get_post($compare_to))) {
return false;
}
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ($compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID) {
return false;
}
if ($compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID) {
return false;
}
if ($compare_from && strtotime($compare_from->post_date_gmt) > strtotime($compare_to->post_date_gmt)) {
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ($compare_from && empty($compare_from->post_title)) {
$compare_from->post_title = __('(no title)');
}
if (empty($compare_to->post_title)) {
$compare_to->post_title = __('(no title)');
}
$return = array();
foreach (_wp_post_revision_fields() as $field => $name) {
$content_from = $compare_from ? apply_filters("_wp_post_revision_field_{$field}", $compare_from->{$field}, $field, $compare_from, 'from') : '';
$content_to = apply_filters("_wp_post_revision_field_{$field}", $compare_to->{$field}, $field, $compare_to, 'to');
$diff = wp_text_diff($content_from, $content_to, array('show_split_view' => true));
if (!$diff && 'post_title' === $field) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
$diff .= '<td>' . esc_html($compare_from->post_title) . '</td><td></td><td>' . esc_html($compare_to->post_title) . '</td>';
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ($diff) {
$return[] = array('id' => $field, 'name' => $name, 'diff' => $diff);
}
}
return $return;
}
public function diff()
{
// make sure the keys are set on $left and $right so we don't get any undefined errors
$field_keys = array_fill_keys($this->fields_to_add, null);
$left = array_merge($field_keys, (array) $this->left);
$right = array_merge($field_keys, (array) $this->right);
$identical = true;
$rev_fields = array();
foreach (_wp_post_revision_fields() as $field => $field_title) {
$left_content = apply_filters("_wp_post_revision_field_{$field}", $left[$field], $field);
$right_content = apply_filters("_wp_post_revision_field_{$field}", $right[$field], $field);
if (!($content = wp_text_diff($left_content, $right_content))) {
continue;
}
// There is no difference between left and right
$identical = false;
$rev_fields[] = array('field' => $field, 'title' => $field_title, 'content' => $content);
}
return $identical ? false : $rev_fields;
}
$notices[1] = __('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>.');
if (!isset($post_ID) || 0 == $post_ID) {
$form_action = 'post';
$temp_ID = -1 * time();
// don't change this formula without looking at wp_write_post()
$form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='{$temp_ID}' />";
$autosave = false;
} else {
$post_ID = (int) $post_ID;
$form_action = 'editpost';
$form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='{$post_ID}' />";
$autosave = wp_get_post_autosave($post_id);
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ($autosave && mysql2date('U', $autosave->post_modified_gmt) > mysql2date('U', $post->post_modified_gmt)) {
foreach (_wp_post_revision_fields() as $autosave_field => $_autosave_field) {
if (wp_text_diff($autosave->{$autosave_field}, $post->{$autosave_field})) {
$notice = sprintf($notices[1], get_edit_post_link($autosave->ID));
break;
}
}
unset($autosave_field, $_autosave_field);
}
}
if ($notice) {
?>
<div id="notice" class="error"><p><?php
echo $notice;
?>
</p></div>
<?php
}
/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $compare_from The revision ID to compare from.
* @param int $compare_to The revision ID to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff($post, $compare_from, $compare_to)
{
if (!($post = get_post($post))) {
return false;
}
if ($compare_from) {
if (!($compare_from = get_post($compare_from))) {
return false;
}
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if (!($compare_to = get_post($compare_to))) {
return false;
}
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ($compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID) {
return false;
}
if ($compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID) {
return false;
}
if ($compare_from && strtotime($compare_from->post_date_gmt) > strtotime($compare_to->post_date_gmt)) {
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ($compare_from && empty($compare_from->post_title)) {
$compare_from->post_title = __('(no title)');
}
if (empty($compare_to->post_title)) {
$compare_to->post_title = __('(no title)');
}
$return = array();
foreach (_wp_post_revision_fields() as $field => $name) {
/**
* Contextually filter a post revision field.
*
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
* fields of the revision object being iterated over in a foreach statement.
*
* @since 3.6.0
*
* @param string $compare_from->$field The current revision field to compare to or from.
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post object to compare to or from.
* @param string null The context of whether the current revision is the old
* or the new one. Values are 'to' or 'from'.
*/
$content_from = $compare_from ? apply_filters("_wp_post_revision_field_{$field}", $compare_from->{$field}, $field, $compare_from, 'from') : '';
/** This filter is documented in wp-admin/includes/revision.php */
$content_to = apply_filters("_wp_post_revision_field_{$field}", $compare_to->{$field}, $field, $compare_to, 'to');
$args = array('show_split_view' => true);
/**
* Filter revisions text diff options.
*
* Filter the options passed to {@see wp_text_diff()} when viewing a post revision.
*
* @since 4.1.0
*
* @param array $args {
* Associative array of options to pass to {@see wp_text_diff()}.
*
* @type bool $show_split_view True for split view (two columns), false for
* un-split view (single column). Default true.
* }
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
$args = apply_filters('revision_text_diff_options', $args, $field, $compare_from, $compare_to);
$diff = wp_text_diff($content_from, $content_to, $args);
if (!$diff && 'post_title' === $field) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
$diff .= '<td>' . esc_html($compare_from->post_title) . '</td><td></td><td>' . esc_html($compare_to->post_title) . '</td>';
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ($diff) {
$return[] = array('id' => $field, 'name' => $name, 'diff' => $diff);
}
}
/**
//.........这里部分代码省略.........
function wsc_mod_rewrite()
{
global $cache_enabled, $super_cache_enabled, $valid_nonce, $cache_path, $wp_cache_mod_rewrite, $wpmu_version;
if (!$wp_cache_mod_rewrite) {
return false;
}
if (isset($wpmu_version) || function_exists('is_multisite') && is_multisite()) {
if (false == wpsupercache_site_admin()) {
return false;
}
if (function_exists("is_main_site") && false == is_main_site() || function_exists('is_main_blog') && false == is_main_blog()) {
global $current_site;
$protocol = 'on' == strtolower($_SERVER['HTTPS']) ? 'https://' : 'http://';
if (isset($wpmu_version)) {
$link_to_admin = admin_url("wpmu-admin.php?page=wpsupercache");
} else {
$link_to_admin = admin_url("ms-admin.php?page=wpsupercache");
}
echo '<div id="message" class="updated fade"><p>' . sprintf(__('Notice: WP Super Cache mod_rewrite rule checks disabled unless running on <a href="%s">the main site</a> of this network.', 'wp-super-cache'), $link_to_admin) . '</p></div>';
return false;
}
}
if (function_exists("is_main_site") && false == is_main_site() || function_exists('is_main_blog') && false == is_main_blog()) {
return true;
}
?>
<a name="modrewrite"></a><fieldset class="options">
<h3><?php
_e('Mod Rewrite Rules', 'wp-super-cache');
?>
</h3><?php
extract(wpsc_get_htaccess_info());
$dohtaccess = true;
global $wpmu_version;
if (isset($wpmu_version)) {
echo "<h4 style='color: #a00'>" . __('WordPress MU Detected', 'wp-super-cache') . "</h4><p>" . __("Unfortunately the rewrite rules cannot be updated automatically when running WordPress MU. Please open your .htaccess and add the following mod_rewrite rules above any other rules in that file.", 'wp-super-cache') . "</p>";
} elseif (!$wprules || $wprules == '') {
echo "<h4 style='color: #a00'>" . __('Mod Rewrite rules cannot be updated!', 'wp-super-cache') . "</h4>";
echo "<p>" . sprintf(__("You must have <strong>BEGIN</strong> and <strong>END</strong> markers in %s.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:", 'wp-super-cache'), $home_path);
echo "<blockquote><pre><em># BEGIN WordPress</em>\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule . /index.php [L]\n <em># END WordPress</em></pre></blockquote>";
_e('Refresh this page when you have updated your .htaccess file.', 'wp-super-cache');
echo "</fieldset>";
$dohtaccess = false;
} elseif (strpos($wprules, 'wordpressuser')) {
// Need to clear out old mod_rewrite rules
echo "<p><strong>" . __('Thank you for upgrading.', 'wp-super-cache') . "</strong> " . sprintf(__('The mod_rewrite rules changed since you last installed this plugin. Unfortunately you must remove the old supercache rules before the new ones are updated. Refresh this page when you have edited your .htaccess file. If you wish to manually upgrade, change the following line: %1$s so it looks like this: %2$s The only changes are "HTTP_COOKIE" becomes "HTTP:Cookie" and "wordpressuser" becomes "wordpress". This is a WordPress 2.5 change but it’s backwards compatible with older versions if you’re brave enough to use them.', 'wp-super-cache'), '<blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$</code></blockquote>', '<blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*$</code></blockquote>') . "</p>";
echo "</fieldset></div>";
return;
} elseif ($scrules != '' && strpos($scrules, '%{REQUEST_URI} !^.*[^/]$') === false && substr(get_option('permalink_structure'), -1) == '/') {
// permalink structure has a trailing slash, need slash check in rules.
echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __('Trailing slash check required.', 'wp-super-cache') . "</h4><p>" . __('It looks like your blog has URLs that end with a "/". Unfortunately since you installed this plugin a duplicate content bug has been found where URLs not ending in a "/" end serve the same content as those with the "/" and do not redirect to the proper URL. To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:', 'wp-super-cache') . "</p>";
echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]{$RewriteCond} %{REQUEST_URI} !^.*//.*\$</code></blockquote>";
echo "<p>" . __('You can see where the rules go and examine the complete rules by clicking the "View mod_rewrite rules" link below.', 'wp-super-cache') . "</p></div>";
$dohtaccess = false;
} elseif (strpos($scrules, 'supercache') || strpos($wprules, 'supercache')) {
// only write the rules once
$dohtaccess = false;
}
if ($dohtaccess && !$_POST['updatehtaccess']) {
if ($scrules == '') {
wpsc_update_htaccess_form(0);
// don't hide the update htaccess form
} else {
wpsc_update_htaccess_form();
}
} elseif ($valid_nonce && $_POST['updatehtaccess']) {
echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
if (wpsc_update_htaccess()) {
echo "<h4>" . __('Mod Rewrite rules updated!', 'wp-super-cache') . "</h4>";
echo "<p><strong>" . sprintf(__('%s.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:', 'wp-super-cache'), $home_path) . "</strong></p>\n";
} else {
echo "<h4>" . __('Mod Rewrite rules must be updated!', 'wp-super-cache') . "</h4>";
echo "<p><strong>" . sprintf(__('Your %s.htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:', 'wp-super-cache'), $home_path) . "</strong></p>\n";
}
echo "<p><pre>" . esc_html($rules) . "</pre></p>\n</div>";
} else {
?>
<p><?php
printf(__('WP Super Cache mod rewrite rules were detected in your %s.htaccess file.<br /> Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.', 'wp-super-cache'), $home_path);
?>
</p>
<?php
if ($rules != $scrules) {
?>
<p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><?php
_e('A difference between the rules in your .htaccess file and the plugin rewrite rules has been found. This could be simple whitespace differences but you should compare the rules in the file with those below as soon as possible. Click the ’Update Mod_Rewrite Rules’ button to update the rules.', 'wp-super-cache');
?>
</p><?php
}
?>
<a href="javascript:toggleLayer('rewriterules');" class="button"><?php
_e('View Mod_Rewrite Rules', 'wp-super-cache');
?>
</a><?php
wpsc_update_htaccess_form();
echo "<div id='rewriterules' style='display: none;'>";
if ($rules != $scrules) {
echo '<div style="background: #fff; border: 1px solid #333; margin: 2px;">' . wp_text_diff($scrules, $rules, array('title' => 'Rewrite Rules', 'title_left' => 'Current Rules', 'title_right' => 'New Rules')) . "</div>";
}
echo "<p><pre># BEGIN WPSuperCache\n" . esc_html($rules) . "# END WPSuperCache</pre></p>\n";
//.........这里部分代码省略.........
请发表评论