-
Notifications
You must be signed in to change notification settings - Fork 793
/
akismet.jsx
175 lines (163 loc) · 4.42 KB
/
akismet.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* External dependencies
*/
import React from 'react';
import { connect } from 'react-redux';
import DashItem from 'components/dash-item';
import { numberFormat, translate as __ } from 'i18n-calypso';
/**
* Internal dependencies
*/
import QueryAkismetData from 'components/data/query-akismet-data';
import {
getAkismetData as _getAkismetData
} from 'state/at-a-glance';
import { getSitePlan } from 'state/site';
import {
isModuleActivated as _isModuleActivated,
activateModule
} from 'state/modules';
const DashAkismet = React.createClass( {
activateManageAndRedirect: function( e ) {
e.preventDefault();
this.props.activateModule( 'manage' )
.then( window.location = 'https://wordpress.com/plugins/akismet/' + this.props.siteRawUrl )
.catch( console.log( 'Error: unable to activate Manage' ) );
},
getContent: function() {
const akismetData = this.props.getAkismetData(),
akismetSettingsUrl = this.props.siteAdminUrl + 'admin.php?page=akismet-key-config',
labelName = __( 'Spam Protection' ),
hasSitePlan = false !== this.props.getSitePlan();
if ( akismetData === 'N/A' ) {
return (
<DashItem
label={ labelName }
module="akismet"
pro={ true }
>
<p className="jp-dash-item__description">
{ __( 'Loading…' ) }
</p>
</DashItem>
);
}
if ( akismetData === 'not_installed' ) {
return (
<DashItem
label={ labelName }
module="akismet"
className="jp-dash-item__is-inactive"
status={ hasSitePlan ? 'pro-uninstalled' : 'no-pro-uninstalled-or-inactive' }
pro={ true }
>
<p className="jp-dash-item__description">
{
__( 'For state-of-the-art spam defense, please {{a}}install Akismet{{/a}}.', {
components: {
a: <a href={ 'https://wordpress.com/plugins/akismet/' + this.props.siteRawUrl } target="_blank" />
}
} )
}
</p>
</DashItem>
);
}
if ( akismetData === 'not_active' ) {
return (
<DashItem
label={ labelName }
module="akismet"
status={ hasSitePlan ? 'pro-inactive' : 'no-pro-uninstalled-or-inactive' }
className="jp-dash-item__is-inactive"
pro={ true }
>
<p className="jp-dash-item__description">
{
__( 'For state-of-the-art spam defense, please {{a}}activate Akismet{{/a}}.', {
components: {
a: <a href={ 'https://wordpress.com/plugins/akismet/' + this.props.siteRawUrl } target="_blank" />
}
} )
}
</p>
</DashItem>
);
}
if ( akismetData === 'invalid_key' ) {
return (
<DashItem
label={ labelName }
module="akismet"
className="jp-dash-item__is-inactive"
status="is-warning"
statusText={ __( 'Invalid Key' ) }
pro={ true }
siteAdminUrl={ this.props.siteAdminUrl }
>
<p className="jp-dash-item__description">
{
__( 'Whoops! Your Akismet key is missing or invalid. {{akismetSettings}}Go to Akismet settings to fix{{/akismetSettings}}.', {
components: {
akismetSettings: <a href={ akismetSettingsUrl } />
}
} )
}
</p>
</DashItem>
);
}
return (
<DashItem
label={ labelName }
module="akismet"
status="is-working"
pro={ true }
>
<h2 className="jp-dash-item__count">{ numberFormat( akismetData.all.spam ) }</h2>
<p className="jp-dash-item__description">
{
__( 'Spam comments blocked.', {
context: 'Example: "412 Spam comments blocked"'
} )
}
</p>
{/*
<strong>This is the data we could show here: </strong> <br/>
Spam blocked all-time: { akismetData.all.spam } <br/>
Time saved ( in seconds ): { akismetData.all.time_saved } <br/>
Accuracy: { akismetData.all.accuracy } <br/>
false positives: { akismetData.all.false_positives }
*/}
</DashItem>
);
},
render: function() {
return (
<div className="jp-dash-item__interior">
<QueryAkismetData />
{ this.getContent() }
</div>
);
}
} );
DashAkismet.propTypes = {
siteRawUrl: React.PropTypes.string.isRequired,
siteAdminUrl: React.PropTypes.string.isRequired
};
export default connect(
( state ) => {
return {
getAkismetData: () => _getAkismetData( state ),
isModuleActivated: ( module_name ) => _isModuleActivated( state, module_name ),
getSitePlan: () => getSitePlan( state )
};
},
( dispatch ) => {
return {
activateModule: ( slug ) => {
return dispatch( activateModule( slug ) );
}
}
}
)( DashAkismet );