Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Announcements.php
4 years ago
Assets.php
3 years ago
Backend_Page_Trait.php
4 years ago
Course.php
3 years ago
Course_Filter.php
4 years ago
Course_List.php
3 years ago
Course_Settings_Tabs.php
4 years ago
Course_Widget.php
4 years ago
Custom_Validation.php
4 years ago
Dashboard.php
3 years ago
FormHandler.php
4 years ago
Frontend.php
3 years ago
Gutenberg.php
4 years ago
Input.php
3 years ago
Instructor.php
4 years ago
Instructors_List.php
3 years ago
Lesson.php
4 years ago
Options_V2.php
3 years ago
Post_types.php
4 years ago
Private_Course_Access.php
4 years ago
Q_and_A.php
4 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Reviews.php
4 years ago
Rewrite_Rules.php
4 years ago
Shortcode.php
4 years ago
Student.php
4 years ago
Students_List.php
4 years ago
Taxonomies.php
4 years ago
Template.php
3 years ago
Theme_Compatibility.php
5 years ago
Tools.php
3 years ago
Tools_V2.php
4 years ago
Tutor.php
3 years ago
TutorEDD.php
4 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
4 years ago
User.php
4 years ago
Utils.php
3 years ago
Video_Stream.php
4 years ago
Withdraw.php
3 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
3 years ago
Input.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Input class |
| 4 | * |
| 5 | * @author: themeum |
| 6 | * @author_uri: https://themeum.com |
| 7 | * @package Tutor |
| 8 | * @since 2.0.2 |
| 9 | */ |
| 10 | |
| 11 | namespace TUTOR; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | /** |
| 17 | * Input class for handling GET and POST request |
| 18 | * |
| 19 | * @since 2.0.2 |
| 20 | */ |
| 21 | class Input { |
| 22 | |
| 23 | const TYPE_RAW = 'raw'; |
| 24 | const TYPE_STRING = 'string'; |
| 25 | const TYPE_INT = 'int'; |
| 26 | const TYPE_NUMERIC = 'numeric'; |
| 27 | const TYPE_TEXTAREA = 'textarea'; |
| 28 | |
| 29 | /** |
| 30 | * Common data sanitize method |
| 31 | * |
| 32 | * @param string $value input value. |
| 33 | * @param string $default default value if input key is not exit. |
| 34 | * @param string $type Default is Input::TYPE_STRING. |
| 35 | * @param boolean $trim remove blank splace from start and end. |
| 36 | * @return mixed |
| 37 | */ |
| 38 | private static function sanitize( $value, $default = null, $type = self::TYPE_STRING, $trim = true ) { |
| 39 | if ( $value === $default ) { |
| 40 | return $default; |
| 41 | } |
| 42 | |
| 43 | if ( $trim ) { |
| 44 | $value = trim( $value ); |
| 45 | } |
| 46 | |
| 47 | if ( self::TYPE_RAW === $type ) { |
| 48 | return $value; |
| 49 | } |
| 50 | if ( self::TYPE_INT === $type ) { |
| 51 | return (int) sanitize_text_field( wp_unslash( $value ) ); |
| 52 | } |
| 53 | if ( self::TYPE_NUMERIC === $type ) { |
| 54 | $val = sanitize_text_field( wp_unslash( $value ) ); |
| 55 | return is_numeric( $val ) ? $val + 0 : 0; |
| 56 | } |
| 57 | if ( self::TYPE_TEXTAREA === $type ) { |
| 58 | return sanitize_textarea_field( wp_unslash( $value ) ); |
| 59 | } |
| 60 | |
| 61 | return sanitize_text_field( wp_unslash( $value ) ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get input value from GET request |
| 66 | * |
| 67 | * @param string $key $_GET request key. |
| 68 | * @param mixed $default default value if input key is not exit. |
| 69 | * @param string $type input type. Default is Input::TYPE_STRING. |
| 70 | * @param boolean $trim remove blank splace from start and end. |
| 71 | * @return mixed |
| 72 | */ |
| 73 | public static function get( $key, $default = null, $type = self::TYPE_STRING, $trim = true ) { |
| 74 | //phpcs:ignore |
| 75 | $value = isset( $_GET[ $key ] ) ? $_GET[ $key ] : $default; |
| 76 | return self::sanitize( $value, $default, $type, $trim ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get input value from POST request |
| 81 | * |
| 82 | * @param string $key $_POST request key. |
| 83 | * @param mixed $default default value if input key is not exit. |
| 84 | * @param string $type input type. Default is Input::TYPE_STRING. |
| 85 | * @param boolean $trim remove blank splace from start and end. |
| 86 | * @return mixed |
| 87 | */ |
| 88 | public static function post( $key, $default = null, $type = self::TYPE_STRING, $trim = true ) { |
| 89 | //phpcs:ignore |
| 90 | $value = isset( $_POST[ $key ] ) ? $_POST[ $key ] : $default; |
| 91 | return self::sanitize( $value, $default, $type, $trim ); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Check input has key or not |
| 96 | * |
| 97 | * @param string $key input key name. |
| 98 | * @return boolean |
| 99 | */ |
| 100 | public static function has( $key ) { |
| 101 | //phpcs:ignore |
| 102 | return isset( $_REQUEST[ $key ] ); |
| 103 | } |
| 104 | } |
| 105 |