/** * Parse/validate input value. See self::get_input_value() * Performs stripslashes() and charset conversion if necessary * * @param string Input value * @param boolean Allow HTML tags in field value * @param string Charset to convert into * * @return string Parsed value */ public static function parse_input_value($value, $allow_html = FALSE, $charset = NULL) { global $OUTPUT; if (empty($value)) { return $value; } if (is_array($value)) { foreach ($value as $idx => $val) { $value[$idx] = self::parse_input_value($val, $allow_html, $charset); } return $value; } // strip single quotes if magic_quotes_sybase is enabled if (ini_get('magic_quotes_sybase')) { $value = str_replace("''", "'", $value); } else { if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) { $value = stripslashes($value); } } // remove HTML tags if not allowed if (!$allow_html) { $value = strip_tags($value); } $output_charset = is_object($OUTPUT) ? $OUTPUT->get_charset() : null; // remove invalid characters (#1488124) if ($output_charset == 'UTF-8') { $value = rcube_charset::clean($value); } // convert to internal charset if ($charset && $output_charset) { $value = rcube_charset::convert($value, $output_charset, $charset); } return $value; }
/** * Returns header value */ public function get($name, $decode = true) { $name = strtolower($name); if (isset($this->obj_headers[$name])) { $value = $this->{$this->obj_headers[$name]}; } else { $value = $this->others[$name]; } if ($decode) { if (is_array($value)) { foreach ($value as $key => $val) { $value[$key] = rcube_mime::decode_header($val, $this->charset); $value[$key] = rcube_charset::clean($val); } } else { $value = rcube_mime::decode_header($value, $this->charset); $value = rcube_charset::clean($value); } } return $value; }
/** * Fix attachment name encoding if needed/possible */ protected function fix_attachment_name($name, $part) { if ($name == rcube_charset::clean($name)) { return $name; } // find charset from part or its parent(s) if ($part->charset) { $charsets[] = $part->charset; } else { // check first part (common case) $n = strpos($part->mime_id, '.') ? preg_replace('/\\.[0-9]+$/', '', $part->mime_id) . '.1' : 1; if (($_part = $this->mime_parts[$n]) && $_part->charset) { $charsets[] = $_part->charset; } // check parents' charset $items = explode('.', $part->mime_id); for ($i = count($items) - 1; $i > 0; $i--) { $last = array_pop($items); $parent = $this->mime_parts[join('.', $items)]; if ($parent && $parent->charset) { $charsets[] = $parent->charset; } } } if ($this->headers->charset) { $charsets[] = $this->headers->charset; } if (empty($charsets)) { $rcube = rcube::get_instance(); $charsets[] = rcube_charset::detect($name, $rcube->config->get('default_charset', RCUBE_CHARSET)); } foreach (array_unique($charsets) as $charset) { $_name = rcube_charset::convert($name, $charset); if ($_name == rcube_charset::clean($_name)) { if (!$part->charset) { $part->charset = $charset; } return $_name; } } return $name; }
/** * Convert a variable into a javascript object notation * * @param mixed $input Input value * @param boolean $pretty Enable JSON formatting * * @return string Serialized JSON string */ public static function json_serialize($input, $pretty = false) { $input = rcube_charset::clean($input); $options = 0; if ($pretty) { $options |= JSON_PRETTY_PRINT; } // sometimes even using rcube_charset::clean() the input contains invalid UTF-8 sequences // that's why we have @ here return @json_encode($input, $options); }
function rc_utf8_clean($input) { return rcube_charset::clean($input); }
/** * Convert a variable into a javascript object notation * * @param mixed Input value * * @return string Serialized JSON string */ public static function json_serialize($input) { $input = rcube_charset::clean($input); // sometimes even using rcube_charset::clean() the input contains invalid UTF-8 sequences // that's why we have @ here return @json_encode($input); }
/** * Returns header value */ public function get($name, $decode = true) { $name = strtolower($name); if (isset($this->obj_headers[$name])) { $value = $this->{$this->obj_headers[$name]}; } else { $value = $this->others[$name]; } if ($decode) { $value = rcube_mime::decode_header($value, $this->charset); $value = rcube_charset::clean($value); } return $value; }
/** * Parse/validate input value. See self::get_input_value() * Performs stripslashes() and charset conversion if necessary * * @param string Input value * @param boolean Allow HTML tags in field value * @param string Charset to convert into * * @return string Parsed value */ public static function parse_input_value($value, $allow_html = false, $charset = null) { global $OUTPUT; if (empty($value)) { return $value; } if (is_array($value)) { foreach ($value as $idx => $val) { $value[$idx] = self::parse_input_value($val, $allow_html, $charset); } return $value; } // remove HTML tags if not allowed if (!$allow_html) { $value = strip_tags($value); } $output_charset = is_object($OUTPUT) ? $OUTPUT->get_charset() : null; // remove invalid characters (#1488124) if ($output_charset == 'UTF-8') { $value = rcube_charset::clean($value); } // convert to internal charset if ($charset && $output_charset) { $value = rcube_charset::convert($value, $output_charset, $charset); } return $value; }
/** * @dataProvider data_clean */ function test_clean($input, $output) { $this->assertEquals($output, rcube_charset::clean($input)); }
function rc_utf8_clean($input) { _deprecation_warning(__FUNCTION__); return rcube_charset::clean($input); }