Changeset 23769 for trunk/wp-admin/includes/ajax-actions.php
- Timestamp:
- 03/21/2013 03:54:11 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/ajax-actions.php
r23743 r23769 2124 2124 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 2125 2125 2126 $left_revision = get_post( $compare_to ); 2127 2126 2128 //single model fetch mode 2129 //return the diff of a single revision comparison 2127 2130 if ( 0 != $single_revision_id ) { 2128 $left_revision = get_post( $compare_to );2129 2131 $right_revision = get_post( $single_revision_id ); 2130 2132 2133 // 2134 //make sure the left revision is the most recent 2135 // 2136 2137 if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) { 2138 $temp = $left_revision; 2139 $left_revision = $right_revision; 2140 $right_revision = $temp; 2141 } 2142 2143 $linesadded=0; 2144 $linesdeleted=0; 2145 2146 // 2147 //compare from left to right, passed from application 2148 // 2149 $content=''; 2150 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2151 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2152 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); 2153 2154 add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' ); 2155 2156 $args = array(); 2157 2158 if ( ! empty( $show_split_view ) ) 2159 $args = array( 'show_split_view' => true ); 2160 2161 $diff = wp_text_diff_with_count( $left_content, $right_content, $args ); 2162 2163 if ( isset( $diff[ 'html' ] ) ) 2164 $content .= $diff[ 'html' ]; 2165 2166 if ( isset( $diff[ 'linesadded' ] ) ) 2167 $linesadded = $linesadded + $diff[ 'linesadded' ]; 2168 2169 if ( isset( $diff[ 'linesdeleted' ] ) ) 2170 $linesdeleted = $linesdeleted + $diff[ 'linesdeleted' ]; 2171 2172 2173 } 2174 $content = '' == $content ? __( 'No difference' ) : $content; 2175 2176 $alltherevisions = array ( 2177 'revisiondiff' => $content, 2178 'lines_deleted' => $linesdeleted, 2179 'lines_added' => $linesadded 2180 ); 2181 echo json_encode( $alltherevisions ); 2182 exit(); 2183 } //end single model fetch 2184 2185 //fetch the list of revisions available 2186 2187 //if we are comparing two revisions, the first 'revision' represented by the leftmost 2188 //slider position is the current revision, prepend a comparison to this revision 2189 if ( ! wp_first_revision_matches_current_version( $post_id ) ) //revisions don't have current version 2190 array_unshift( $revisions, get_post( $post_id ) ) ; 2191 //$revisions->append ( get_post( $post_id ) ); 2192 //error_log( var_dump( $revisions )); 2193 $count = -1; 2194 2195 //reverse the list to start with oldes revision 2196 $revisions = array_reverse( $revisions ); 2197 2198 $previous_revision_id = 0; 2199 foreach ( $revisions as $revision ) : 2200 //error_log( ( $show_autosaves )); 2201 if ( empty( $show_autosaves ) && wp_is_post_autosave( $revision ) ) 2202 continue; 2203 2204 $revision_from_date_author = ''; 2205 $count++; 2206 // return blank data for diffs to the left of the left handle (for right handel model) 2207 // or to the right of the right handle (for left handel model) 2208 if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) || 2209 ( 0 != $right_handle_at && $count > $right_handle_at )) { 2210 $alltherevisions[] = array ( 2211 'ID' => $revision->ID, 2212 ); 2213 continue; 2214 } 2215 2131 2216 if ( $compare_two_mode ) { 2132 $compare_to_gravatar = get_avatar( $left_revision->post_author, 18);2217 $compare_to_gravatar = get_avatar( $left_revision->post_author, 24 ); 2133 2218 $compare_to_author = get_the_author_meta( 'display_name', $left_revision->post_author ); 2134 2219 $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); … … 2144 2229 } 2145 2230 2146 // 2147 //make sure the left revision is the most recent 2148 // 2149 if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) { 2150 $temp = $left_revision; 2151 $left_revision = $right_revision; 2152 $right_revision = $temp; 2153 } 2154 2155 // 2156 //compare from left to right, passed from application 2157 // 2158 $content=''; 2159 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2160 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2161 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); 2162 2163 add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' ); 2164 2165 $args = array(); 2166 2167 if ( ! empty( $show_split_view ) ) 2168 $args = array( 'show_split_view' => true ); 2169 2170 $content .= wp_text_diff( $left_content, $right_content, $args ); 2171 } 2172 $content = '' == $content ? __( 'No difference' ) : $content; 2173 $alltherevisions = array ( 2174 'revisiondiff' => $content 2175 ); 2176 echo json_encode( $alltherevisions ); 2177 exit(); 2178 } 2179 2180 //if we are comparing two revisions, the first 'revision' represented by the leftmost 2181 //slider position is the current revision, prepend a comparison to this revision 2182 if ( $compare_two_mode ) 2183 array_unshift( $revisions, get_post( $post_id ) ); 2184 2185 $count = -1; 2186 2187 foreach ( $revisions as $revision ) : 2188 if ( ! empty( $show_autosaves ) && wp_is_post_autosave( $revision ) ) 2189 continue; 2190 2191 $revision_from_date_author = ''; 2192 $count++; 2193 // return blank data for diffs to the left of the left handle (for right handel model) 2194 // or to the right of the right handle (for left handel model) 2195 if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) || 2196 ( 0 != $right_handle_at && $count > $right_handle_at )) { 2197 $alltherevisions[] = array ( 2198 'ID' => $revision->ID, 2199 ); 2200 2201 continue; 2202 } 2203 2204 $gravatar = get_avatar( $revision->post_author, 18 ); 2231 $gravatar = get_avatar( $revision->post_author, 24 ); 2205 2232 $author = get_the_author_meta( 'display_name', $revision->post_author ); 2206 2233 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); … … 2214 2241 ); 2215 2242 2243 $autosavef = __( '%1$s [Autosave]' ); 2244 $currentf = __( '%1$s [Current Revision]' ); 2245 2246 if ( ! $post = get_post( $post_id)) 2247 exit(); 2248 2249 if ( $left_revision->post_modified === $post->post_modified ) 2250 $revision_from_date_author = sprintf( $currentf, $revision_from_date_author ); 2251 elseif ( wp_is_post_autosave( $left_revision ) ) 2252 $revision_from_date_author = sprintf( $autosavef, $revision_from_date_author ); 2253 2254 if ( $revision->post_modified === $post->post_modified ) 2255 $revision_date_author = sprintf( $currentf, $revision_date_author ); 2256 elseif ( wp_is_post_autosave( $revision ) ) 2257 $revision_date_author = sprintf( $autosavef, $revision_date_author ); 2258 2259 $date_short_format = __( 'j M @ G:i' ); 2260 $date_short = date_i18n( $date_short_format, strtotime( $revision->post_modified ) ); 2261 2262 $revision_date_author_short = sprintf( 2263 '%s <strong>%s</strong><br />%s', 2264 $gravatar, 2265 $author, 2266 $date_short 2267 ); 2268 2216 2269 $restoreaction = wp_nonce_url( 2217 2270 add_query_arg( … … 2220 2273 admin_url( 'revision.php' ) 2221 2274 ), 2222 "restore-post_{$ compare_to}|{$revision->ID}"2275 "restore-post_{$revision->ID}" 2223 2276 ); 2224 2225 $alltherevisions[] = array ( 2277 // if this is a left handled calculation swap data 2278 if ( 0 != $right_handle_at ) { 2279 $tmp = $revision_from_date_author; 2280 $revision_from_date_author = $revision_date_author; 2281 $revision_date_author = $tmp; 2282 } 2283 if ( ( $compare_two_mode || 0 !== $previous_revision_id ) ) { 2284 $alltherevisions[] = array ( 2226 2285 'ID' => $revision->ID, 2227 2286 'revision_date_author' => $revision_date_author, 2228 2287 'revision_from_date_author' => $revision_from_date_author, 2288 'revision_date_author_short' => $revision_date_author_short, 2229 2289 'restoreaction' => urldecode( $restoreaction ), 2230 'revision_toload' => true 2290 'revision_toload' => true, 2291 'previous_revision_id' => $previous_revision_id 2231 2292 ); 2293 } 2294 $previous_revision_id = $revision->ID; 2232 2295 2233 2296 endforeach;
Note: See TracChangeset
for help on using the changeset viewer.