| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/RankMath.tar |
RankMath.php 0000666 00000002063 15114437601 0006771 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
class RankMath extends ImportExport\Importer {
/**
* A list of plugins to look for to import.
*
* @since 4.0.0
*
* @var array
*/
public $plugins = [
[
'name' => 'Rank Math SEO',
'version' => '1.0',
'basename' => 'seo-by-rank-math/rank-math.php',
'slug' => 'rank-math-seo'
]
];
/**
* Class constructor.
*
* @since 4.0.0
*
* @param ImportExport\ImportExport $importer the ImportExport class.
*/
public function __construct( $importer ) {
$this->helpers = new Helpers();
$this->postMeta = new PostMeta();
$plugins = $this->plugins;
foreach ( $plugins as $key => $plugin ) {
$plugins[ $key ]['class'] = $this;
}
$importer->addPlugins( $plugins );
}
/**
* Imports the settings.
*
* @since 4.0.0
*
* @return void
*/
protected function importSettings() {
new GeneralSettings();
new TitleMeta();
new Sitemap();
}
} Helpers.php 0000666 00000007433 15114437601 0006674 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Contains helper methods for the import from Rank Math.
*
* @since 4.0.0
*/
class Helpers extends ImportExport\Helpers {
/**
* Converts the macros from Rank Math to our own smart tags.
*
* @since 4.0.0
*
* @param string $string The string with macros.
* @param string $pageType The page type.
* @return string $string The string with smart tags.
*/
public function macrosToSmartTags( $string, $pageType = null ) {
$macros = $this->getMacros( $pageType );
if ( preg_match( '#%BLOGDESCLINK%#', (string) $string ) ) {
$blogDescriptionLink = '<a href="' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'url' ) ) . '">' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'name' ) ) . ' - ' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'description' ) ) . '</a>';
$string = str_replace( '%BLOGDESCLINK%', $blogDescriptionLink, $string );
}
if ( preg_match_all( '#%customfield\(([^%\s]*)\)%#', (string) $string, $matches ) && ! empty( $matches[1] ) ) {
foreach ( $matches[1] as $name ) {
$string = aioseo()->helpers->pregReplace( "#%customfield\($name\)%#", "#custom_field-$name", $string );
}
}
if ( preg_match_all( '#%customterm\(([^%\s]*)\)%#', (string) $string, $matches ) && ! empty( $matches[1] ) ) {
foreach ( $matches[1] as $name ) {
$string = aioseo()->helpers->pregReplace( "#%customterm\($name\)%#", "#tax_name-$name", $string );
}
}
foreach ( $macros as $macro => $tag ) {
$string = aioseo()->helpers->pregReplace( "#$macro(?![a-zA-Z0-9_])#im", $tag, $string );
}
// Strip out all remaining tags.
$string = aioseo()->helpers->pregReplace( '/%[^\%\s]*\([^\%]*\)%/i', '', aioseo()->helpers->pregReplace( '/%[^\%\s]*%/i', '', $string ) );
return trim( $string );
}
/**
* Returns the macro mappings.
*
* @since 4.1.1
*
* @param string $pageType The page type.
* @return array $macros The macros.
*/
protected function getMacros( $pageType = null ) {
$macros = [
'%sitename%' => '#site_title',
'%blog_title%' => '#site_title',
'%blog_description%' => '#tagline',
'%sitedesc%' => '#tagline',
'%sep%' => '#separator_sa',
'%post_title%' => '#post_title',
'%page_title%' => '#post_title',
'%postname%' => '#post_title',
'%title%' => '#post_title',
'%seo_title%' => '#post_title',
'%excerpt%' => '#post_excerpt',
'%wc_shortdesc%' => '#post_excerpt',
'%category%' => '#taxonomy_title',
'%term%' => '#taxonomy_title',
'%term_description%' => '#taxonomy_description',
'%currentdate%' => '#current_date',
'%currentday%' => '#current_day',
'%currentyear%' => '#current_year',
'%currentmonth%' => '#current_month',
'%name%' => '#author_first_name #author_last_name',
'%author%' => '#author_first_name #author_last_name',
'%date%' => '#post_date',
'%year%' => '#current_year',
'%search_query%' => '#search_term',
// RSS Content tags.
'%AUTHORLINK%' => '#author_link',
'%POSTLINK%' => '#post_link',
'%BLOGLINK%' => '#site_link',
'%FEATUREDIMAGE%' => '#featured_image'
];
switch ( $pageType ) {
case 'archive':
$macros['%title%'] = '#archive_title';
break;
case 'term':
$macros['%title%'] = '#taxonomy_title';
break;
default:
$macros['%title%'] = '#post_title';
break;
}
// Strip all other tags.
$macros['%[^%]*%'] = '';
return $macros;
}
} TitleMeta.php 0000666 00000047334 15114437601 0007166 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
use AIOSEO\Plugin\Common\Models;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the Search Appearance settings.
*
* @since 4.0.0
*/
class TitleMeta extends ImportExport\SearchAppearance {
/**
* Our robot meta settings.
*
* @since 4.0.0
*/
private $robotMetaSettings = [
'noindex',
'nofollow',
'noarchive',
'noimageindex',
'nosnippet'
];
/**
* 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-titles' );
if ( empty( $this->options ) ) {
return;
}
$this->migrateHomePageSettings();
$this->migratePostTypeSettings();
$this->migratePostTypeArchiveSettings();
$this->migrateArchiveSettings();
$this->migrateRobotMetaSettings();
$this->migrateKnowledgeGraphSettings();
$this->migrateSocialMetaSettings();
$settings = [
'title_separator' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'separator' ] ],
];
aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the homepage settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateHomePageSettings() {
if ( isset( $this->options['homepage_title'] ) ) {
aioseo()->options->searchAppearance->global->siteTitle =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['homepage_title'] ) );
}
if ( isset( $this->options['homepage_description'] ) ) {
aioseo()->options->searchAppearance->global->metaDescription =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['homepage_description'] ) );
}
if ( isset( $this->options['homepage_facebook_title'] ) ) {
aioseo()->options->social->facebook->homePage->title = aioseo()->helpers->sanitizeOption( $this->options['homepage_facebook_title'] );
}
if ( isset( $this->options['homepage_facebook_description'] ) ) {
aioseo()->options->social->facebook->homePage->description = aioseo()->helpers->sanitizeOption( $this->options['homepage_facebook_description'] );
}
if ( isset( $this->options['homepage_facebook_image'] ) ) {
aioseo()->options->social->facebook->homePage->image = esc_url( $this->options['homepage_facebook_image'] );
}
}
/**
* Migrates the archive settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateArchiveSettings() {
$archives = [
'author',
'date'
];
foreach ( $archives as $archive ) {
// Reset existing values first.
foreach ( $this->robotMetaSettings as $robotsMetaName ) {
aioseo()->options->searchAppearance->archives->$archive->advanced->robotsMeta->$robotsMetaName = false;
}
if ( isset( $this->options[ "disable_{$archive}_archives" ] ) ) {
aioseo()->options->searchAppearance->archives->$archive->show = 'off' === $this->options[ "disable_{$archive}_archives" ];
aioseo()->options->searchAppearance->archives->$archive->advanced->robotsMeta->default = 'on' === $this->options[ "disable_{$archive}_archives" ];
aioseo()->options->searchAppearance->archives->$archive->advanced->robotsMeta->noindex = 'on' === $this->options[ "disable_{$archive}_archives" ];
}
if ( isset( $this->options[ "{$archive}_archive_title" ] ) ) {
$value = aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options[ "{$archive}_archive_title" ], 'archive' ) );
if ( 'date' !== $archive ) {
// Archive Title tag needs to be stripped since we don't support it for author archives.
$value = aioseo()->helpers->pregReplace( '/#archive_title/', '', $value );
}
aioseo()->options->searchAppearance->archives->$archive->title = $value;
}
if ( isset( $this->options[ "{$archive}_archive_description" ] ) ) {
aioseo()->options->searchAppearance->archives->$archive->metaDescription =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options[ "{$archive}_archive_description" ], 'archive' ) );
}
if ( ! empty( $this->options[ "{$archive}_custom_robots" ] ) ) {
aioseo()->options->searchAppearance->archives->$archive->advanced->robotsMeta->default = 'off' === $this->options[ "{$archive}_custom_robots" ];
}
if ( ! empty( $this->options[ "{$archive}_robots" ] ) ) {
foreach ( $this->options[ "{$archive}_robots" ] as $robotsName ) {
if ( 'index' === $robotsName ) {
continue;
}
if ( 'noindex' === $robotsName ) {
aioseo()->options->searchAppearance->archives->{$archive}->show = false;
}
aioseo()->options->searchAppearance->archives->{$archive}->advanced->robotsMeta->{$robotsName} = true;
}
}
if ( ! empty( $this->options[ "{$archive}_advanced_robots" ] ) ) {
if ( isset( $this->options[ "{$archive}_advanced_robots" ]['max-snippet'] ) && is_numeric( $this->options[ "{$archive}_advanced_robots" ]['max-snippet'] ) ) {
aioseo()->options->searchAppearance->archives->$archive->advanced->robotsMeta->maxSnippet = intval( $this->options[ "{$archive}_advanced_robots" ]['max-snippet'] );
}
if ( isset( $this->options[ "{$archive}_advanced_robots" ]['max-video-preview'] ) && is_numeric( isset( $this->options[ "{$archive}_advanced_robots" ]['max-video-preview'] ) ) ) {
aioseo()->options->searchAppearance->archives->$archive->advanced->robotsMeta->maxVideoPreview = intval( $this->options[ "{$archive}_advanced_robots" ]['max-video-preview'] );
}
if ( ! empty( $this->options[ "{$archive}_advanced_robots" ]['max-image-preview'] ) ) {
aioseo()->options->searchAppearance->archives->$archive->advanced->robotsMeta->maxImagePreview =
aioseo()->helpers->sanitizeOption( lcfirst( $this->options[ "{$archive}_advanced_robots" ]['max-image-preview'] ) );
}
}
}
if ( isset( $this->options['search_title'] ) ) {
// Archive Title tag needs to be stripped since we don't support it for search archives.
$value = aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['search_title'], 'archive' ) );
aioseo()->options->searchAppearance->archives->search->title = aioseo()->helpers->pregReplace( '/#archive_title/', '', $value );
}
if ( ! empty( $this->options['noindex_search'] ) ) {
aioseo()->options->searchAppearance->archives->search->show = 'off' === $this->options['noindex_search'];
aioseo()->options->searchAppearance->archives->search->advanced->robotsMeta->default = 'on' === $this->options['noindex_search'];
aioseo()->options->searchAppearance->archives->search->advanced->robotsMeta->noindex = 'on' === $this->options['noindex_search'];
}
}
/**
* Migrates the post type settings.
*
* @since 4.0.0
*
* @return void
*/
private function migratePostTypeSettings() {
$supportedSettings = [
'title',
'description',
'custom_robots',
'robots',
'advanced_robots',
'default_rich_snippet',
'default_article_type',
'add_meta_box'
];
foreach ( aioseo()->helpers->getPublicPostTypes( true ) as $postType ) {
// Reset existing values first.
foreach ( $this->robotMetaSettings as $robotsMetaName ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->$robotsMetaName = false;
}
foreach ( $this->options as $name => $value ) {
if ( ! preg_match( "#^pt_{$postType}_(.*)$#", (string) $name, $match ) || ! in_array( $match[1], $supportedSettings, true ) ) {
continue;
}
switch ( $match[1] ) {
case 'title':
if ( 'page' === $postType ) {
$value = aioseo()->helpers->pregReplace( '#%category%#', '', $value );
$value = aioseo()->helpers->pregReplace( '#%excerpt%#', '', $value );
}
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->title =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value ) );
break;
case 'description':
if ( 'page' === $postType ) {
$value = aioseo()->helpers->pregReplace( '#%category%#', '', $value );
$value = aioseo()->helpers->pregReplace( '#%excerpt%#', '', $value );
}
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->metaDescription =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value ) );
break;
case 'custom_robots':
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->default = 'off' === $value;
break;
case 'robots':
if ( ! empty( $value ) ) {
foreach ( $value as $robotsName ) {
if ( 'index' === $robotsName ) {
continue;
}
if ( 'noindex' === $robotsName ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->{$postType}->show = false;
}
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->$robotsName = true;
}
}
break;
case 'advanced_robots':
if ( isset( $value['max-snippet'] ) && is_numeric( $value['max-snippet'] ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->maxSnippet = intval( $value['max-snippet'] );
}
if ( isset( $value['max-video-preview'] ) && is_numeric( $value['max-video-preview'] ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->maxVideoPreview = intval( $value['max-video-preview'] );
}
if ( ! empty( $value['max-image-preview'] ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->maxImagePreview =
aioseo()->helpers->sanitizeOption( $value['max-image-preview'] );
}
break;
case 'add_meta_box':
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->showMetaBox = 'on' === $value;
break;
case 'default_rich_snippet':
$value = aioseo()->helpers->pregReplace( '#\s#', '', $value );
if ( 'off' === lcfirst( $value ) || in_array( $postType, [ 'page', 'attachment' ], true ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->schemaType = 'none';
break;
}
if ( in_array( ucfirst( $value ), ImportExport\SearchAppearance::$supportedSchemaGraphs, true ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->schemaType = ucfirst( $value );
}
break;
case 'default_article_type':
if ( in_array( $postType, [ 'page', 'attachment' ], true ) ) {
break;
}
$value = aioseo()->helpers->pregReplace( '#\s#', '', $value );
if ( in_array( ucfirst( $value ), ImportExport\SearchAppearance::$supportedArticleGraphs, true ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->articleType = ucfirst( $value );
} else {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->articleType = 'BlogPosting';
}
break;
default:
break;
}
}
}
}
/**
* Migrates the post type archive settings.
*
* @since 4.0.16
*
* @return void
*/
private function migratePostTypeArchiveSettings() {
$supportedSettings = [
'title',
'description'
];
foreach ( aioseo()->helpers->getPublicPostTypes( true, true ) as $postType ) {
foreach ( $this->options as $name => $value ) {
if ( ! preg_match( "#^pt_{$postType}_archive_(.*)$#", (string) $name, $match ) || ! in_array( $match[1], $supportedSettings, true ) ) {
continue;
}
switch ( $match[1] ) {
case 'title':
aioseo()->dynamicOptions->searchAppearance->archives->$postType->title =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value, 'archive' ) );
break;
case 'description':
aioseo()->dynamicOptions->searchAppearance->archives->$postType->metaDescription =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value, 'archive' ) );
break;
default:
break;
}
}
}
}
/**
* Migrates the robots meta settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateRobotMetaSettings() {
// Reset existing values first.
foreach ( $this->robotMetaSettings as $robotsMetaName ) {
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->$robotsMetaName = false;
}
if ( ! empty( $this->options['robots_global'] ) ) {
foreach ( $this->options['robots_global'] as $robotsName ) {
if ( 'index' === $robotsName ) {
continue;
}
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->default = false;
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->$robotsName = true;
}
}
if ( ! empty( $this->options['advanced_robots_global'] ) ) {
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->default = false;
if ( isset( $this->options['robots_global']['max-snippet'] ) && is_numeric( $this->options['robots_global']['max-snippet'] ) ) {
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->maxSnippet = intval( $this->options['robots_global']['max-snippet'] );
}
if ( isset( $this->options['robots_global']['max-video-preview'] ) && is_numeric( $this->options['robots_global']['max-video-preview'] ) ) {
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->maxVideoPreview = intval( $this->options['robots_global']['max-video-preview'] );
}
if ( ! empty( $this->options['robots_global']['max-image-preview'] ) ) {
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->maxImagePreview =
aioseo()->helpers->sanitizeOption( $this->options['robots_global']['max-image-preview'] );
}
}
if ( ! empty( $this->options['noindex_paginated_pages'] ) ) {
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->default = false;
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->noindexPaginated = 'on' === $this->options['noindex_paginated_pages'];
}
}
/**
* Migrates the Knowledge Graph settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateKnowledgeGraphSettings() {
if ( empty( $this->options['knowledgegraph_type'] ) ) {
return;
}
aioseo()->options->searchAppearance->global->schema->siteRepresents =
'company' === $this->options['knowledgegraph_type'] ? 'organization' : 'person';
if ( ! empty( $this->options['knowledgegraph_name'] ) && 'company' === $this->options['knowledgegraph_type'] ) {
aioseo()->options->searchAppearance->global->schema->organizationName = aioseo()->helpers->sanitizeOption( $this->options['knowledgegraph_name'] );
} elseif ( ! empty( $this->options['knowledgegraph_logo'] ) ) {
aioseo()->options->searchAppearance->global->schema->person = 'manual';
aioseo()->options->searchAppearance->global->schema->personName = aioseo()->helpers->sanitizeOption( $this->options['knowledgegraph_name'] );
}
if ( ! empty( $this->options['knowledgegraph_logo'] ) && 'company' === $this->options['knowledgegraph_type'] ) {
aioseo()->options->searchAppearance->global->schema->organizationLogo = esc_url( $this->options['knowledgegraph_logo'] );
} elseif ( ! empty( $this->options['knowledgegraph_logo'] ) ) {
aioseo()->options->searchAppearance->global->schema->person = 'manual';
aioseo()->options->searchAppearance->global->schema->personLogo = esc_url( $this->options['knowledgegraph_logo'] );
}
$this->migrateKnowledgeGraphPhoneNumber();
}
/**
* Migrates the Knowledge Graph phone number.
*
* @since 4.0.0
*
* @return void
*/
private function migrateKnowledgeGraphPhoneNumber() {
if ( empty( $this->options['phone'] ) ) {
return;
}
$phoneNumber = aioseo()->helpers->sanitizeOption( $this->options['phone'] );
if ( ! preg_match( '#\+\d+#', (string) $phoneNumber ) ) {
$notification = Models\Notification::getNotificationByName( 'v3-migration-schema-number' );
if ( $notification->notification_name ) {
return;
}
Models\Notification::addNotification( [
'slug' => uniqid(),
'notification_name' => 'v3-migration-schema-number',
'title' => __( 'Invalid Phone Number for Knowledge Graph', 'all-in-one-seo-pack' ),
'content' => sprintf(
// Translators: 1 - The phone number.
__( 'We were unable to import the phone number that you previously entered for your Knowledge Graph schema markup.
As it needs to be internationally formatted, please enter it (%1$s) with the country code, e.g. +1 (555) 555-1234.', 'all-in-one-seo-pack' ),
"<strong>$phoneNumber</strong>"
),
'type' => 'warning',
'level' => [ 'all' ],
'button1_label' => __( 'Fix Now', 'all-in-one-seo-pack' ),
'button1_action' => 'http://route#aioseo-search-appearance&aioseo-scroll=schema-graph-phone&aioseo-highlight=schema-graph-phone:schema-markup',
'button2_label' => __( 'Remind Me Later', 'all-in-one-seo-pack' ),
'button2_action' => 'http://action#notification/v3-migration-schema-number-reminder',
'start' => gmdate( 'Y-m-d H:i:s' )
] );
return;
}
aioseo()->options->searchAppearance->global->schema->phone = $phoneNumber;
}
/**
* Migrates the Social Meta settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateSocialMetaSettings() {
if ( ! empty( $this->options['open_graph_image'] ) ) {
$defaultImage = esc_url( $this->options['open_graph_image'] );
aioseo()->options->social->facebook->general->defaultImagePosts = $defaultImage;
aioseo()->options->social->twitter->general->defaultImagePosts = $defaultImage;
}
if ( ! empty( $this->options['social_url_facebook'] ) ) {
aioseo()->options->social->profiles->urls->facebookPageUrl = esc_url( $this->options['social_url_facebook'] );
}
if ( ! empty( $this->options['facebook_author_urls'] ) ) {
aioseo()->options->social->facebook->advanced->enable = true;
aioseo()->options->social->facebook->advanced->authorUrl = esc_url( $this->options['facebook_author_urls'] );
}
if ( ! empty( $this->options['facebook_admin_id'] ) ) {
aioseo()->options->social->facebook->advanced->enable = true;
aioseo()->options->social->facebook->advanced->adminId = aioseo()->helpers->sanitizeOption( $this->options['facebook_admin_id'] );
}
if ( ! empty( $this->options['facebook_app_id'] ) ) {
aioseo()->options->social->facebook->advanced->enable = true;
aioseo()->options->social->facebook->advanced->appId = aioseo()->helpers->sanitizeOption( $this->options['facebook_app_id'] );
}
if ( ! empty( $this->options['twitter_author_names'] ) ) {
aioseo()->options->social->profiles->urls->twitterUrl =
'https://x.com/' . aioseo()->helpers->sanitizeOption( $this->options['twitter_author_names'] );
}
if ( ! empty( $this->options['twitter_card_type'] ) ) {
preg_match( '#large#', $this->options['twitter_card_type'], $match );
aioseo()->options->social->twitter->general->defaultCardType = ! empty( $match ) ? 'summary_large_image' : 'summary';
}
}
/**
* Migrates the default social image for posts.
*
* @since 4.0.0
*
* @return void
*/
private function migrateDefaultPostSocialImage() {
if ( ! empty( $this->options['open_graph_image'] ) ) {
$defaultImage = esc_url( $this->options['open_graph_image'] );
aioseo()->options->social->facebook->general->defaultImagePosts = $defaultImage;
aioseo()->options->social->twitter->general->defaultImagePosts = $defaultImage;
}
}
} PostMeta.php 0000666 00000022432 15114437601 0007022 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Imports the post meta from Rank Math.
*
* @since 4.0.0
*/
class PostMeta {
/**
* The batch import action name.
*
* @since 4.0.0
* @version 4.8.3 Moved from RankMath class to here.
*
* @var string
*/
public $postActionName = 'aioseo_import_post_meta_rank_math';
/**
* The mapped meta
*
* @since 4.8.3
*
* @var array
*/
private $mappedMeta = [
'rank_math_title' => 'title',
'rank_math_description' => 'description',
'rank_math_canonical_url' => 'canonical_url',
'rank_math_focus_keyword' => 'keyphrases',
'rank_math_robots' => '',
'rank_math_advanced_robots' => '',
'rank_math_facebook_title' => 'og_title',
'rank_math_facebook_description' => 'og_description',
'rank_math_facebook_image' => 'og_image_custom_url',
'rank_math_twitter_use_facebook' => 'twitter_use_og',
'rank_math_twitter_title' => 'twitter_title',
'rank_math_twitter_description' => 'twitter_description',
'rank_math_twitter_image' => 'twitter_image_custom_url',
'rank_math_twitter_card_type' => 'twitter_card',
'rank_math_primary_category' => 'primary_term',
'rank_math_pillar_content' => 'pillar_content',
];
/**
* Class constructor.
*
* @since 4.8.3
*/
public function __construct() {
add_action( $this->postActionName, [ $this, 'importPostMeta' ] );
}
/**
* Schedules the post meta import.
*
* @since 4.0.0
*
* @return void
*/
public function scheduleImport() {
try {
if ( as_next_scheduled_action( $this->postActionName ) ) {
return;
}
if ( ! aioseo()->core->cache->get( 'import_post_meta_rank_math' ) ) {
aioseo()->core->cache->update( 'import_post_meta_rank_math', time(), WEEK_IN_SECONDS );
}
as_schedule_single_action( time(), $this->postActionName, [], 'aioseo' );
} catch ( \Exception $e ) {
// Do nothing.
}
}
/**
* Get all posts to be imported
*
* @since 4.8.3
*
* @param int $postsPerAction The number of posts to import per action.
* @return array The posts to be imported.
*/
protected function getPostsToImport( $postsPerAction = 100 ) {
$publicPostTypes = implode( "', '", aioseo()->helpers->getPublicPostTypes( true ) );
$timeStarted = gmdate( 'Y-m-d H:i:s', aioseo()->core->cache->get( 'import_post_meta_rank_math' ) );
$posts = aioseo()->core->db
->start( 'posts' . ' as p' )
->select( 'p.ID, p.post_type' )
->join( 'postmeta as pm', '`p`.`ID` = `pm`.`post_id`' )
->leftJoin( 'aioseo_posts as ap', '`p`.`ID` = `ap`.`post_id`' )
->whereRaw( "pm.meta_key LIKE 'rank_math_%'" )
->whereRaw( "( p.post_type IN ( '$publicPostTypes' ) )" )
->whereRaw( "( ap.post_id IS NULL OR ap.updated < '$timeStarted' )" )
->orderBy( 'p.ID DESC' )
->groupBy( 'p.ID' )
->limit( $postsPerAction )
->run()
->result();
return $posts;
}
/**
* Imports the post meta.
*
* @since 4.0.0
*
* @return array The posts that were imported.
*/
public function importPostMeta() {
$postsPerAction = apply_filters( 'aioseo_import_rank_math_posts_per_action', 100 );
$posts = $this->getPostsToImport( $postsPerAction );
if ( ! $posts || ! count( $posts ) ) {
aioseo()->core->cache->delete( 'import_post_meta_rank_math' );
return [];
}
foreach ( $posts as $post ) {
$postMeta = aioseo()->core->db
->start( 'postmeta' . ' as pm' )
->select( 'pm.meta_key, pm.meta_value' )
->where( 'pm.post_id', $post->ID )
->whereRaw( "`pm`.`meta_key` LIKE 'rank_math_%'" )
->run()
->result();
$meta = array_merge( [
'post_id' => (int) $post->ID,
], $this->getMetaData( $postMeta, $post ) );
$aioseoPost = Models\Post::getPost( $post->ID );
$aioseoPost->set( $meta );
$aioseoPost->save();
aioseo()->migration->meta->migrateAdditionalPostMeta( $post->ID );
}
// Clear the Overview cache.
aioseo()->postSettings->clearPostTypeOverviewCache( $posts[0]->ID );
if ( count( $posts ) === $postsPerAction ) {
try {
as_schedule_single_action( time() + 5, $this->postActionName, [], 'aioseo' );
} catch ( \Exception $e ) {
// Do nothing.
}
} else {
aioseo()->core->cache->delete( 'import_post_meta_rank_math' );
}
return $posts;
}
/**
* Get the meta data by post meta.
*
* @since 4.8.3
*
* @param object $postMeta The post meta from database.
* @param object $post The post object.
* @return array The meta data.
*/
public function getMetaData( $postMeta, $post ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$meta = [
'post_id' => $post->ID,
'robots_default' => true,
'robots_noarchive' => false,
'canonical_url' => '',
'robots_nofollow' => false,
'robots_noimageindex' => false,
'robots_noindex' => false,
'robots_noodp' => false,
'robots_nosnippet' => false,
'keyphrases' => [
'focus' => [ 'keyphrase' => '' ],
'additional' => []
],
];
foreach ( $postMeta as $record ) {
$name = $record->meta_key;
$value = $record->meta_value;
if (
! in_array( $post->post_type, [ 'page', 'attachment' ], true ) &&
preg_match( '#^rank_math_schema_([^\s]*)$#', (string) $name, $match ) && ! empty( $match[1] )
) {
switch ( $match[1] ) {
case 'Article':
case 'NewsArticle':
case 'BlogPosting':
$meta['schema_type'] = 'Article';
$meta['schema_type_options'] = wp_json_encode(
[ 'article' => [ 'articleType' => $match[1] ] ]
);
break;
default:
break;
}
}
if ( ! in_array( $name, array_keys( $this->mappedMeta ), true ) ) {
continue;
}
switch ( $name ) {
case 'rank_math_focus_keyword':
$keyphrases = array_map( 'trim', explode( ',', $value ) );
$keyphraseArray = [
'focus' => [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $keyphrases[0] ) ],
'additional' => []
];
unset( $keyphrases[0] );
foreach ( $keyphrases as $keyphrase ) {
$keyphraseArray['additional'][] = [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $keyphrase ) ];
}
$meta['keyphrases'] = $keyphraseArray;
break;
case 'rank_math_robots':
$value = aioseo()->helpers->maybeUnserialize( $value );
if ( ! empty( $value ) ) {
$supportedValues = [ 'index', 'noindex', 'nofollow', 'noarchive', 'noimageindex', 'nosnippet' ];
$meta['robots_default'] = false;
foreach ( $supportedValues as $val ) {
$meta[ "robots_$val" ] = false;
}
// This is a separated foreach as we can import any and all values.
foreach ( $value as $robotsName ) {
$meta[ "robots_$robotsName" ] = true;
}
}
break;
case 'rank_math_advanced_robots':
$value = aioseo()->helpers->maybeUnserialize( $value );
if ( isset( $value['max-snippet'] ) && is_numeric( $value['max-snippet'] ) ) {
$meta['robots_default'] = false;
$meta['robots_max_snippet'] = intval( $value['max-snippet'] );
}
if ( isset( $value['max-video-preview'] ) && is_numeric( $value['max-video-preview'] ) ) {
$meta['robots_default'] = false;
$meta['robots_max_videopreview'] = intval( $value['max-video-preview'] );
}
if ( ! empty( $value['max-image-preview'] ) ) {
$meta['robots_default'] = false;
$meta['robots_max_imagepreview'] = aioseo()->helpers->sanitizeOption( lcfirst( $value['max-image-preview'] ) );
}
break;
case 'rank_math_facebook_image':
$meta['og_image_type'] = 'custom_image';
$meta[ $this->mappedMeta[ $name ] ] = esc_url( $value );
break;
case 'rank_math_twitter_image':
$meta['twitter_image_type'] = 'custom_image';
$meta[ $this->mappedMeta[ $name ] ] = esc_url( $value );
break;
case 'rank_math_twitter_card_type':
preg_match( '#large#', (string) $value, $match );
$meta[ $this->mappedMeta[ $name ] ] = ! empty( $match ) ? 'summary_large_image' : 'summary';
break;
case 'rank_math_twitter_use_facebook':
$meta[ $this->mappedMeta[ $name ] ] = 'on' === $value;
break;
case 'rank_math_primary_category':
$taxonomy = 'category';
$options = new \stdClass();
$options->$taxonomy = (int) $value;
$meta[ $this->mappedMeta[ $name ] ] = wp_json_encode( $options );
break;
case 'rank_math_title':
case 'rank_math_description':
if ( 'page' === $post->post_type ) {
$value = aioseo()->helpers->pregReplace( '#%category%#', '', $value );
$value = aioseo()->helpers->pregReplace( '#%excerpt%#', '', $value );
}
$value = aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value );
$meta[ $this->mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
break;
case 'rank_math_pillar_content':
$meta['pillar_content'] = 'on' === $value ? 1 : 0;
break;
default:
$meta[ $this->mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
break;
}
}
return $meta;
}
} GeneralSettings.php 0000666 00000005777 15114437601 0010401 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the General Settings.
*
* @since 4.0.0
*/
class GeneralSettings {
/**
* 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-general' );
if ( empty( $this->options ) ) {
return;
}
$this->isTruSeoDisabled();
$this->migrateRedirectAttachments();
$this->migrateStripCategoryBase();
$this->migrateRssContentSettings();
$settings = [
'google_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'google' ] ],
'bing_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'bing' ] ],
'yandex_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'yandex' ] ],
'baidu_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'baidu' ] ],
'pinterest_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'pinterest' ] ],
];
aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Checks whether TruSEO should be disabled.
*
* @since 4.0.0
*
* @return void
*/
private function isTruSeoDisabled() {
if ( ! empty( $this->options['frontend_seo_score'] ) ) {
aioseo()->options->advanced->truSeo = 'on' === $this->options['frontend_seo_score'];
}
}
/**
* Migrates the Redirect Attachments setting.
*
* @since 4.0.0
*
* @return void
*/
private function migrateRedirectAttachments() {
if ( isset( $this->options['attachment_redirect_urls'] ) ) {
if ( 'on' === $this->options['attachment_redirect_urls'] ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'attachment_parent';
} else {
aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'disabled';
}
}
}
/**
* Migrates the Strip Category Base setting.
*
* @since 4.2.0
*
* @return void
*/
private function migrateStripCategoryBase() {
if ( isset( $this->options['strip_category_base'] ) ) {
aioseo()->options->searchAppearance->advanced->removeCategoryBase = 'on' === $this->options['strip_category_base'] ? true : false;
}
}
/**
* Migrates the RSS content settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateRssContentSettings() {
if ( isset( $this->options['rss_before_content'] ) ) {
aioseo()->options->rssContent->before = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_before_content'] ) );
}
if ( isset( $this->options['rss_after_content'] ) ) {
aioseo()->options->rssContent->after = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_after_content'] ) );
}
}
} Sitemap.php 0000666 00000011643 15114437601 0006672 0 ustar 00 <?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;
}
}