(int)$number) { die("Please make sure that you place the right number of arguments into the $method method"); } } /** * Validation_Sanitisation::sanitize() * * @param string $handle * @param array $form_output * @return array */ public function sanitize(&$form_output, $handle) { $this->method_args_validation(2, func_num_args(), 'sanitize'); switch ($handle) { case 'sanitize_post': array_walk_recursive($form_output, array($this, 'sanitize_post')); break; case 'trim_post': array_walk_recursive($form_output, array($this, 'trim_post')); break; case 'strip_tags_post': array_walk_recursive($form_output, array($this, 'strip_tags_post')); case 'stripslashes': array_walk_recursive($form_output, array($this, 'stripslashes')); break; case 'sanitize_file_name_new': array_walk_recursive($form_output, array($this, 'sanitize_file_name_new')); break; case 'wp_kses_new': array_walk_recursive($form_output, array($this, 'wp_kses_new')); break; default: die("The value you ented into the sanitize() method is not recognised: $handle"); break; } // end switch } /** * Validation_Sanitisation::wp_kses_new() * * @param string $att * @param string $single * @param array $form_output * @return array */ public function wp_kses_new(&$form_output, $att = NULL, $single = NULL) { if ($single == NULL) { if (is_array($form_output)) { array_walk_recursive($form_output, ' wp_kses_kses'); } else { $form_output = wp_filter_nohtml_kses($form_output); } } else { extract(static::$form); foreach ($form_output[$option_name] as $thisKey => $result) { if (!preg_match("/$att/i", $thisKey)) continue; if (is_string($thisKey)) { $form_output[$option_name][$thisKey] = wp_filter_nohtml_kses($result); } } return $form_output; } } /** * Validation_Sanitisation::trim_post() * * @param string $att * @param string $single * @param array $form_output * @return array */ public function trim_post(&$form_output, $att = NULL, $single = NULL) { if ($single == NULL) { if (is_array($form_output)) { array_walk_recursive($form_output, 'trim'); } else { $form_output = trim($form_output); } } else { extract(static::$form); foreach ($form_output[$option_name] as $thisKey => $result) { if (!preg_match("/$att/i", $thisKey)) continue; if (is_string($thisKey)) { $form_output[$option_name][$thisKey] = trim($result); } } return $form_output; } } /** * Validation_Sanitisation::sanitize_post() * * @param string $att * @param string $single * @param array $form_output * @return array */ public function sanitize_post(&$form_output, $att = NULL, $single = NULL) { if ($single == NULL) { if (is_array($form_output)) { array_walk_recursive($form_output, 'sanitize_text_field'); } else { $form_output = sanitize_text_field($form_output); } } else { extract(static::$form); foreach ($form_output[$option_name] as $thisKey => $result) { if (!preg_match("/$att/i", $thisKey)) continue; if (is_string($thisKey)) { $form_output[$option_name][$thisKey] = sanitize_text_field($result); } } // end foreach return $form_output; } } /** * Validation_Sanitisation::strip_tags_post() * * @param string $att * @param boolean $single * @param array $form_output * @return array $form_output */ public function strip_tags_post(&$form_output, $att = NULL, $single = NULL) { if ($single == NULL) { if (is_array($form_output)) { array_walk_recursive($form_output, 'wp_strip_all_tags'); } else { $form_output = wp_strip_all_tags($form_output); } } else { extract(static::$form); foreach ($form_output[$option_name] as $thisKey => $result) { if (!preg_match("/$att/i", $thisKey)) continue; if (is_string($thisKey)) { $form_output[$option_name][$thisKey] = wp_strip_all_tags($result); } } // end foreach return $form_output; } } /** * Validation_Sanitisation::stripslashes() * * @param string $att * @param string $single * @param array $form_output * @return array */ public function stripslashes(&$form_output, $att = NULL, $single = NULL) { if ($single == NULL) { if (is_array($form_output)) { array_walk_recursive($form_output, 'stripslashes_deep'); } else { $form_output = stripslashes_deep($form_output); } } else { extract(static::$form); foreach ($form_output[$option_name] as $thisKey => $result) { if (preg_match("/$att/i", $thisKey)) continue; if (is_string($thisKey)) { $form_output[$option_name][$thisKey] = stripslashes_deep($result); } } // end foreach return $form_output; } } /** * Validation_Sanitisation::alnum() * * @param array $form_output * @param string $att * @return boolean */ public function alnum($form_output, $att) { extract(static::$form); if (is_array($form_output) && is_string($att)) { foreach ($form_output[$option_name] as $key => $value) { if (!preg_match("/$att/i", $key)) continue; if ($value == '') continue; if (!ctype_alnum($value)) { return FALSE; } } // end foreach } else { die('Make sure that the inputs for validate_url() is an array and a string'); } return TRUE; } /** * Validation_Sanitisation::title_check() * * Checks to make sure that title only uses code and nothing else * * @param string $att * @param array $form_output * @return boolean */ // need to make sure that only code [#425#] is public function title_check($form_output, $att) { extract(static::$form); if (is_array($form_output) && is_string($att)) { foreach ($form_output[$option_name] as $thisKey => $result) { if (!preg_match("/$att/i", $thisKey)) continue; if ($result == '') continue; if (!preg_match('/^\[#([0-9]*)#\]$/', $result)) { return FALSE; } // end if } // end foreach } else { die('Make sure that the inputs for validate_url() is an array and a string'); } return TRUE; } /** * Validation_Sanitisation::check_file_error() * * @param string $att * @param array $file * @return string * */ public function check_file_error($file, $att) { $max_up = ah_max_upload(); foreach ($file as $key => $value) { if ($key != 'size') continue; foreach ($value as $new_key => $new_value) { if ((int)implode($new_value) >= $max_up) { return FALSE; } } // end foreach } // end foreach return TRUE; } /** * Validation_Sanitisation::security_check() * * ESSENTIAL! Must include this * Removes non-relevant HTML form fields before database update * and checks nonce value * * @param array $array * @return array */ public function security_check($array) { if (!wp_verify_nonce($array['_wpnonce_options_cov'], 'options_form_cov')) die('Security check failed'); if ($_SERVER['REQUEST_URI'] != $array['_wp_http_referer']) die('Security check failed'); // The values below need to be removed before further validation and database entry unset($array['option_page']); unset($array['_wpnonce_options_cov']); unset($array['_wp_http_referer']); unset($array['submit']); return $array; } /** * Validation_Sanitisation::check_file_empty() * * @param array $file * @param string $att * @return boolean * */ public function check_file_empty($file, $att) { foreach ($file as $key => $value) { if ($key != 'type') continue; foreach ($value as $new_key => $new_value) { if (implode($new_value) == '') { return FALSE; } } // end foreach } // end foreach return TRUE; } /** * Validation_Sanitisation::check_file_ext() * * @param array $file * @param string $att * @return boolean * */ public function check_file_ext($file, $att) { foreach ($file as $key => $value) { if ($key != 'name') continue; foreach ($value as $new_key => $new_value) { if (implode($new_value) == '') continue; // find file extension $ext = pathinfo(implode($new_value), PATHINFO_EXTENSION); if ($ext != 'csv') { return FALSE; } // end if } // end foreach } // end foreach return TRUE; } public function check_file_duplicate($file, $att) { foreach ($file as $key => $value) { if ($key != 'name') continue; $file = $this->db_find_file_name(); foreach ($value as $new_key => $new_value) { if (implode($new_value) == '') continue; foreach ($file as $result) { // get basename of file $basename = pathinfo(implode($new_value), PATHINFO_FILENAME); if (preg_match("/$basename/", $result->fileName)) { return FALSE; } // end if } // end foreach } // end foreach } // end foreach return TRUE; } /** * Validation_Sanitisation::parse_feeds_loop() * * Finds string for parse_feeds() * * @param array $file * @param string $att * @return boolean * */ public function parse_feeds_loop($form_output, $att) { extract(static::$form); if (is_array($form_output) && is_string($att)) { foreach ($form_output[$option_name] as $thisKey => $result) { if (!preg_match("/$att/i", $thisKey)) continue; if ($result != '') continue; return $this->parse_feeds($result); } // end foreach } else { die('Make sure that the inputs for validate_file() is an array and a string'); } } /** * Validation_Sanitisation::failure_message() * * @param mixed $message * @return */ protected function failure_message($message) { //essential extract(static::$form); $html = '
'.$line.'
'; } } else { $html .= ''.$message.'
'; } // end if $html .= '