' . __( 'You can navigate to your sitemap(s) using the links below:', 'all-in-one-seo-pack' ) . '
' . __( 'Any changes are automatically submitted to search engines.', 'all-in-one-seo-pack' ) . '
' . sprintf( __( 'Warning: your privacy settings are configured to ask search engines to not index your site; you can change this under %s for your site.', 'all-in-one-seo-pack' ), $privacy_link ); } $excl_terms = array(); if ( isset( $options[ $this->prefix . 'excl_terms' ] ) && is_array( $options[ $this->prefix . 'excl_terms' ] ) ) { foreach ( $options[ $this->prefix . 'excl_terms' ] as $k1_taxonomy => $v1_tax_terms ) { foreach ( $v1_tax_terms['terms'] as $v2_term ) { $excl_terms[] = $k1_taxonomy . '-' . $v2_term; } } } $options[ $this->prefix . 'excl_terms' ] = $excl_terms; return $options; } /** * Filter Options * * Handle 'all' option for post types / taxonomies, further sanitization of filename, rewrites on for multisite, setting up addl pages option. * * @todo This needs nonce support. * * @since ? * @since 3.0 Change saving 'excl_terms' to database with tax_query format for custom taxonomy support. (Pro #240) * * @param $options * @return mixed */ public function filter_options( $options ) { if ( ! isset( $this->default_options['posttypes']['initial_options'] ) ) { $this->add_post_types(); } // TODO Add `true` in 3rd argument with in_array(); which changes it to a strict comparison. if ( is_array( $options[ "{$this->prefix}posttypes" ] ) && in_array( 'all', $options[ "{$this->prefix}posttypes" ] ) && is_array( $this->default_options['posttypes']['initial_options'] ) ) { $options[ "{$this->prefix}posttypes" ] = array_keys( $this->default_options['posttypes']['initial_options'] ); } // TODO Add `true` in 3rd argument with in_array(); which changes it to a strict comparison. if ( is_array( $options[ "{$this->prefix}taxonomies" ] ) && in_array( 'all', $options[ "{$this->prefix}taxonomies" ] ) && is_array( $this->default_options['taxonomies']['initial_options'] ) ) { $options[ "{$this->prefix}taxonomies" ] = array_keys( $this->default_options['taxonomies']['initial_options'] ); } if ( is_multisite() ) { $options[ $this->prefix . 'rewrite' ] = 'On'; } if ( ! is_array( $options[ $this->prefix . 'addl_pages' ] ) ) { $options[ $this->prefix . 'addl_pages' ] = wp_specialchars_decode( stripslashes_deep( $options[ $this->prefix . 'addl_pages' ] ), ENT_QUOTES ); $decoded = json_decode( $options[ $this->prefix . 'addl_pages' ] ); if ( null === $decoded ) { $decoded = maybe_unserialize( $options[ $this->prefix . 'addl_pages' ] ); } if ( ! is_array( $decoded ) ) { $decoded = (array) $decoded; } if ( null === $decoded ) { $decoded = $options[ $this->prefix . 'addl_pages' ]; } $options[ $this->prefix . 'addl_pages' ] = $decoded; } if ( is_array( $options[ $this->prefix . 'addl_pages' ] ) ) { foreach ( $options[ $this->prefix . 'addl_pages' ] as $k => $v ) { if ( is_object( $v ) ) { $options[ $this->prefix . 'addl_pages' ][ $k ] = (array) $v; } } } if ( isset( $options[ $this->prefix . 'addl_pages' ][0] ) ) { unset( $options[ $this->prefix . 'addl_pages' ][0] ); } // TODO Refactor all these... use a nonce, dump the incoming _Post into an array and use that. if ( ! empty( $_POST[ $this->prefix . 'addl_url' ] ) ) { foreach ( array( 'addl_url', 'addl_prio', 'addl_freq', 'addl_mod' ) as $field ) { if ( ! empty( $_POST[ $this->prefix . $field ] ) ) { // TODO Add/Change to filter_input(). $_POST[ $this->prefix . $field ] = esc_attr( wp_kses_post( $_POST[ $this->prefix . $field ] ) ); } else { // TODO Add/Change to filter_input(). $_POST[ $this->prefix . $field ] = ''; } } if ( ! is_array( $options[ $this->prefix . 'addl_pages' ] ) ) { $options[ $this->prefix . 'addl_pages' ] = array(); } if ( aiosp_common::is_url_valid( $_POST[ $this->prefix . 'addl_url' ] ) ) { $options[ $this->prefix . 'addl_pages' ][ $_POST[ $this->prefix . 'addl_url' ] ] = array( // TODO Add/Change to filter_input(). 'prio' => $_POST[ $this->prefix . 'addl_prio' ], 'freq' => $_POST[ $this->prefix . 'addl_freq' ], 'mod' => $_POST[ $this->prefix . 'addl_mod' ], ); } } if ( ! empty( $_POST[ $this->prefix . 'excl_terms' ] ) ) { $raw_excl_terms = filter_input( INPUT_POST, $this->prefix . 'excl_terms', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); // Parse taxonomy terms {$taxonomy_slug}-{$term_id}. $excl_terms = array(); foreach ( $raw_excl_terms as $v1_tax_term ) { $term_id = explode( '-', $v1_tax_term ); $term_id = intval( end( $term_id ) ); $taxonomy_slug = sanitize_text_field( str_replace( '-' . $term_id, '', $v1_tax_term ) ); // Initialize taxonomy => terms array if not yet set. if ( ! isset( $excl_terms[ $taxonomy_slug ] ) ) { $excl_terms[ $taxonomy_slug ] = array( 'terms' => array(), ); } $excl_terms[ $taxonomy_slug ]['taxonomy'] = $taxonomy_slug; $excl_terms[ $taxonomy_slug ]['terms'][] = $term_id; } $options[ $this->prefix . 'excl_terms' ] = $excl_terms; } return $options; } /** * Gets Home Path * * If we're in wp-admin, use the WordPress function, otherwise we user our own version here. * This only applies to static sitemaps. * * @since 2.3.6.1 * * @return mixed|string */ public function get_home_path() { if ( function_exists( 'get_home_path' ) ) { return get_home_path(); } $home = set_url_scheme( get_option( 'home' ), 'http' ); $siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' ); if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) { $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */ $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) ); $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos ); $home_path = trailingslashit( $home_path ); } else { $home_path = ABSPATH; } return str_replace( '\\', '/', $home_path ); } /** * Whitelist Static Sitemaps * * Whitelists files from static sitemap conflict warning. * For right now, this is just externally produced news sitemaps until we figure out something better. * * @since 2.3.10.2 * * @param $file * @return string */ public function whitelist_static_sitemaps( $file ) { $whitelist = array( 'sitemap_news.xml', 'sitemap-news.xml' ); if ( in_array( $file, $whitelist, true ) ) { return ''; } return $file; } /** * Scan Match Files * * Scan for sitemaps on filesystem. * * @since ? * * @return array */ public function scan_match_files() { $scan1 = ''; $files = array(); $filename = $this->get_filename(); if ( ! empty( $filename ) ) { $scan1 = get_home_path() . $filename . '*.xml'; if ( empty( $scan1 ) ) { return $files; } $home_path = get_home_path(); $filescan = $this->scandir( $home_path ); if ( ! empty( $filescan ) ) { foreach ( $filescan as $f ) { if ( ! empty( $scan1 ) && fnmatch( $scan1, $home_path . $f ) ) { $f = $this->whitelist_static_sitemaps( $f ); $files[] = $home_path . $f; continue; } } } return $files; } } /** * Do Sitemap Scan * * Handle deleting / renaming of conflicting sitemap files. * * @todo Add/Fix nonce. * * @since ? */ public function do_sitemap_scan() { $msg = ''; if ( ! empty( $this->options[ "{$this->prefix}rewrite" ] ) && ( get_option( 'permalink_structure' ) === '' ) ) { $msg = '
' . __( 'Warning: dynamic sitemap generation must have permalinks enabled.', 'all-in-one-seo-pack' ) . '
' . sprintf( __( 'Deleted %s.', 'all-in-one-seo-pack' ), $ren_file ) . '
' . sprintf( __( "Couldn't rename file %s!", 'all-in-one-seo-pack' ), $ren_file ) . '
' . sprintf( __( 'Renamed %1$s to %2$s.', 'all-in-one-seo-pack' ), $ren_file, $ren_to ) . '
' . sprintf( __( "Couldn't find file %s!", 'all-in-one-seo-pack' ), $ren_file ) . '
' . sprintf( __( "Warning: a static sitemap '%1\$s' generated by %2\$s %3\$s on %4\$s already exists that may conflict with dynamic sitemap generation.", 'all-in-one-seo-pack' ), $f, AIOSEOP_PLUGIN_NAME, $matches[2], $matches[3] ) . "
' . sprintf( __( 'Potential conflict with unknown file %s.', 'all-in-one-seo-pack' ), $f ) . "
' . sprintf( __( 'Removed empty file %s.', 'all-in-one-seo-pack' ), $f ) . "