1010
1111class HTMLProcessor extends StaticHTMLOutput {
1212
13- /**
14- * @var bool
15- */
16- public $ allow_offline_usage ;
1713 /**
1814 * @var bool
1915 */
@@ -100,7 +96,6 @@ class HTMLProcessor extends StaticHTMLOutput {
10096 public $ processed_urls ;
10197
10298 public function __construct (
103- bool $ allow_offline_usage = false ,
10499 bool $ remove_conditional_head_comments = false ,
105100 bool $ remove_html_comments = false ,
106101 bool $ remove_wp_links = false ,
@@ -113,7 +108,6 @@ public function __construct(
113108 string $ wp_site_url ,
114109 string $ wp_uploads_path
115110 ) {
116- $ this ->allow_offline_usage = $ allow_offline_usage ;
117111 $ this ->remove_conditional_head_comments = $ remove_conditional_head_comments ;
118112 $ this ->remove_html_comments = $ remove_html_comments ;
119113 $ this ->remove_wp_links = $ remove_wp_links ;
@@ -281,7 +275,6 @@ public function processLink( DOMElement $element ) : void {
281275 $ this ->rewriteWPPaths ( $ element );
282276 $ this ->rewriteBaseURL ( $ element );
283277 $ this ->convertToRelativeURL ( $ element );
284- $ this ->convertToOfflineURL ( $ element );
285278
286279 if ( $ this ->remove_wp_links ) {
287280 $ relative_links_to_rm = [
@@ -405,7 +398,6 @@ public function processImageSrcSet( DOMElement $element ) : void {
405398 $ url = $ this ->rewriteWPPathsSrcSetURL ( (string ) $ url );
406399 $ url = $ this ->rewriteBaseURLSrcSetURL ( $ url );
407400 $ url = $ this ->convertToRelativeURLSrcSetURL ( $ url );
408- $ url = $ this ->convertToOfflineURLSrcSetURL ( $ url );
409401 }
410402
411403 $ new_src_set [] = "{$ url } {$ dimension }" ;
@@ -421,7 +413,6 @@ public function processImage( DOMElement $element ) : void {
421413 $ this ->rewriteWPPaths ( $ element );
422414 $ this ->rewriteBaseURL ( $ element );
423415 $ this ->convertToRelativeURL ( $ element );
424- $ this ->convertToOfflineURL ( $ element );
425416 }
426417
427418 public function stripHTMLComments () : void {
@@ -479,7 +470,6 @@ public function processScript( DOMElement $element ) : void {
479470 $ this ->rewriteWPPaths ( $ element );
480471 $ this ->rewriteBaseURL ( $ element );
481472 $ this ->convertToRelativeURL ( $ element );
482- $ this ->convertToOfflineURL ( $ element );
483473 }
484474
485475 public function processAnchor ( DOMElement $ element ) : void {
@@ -507,7 +497,6 @@ public function processAnchor( DOMElement $element ) : void {
507497 $ this ->rewriteWPPaths ( $ element );
508498 $ this ->rewriteBaseURL ( $ element );
509499 $ this ->convertToRelativeURL ( $ element );
510- $ this ->convertToOfflineURL ( $ element );
511500 }
512501
513502 public function processMeta ( DOMElement $ element ) : void {
@@ -549,7 +538,6 @@ public function processMeta( DOMElement $element ) : void {
549538 $ this ->rewriteWPPaths ( $ element );
550539 $ this ->rewriteBaseURL ( $ element );
551540 $ this ->convertToRelativeURL ( $ element );
552- $ this ->convertToOfflineURL ( $ element );
553541 }
554542
555543 public function writeDiscoveredURLs () : void {
@@ -924,91 +912,6 @@ public function convertToRelativeURL( DOMElement $element ) : void {
924912 }
925913 }
926914
927- public function convertToOfflineURLSrcSetURL ( string $ url_to_change ) : string {
928- if ( ! $ this ->shouldCreateOfflineURLs () ) {
929- return $ url_to_change ;
930- }
931-
932- $ current_page_path_to_root = '' ;
933- $ current_page_path = parse_url ( $ this ->page_url , PHP_URL_PATH );
934- $ number_of_segments_in_path = explode ( '/ ' , (string ) $ current_page_path );
935- $ num_dots_to_root = count ( $ number_of_segments_in_path ) - 2 ;
936-
937- for ( $ i = 0 ; $ i < $ num_dots_to_root ; $ i ++ ) {
938- $ current_page_path_to_root .= '../ ' ;
939- }
940-
941- if ( ! $ this ->isInternalLink (
942- $ url_to_change
943- ) ) {
944- return $ url_to_change ;
945- }
946-
947- $ rewritten_url = str_replace (
948- $ this ->placeholder_url ,
949- '' ,
950- $ url_to_change
951- );
952-
953- $ offline_url = $ current_page_path_to_root . $ rewritten_url ;
954-
955- // add index.html if no extension
956- if ( substr ( $ offline_url , -1 ) === '/ ' ) {
957- // TODO: check XML/RSS case
958- $ offline_url .= 'index.html ' ;
959- }
960-
961- return $ offline_url ;
962- }
963-
964- public function convertToOfflineURL ( DOMElement $ element ) : void {
965- if ( ! $ this ->shouldCreateOfflineURLs () ) {
966- return ;
967- }
968-
969- if ( $ element ->hasAttribute ( 'href ' ) ) {
970- $ attribute_to_change = 'href ' ;
971- } elseif ( $ element ->hasAttribute ( 'src ' ) ) {
972- $ attribute_to_change = 'src ' ;
973- } elseif ( $ element ->hasAttribute ( 'content ' ) ) {
974- $ attribute_to_change = 'content ' ;
975- } else {
976- return ;
977- }
978-
979- $ url_to_change = $ element ->getAttribute ( $ attribute_to_change );
980- $ current_page_path_to_root = '' ;
981- $ current_page_path = parse_url ( $ this ->page_url , PHP_URL_PATH );
982- $ number_of_segments_in_path = explode ( '/ ' , (string ) $ current_page_path );
983- $ num_dots_to_root = count ( $ number_of_segments_in_path ) - 2 ;
984-
985- for ( $ i = 0 ; $ i < $ num_dots_to_root ; $ i ++ ) {
986- $ current_page_path_to_root .= '../ ' ;
987- }
988-
989- if ( ! $ this ->isInternalLink (
990- $ url_to_change
991- ) ) {
992- return ;
993- }
994-
995- $ rewritten_url = str_replace (
996- $ this ->placeholder_url ,
997- '' ,
998- $ url_to_change
999- );
1000-
1001- $ offline_url = $ current_page_path_to_root . $ rewritten_url ;
1002-
1003- // add index.html if no extension
1004- if ( substr ( $ offline_url , -1 ) === '/ ' ) {
1005- // TODO: check XML/RSS case
1006- $ offline_url .= 'index.html ' ;
1007- }
1008-
1009- $ element ->setAttribute ( $ attribute_to_change , $ offline_url );
1010- }
1011-
1012915 // TODO: move some of these URLs into settings to avoid extra calls
1013916 public function getProtocolRelativeURL ( string $ url ) : string {
1014917 $ this ->destination_protocol_relative_url = str_replace (
@@ -1118,40 +1021,14 @@ public function rewriteSiteURLsToPlaceholder(
11181021 }
11191022
11201023 public function shouldUseRelativeURLs () : bool {
1121- if ( ! $ this ->use_relative_urls ) {
1122- return false ;
1123- }
1124-
1125- // NOTE: relative URLs should not be used when creating an offline ZIP
1126- if ( $ this ->allow_offline_usage ) {
1127- return false ;
1128- }
1129-
1130- return true ;
1024+ return $ this ->use_relative_urls ;
11311025 }
11321026
11331027 public function shouldCreateBaseHREF () : bool {
11341028 if ( empty ( $ this ->base_href ) ) {
11351029 return false ;
11361030 }
11371031
1138- // NOTE: base HREF should not be set when creating an offline ZIP
1139- if ( $ this ->allow_offline_usage ) {
1140- return false ;
1141- }
1142-
1143- return true ;
1144- }
1145-
1146- public function shouldCreateOfflineURLs () : bool {
1147- if ( ! $ this ->allow_offline_usage ) {
1148- return false ;
1149- }
1150-
1151- if ( $ this ->selected_deployment_option != 'zip ' ) {
1152- return false ;
1153- }
1154-
11551032 return true ;
11561033 }
11571034
0 commit comments