summaryrefslogtreecommitdiff
blob: 31cc4da35512106d4c2fc53c496ce842a7eb2d67 (plain)
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
<?php
/*
 *   Display the configuration options for AtD
 */

/*
 *   A convienence function to display the HTML for an AtD option
 */
function AtD_print_option( $name, $value, $options ) {
	// Attribute-safe version of $name
	$attr_name = sanitize_title($name); // Using sanitize_title since there's no comparable function for attributes
?>
   <input type="checkbox" id="atd_<?php echo ($attr_name) ?>" name="<?php echo $options['name'] ?>[<?php echo $name; ?>]" value="1" <?php checked( '1', isset( $options[$name] ) ? $options[$name] : false ); ?>> <label for="atd_<?php echo $attr_name ?>"><?php echo $value; ?></label>
<?php
}

/*
 *  Save AtD options
 */
function AtD_process_options_update() {

	$user = wp_get_current_user();

	if ( ! $user || $user->ID == 0 )
		return;

	AtD_update_options( $user->ID, 'AtD_options' );
	AtD_update_options( $user->ID, 'AtD_check_when' );
	AtD_update_options( $user->ID, 'AtD_guess_lang' );
}

/*
 *  Display the various AtD options
 */
function AtD_display_options_form() {

	/* grab our user and validate their existence */
	$user = wp_get_current_user();
	if ( ! $user || $user->ID == 0 )
		return;

	$options_show_types = AtD_get_options( $user->ID, 'AtD_options' );
	$options_check_when = AtD_get_options( $user->ID, 'AtD_check_when' );
	$options_guess_lang = AtD_get_options( $user->ID, 'AtD_guess_lang' );
?>
   <table class="form-table">
      <tr valign="top">
         <th scope="row"> <a name="atd"></a> <?php _e( 'Proofreading', 'jetpack' ); ?></th>
		 <td>
   <p><?php _e( 'Automatically proofread content when:', 'jetpack' ); ?>

   <p><?php 
		AtD_print_option( 'onpublish', __('a post or page is first published', 'jetpack'), $options_check_when ); 
		echo '<br />';
		AtD_print_option( 'onupdate', __('a post or page is updated', 'jetpack'), $options_check_when );
   ?></p>

   <p style="font-weight: bold"><?php _e('English Options', 'jetpack'); ?></font>

   <p><?php _e('Enable proofreading for the following grammar and style rules when writing posts and pages:', 'jetpack'); ?></p>

   <p><?php 
		AtD_print_option( 'Bias Language', __('Bias Language', 'jetpack'), $options_show_types );
		echo '<br />';
		AtD_print_option( 'Cliches', __('Clich&eacute;s', 'jetpack'), $options_show_types );
		echo '<br />';
		AtD_print_option( 'Complex Expression', __('Complex Phrases', 'jetpack'), $options_show_types ); 
		echo '<br />';
		AtD_print_option( 'Diacritical Marks', __('Diacritical Marks', 'jetpack'), $options_show_types );
		echo '<br />';
		AtD_print_option( 'Double Negative', __('Double Negatives', 'jetpack'), $options_show_types );
		echo '<br />';
		AtD_print_option( 'Hidden Verbs', __('Hidden Verbs', 'jetpack'), $options_show_types );
		echo '<br />';
		AtD_print_option( 'Jargon Language', __('Jargon', 'jetpack'), $options_show_types ); 
		echo '<br />';
		AtD_print_option( 'Passive voice', __('Passive Voice', 'jetpack'), $options_show_types ); 
		echo '<br />';
		AtD_print_option( 'Phrases to Avoid', __('Phrases to Avoid', 'jetpack'), $options_show_types ); 
		echo '<br />';
		AtD_print_option( 'Redundant Expression', __('Redundant Phrases', 'jetpack'), $options_show_types ); 
   ?></p>
   <p><?php printf( __( '<a href="%s">Learn more</a> about these options.', 'jetpack' ), 'http://support.wordpress.com/proofreading/' ); 
?></p>

   <p style="font-weight: bold"><?php _e( 'Language', 'jetpack' ); ?></font>

   <p><?php printf(
	_x( 'The proofreader supports English, French, German, Portuguese, and Spanish. Your <a href="%1$s">%2%s</a> value is the default proofreading language.', '%1$s = http://codex.wordpress.org/Installing_WordPress_in_Your_Language, %2$s = WPLANG', 'jetpack' ),
	'http://codex.wordpress.org/Installing_WordPress_in_Your_Language',
	'WPLANG'
   ); ?></p>

   <p><?php
	AtD_print_option( 'true', __('Use automatically detected language to proofread posts and pages', 'jetpack' ), $options_guess_lang );
   ?></p>

<?php
}

/*
 *  Returns an array of AtD user options specified by $name
 */
function AtD_get_options( $user_id, $name ) {
	$options_raw = AtD_get_setting( $user_id, $name, 'single' );
	
	$options = array();
	$options['name'] = $name;

	if ( $options_raw )
		foreach ( explode( ',', $options_raw ) as $option ) 
			$options[ $option ] = 1;
	
	return $options;
}

/*
 *  Saves set of user options specified by $name from POST data
 */
function AtD_update_options( $user_id, $name ) {
	/* We should probably run $_POST[name] through an esc_*() function... */
	if ( isset( $_POST[$name] ) && is_array( $_POST[$name] ) ) {
		$copy = array_map( 'strip_tags', array_keys( $_POST[$name] ) );
		AtD_update_setting( $user_id, AtD_sanitize( $name ), implode( ',', $copy )  );
	} else {
		AtD_update_setting( $user_id, AtD_sanitize( $name ), '');
	}
	
	return;
}