| @@ -1,109 +1,107 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | - exit; | |
| 5 | -} | |
| 6 | - | |
| 7 | -class TCMP_Check { | |
| 8 | - var $data; | |
| 9 | - | |
| 10 | - public function __construct() { | |
| 11 | - $this->data = array_merge( $_POST, $_GET ); | |
| 12 | - } | |
| 13 | - | |
| 14 | - public function is( $name, $value, $ignoreCase = true ) { | |
| 15 | - $result = false; | |
| 16 | - if ( isset( $this->data[ $name ] ) ) { | |
| 17 | - if ( $ignoreCase ) { | |
| 18 | - $result = ( strtolower( $this->data[ $name ] ) == strtolower( $value ) ); | |
| 19 | - } else { | |
| 20 | - $result = ( $this->data[ $name ] == $value ); | |
| 21 | - } | |
| 22 | - } | |
| 23 | - return $result; | |
| 24 | - } | |
| 25 | - public function of( $name, $default = '' ) { | |
| 26 | - $result = $default; | |
| 27 | - if ( isset( $this->data[ $name ] ) ) { | |
| 28 | - $result = $this->data[ $name ]; | |
| 29 | - } | |
| 30 | - return $result; | |
| 31 | - } | |
| 32 | - public function nonce( $action, $nonce = '_wpnonce' ) { | |
| 33 | - if ( isset( $_REQUEST[ $nonce ] ) ) { | |
| 34 | - $nonce = sanitize_text_field( wp_unslash( $_REQUEST[ $nonce ] ) ); | |
| 35 | - } | |
| 36 | - return wp_verify_nonce( $nonce, $action ); | |
| 37 | - } | |
| 38 | - | |
| 39 | - //check if is a mandatory field by checking the .txt language file | |
| 40 | - private function error( $name ) { | |
| 41 | - global $tcmp; | |
| 42 | - | |
| 43 | - $result = false; | |
| 44 | - $k = $tcmp->form->prefix . '.' . $name . '.check'; | |
| 45 | - $v = $tcmp->lang->L( $k ); | |
| 46 | - if ( $v != $k ) { | |
| 47 | - //this is a mandatory field so we give error | |
| 48 | - $tcmp->options->pushErrorMessage( $v ); | |
| 49 | - $result = true; | |
| 50 | - } | |
| 51 | - return $result; | |
| 52 | - } | |
| 53 | - | |
| 54 | - public function value( $name ) { | |
| 55 | - $result = ''; | |
| 56 | - if ( isset( $this->data[ $name ] ) ) { | |
| 57 | - $result = sanitize_text_field( $this->data[ $name ] ); | |
| 58 | - } | |
| 59 | - if ( '' == $result ) { | |
| 60 | - $this->error( $name ); | |
| 61 | - } | |
| 62 | - $this->data[ $name ] = $result; | |
| 63 | - return $result; | |
| 64 | - } | |
| 65 | - public function values( $name ) { | |
| 66 | - $result = array(); | |
| 67 | - if ( is_string( $name ) ) { | |
| 68 | - $name = explode( ',', $name ); | |
| 69 | - } | |
| 70 | - foreach ( $name as $v ) { | |
| 71 | - $result[] = $this->value( trim( $v ) ); | |
| 72 | - } | |
| 73 | - return $result; | |
| 74 | - } | |
| 75 | - public function email( $name ) { | |
| 76 | - $result = $this->value( $name ); | |
| 77 | - if ( '' != $result ) { | |
| 78 | - $result = sanitize_email( $result ); | |
| 79 | - if ( ! is_email( $result ) ) { | |
| 80 | - $this->error( $name ); | |
| 81 | - } | |
| 82 | - } | |
| 83 | - $this->data[ $name ] = $result; | |
| 84 | - return $result; | |
| 85 | - } | |
| 86 | - public function float( $name ) { | |
| 87 | - $result = $this->value( $name ); | |
| 88 | - if ( '' != $result && ! is_float( $result ) ) { | |
| 89 | - $this->error( $name ); | |
| 90 | - } | |
| 91 | - $result = floatval( $result ); | |
| 92 | - $this->data[ $name ] = $result; | |
| 93 | - return $result; | |
| 94 | - } | |
| 95 | - public function integer( $name ) { | |
| 96 | - $result = $this->value( $name ); | |
| 97 | - if ( '' != $result && ! is_int( $result ) ) { | |
| 98 | - $this->error( $name ); | |
| 99 | - } | |
| 100 | - $result = intval( $result ); | |
| 101 | - $this->data[ $name ] = $result; | |
| 102 | - return $result; | |
| 103 | - } | |
| 104 | - | |
| 105 | - public function hasErrors() { | |
| 106 | - global $tcmp; | |
| 107 | - return $tcmp->options->hasErrorMessages(); | |
| 108 | - } | |
| 109 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) exit; | |
| 4 | + | |
| 5 | +class TCMP_Check { | |
| 6 | + var $data; | |
| 7 | + | |
| 8 | + public function __construct() { | |
| 9 | + $this->data=array_merge($_POST, $_GET); | |
| 10 | + } | |
| 11 | + | |
| 12 | + public function is($name, $value, $ignoreCase=TRUE) { | |
| 13 | + $result=FALSE; | |
| 14 | + if(isset($this->data[$name])) { | |
| 15 | + if($ignoreCase) { | |
| 16 | + $result=(strtolower($this->data[$name])==strtolower($value)); | |
| 17 | + } else { | |
| 18 | + $result=($this->data[$name]==$value); | |
| 19 | + } | |
| 20 | + } | |
| 21 | + return $result; | |
| 22 | + } | |
| 23 | + public function of($name, $default='') { | |
| 24 | + $result=$default; | |
| 25 | + if(isset($this->data[$name])) { | |
| 26 | + $result=$this->data[$name]; | |
| 27 | + } | |
| 28 | + return $result; | |
| 29 | + } | |
| 30 | + public function nonce($action, $nonce='_wpnonce') { | |
| 31 | + if(isset($_REQUEST[$nonce])) { | |
| 32 | + $nonce=$_REQUEST[$nonce]; | |
| 33 | + } | |
| 34 | + return wp_verify_nonce($nonce, $action); | |
| 35 | + } | |
| 36 | + | |
| 37 | + //check if is a mandatory field by checking the .txt language file | |
| 38 | + private function error($name) { | |
| 39 | + global $tcmp; | |
| 40 | + | |
| 41 | + $result=FALSE; | |
| 42 | + $k=$tcmp->Form->prefix.'.'.$name.'.check'; | |
| 43 | + $v=$tcmp->Lang->L($k); | |
| 44 | + if($v!=$k) { | |
| 45 | + //this is a mandatory field so we give error | |
| 46 | + $tcmp->Options->pushErrorMessage($v); | |
| 47 | + $result=TRUE; | |
| 48 | + } | |
| 49 | + return $result; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public function value($name) { | |
| 53 | + $result=''; | |
| 54 | + if(isset($this->data[$name])) { | |
| 55 | + $result=sanitize_text_field($this->data[$name]); | |
| 56 | + } | |
| 57 | + if($result=='') { | |
| 58 | + $this->error($name); | |
| 59 | + } | |
| 60 | + $this->data[$name]=$result; | |
| 61 | + return $result; | |
| 62 | + } | |
| 63 | + public function values($name) { | |
| 64 | + $result=array(); | |
| 65 | + if(is_string($name)) { | |
| 66 | + $name=explode(',', $name); | |
| 67 | + } | |
| 68 | + foreach($name as $v) { | |
| 69 | + $result[]=$this->value(trim($v)); | |
| 70 | + } | |
| 71 | + return $result; | |
| 72 | + } | |
| 73 | + public function email($name) { | |
| 74 | + $result=$this->value($name); | |
| 75 | + if($result!='') { | |
| 76 | + $result=sanitize_email($result); | |
| 77 | + if(!is_email($result)) { | |
| 78 | + $this->error($name); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + $this->data[$name]=$result; | |
| 82 | + return $result; | |
| 83 | + } | |
| 84 | + public function float($name) { | |
| 85 | + $result=$this->value($name); | |
| 86 | + if($result!='' && !is_float($result)) { | |
| 87 | + $this->error($name); | |
| 88 | + } | |
| 89 | + $result=floatval($result); | |
| 90 | + $this->data[$name]=$result; | |
| 91 | + return $result; | |
| 92 | + } | |
| 93 | + public function integer($name) { | |
| 94 | + $result=$this->value($name); | |
| 95 | + if($result!='' && !is_int($result)) { | |
| 96 | + $this->error($name); | |
| 97 | + } | |
| 98 | + $result=intval($result); | |
| 99 | + $this->data[$name]=$result; | |
| 100 | + return $result; | |
| 101 | + } | |
| 102 | + | |
| 103 | + public function hasErrors() { | |
| 104 | + global $tcmp; | |
| 105 | + return $tcmp->Options->hasErrorMessages(); | |
| 106 | + } | |
| 107 | +} | |