| @@ -114,8 +114,9 @@ | ||
| 114 | 114 | * |
| 115 | 115 | * @return string Translated string |
| 116 | 116 | */ |
| 117 | 117 | public function get_message() { |
| 118 | + // translators: Placeholders refer to a file name, and a theme / plugin name (e.g. "index.php", "Stream") | |
| 118 | 119 | return _x( |
| 119 | 120 | '"%1$s" in "%2$s" updated', |
| 120 | 121 | '1: File name, 2: Theme/plugin name', |
| 121 | 122 | 'stream' |
| @@ -145,10 +146,10 @@ | ||
| 145 | 146 | |
| 146 | 147 | if ( $theme_exists ) { |
| 147 | 148 | $links[ esc_html__( 'Edit File', 'stream' ) ] = add_query_arg( |
| 148 | 149 | array( |
| 149 | - 'theme' => urlencode( $theme_slug ), | |
| 150 | - 'file' => urlencode( $file_name ), | |
| 150 | + 'theme' => rawurlencode( $theme_slug ), | |
| 151 | + 'file' => rawurlencode( $file_name ), | |
| 151 | 152 | ), |
| 152 | 153 | self_admin_url( 'theme-editor.php' ) |
| 153 | 154 | ); |
| 154 | 155 | |
| @@ -153,9 +154,9 @@ | ||
| 153 | 154 | ); |
| 154 | 155 | |
| 155 | 156 | $links[ esc_html__( 'Theme Details', 'stream' ) ] = add_query_arg( |
| 156 | 157 | array( |
| 157 | - 'theme' => urlencode( $theme_slug ), | |
| 158 | + 'theme' => rawurlencode( $theme_slug ), | |
| 158 | 159 | ), |
| 159 | 160 | self_admin_url( 'themes.php' ) |
| 160 | 161 | ); |
| 161 | 162 | } |
| @@ -162,10 +163,10 @@ | ||
| 162 | 163 | |
| 163 | 164 | if ( $plugin_exists ) { |
| 164 | 165 | $links[ esc_html__( 'Edit File', 'stream' ) ] = add_query_arg( |
| 165 | 166 | array( |
| 166 | - 'plugin' => urlencode( $plugin_slug ), | |
| 167 | - 'file' => urlencode( str_ireplace( trailingslashit( WP_PLUGIN_DIR ), '', $file_path ) ), | |
| 167 | + 'plugin' => rawurlencode( $plugin_slug ), | |
| 168 | + 'file' => rawurlencode( str_ireplace( trailingslashit( WP_PLUGIN_DIR ), '', $file_path ) ), | |
| 168 | 169 | ), |
| 169 | 170 | self_admin_url( 'plugin-editor.php' ) |
| 170 | 171 | ); |
| 171 | 172 | } |
| @@ -185,9 +186,9 @@ | ||
| 185 | 186 | if ( |
| 186 | 187 | ( |
| 187 | 188 | isset( $_SERVER['REQUEST_METHOD'] ) |
| 188 | 189 | && |
| 189 | - 'POST' !== esc_attr( $_SERVER['REQUEST_METHOD'] ) | |
| 190 | + 'POST' !== sanitize_text_field( $_SERVER['REQUEST_METHOD'] ) | |
| 190 | 191 | ) |
| 191 | 192 | || |
| 192 | 193 | 'update' !== wp_stream_filter_input( INPUT_POST, 'action' ) |
| 193 | 194 | ) { |
| @@ -193,14 +194,16 @@ | ||
| 193 | 194 | ) { |
| 194 | 195 | return; |
| 195 | 196 | } |
| 196 | 197 | |
| 197 | - if ( $slug = wp_stream_filter_input( INPUT_POST, 'theme' ) ) { | |
| 198 | - $this->edited_file = $this->get_theme_data( $slug ); | |
| 198 | + $theme_slug = wp_stream_filter_input( INPUT_POST, 'theme' ); | |
| 199 | + if ( $theme_slug ) { | |
| 200 | + $this->edited_file = $this->get_theme_data( $theme_slug ); | |
| 199 | 201 | } |
| 200 | 202 | |
| 201 | - if ( $slug = wp_stream_filter_input( INPUT_POST, 'plugin' ) ) { | |
| 202 | - $this->edited_file = $this->get_plugin_data( $slug ); | |
| 203 | + $plugin_slug = wp_stream_filter_input( INPUT_POST, 'plugin' ); | |
| 204 | + if ( $plugin_slug ) { | |
| 205 | + $this->edited_file = $this->get_plugin_data( $plugin_slug ); | |
| 203 | 206 | } |
| 204 | 207 | } |
| 205 | 208 | |
| 206 | 209 | /** |
| @@ -230,17 +233,15 @@ | ||
| 230 | 233 | $file_name = $file; |
| 231 | 234 | $file_path = sprintf( '%s/%s', $theme->get_stylesheet_directory(), $file_name ); |
| 232 | 235 | } |
| 233 | 236 | |
| 234 | - //TODO: phpcs fix | |
| 235 | - $file_contents_before = file_get_contents( $file_path ); | |
| 237 | + $file_md5 = md5_file( $file_path ); | |
| 238 | + $name = $theme->get( 'Name' ); | |
| 236 | 239 | |
| 237 | - $name = $theme->get( 'Name' ); | |
| 238 | - | |
| 239 | 240 | $output = compact( |
| 240 | 241 | 'file_name', |
| 241 | 242 | 'file_path', |
| 242 | - 'file_contents_before', | |
| 243 | + 'file_md5', | |
| 243 | 244 | 'slug', |
| 244 | 245 | 'name' |
| 245 | 246 | ); |
| 246 | 247 | |
| @@ -258,14 +259,11 @@ | ||
| 258 | 259 | $name = null; |
| 259 | 260 | $slug = current( explode( '/', $slug ) ); |
| 260 | 261 | $file_name = wp_stream_filter_input( INPUT_POST, 'file' ); |
| 261 | 262 | $file_path = WP_PLUGIN_DIR . '/' . $file_name; |
| 263 | + $file_md5 = md5_file( $file_path ); | |
| 264 | + $plugins = get_plugins(); | |
| 262 | 265 | |
| 263 | - //TODO: phpcs fix | |
| 264 | - $file_contents_before = file_get_contents( $file_path ); | |
| 265 | - | |
| 266 | - $plugins = get_plugins(); | |
| 267 | - | |
| 268 | 266 | foreach ( $plugins as $key => $plugin_data ) { |
| 269 | 267 | if ( 0 === strpos( $key, $slug ) ) { |
| 270 | 268 | $base = $key; |
| 271 | 269 | $name = $plugin_data['Name']; |
| @@ -278,9 +276,9 @@ | ||
| 278 | 276 | |
| 279 | 277 | $output = compact( |
| 280 | 278 | 'file_name', |
| 281 | 279 | 'file_path', |
| 282 | - 'file_contents_before', | |
| 280 | + 'file_md5', | |
| 283 | 281 | 'slug', |
| 284 | 282 | 'name' |
| 285 | 283 | ); |
| 286 | 284 | |
| @@ -292,9 +290,9 @@ | ||
| 292 | 290 | */ |
| 293 | 291 | public function log_changes( $location ) { |
| 294 | 292 | if ( ! empty( $this->edited_file ) ) { |
| 295 | 293 | // TODO: phpcs fix |
| 296 | - if ( file_get_contents( $this->edited_file['file_path'] ) !== $this->edited_file['file_contents_before'] ) { | |
| 294 | + if ( md5_file( $this->edited_file['file_path'] ) !== $this->edited_file['file_md5'] ) { | |
| 297 | 295 | $context = $this->get_context( $location ); |
| 298 | 296 | |
| 299 | 297 | switch ( $context ) { |
| 300 | 298 | case 'themes': |