<?php
/**
 * Spam protection using HonyPot method.
 *
 * @package TutorPro\Auth
 * @author Themeum <support@themeum.com>
 * @link https://themeum.com
 * @since 2.1.9
 */

namespace TutorPro\Auth;

use TUTOR\Input;

/**
 * HoneyPot Class.
 *
 * @since 2.1.9
 */
class HoneyPot {

	/**
	 * Add form input for check spam request.
	 *
	 * @since 2.1.9
	 *
	 * @return void
	 */
	public static function form_content( $field_name ) {
		?>
		<input type="text"
		       name="<?php echo esc_attr( $field_name ); ?>"
		       value=""
		       tabindex="-1"
		       aria-hidden="true"
		       autocomplete="off"
		       autocorrect="off"
		       autocapitalize="off"
		       spellcheck="false"
		       style="position:absolute!important; left:-99999px!important; top:auto!important; width:1px!important; height:1px!important; opacity:0!important; pointer-events:none!important;"
		>
		<?php
	}

	/**
	 * Verify request using HonyPot technique.
	 *
	 * @since 2.1.9
	 *
	 * @return void
	 */
	public static function verify( $field_name ) {
		$value = '';
		if ( Input::has( $field_name ) ) {
			$value = (string) Input::post( $field_name );
			$value = trim( $value );
		}

		if ( '' !== $value ) {
			return new \WP_Error( 'tutor_sp_error', __( 'Spam request catched!', 'tutor-pro' ) );
		}
	}
}
