Skip to content

Commit c88044f

Browse files
committed
closes #55 drop offline zip functionality
1 parent 0d2e36b commit c88044f

File tree

11 files changed

+5
-194
lines changed

11 files changed

+5
-194
lines changed

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Everyone's WordPress hosting environment and configuration is unique, with diffe
144144
* Matching project name to wp.org slug
145145
* Implement code quality tooling
146146
* Performance optimization for slow hosting providers
147+
* rm offline zip functionality
147148
* Minor fix for setting base HREF option
148149
* use WP's mime-types lookup for S3 deployer
149150

src/CSSProcessor.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ class CSSProcessor extends StaticHTMLOutput {
1111
* @var string
1212
*/
1313
public $destination_protocol_relative_url;
14-
/**
15-
* @var bool
16-
*/
17-
public $allow_offline_usage;
1814
/**
1915
* @var bool
2016
*/
@@ -89,7 +85,6 @@ class CSSProcessor extends StaticHTMLOutput {
8985
public $processed_urls;
9086

9187
public function __construct(
92-
bool $allow_offline_usage = false,
9388
bool $remove_conditional_head_comments = false,
9489
bool $remove_html_comments = false,
9590
bool $remove_wp_links = false,
@@ -102,7 +97,6 @@ public function __construct(
10297
string $wp_site_url,
10398
string $wp_uploads_path
10499
) {
105-
$this->allow_offline_usage = $allow_offline_usage;
106100
$this->remove_conditional_head_comments = $remove_conditional_head_comments;
107101
$this->remove_html_comments = $remove_html_comments;
108102
$this->remove_wp_links = $remove_wp_links;
@@ -248,7 +242,7 @@ public function isInternalLink( string $link, string $domain = '' ) : bool {
248242
* We don't use the CSSParser's output, as it
249243
* mangles the output too much. We simply do placeholder URL
250244
* rewrites to destination URL. This may need to be improved
251-
* for URL format transformations (relative/offline URLs), at
245+
* for URL format transformations (relative URLs), at
252246
* which point, we may store a list of each file's URLs and how
253247
* they need to be transformed, then do that on the raw CSS here.
254248
*

src/DBSettings.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public static function get( array $sets = [] ) {
3333

3434
$key_sets['processing'] = [
3535
'removeConditionalHeadComments',
36-
'allowOfflineUsage',
3736
'baseHREF',
3837
'rewrite_rules',
3938
'rename_rules',
@@ -61,7 +60,6 @@ public static function get( array $sets = [] ) {
6160

6261
$key_sets['zip'] = [
6362
'baseUrl-zip',
64-
'allowOfflineUsage',
6563
];
6664

6765
$key_sets['github'] = [
@@ -161,9 +159,6 @@ public static function get( array $sets = [] ) {
161159
(int) $plugin->options->crawl_increment :
162160
10;
163161

164-
// NOTE: any baseUrl required if creating an offline ZIP
165-
$settings['baseUrl'] = rtrim( $plugin->options->baseUrl, '/' ) . '/';
166-
167162
return array_filter( $settings );
168163
}
169164
}

src/HTMLProcessor.php

Lines changed: 1 addition & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
class 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

src/Options.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class Options {
2222
*/
2323
protected $statichtmloutput_options_keys = [
2424
'additionalUrls',
25-
'allowOfflineUsage',
2625
'baseHREF',
2726
'baseUrl',
2827
'baseUrl-bitbucket',
@@ -99,7 +98,6 @@ class Options {
9998
*/
10099
protected $whitelisted_keys = [
101100
'additionalUrls',
102-
'allowOfflineUsage',
103101
'baseHREF',
104102
'baseUrl',
105103
'baseUrl-bitbucket',

src/PostSettings.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static function get( array $sets = [] ) : array {
3131

3232
$key_sets['processing'] = [
3333
'removeConditionalHeadComments',
34-
'allowOfflineUsage',
3534
'baseHREF',
3635
'rewrite_rules',
3736
'rename_rules',
@@ -59,7 +58,6 @@ public static function get( array $sets = [] ) : array {
5958

6059
$key_sets['zip'] = [
6160
'baseUrl-zip',
62-
'allowOfflineUsage',
6361
];
6462

6563
$key_sets['github'] = [
@@ -164,13 +162,6 @@ public static function get( array $sets = [] ) : array {
164162
(int) $_POST['crawl_increment'] :
165163
1;
166164

167-
// any baseUrl required if creating an offline ZIP
168-
$settings['baseUrl'] =
169-
isset( $_POST['baseUrl'] ) ?
170-
rtrim( $_POST['baseUrl'], '/' ) . '/' :
171-
'http://OFFLINEZIP.wpsho';
172-
// @codingStandardsIgnoreEnd
173-
174165
return array_filter( $settings );
175166
}
176167
}

src/SiteCrawler.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ public function loadFileForProcessing() : bool {
497497

498498
// prepare bool settings
499499
$bool_settings = [
500-
'allowOfflineUsage',
501500
'removeConditionalHeadComments',
502501
'removeHTMLComments',
503502
'removeWPLinks',
@@ -512,7 +511,6 @@ public function loadFileForProcessing() : bool {
512511
}
513512

514513
$processor = new HTMLProcessor(
515-
$this->settings['allowOfflineUsage'],
516514
$this->settings['removeConditionalHeadComments'],
517515
$this->settings['removeHTMLComments'],
518516
$this->settings['removeWPLinks'],
@@ -557,7 +555,6 @@ public function loadFileForProcessing() : bool {
557555

558556
// prepare bool settings
559557
$bool_settings = [
560-
'allowOfflineUsage',
561558
'removeConditionalHeadComments',
562559
'removeHTMLComments',
563560
'removeWPLinks',
@@ -571,7 +568,6 @@ public function loadFileForProcessing() : bool {
571568
}
572569
}
573570
$processor = new CSSProcessor(
574-
$this->settings['allowOfflineUsage'],
575571
$this->settings['removeConditionalHeadComments'],
576572
$this->settings['removeHTMLComments'],
577573
$this->settings['removeWPLinks'],

tests/CSSProcessorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public function testParsingStylesheets( string $raw_css, string $parsed_css ) {
3636
3737
*/
3838
$css_processor = new CSSProcessor(
39-
false, // $allow_offline_usage = false
4039
false, // $remove_conditional_head_comments = false
4140
false, // $remove_html_comments = false
4241
false, // $remove_wp_links = false

0 commit comments

Comments
 (0)