PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 1.4
Tracking Code Manager v1.4
trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0
tracking-code-manager / includes / class-TCM-check.php
tracking-code-manager / includes Last commit date
admin 11 years ago actions.php 11 years ago class-TCM-check.php 11 years ago class-TCM-cron.php 11 years ago class-TCM-form.php 11 years ago class-TCM-language.php 11 years ago class-TCM-logger.php 11 years ago class-TCM-manager.php 11 years ago class-TCM-options.php 11 years ago class-TCM-tracking.php 11 years ago class-TCM-utils.php 11 years ago core.php 11 years ago install.php 11 years ago uninstall.php 11 years ago
class-TCM-check.php
112 lines
1 <?php
2 /**
3 * Created by PhpStorm.
4 * User: alessio
5 * Date: 28/03/2015
6 * Time: 10:20
7 */
8 if ( ! defined( 'ABSPATH' ) ) exit;
9
10 class TCM_Check {
11 var $data;
12
13 public function __construct() {
14 $this->data=array_merge($_POST, $_GET);
15 }
16
17 public function is($name, $value, $ignoreCase=TRUE) {
18 $result=FALSE;
19 if(isset($this->data[$name])) {
20 if($ignoreCase) {
21 $result=(strtolower($this->data[$name])==strtolower($value));
22 } else {
23 $result=($this->data[$name]==$value);
24 }
25 }
26 return $result;
27 }
28 public function of($name, $default='') {
29 $result=$default;
30 if(isset($this->data[$name])) {
31 $result=$this->data[$name];
32 }
33 return $result;
34 }
35 public function nonce($action, $nonce='_wpnonce') {
36 if(isset($_REQUEST[$nonce])) {
37 $nonce=$_REQUEST[$nonce];
38 }
39 return wp_verify_nonce($nonce, $action);
40 }
41
42 //check if is a mandatory field by checking the .txt language file
43 private function error($name) {
44 global $tcm;
45
46 $result=FALSE;
47 $k=$tcm->Form->prefix.'.'.$name.'.check';
48 $v=$tcm->Lang->L($k);
49 if($v!=$k) {
50 //this is a mandatory field so we give error
51 $tcm->Options->pushErrorMessage($v);
52 $result=TRUE;
53 }
54 return $result;
55 }
56
57 public function value($name) {
58 $result='';
59 if(isset($this->data[$name])) {
60 $result=sanitize_text_field($this->data[$name]);
61 }
62 if($result=='') {
63 $this->error($name);
64 }
65 $this->data[$name]=$result;
66 return $result;
67 }
68 public function values($name) {
69 $result=array();
70 if(is_string($name)) {
71 $name=explode(',', $name);
72 }
73 foreach($name as $v) {
74 $result[]=$this->value(trim($v));
75 }
76 return $result;
77 }
78 public function email($name) {
79 $result=$this->value($name);
80 if($result!='') {
81 $result=sanitize_email($result);
82 if(!is_email($result)) {
83 $this->error($name);
84 }
85 }
86 $this->data[$name]=$result;
87 return $result;
88 }
89 public function float($name) {
90 $result=$this->value($name);
91 if($result!='' && !is_float($result)) {
92 $this->error($name);
93 }
94 $result=floatval($result);
95 $this->data[$name]=$result;
96 return $result;
97 }
98 public function integer($name) {
99 $result=$this->value($name);
100 if($result!='' && !is_int($result)) {
101 $this->error($name);
102 }
103 $result=intval($result);
104 $this->data[$name]=$result;
105 return $result;
106 }
107
108 public function hasErrors() {
109 global $tcm;
110 return $tcm->Options->hasErrorMessages();
111 }
112 }