| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/Sitemap.php.tar |
namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/ImportExport/SeoPress/Sitemap.php 0000644 00000003600 15113670025 0031317 0 ustar 00 home/xbodynamge <?php
namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the Sitemap Settings.
*
* @since 4.1.4
*/
class Sitemap {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Class constructor.
*
* @since 4.1.4
*/
public function __construct() {
$this->options = get_option( 'seopress_xml_sitemap_option_name' );
if ( empty( $this->options ) ) {
return;
}
$this->migratePostTypesInclude();
$this->migrateTaxonomiesInclude();
$settings = [
'seopress_xml_sitemap_general_enable' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'enable' ] ],
'seopress_xml_sitemap_author_enable' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'author' ] ],
];
aioseo()->importExport->seoPress->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the post types to include in sitemap settings.
*
* @since 4.1.4
*
* @return void
*/
public function migratePostTypesInclude() {
$postTypesMigrate = $this->options['seopress_xml_sitemap_post_types_list'];
$postTypesInclude = [];
foreach ( $postTypesMigrate as $postType => $options ) {
$postTypesInclude[] = $postType;
}
aioseo()->options->sitemap->general->postTypes->included = $postTypesInclude;
}
/**
* Migrates the taxonomies to include in sitemap settings.
*
* @since 4.1.4
*
* @return void
*/
public function migrateTaxonomiesInclude() {
$taxonomiesMigrate = $this->options['seopress_xml_sitemap_taxonomies_list'];
$taxonomiesInclude = [];
foreach ( $taxonomiesMigrate as $taxonomy => $options ) {
$taxonomiesInclude[] = $taxonomy;
}
aioseo()->options->sitemap->general->taxonomies->included = $taxonomiesInclude;
}
} namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/ImportExport/RankMath/Sitemap.php 0000644 00000011643 15113670767 0031304 0 ustar 00 home/xbodynamge <?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the sitemap settings.
*
* @since 4.0.0
*/
class Sitemap {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->options = get_option( 'rank-math-options-sitemap' );
if ( empty( $this->options ) ) {
return;
}
$this->migrateIncludedObjects();
$this->migrateIncludeImages();
$this->migrateExcludedPosts();
$this->migrateExcludedTerms();
$settings = [
'items_per_page' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'linksPerIndex' ] ],
];
aioseo()->options->sitemap->general->indexes = true;
aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the included post types and taxonomies.
*
* @since 4.0.0
*
* @return void
*/
private function migrateIncludedObjects() {
$includedPostTypes = [];
$includedTaxonomies = [];
$allowedPostTypes = array_values( array_diff( aioseo()->helpers->getPublicPostTypes( true ), aioseo()->helpers->getNoindexedPostTypes() ) );
foreach ( $allowedPostTypes as $postType ) {
foreach ( $this->options as $name => $value ) {
if ( preg_match( "#pt_{$postType}_sitemap$#", (string) $name, $match ) && 'on' === $this->options[ $name ] ) {
$includedPostTypes[] = $postType;
}
}
}
$allowedTaxonomies = array_values( array_diff( aioseo()->helpers->getPublicTaxonomies( true ), aioseo()->helpers->getNoindexedTaxonomies() ) );
foreach ( $allowedTaxonomies as $taxonomy ) {
foreach ( $this->options as $name => $value ) {
if ( preg_match( "#tax_{$taxonomy}_sitemap$#", (string) $name, $match ) && 'on' === $this->options[ $name ] ) {
$includedTaxonomies[] = $taxonomy;
}
}
}
aioseo()->options->sitemap->general->postTypes->included = $includedPostTypes;
if ( count( $allowedPostTypes ) !== count( $includedPostTypes ) ) {
aioseo()->options->sitemap->general->postTypes->all = false;
}
aioseo()->options->sitemap->general->taxonomies->included = $includedTaxonomies;
if ( count( $allowedTaxonomies ) !== count( $includedTaxonomies ) ) {
aioseo()->options->sitemap->general->taxonomies->all = false;
}
}
/**
* Migrates the Redirect Attachments setting.
*
* @since 4.0.0
*
* @return void
*/
private function migrateIncludeImages() {
if ( ! empty( $this->options['include_images'] ) ) {
if ( 'off' === $this->options['include_images'] ) {
aioseo()->options->sitemap->general->advancedSettings->enable = true;
aioseo()->options->sitemap->general->advancedSettings->excludeImages = true;
}
}
}
/**
* Migrates the posts that are excluded from the sitemap.
*
* @since 4.0.0
*
* @return void
*/
private function migrateExcludedPosts() {
if ( empty( $this->options['exclude_posts'] ) ) {
return;
}
$rmExcludedPosts = array_filter( explode( ',', $this->options['exclude_posts'] ) );
$excludedPosts = aioseo()->options->sitemap->general->advancedSettings->excludePosts;
if ( count( $rmExcludedPosts ) ) {
foreach ( $rmExcludedPosts as $rmExcludedPost ) {
$post = get_post( trim( $rmExcludedPost ) );
if ( ! is_object( $post ) ) {
continue;
}
$excludedPost = new \stdClass();
$excludedPost->value = $post->ID;
$excludedPost->type = $post->post_type;
$excludedPost->label = $post->post_title;
$excludedPost->link = get_permalink( $post->ID );
array_push( $excludedPosts, wp_json_encode( $excludedPost ) );
}
aioseo()->options->sitemap->general->advancedSettings->enable = true;
}
aioseo()->options->sitemap->general->advancedSettings->excludePosts = $excludedPosts;
}
/**
* Migrates the terms that are excluded from the sitemap.
*
* @since 4.0.0
*
* @return void
*/
private function migrateExcludedTerms() {
if ( empty( $this->options['exclude_terms'] ) ) {
return;
}
$rmExcludedTerms = array_filter( explode( ',', $this->options['exclude_terms'] ) );
$excludedTerms = aioseo()->options->sitemap->general->advancedSettings->excludeTerms;
if ( count( $rmExcludedTerms ) ) {
foreach ( $rmExcludedTerms as $rmExcludedTerm ) {
$term = get_term( trim( $rmExcludedTerm ) );
if ( ! is_object( $term ) ) {
continue;
}
$excludedTerm = new \stdClass();
$excludedTerm->value = $term->term_id;
$excludedTerm->type = $term->taxonomy;
$excludedTerm->label = $term->name;
$excludedTerm->link = get_term_link( $term );
array_push( $excludedTerms, wp_json_encode( $excludedTerm ) );
}
aioseo()->options->sitemap->general->advancedSettings->enable = true;
}
aioseo()->options->sitemap->general->advancedSettings->excludeTerms = $excludedTerms;
}
} home/xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/Migration/Sitemap.php 0000644 00000035775 15113676111 0025720 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Migration;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the XML Sitemap settings from V3.
*
* @since 4.0.0
*/
class Sitemap {
/**
* The old V3 options.
*
* @since 4.0.0
*
* @var array
*/
protected $oldOptions = [];
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->oldOptions = aioseo()->migration->oldOptions;
if ( empty( $this->oldOptions['modules']['aiosp_sitemap_options'] ) ) {
return;
}
$this->checkIfStatic();
$this->migrateLinksPerIndex();
$this->migrateIncludedObjects();
$this->migratePrioFreq();
$this->migrateAdditionalPages();
$this->migrateExcludedPages();
$this->regenerateSitemap();
$settings = [
'aiosp_sitemap_indexes' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'indexes' ] ],
'aiosp_sitemap_archive' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'date' ] ],
'aiosp_sitemap_author' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'author' ] ],
'aiosp_sitemap_images' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'excludeImages' ] ],
'aiosp_sitemap_rss_sitemap' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'rss', 'enable' ] ],
'aiosp_sitemap_filename' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'filename' ] ],
'aiosp_sitemap_publication_name' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'news', 'publicationName' ] ],
'aiosp_sitemap_rewrite' => [ 'type' => 'boolean', 'newOption' => [ 'deprecated', 'sitemap', 'general', 'advancedSettings', 'dynamic' ] ]
];
aioseo()->migration->helpers->mapOldToNew( $settings, $this->oldOptions['modules']['aiosp_sitemap_options'] );
if (
aioseo()->options->sitemap->general->advancedSettings->excludePosts ||
aioseo()->options->sitemap->general->advancedSettings->excludeTerms ||
aioseo()->options->sitemap->general->advancedSettings->excludeImages ||
( in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) && ! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic )
) {
aioseo()->options->sitemap->general->advancedSettings->enable = true;
}
}
/**
* Check if the sitemap is statically generated.
*
* @since 4.0.0
*
* @return void
*/
private function checkIfStatic() {
if (
isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] ) &&
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] )
) {
$deprecatedOptions = aioseo()->internalOptions->internal->deprecatedOptions;
array_push( $deprecatedOptions, 'staticSitemap' );
aioseo()->internalOptions->internal->deprecatedOptions = $deprecatedOptions;
aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic = false;
}
}
/**
* Migrates the amount of links per sitemap index.
*
* @since 4.0.0
*
* @return void
*/
private function migrateLinksPerIndex() {
if ( ! empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_max_posts'] ) ) {
$value = intval( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_max_posts'] );
if ( ! $value ) {
return;
}
$value = $value > 50000 ? 50000 : $value;
aioseo()->options->sitemap->general->linksPerIndex = $value;
}
}
/**
* Migrates the excluded object settings.
*
* @since 4.0.0
*
* @return void
*/
protected function migrateExcludedPages() {
if (
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_terms'] ) &&
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_pages'] )
) {
return;
}
$excludedPosts = aioseo()->options->sitemap->general->advancedSettings->excludePosts;
if ( ! empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_pages'] ) ) {
$pages = explode( ',', $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_pages'] );
if ( count( $pages ) ) {
foreach ( $pages as $page ) {
$page = trim( $page );
$id = intval( $page );
if ( ! $id ) {
$post = get_page_by_path( $page, OBJECT, aioseo()->helpers->getPublicPostTypes( true ) );
if ( $post && is_object( $post ) ) {
$id = $post->ID;
}
}
if ( $id ) {
$post = get_post( $id );
if ( ! is_object( $post ) ) {
continue;
}
$excludedPost = new \stdClass();
$excludedPost->value = $id;
$excludedPost->type = $post->post_type;
$excludedPost->label = $post->post_title;
$excludedPost->link = get_permalink( $id );
array_push( $excludedPosts, wp_json_encode( $excludedPost ) );
}
}
}
}
aioseo()->options->sitemap->general->advancedSettings->excludePosts = $excludedPosts;
$excludedTerms = aioseo()->options->sitemap->general->advancedSettings->excludeTerms;
if ( ! empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_terms'] ) ) {
foreach ( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_terms'] as $taxonomy ) {
foreach ( $taxonomy['terms'] as $id ) {
$term = get_term( $id );
if ( ! is_a( $term, 'WP_Term' ) ) {
continue;
}
$excludedTerm = new \stdClass();
$excludedTerm->value = $id;
$excludedTerm->type = $term->taxonomy;
$excludedTerm->label = $term->name;
$excludedTerm->link = get_term_link( $term );
array_push( $excludedTerms, wp_json_encode( $excludedTerm ) );
}
}
}
aioseo()->options->sitemap->general->advancedSettings->excludeTerms = $excludedTerms;
}
/**
* Migrates the objects that are included in the sitemap.
*
* @since 4.0.0
*
* @return void
*/
protected function migrateIncludedObjects() {
if (
! isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] ) &&
! isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] )
) {
return;
}
if ( ! is_array( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] ) ) {
$this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] = [];
}
if ( ! is_array( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] ) ) {
$this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] = [];
}
$publicPostTypes = aioseo()->helpers->getPublicPostTypes( true );
$publicTaxonomies = aioseo()->helpers->getPublicTaxonomies( true );
if ( in_array( 'all', $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'], true ) ) {
aioseo()->options->sitemap->general->postTypes->all = true;
aioseo()->options->sitemap->general->postTypes->included = array_values( $publicPostTypes );
} else {
$allPostTypes = true;
foreach ( $publicPostTypes as $postType ) {
if ( ! in_array( $postType, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'], true ) ) {
$allPostTypes = false;
}
}
aioseo()->options->sitemap->general->postTypes->all = $allPostTypes;
aioseo()->options->sitemap->general->postTypes->included = array_values(
array_intersect( $publicPostTypes, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] )
);
}
if ( in_array( 'all', $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'], true ) ) {
aioseo()->options->sitemap->general->taxonomies->all = true;
aioseo()->options->sitemap->general->taxonomies->included = array_values( $publicTaxonomies );
} else {
$allTaxonomies = true;
foreach ( $publicTaxonomies as $taxonomy ) {
if ( ! in_array( $taxonomy, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'], true ) ) {
$allTaxonomies = false;
}
}
aioseo()->options->sitemap->general->taxonomies->all = $allTaxonomies;
aioseo()->options->sitemap->general->taxonomies->included = array_values(
array_intersect( $publicTaxonomies, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] )
);
}
}
/**
* Migrates the additional pages that are included in the sitemap.
*
* @since 4.0.0
*
* @return void
*/
private function migrateAdditionalPages() {
if ( empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] ) ) {
return;
}
$pages = [];
foreach ( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] as $url => $values ) {
$page = new \stdClass();
$page->url = esc_url( wp_strip_all_tags( $url ) );
$page->priority = [ 'label' => $values['prio'], 'value' => $values['prio'] ];
$page->frequency = [ 'label' => $values['freq'], 'value' => $values['freq'] ];
$page->lastModified = gmdate( 'm/d/Y', strtotime( $values['mod'] ) );
$pages[] = wp_json_encode( $page );
}
aioseo()->options->sitemap->general->additionalPages->enable = true;
aioseo()->options->sitemap->general->additionalPages->pages = $pages;
}
/**
* Migrates the priority/frequency settings.
*
* @since 4.0.0
*
* @return void
*/
private function migratePrioFreq() {
$settings = [
'aiosp_sitemap_prio_homepage' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'homePage', 'priority' ] ],
'aiosp_sitemap_freq_homepage' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'homePage', 'frequency' ] ],
'aiosp_sitemap_prio_post' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'postTypes', 'priority' ] ],
'aiosp_sitemap_freq_post' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'postTypes', 'frequency' ] ],
'aiosp_sitemap_prio_post_post' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'priority', 'postTypes', 'post', 'priority' ], 'dynamic' => true ],
'aiosp_sitemap_freq_post_post' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'priority', 'postTypes', 'post', 'frequency' ], 'dynamic' => true ],
'aiosp_sitemap_prio_taxonomies' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'taxonomies', 'priority' ] ],
'aiosp_sitemap_freq_taxonomies' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'taxonomies', 'frequency' ] ],
'aiosp_sitemap_prio_archive' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'archive', 'priority' ] ],
'aiosp_sitemap_freq_archive' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'archive', 'frequency' ] ],
'aiosp_sitemap_prio_author' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'author', 'priority' ] ],
'aiosp_sitemap_freq_author' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'author', 'frequency' ] ],
];
foreach ( $this->oldOptions['modules']['aiosp_sitemap_options'] as $name => $value ) {
// Ignore fixed settings.
if ( in_array( $name, array_keys( $settings ), true ) ) {
continue;
}
$type = false;
$slug = '';
if ( preg_match( '#aiosp_sitemap_prio_(.*)#', (string) $name, $slug ) ) {
$type = 'priority';
} elseif ( preg_match( '#aiosp_sitemap_freq_(.*)#', (string) $name, $slug ) ) {
$type = 'frequency';
}
if ( empty( $slug ) || empty( $slug[1] ) ) {
continue;
}
$objectSlug = aioseo()->helpers->pregReplace( '#post_(?!tag)|taxonomies_#', '', $slug[1] );
if ( in_array( $objectSlug, aioseo()->helpers->getPublicPostTypes( true ), true ) ) {
$settings[ $name ] = [
'type' => 'priority' === $type ? 'float' : 'string',
'newOption' => [ 'sitemap', 'priority', 'postTypes', $objectSlug, $type ],
'dynamic' => true
];
continue;
}
if ( in_array( $objectSlug, aioseo()->helpers->getPublicTaxonomies( true ), true ) ) {
$settings[ $name ] = [
'type' => 'priority' === $type ? 'float' : 'string',
'newOption' => [ 'sitemap', 'priority', 'taxonomies', $objectSlug, $type ],
'dynamic' => true
];
}
}
$mainOptions = aioseo()->options->noConflict();
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
foreach ( $settings as $name => $values ) {
// If setting is set to default, do nothing.
if (
empty( $this->oldOptions['modules']['aiosp_sitemap_options'][ $name ] ) ||
'no' === $this->oldOptions['modules']['aiosp_sitemap_options'][ $name ]
) {
unset( $settings[ $name ] );
continue;
}
// If value is "Select Individual", set grouped to false.
$value = $this->oldOptions['modules']['aiosp_sitemap_options'][ $name ];
if ( 'sel' === $value ) {
if ( preg_match( '#post$#', (string) $name ) ) {
aioseo()->options->sitemap->general->advancedSettings->priority->postTypes->grouped = false;
} else {
aioseo()->options->sitemap->general->advancedSettings->priority->taxonomies->grouped = false;
}
continue;
}
$object = new \stdClass();
$object->label = $value;
$object->value = $value;
$error = false;
$options = ! empty( $values['dynamic'] ) ? $dynamicOptions : $mainOptions;
$lastOption = '';
for ( $i = 0; $i < count( $values['newOption'] ); $i++ ) {
$lastOption = $values['newOption'][ $i ];
if ( ! $options->has( $lastOption, false ) ) {
$error = true;
break;
}
if ( count( $values['newOption'] ) - 1 !== $i ) {
$options = $options->$lastOption;
}
}
if ( $error ) {
continue;
}
$options->$lastOption = wp_json_encode( $object );
}
if ( count( $settings ) ) {
$mainOptions->sitemap->general->advancedSettings->enable = true;
}
}
/**
* Regenerates the sitemap if it is static.
*
* We need to do this since the stylesheet URLs have changed.
*
* @since 4.0.0
*
* @return void
*/
private function regenerateSitemap() {
if (
isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] ) &&
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] )
) {
$files = aioseo()->sitemap->file->files();
$detectedFiles = [];
foreach ( $files as $filename ) {
// We don't want to delete the video sitemap here at all.
$isVideoSitemap = preg_match( '#.*video.*#', (string) $filename ) ? true : false;
if ( ! $isVideoSitemap ) {
$detectedFiles[] = $filename;
}
}
$fs = aioseo()->core->fs;
if ( count( $detectedFiles ) && $fs->isWpfsValid() ) {
foreach ( $detectedFiles as $file ) {
$fs->fs->delete( $file, false, 'f' );
}
}
aioseo()->sitemap->file->generate( true );
}
}
} home/xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/SearchStatistics/Sitemap.php 0000644 00000007546 15114313024 0027232 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\SearchStatistics;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles the sitemaps for the search statistics.
*
* @since 4.6.2
*/
class Sitemap {
/**
* The action name.
*
* @since 4.6.2
*
* @var string
*/
public $action = 'aioseo_search_statistics_sitemap_sync';
/**
* Class constructor.
*
* @since 4.6.2
*/
public function __construct() {
add_action( 'admin_init', [ $this, 'init' ] );
add_action( $this->action, [ $this, 'worker' ] );
}
/**
* Initialize the class.
*
* @since 4.6.2
*
* @return void
*/
public function init() {
if (
! aioseo()->searchStatistics->api->auth->isConnected() ||
! aioseo()->internalOptions->searchStatistics->site->verified ||
aioseo()->actionScheduler->isScheduled( $this->action )
) {
return;
}
aioseo()->actionScheduler->scheduleAsync( $this->action );
}
/**
* Sync the sitemap.
*
* @since 4.6.3
*
* @return void
*/
public function worker() {
if ( ! $this->canSync() ) {
return;
}
$api = new Api\Request( 'google-search-console/sitemap/sync/', [ 'sitemaps' => aioseo()->sitemap->helpers->getSitemapUrls() ] );
$response = $api->request();
if ( is_wp_error( $response ) || empty( $response['data'] ) ) {
// If it failed to communicate with the server, try again in a few hours.
aioseo()->actionScheduler->scheduleSingle( $this->action, wp_rand( HOUR_IN_SECONDS, 2 * HOUR_IN_SECONDS ), [], true );
return;
}
aioseo()->internalOptions->searchStatistics->sitemap->list = $response['data'];
aioseo()->internalOptions->searchStatistics->sitemap->lastFetch = time();
// Schedule a new sync for the next week.
aioseo()->actionScheduler->scheduleSingle( $this->action, WEEK_IN_SECONDS + wp_rand( 0, 3 * DAY_IN_SECONDS ), [], true );
}
/**
* Maybe sync the sitemap after updating the options.
* It will check whether the sitemap options have changed and sync the sitemap if needed.
*
* @since 4.6.2
*
* @param array $oldSitemapOptions The old sitemap options.
* @param array $newSitemapOptions The new sitemap options.
*
* @return void
*/
public function maybeSync( $oldSitemapOptions, $newSitemapOptions ) {
if (
! $this->canSync() ||
empty( $oldSitemapOptions ) ||
empty( $newSitemapOptions )
) {
return;
}
// Ignore the HTML sitemap, since it's not actually a sitemap to be synced with Google.
unset( $newSitemapOptions['html'] );
$shouldResync = false;
foreach ( $newSitemapOptions as $type => $options ) {
if ( empty( $oldSitemapOptions[ $type ] ) ) {
continue;
}
if ( $oldSitemapOptions[ $type ]['enable'] !== $options['enable'] ) {
$shouldResync = true;
break;
}
}
if ( ! $shouldResync ) {
return;
}
aioseo()->actionScheduler->unschedule( $this->action );
aioseo()->actionScheduler->scheduleAsync( $this->action );
}
/**
* Get the sitemaps with errors.
*
* @since 4.6.2
*
* @return array
*/
public function getSitemapsWithErrors() {
$sitemaps = aioseo()->internalOptions->searchStatistics->sitemap->list;
$ignored = aioseo()->internalOptions->searchStatistics->sitemap->ignored;
if ( empty( $sitemaps ) ) {
return [];
}
$errors = [];
$pluginSitemaps = aioseo()->sitemap->helpers->getSitemapUrls();
foreach ( $sitemaps as $sitemap ) {
if (
empty( $sitemap['errors'] ) ||
in_array( $sitemap['path'], $ignored, true ) || // Skip user-ignored sitemaps.
in_array( $sitemap['path'], $pluginSitemaps, true ) // Skip plugin sitemaps.
) {
continue;
}
$errors[] = $sitemap;
}
return $errors;
}
/**
* Check if the sitemap can be synced.
*
* @since 4.6.2
*
* @return bool
*/
private function canSync() {
return aioseo()->searchStatistics->api->auth->isConnected() && aioseo()->internalOptions->searchStatistics->site->verified;
}
} home/xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/Sitemap/Html/Sitemap.php 0000644 00000014025 15114330126 0026250 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Sitemap\Html {
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Main class for the HTML sitemap.
*
* @since 4.1.3
*/
class Sitemap {
/** Instance of the frontend class.
*
* @since 4.1.3
*
* @var Frontend
*/
public $frontend;
/**
* Instance of the shortcode class.
*
* @since 4.1.3
*
* @var Shortcode
*/
public $shortcode;
/**
* Instance of the block class.
*
* @since 4.1.3
*
* @var Block
*/
public $block;
/**
* Whether the current queried page is the dedicated sitemap page.
*
* @since 4.1.3
*
* @var bool
*/
public $isDedicatedPage = false;
/**
* Class constructor.
*
* @since 4.1.3
*/
public function __construct() {
$this->frontend = new Frontend();
$this->shortcode = new Shortcode();
$this->block = new Block();
add_action( 'widgets_init', [ $this, 'registerWidget' ] );
add_filter( 'aioseo_canonical_url', [ $this, 'getCanonicalUrl' ] );
if ( ! is_admin() || wp_doing_ajax() || wp_doing_cron() ) {
add_action( 'template_redirect', [ $this, 'checkForDedicatedPage' ] );
}
}
/**
* Register our HTML sitemap widget.
*
* @since 4.1.3
*
* @return void
*/
public function registerWidget() {
if ( aioseo()->helpers->canRegisterLegacyWidget( 'aioseo-html-sitemap-widget' ) ) {
register_widget( 'AIOSEO\Plugin\Common\Sitemap\Html\Widget' );
}
}
/**
* Checks whether the current request is for our dedicated HTML sitemap page.
*
* @since 4.1.3
*
* @return void
*/
public function checkForDedicatedPage() {
if ( ! aioseo()->options->sitemap->html->enable ) {
return;
}
global $wp;
$sitemapUrl = aioseo()->options->sitemap->html->pageUrl;
if ( ! $sitemapUrl || empty( $wp->request ) ) {
return;
}
$sitemapUrl = wp_parse_url( $sitemapUrl );
if ( empty( $sitemapUrl['path'] ) ) {
return;
}
$sitemapUrl = trim( $sitemapUrl['path'], '/' );
if ( trim( $wp->request, '/' ) === $sitemapUrl ) {
$this->isDedicatedPage = true;
$this->generatePage();
}
}
/**
* Checks whether the current request is for our dedicated HTML sitemap page.
*
* @since 4.1.3
*
* @return void
*/
private function generatePage() {
global $wp_query, $wp, $post; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
$postId = -1337; // Set a negative ID to prevent conflicts with existing posts.
$sitemapUrl = aioseo()->options->sitemap->html->pageUrl;
$path = trim( wp_parse_url( $sitemapUrl )['path'], '/' );
$fakePost = new \stdClass();
$fakePost->ID = $postId;
$fakePost->post_author = 1;
$fakePost->post_date = current_time( 'mysql' );
$fakePost->post_date_gmt = current_time( 'mysql', 1 );
$fakePost->post_title = apply_filters( 'aioseo_html_sitemap_page_title', __( 'Sitemap', 'all-in-one-seo-pack' ) );
$fakePost->post_content = '[aioseo_html_sitemap archives=false]';
// We're using post instead of page to prevent calls to get_ancestors(), which will trigger errors.
// To loead the page template, we set is_page to true on the WP_Query object.
$fakePost->post_type = 'post';
$fakePost->post_status = 'publish';
$fakePost->comment_status = 'closed';
$fakePost->ping_status = 'closed';
$fakePost->post_name = $path;
$fakePost->filter = 'raw'; // Needed to prevent calls to the database when creating the WP_Post object.
$postObject = new \WP_Post( $fakePost );
$post = $postObject;
// We'll set as much properties on the WP_Query object as we can to prevent conflicts with other plugins/themes.
// phpcs:disable Squiz.NamingConventions.ValidVariableName
$wp_query->is_404 = false;
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->post = $postObject;
$wp_query->posts = [ $postObject ];
$wp_query->queried_object = $postObject;
$wp_query->queried_object_id = $postId;
$wp_query->found_posts = 1;
$wp_query->post_count = 1;
$wp_query->max_num_pages = 1;
unset( $wp_query->query['error'] );
$wp_query->query_vars['error'] = '';
// phpcs:enable Squiz.NamingConventions.ValidVariableName
// We need to add the post object to the cache so that get_post() calls don't trigger database calls.
wp_cache_add( $postId, $postObject, 'posts' );
$GLOBALS['wp_query'] = $wp_query; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
$wp->register_globals();
// Setting is_404 is not sufficient, so we still need to change the status code.
status_header( 200 );
}
/**
* Get the canonical URL for the dedicated HTML sitemap page.
*
* @since 4.5.7
*
* @param string $originalUrl The canonical URL.
* @return string The canonical URL.
*/
public function getCanonicalUrl( $originalUrl ) {
$sitemapOptions = aioseo()->options->sitemap->html;
if ( ! $sitemapOptions->enable || ! $this->isDedicatedPage ) {
return $originalUrl;
}
// If the user has set a custom URL for the sitemap page, use that.
if ( $sitemapOptions->pageUrl ) {
return $sitemapOptions->pageUrl;
}
// Return the current URL of WP.
global $wp;
return home_url( $wp->request );
}
}
}
namespace {
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'aioseo_html_sitemap' ) ) {
/**
* Global function that can be used to print the HTML sitemap.
*
* @since 4.1.3
*
* @param array $attributes User-defined attributes that override the default settings.
* @param boolean $echo Whether to echo the output or return it.
* @return string The HTML sitemap code.
*/
function aioseo_html_sitemap( $attributes = [], $echo = true ) {
$attributes = aioseo()->htmlSitemap->frontend->getAttributes( $attributes );
return aioseo()->htmlSitemap->frontend->output( $echo, $attributes );
}
}
} xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/ImportExport/SeoPress/Sitemap.php 0000644 00000003600 15114435240 0030102 0 ustar 00 home <?php
namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the Sitemap Settings.
*
* @since 4.1.4
*/
class Sitemap {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Class constructor.
*
* @since 4.1.4
*/
public function __construct() {
$this->options = get_option( 'seopress_xml_sitemap_option_name' );
if ( empty( $this->options ) ) {
return;
}
$this->migratePostTypesInclude();
$this->migrateTaxonomiesInclude();
$settings = [
'seopress_xml_sitemap_general_enable' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'enable' ] ],
'seopress_xml_sitemap_author_enable' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'author' ] ],
];
aioseo()->importExport->seoPress->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the post types to include in sitemap settings.
*
* @since 4.1.4
*
* @return void
*/
public function migratePostTypesInclude() {
$postTypesMigrate = $this->options['seopress_xml_sitemap_post_types_list'];
$postTypesInclude = [];
foreach ( $postTypesMigrate as $postType => $options ) {
$postTypesInclude[] = $postType;
}
aioseo()->options->sitemap->general->postTypes->included = $postTypesInclude;
}
/**
* Migrates the taxonomies to include in sitemap settings.
*
* @since 4.1.4
*
* @return void
*/
public function migrateTaxonomiesInclude() {
$taxonomiesMigrate = $this->options['seopress_xml_sitemap_taxonomies_list'];
$taxonomiesInclude = [];
foreach ( $taxonomiesMigrate as $taxonomy => $options ) {
$taxonomiesInclude[] = $taxonomy;
}
aioseo()->options->sitemap->general->taxonomies->included = $taxonomiesInclude;
}
} xbodynamge/namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/SearchStatistics/Sitemap.php 0000644 00000007546 15114436100 0030370 0 ustar 00 home <?php
namespace AIOSEO\Plugin\Common\SearchStatistics;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles the sitemaps for the search statistics.
*
* @since 4.6.2
*/
class Sitemap {
/**
* The action name.
*
* @since 4.6.2
*
* @var string
*/
public $action = 'aioseo_search_statistics_sitemap_sync';
/**
* Class constructor.
*
* @since 4.6.2
*/
public function __construct() {
add_action( 'admin_init', [ $this, 'init' ] );
add_action( $this->action, [ $this, 'worker' ] );
}
/**
* Initialize the class.
*
* @since 4.6.2
*
* @return void
*/
public function init() {
if (
! aioseo()->searchStatistics->api->auth->isConnected() ||
! aioseo()->internalOptions->searchStatistics->site->verified ||
aioseo()->actionScheduler->isScheduled( $this->action )
) {
return;
}
aioseo()->actionScheduler->scheduleAsync( $this->action );
}
/**
* Sync the sitemap.
*
* @since 4.6.3
*
* @return void
*/
public function worker() {
if ( ! $this->canSync() ) {
return;
}
$api = new Api\Request( 'google-search-console/sitemap/sync/', [ 'sitemaps' => aioseo()->sitemap->helpers->getSitemapUrls() ] );
$response = $api->request();
if ( is_wp_error( $response ) || empty( $response['data'] ) ) {
// If it failed to communicate with the server, try again in a few hours.
aioseo()->actionScheduler->scheduleSingle( $this->action, wp_rand( HOUR_IN_SECONDS, 2 * HOUR_IN_SECONDS ), [], true );
return;
}
aioseo()->internalOptions->searchStatistics->sitemap->list = $response['data'];
aioseo()->internalOptions->searchStatistics->sitemap->lastFetch = time();
// Schedule a new sync for the next week.
aioseo()->actionScheduler->scheduleSingle( $this->action, WEEK_IN_SECONDS + wp_rand( 0, 3 * DAY_IN_SECONDS ), [], true );
}
/**
* Maybe sync the sitemap after updating the options.
* It will check whether the sitemap options have changed and sync the sitemap if needed.
*
* @since 4.6.2
*
* @param array $oldSitemapOptions The old sitemap options.
* @param array $newSitemapOptions The new sitemap options.
*
* @return void
*/
public function maybeSync( $oldSitemapOptions, $newSitemapOptions ) {
if (
! $this->canSync() ||
empty( $oldSitemapOptions ) ||
empty( $newSitemapOptions )
) {
return;
}
// Ignore the HTML sitemap, since it's not actually a sitemap to be synced with Google.
unset( $newSitemapOptions['html'] );
$shouldResync = false;
foreach ( $newSitemapOptions as $type => $options ) {
if ( empty( $oldSitemapOptions[ $type ] ) ) {
continue;
}
if ( $oldSitemapOptions[ $type ]['enable'] !== $options['enable'] ) {
$shouldResync = true;
break;
}
}
if ( ! $shouldResync ) {
return;
}
aioseo()->actionScheduler->unschedule( $this->action );
aioseo()->actionScheduler->scheduleAsync( $this->action );
}
/**
* Get the sitemaps with errors.
*
* @since 4.6.2
*
* @return array
*/
public function getSitemapsWithErrors() {
$sitemaps = aioseo()->internalOptions->searchStatistics->sitemap->list;
$ignored = aioseo()->internalOptions->searchStatistics->sitemap->ignored;
if ( empty( $sitemaps ) ) {
return [];
}
$errors = [];
$pluginSitemaps = aioseo()->sitemap->helpers->getSitemapUrls();
foreach ( $sitemaps as $sitemap ) {
if (
empty( $sitemap['errors'] ) ||
in_array( $sitemap['path'], $ignored, true ) || // Skip user-ignored sitemaps.
in_array( $sitemap['path'], $pluginSitemaps, true ) // Skip plugin sitemaps.
) {
continue;
}
$errors[] = $sitemap;
}
return $errors;
}
/**
* Check if the sitemap can be synced.
*
* @since 4.6.2
*
* @return bool
*/
private function canSync() {
return aioseo()->searchStatistics->api->auth->isConnected() && aioseo()->internalOptions->searchStatistics->site->verified;
}
} xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/ImportExport/RankMath/Sitemap.php 0000644 00000011643 15114437667 0030071 0 ustar 00 home <?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the sitemap settings.
*
* @since 4.0.0
*/
class Sitemap {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->options = get_option( 'rank-math-options-sitemap' );
if ( empty( $this->options ) ) {
return;
}
$this->migrateIncludedObjects();
$this->migrateIncludeImages();
$this->migrateExcludedPosts();
$this->migrateExcludedTerms();
$settings = [
'items_per_page' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'linksPerIndex' ] ],
];
aioseo()->options->sitemap->general->indexes = true;
aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the included post types and taxonomies.
*
* @since 4.0.0
*
* @return void
*/
private function migrateIncludedObjects() {
$includedPostTypes = [];
$includedTaxonomies = [];
$allowedPostTypes = array_values( array_diff( aioseo()->helpers->getPublicPostTypes( true ), aioseo()->helpers->getNoindexedPostTypes() ) );
foreach ( $allowedPostTypes as $postType ) {
foreach ( $this->options as $name => $value ) {
if ( preg_match( "#pt_{$postType}_sitemap$#", (string) $name, $match ) && 'on' === $this->options[ $name ] ) {
$includedPostTypes[] = $postType;
}
}
}
$allowedTaxonomies = array_values( array_diff( aioseo()->helpers->getPublicTaxonomies( true ), aioseo()->helpers->getNoindexedTaxonomies() ) );
foreach ( $allowedTaxonomies as $taxonomy ) {
foreach ( $this->options as $name => $value ) {
if ( preg_match( "#tax_{$taxonomy}_sitemap$#", (string) $name, $match ) && 'on' === $this->options[ $name ] ) {
$includedTaxonomies[] = $taxonomy;
}
}
}
aioseo()->options->sitemap->general->postTypes->included = $includedPostTypes;
if ( count( $allowedPostTypes ) !== count( $includedPostTypes ) ) {
aioseo()->options->sitemap->general->postTypes->all = false;
}
aioseo()->options->sitemap->general->taxonomies->included = $includedTaxonomies;
if ( count( $allowedTaxonomies ) !== count( $includedTaxonomies ) ) {
aioseo()->options->sitemap->general->taxonomies->all = false;
}
}
/**
* Migrates the Redirect Attachments setting.
*
* @since 4.0.0
*
* @return void
*/
private function migrateIncludeImages() {
if ( ! empty( $this->options['include_images'] ) ) {
if ( 'off' === $this->options['include_images'] ) {
aioseo()->options->sitemap->general->advancedSettings->enable = true;
aioseo()->options->sitemap->general->advancedSettings->excludeImages = true;
}
}
}
/**
* Migrates the posts that are excluded from the sitemap.
*
* @since 4.0.0
*
* @return void
*/
private function migrateExcludedPosts() {
if ( empty( $this->options['exclude_posts'] ) ) {
return;
}
$rmExcludedPosts = array_filter( explode( ',', $this->options['exclude_posts'] ) );
$excludedPosts = aioseo()->options->sitemap->general->advancedSettings->excludePosts;
if ( count( $rmExcludedPosts ) ) {
foreach ( $rmExcludedPosts as $rmExcludedPost ) {
$post = get_post( trim( $rmExcludedPost ) );
if ( ! is_object( $post ) ) {
continue;
}
$excludedPost = new \stdClass();
$excludedPost->value = $post->ID;
$excludedPost->type = $post->post_type;
$excludedPost->label = $post->post_title;
$excludedPost->link = get_permalink( $post->ID );
array_push( $excludedPosts, wp_json_encode( $excludedPost ) );
}
aioseo()->options->sitemap->general->advancedSettings->enable = true;
}
aioseo()->options->sitemap->general->advancedSettings->excludePosts = $excludedPosts;
}
/**
* Migrates the terms that are excluded from the sitemap.
*
* @since 4.0.0
*
* @return void
*/
private function migrateExcludedTerms() {
if ( empty( $this->options['exclude_terms'] ) ) {
return;
}
$rmExcludedTerms = array_filter( explode( ',', $this->options['exclude_terms'] ) );
$excludedTerms = aioseo()->options->sitemap->general->advancedSettings->excludeTerms;
if ( count( $rmExcludedTerms ) ) {
foreach ( $rmExcludedTerms as $rmExcludedTerm ) {
$term = get_term( trim( $rmExcludedTerm ) );
if ( ! is_object( $term ) ) {
continue;
}
$excludedTerm = new \stdClass();
$excludedTerm->value = $term->term_id;
$excludedTerm->type = $term->taxonomy;
$excludedTerm->label = $term->name;
$excludedTerm->link = get_term_link( $term );
array_push( $excludedTerms, wp_json_encode( $excludedTerm ) );
}
aioseo()->options->sitemap->general->advancedSettings->enable = true;
}
aioseo()->options->sitemap->general->advancedSettings->excludeTerms = $excludedTerms;
}
} home/xbodynamge/namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/Sitemap/Sitemap.php 0000644 00000025377 15114446233 0026603 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Sitemap;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
/**
* Handles our sitemaps.
*
* @since 4.0.0
*/
class Sitemap extends SitemapAbstract {
/**
* The sitemap filename.
*
* @since 4.4.2
*
* @var string
*/
public $filename = '';
/**
* Whether the sitemap indexes are enabled.
*
* @since 4.4.2
*
* @var bool
*/
public $indexes = false;
/**
* The sitemap index name.
*
* @since 4.4.2
*
* @var string
*/
public $indexName = '';
/**
* The number of links per index.
*
* @since 4.4.2
*
* @var int
*/
public $linksPerIndex = 1000;
/**
* The current page number.
*
* @since 4.4.2
*
* @var int
*/
public $pageNumber = 0;
/**
* The entries' offset.
*
* @since 4.4.2
*
* @var int
*/
public $offset = 0;
/**
* Whether the sitemap is static.
*
* @since 4.4.2
*
* @var bool
*/
public $isStatic = false;
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->content = new Content();
$this->root = new Root();
$this->query = new Query();
$this->file = new File();
$this->image = new Image\Image();
$this->priority = new Priority();
$this->output = new Output();
$this->helpers = new Helpers();
$this->requestParser = new RequestParser();
$this->xsl = new Xsl();
new Localization();
$this->disableWpSitemap();
}
/**
* Adds our hooks.
* Note: This runs init and is triggered in the main AIOSEO class.
*
* @since 4.0.0
*
* @return void
*/
public function init() {
add_action( 'aioseo_static_sitemap_regeneration', [ $this, 'regenerateStaticSitemap' ] );
// Check if static files need to be updated.
add_action( 'wp_insert_post', [ $this, 'regenerateOnUpdate' ] );
add_action( 'edited_term', [ $this, 'regenerateStaticSitemap' ] );
add_action( 'admin_init', [ $this, 'detectStatic' ] );
$this->maybeAddHtaccessRewriteRules();
}
/**
* Disables the WP Core sitemap if our general sitemap is enabled.
*
* @since 4.2.1
*
* @return void
*/
protected function disableWpSitemap() {
if ( ! aioseo()->options->sitemap->general->enable ) {
return;
}
remove_action( 'init', 'wp_sitemaps_get_server' );
add_filter( 'wp_sitemaps_enabled', '__return_false' );
}
/**
* Check if the .htaccess rewrite rules are present if the user is using Apache. If not, add them.
*
* @since 4.2.5
*
* @return void
*/
private function maybeAddHtaccessRewriteRules() {
if ( ! aioseo()->helpers->isApache() || wp_doing_ajax() || wp_doing_cron() ) {
return;
}
ob_start();
aioseo()->templates->getTemplate( 'sitemap/htaccess-rewrite-rules.php' );
$rewriteRules = ob_get_clean();
$escapedRewriteRules = aioseo()->helpers->escapeRegex( $rewriteRules );
$contents = aioseo()->helpers->decodeHtmlEntities( aioseo()->htaccess->getContents() );
if ( get_option( 'permalink_structure' ) ) {
if ( preg_match( '/All in One SEO Sitemap Rewrite Rules/i', (string) $contents ) && ! aioseo()->core->cache->get( 'aioseo_sitemap_htaccess_rewrite_rules_remove' ) ) {
aioseo()->core->cache->update( 'aioseo_sitemap_htaccess_rewrite_rules_remove', time(), HOUR_IN_SECONDS );
$contents = preg_replace( "/$escapedRewriteRules/i", '', (string) $contents );
aioseo()->htaccess->saveContents( $contents );
}
return;
}
if ( preg_match( '/All in One SEO Sitemap Rewrite Rules/i', (string) $contents ) || aioseo()->core->cache->get( 'aioseo_sitemap_htaccess_rewrite_rules_add' ) ) {
return;
}
aioseo()->core->cache->update( 'aioseo_sitemap_htaccess_rewrite_rules_add', time(), HOUR_IN_SECONDS );
$contents .= $rewriteRules;
aioseo()->htaccess->saveContents( $contents );
}
/**
* Checks if static sitemap files prevent dynamic sitemap generation.
*
* @since 4.0.0
*
* @return void
*/
public function detectStatic() {
$isGeneralSitemapStatic = aioseo()->options->sitemap->general->advancedSettings->enable &&
in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) &&
! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic;
if ( $isGeneralSitemapStatic ) {
Models\Notification::deleteNotificationByName( 'sitemap-static-files' );
return;
}
require_once ABSPATH . 'wp-admin/includes/file.php';
$files = list_files( get_home_path(), 1 );
if ( ! count( $files ) ) {
return;
}
$detectedFiles = [];
if ( ! $isGeneralSitemapStatic ) {
foreach ( $files as $filename ) {
if ( preg_match( '#.*sitemap.*#', (string) $filename ) ) {
// We don't want to delete the video sitemap here at all.
$isVideoSitemap = preg_match( '#.*video.*#', (string) $filename ) ? true : false;
if ( ! $isVideoSitemap ) {
$detectedFiles[] = $filename;
}
}
}
}
$this->maybeShowStaticSitemapNotification( $detectedFiles );
}
/**
* If there are files, show a notice, otherwise delete it.
*
* @since 4.0.0
*
* @param array $detectedFiles An array of detected files.
* @return void
*/
protected function maybeShowStaticSitemapNotification( $detectedFiles ) {
if ( ! count( $detectedFiles ) ) {
Models\Notification::deleteNotificationByName( 'sitemap-static-files' );
return;
}
$notification = Models\Notification::getNotificationByName( 'sitemap-static-files' );
if ( $notification->notification_name ) {
return;
}
Models\Notification::addNotification( [
'slug' => uniqid(),
'notification_name' => 'sitemap-static-files',
'title' => __( 'Static sitemap files detected', 'all-in-one-seo-pack' ),
'content' => sprintf(
// Translators: 1 - The plugin short name ("AIOSEO"), 2 - Same as previous.
__( '%1$s has detected static sitemap files in the root folder of your WordPress installation.
As long as these files are present, %2$s is not able to dynamically generate your sitemap.', 'all-in-one-seo-pack' ),
AIOSEO_PLUGIN_SHORT_NAME,
AIOSEO_PLUGIN_SHORT_NAME
),
'type' => 'error',
'level' => [ 'all' ],
'button1_label' => __( 'Delete Static Files', 'all-in-one-seo-pack' ),
'button1_action' => 'http://action#sitemap/delete-static-files',
'start' => gmdate( 'Y-m-d H:i:s' )
] );
}
/**
* Regenerates the static sitemap files when a post is updated.
*
* @since 4.0.0
*
* @param integer $postId The post ID.
* @return void
*/
public function regenerateOnUpdate( $postId ) {
if ( aioseo()->helpers->isValidPost( $postId ) ) {
$this->scheduleRegeneration();
}
}
/**
* Schedules an action to regenerate the static sitemap files.
*
* @since 4.0.5
*
* @return void
*/
public function scheduleRegeneration() {
try {
if (
! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic &&
! as_next_scheduled_action( 'aioseo_static_sitemap_regeneration' )
) {
as_schedule_single_action( time() + 60, 'aioseo_static_sitemap_regeneration', [], 'aioseo' );
}
} catch ( \Exception $e ) {
// Do nothing.
}
}
/**
* Regenerates the static sitemap files.
*
* @since 4.0.5
*
* @return void
*/
public function regenerateStaticSitemap() {
aioseo()->sitemap->file->generate();
}
/**
* Generates the requested sitemap.
*
* @since 4.0.0
*
* @return void
*/
public function generate() {
if ( empty( $this->type ) ) {
return;
}
// This is a hack to prevent WordPress from running it's default stuff during our processing.
global $wp_query; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
$wp_query->is_home = false; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
// This prevents the sitemap from including terms twice when WPML is active.
if ( class_exists( 'SitePress' ) ) {
global $sitepress_settings; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
// Before building the sitemap make sure links aren't translated.
// The setting should not be updated in the DB.
$sitepress_settings['auto_adjust_ids'] = 0; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
}
// If requested sitemap should be static and doesn't exist, then generate it.
// We'll then serve it dynamically for the current request so that we don't serve a blank page.
$this->doesFileExist();
$options = aioseo()->options->noConflict();
if ( ! $options->sitemap->{aioseo()->sitemap->type}->enable ) {
aioseo()->helpers->notFoundPage();
return;
}
$entries = aioseo()->sitemap->content->get();
$total = aioseo()->sitemap->content->getTotal();
if ( ! $entries ) {
$addonsEntries = aioseo()->addons->doAddonFunction( 'content', 'get' );
$addonTotals = aioseo()->addons->doAddonFunction( 'content', 'getTotal' );
foreach ( $addonsEntries as $addonSlug => $addonEntries ) {
if ( ! empty( $addonEntries ) ) {
$entries = $addonEntries;
$total = ! empty( $addonTotals[ $addonSlug ] ) ? $addonTotals[ $addonSlug ] : count( $entries );
break;
}
}
}
if ( 0 === $total && empty( $entries ) ) {
status_header( 404 );
}
$this->xsl->saveXslData(
aioseo()->sitemap->requestParser->slug,
$entries,
$total
);
$this->headers();
aioseo()->sitemap->output->output( $entries );
aioseo()->addons->doAddonFunction( 'output', 'output', [ $entries ] );
exit;
}
/**
* Checks if static file should be served and generates it if it doesn't exist.
*
* This essentially acts as a safety net in case a file doesn't exist yet or has been deleted.
*
* @since 4.0.0
*
* @return void
*/
protected function doesFileExist() {
aioseo()->addons->doAddonFunction( 'sitemap', 'doesFileExist' );
if (
'general' !== $this->type ||
! aioseo()->options->sitemap->general->advancedSettings->enable ||
! in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) ||
aioseo()->options->sitemap->general->advancedSettings->dynamic
) {
return;
}
require_once ABSPATH . 'wp-admin/includes/file.php';
if ( isset( $_SERVER['REQUEST_URI'] ) && ! aioseo()->core->fs->exists( get_home_path() . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ) {
$this->scheduleRegeneration();
}
}
/**
* Sets the HTTP headers for the sitemap.
*
* @since 4.0.0
*
* @return void
*/
public function headers() {
$charset = aioseo()->helpers->getCharset();
header( "Content-Type: text/xml; charset=$charset", true );
header( 'X-Robots-Tag: noindex, follow', true );
}
/**
* Registers an active sitemap addon and its classes.
* NOTE: This is deprecated and only there for users who already were using the previous sitemap addons version.
*
* @final 4.2.7
* @since 4.0.0
*
* @return void
*/
public function addAddon() {}
} home/xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/Sitemap/Sitemap.php 0000644 00000025377 15114517132 0025364 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Sitemap;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
/**
* Handles our sitemaps.
*
* @since 4.0.0
*/
class Sitemap extends SitemapAbstract {
/**
* The sitemap filename.
*
* @since 4.4.2
*
* @var string
*/
public $filename = '';
/**
* Whether the sitemap indexes are enabled.
*
* @since 4.4.2
*
* @var bool
*/
public $indexes = false;
/**
* The sitemap index name.
*
* @since 4.4.2
*
* @var string
*/
public $indexName = '';
/**
* The number of links per index.
*
* @since 4.4.2
*
* @var int
*/
public $linksPerIndex = 1000;
/**
* The current page number.
*
* @since 4.4.2
*
* @var int
*/
public $pageNumber = 0;
/**
* The entries' offset.
*
* @since 4.4.2
*
* @var int
*/
public $offset = 0;
/**
* Whether the sitemap is static.
*
* @since 4.4.2
*
* @var bool
*/
public $isStatic = false;
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->content = new Content();
$this->root = new Root();
$this->query = new Query();
$this->file = new File();
$this->image = new Image\Image();
$this->priority = new Priority();
$this->output = new Output();
$this->helpers = new Helpers();
$this->requestParser = new RequestParser();
$this->xsl = new Xsl();
new Localization();
$this->disableWpSitemap();
}
/**
* Adds our hooks.
* Note: This runs init and is triggered in the main AIOSEO class.
*
* @since 4.0.0
*
* @return void
*/
public function init() {
add_action( 'aioseo_static_sitemap_regeneration', [ $this, 'regenerateStaticSitemap' ] );
// Check if static files need to be updated.
add_action( 'wp_insert_post', [ $this, 'regenerateOnUpdate' ] );
add_action( 'edited_term', [ $this, 'regenerateStaticSitemap' ] );
add_action( 'admin_init', [ $this, 'detectStatic' ] );
$this->maybeAddHtaccessRewriteRules();
}
/**
* Disables the WP Core sitemap if our general sitemap is enabled.
*
* @since 4.2.1
*
* @return void
*/
protected function disableWpSitemap() {
if ( ! aioseo()->options->sitemap->general->enable ) {
return;
}
remove_action( 'init', 'wp_sitemaps_get_server' );
add_filter( 'wp_sitemaps_enabled', '__return_false' );
}
/**
* Check if the .htaccess rewrite rules are present if the user is using Apache. If not, add them.
*
* @since 4.2.5
*
* @return void
*/
private function maybeAddHtaccessRewriteRules() {
if ( ! aioseo()->helpers->isApache() || wp_doing_ajax() || wp_doing_cron() ) {
return;
}
ob_start();
aioseo()->templates->getTemplate( 'sitemap/htaccess-rewrite-rules.php' );
$rewriteRules = ob_get_clean();
$escapedRewriteRules = aioseo()->helpers->escapeRegex( $rewriteRules );
$contents = aioseo()->helpers->decodeHtmlEntities( aioseo()->htaccess->getContents() );
if ( get_option( 'permalink_structure' ) ) {
if ( preg_match( '/All in One SEO Sitemap Rewrite Rules/i', (string) $contents ) && ! aioseo()->core->cache->get( 'aioseo_sitemap_htaccess_rewrite_rules_remove' ) ) {
aioseo()->core->cache->update( 'aioseo_sitemap_htaccess_rewrite_rules_remove', time(), HOUR_IN_SECONDS );
$contents = preg_replace( "/$escapedRewriteRules/i", '', (string) $contents );
aioseo()->htaccess->saveContents( $contents );
}
return;
}
if ( preg_match( '/All in One SEO Sitemap Rewrite Rules/i', (string) $contents ) || aioseo()->core->cache->get( 'aioseo_sitemap_htaccess_rewrite_rules_add' ) ) {
return;
}
aioseo()->core->cache->update( 'aioseo_sitemap_htaccess_rewrite_rules_add', time(), HOUR_IN_SECONDS );
$contents .= $rewriteRules;
aioseo()->htaccess->saveContents( $contents );
}
/**
* Checks if static sitemap files prevent dynamic sitemap generation.
*
* @since 4.0.0
*
* @return void
*/
public function detectStatic() {
$isGeneralSitemapStatic = aioseo()->options->sitemap->general->advancedSettings->enable &&
in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) &&
! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic;
if ( $isGeneralSitemapStatic ) {
Models\Notification::deleteNotificationByName( 'sitemap-static-files' );
return;
}
require_once ABSPATH . 'wp-admin/includes/file.php';
$files = list_files( get_home_path(), 1 );
if ( ! count( $files ) ) {
return;
}
$detectedFiles = [];
if ( ! $isGeneralSitemapStatic ) {
foreach ( $files as $filename ) {
if ( preg_match( '#.*sitemap.*#', (string) $filename ) ) {
// We don't want to delete the video sitemap here at all.
$isVideoSitemap = preg_match( '#.*video.*#', (string) $filename ) ? true : false;
if ( ! $isVideoSitemap ) {
$detectedFiles[] = $filename;
}
}
}
}
$this->maybeShowStaticSitemapNotification( $detectedFiles );
}
/**
* If there are files, show a notice, otherwise delete it.
*
* @since 4.0.0
*
* @param array $detectedFiles An array of detected files.
* @return void
*/
protected function maybeShowStaticSitemapNotification( $detectedFiles ) {
if ( ! count( $detectedFiles ) ) {
Models\Notification::deleteNotificationByName( 'sitemap-static-files' );
return;
}
$notification = Models\Notification::getNotificationByName( 'sitemap-static-files' );
if ( $notification->notification_name ) {
return;
}
Models\Notification::addNotification( [
'slug' => uniqid(),
'notification_name' => 'sitemap-static-files',
'title' => __( 'Static sitemap files detected', 'all-in-one-seo-pack' ),
'content' => sprintf(
// Translators: 1 - The plugin short name ("AIOSEO"), 2 - Same as previous.
__( '%1$s has detected static sitemap files in the root folder of your WordPress installation.
As long as these files are present, %2$s is not able to dynamically generate your sitemap.', 'all-in-one-seo-pack' ),
AIOSEO_PLUGIN_SHORT_NAME,
AIOSEO_PLUGIN_SHORT_NAME
),
'type' => 'error',
'level' => [ 'all' ],
'button1_label' => __( 'Delete Static Files', 'all-in-one-seo-pack' ),
'button1_action' => 'http://action#sitemap/delete-static-files',
'start' => gmdate( 'Y-m-d H:i:s' )
] );
}
/**
* Regenerates the static sitemap files when a post is updated.
*
* @since 4.0.0
*
* @param integer $postId The post ID.
* @return void
*/
public function regenerateOnUpdate( $postId ) {
if ( aioseo()->helpers->isValidPost( $postId ) ) {
$this->scheduleRegeneration();
}
}
/**
* Schedules an action to regenerate the static sitemap files.
*
* @since 4.0.5
*
* @return void
*/
public function scheduleRegeneration() {
try {
if (
! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic &&
! as_next_scheduled_action( 'aioseo_static_sitemap_regeneration' )
) {
as_schedule_single_action( time() + 60, 'aioseo_static_sitemap_regeneration', [], 'aioseo' );
}
} catch ( \Exception $e ) {
// Do nothing.
}
}
/**
* Regenerates the static sitemap files.
*
* @since 4.0.5
*
* @return void
*/
public function regenerateStaticSitemap() {
aioseo()->sitemap->file->generate();
}
/**
* Generates the requested sitemap.
*
* @since 4.0.0
*
* @return void
*/
public function generate() {
if ( empty( $this->type ) ) {
return;
}
// This is a hack to prevent WordPress from running it's default stuff during our processing.
global $wp_query; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
$wp_query->is_home = false; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
// This prevents the sitemap from including terms twice when WPML is active.
if ( class_exists( 'SitePress' ) ) {
global $sitepress_settings; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
// Before building the sitemap make sure links aren't translated.
// The setting should not be updated in the DB.
$sitepress_settings['auto_adjust_ids'] = 0; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
}
// If requested sitemap should be static and doesn't exist, then generate it.
// We'll then serve it dynamically for the current request so that we don't serve a blank page.
$this->doesFileExist();
$options = aioseo()->options->noConflict();
if ( ! $options->sitemap->{aioseo()->sitemap->type}->enable ) {
aioseo()->helpers->notFoundPage();
return;
}
$entries = aioseo()->sitemap->content->get();
$total = aioseo()->sitemap->content->getTotal();
if ( ! $entries ) {
$addonsEntries = aioseo()->addons->doAddonFunction( 'content', 'get' );
$addonTotals = aioseo()->addons->doAddonFunction( 'content', 'getTotal' );
foreach ( $addonsEntries as $addonSlug => $addonEntries ) {
if ( ! empty( $addonEntries ) ) {
$entries = $addonEntries;
$total = ! empty( $addonTotals[ $addonSlug ] ) ? $addonTotals[ $addonSlug ] : count( $entries );
break;
}
}
}
if ( 0 === $total && empty( $entries ) ) {
status_header( 404 );
}
$this->xsl->saveXslData(
aioseo()->sitemap->requestParser->slug,
$entries,
$total
);
$this->headers();
aioseo()->sitemap->output->output( $entries );
aioseo()->addons->doAddonFunction( 'output', 'output', [ $entries ] );
exit;
}
/**
* Checks if static file should be served and generates it if it doesn't exist.
*
* This essentially acts as a safety net in case a file doesn't exist yet or has been deleted.
*
* @since 4.0.0
*
* @return void
*/
protected function doesFileExist() {
aioseo()->addons->doAddonFunction( 'sitemap', 'doesFileExist' );
if (
'general' !== $this->type ||
! aioseo()->options->sitemap->general->advancedSettings->enable ||
! in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) ||
aioseo()->options->sitemap->general->advancedSettings->dynamic
) {
return;
}
require_once ABSPATH . 'wp-admin/includes/file.php';
if ( isset( $_SERVER['REQUEST_URI'] ) && ! aioseo()->core->fs->exists( get_home_path() . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ) {
$this->scheduleRegeneration();
}
}
/**
* Sets the HTTP headers for the sitemap.
*
* @since 4.0.0
*
* @return void
*/
public function headers() {
$charset = aioseo()->helpers->getCharset();
header( "Content-Type: text/xml; charset=$charset", true );
header( 'X-Robots-Tag: noindex, follow', true );
}
/**
* Registers an active sitemap addon and its classes.
* NOTE: This is deprecated and only there for users who already were using the previous sitemap addons version.
*
* @final 4.2.7
* @since 4.0.0
*
* @return void
*/
public function addAddon() {}
} xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/Standalone/BuddyPress/Sitemap.php 0000644 00000015654 15114546261 0030061 0 ustar 00 home <?php
namespace AIOSEO\Plugin\Common\Standalone\BuddyPress;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Integrations\BuddyPress as BuddyPressIntegration;
/**
* BuddyPress Sitemap class.
*
* @since 4.7.6
*/
class Sitemap {
/**
* Returns the indexes for the sitemap root index.
*
* @since 4.7.6
*
* @return array The indexes.
*/
public function indexes() {
$indexes = [];
$includedPostTypes = array_flip( aioseo()->sitemap->helpers->includedPostTypes() );
$filterPostTypes = array_filter( [
BuddyPressIntegration::isComponentActive( 'activity' ) && isset( $includedPostTypes['bp-activity'] ) ? 'bp-activity' : '',
BuddyPressIntegration::isComponentActive( 'group' ) && isset( $includedPostTypes['bp-group'] ) ? 'bp-group' : '',
BuddyPressIntegration::isComponentActive( 'member' ) && isset( $includedPostTypes['bp-member'] ) ? 'bp-member' : '',
] );
foreach ( $filterPostTypes as $postType ) {
$indexes = array_merge( $indexes, $this->buildIndexesPostType( $postType ) );
}
return $indexes;
}
/**
* Builds BuddyPress related root indexes.
*
* @since 4.7.6
*
* @param string $postType The BuddyPress fake post type.
* @return array The BuddyPress related root indexes.
*/
private function buildIndexesPostType( $postType ) {
switch ( $postType ) {
case 'bp-activity':
return $this->buildIndexesActivity();
case 'bp-group':
return $this->buildIndexesGroup();
case 'bp-member':
return $this->buildIndexesMember();
default:
return [];
}
}
/**
* Builds activity root indexes.
*
* @since 4.7.6
*
* @return array The activity root indexes.
*/
private function buildIndexesActivity() {
$activityTable = aioseo()->core->db->prefix . 'bp_activity';
$linksPerIndex = aioseo()->sitemap->linksPerIndex;
$items = aioseo()->core->db->execute(
aioseo()->core->db->db->prepare(
"SELECT id, date_recorded
FROM (
SELECT @row := @row + 1 AS rownum, id, date_recorded
FROM (
SELECT a.id, a.date_recorded FROM $activityTable as a
WHERE a.is_spam = 0
AND a.hide_sitewide = 0
AND a.type NOT IN ('activity_comment', 'last_activity')
ORDER BY a.date_recorded DESC
) AS x
CROSS JOIN (SELECT @row := 0) AS vars
ORDER BY date_recorded DESC
) AS y
WHERE rownum = 1 OR rownum % %d = 1;",
[
$linksPerIndex
]
),
true
)->result();
$totalItems = aioseo()->core->db->execute(
"SELECT COUNT(*) as count
FROM $activityTable as a
WHERE a.is_spam = 0
AND a.hide_sitewide = 0
AND a.type NOT IN ('activity_comment', 'last_activity')
",
true
)->result();
$indexes = [];
if ( $items ) {
$filename = aioseo()->sitemap->filename;
$count = count( $items );
for ( $i = 0; $i < $count; $i++ ) {
$indexNumber = 0 !== $i && 1 < $count ? $i + 1 : '';
$indexes[] = [
'loc' => aioseo()->helpers->localizedUrl( "/bp-activity-$filename$indexNumber.xml" ),
'lastmod' => aioseo()->helpers->dateTimeToIso8601( $items[ $i ]->date_recorded ),
'count' => $linksPerIndex
];
}
// We need to update the count of the last index since it won't necessarily be the same as the links per index.
$indexes[ count( $indexes ) - 1 ]['count'] = $totalItems[0]->count - ( $linksPerIndex * ( $count - 1 ) );
}
return $indexes;
}
/**
* Builds group root indexes.
*
* @since 4.7.6
*
* @return array The group root indexes.
*/
private function buildIndexesGroup() {
$groupsTable = aioseo()->core->db->prefix . 'bp_groups';
$groupsMetaTable = aioseo()->core->db->prefix . 'bp_groups_groupmeta';
$linksPerIndex = aioseo()->sitemap->linksPerIndex;
$items = aioseo()->core->db->execute(
aioseo()->core->db->db->prepare(
"SELECT id, date_modified
FROM (
SELECT @row := @row + 1 AS rownum, id, date_modified
FROM (
SELECT g.id, gm.group_id, MAX(gm.meta_value) as date_modified FROM $groupsTable as g
INNER JOIN $groupsMetaTable AS gm ON g.id = gm.group_id
WHERE g.status = 'public'
AND gm.meta_key = 'last_activity'
GROUP BY g.id
ORDER BY date_modified DESC
) AS x
CROSS JOIN (SELECT @row := 0) AS vars
ORDER BY date_modified DESC
) AS y
WHERE rownum = 1 OR rownum % %d = 1;",
[
$linksPerIndex
]
),
true
)->result();
$totalItems = aioseo()->core->db->execute(
"SELECT COUNT(*) as count
FROM $groupsTable as g
WHERE g.status = 'public'
",
true
)->result();
$indexes = [];
if ( $items ) {
$filename = aioseo()->sitemap->filename;
$count = count( $items );
for ( $i = 0; $i < $count; $i++ ) {
$indexNumber = 0 !== $i && 1 < $count ? $i + 1 : '';
$indexes[] = [
'loc' => aioseo()->helpers->localizedUrl( "/bp-group-$filename$indexNumber.xml" ),
'lastmod' => aioseo()->helpers->dateTimeToIso8601( $items[ $i ]->date_modified ),
'count' => $linksPerIndex
];
}
// We need to update the count of the last index since it won't necessarily be the same as the links per index.
$indexes[ count( $indexes ) - 1 ]['count'] = $totalItems[0]->count - ( $linksPerIndex * ( $count - 1 ) );
}
return $indexes;
}
/**
* Builds member root indexes.
*
* @since 4.7.6
*
* @return array The member root indexes.
*/
private function buildIndexesMember() {
$activityTable = aioseo()->core->db->prefix . 'bp_activity';
$linksPerIndex = aioseo()->sitemap->linksPerIndex;
$items = aioseo()->core->db->execute(
aioseo()->core->db->db->prepare(
"SELECT user_id, date_recorded
FROM (
SELECT @row := @row + 1 AS rownum, user_id, date_recorded
FROM (
SELECT a.user_id, a.date_recorded FROM $activityTable as a
WHERE a.component = 'members'
AND a.type = 'last_activity'
ORDER BY a.date_recorded DESC
) AS x
CROSS JOIN (SELECT @row := 0) AS vars
ORDER BY date_recorded DESC
) AS y
WHERE rownum = 1 OR rownum % %d = 1;",
[
$linksPerIndex
]
),
true
)->result();
$totalItems = aioseo()->core->db->execute(
"SELECT COUNT(*) as count
FROM $activityTable as a
WHERE a.component = 'members'
AND a.type = 'last_activity'
",
true
)->result();
$indexes = [];
if ( $items ) {
$filename = aioseo()->sitemap->filename;
$count = count( $items );
for ( $i = 0; $i < $count; $i++ ) {
$indexNumber = 0 !== $i && 1 < $count ? $i + 1 : '';
$indexes[] = [
'loc' => aioseo()->helpers->localizedUrl( "/bp-member-$filename$indexNumber.xml" ),
'lastmod' => aioseo()->helpers->dateTimeToIso8601( $items[ $i ]->date_recorded ),
'count' => $linksPerIndex
];
}
// We need to update the count of the last index since it won't necessarily be the same as the links per index.
$indexes[ count( $indexes ) - 1 ]['count'] = $totalItems[0]->count - ( $linksPerIndex * ( $count - 1 ) );
}
return $indexes;
}
} home/xbodynamge/namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/Sitemap/Html/Sitemap.php0000644 00000014025 15115037501 0027466 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Sitemap\Html {
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Main class for the HTML sitemap.
*
* @since 4.1.3
*/
class Sitemap {
/** Instance of the frontend class.
*
* @since 4.1.3
*
* @var Frontend
*/
public $frontend;
/**
* Instance of the shortcode class.
*
* @since 4.1.3
*
* @var Shortcode
*/
public $shortcode;
/**
* Instance of the block class.
*
* @since 4.1.3
*
* @var Block
*/
public $block;
/**
* Whether the current queried page is the dedicated sitemap page.
*
* @since 4.1.3
*
* @var bool
*/
public $isDedicatedPage = false;
/**
* Class constructor.
*
* @since 4.1.3
*/
public function __construct() {
$this->frontend = new Frontend();
$this->shortcode = new Shortcode();
$this->block = new Block();
add_action( 'widgets_init', [ $this, 'registerWidget' ] );
add_filter( 'aioseo_canonical_url', [ $this, 'getCanonicalUrl' ] );
if ( ! is_admin() || wp_doing_ajax() || wp_doing_cron() ) {
add_action( 'template_redirect', [ $this, 'checkForDedicatedPage' ] );
}
}
/**
* Register our HTML sitemap widget.
*
* @since 4.1.3
*
* @return void
*/
public function registerWidget() {
if ( aioseo()->helpers->canRegisterLegacyWidget( 'aioseo-html-sitemap-widget' ) ) {
register_widget( 'AIOSEO\Plugin\Common\Sitemap\Html\Widget' );
}
}
/**
* Checks whether the current request is for our dedicated HTML sitemap page.
*
* @since 4.1.3
*
* @return void
*/
public function checkForDedicatedPage() {
if ( ! aioseo()->options->sitemap->html->enable ) {
return;
}
global $wp;
$sitemapUrl = aioseo()->options->sitemap->html->pageUrl;
if ( ! $sitemapUrl || empty( $wp->request ) ) {
return;
}
$sitemapUrl = wp_parse_url( $sitemapUrl );
if ( empty( $sitemapUrl['path'] ) ) {
return;
}
$sitemapUrl = trim( $sitemapUrl['path'], '/' );
if ( trim( $wp->request, '/' ) === $sitemapUrl ) {
$this->isDedicatedPage = true;
$this->generatePage();
}
}
/**
* Checks whether the current request is for our dedicated HTML sitemap page.
*
* @since 4.1.3
*
* @return void
*/
private function generatePage() {
global $wp_query, $wp, $post; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
$postId = -1337; // Set a negative ID to prevent conflicts with existing posts.
$sitemapUrl = aioseo()->options->sitemap->html->pageUrl;
$path = trim( wp_parse_url( $sitemapUrl )['path'], '/' );
$fakePost = new \stdClass();
$fakePost->ID = $postId;
$fakePost->post_author = 1;
$fakePost->post_date = current_time( 'mysql' );
$fakePost->post_date_gmt = current_time( 'mysql', 1 );
$fakePost->post_title = apply_filters( 'aioseo_html_sitemap_page_title', __( 'Sitemap', 'all-in-one-seo-pack' ) );
$fakePost->post_content = '[aioseo_html_sitemap archives=false]';
// We're using post instead of page to prevent calls to get_ancestors(), which will trigger errors.
// To loead the page template, we set is_page to true on the WP_Query object.
$fakePost->post_type = 'post';
$fakePost->post_status = 'publish';
$fakePost->comment_status = 'closed';
$fakePost->ping_status = 'closed';
$fakePost->post_name = $path;
$fakePost->filter = 'raw'; // Needed to prevent calls to the database when creating the WP_Post object.
$postObject = new \WP_Post( $fakePost );
$post = $postObject;
// We'll set as much properties on the WP_Query object as we can to prevent conflicts with other plugins/themes.
// phpcs:disable Squiz.NamingConventions.ValidVariableName
$wp_query->is_404 = false;
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->post = $postObject;
$wp_query->posts = [ $postObject ];
$wp_query->queried_object = $postObject;
$wp_query->queried_object_id = $postId;
$wp_query->found_posts = 1;
$wp_query->post_count = 1;
$wp_query->max_num_pages = 1;
unset( $wp_query->query['error'] );
$wp_query->query_vars['error'] = '';
// phpcs:enable Squiz.NamingConventions.ValidVariableName
// We need to add the post object to the cache so that get_post() calls don't trigger database calls.
wp_cache_add( $postId, $postObject, 'posts' );
$GLOBALS['wp_query'] = $wp_query; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
$wp->register_globals();
// Setting is_404 is not sufficient, so we still need to change the status code.
status_header( 200 );
}
/**
* Get the canonical URL for the dedicated HTML sitemap page.
*
* @since 4.5.7
*
* @param string $originalUrl The canonical URL.
* @return string The canonical URL.
*/
public function getCanonicalUrl( $originalUrl ) {
$sitemapOptions = aioseo()->options->sitemap->html;
if ( ! $sitemapOptions->enable || ! $this->isDedicatedPage ) {
return $originalUrl;
}
// If the user has set a custom URL for the sitemap page, use that.
if ( $sitemapOptions->pageUrl ) {
return $sitemapOptions->pageUrl;
}
// Return the current URL of WP.
global $wp;
return home_url( $wp->request );
}
}
}
namespace {
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'aioseo_html_sitemap' ) ) {
/**
* Global function that can be used to print the HTML sitemap.
*
* @since 4.1.3
*
* @param array $attributes User-defined attributes that override the default settings.
* @param boolean $echo Whether to echo the output or return it.
* @return string The HTML sitemap code.
*/
function aioseo_html_sitemap( $attributes = [], $echo = true ) {
$attributes = aioseo()->htmlSitemap->frontend->getAttributes( $attributes );
return aioseo()->htmlSitemap->frontend->output( $echo, $attributes );
}
}
} home/xbodynamge/namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/Migration/Sitemap.php 0000644 00000035775 15115067565 0027145 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Migration;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the XML Sitemap settings from V3.
*
* @since 4.0.0
*/
class Sitemap {
/**
* The old V3 options.
*
* @since 4.0.0
*
* @var array
*/
protected $oldOptions = [];
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->oldOptions = aioseo()->migration->oldOptions;
if ( empty( $this->oldOptions['modules']['aiosp_sitemap_options'] ) ) {
return;
}
$this->checkIfStatic();
$this->migrateLinksPerIndex();
$this->migrateIncludedObjects();
$this->migratePrioFreq();
$this->migrateAdditionalPages();
$this->migrateExcludedPages();
$this->regenerateSitemap();
$settings = [
'aiosp_sitemap_indexes' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'indexes' ] ],
'aiosp_sitemap_archive' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'date' ] ],
'aiosp_sitemap_author' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'author' ] ],
'aiosp_sitemap_images' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'excludeImages' ] ],
'aiosp_sitemap_rss_sitemap' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'rss', 'enable' ] ],
'aiosp_sitemap_filename' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'filename' ] ],
'aiosp_sitemap_publication_name' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'news', 'publicationName' ] ],
'aiosp_sitemap_rewrite' => [ 'type' => 'boolean', 'newOption' => [ 'deprecated', 'sitemap', 'general', 'advancedSettings', 'dynamic' ] ]
];
aioseo()->migration->helpers->mapOldToNew( $settings, $this->oldOptions['modules']['aiosp_sitemap_options'] );
if (
aioseo()->options->sitemap->general->advancedSettings->excludePosts ||
aioseo()->options->sitemap->general->advancedSettings->excludeTerms ||
aioseo()->options->sitemap->general->advancedSettings->excludeImages ||
( in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) && ! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic )
) {
aioseo()->options->sitemap->general->advancedSettings->enable = true;
}
}
/**
* Check if the sitemap is statically generated.
*
* @since 4.0.0
*
* @return void
*/
private function checkIfStatic() {
if (
isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] ) &&
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] )
) {
$deprecatedOptions = aioseo()->internalOptions->internal->deprecatedOptions;
array_push( $deprecatedOptions, 'staticSitemap' );
aioseo()->internalOptions->internal->deprecatedOptions = $deprecatedOptions;
aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic = false;
}
}
/**
* Migrates the amount of links per sitemap index.
*
* @since 4.0.0
*
* @return void
*/
private function migrateLinksPerIndex() {
if ( ! empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_max_posts'] ) ) {
$value = intval( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_max_posts'] );
if ( ! $value ) {
return;
}
$value = $value > 50000 ? 50000 : $value;
aioseo()->options->sitemap->general->linksPerIndex = $value;
}
}
/**
* Migrates the excluded object settings.
*
* @since 4.0.0
*
* @return void
*/
protected function migrateExcludedPages() {
if (
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_terms'] ) &&
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_pages'] )
) {
return;
}
$excludedPosts = aioseo()->options->sitemap->general->advancedSettings->excludePosts;
if ( ! empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_pages'] ) ) {
$pages = explode( ',', $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_pages'] );
if ( count( $pages ) ) {
foreach ( $pages as $page ) {
$page = trim( $page );
$id = intval( $page );
if ( ! $id ) {
$post = get_page_by_path( $page, OBJECT, aioseo()->helpers->getPublicPostTypes( true ) );
if ( $post && is_object( $post ) ) {
$id = $post->ID;
}
}
if ( $id ) {
$post = get_post( $id );
if ( ! is_object( $post ) ) {
continue;
}
$excludedPost = new \stdClass();
$excludedPost->value = $id;
$excludedPost->type = $post->post_type;
$excludedPost->label = $post->post_title;
$excludedPost->link = get_permalink( $id );
array_push( $excludedPosts, wp_json_encode( $excludedPost ) );
}
}
}
}
aioseo()->options->sitemap->general->advancedSettings->excludePosts = $excludedPosts;
$excludedTerms = aioseo()->options->sitemap->general->advancedSettings->excludeTerms;
if ( ! empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_terms'] ) ) {
foreach ( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_excl_terms'] as $taxonomy ) {
foreach ( $taxonomy['terms'] as $id ) {
$term = get_term( $id );
if ( ! is_a( $term, 'WP_Term' ) ) {
continue;
}
$excludedTerm = new \stdClass();
$excludedTerm->value = $id;
$excludedTerm->type = $term->taxonomy;
$excludedTerm->label = $term->name;
$excludedTerm->link = get_term_link( $term );
array_push( $excludedTerms, wp_json_encode( $excludedTerm ) );
}
}
}
aioseo()->options->sitemap->general->advancedSettings->excludeTerms = $excludedTerms;
}
/**
* Migrates the objects that are included in the sitemap.
*
* @since 4.0.0
*
* @return void
*/
protected function migrateIncludedObjects() {
if (
! isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] ) &&
! isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] )
) {
return;
}
if ( ! is_array( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] ) ) {
$this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] = [];
}
if ( ! is_array( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] ) ) {
$this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] = [];
}
$publicPostTypes = aioseo()->helpers->getPublicPostTypes( true );
$publicTaxonomies = aioseo()->helpers->getPublicTaxonomies( true );
if ( in_array( 'all', $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'], true ) ) {
aioseo()->options->sitemap->general->postTypes->all = true;
aioseo()->options->sitemap->general->postTypes->included = array_values( $publicPostTypes );
} else {
$allPostTypes = true;
foreach ( $publicPostTypes as $postType ) {
if ( ! in_array( $postType, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'], true ) ) {
$allPostTypes = false;
}
}
aioseo()->options->sitemap->general->postTypes->all = $allPostTypes;
aioseo()->options->sitemap->general->postTypes->included = array_values(
array_intersect( $publicPostTypes, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_posttypes'] )
);
}
if ( in_array( 'all', $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'], true ) ) {
aioseo()->options->sitemap->general->taxonomies->all = true;
aioseo()->options->sitemap->general->taxonomies->included = array_values( $publicTaxonomies );
} else {
$allTaxonomies = true;
foreach ( $publicTaxonomies as $taxonomy ) {
if ( ! in_array( $taxonomy, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'], true ) ) {
$allTaxonomies = false;
}
}
aioseo()->options->sitemap->general->taxonomies->all = $allTaxonomies;
aioseo()->options->sitemap->general->taxonomies->included = array_values(
array_intersect( $publicTaxonomies, $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_taxonomies'] )
);
}
}
/**
* Migrates the additional pages that are included in the sitemap.
*
* @since 4.0.0
*
* @return void
*/
private function migrateAdditionalPages() {
if ( empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] ) ) {
return;
}
$pages = [];
foreach ( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] as $url => $values ) {
$page = new \stdClass();
$page->url = esc_url( wp_strip_all_tags( $url ) );
$page->priority = [ 'label' => $values['prio'], 'value' => $values['prio'] ];
$page->frequency = [ 'label' => $values['freq'], 'value' => $values['freq'] ];
$page->lastModified = gmdate( 'm/d/Y', strtotime( $values['mod'] ) );
$pages[] = wp_json_encode( $page );
}
aioseo()->options->sitemap->general->additionalPages->enable = true;
aioseo()->options->sitemap->general->additionalPages->pages = $pages;
}
/**
* Migrates the priority/frequency settings.
*
* @since 4.0.0
*
* @return void
*/
private function migratePrioFreq() {
$settings = [
'aiosp_sitemap_prio_homepage' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'homePage', 'priority' ] ],
'aiosp_sitemap_freq_homepage' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'homePage', 'frequency' ] ],
'aiosp_sitemap_prio_post' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'postTypes', 'priority' ] ],
'aiosp_sitemap_freq_post' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'postTypes', 'frequency' ] ],
'aiosp_sitemap_prio_post_post' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'priority', 'postTypes', 'post', 'priority' ], 'dynamic' => true ],
'aiosp_sitemap_freq_post_post' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'priority', 'postTypes', 'post', 'frequency' ], 'dynamic' => true ],
'aiosp_sitemap_prio_taxonomies' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'taxonomies', 'priority' ] ],
'aiosp_sitemap_freq_taxonomies' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'taxonomies', 'frequency' ] ],
'aiosp_sitemap_prio_archive' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'archive', 'priority' ] ],
'aiosp_sitemap_freq_archive' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'archive', 'frequency' ] ],
'aiosp_sitemap_prio_author' => [ 'type' => 'float', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'author', 'priority' ] ],
'aiosp_sitemap_freq_author' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'advancedSettings', 'priority', 'author', 'frequency' ] ],
];
foreach ( $this->oldOptions['modules']['aiosp_sitemap_options'] as $name => $value ) {
// Ignore fixed settings.
if ( in_array( $name, array_keys( $settings ), true ) ) {
continue;
}
$type = false;
$slug = '';
if ( preg_match( '#aiosp_sitemap_prio_(.*)#', (string) $name, $slug ) ) {
$type = 'priority';
} elseif ( preg_match( '#aiosp_sitemap_freq_(.*)#', (string) $name, $slug ) ) {
$type = 'frequency';
}
if ( empty( $slug ) || empty( $slug[1] ) ) {
continue;
}
$objectSlug = aioseo()->helpers->pregReplace( '#post_(?!tag)|taxonomies_#', '', $slug[1] );
if ( in_array( $objectSlug, aioseo()->helpers->getPublicPostTypes( true ), true ) ) {
$settings[ $name ] = [
'type' => 'priority' === $type ? 'float' : 'string',
'newOption' => [ 'sitemap', 'priority', 'postTypes', $objectSlug, $type ],
'dynamic' => true
];
continue;
}
if ( in_array( $objectSlug, aioseo()->helpers->getPublicTaxonomies( true ), true ) ) {
$settings[ $name ] = [
'type' => 'priority' === $type ? 'float' : 'string',
'newOption' => [ 'sitemap', 'priority', 'taxonomies', $objectSlug, $type ],
'dynamic' => true
];
}
}
$mainOptions = aioseo()->options->noConflict();
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
foreach ( $settings as $name => $values ) {
// If setting is set to default, do nothing.
if (
empty( $this->oldOptions['modules']['aiosp_sitemap_options'][ $name ] ) ||
'no' === $this->oldOptions['modules']['aiosp_sitemap_options'][ $name ]
) {
unset( $settings[ $name ] );
continue;
}
// If value is "Select Individual", set grouped to false.
$value = $this->oldOptions['modules']['aiosp_sitemap_options'][ $name ];
if ( 'sel' === $value ) {
if ( preg_match( '#post$#', (string) $name ) ) {
aioseo()->options->sitemap->general->advancedSettings->priority->postTypes->grouped = false;
} else {
aioseo()->options->sitemap->general->advancedSettings->priority->taxonomies->grouped = false;
}
continue;
}
$object = new \stdClass();
$object->label = $value;
$object->value = $value;
$error = false;
$options = ! empty( $values['dynamic'] ) ? $dynamicOptions : $mainOptions;
$lastOption = '';
for ( $i = 0; $i < count( $values['newOption'] ); $i++ ) {
$lastOption = $values['newOption'][ $i ];
if ( ! $options->has( $lastOption, false ) ) {
$error = true;
break;
}
if ( count( $values['newOption'] ) - 1 !== $i ) {
$options = $options->$lastOption;
}
}
if ( $error ) {
continue;
}
$options->$lastOption = wp_json_encode( $object );
}
if ( count( $settings ) ) {
$mainOptions->sitemap->general->advancedSettings->enable = true;
}
}
/**
* Regenerates the sitemap if it is static.
*
* We need to do this since the stylesheet URLs have changed.
*
* @since 4.0.0
*
* @return void
*/
private function regenerateSitemap() {
if (
isset( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] ) &&
empty( $this->oldOptions['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] )
) {
$files = aioseo()->sitemap->file->files();
$detectedFiles = [];
foreach ( $files as $filename ) {
// We don't want to delete the video sitemap here at all.
$isVideoSitemap = preg_match( '#.*video.*#', (string) $filename ) ? true : false;
if ( ! $isVideoSitemap ) {
$detectedFiles[] = $filename;
}
}
$fs = aioseo()->core->fs;
if ( count( $detectedFiles ) && $fs->isWpfsValid() ) {
foreach ( $detectedFiles as $file ) {
$fs->fs->delete( $file, false, 'f' );
}
}
aioseo()->sitemap->file->generate( true );
}
}
}