diff --git a/.gitignore b/.gitignore index 0b9fec5..0d75da9 100644 --- a/.gitignore +++ b/.gitignore @@ -233,3 +233,6 @@ pip-log.txt #Composer composer.json + + +vendor/* diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..14623b4 --- /dev/null +++ b/composer.lock @@ -0,0 +1,153 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "81ff4fd6aed1d08f491e16f206291a67", + "packages": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "3.3.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2018-09-23T23:08:17+00:00" + }, + { + "name": "stevegrunwell/wp-enforcer", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/stevegrunwell/wp-enforcer.git", + "reference": "6d583588d06346982b5819066f14675ddc8004d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stevegrunwell/wp-enforcer/zipball/6d583588d06346982b5819066f14675ddc8004d7", + "reference": "6d583588d06346982b5819066f14675ddc8004d7", + "shasum": "" + }, + "require": { + "wp-coding-standards/wpcs": "*" + }, + "bin": [ + "bin/wp-enforcer" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Steve Grunwell", + "email": "steve@stevegrunwell.com", + "homepage": "https://stevegrunwell.com" + } + ], + "description": "Git hooks to encourage well-written WordPress.", + "keywords": [ + "PHP_CodeSniffer", + "coding standards", + "git hooks", + "wordpress" + ], + "time": "2017-05-28T18:44:13+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", + "reference": "7aa217ab38156c5cb4eae0f04ae376027c407a9b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/7aa217ab38156c5cb4eae0f04ae376027c407a9b", + "reference": "7aa217ab38156c5cb4eae0f04ae376027c407a9b", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + }, + "require-dev": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2018-11-12T10:13:12+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/includes/ReCaptcha/ReCaptcha.php b/includes/ReCaptcha/ReCaptcha.php index c157dc9..1ca431d 100755 --- a/includes/ReCaptcha/ReCaptcha.php +++ b/includes/ReCaptcha/ReCaptcha.php @@ -29,70 +29,71 @@ /** * reCAPTCHA client. */ -class ReCaptcha -{ - /** - * Version of this client library. - * @const string - */ - const VERSION = 'php_1.1.2'; +class ReCaptcha { - /** - * Shared secret for the site. - * @var string - */ - private $secret; + /** + * Version of this client library. + * + * @const string + */ + const VERSION = 'php_1.1.2'; - /** - * Method used to communicate with service. Defaults to POST request. - * @var RequestMethod - */ - private $requestMethod; + /** + * Shared secret for the site. + * + * @var string + */ + private $secret; - /** - * Create a configured instance to use the reCAPTCHA service. - * - * @param string $secret shared secret between site and reCAPTCHA server. - * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. - * @throws \RuntimeException if $secret is invalid - */ - public function __construct($secret, RequestMethod $requestMethod = null) - { - if (empty($secret)) { - throw new \RuntimeException('No secret provided'); - } + /** + * Method used to communicate with service. Defaults to POST request. + * + * @var RequestMethod + */ + private $requestMethod; - if (!is_string($secret)) { - throw new \RuntimeException('The provided secret must be a string'); - } + /** + * Create a configured instance to use the reCAPTCHA service. + * + * @param string $secret shared secret between site and reCAPTCHA server. + * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. + * @throws \RuntimeException if $secret is invalid + */ + public function __construct( $secret, RequestMethod $requestMethod = null ) { + if ( empty( $secret ) ) { + throw new \RuntimeException( 'No secret provided' ); + } - $this->secret = $secret; + if ( ! is_string( $secret ) ) { + throw new \RuntimeException( 'The provided secret must be a string' ); + } - if (!is_null($requestMethod)) { - $this->requestMethod = $requestMethod; - } else { - $this->requestMethod = new RequestMethod\Post(); - } - } + $this->secret = $secret; - /** - * Calls the reCAPTCHA siteverify API to verify whether the user passes - * CAPTCHA test. - * - * @param string $response The value of 'g-recaptcha-response' in the submitted form. - * @param string $remoteIp The end user's IP address. - * @return Response Response from the service. - */ - public function verify($response, $remoteIp = null) - { - // Discard empty solution submissions - if (empty($response)) { - $recaptchaResponse = new Response(false, array('missing-input-response')); - return $recaptchaResponse; - } + if ( ! is_null( $requestMethod ) ) { + $this->requestMethod = $requestMethod; + } else { + $this->requestMethod = new RequestMethod\Post(); + } + } - $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); - $rawResponse = $this->requestMethod->submit($params); - return Response::fromJson($rawResponse); - } + /** + * Calls the reCAPTCHA siteverify API to verify whether the user passes + * CAPTCHA test. + * + * @param string $response The value of 'g-recaptcha-response' in the submitted form. + * @param string $remoteIp The end user's IP address. + * @return Response Response from the service. + */ + public function verify( $response, $remoteIp = null ) { + // Discard empty solution submissions + if ( empty( $response ) ) { + $recaptchaResponse = new Response( false, array( 'missing-input-response' ) ); + return $recaptchaResponse; + } + + $params = new RequestParameters( $this->secret, $response, $remoteIp, self::VERSION ); + $rawResponse = $this->requestMethod->submit( $params ); + return Response::fromJson( $rawResponse ); + } } diff --git a/includes/ReCaptcha/RequestMethod.php b/includes/ReCaptcha/RequestMethod.php index fc4dde5..78fa249 100755 --- a/includes/ReCaptcha/RequestMethod.php +++ b/includes/ReCaptcha/RequestMethod.php @@ -29,14 +29,14 @@ /** * Method used to send the request to the service. */ -interface RequestMethod -{ +interface RequestMethod { - /** - * Submit the request with the specified parameters. - * - * @param RequestParameters $params Request parameters - * @return string Body of the reCAPTCHA response - */ - public function submit(RequestParameters $params); + + /** + * Submit the request with the specified parameters. + * + * @param RequestParameters $params Request parameters + * @return string Body of the reCAPTCHA response + */ + public function submit( RequestParameters $params); } diff --git a/includes/ReCaptcha/RequestParameters.php b/includes/ReCaptcha/RequestParameters.php index cb66f26..9d47b58 100755 --- a/includes/ReCaptcha/RequestParameters.php +++ b/includes/ReCaptcha/RequestParameters.php @@ -29,75 +29,79 @@ /** * Stores and formats the parameters for the request to the reCAPTCHA service. */ -class RequestParameters -{ - /** - * Site secret. - * @var string - */ - private $secret; +class RequestParameters { - /** - * Form response. - * @var string - */ - private $response; + /** + * Site secret. + * + * @var string + */ + private $secret; - /** - * Remote user's IP address. - * @var string - */ - private $remoteIp; + /** + * Form response. + * + * @var string + */ + private $response; - /** - * Client version. - * @var string - */ - private $version; + /** + * Remote user's IP address. + * + * @var string + */ + private $remoteIp; - /** - * Initialise parameters. - * - * @param string $secret Site secret. - * @param string $response Value from g-captcha-response form field. - * @param string $remoteIp User's IP address. - * @param string $version Version of this client library. - */ - public function __construct($secret, $response, $remoteIp = null, $version = null) - { - $this->secret = $secret; - $this->response = $response; - $this->remoteIp = $remoteIp; - $this->version = $version; - } + /** + * Client version. + * + * @var string + */ + private $version; - /** - * Array representation. - * - * @return array Array formatted parameters. - */ - public function toArray() - { - $params = array('secret' => $this->secret, 'response' => $this->response); + /** + * Initialise parameters. + * + * @param string $secret Site secret. + * @param string $response Value from g-captcha-response form field. + * @param string $remoteIp User's IP address. + * @param string $version Version of this client library. + */ + public function __construct( $secret, $response, $remoteIp = null, $version = null ) { + $this->secret = $secret; + $this->response = $response; + $this->remoteIp = $remoteIp; + $this->version = $version; + } - if (!is_null($this->remoteIp)) { - $params['remoteip'] = $this->remoteIp; - } + /** + * Array representation. + * + * @return array Array formatted parameters. + */ + public function toArray() { + $params = array( + 'secret' => $this->secret, + 'response' => $this->response, + ); - if (!is_null($this->version)) { - $params['version'] = $this->version; - } + if ( ! is_null( $this->remoteIp ) ) { + $params['remoteip'] = $this->remoteIp; + } - return $params; - } + if ( ! is_null( $this->version ) ) { + $params['version'] = $this->version; + } - /** - * Query string representation for HTTP request. - * - * @return string Query string formatted parameters. - */ - public function toQueryString() - { - return http_build_query($this->toArray(), '', '&'); - } + return $params; + } + + /** + * Query string representation for HTTP request. + * + * @return string Query string formatted parameters. + */ + public function toQueryString() { + return http_build_query( $this->toArray(), '', '&' ); + } } diff --git a/includes/ReCaptcha/Response.php b/includes/ReCaptcha/Response.php index 111df97..eb482bf 100755 --- a/includes/ReCaptcha/Response.php +++ b/includes/ReCaptcha/Response.php @@ -29,74 +29,72 @@ /** * The response returned from the service. */ -class Response -{ - /** - * Success or failure. - * @var boolean - */ - private $success = false; +class Response { - /** - * Error code strings. - * @var array - */ - private $errorCodes = array(); + /** + * Success or failure. + * + * @var boolean + */ + private $success = false; - /** - * Build the response from the expected JSON returned by the service. - * - * @param string $json - * @return \ReCaptcha\Response - */ - public static function fromJson($json) - { - $responseData = json_decode($json, true); + /** + * Error code strings. + * + * @var array + */ + private $errorCodes = array(); - if (!$responseData) { - return new Response(false, array('invalid-json')); - } + /** + * Build the response from the expected JSON returned by the service. + * + * @param string $json + * @return \ReCaptcha\Response + */ + public static function fromJson( $json ) { + $responseData = json_decode( $json, true ); - if (isset($responseData['success']) && $responseData['success'] == true) { - return new Response(true); - } + if ( ! $responseData ) { + return new Response( false, array( 'invalid-json' ) ); + } - if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { - return new Response(false, $responseData['error-codes']); - } + if ( isset( $responseData['success'] ) && $responseData['success'] == true ) { + return new Response( true ); + } - return new Response(false); - } + if ( isset( $responseData['error-codes'] ) && is_array( $responseData['error-codes'] ) ) { + return new Response( false, $responseData['error-codes'] ); + } - /** - * Constructor. - * - * @param boolean $success - * @param array $errorCodes - */ - public function __construct($success, array $errorCodes = array()) - { - $this->success = $success; - $this->errorCodes = $errorCodes; - } + return new Response( false ); + } - /** - * Is success? - * - * @return boolean - */ - public function isSuccess() - { - return $this->success; - } + /** + * Constructor. + * + * @param boolean $success + * @param array $errorCodes + */ + public function __construct( $success, array $errorCodes = array() ) { + $this->success = $success; + $this->errorCodes = $errorCodes; + } - /** - * Get error codes. - * - * @return array - */ - public function getErrorCodes() - { - return $this->errorCodes; - } + /** + * Is success? + * + * @return boolean + */ + public function isSuccess() { + return $this->success; + } + + /** + * Get error codes. + * + * @return array + */ + public function getErrorCodes() { + return $this->errorCodes; + } } diff --git a/includes/class-admin-notice.php b/includes/class-admin-notice.php index 0a13d8c..c71c1ac 100755 --- a/includes/class-admin-notice.php +++ b/includes/class-admin-notice.php @@ -38,7 +38,7 @@ class WP_Listings_Admin_Notice { * * @var string */ - protected static $nonce_field = ''; + protected static $nonce_field = ''; /** * The ignore key @@ -49,22 +49,22 @@ class WP_Listings_Admin_Notice { * * @var string */ - protected static $ignore_key = ''; + protected static $ignore_key = ''; /** * Output the message * * @since 1.3 * - * @param string $message The text of the message. - * @param bool $error Optional. Whether to show as error or update. Default is notice. - * @param string $cap_check Optional. Minimum user capability to show notice to. Default is "activate_plugins" + * @param string $message The text of the message. + * @param bool $error Optional. Whether to show as error or update. Default is notice. + * @param string $cap_check Optional. Minimum user capability to show notice to. Default is "activate_plugins" * @param string|bool $ignore_key Optional. The user meta key to use for storing if this message has been dismissed by current user or not. If false, it will be generated. * * @return string|void Admin notice if is_admin() and not dismissed. */ - public static function notice( $message, $error = false, $cap_check = 'activate_plugins', $ignore_key = false ) { - if ( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) { + public static function notice( $message, $error = false, $cap_check = 'activate_plugins', $ignore_key = false ) { + if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { if ( current_user_can( $cap_check ) ) { $user_id = get_current_user_id(); if ( ! is_string( $ignore_key ) ) { @@ -96,9 +96,7 @@ public static function notice( $message, $error = false, $cap_check = 'activate return implode( '', $out ); } - } - } } @@ -114,11 +112,15 @@ public static function js_css() { global $wp_version; wp_enqueue_style( 'wp-listings-admin-notice', plugin_dir_url( __FILE__ ) . '/includes/css/wp-listings-admin-notice.css' ); wp_enqueue_script( 'wp-listings-admin', plugin_dir_url( __FILE__ ) . '/includes/js/admin.js' ); - wp_localize_script( 'wp-listings-admin', 'wp_listings_adminL10n', array( - 'nonce' => wp_create_nonce( self::$nonce_action ), - 'wp_version' => $wp_version, - 'dismiss' => __( 'Dismiss this notice', 'wp-listings' ), - ) ); + wp_localize_script( + 'wp-listings-admin', + 'wp_listings_adminL10n', + array( + 'nonce' => wp_create_nonce( self::$nonce_action ), + 'wp_version' => $wp_version, + 'dismiss' => __( 'Dismiss this notice', 'wp-listings' ), + ) + ); } /** @@ -131,12 +133,12 @@ public static function js_css() { * @return bool */ public static function ajax_cb() { - if ( ! isset( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], self::$nonce_action ) ) { + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], self::$nonce_action ) ) { return false; } - $nag = sanitize_key( $_POST[ 'nag' ] ); - if ( $nag === $_POST[ 'nag' ] ) { + $nag = sanitize_key( $_POST['nag'] ); + if ( $nag === $_POST['nag'] ) { update_user_meta( get_current_user_id(), $nag, true ); } diff --git a/includes/class-featured-listings-widget.php b/includes/class-featured-listings-widget.php index f111076..c3c696b 100755 --- a/includes/class-featured-listings-widget.php +++ b/includes/class-featured-listings-widget.php @@ -8,8 +8,15 @@ class WP_Listings_Featured_Listings_Widget extends WP_Widget { function __construct() { - $widget_ops = array( 'classname' => 'wplistings-featured-listings clearfix', 'description' => __( 'Display grid-style featured listings', 'wp-listings' ), 'customize_selective_refresh' => true ); - $control_ops = array( 'width' => 300, 'height' => 350 ); + $widget_ops = array( + 'classname' => 'wplistings-featured-listings clearfix', + 'description' => __( 'Display grid-style featured listings', 'wp-listings' ), + 'customize_selective_refresh' => true, + ); + $control_ops = array( + 'width' => 300, + 'height' => 350, + ); parent::__construct( 'wplistings-featured-listings', __( 'IMPress Listings - Featured Listings', 'wp-listings' ), $widget_ops, $control_ops ); } @@ -19,15 +26,15 @@ function __construct() { * @param int $number_columns * @param int $number_items */ - function get_column_class($number_columns) { + function get_column_class( $number_columns ) { $column_class = ''; // Max of six columns - $number_columns = ( $number_columns > 6 ) ? 6 : (int)$number_columns; + $number_columns = ( $number_columns > 6 ) ? 6 : (int) $number_columns; // column class - switch ($number_columns) { + switch ( $number_columns ) { case 0: case 1: $column_class = ''; @@ -56,29 +63,29 @@ function widget( $args, $instance ) { extract( $args ); - $options = get_option('plugin_wp_listings_settings'); + $options = get_option( 'plugin_wp_listings_settings' ); - $column_class = $instance['use_columns'] ? $this->get_column_class($instance['number_columns']) : ''; + $column_class = $instance['use_columns'] ? $this->get_column_class( $instance['number_columns'] ) : ''; echo $before_widget; - if ( ! empty( $instance['title'] ) ) { - echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; - } + if ( ! empty( $instance['title'] ) ) { + echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; + } - if ( !empty( $instance['posts_term'] ) ) { - $posts_term = explode( ',', $instance['posts_term'] ); - } + if ( ! empty( $instance['posts_term'] ) ) { + $posts_term = explode( ',', $instance['posts_term'] ); + } $query_args = array( - 'post_type' => 'listing', - 'posts_per_page' => $instance['posts_per_page'], - 'paged' => get_query_var('paged') ? get_query_var('paged') : 1 + 'post_type' => 'listing', + 'posts_per_page' => $instance['posts_per_page'], + 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, ); - if ( !empty( $instance['posts_term'] ) && count($posts_term) == 2 ) { - $query_args[$posts_term['0']] = $posts_term['1']; - } + if ( ! empty( $instance['posts_term'] ) && count( $posts_term ) == 2 ) { + $query_args[ $posts_term['0'] ] = $posts_term['1']; + } $wp_listings_widget_query = new WP_Query( $query_args ); @@ -86,7 +93,9 @@ function widget( $args, $instance ) { global $post; - if ( $wp_listings_widget_query->have_posts() ) : while ( $wp_listings_widget_query->have_posts() ) : $wp_listings_widget_query->the_post(); + if ( $wp_listings_widget_query->have_posts() ) : + while ( $wp_listings_widget_query->have_posts() ) : + $wp_listings_widget_query->the_post(); $count = ( $count == $instance['number_columns'] ) ? 1 : $count + 1; @@ -95,7 +104,7 @@ function widget( $args, $instance ) { $loop = sprintf( '
' ); @@ -120,18 +129,19 @@ function widget( $args, $instance ) { $loop .= sprintf( '%s
', wp_listings_get_address() );
$loop .= sprintf( '%s, %s %s
%s
', __( 'How many results should be returned?', 'wp-listings' ), - $this->get_field_name('posts_per_page'), + $this->get_field_name( 'posts_per_page' ), esc_attr( $instance['posts_per_page'] ) ); - echo '+ echo '
-
'; ?>- id="get_field_id( 'use_columns' ); ?>" name="get_field_name( 'use_columns' ); ?>" value="1" /> + id="get_field_id( 'use_columns' ); ?>" name="get_field_name( 'use_columns' ); ?>" value="1" />
@@ -550,7 +565,7 @@ function wp_listings_idx_listing_setting_page() {
return;
}
- settings_errors('wp_listings_idx_listing_settings_group');
+ settings_errors( 'wp_listings_idx_listing_settings_group' );
?>
%s
@@ -602,30 +657,33 @@ function wp_listings_edit_term_image_field( $term ) {
';
\ No newline at end of file
+echo '
';
diff --git a/includes/views/listing-details-metabox.php b/includes/views/listing-details-metabox.php
index fa42c72..fc7efff 100755
--- a/includes/views/listing-details-metabox.php
+++ b/includes/views/listing-details-metabox.php
@@ -7,112 +7,116 @@
echo '
', 'wp-listings');
- printf( __( '
', 'wp-listings' );
+ printf( __( '
Yes No
Yes No
Recommend size: 660x300 (If possible, use 100% width, or your themes content width)
', 'wp-listings');
- printf( __( '
Recommend size: 660x300 (If possible, use 100% width, or your themes content width)
', 'wp-listings' );
+ printf( __( '
', 'wp-listings');
- printf( __( '
', 'wp-listings' );
+ printf( __( '