@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Return true if the current page is the mijireh checkout page, otherwise return false. |
|
114 | - * |
|
115 | - * @return boolean |
|
116 | - */ |
|
113 | + * Return true if the current page is the mijireh checkout page, otherwise return false. |
|
114 | + * |
|
115 | + * @return boolean |
|
116 | + */ |
|
117 | 117 | public static function is_slurp_page() { |
118 | 118 | global $post; |
119 | 119 | $isSlurp = false; |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * adds the callback to adding the slurp page metabox, which shoudl only appear on a page with the {{mj-checkout-form}} "shortcode" |
|
134 | - * @return void |
|
135 | - */ |
|
133 | + * adds the callback to adding the slurp page metabox, which shoudl only appear on a page with the {{mj-checkout-form}} "shortcode" |
|
134 | + * @return void |
|
135 | + */ |
|
136 | 136 | public static function add_slurp_page_metabox() { |
137 | 137 | if(self::is_slurp_page() && EEM_Payment_Method::instance()->get_one_active( EEM_Payment_Method::scope_cart, array( array( 'PMD_type' => 'Mijireh' ) ) ) ){ |
138 | 138 | add_meta_box( |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | - * outputs HTML for displaying the slurping metabox |
|
151 | - * @param WP_Post $post |
|
152 | - * @return void echoes out html |
|
153 | - */ |
|
150 | + * outputs HTML for displaying the slurping metabox |
|
151 | + * @param WP_Post $post |
|
152 | + * @return void echoes out html |
|
153 | + */ |
|
154 | 154 | public static function slurp_page_metabox($post) { |
155 | 155 | global $wp; |
156 | 156 | $mijireh_payment_method = EEM_Payment_Method::instance()->get_one_of_type( 'Mijireh' ); |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
171 | - * decides whether to slurp the post indicated by the $post global or not, based entirely |
|
172 | - * on a special arg being in the querystring |
|
173 | - * @return void |
|
174 | - */ |
|
171 | + * decides whether to slurp the post indicated by the $post global or not, based entirely |
|
172 | + * on a special arg being in the querystring |
|
173 | + * @return void |
|
174 | + */ |
|
175 | 175 | public static function slurp_or_not(){ |
176 | 176 | //check if this page has the right mijire 'shortcode' and if they've specified to slurp it |
177 | 177 | if(isset($_GET['mijireh_slurp_now']) && $_GET['mijireh_slurp_now'] == 'true' && EED_Mijireh_Slurper::is_slurp_page()){ |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Sends a request to mijireh to slurp the current $post, and then redirects the user back to the current page without the |
|
184 | - * special querystring arg indicating to slurp. Also, should temporarily make the current post published, then revert it to its previous status |
|
185 | - */ |
|
183 | + * Sends a request to mijireh to slurp the current $post, and then redirects the user back to the current page without the |
|
184 | + * special querystring arg indicating to slurp. Also, should temporarily make the current post published, then revert it to its previous status |
|
185 | + */ |
|
186 | 186 | public static function slurp_now(){ |
187 | 187 | global $post; |
188 | 188 | if ( $post->post_status != 'publish' ) { |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | * @return void |
50 | 50 | */ |
51 | 51 | public static function set_hooks_admin() { |
52 | - define('EED_MIJIREH_SLURPER_PATH',EE_CAFF_PATH.'modules'.DS.'mijireh_slurper'.DS); |
|
53 | - add_action('load-post.php',array('EED_Mijireh_Slurper','set_edit_post_page_hooks')); |
|
54 | - add_action('load-admin.php',array('EED_Mijireh_Slurper','check_for_edit_slurp_page')); |
|
55 | - add_action('AHEE__EE_Mijireh__settings_end',array('EED_Mijireh_Slurper','add_slurp_link_to_gateway')); |
|
52 | + define('EED_MIJIREH_SLURPER_PATH', EE_CAFF_PATH.'modules'.DS.'mijireh_slurper'.DS); |
|
53 | + add_action('load-post.php', array('EED_Mijireh_Slurper', 'set_edit_post_page_hooks')); |
|
54 | + add_action('load-admin.php', array('EED_Mijireh_Slurper', 'check_for_edit_slurp_page')); |
|
55 | + add_action('AHEE__EE_Mijireh__settings_end', array('EED_Mijireh_Slurper', 'add_slurp_link_to_gateway')); |
|
56 | 56 | } |
57 | 57 | /** |
58 | 58 | * Merely used to avoid even bothering to add these hooks on pages besides admin's post.php |
59 | 59 | */ |
60 | - public static function set_edit_post_page_hooks(){ |
|
61 | - add_action('add_meta_boxes',array('EED_Mijireh_Slurper','add_slurp_page_metabox')); |
|
62 | - add_action('posts_selection',array('EED_Mijireh_Slurper','slurp_or_not')); |
|
63 | - if(get_transient(EED_Mijireh_Slurper::slurp_started_transient_name)){ |
|
64 | - add_action( 'admin_notices', array('EED_Mijireh_Slurper', 'slurping_in_progress_notice') ); |
|
60 | + public static function set_edit_post_page_hooks() { |
|
61 | + add_action('add_meta_boxes', array('EED_Mijireh_Slurper', 'add_slurp_page_metabox')); |
|
62 | + add_action('posts_selection', array('EED_Mijireh_Slurper', 'slurp_or_not')); |
|
63 | + if (get_transient(EED_Mijireh_Slurper::slurp_started_transient_name)) { |
|
64 | + add_action('admin_notices', array('EED_Mijireh_Slurper', 'slurping_in_progress_notice')); |
|
65 | 65 | delete_transient(EED_Mijireh_Slurper::slurp_started_transient_name); |
66 | 66 | } |
67 | 67 | } |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | * Adds the slurping content to the gateway's settings page, because I thought this was best suited to remain in the module's code (because |
71 | 71 | * the gateway works fine independent of this module) |
72 | 72 | */ |
73 | - public static function add_slurp_link_to_gateway($existing_content){ |
|
74 | - echo EEH_Template::display_template( EED_MIJIREH_SLURPER_PATH.'templates/additional_content_on_gateway.template.php', array(),true ) . $existing_content; |
|
73 | + public static function add_slurp_link_to_gateway($existing_content) { |
|
74 | + echo EEH_Template::display_template(EED_MIJIREH_SLURPER_PATH.'templates/additional_content_on_gateway.template.php', array(), true).$existing_content; |
|
75 | 75 | } |
76 | - public static function slurping_in_progress_notice(){ |
|
77 | - EEH_Template::display_template( EED_MIJIREH_SLURPER_PATH.'templates/slurping_in_progress_notice.template.php', array() ); |
|
76 | + public static function slurping_in_progress_notice() { |
|
77 | + EEH_Template::display_template(EED_MIJIREH_SLURPER_PATH.'templates/slurping_in_progress_notice.template.php', array()); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | * need to first make it). If the special arg is present, redirects the user to the slurp page's edit page |
84 | 84 | * @return void |
85 | 85 | */ |
86 | - public static function check_for_edit_slurp_page(){ |
|
87 | - if(isset($_GET['mijireh_edit_slurp_page']) && $_GET['mijireh_edit_slurp_page'] == 'true'){ |
|
86 | + public static function check_for_edit_slurp_page() { |
|
87 | + if (isset($_GET['mijireh_edit_slurp_page']) && $_GET['mijireh_edit_slurp_page'] == 'true') { |
|
88 | 88 | //check if we already have a slurping page |
89 | - if( ! $slurp_page_id = self::find_slurp_page() ){ |
|
89 | + if ( ! $slurp_page_id = self::find_slurp_page()) { |
|
90 | 90 | //if no slurp page yet, make one |
91 | 91 | $slurp_page_id = wp_insert_post( |
92 | 92 | array( |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | } |
99 | - wp_redirect(add_query_arg(array('post'=>$slurp_page_id,'action'=>'edit'),admin_url('post.php'))); |
|
99 | + wp_redirect(add_query_arg(array('post'=>$slurp_page_id, 'action'=>'edit'), admin_url('post.php'))); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * Gets the post id which has the {{mj-checkout-form}} "shortcode" in it, otherwise null |
105 | 105 | * @return int |
106 | 106 | */ |
107 | - public static function find_slurp_page(){ |
|
107 | + public static function find_slurp_page() { |
|
108 | 108 | global $wpdb; |
109 | 109 | return $wpdb->get_var("SELECT id FROM {$wpdb->posts} WHERE post_content LIKE '%".EED_Mijireh_Slurper::mijireh_slurper_shortcode."%'"); |
110 | 110 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | public static function is_slurp_page() { |
118 | 118 | global $post; |
119 | 119 | $isSlurp = false; |
120 | - if(isset($post) && is_object($post)) { |
|
120 | + if (isset($post) && is_object($post)) { |
|
121 | 121 | $content = $post->post_content; |
122 | - if( strpos($content, EED_Mijireh_Slurper::mijireh_slurper_shortcode ) !== false ) { |
|
122 | + if (strpos($content, EED_Mijireh_Slurper::mijireh_slurper_shortcode) !== false) { |
|
123 | 123 | $isSlurp = true; |
124 | 124 | } |
125 | 125 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @return void |
135 | 135 | */ |
136 | 136 | public static function add_slurp_page_metabox() { |
137 | - if(self::is_slurp_page() && EEM_Payment_Method::instance()->get_one_active( EEM_Payment_Method::scope_cart, array( array( 'PMD_type' => 'Mijireh' ) ) ) ){ |
|
137 | + if (self::is_slurp_page() && EEM_Payment_Method::instance()->get_one_active(EEM_Payment_Method::scope_cart, array(array('PMD_type' => 'Mijireh')))) { |
|
138 | 138 | add_meta_box( |
139 | 139 | 'slurp_meta_box', // $id |
140 | 140 | 'Mijireh Page Slurp', // $title |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public static function slurp_page_metabox($post) { |
155 | 155 | global $wp; |
156 | - $mijireh_payment_method = EEM_Payment_Method::instance()->get_one_of_type( 'Mijireh' ); |
|
157 | - if( $mijireh_payment_method ){ |
|
158 | - $access_key = $mijireh_payment_method->get_extra_meta( 'access_key', TRUE ); |
|
156 | + $mijireh_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Mijireh'); |
|
157 | + if ($mijireh_payment_method) { |
|
158 | + $access_key = $mijireh_payment_method->get_extra_meta('access_key', TRUE); |
|
159 | 159 | EEH_Template::display_template( |
160 | 160 | EED_MIJIREH_SLURPER_PATH.'templates/mijireh_slurp_page_metabox.template.php', |
161 | 161 | array( |
162 | 162 | 'mijireh_image_url'=> $mijireh_payment_method->button_url(), |
163 | 163 | 'access_key'=>$access_key, |
164 | - 'slurp_action_link'=> esc_url_raw( add_query_arg('mijireh_slurp_now','true', add_query_arg( $wp->query_string, '', '?'.$_SERVER['QUERY_STRING'] ))) |
|
164 | + 'slurp_action_link'=> esc_url_raw(add_query_arg('mijireh_slurp_now', 'true', add_query_arg($wp->query_string, '', '?'.$_SERVER['QUERY_STRING']))) |
|
165 | 165 | ) |
166 | 166 | ); |
167 | 167 | } |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | * on a special arg being in the querystring |
173 | 173 | * @return void |
174 | 174 | */ |
175 | - public static function slurp_or_not(){ |
|
175 | + public static function slurp_or_not() { |
|
176 | 176 | //check if this page has the right mijire 'shortcode' and if they've specified to slurp it |
177 | - if(isset($_GET['mijireh_slurp_now']) && $_GET['mijireh_slurp_now'] == 'true' && EED_Mijireh_Slurper::is_slurp_page()){ |
|
177 | + if (isset($_GET['mijireh_slurp_now']) && $_GET['mijireh_slurp_now'] == 'true' && EED_Mijireh_Slurper::is_slurp_page()) { |
|
178 | 178 | EED_Mijireh_Slurper::slurp_now(); |
179 | 179 | } |
180 | 180 | } |
@@ -183,22 +183,22 @@ discard block |
||
183 | 183 | * Sends a request to mijireh to slurp the current $post, and then redirects the user back to the current page without the |
184 | 184 | * special querystring arg indicating to slurp. Also, should temporarily make the current post published, then revert it to its previous status |
185 | 185 | */ |
186 | - public static function slurp_now(){ |
|
186 | + public static function slurp_now() { |
|
187 | 187 | global $post; |
188 | - if ( $post->post_status != 'publish' ) { |
|
188 | + if ($post->post_status != 'publish') { |
|
189 | 189 | //make sure the post is published at least while slurping |
190 | 190 | $post->post_status = 'publish'; |
191 | 191 | wp_update_post($post); |
192 | 192 | } |
193 | - $mijireh_gateway = EEM_Payment_Method::instance()->get_one_of_type( 'Mijireh' ); |
|
194 | - $access_key = $mijireh_gateway->get_extra_meta( 'access_key', TRUE ); |
|
193 | + $mijireh_gateway = EEM_Payment_Method::instance()->get_one_of_type('Mijireh'); |
|
194 | + $access_key = $mijireh_gateway->get_extra_meta('access_key', TRUE); |
|
195 | 195 | // 'slurp_url'=>get_permalink($post), |
196 | 196 | // 'page_id'=>$post->ID, |
197 | 197 | // 'return_url'=>$return_url |
198 | 198 | $url = 'https://secure.mijireh.com/api/1/slurps'; |
199 | 199 | $args = array( |
200 | 200 | 'headers' => array( |
201 | - 'Authorization' => 'Basic ' . base64_encode( $access_key . ':' ), |
|
201 | + 'Authorization' => 'Basic '.base64_encode($access_key.':'), |
|
202 | 202 | 'Accept'=>'application/json' |
203 | 203 | ), |
204 | 204 | 'body'=>json_encode( |
@@ -209,12 +209,12 @@ discard block |
||
209 | 209 | ) |
210 | 210 | ) |
211 | 211 | ); |
212 | - $response = wp_remote_post($url,$args); |
|
212 | + $response = wp_remote_post($url, $args); |
|
213 | 213 | //now redirect the user back to the same page |
214 | 214 | $redirect_args = $_GET; |
215 | 215 | unset($redirect_args['mijireh_slurp_now']); |
216 | - $url = add_query_arg($redirect_args,admin_url('post.php')); |
|
217 | - set_transient(EED_Mijireh_Slurper::slurp_started_transient_name,true); |
|
216 | + $url = add_query_arg($redirect_args, admin_url('post.php')); |
|
217 | + set_transient(EED_Mijireh_Slurper::slurp_started_transient_name, true); |
|
218 | 218 | // echo "redirect to $url"; |
219 | 219 | wp_redirect($url); |
220 | 220 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @access public |
226 | 226 | * @return void |
227 | 227 | */ |
228 | - public function run( $WP ) { |
|
228 | + public function run($WP) { |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | } |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -122,8 +124,7 @@ discard block |
||
122 | 124 | if( strpos($content, EED_Mijireh_Slurper::mijireh_slurper_shortcode ) !== false ) { |
123 | 125 | $isSlurp = true; |
124 | 126 | } |
125 | - } |
|
126 | - else { |
|
127 | + } else { |
|
127 | 128 | // echo '[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Check Slurp Page Failed: " . print_r($post, 1); |
128 | 129 | } |
129 | 130 | return $isSlurp; |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <tr> |
2 | - <th><?php _e("Mijireh Checkout Page Design", 'event_espresso');?><?php echo EEH_Template::get_help_tab_link( 'ee_mijireh_help_tab' ); ?></th> |
|
2 | + <th><?php _e("Mijireh Checkout Page Design", 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link('ee_mijireh_help_tab'); ?></th> |
|
3 | 3 | <td> |
4 | - <a href="?mijireh_edit_slurp_page=true"><?php _e("Edit Slurp Page", 'event_espresso');?></a> |
|
4 | + <a href="?mijireh_edit_slurp_page=true"><?php _e("Edit Slurp Page", 'event_espresso'); ?></a> |
|
5 | 5 | </td> |
6 | 6 | </tr> |
7 | 7 | \ No newline at end of file |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <div id='mijireh_notice' class='mijireh-info alert-message info' data-alert='alert'> |
2 | - <div class='mijireh-logo'><img src='<?php echo $mijireh_image_url;?>' alt='<?php printf( esc_attr__( '%s Checkout Logo', 'event_espresso' ), 'Mijereh' ); ?>'></div> |
|
2 | + <div class='mijireh-logo'><img src='<?php echo $mijireh_image_url; ?>' alt='<?php printf(esc_attr__('%s Checkout Logo', 'event_espresso'), 'Mijereh'); ?>'></div> |
|
3 | 3 | <div class='mijireh-blurb'> |
4 | - <h2><?php _e("Slurp Into Mijireh", 'event_espresso');?></h2> |
|
5 | - <p><?php printf(__("Design the page how you want, and be sure to include the special text {{mj-checkout-form}} to indicate where to place Mijireh's Checkout Form. You may want to read %s Mijireh's instructions on slurping%s.", 'event_espresso'),"<a href='http://www.mijireh.com/docs/what-is-page-slurp/'>","</a>");?> |
|
4 | + <h2><?php _e("Slurp Into Mijireh", 'event_espresso'); ?></h2> |
|
5 | + <p><?php printf(__("Design the page how you want, and be sure to include the special text {{mj-checkout-form}} to indicate where to place Mijireh's Checkout Form. You may want to read %s Mijireh's instructions on slurping%s.", 'event_espresso'), "<a href='http://www.mijireh.com/docs/what-is-page-slurp/'>", "</a>"); ?> |
|
6 | 6 | |
7 | 7 | <p class='aligncenter'><a href='<?php echo $slurp_action_link?>' id='page_slurp' class='button-primary'>Slurp This Page!</a></p> |
8 | 8 | <p class="aligncenter"><a class="nobold" href="https://secure.mijireh.com/checkout/<?php echo $access_key?>" id="view_slurp" target="_new">Preview Checkout Page</a></p> |
@@ -1,3 +1,3 @@ |
||
1 | 1 | <div class="updated"> |
2 | - <p><?php _e( "Mijireh is currently slurping your content. This will usually take a few minutes. Please login to Mijireh to see the slurp's progress", 'event_espresso' ); ?></p> |
|
2 | + <p><?php _e("Mijireh is currently slurping your content. This will usually take a few minutes. Please login to Mijireh to see the slurp's progress", 'event_espresso'); ?></p> |
|
3 | 3 | </div> |
4 | 4 | \ No newline at end of file |
@@ -31,67 +31,67 @@ |
||
31 | 31 | */ |
32 | 32 | class ReCaptcha |
33 | 33 | { |
34 | - /** |
|
35 | - * Version of this client library. |
|
36 | - * @const string |
|
37 | - */ |
|
38 | - const VERSION = 'php_1.1.1'; |
|
34 | + /** |
|
35 | + * Version of this client library. |
|
36 | + * @const string |
|
37 | + */ |
|
38 | + const VERSION = 'php_1.1.1'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Shared secret for the site. |
|
42 | - * @var type string |
|
43 | - */ |
|
44 | - private $secret; |
|
40 | + /** |
|
41 | + * Shared secret for the site. |
|
42 | + * @var type string |
|
43 | + */ |
|
44 | + private $secret; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Method used to communicate with service. Defaults to POST request. |
|
48 | - * @var RequestMethod |
|
49 | - */ |
|
50 | - private $requestMethod; |
|
46 | + /** |
|
47 | + * Method used to communicate with service. Defaults to POST request. |
|
48 | + * @var RequestMethod |
|
49 | + */ |
|
50 | + private $requestMethod; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Create a configured instance to use the reCAPTCHA service. |
|
54 | - * |
|
55 | - * @param string $secret shared secret between site and reCAPTCHA server. |
|
56 | - * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
57 | - */ |
|
58 | - public function __construct($secret, RequestMethod $requestMethod = null) |
|
59 | - { |
|
60 | - if (empty($secret)) { |
|
61 | - throw new \RuntimeException('No secret provided'); |
|
62 | - } |
|
52 | + /** |
|
53 | + * Create a configured instance to use the reCAPTCHA service. |
|
54 | + * |
|
55 | + * @param string $secret shared secret between site and reCAPTCHA server. |
|
56 | + * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
57 | + */ |
|
58 | + public function __construct($secret, RequestMethod $requestMethod = null) |
|
59 | + { |
|
60 | + if (empty($secret)) { |
|
61 | + throw new \RuntimeException('No secret provided'); |
|
62 | + } |
|
63 | 63 | |
64 | - if (!is_string($secret)) { |
|
65 | - throw new \RuntimeException('The provided secret must be a string'); |
|
66 | - } |
|
64 | + if (!is_string($secret)) { |
|
65 | + throw new \RuntimeException('The provided secret must be a string'); |
|
66 | + } |
|
67 | 67 | |
68 | - $this->secret = $secret; |
|
68 | + $this->secret = $secret; |
|
69 | 69 | |
70 | - if (!is_null($requestMethod)) { |
|
71 | - $this->requestMethod = $requestMethod; |
|
72 | - } else { |
|
73 | - $this->requestMethod = new RequestMethod\Post(); |
|
74 | - } |
|
75 | - } |
|
70 | + if (!is_null($requestMethod)) { |
|
71 | + $this->requestMethod = $requestMethod; |
|
72 | + } else { |
|
73 | + $this->requestMethod = new RequestMethod\Post(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
79 | - * CAPTCHA test. |
|
80 | - * |
|
81 | - * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
82 | - * @param string $remoteIp The end user's IP address. |
|
83 | - * @return Response Response from the service. |
|
84 | - */ |
|
85 | - public function verify($response, $remoteIp = null) |
|
86 | - { |
|
87 | - // Discard empty solution submissions |
|
88 | - if (empty($response)) { |
|
89 | - $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
90 | - return $recaptchaResponse; |
|
91 | - } |
|
77 | + /** |
|
78 | + * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
79 | + * CAPTCHA test. |
|
80 | + * |
|
81 | + * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
82 | + * @param string $remoteIp The end user's IP address. |
|
83 | + * @return Response Response from the service. |
|
84 | + */ |
|
85 | + public function verify($response, $remoteIp = null) |
|
86 | + { |
|
87 | + // Discard empty solution submissions |
|
88 | + if (empty($response)) { |
|
89 | + $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
90 | + return $recaptchaResponse; |
|
91 | + } |
|
92 | 92 | |
93 | - $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
94 | - $rawResponse = $this->requestMethod->submit($params); |
|
95 | - return Response::fromJson($rawResponse); |
|
96 | - } |
|
93 | + $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
94 | + $rawResponse = $this->requestMethod->submit($params); |
|
95 | + return Response::fromJson($rawResponse); |
|
96 | + } |
|
97 | 97 | } |
@@ -61,13 +61,13 @@ |
||
61 | 61 | throw new \RuntimeException('No secret provided'); |
62 | 62 | } |
63 | 63 | |
64 | - if (!is_string($secret)) { |
|
64 | + if ( ! is_string($secret)) { |
|
65 | 65 | throw new \RuntimeException('The provided secret must be a string'); |
66 | 66 | } |
67 | 67 | |
68 | 68 | $this->secret = $secret; |
69 | 69 | |
70 | - if (!is_null($requestMethod)) { |
|
70 | + if ( ! is_null($requestMethod)) { |
|
71 | 71 | $this->requestMethod = $requestMethod; |
72 | 72 | } else { |
73 | 73 | $this->requestMethod = new RequestMethod\Post(); |
@@ -10,38 +10,38 @@ |
||
10 | 10 | */ |
11 | 11 | class Curl implements RequestMethod |
12 | 12 | { |
13 | - /** |
|
14 | - * URL to which requests are sent via cURL. |
|
15 | - * @const string |
|
16 | - */ |
|
17 | - const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
13 | + /** |
|
14 | + * URL to which requests are sent via cURL. |
|
15 | + * @const string |
|
16 | + */ |
|
17 | + const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Submit the cURL request with the specified parameters. |
|
21 | - * |
|
22 | - * @param RequestParameters $params Request parameters |
|
23 | - * @return string Body of the reCAPTCHA response |
|
24 | - */ |
|
25 | - public function submit(RequestParameters $params) |
|
26 | - { |
|
27 | - $handle = curl_init(self::SITE_VERIFY_URL); |
|
19 | + /** |
|
20 | + * Submit the cURL request with the specified parameters. |
|
21 | + * |
|
22 | + * @param RequestParameters $params Request parameters |
|
23 | + * @return string Body of the reCAPTCHA response |
|
24 | + */ |
|
25 | + public function submit(RequestParameters $params) |
|
26 | + { |
|
27 | + $handle = curl_init(self::SITE_VERIFY_URL); |
|
28 | 28 | |
29 | - $options = array( |
|
30 | - CURLOPT_POST => true, |
|
31 | - CURLOPT_POSTFIELDS => $params->toQueryString(), |
|
32 | - CURLOPT_HTTPHEADER => array( |
|
33 | - 'Content-Type: application/x-www-form-urlencoded' |
|
34 | - ), |
|
35 | - CURLINFO_HEADER_OUT => false, |
|
36 | - CURLOPT_HEADER => false, |
|
37 | - CURLOPT_RETURNTRANSFER => true, |
|
38 | - CURLOPT_SSL_VERIFYPEER => true |
|
39 | - ); |
|
40 | - curl_setopt_array($handle, $options); |
|
29 | + $options = array( |
|
30 | + CURLOPT_POST => true, |
|
31 | + CURLOPT_POSTFIELDS => $params->toQueryString(), |
|
32 | + CURLOPT_HTTPHEADER => array( |
|
33 | + 'Content-Type: application/x-www-form-urlencoded' |
|
34 | + ), |
|
35 | + CURLINFO_HEADER_OUT => false, |
|
36 | + CURLOPT_HEADER => false, |
|
37 | + CURLOPT_RETURNTRANSFER => true, |
|
38 | + CURLOPT_SSL_VERIFYPEER => true |
|
39 | + ); |
|
40 | + curl_setopt_array($handle, $options); |
|
41 | 41 | |
42 | - $response = curl_exec($handle); |
|
43 | - curl_close($handle); |
|
42 | + $response = curl_exec($handle); |
|
43 | + curl_close($handle); |
|
44 | 44 | |
45 | - return $response; |
|
46 | - } |
|
45 | + return $response; |
|
46 | + } |
|
47 | 47 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function __construct(Socket $socket = null) |
72 | 72 | { |
73 | - if (!is_null($socket)) { |
|
73 | + if ( ! is_null($socket)) { |
|
74 | 74 | $this->socket = $socket; |
75 | 75 | } else { |
76 | 76 | $this->socket = new Socket(); |
@@ -88,20 +88,20 @@ discard block |
||
88 | 88 | $errno = 0; |
89 | 89 | $errstr = ''; |
90 | 90 | |
91 | - if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
91 | + if ($this->socket->fsockopen('ssl://'.self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
92 | 92 | $content = $params->toQueryString(); |
93 | 93 | |
94 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
95 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
94 | + $request = "POST ".self::SITE_VERIFY_PATH." HTTP/1.1\r\n"; |
|
95 | + $request .= "Host: ".self::RECAPTCHA_HOST."\r\n"; |
|
96 | 96 | $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
97 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
97 | + $request .= "Content-length: ".strlen($content)."\r\n"; |
|
98 | 98 | $request .= "Connection: close\r\n\r\n"; |
99 | - $request .= $content . "\r\n\r\n"; |
|
99 | + $request .= $content."\r\n\r\n"; |
|
100 | 100 | |
101 | 101 | $this->socket->fwrite($request); |
102 | 102 | $response = ''; |
103 | 103 | |
104 | - while (!$this->socket->feof()) { |
|
104 | + while ( ! $this->socket->feof()) { |
|
105 | 105 | $response .= $this->socket->fgets(4096); |
106 | 106 | } |
107 | 107 |
@@ -36,85 +36,85 @@ |
||
36 | 36 | */ |
37 | 37 | class SocketPost implements RequestMethod |
38 | 38 | { |
39 | - /** |
|
40 | - * reCAPTCHA service host. |
|
41 | - * @const string |
|
42 | - */ |
|
43 | - const RECAPTCHA_HOST = 'www.google.com'; |
|
44 | - |
|
45 | - /** |
|
46 | - * @const string reCAPTCHA service path |
|
47 | - */ |
|
48 | - const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
49 | - |
|
50 | - /** |
|
51 | - * @const string Bad request error |
|
52 | - */ |
|
53 | - const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
54 | - |
|
55 | - /** |
|
56 | - * @const string Bad response error |
|
57 | - */ |
|
58 | - const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
59 | - |
|
60 | - /** |
|
61 | - * Socket to the reCAPTCHA service |
|
62 | - * @var Socket |
|
63 | - */ |
|
64 | - private $socket; |
|
65 | - |
|
66 | - /** |
|
67 | - * Constructor |
|
68 | - * |
|
69 | - * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
70 | - */ |
|
71 | - public function __construct(Socket $socket = null) |
|
72 | - { |
|
73 | - if (!is_null($socket)) { |
|
74 | - $this->socket = $socket; |
|
75 | - } else { |
|
76 | - $this->socket = new Socket(); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Submit the POST request with the specified parameters. |
|
82 | - * |
|
83 | - * @param RequestParameters $params Request parameters |
|
84 | - * @return string Body of the reCAPTCHA response |
|
85 | - */ |
|
86 | - public function submit(RequestParameters $params) |
|
87 | - { |
|
88 | - $errno = 0; |
|
89 | - $errstr = ''; |
|
90 | - |
|
91 | - if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
92 | - $content = $params->toQueryString(); |
|
93 | - |
|
94 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
95 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
96 | - $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
97 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
98 | - $request .= "Connection: close\r\n\r\n"; |
|
99 | - $request .= $content . "\r\n\r\n"; |
|
100 | - |
|
101 | - $this->socket->fwrite($request); |
|
102 | - $response = ''; |
|
103 | - |
|
104 | - while (!$this->socket->feof()) { |
|
105 | - $response .= $this->socket->fgets(4096); |
|
106 | - } |
|
107 | - |
|
108 | - $this->socket->fclose(); |
|
109 | - |
|
110 | - if (0 === strpos($response, 'HTTP/1.1 200 OK')) { |
|
111 | - $parts = preg_split("#\n\s*\n#Uis", $response); |
|
112 | - return $parts[1]; |
|
113 | - } |
|
114 | - |
|
115 | - return self::BAD_RESPONSE; |
|
116 | - } |
|
117 | - |
|
118 | - return self::BAD_REQUEST; |
|
119 | - } |
|
39 | + /** |
|
40 | + * reCAPTCHA service host. |
|
41 | + * @const string |
|
42 | + */ |
|
43 | + const RECAPTCHA_HOST = 'www.google.com'; |
|
44 | + |
|
45 | + /** |
|
46 | + * @const string reCAPTCHA service path |
|
47 | + */ |
|
48 | + const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
49 | + |
|
50 | + /** |
|
51 | + * @const string Bad request error |
|
52 | + */ |
|
53 | + const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
54 | + |
|
55 | + /** |
|
56 | + * @const string Bad response error |
|
57 | + */ |
|
58 | + const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
59 | + |
|
60 | + /** |
|
61 | + * Socket to the reCAPTCHA service |
|
62 | + * @var Socket |
|
63 | + */ |
|
64 | + private $socket; |
|
65 | + |
|
66 | + /** |
|
67 | + * Constructor |
|
68 | + * |
|
69 | + * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
70 | + */ |
|
71 | + public function __construct(Socket $socket = null) |
|
72 | + { |
|
73 | + if (!is_null($socket)) { |
|
74 | + $this->socket = $socket; |
|
75 | + } else { |
|
76 | + $this->socket = new Socket(); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Submit the POST request with the specified parameters. |
|
82 | + * |
|
83 | + * @param RequestParameters $params Request parameters |
|
84 | + * @return string Body of the reCAPTCHA response |
|
85 | + */ |
|
86 | + public function submit(RequestParameters $params) |
|
87 | + { |
|
88 | + $errno = 0; |
|
89 | + $errstr = ''; |
|
90 | + |
|
91 | + if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
92 | + $content = $params->toQueryString(); |
|
93 | + |
|
94 | + $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
95 | + $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
96 | + $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
97 | + $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
98 | + $request .= "Connection: close\r\n\r\n"; |
|
99 | + $request .= $content . "\r\n\r\n"; |
|
100 | + |
|
101 | + $this->socket->fwrite($request); |
|
102 | + $response = ''; |
|
103 | + |
|
104 | + while (!$this->socket->feof()) { |
|
105 | + $response .= $this->socket->fgets(4096); |
|
106 | + } |
|
107 | + |
|
108 | + $this->socket->fclose(); |
|
109 | + |
|
110 | + if (0 === strpos($response, 'HTTP/1.1 200 OK')) { |
|
111 | + $parts = preg_split("#\n\s*\n#Uis", $response); |
|
112 | + return $parts[1]; |
|
113 | + } |
|
114 | + |
|
115 | + return self::BAD_RESPONSE; |
|
116 | + } |
|
117 | + |
|
118 | + return self::BAD_REQUEST; |
|
119 | + } |
|
120 | 120 | } |
@@ -80,11 +80,11 @@ |
||
80 | 80 | { |
81 | 81 | $params = array('secret' => $this->secret, 'response' => $this->response); |
82 | 82 | |
83 | - if (!is_null($this->remoteIp)) { |
|
83 | + if ( ! is_null($this->remoteIp)) { |
|
84 | 84 | $params['remoteip'] = $this->remoteIp; |
85 | 85 | } |
86 | 86 | |
87 | - if (!is_null($this->version)) { |
|
87 | + if ( ! is_null($this->version)) { |
|
88 | 88 | $params['version'] = $this->version; |
89 | 89 | } |
90 | 90 |
@@ -31,73 +31,73 @@ |
||
31 | 31 | */ |
32 | 32 | class RequestParameters |
33 | 33 | { |
34 | - /** |
|
35 | - * Site secret. |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private $secret; |
|
34 | + /** |
|
35 | + * Site secret. |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private $secret; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Form response. |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - private $response; |
|
40 | + /** |
|
41 | + * Form response. |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + private $response; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Remote user's IP address. |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $remoteIp; |
|
46 | + /** |
|
47 | + * Remote user's IP address. |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $remoteIp; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Client version. |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - private $version; |
|
52 | + /** |
|
53 | + * Client version. |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + private $version; |
|
57 | 57 | |
58 | - /** |
|
59 | - * Initialise parameters. |
|
60 | - * |
|
61 | - * @param string $secret Site secret. |
|
62 | - * @param string $response Value from g-captcha-response form field. |
|
63 | - * @param string $remoteIp User's IP address. |
|
64 | - * @param string $version Version of this client library. |
|
65 | - */ |
|
66 | - public function __construct($secret, $response, $remoteIp = null, $version = null) |
|
67 | - { |
|
68 | - $this->secret = $secret; |
|
69 | - $this->response = $response; |
|
70 | - $this->remoteIp = $remoteIp; |
|
71 | - $this->version = $version; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Initialise parameters. |
|
60 | + * |
|
61 | + * @param string $secret Site secret. |
|
62 | + * @param string $response Value from g-captcha-response form field. |
|
63 | + * @param string $remoteIp User's IP address. |
|
64 | + * @param string $version Version of this client library. |
|
65 | + */ |
|
66 | + public function __construct($secret, $response, $remoteIp = null, $version = null) |
|
67 | + { |
|
68 | + $this->secret = $secret; |
|
69 | + $this->response = $response; |
|
70 | + $this->remoteIp = $remoteIp; |
|
71 | + $this->version = $version; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Array representation. |
|
76 | - * |
|
77 | - * @return array Array formatted parameters. |
|
78 | - */ |
|
79 | - public function toArray() |
|
80 | - { |
|
81 | - $params = array('secret' => $this->secret, 'response' => $this->response); |
|
74 | + /** |
|
75 | + * Array representation. |
|
76 | + * |
|
77 | + * @return array Array formatted parameters. |
|
78 | + */ |
|
79 | + public function toArray() |
|
80 | + { |
|
81 | + $params = array('secret' => $this->secret, 'response' => $this->response); |
|
82 | 82 | |
83 | - if (!is_null($this->remoteIp)) { |
|
84 | - $params['remoteip'] = $this->remoteIp; |
|
85 | - } |
|
83 | + if (!is_null($this->remoteIp)) { |
|
84 | + $params['remoteip'] = $this->remoteIp; |
|
85 | + } |
|
86 | 86 | |
87 | - if (!is_null($this->version)) { |
|
88 | - $params['version'] = $this->version; |
|
89 | - } |
|
87 | + if (!is_null($this->version)) { |
|
88 | + $params['version'] = $this->version; |
|
89 | + } |
|
90 | 90 | |
91 | - return $params; |
|
92 | - } |
|
91 | + return $params; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Query string representation for HTTP request. |
|
96 | - * |
|
97 | - * @return string Query string formatted parameters. |
|
98 | - */ |
|
99 | - public function toQueryString() |
|
100 | - { |
|
101 | - return http_build_query($this->toArray(), '', '&'); |
|
102 | - } |
|
94 | + /** |
|
95 | + * Query string representation for HTTP request. |
|
96 | + * |
|
97 | + * @return string Query string formatted parameters. |
|
98 | + */ |
|
99 | + public function toQueryString() |
|
100 | + { |
|
101 | + return http_build_query($this->toArray(), '', '&'); |
|
102 | + } |
|
103 | 103 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | { |
54 | 54 | $responseData = json_decode($json, true); |
55 | 55 | |
56 | - if (!$responseData) { |
|
56 | + if ( ! $responseData) { |
|
57 | 57 | return new Response(false, array('invalid-json')); |
58 | 58 | } |
59 | 59 |
@@ -31,72 +31,72 @@ |
||
31 | 31 | */ |
32 | 32 | class Response |
33 | 33 | { |
34 | - /** |
|
35 | - * Succes or failure. |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - private $success = false; |
|
34 | + /** |
|
35 | + * Succes or failure. |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + private $success = false; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Error code strings. |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $errorCodes = array(); |
|
40 | + /** |
|
41 | + * Error code strings. |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $errorCodes = array(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Build the response from the expected JSON returned by the service. |
|
48 | - * |
|
49 | - * @param string $json |
|
50 | - * @return \ReCaptcha\Response |
|
51 | - */ |
|
52 | - public static function fromJson($json) |
|
53 | - { |
|
54 | - $responseData = json_decode($json, true); |
|
46 | + /** |
|
47 | + * Build the response from the expected JSON returned by the service. |
|
48 | + * |
|
49 | + * @param string $json |
|
50 | + * @return \ReCaptcha\Response |
|
51 | + */ |
|
52 | + public static function fromJson($json) |
|
53 | + { |
|
54 | + $responseData = json_decode($json, true); |
|
55 | 55 | |
56 | - if (!$responseData) { |
|
57 | - return new Response(false, array('invalid-json')); |
|
58 | - } |
|
56 | + if (!$responseData) { |
|
57 | + return new Response(false, array('invalid-json')); |
|
58 | + } |
|
59 | 59 | |
60 | - if (isset($responseData['success']) && $responseData['success'] == true) { |
|
61 | - return new Response(true); |
|
62 | - } |
|
60 | + if (isset($responseData['success']) && $responseData['success'] == true) { |
|
61 | + return new Response(true); |
|
62 | + } |
|
63 | 63 | |
64 | - if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
|
65 | - return new Response(false, $responseData['error-codes']); |
|
66 | - } |
|
64 | + if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
|
65 | + return new Response(false, $responseData['error-codes']); |
|
66 | + } |
|
67 | 67 | |
68 | - return new Response(false); |
|
69 | - } |
|
68 | + return new Response(false); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Constructor. |
|
73 | - * |
|
74 | - * @param boolean $success |
|
75 | - * @param array $errorCodes |
|
76 | - */ |
|
77 | - public function __construct($success, array $errorCodes = array()) |
|
78 | - { |
|
79 | - $this->success = $success; |
|
80 | - $this->errorCodes = $errorCodes; |
|
81 | - } |
|
71 | + /** |
|
72 | + * Constructor. |
|
73 | + * |
|
74 | + * @param boolean $success |
|
75 | + * @param array $errorCodes |
|
76 | + */ |
|
77 | + public function __construct($success, array $errorCodes = array()) |
|
78 | + { |
|
79 | + $this->success = $success; |
|
80 | + $this->errorCodes = $errorCodes; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Is success? |
|
85 | - * |
|
86 | - * @return boolean |
|
87 | - */ |
|
88 | - public function isSuccess() |
|
89 | - { |
|
90 | - return $this->success; |
|
91 | - } |
|
83 | + /** |
|
84 | + * Is success? |
|
85 | + * |
|
86 | + * @return boolean |
|
87 | + */ |
|
88 | + public function isSuccess() |
|
89 | + { |
|
90 | + return $this->success; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get error codes. |
|
95 | - * |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public function getErrorCodes() |
|
99 | - { |
|
100 | - return $this->errorCodes; |
|
101 | - } |
|
93 | + /** |
|
94 | + * Get error codes. |
|
95 | + * |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public function getErrorCodes() |
|
99 | + { |
|
100 | + return $this->errorCodes; |
|
101 | + } |
|
102 | 102 | } |