Skip to content

Commit dbe2fe5

Browse files
committed
feat: add error message. fix bug with subfolder
1 parent a928678 commit dbe2fe5

33 files changed

+122
-46
lines changed

plugin.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,39 +103,76 @@ function VFA_vuefront_admin_action_turn_off() {
103103
function VFA_vuefront_admin_action_turn_on() {
104104
try {
105105
if ( strpos( $_SERVER["SERVER_SOFTWARE"], "Apache" ) !== false ) {
106+
$catalog = get_site_url();
107+
$catalog_url_info = parse_url($catalog);
108+
109+
$catalog_path = $catalog_url_info['path'];
110+
111+
$catalog_path = $catalog_path == '' ? '/' : $catalog_path;
112+
if(!file_exists(ABSPATH . '.htaccess')) {
113+
file_put_contents(ABSPATH.'.htaccess', "# BEGIN WordPress
114+
<IfModule mod_rewrite.c>
115+
RewriteEngine On
116+
RewriteBase ".$catalog_path."
117+
RewriteRule ^index\.php$ - [L]
118+
RewriteCond %{REQUEST_FILENAME} !-f
119+
RewriteCond %{REQUEST_FILENAME} !-d
120+
RewriteRule . /index.php [L]
121+
</IfModule>
122+
123+
# END WordPress
124+
");
125+
}
126+
127+
if(!is_writable(ABSPATH . '.htaccess')) {
128+
// http_response_code(500);
129+
// header("HTTP/1.1 401 Unauthorized");
130+
// status_header(500);
131+
// echo json_encode(array(
132+
// 'error'=> 'not_writable_htaccess'
133+
// ));
134+
$error = new WP_Error( '500', 'not_writable_htaccess' );
135+
136+
wp_send_json_error( $error, 500 );
137+
return;
138+
// new WP_Error( json_encode(array(
139+
// 'error'=> 'not_writable_htaccess'
140+
// )));
141+
}
142+
106143
if ( file_exists( ABSPATH . '.htaccess' ) ) {
107144
$inserting = "# VueFront scripts, styles and images
108145
RewriteCond %{REQUEST_URI} .*(_nuxt)
109-
RewriteCond %{REQUEST_URI} !.*vuefront/_nuxt
146+
RewriteCond %{REQUEST_URI} !.*/vuefront/_nuxt
110147
RewriteRule ^([^?]*) vuefront/$1
111148
112149
# VueFront pages
113150
114151
# VueFront home page
115152
RewriteCond %{REQUEST_URI} !.*(images|index.php|.html|admin|.js|.css|.png|.jpeg|.ico|wp-json|wp-admin|checkout)
116153
RewriteCond %{QUERY_STRING} !.*(rest_route)
117-
RewriteCond %{DOCUMENT_ROOT}/vuefront/index.html -f
154+
RewriteCond %{DOCUMENT_ROOT}".$catalog_path."vuefront/index.html -f
118155
RewriteRule ^$ vuefront/index.html [L]
119156
120157
RewriteCond %{REQUEST_URI} !.*(images|index.php|.html|admin|.js|.css|.png|.jpeg|.ico|wp-json|wp-admin|checkout)
121158
RewriteCond %{QUERY_STRING} !.*(rest_route)
122-
RewriteCond %{DOCUMENT_ROOT}/vuefront/index.html !-f
159+
RewriteCond %{DOCUMENT_ROOT}".$catalog_path."vuefront/index.html !-f
123160
RewriteRule ^$ vuefront/200.html [L]
124161
125162
# VueFront page if exists html file
126163
RewriteCond %{REQUEST_FILENAME} !-f
127164
RewriteCond %{REQUEST_FILENAME} !-d
128165
RewriteCond %{REQUEST_URI} !.*(images|index.php|.html|admin|.js|.css|.png|.jpeg|.ico|wp-json|wp-admin|checkout)
129166
RewriteCond %{QUERY_STRING} !.*(rest_route)
130-
RewriteCond %{DOCUMENT_ROOT}/vuefront/$1.html -f
167+
RewriteCond %{DOCUMENT_ROOT}".$catalog_path."vuefront/$1.html -f
131168
RewriteRule ^([^?]*) vuefront/$1.html [L,QSA]
132169
133170
# VueFront page if not exists html file
134171
RewriteCond %{REQUEST_FILENAME} !-f
135172
RewriteCond %{REQUEST_FILENAME} !-d
136173
RewriteCond %{REQUEST_URI} !.*(images|index.php|.html|admin|.js|.css|.png|.jpeg|.ico|wp-json|wp-admin|checkout)
137174
RewriteCond %{QUERY_STRING} !.*(rest_route)
138-
RewriteCond %{DOCUMENT_ROOT}/vuefront/$1.html !-f
175+
RewriteCond %{DOCUMENT_ROOT}".$catalog_path."vuefront/$1.html !-f
139176
RewriteRule ^([^?]*) vuefront/200.html [L,QSA]";
140177

141178
$content = file_get_contents(ABSPATH . '.htaccess');

view/javascript/d_pax/components/firstBuild.vue

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
>
2727
{{ $t('footerTitlePopup') }}
2828
</div>
29+
<div class="text-center">
30+
<div
31+
v-if="error"
32+
class="first-build__error"
33+
>
34+
{{ $t(error) }}
35+
</div>
36+
</div>
2937
<div
3038
v-if="information.apache"
3139
class="text-center"
@@ -73,7 +81,7 @@ export default {
7381
}
7482
},
7583
computed: {
76-
...mapGetters({information: 'information/get', cms: 'cms/get'})
84+
...mapGetters({information: 'information/get', cms: 'cms/get', error: 'error'})
7785
},
7886
methods: {
7987
async handleSearch() {
@@ -89,8 +97,12 @@ export default {
8997
} else {
9098
await this.$store.dispatch('information/deActivateVueFront', {url: this.cms.downloadUrl})
9199
}
92-
this.$store.commit('cms/setFirstBuild', false)
100+
93101
this.loading = false
102+
103+
if(!this.error) {
104+
this.$store.commit('cms/setFirstBuild', false)
105+
}
94106
},
95107
handleClose() {
96108
this.$store.commit('cms/setFirstBuild', false)
@@ -105,7 +117,8 @@ export default {
105117
"text_bellow": "instructions",
106118
"footerTitlePopup": "Would you like us to do this for you?",
107119
"buttonConfirm": "Activate",
108-
"buttonAbort": "Close"
120+
"buttonAbort": "Close",
121+
"not_writable_htaccess": "File permissions. Please add writing permissions to the following files and folder: .htaccess"
109122
}
110123
</i18n>
111124
<style lang="scss">
@@ -128,6 +141,12 @@ export default {
128141
&__image {
129142
margin-bottom: 30px;
130143
}
144+
&__error {
145+
color: $tomato;
146+
margin-bottom: 20px;
147+
font-family: 'Open Sans', sans-serif;
148+
font-size: 16px;
149+
}
131150
&__title {
132151
font-family: 'Open Sans', sans-serif;
133152
font-size: 30px;

view/javascript/d_pax/components/header/Activation.vue

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
>
5555
{{ $t('footerTitlePopup') }}
5656
</div>
57+
<div class="text-center">
58+
<div
59+
v-if="error"
60+
class="cms-activation__modal__error"
61+
>
62+
{{ $t(error) }}
63+
</div>
64+
</div>
5765
<div class="text-center">
5866
<b-button
5967
:disabled="loading"
@@ -103,19 +111,16 @@ export default {
103111
computed: {
104112
...mapGetters({
105113
information: 'information/get',
106-
cms: 'cms/get'
114+
cms: 'cms/get',
115+
error: 'error'
107116
})
108117
},
109118
methods: {
110119
async handleClick() {
111120
if(!this.information.status) {
112-
if(this.information.apache) {
113121
this.popup = true
114-
} else {
115-
this.loading = true
116-
await this.$store.dispatch('information/activateVueFront', {url: this.cms.downloadUrl})
117-
}
118122
} else {
123+
this.loading = true
119124
await this.$store.dispatch('information/deActivateVueFront', {url: this.cms.downloadUrl})
120125
}
121126
this.loading = false
@@ -133,8 +138,10 @@ export default {
133138
} else {
134139
await this.$store.dispatch('information/deActivateVueFront', {url: this.cms.downloadUrl})
135140
}
136-
this.popup = false
137141
this.loading = false
142+
if(!this.error) {
143+
this.popup = false
144+
}
138145
}
139146
}
140147
}
@@ -150,7 +157,8 @@ export default {
150157
"descriptionPopup": "To ensure your security, we will make a copy of your .htaccess file at <br>[path]. In case of unexpected situations or even site failure, please restore your old .htaccess file via ftp or your Cpanel file manager.",
151158
"buttonConfirm": "Confirm",
152159
"buttonAbort": "Abort",
153-
"footerTitlePopup": "Ready to turn your website into a PWA and SPA?"
160+
"footerTitlePopup": "Ready to turn your website into a PWA and SPA?",
161+
"not_writable_htaccess": "File permissions. Please add writing permissions to the following files and folder: .htaccess"
154162
}
155163
</i18n>
156164
<style lang="scss">
@@ -184,6 +192,12 @@ export default {
184192
&__image {
185193
margin-bottom: 30px;
186194
}
195+
&__error {
196+
color: $tomato;
197+
margin-bottom: 20px;
198+
font-family: 'Open Sans', sans-serif;
199+
font-size: 16px;
200+
}
187201
&__title {
188202
font-family: 'Open Sans', sans-serif;
189203
font-size: 30px;

view/javascript/d_pax/store/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export const mutations = {
1414
state.error = e.graphQLErrors[0].message.error
1515
} else if (e.graphQLErrors) {
1616
state.error = e.graphQLErrors
17+
} else if (e.response){
18+
if(e.response.data.data[0].message) {
19+
state.error = e.response.data.data[0].message
20+
} else {
21+
state.error = e.response.data.error
22+
}
1723
} else {
1824
state.error = e
1925
}

view/javascript/d_vuefront/0.5eab5c8e0c23abfb49ac.bundle.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

view/javascript/d_vuefront/0.e2bff312d2fc637e1a8b.bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)