$value) { if (is_array($input[$key])) { array_walk_recursive($input[$key], $funcname, $userdata); } else { $saved_value = $value; if (!empty($userdata)) { $funcname($value, $key, $userdata); } else { $funcname($value, $key); } if ($value != $saved_value) { $input[$key] = $value; } } } return true; } } if (!function_exists('wp_strip_all_tags')) { /** * Properly strip all HTML tags including script and style * * @since 2.9.0 * * @param string $string String containing HTML tags * @param bool $remove_breaks optional Whether to remove left over line breaks and white space chars * @return string The processed string. */ function wp_strip_all_tags($string, $remove_breaks = false) { $string = preg_replace( '@<(script|style)[^>]*?>.*?@si', '', $string ); $string = strip_tags($string); if ( $remove_breaks ) $string = preg_replace('/[\r\n\t ]+/', ' ', $string); return trim($string); } } if (!function_exists('esc_textarea')) { /** * Escaping for textarea values. * * @since 3.1 * * @param string $text * @return string */ function esc_textarea( $text ) { $safe_text = htmlspecialchars( $text, ENT_QUOTES ); return apply_filters( 'esc_textarea', $safe_text, $text ); } } if (!function_exists('wp_trim_words')) { /** * Trims text to a certain number of words. * * @param string $text Text to trim. * @param int $num_words Number of words. Default 55. * @param string $more What to append if $text needs to be trimmed. Default '…'. * @return string Trimmed text. */ function wp_trim_words( $text, $num_words = 55, $more = null ) { if ( null === $more ) $more = __( '…', 'AWPCP' ); $original_text = $text; $text = wp_strip_all_tags( $text ); $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); if ( count( $words_array ) > $num_words ) { array_pop( $words_array ); $text = implode( ' ', $words_array ); $text = $text . $more; } else { $text = implode( ' ', $words_array ); } return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); } } function awpcp_esc_attr($text) { // WP adds slashes to all request variables $text = stripslashes($text); // AWPCP adds more slashes $text = stripslashes($text); $text = esc_attr($text); return $text; } function awpcp_esc_textarea($text) { $text = stripslashes($text); $text = stripslashes($text); $text = esc_textarea($text); return $text; } /** * @since 3.3 */ function awpcp_apply_function_deep( $function, $value ) { if ( is_array( $value ) ) { foreach ( $value as $key => $data ) { $value[ $key ] = awpcp_apply_function_deep( $function, $data ); } } elseif ( is_object( $value ) ) { $vars = get_object_vars( $value ); foreach ( $vars as $key => $data ) { $value->{$key} = awpcp_apply_function_deep( $function, $data ); } } elseif ( is_string( $value ) ) { $value = call_user_func( $function, $value ); } return $value; } /** * @since 3.3 */ function awpcp_strip_all_tags_deep( $string ) { return awpcp_apply_function_deep( 'wp_strip_all_tags', $string ); } /** * @since 3.0.2 */ function awpcp_strptime( $date, $format ) { if ( function_exists( 'strptime' ) ) { return strptime( $date, $format ); } else { return awpcp_strptime_replacement( $date, $format ); } } /** * @since 3.0.2 */ function awpcp_strptime_replacement( $date, $format ) { $masks = array( '%d' => '(?P[0-9]{2})', '%m' => '(?P[0-9]{2})', '%y' => '(?P[0-9]{2})', '%Y' => '(?P[0-9]{4})', '%H' => '(?P[0-9]{2})', '%M' => '(?P[0-9]{2})', '%S' => '(?P[0-9]{2})', // usw.. ); $regexp = "#" . strtr( preg_quote( $format ), $masks ) . "#"; if ( ! preg_match( $regexp, $date, $out ) ) { return false; } $unparsed = preg_replace( $regexp, '', $date ); if ( isset( $out['y'] ) && strlen( $out['y'] ) ) { $out['Y'] = ( $out['y'] > 69 ? 1900 : 2000 ) + $out['y']; } $ret = array( 'tm_sec' => (int) awpcp_array_data( 'S', 0, $out), 'tm_min' => (int) awpcp_array_data( 'M', 0, $out), 'tm_hour' => (int) awpcp_array_data( 'H', 0, $out), 'tm_mday' => (int) awpcp_array_data( 'd', 0, $out), 'tm_mon' => awpcp_array_data( 'm', 0, $out) ? awpcp_array_data( 'm', 0, $out) - 1 : 0, 'tm_year' => awpcp_array_data( 'Y', 0, $out) > 1900 ? awpcp_array_data( 'Y', 0, $out) - 1900 : 0, 'unparsed' => $unparsed, ); return $ret; } /** * @since 3.0 */ function awpcp_date_formats() { static $translations; if ( ! is_array( $translations ) ) { $translations = array( 'd' => 'dd', 'j' => 'd', 's' => null, 'l' => 'DD', 'D' => 'D', 'm' => 'mm', 'n' => 'm', 'F' => 'MM', 'M' => 'M', 'Y' => 'yy', 'y' => 'y', 'c' => 'ISO_8601', 'r' => 'RFC_822', ); } return $translations; } /** * @since 3.0 */ function awpcp_time_formats() { static $translations; if ( ! is_array( $translations ) ) { $translations = array( 'a' => 'p', 'A' => 'P', 'g' => 'h', 'h' => 'hh', 'G' => 'H', 'H' => 'HH', 'i' => 'mm', 's' => 'ss', 'T' => null, 'c' => null, 'r' => null ); } return $translations; } /** * Translates PHP date format strings to jQuery Datepicker format. * @since 3.0 */ function awpcp_datepicker_format($format) { return _awpcp_replace_format($format, awpcp_date_formats()); } /** * Translates PHP time format strings to jQuery TimePicker format. * @since 3.0 */ function awpcp_timepicker_format($format) { return _awpcp_replace_format($format, awpcp_time_formats()); } /** * @since 3.0 */ function _awpcp_replace_format($format, $translations) { $pattern = join( '|', array_map( 'preg_quote', array_keys( $translations ) ) ); preg_match_all( "/$pattern/s", $format, $matches ); $processed = array(); foreach ( $matches[0] as $match ) { if ( ! isset( $processed[ $match ] ) ) { $format = str_replace( $match, $translations[ $match ], $format ); $processed[ $match ] = true; } } return $format; } /** * @since 3.0 */ function awpcp_get_date_format() { return get_awpcp_option('date-format'); } /** * @since 3.0 */ function awpcp_get_time_format() { return get_awpcp_option('time-format'); } /** * @since 3.0 */ function awpcp_get_datetime_format() { $format = get_awpcp_option('date-time-format'); $format = str_replace('', '******', $format); $format = str_replace('