PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / hc3 / post.php

post.php in ShiftController Employee Shift Scheduling 4.9.26, at hc3/post.php

103 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 class HC3_Post
3 {
4 protected $_postPrefix = 'hc-';
5
6 public function __construct()
7 {
8 $this->_sanitize();
9 }
10
11 public function get( $k = NULL )
12 {
13 if( ! empty($_POST) ){
14 $nonce = isset( $_REQUEST['hc_nonce'] ) ? $_REQUEST['hc_nonce'] : '';
15 if( ! wp_verify_nonce( $nonce, 'shiftcontroller' ) ){
16 die( 'Security check failed' );
17 }
18 }
19
20 $return = array();
21
22 if( ! empty($_POST) ){
23 foreach( array_keys($_POST) as $key ){
24 if( substr($key, 0, strlen($this->_postPrefix)) != $this->_postPrefix ){
25 continue;
26 }
27 $my_key = substr($key, strlen($this->_postPrefix));
28 $return[$my_key] = $this->_fetch_from_array($_POST, $key);
29 }
30 }
31
32 if( NULL !== $k ){
33 $return = array_key_exists($k, $return) ? $return[$k] : NULL;
34 }
35
36 return $return;
37 }
38
39 protected function _fetch_from_array($array, $index = '')
40 {
41 if ( ! isset($array[$index])){
42 return FALSE;
43 }
44 return $array[$index];
45 }
46
47 protected function _sanitize()
48 {
49 if (is_array($_POST) AND count($_POST) > 0){
50 foreach ($_POST as $key => $val){
51 if( substr($key, 0, strlen($this->_postPrefix)) !== $this->_postPrefix ){
52 continue;
53 }
54 $_POST[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
55 }
56 }
57 }
58
59 protected function _cleanInputKeys( $str )
60 {
61 if ( ! preg_match("/^[a-z0-9:_\/\-\~]+$/i", $str)){
62 exit('Disallowed Key Characters on: ' . '"' . $str . '"' . '<br>');
63 }
64 return $str;
65 }
66
67 protected function _cleanInputData( $str )
68 {
69 if( is_array($str) ){
70 $new_array = array();
71 foreach ($str as $key => $val){
72 $new_array[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
73 }
74 return $new_array;
75 }
76
77 /* We strip slashes if magic quotes is on to keep things consistent
78 NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
79 it will probably not exist in future versions at all.
80 */
81 $need_strip = FALSE;
82 if( version_compare(PHP_VERSION, '5.4', '<') && get_magic_quotes_gpc() ){
83 $need_strip = TRUE;
84 }
85 elseif( defined('WPINC') ){
86 $need_strip = TRUE;
87 }
88
89 if( $need_strip ){
90 $str = stripslashes($str);
91 }
92
93 // Remove control characters
94 $str = HC3_Functions::removeInvisibleCharacters($str);
95
96 // Standardize newlines
97 if (strpos($str, "\r") !== FALSE){
98 $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
99 }
100
101 return $str;
102 }
103 }