false, 'imported' => 0, 'skipped_missing_target' => 0, 'skipped_loop' => 0, 'regex_unverified' => 0 ); } protected function empty_result( $after_id = 0 ) { return array( 'imported' => 0, 'stripped' => 0, 'skipped' => 0, 'last_id' => (int) $after_id, 'done' => true ); } protected function macros_to_tags( $string, $macros, $trailing ) { $string = (string) $string; if ( '' === $string ) { return ''; } foreach ( $macros as $macro => $tag ) { $string = (string) preg_replace( '#' . $macro . '(?![a-zA-Z0-9_])#im', $tag, $string ); } $string = (string) preg_replace( '#' . $trailing . '#', '', $string ); $string = (string) preg_replace( '/\s+/u', ' ', $string ); return trim( $string, " \t\n\r\0\x0B" ); } protected function normalise_schema_type( $type ) { $type = trim( (string) preg_replace( '#\s#', '', (string) $type ) ); if ( '' === $type ) { return array( '', false ); } $lower = strtolower( $type ); if ( 'faqpage' === $lower || 'faq' === $lower || 'howto' === $lower ) { return array( 'WebPage', true ); } if ( in_array( $lower, array( 'article', 'newsarticle', 'blogposting' ), true ) ) { return array( 'Article', false ); } if ( 'product' === $lower ) { return array( 'Product', false ); } if ( 'webpage' === $lower || 'itempage' === $lower || 'aboutpage' === $lower || 'contactpage' === $lower || 'collectionpage' === $lower || 'checkoutpage' === $lower || 'profilepage' === $lower || 'searchresultspage' === $lower || 'realestatelisting' === $lower ) { return array( 'WebPage', false ); } if ( 'none' === $lower || 'off' === $lower || 'default' === $lower ) { return array( 'default', false ); } return array( 'default', false ); } protected function keyphrase_fields( $focus, $additional = array() ) { $focus = trim( (string) $focus ); $extra = array(); foreach ( (array) $additional as $k ) { $k = trim( (string) $k ); if ( '' !== $k && $k !== $focus ) { $extra[] = array( 'keyphrase' => $k ); } } if ( '' === $focus && ! $extra ) { return array(); } $json = array( 'focus' => array( 'keyphrase' => $focus ) ); if ( $extra ) { $json['additional'] = $extra; } $out = array( 'keyphrases' => wp_json_encode( $json ) ); if ( '' !== $focus ) { $out['focus_keyphrase'] = $focus; $out['focus_keyphrase_source'] = 'imported'; } return $out; } protected function primary_term_fields( $map ) { $clean = array(); foreach ( (array) $map as $tax => $term_id ) { $tax = (string) $tax; $term_id = (int) $term_id; if ( '' !== $tax && $term_id > 0 ) { $clean[ $tax ] = $term_id; } } if ( ! $clean ) { return array(); } $out = array( 'primary_term' => wp_json_encode( $clean ) ); if ( ! empty( $clean['product_cat'] ) ) { $out['primary_cat_id'] = (int) $clean['product_cat']; } elseif ( ! empty( $clean['category'] ) ) { $out['primary_cat_id'] = (int) $clean['category']; } return $out; } protected function robots_fields( $explicit, $flags = array() ) { $known = array( 'noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex', 'noodp', 'notranslate' ); $out = array( 'robots_default' => $explicit ? 0 : 1 ); foreach ( $known as $f ) { $out[ 'robots_' . $f ] = ! empty( $flags[ $f ] ) ? 1 : 0; } return $out; } protected function like_prefix( $prefix ) { global $wpdb; return $wpdb->esc_like( (string) $prefix ) . '%'; } }