@@ -89,14 +89,12 @@ public function processIter(
89
89
return $ crawl_responses ;
90
90
}
91
91
92
- $ rewriter = new SimpleRewriter ();
93
- $ process = function ( $ crawl_responses ) use ( $ rewriter ) {
92
+ $ process = function ( $ crawl_responses ) {
94
93
foreach ( $ crawl_responses as $ crawled ) {
95
94
$ content_type = $ crawled ->content_type ;
96
95
if ( $ content_type && $ this ->processContentType ( $ content_type ) ) {
97
96
if ( $ crawled ->body ) {
98
- $ rewritten = $ rewriter ->rewriteFileContents (
99
- $ this ->config ,
97
+ $ rewritten = $ this ->rewriteFileContents (
100
98
$ crawled ->body ,
101
99
);
102
100
if ( $ rewritten !== $ crawled ->body ) {
@@ -105,8 +103,7 @@ public function processIter(
105
103
++$ this ->processed ;
106
104
} elseif ( $ crawled ->filename ) {
107
105
$ file_contents = file_get_contents ( $ crawled ->filename );
108
- $ rewritten = $ rewriter ->rewriteFileContents (
109
- $ this ->config ,
106
+ $ rewritten = $ this ->rewriteFileContents (
110
107
$ file_contents
111
108
);
112
109
if ( $ rewritten !== $ file_contents ) {
@@ -124,6 +121,28 @@ public function processIter(
124
121
return $ process ( $ crawl_responses );
125
122
}
126
123
124
+ /**
125
+ * Rewrite URLs in a string to destination_url
126
+ *
127
+ * @param string $file_contents
128
+ * @return string
129
+ */
130
+ public function rewriteFileContents (
131
+ string $ file_contents ,
132
+ ): string {
133
+ // TODO: allow empty file saving here? Exception for style.css
134
+ if ( ! $ file_contents ) {
135
+ return '' ;
136
+ }
137
+
138
+ $ rewritten_contents = strtr (
139
+ $ file_contents ,
140
+ $ this ->config ->replacement_patterns
141
+ );
142
+
143
+ return $ rewritten_contents ;
144
+ }
145
+
127
146
public function complete (): void {
128
147
WsLog::l (
129
148
"Post processing complete. $ this ->processed processed, $ this ->skipped skipped. "
0 commit comments