文件操作 - parsers.php
返回文件管理
返回主菜单
删除本文件
文件: /storage/v12552/jimbrandstatter/public_html/wp-content/themes/Total/inc/functions/parsers.php
编辑文件内容
<?php defined( 'ABSPATH' ) || exit; /** * Parses color to return correct value. */ function wpex_parse_color( $color = '' ) { $color = $color ? trim( (string) $color ) : ''; if ( 'transparent' === $color || 'inherit' === $color || 'currentColor' === $color ) { return $color; } $palette = (array) wpex_get_color_palette(); $palette_color = $palette[$color]['color'] ?? null; if ( $palette_color ) { switch ( $color ) { case 'accent': case 'on-accent': case 'accent-alt': case 'on-accent-alt': $color = "var(--wpex-{$color})"; break; case 'link': $color = 'var(--wpex-link-color, var(--wpex-accent))'; break; /*case 'link-hover': $color = 'var(--wpex-hover-link-color,var(--wpex-link-color, var(--wpex-accent)))'; break;*/ default: $color = "var(--wpex-{$color}-color)"; break; } } return $color; } /** * Cleans up an array, comma- or space-separated list of scalar values. */ function wpex_parse_list( $list ) { if ( is_array( $list ) ) { return $list; } if ( function_exists( 'wp_parse_list' ) ) { return wp_parse_list( $list ); // added in WP 5.1 } // @todo remove fallback. if ( ! is_array( $list ) ) { return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); } } /** * Parse CSS. */ function wpex_parse_css( string $value = '', string $property = '', string $selector = '', string $unit = '', bool $important = false ): string { $css = ''; if ( $selector && $property && $value ) { if ( ! empty( $unit ) ) { $value .= strtolower( $unit ); } if ( $important ) { $value .= '!important'; } $css = strip_tags( "{$selector}{{$property}:{$value};}" ); } return $css; } /** * Takes an array of attributes and outputs them for HTML. */ function wpex_parse_html( string $tag = '', array $attrs = [], string $content_safe = '' ): string { $attrs = wpex_parse_attrs( $attrs ); $tag_escaped = tag_escape( $tag ) ?: 'div'; $output = "<{$tag_escaped} {$attrs}>"; if ( $content_safe ) { $output .= $content_safe; } $output .= "</{$tag_escaped}>"; return $output; } /** * Parses an html data attribute. */ function wpex_parse_attrs( $attrs = [] ) { $output = ''; if ( empty( $attrs ) ) { return $output; } if ( is_string( $attrs ) ) { return $attrs; } // Add noopener noreferrer automatically to nofollow links if rel attr isn't set. if ( isset( $attrs['href'] ) && isset( $attrs['target'] ) && in_array( $attrs['target'], [ '_blank', 'blank' ] ) ) { $rel = apply_filters( 'wpex_targeted_link_rel', 'noopener noreferrer', $attrs['href'] ); if ( ! empty( $rel ) ) { if ( ! empty( $attrs['rel'] ) ) { $attrs['rel'] .= " {$rel}"; } else { $attrs['rel'] = $rel; } } } // Loop through attributes. foreach ( $attrs as $key => $val ) { // Attributes used for other things, we can skip these. if ( 'content' === $key ) { continue; } // If the attribute is an array convert to string. if ( is_array( $val ) && $val = array_filter( $val ) ) { $val = array_map( 'trim', $val ); $val = implode( ' ', $val ); } // Sanitize specific attributes (must go here to prevent ending up with empty attrs). switch ( $key ) { case 'href': case 'src': $val = $val ? esc_url( $val ) : ''; // allow empty don't set to # break; case 'id': if ( $val && is_string( $val ) ) { $val = ltrim( str_replace( ' ', '', $val ), '#' ); } break; case 'target': if ( ! in_array( $val, [ '_blank', 'blank', '_self', '_parent', '_top' ] ) ) { $val = ''; } elseif ( 'blank' === $val ) { $val = '_blank'; } break; } // Add attribute to output if value exists or is a string equal to 0. if ( $val || '0' === $val ) { // Add items to the $output var. switch ( $key ) { // Attributes that don't have values and equal themselves. case 'download': $safe_attr = preg_replace( '/[^a-z0-9_\-]/', '', $val ); $output .= ' ' . trim( $safe_attr ); // Used for example on total button download attribute. break; // Attributes with values. default: $needle = ( 'data' === $key ) ? 'data-' : esc_attr( $key ) . '='; // Tag is already included in the value. if ( strpos( $val, $needle ) !== false ) { $output .= ' ' . trim( wp_strip_all_tags( $val ) ); } // Tag not included in the value. else { $safe_attr = preg_replace( '/[^a-z0-9_\-]/', '', $key ); $output .= ' ' . trim( $safe_attr ) . '="' . esc_attr( trim( $val ) ) . '"'; } break; } } // Attributes without values. elseif ( 'alt' === $key ) { $output .= ' alt=""'; } elseif ( in_array( $key, [ 'itemscope', 'controls', 'playsinline', 'muted' ] ) ) { $output .= " {$key}"; } elseif ( 'data-wpex-hover' !== $key && str_contains( $key, 'data-' ) ) { $safe_attr = preg_replace( '/[^a-z0-9_\-]/', '', $key ); $output .= ' ' . trim( $safe_attr ); } } return trim( (string) $output ); } /** * Returns link target attribute. */ function wpex_parse_link_target( $target = true, $add_rel = true ) { $output = ''; if ( 'blank' === $target || '_blank' === $target ) { $output = ' target="_blank"'; if ( $add_rel ) { $output .= ' rel="noopener noreferrer"'; } } return $output; } /** * Parses background style class. */ function wpex_parse_background_style_class( string $style = '' ): string { $class = ''; switch ( $style ) { case 'stretched': case 'stretch': case 'cover': $class = 'wpex-bg-cover wpex-bg-center wpex-bg-no-repeat'; break; case 'repeat': case 'no-repeat': case 'repeat-x': case 'repeat-y': $class = "wpex-bg-{$style}"; break; case 'fixed': $class = 'wpex-bg-fixed wpex-bg-cover wpex-bg-center wpex-bg-no-repeat'; break; case 'fixed-top': $class = 'wpex-bg-fixed wpex-bg-cover wpex-bg-top wpex-bg-no-repeat'; break; case 'fixed-bottom': $class = 'wpex-bg-fixed wpex-bg-cover wpex-bg-bottom wpex-bg-no-repeat'; break; } return $class; } /** * Parses text_align class. */ function wpex_parse_text_align_class( string $align = '' ) { if ( 'left' === $align || 'center' === $align || 'right' === $align ) { return "wpex-text-{$align}"; } } /** * Parses padding class. */ function wpex_parse_padding_class( string $padding = '' ) { if ( $padding_safe = trim( absint( $padding ) ) ) { return "wpex-p-{$padding_safe}"; } } /** * Parses border_radius class. */ function wpex_parse_border_radius_class( string $border_radius = '' ) { if ( $border_radius_safe = sanitize_html_class( $border_radius ) ) { return "wpex-{$border_radius_safe}"; } } /** * Parses border_width class. */ function wpex_parse_border_width_class( $border_width = '', $sides = 'all' ) { if ( ! $border_width ) { return; } $border_width = absint( $border_width ); $prefix = 'border'; switch ( $sides ) { case 'top': $prefix = 'border-t'; break; case 'left': $prefix = 'border-l'; break; case 'right': $prefix = 'border-r'; break; } if ( 1 === $border_width ) { return 'wpex-border'; } return 'wpex-' . sanitize_html_class( $prefix . '-' . $border_width ); } /** * Parses border_radius class. * * @todo deprecate - this isn't used anywhere, we can instead use vcex_ function instead. */ function wpex_parse_border_style_class( $border_style = '' ) { $allowed = array( 'dashed', 'solid', 'double', 'dotted' ); if ( $border_style && in_array( $border_style, $allowed ) ) { return 'wpex-border-' . sanitize_html_class( $border_style ); } } /** * Parses margin class. * * @todo deprecate - this isn't used anywhere, we can instead use vcex_ function instead. */ function wpex_parse_margin_class( $margin = '', $prefix = '' ) { $margin_choices = wpex_utl_margins(); if ( $margin && array_key_exists( $margin, $margin_choices ) ) { $margin = absint( $margin ); } return sanitize_html_class( $prefix . $margin ); } /** * Parses a direction for RTL compatibility. */ function wpex_parse_direction( string $direction = '' ): string { if ( $direction && is_rtl() ) { switch ( $direction ) { case 'left' : $direction = 'right'; break; case 'right' : $direction = 'left'; break; } } return $direction; }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件