852e694c by Jeff Balicki

all-in-one-seo-pack

1 parent 754b5b5e
Showing 956 changed files with 4898 additions and 0 deletions
1 <?php
2 /**
3 * Plugin Name: All in One SEO
4 * Plugin URI: https://aioseo.com/
5 * Description: SEO for WordPress. Features like XML Sitemaps, SEO for custom post types, SEO for blogs, business sites, ecommerce sites, and much more. More than 80 million downloads since 2007.
6 * Author: All in One SEO Team
7 * Author URI: https://aioseo.com/
8 * Version: 4.1.6.2
9 * Text Domain: all-in-one-seo-pack
10 * Domain Path: /i18n/
11 *
12 * All in One SEO is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * any later version.
16 *
17 * All in One SEO is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with AIOSEO. If not, see <https://www.gnu.org/licenses/>.
24 *
25 * @since 4.0.0
26 * @author All in One SEO Team
27 * @package AIOSEO\Plugin
28 * @license GPL-2.0+
29 * @copyright Copyright (c) 2020, All in One SEO
30 */
31
32 // Exit if accessed directly.
33 if ( ! defined( 'ABSPATH' ) ) {
34 exit;
35 }
36
37 if ( ! defined( 'AIOSEO_PHP_VERSION_DIR' ) ) {
38 define( 'AIOSEO_PHP_VERSION_DIR', basename( dirname( __FILE__ ) ) );
39 }
40
41 require_once( dirname( __FILE__ ) . '/app/init/init.php' );
42
43 // Check if this plugin should be disabled.
44 if ( aioseoPluginIsDisabled() ) {
45 return;
46 }
47
48 require_once( dirname( __FILE__ ) . '/app/init/notices.php' );
49 require_once( dirname( __FILE__ ) . '/app/init/activation.php' );
50
51 // We require PHP 5.4+ for the whole plugin to work.
52 if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
53 add_action( 'admin_notices', 'aioseo_php_notice' );
54
55 // Do not process the plugin code further.
56 return;
57 }
58
59 // We require WP 4.9+ for the whole plugin to work.
60 global $wp_version;
61 if ( version_compare( $wp_version, '4.9', '<' ) ) {
62 add_action( 'admin_notices', 'aioseo_wordpress_notice' );
63
64 // Do not process the plugin code further.
65 return;
66 }
67
68 if ( ! defined( 'AIOSEO_DIR' ) ) {
69 define( 'AIOSEO_DIR', __DIR__ );
70 }
71 if ( ! defined( 'AIOSEO_FILE' ) ) {
72 define( 'AIOSEO_FILE', __FILE__ );
73 }
74
75 // Don't allow multiple versions to be active.
76 if ( function_exists( 'aioseo' ) ) {
77 add_action( 'activate_all-in-one-seo-pack/all_in_one_seo_pack.php', 'aioseo_lite_just_activated' );
78 add_action( 'deactivate_all-in-one-seo-pack/all_in_one_seo_pack.php', 'aioseo_lite_just_deactivated' );
79 add_action( 'activate_all-in-one-seo-pack-pro/all_in_one_seo_pack.php', 'aioseo_pro_just_activated' );
80 add_action( 'admin_notices', 'aioseo_lite_notice' );
81
82 // Do not process the plugin code further.
83 return;
84 }
85
86 // We will be deprecating these versions of PHP in the future, so let's let the user know.
87 if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
88 add_action( 'admin_notices', 'aioseo_php_notice_deprecated' );
89 }
90
91 // Define the class and the function.
92 require_once( dirname( __FILE__ ) . '/app/AIOSEO.php' );
93
94 aioseo();
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Models;
10
11 /**
12 * Checks for conflicting plugins.
13 *
14 * @since 4.0.0
15 */
16 class ConflictingPlugins {
17 /**
18 * Class Constructor.
19 *
20 * @since 4.0.0
21 */
22 public function __construct() {
23 // We don't want to trigger our notices when not in the admin.
24 if ( ! is_admin() ) {
25 return;
26 }
27
28 add_action( 'init', [ $this, 'init' ] );
29 }
30
31 /**
32 * Initialize the conflicting plugins check.
33 *
34 * @since 4.0.0
35 *
36 * @return void
37 */
38 public function init() {
39 // Only do this for users who can install/deactivate plugins.
40 if ( ! current_user_can( 'install_plugins' ) ) {
41 return;
42 }
43
44 $conflictingPlugins = $this->getAllConflictingPlugins();
45
46 $notification = Models\Notification::getNotificationByName( 'conflicting-plugins' );
47 if ( empty( $conflictingPlugins ) ) {
48 if ( ! $notification->exists() ) {
49 return;
50 }
51
52 Models\Notification::deleteNotificationByName( 'conflicting-plugins' );
53
54 return;
55 }
56
57 aioseo()->notices->conflictingPlugins( $conflictingPlugins );
58 }
59
60 /**
61 * Get a list of all conflicting plugins.
62 *
63 * @since 4.0.0
64 *
65 * @return array An array of conflicting plugins.
66 */
67 protected function getAllConflictingPlugins() {
68 $conflictingSeoPlugins = $this->getConflictingPlugins( 'seo' );
69 $conflictingSitemapPlugins = [];
70
71 if (
72 aioseo()->options->sitemap->general->enable ||
73 aioseo()->options->sitemap->rss->enable
74 ) {
75 $conflictingSitemapPlugins = $this->getConflictingPlugins( 'sitemap' );
76 }
77
78 return array_merge( $conflictingSeoPlugins, $conflictingSitemapPlugins );
79 }
80
81 /**
82 * Get a list of conflicting plugins for AIOSEO.
83 *
84 * @since 4.0.0
85 *
86 * @param string $type A type to look for.
87 * @return array An array of conflicting plugins.
88 */
89 public function getConflictingPlugins( $type ) {
90 $activePlugins = get_option( 'active_plugins' );
91
92 $conflictingPlugins = [];
93 switch ( $type ) {
94 case 'seo':
95 $conflictingPlugins = [
96 'Yoast SEO' => 'wordpress-seo/wp-seo.php',
97 'Yoast SEO Premium' => 'wordpress-seo-premium/wp-seo-premium.php',
98 'Rank Math SEO' => 'seo-by-rank-math/rank-math.php',
99 'SEOPress' => 'wp-seopress/seopress.php',
100 'The SEO Framework' => 'autodescription/autodescription.php',
101 ];
102 break;
103 case 'sitemap':
104 $conflictingPlugins = [
105 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php',
106 'XML Sitemap & Google News' => 'xml-sitemap-feed/xml-sitemap.php',
107 'Google XML Sitemap Generator' => 'www-xml-sitemap-generator-org/www-xml-sitemap-generator-org.php',
108 'Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php',
109 ];
110 break;
111 }
112
113 return array_intersect( $conflictingPlugins, $activePlugins );
114 }
115 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Class that holds our dashboard widget.
11 *
12 * @since 4.0.0
13 */
14 class Dashboard {
15 /**
16 * Class Constructor.
17 *
18 * @since 4.0.0
19 */
20 public function __construct() {
21 add_action( 'wp_dashboard_setup', [ $this, 'addDashboardWidget' ] );
22 }
23
24 /**
25 * Add Dashboard Widget
26 *
27 * @since 2.3.10
28 */
29 public function addDashboardWidget() {
30 if ( current_user_can( 'install_plugins' ) && $this->showWidget() ) {
31 wp_add_dashboard_widget(
32 'aioseo-rss-feed',
33 esc_html__( 'SEO News', 'all-in-one-seo-pack' ),
34 [
35 $this,
36 'displayRssDashboardWidget',
37 ]
38 );
39 }
40 }
41
42 /**
43 * Whether or not to show the widget.
44 *
45 * @since 4.0.0
46 *
47 * @return boolean True if yes, false otherwise.
48 */
49 protected function showWidget() {
50 // API filter hook to disable showing SEO News dashboard widget.
51 if ( false === apply_filters( 'aioseo_show_seo_news', true ) ) {
52 return false;
53 }
54
55 return true;
56 }
57
58 /**
59 * Display RSS Dashboard Widget
60 *
61 * @since 4.0.0
62 */
63 public function displayRssDashboardWidget() {
64 // check if the user has chosen not to display this widget through screen options.
65 $currentScreen = get_current_screen();
66 $hiddenWidgets = get_user_meta( get_current_user_id(), 'metaboxhidden_' . $currentScreen->id );
67 if ( $hiddenWidgets && count( $hiddenWidgets ) > 0 && is_array( $hiddenWidgets[0] ) && in_array( 'aioseo-rss-feed', $hiddenWidgets[0], true ) ) {
68 return;
69 }
70
71 include_once( ABSPATH . WPINC . '/feed.php' );
72
73 $rssItems = aioseo()->cache->get( 'rss_feed' );
74 if ( null === $rssItems ) {
75
76 $rss = fetch_feed( 'https://aioseo.com/feed/' );
77 if ( is_wp_error( $rss ) ) {
78 esc_html_e( 'Temporarily unable to load feed.', 'all-in-one-seo-pack' );
79
80 return;
81 }
82 $rssItems = $rss->get_items( 0, 4 ); // Show four items.
83 $cached = [];
84 foreach ( $rssItems as $item ) {
85 $cached[] = [
86 'url' => $item->get_permalink(),
87 'title' => $item->get_title(),
88 'date' => $item->get_date( 'M jS Y' ),
89 'content' => substr( wp_strip_all_tags( $item->get_content() ), 0, 128 ) . '...',
90 ];
91 }
92 $rssItems = $cached;
93
94 aioseo()->cache->update( 'rss_feed', $cached, 12 * HOUR_IN_SECONDS );
95
96 }
97
98 ?>
99
100 <ul>
101 <?php
102 if ( false === $rssItems ) {
103 echo '<li>No items</li>';
104
105 return;
106 }
107
108 foreach ( $rssItems as $item ) {
109 ?>
110 <li>
111 <a target="_blank" href="<?php echo esc_url( $item['url'] ); ?>">
112 <?php echo esc_html( $item['title'] ); ?>
113 </a>
114 <span class="aioseop-rss-date"><?php echo esc_html( $item['date'] ); ?></span>
115 <div class="aioseop_news">
116 <?php echo esc_html( wp_strip_all_tags( $item['content'] ) ) . '...'; ?>
117 </div>
118 </li>
119 <?php
120 }
121
122 ?>
123 </ul>
124
125 <?php
126
127 }
128 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin\Notices;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * WordPress Deprecated Notice.
11 *
12 * @since 4.1.2
13 */
14 class DeprecatedWordPress {
15 /**
16 * Class Constructor.
17 *
18 * @since 4.1.2
19 */
20 public function __construct() {
21 add_action( 'wp_ajax_aioseo-dismiss-deprecated-wordpress-notice', [ $this, 'dismissNotice' ] );
22 }
23
24 /**
25 * Go through all the checks to see if we should show the notice.
26 *
27 * @since 4.1.2
28 *
29 * @return void
30 */
31 public function maybeShowNotice() {
32 global $wp_version;
33
34 $dismissed = get_option( '_aioseo_deprecated_wordpress_dismissed', true );
35 if ( '1' === $dismissed ) {
36 return;
37 }
38
39 // Only show to users that interact with our pluign.
40 if ( ! current_user_can( 'publish_posts' ) ) {
41 return;
42 }
43
44 // Only show if WordPress version is deprecated.
45 if ( version_compare( $wp_version, '5.3', '>=' ) ) {
46 return;
47 }
48
49 $this->showNotice();
50
51 // Print the script to the footer.
52 add_action( 'admin_footer', [ $this, 'printScript' ] );
53 }
54
55 /**
56 * Actually show the review plugin.
57 *
58 * @since 4.1.2
59 *
60 * @return void
61 */
62 public function showNotice() {
63 $medium = false !== strpos( AIOSEO_PHP_VERSION_DIR, 'pro' ) ? 'proplugin' : 'liteplugin';
64 ?>
65 <div class="notice notice-warning aioseo-deprecated-wordpress-notice is-dismissible">
66 <p>
67 <?php
68 echo wp_kses(
69 sprintf(
70 // Translators: 1 - Opening HTML bold tag, 2 - Closing HTML bold tag.
71 __( 'Your site is running an %1$soutdated version%2$s of WordPress. We recommend using the latest version of WordPress in order to keep your site secure.', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
72 '<strong>',
73 '</strong>'
74 ),
75 [
76 'strong' => [],
77 ]
78 );
79 ?>
80 <br><br>
81 <?php
82 echo wp_kses(
83 sprintf(
84 // Translators: 1 - Opening HTML bold tag, 2 - Closing HTML bold tag, 3 - The plugin name ("All in One SEO"), 4 - Opening HTML link tag, 5 - Closing HTML link tag.
85 __( '%1$sNote:%2$s %3$s will be discontinuing support for WordPress versions older than version 5.3 by the end of 2021. %4$sRead more for additional information.%5$s', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
86 '<strong>',
87 '</strong>',
88 'AIOSEO',
89 '<a href="https://aioseo.com/docs/update-wordpress/?utm_source=WordPress&utm_medium=' . $medium . '&utm_campaign=outdated-wordpress-notice" target="_blank" rel="noopener noreferrer">', // phpcs:ignore Generic.Files.LineLength.MaxExceeded
90 '</a>'
91 ),
92 [
93 'a' => [
94 'href' => [],
95 'target' => [],
96 'rel' => [],
97 ],
98 'strong' => [],
99 ]
100 );
101 ?>
102 </p>
103 </div>
104
105 <?php
106 // In case this is on plugin activation.
107 if ( isset( $_GET['activate'] ) ) {
108 unset( $_GET['activate'] );
109 }
110 }
111
112 /**
113 * Print the script for dismissing the notice.
114 *
115 * @since 4.1.2
116 *
117 * @return void
118 */
119 public function printScript() {
120 // Create a nonce.
121 $nonce = wp_create_nonce( 'aioseo-dismiss-deprecated-wordpress' );
122 ?>
123 <script>
124 window.addEventListener('load', function () {
125 var dismissBtn
126
127 // Add an event listener to the dismiss button.
128 dismissBtn = document.querySelector('.aioseo-deprecated-wordpress-notice .notice-dismiss')
129 dismissBtn.addEventListener('click', function (event) {
130 var httpRequest = new XMLHttpRequest(),
131 postData = ''
132
133 // Build the data to send in our request.
134 postData += '&action=aioseo-dismiss-deprecated-wordpress-notice'
135 postData += '&nonce=<?php echo esc_html( $nonce ); ?>'
136
137 httpRequest.open('POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>')
138 httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
139 httpRequest.send(postData)
140 })
141 });
142 </script>
143 <?php
144 }
145
146 /**
147 * Dismiss the deprecated WordPress notice.
148 *
149 * @since 4.1.2
150 *
151 * @return WP_Response The successful response.
152 */
153 public function dismissNotice() {
154 // Early exit if we're not on a aioseo-dismiss-deprecated-wordpress-notice action.
155 if ( ! isset( $_POST['action'] ) || 'aioseo-dismiss-deprecated-wordpress-notice' !== $_POST['action'] ) {
156 return;
157 }
158
159 check_ajax_referer( 'aioseo-dismiss-deprecated-wordpress', 'nonce' );
160
161 update_option( '_aioseo_deprecated_wordpress_dismissed', true );
162
163 return wp_send_json_success();
164 }
165 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin\Notices;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Plugin import notice.
11 *
12 * @since 4.0.0
13 */
14 class Import {
15 /**
16 * Go through all the checks to see if we should show the notice.
17 *
18 * @since 4.0.0
19 *
20 * @return void
21 */
22 public function maybeShowNotice() {
23 if ( ! aioseo()->importExport->isImportRunning() ) {
24 return;
25 }
26
27 $this->showNotice();
28 }
29
30 /**
31 * Register the notice so that it appears.
32 *
33 * @since 4.0.0
34 *
35 * @return void
36 */
37 public function showNotice() {
38 $string1 = __( 'SEO Meta Import In Progress', 'all-in-one-seo-pack' );
39 // Translators: 1 - The plugin name ("All in One SEO").
40 $string2 = sprintf( __( '%1$s is importing your existing SEO data in the background.', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME );
41 $string3 = __( 'This notice will automatically disappear as soon as the import has completed. Meanwhile, everything should continue to work as expected.', 'all-in-one-seo-pack' );
42 ?>
43 <div class="notice notice-info aioseo-migration">
44 <p><strong><?php echo esc_html( $string1 ); ?></strong></p>
45 <p><?php echo esc_html( $string2 ); ?></p>
46 <p><?php echo esc_html( $string3 ); ?></p>
47 </div>
48 <style>
49 </style>
50 <?php
51 }
52 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin\Notices;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * V3 to V4 migration notice.
11 *
12 * @since 4.0.0
13 */
14 class Migration {
15 /**
16 * Go through all the checks to see if we should show the notice.
17 *
18 * @since 4.0.0
19 *
20 * @return void
21 */
22 public function maybeShowNotice() {
23 $transientPosts = aioseo()->cache->get( 'v3_migration_in_progress_posts' );
24 $transientTerms = aioseo()->cache->get( 'v3_migration_in_progress_terms' );
25 if ( ! $transientPosts && ! $transientTerms ) {
26 return;
27 }
28
29 // Disable the notice for now since it is almost unnecessary. We can come back and revisit this in the future.
30 // $this->showNotice();
31 }
32
33 /**
34 * Register the notice so that it appears.
35 *
36 * @since 4.0.0
37 *
38 * @return void
39 */
40 public function showNotice() {
41 // Translators: 1 - The plugin name ("AIOSEO).
42 $string1 = sprintf( __( '%1$s V3->V4 Migration In Progress', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME );
43 // Translators: 1 - The plugin name ("All in One SEO").
44 $string2 = sprintf( __( '%1$s is currently upgrading your database and migrating your SEO data in the background.', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME );
45 $string3 = __( 'This notice will automatically disappear as soon as the migration has completed. Meanwhile, everything should continue to work as expected.', 'all-in-one-seo-pack' );
46 ?>
47 <div class="notice notice-info aioseo-migration">
48 <p><strong><?php echo esc_html( $string1 ); ?></strong></p>
49 <p><?php echo esc_html( $string2 ); ?></p>
50 <p><?php echo esc_html( $string3 ); ?></p>
51 </div>
52 <style>
53 </style>
54 <?php
55 }
56 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin\Notices;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Review Plugin Notice.
11 *
12 * @since 4.0.0
13 */
14 class Review {
15 /**
16 * Class Constructor.
17 *
18 * @since 4.0.0
19 */
20 public function __construct() {
21 add_action( 'wp_ajax_aioseo-dismiss-review-plugin-cta', [ $this, 'dismissNotice' ] );
22 }
23
24 /**
25 * Go through all the checks to see if we should show the notice.
26 *
27 * @since 4.0.0
28 *
29 * @return void
30 */
31 public function maybeShowNotice() {
32 $dismissed = get_user_meta( get_current_user_id(), '_aioseo_plugin_review_dismissed', true );
33 if ( '1' === $dismissed || '2' === $dismissed ) {
34 return;
35 }
36
37 if ( ! empty( $dismissed ) && $dismissed > time() ) {
38 return;
39 }
40
41 // Only show to users that interact with our pluign.
42 if ( ! current_user_can( 'publish_posts' ) ) {
43 return;
44 }
45
46 // Only show if plugin has been active for over two weeks.
47 if ( ! aioseo()->internalOptions->internal->firstActivated ) {
48 aioseo()->internalOptions->internal->firstActivated = time();
49 }
50
51 $activated = aioseo()->internalOptions->internal->firstActivated( time() );
52 if ( $activated > strtotime( '-2 weeks' ) ) {
53 return;
54 }
55
56 $this->showNotice();
57
58 // Print the script to the footer.
59 add_action( 'admin_footer', [ $this, 'printScript' ] );
60 }
61
62 /**
63 * Actually show the review plugin.
64 *
65 * @since 4.0.0
66 *
67 * @return void
68 */
69 public function showNotice() {
70 $feedbackUrl = add_query_arg(
71 [
72 'wpf7528_24' => untrailingslashit( home_url() ),
73 'wpf7528_26' => aioseo()->options->has( 'general' ) && aioseo()->options->general->has( 'licenseKey' )
74 ? aioseo()->options->general->licenseKey
75 : '',
76 'wpf7528_27' => aioseo()->pro ? 'pro' : 'lite',
77 'wpf7528_28' => AIOSEO_VERSION,
78 'utm_source' => aioseo()->pro ? 'proplugin' : 'liteplugin',
79 'utm_medium' => 'review-notice',
80 'utm_campaign' => 'feedback',
81 'utm_content' => AIOSEO_VERSION,
82 ],
83 'https://aioseo.com/plugin-feedback/'
84 );
85
86 // Translators: 1 - The plugin name ("All in One SEO").
87 $string1 = sprintf( __( 'Are you enjoying %1$s?', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME );
88 $string2 = __( 'Yes I love it', 'all-in-one-seo-pack' );
89 $string3 = __( 'Not Really...', 'all-in-one-seo-pack' );
90 // Translators: The plugin name ("All in One SEO").
91 $string4 = sprintf( __( 'We\'re sorry to hear you aren\'t enjoying %1$s. We would love a chance to improve. Could you take a minute and let us know what we can do better?', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME ); // phpcs:ignore Generic.Files.LineLength.MaxExceeded
92 $string5 = __( 'Give feedback', 'all-in-one-seo-pack' );
93 $string6 = __( 'No thanks', 'all-in-one-seo-pack' );
94 $string7 = __( 'That\'s awesome! Could you please do me a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'all-in-one-seo-pack' );
95 // Translators: The plugin name ("All in One SEO").
96 $string8 = sprintf( __( 'CEO of %1$s', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME );
97 $string9 = __( 'Ok, you deserve it', 'all-in-one-seo-pack' );
98 $string10 = __( 'Nope, maybe later', 'all-in-one-seo-pack' );
99 $string11 = __( 'I already did', 'all-in-one-seo-pack' );
100
101 ?>
102 <div class="notice notice-info aioseo-review-plugin-cta is-dismissible">
103 <div class="step-1">
104 <p><?php echo esc_html( $string1 ); ?></p>
105 <p>
106 <a href="#" class="aioseo-review-switch-step-3" data-step="3"><?php echo esc_html( $string2 ); ?></a> 🙂 |
107 <a href="#" class="aioseo-review-switch-step-2" data-step="2"><?php echo esc_html( $string3 ); ?></a>
108 </p>
109 </div>
110 <div class="step-2" style="display:none;">
111 <p><?php echo esc_html( $string4 ); ?></p>
112 <p>
113 <a href="<?php echo esc_url( $feedbackUrl ); ?>" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $string5 ); ?></a>&nbsp;&nbsp;
114 <a href="#" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $string6 ); ?></a>
115 </p>
116 </div>
117 <div class="step-3" style="display:none;">
118 <p><?php echo esc_html( $string7 ); ?></p>
119 <p><strong>~ Syed Balkhi<br><?php echo esc_html( $string8 ); ?></strong></p>
120 <p>
121 <a href="https://wordpress.org/support/plugin/all-in-one-seo-pack/reviews/?filter=5#new-post" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer">
122 <?php echo esc_html( $string9 ); ?>
123 </a>&nbsp;&nbsp;
124 <a href="#" class="aioseo-dismiss-review-notice-delay" target="_blank" rel="noopener noreferrer">
125 <?php echo esc_html( $string10 ); ?>
126 </a>&nbsp;&nbsp;
127 <a href="#" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer">
128 <?php echo esc_html( $string11 ); ?>
129 </a>
130 </p>
131 </div>
132 </div>
133 <?php
134 }
135
136 /**
137 * Print the script for dismissing the notice.
138 *
139 * @since 4.0.13
140 *
141 * @return void
142 */
143 public function printScript() {
144 // Create a nonce.
145 $nonce = wp_create_nonce( 'aioseo-dismiss-review' );
146 ?>
147 <style>
148 .aioseop-notice-review_plugin_cta .aioseo-action-buttons {
149 display: none;
150 }
151 @keyframes dismissBtnVisible {
152 from { opacity: 0.99; }
153 to { opacity: 1; }
154 }
155 .aioseo-review-plugin-cta button.notice-dismiss {
156 animation-duration: 0.001s;
157 animation-name: dismissBtnVisible;
158 }
159 </style>
160 <script>
161 window.addEventListener('load', function () {
162 var aioseoSetupButton,
163 dismissBtn,
164 interval
165
166 aioseoSetupButton = function (dismissBtn) {
167 var notice = document.querySelector('.notice.aioseo-review-plugin-cta'),
168 delay = false,
169 relay = true,
170 stepOne = notice.querySelector('.step-1'),
171 stepTwo = notice.querySelector('.step-2'),
172 stepThree = notice.querySelector('.step-3')
173
174 // Add an event listener to the dismiss button.
175 dismissBtn.addEventListener('click', function (event) {
176 var httpRequest = new XMLHttpRequest(),
177 postData = ''
178
179 // Build the data to send in our request.
180 postData += '&delay=' + delay
181 postData += '&relay=' + relay
182 postData += '&action=aioseo-dismiss-review-plugin-cta'
183 postData += '&nonce=<?php echo esc_html( $nonce ); ?>'
184
185 httpRequest.open('POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>')
186 httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
187 httpRequest.send(postData)
188 })
189
190 notice.addEventListener('click', function (event) {
191 if (event.target.matches('.aioseo-review-switch-step-3')) {
192 event.preventDefault()
193 stepOne.style.display = 'none'
194 stepTwo.style.display = 'none'
195 stepThree.style.display = 'block'
196 }
197 if (event.target.matches('.aioseo-review-switch-step-2')) {
198 event.preventDefault()
199 stepOne.style.display = 'none'
200 stepThree.style.display = 'none'
201 stepTwo.style.display = 'block'
202 }
203 if (event.target.matches('.aioseo-dismiss-review-notice-delay')) {
204 event.preventDefault()
205 delay = true
206 relay = false
207 dismissBtn.click()
208 }
209 if (event.target.matches('.aioseo-dismiss-review-notice')) {
210 if ('#' === event.target.getAttribute('href')) {
211 event.preventDefault()
212 }
213 relay = false
214 dismissBtn.click()
215 }
216 })
217 }
218
219 dismissBtn = document.querySelector('.aioseo-review-plugin-cta .notice-dismiss')
220 if (!dismissBtn) {
221 document.addEventListener('animationstart', function (event) {
222 if (event.animationName == 'dismissBtnVisible') {
223 dismissBtn = document.querySelector('.aioseo-review-plugin-cta .notice-dismiss')
224 if (dismissBtn) {
225 aioseoSetupButton(dismissBtn)
226 }
227 }
228 }, false)
229
230 } else {
231 aioseoSetupButton(dismissBtn)
232 }
233 });
234 </script>
235 <?php
236 }
237
238 /**
239 * Dismiss the review plugin CTA.
240 *
241 * @since 4.0.0
242 *
243 * @return WP_Response The successful response.
244 */
245 public function dismissNotice() {
246 // Early exit if we're not on a aioseo-dismiss-review-plugin-cta action.
247 if ( ! isset( $_POST['action'] ) || 'aioseo-dismiss-review-plugin-cta' !== $_POST['action'] ) {
248 return;
249 }
250
251 check_ajax_referer( 'aioseo-dismiss-review', 'nonce' );
252 $delay = isset( $_POST['delay'] ) ? 'true' === wp_unslash( $_POST['delay'] ) : false; // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized
253 $relay = isset( $_POST['relay'] ) ? 'true' === wp_unslash( $_POST['relay'] ) : false; // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized
254
255 if ( ! $delay ) {
256 update_user_meta( get_current_user_id(), '_aioseo_plugin_review_dismissed', $relay ? '2' : '1' );
257
258 return wp_send_json_success();
259 }
260
261 update_user_meta( get_current_user_id(), '_aioseo_plugin_review_dismissed', strtotime( '+1 week' ) );
262
263 return wp_send_json_success();
264 }
265 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Models;
10
11 /**
12 * Abstract class that Pro and Lite both extend.
13 *
14 * @since 4.0.0
15 */
16 class PostSettings {
17 /**
18 * Initialize the admin.
19 *
20 * @since 4.0.0
21 *
22 * @return void
23 */
24 public function __construct() {
25 if ( is_admin() ) {
26 // Load Vue APP.
27 add_action( 'admin_enqueue_scripts', [ $this, 'enqueuePostSettingsAssets' ] );
28
29 // Add metabox.
30 add_action( 'add_meta_boxes', [ $this, 'addPostSettingsMetabox' ] );
31
32 // Add metabox to terms on init hook.
33 add_action( 'init', [ $this, 'init' ], 1000 );
34
35 // Save metabox.
36 add_action( 'save_post', [ $this, 'saveSettingsMetabox' ] );
37 add_action( 'edit_attachment', [ $this, 'saveSettingsMetabox' ] );
38 add_action( 'add_attachment', [ $this, 'saveSettingsMetabox' ] );
39 }
40 }
41
42 /**
43 * Enqueues the JS/CSS for the on page/posts settings.
44 *
45 * @since 4.0.0
46 *
47 * @return void
48 */
49 public function enqueuePostSettingsAssets() {
50 if (
51 aioseo()->helpers->isScreenBase( 'event-espresso' ) ||
52 aioseo()->helpers->isScreenBase( 'post' ) ||
53 aioseo()->helpers->isScreenBase( 'term' ) ||
54 aioseo()->helpers->isScreenBase( 'edit-tags' )
55 ) {
56 $page = null;
57 if (
58 aioseo()->helpers->isScreenBase( 'event-espresso' ) ||
59 aioseo()->helpers->isScreenBase( 'post' )
60 ) {
61 $page = 'post';
62 }
63
64 aioseo()->helpers->enqueueScript(
65 'aioseo-post-settings-metabox',
66 'js/post-settings.js'
67 );
68 wp_localize_script(
69 'aioseo-post-settings-metabox',
70 'aioseo',
71 aioseo()->helpers->getVueData( $page )
72 );
73
74 if ( 'post' === $page ) {
75 $this->enqueuePublishPanelAssets();
76 }
77
78 $rtl = is_rtl() ? '.rtl' : '';
79 aioseo()->helpers->enqueueStyle(
80 'aioseo-post-settings-metabox',
81 "css/post-settings$rtl.css"
82 );
83 }
84
85 $screen = get_current_screen();
86 if ( 'attachment' === $screen->id ) {
87 wp_enqueue_media();
88 }
89 }
90
91 /**
92 * Enqueues the JS/CSS for the Block Editor integrations.
93 *
94 * @since 4.1.4
95 *
96 * @return void
97 */
98 private function enqueuePublishPanelAssets() {
99 aioseo()->helpers->enqueueScript(
100 'aioseo-publish-panel',
101 'js/publish-panel.js'
102 );
103
104 $rtl = is_rtl() ? '.rtl' : '';
105 aioseo()->helpers->enqueueStyle(
106 'aioseo-publish-panel',
107 "css/publish-panel$rtl.css"
108 );
109 }
110
111 /**
112 * Adds a meta box to page/posts screens.
113 *
114 * @since 4.0.0
115 *
116 * @return void
117 */
118 public function addPostSettingsMetabox() {
119 $dynamicOptions = aioseo()->dynamicOptions->noConflict();
120 $screen = get_current_screen();
121 $postType = $screen->post_type;
122
123 $pageAnalysisSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_analysis' );
124 $generalSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_general_settings' );
125 $socialSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_social_settings' );
126 $schemaSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_schema_settings' );
127 $linkAssistantCapability = aioseo()->access->hasCapability( 'aioseo_page_link_assistant_settings' );
128 $advancedSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_advanced_settings' );
129
130 if (
131 $dynamicOptions->searchAppearance->postTypes->has( $postType ) &&
132 $dynamicOptions->searchAppearance->postTypes->$postType->advanced->showMetaBox &&
133 ! (
134 empty( $pageAnalysisSettingsCapability ) &&
135 empty( $generalSettingsCapability ) &&
136 empty( $socialSettingsCapability ) &&
137 empty( $schemaSettingsCapability ) &&
138 empty( $linkAssistantCapability ) &&
139 empty( $advancedSettingsCapability )
140 )
141 ) {
142 // Translators: 1 - The plugin short name ("AIOSEO").
143 $aioseoMetaboxTitle = sprintf( esc_html__( '%1$s Settings', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME );
144
145 add_meta_box(
146 'aioseo-settings',
147 $aioseoMetaboxTitle,
148 [ $this, 'postSettingsMetabox' ],
149 [ $postType ],
150 'normal',
151 apply_filters( 'aioseo_post_metabox_priority', 'high' )
152 );
153 }
154 }
155
156 /**
157 * Render the on page/posts settings metabox with Vue App wrapper.
158 *
159 * @since 4.0.0
160 *
161 * @param WP_Post $post The current post.
162 * @return void
163 */
164 public function postSettingsMetabox() {
165 $this->postSettingsHiddenField();
166 ?>
167 <div id="aioseo-post-settings-metabox">
168 <?php aioseo()->templates->getTemplate( 'parts/loader.php' ); ?>
169 </div>
170 <?php
171 }
172
173 /**
174 * Adds the hidden field where all the metabox data goes.
175 *
176 * @since 4.0.17
177 *
178 * @return void
179 */
180 public function postSettingsHiddenField() {
181 if ( isset( $this->postSettingsHiddenFieldExists ) ) {
182 return;
183 }
184 $this->postSettingsHiddenFieldExists = true;
185 ?>
186 <div id="aioseo-post-settings-field">
187 <input type="hidden" name="aioseo-post-settings" id="aioseo-post-settings" value=""/>
188 <?php wp_nonce_field( 'aioseoPostSettingsNonce', 'PostSettingsNonce' ); ?>
189 </div>
190 <?php
191 }
192
193 /**
194 * Handles metabox saving.
195 *
196 * @since 4.0.3
197 *
198 * @param int $postId Post ID.
199 * @return void
200 */
201 public function saveSettingsMetabox( $postId ) {
202 // Ignore auto saving
203 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
204 return;
205 }
206
207 // Security check
208 if ( ! isset( $_POST['PostSettingsNonce'] ) || ! wp_verify_nonce( $_POST['PostSettingsNonce'], 'aioseoPostSettingsNonce' ) ) {
209 return;
210 }
211
212 // If we don't have our post settings input, we can safely skip.
213 if ( ! isset( $_POST['aioseo-post-settings'] ) ) {
214 return;
215 }
216
217 // Check user permissions
218 if ( ! current_user_can( 'edit_post', $postId ) ) {
219 return;
220 }
221
222 $currentPost = json_decode( stripslashes( $_POST['aioseo-post-settings'] ), true ); // phpcs:ignore HM.Security.ValidatedSanitizedInput
223
224 // If there is no data, there likely was an error, e.g. if the hidden field wasn't populated on load and the user saved the post without making changes in the metabox.
225 // In that case we should return to prevent a complete reset of the data.
226 if ( empty( $currentPost ) ) {
227 return;
228 }
229
230 Models\Post::savePost( $postId, $currentPost );
231
232 }
233 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Class that holds our setup wizard.
11 *
12 * @since 4.0.0
13 */
14 class SetupWizard {
15 /**
16 * Class Constructor.
17 *
18 * @since 4.0.0
19 */
20 public function __construct() {
21 add_action( 'admin_menu', [ $this, 'addDashboardPage' ] );
22 add_action( 'admin_head', [ $this, 'hideDashboardPageFromMenu' ] );
23 add_action( 'admin_init', [ $this, 'maybeLoadOnboardingWizard' ] );
24 add_action( 'admin_init', [ $this, 'redirect' ], 9999 );
25 }
26
27 /**
28 * Onboarding Wizard redirect.
29 *
30 * This function checks if a new install or update has just occurred. If so,
31 * then we redirect the user to the appropriate page.
32 *
33 * @since 4.0.0
34 *
35 * @return void
36 */
37 public function redirect() {
38 // Check if we should consider redirection.
39 if ( ! aioseo()->cache->get( 'activation_redirect' ) ) {
40 return;
41 }
42
43 // If we are redirecting, clear the transient so it only happens once.
44 aioseo()->cache->delete( 'activation_redirect' );
45
46 // Check option to disable welcome redirect.
47 if ( get_option( 'aioseo_activation_redirect', false ) ) {
48 return;
49 }
50
51 // Only do this for single site installs.
52 if ( isset( $_GET['activate-multi'] ) || is_network_admin() ) {
53 return;
54 }
55
56 wp_safe_redirect( admin_url( 'index.php?page=aioseo-setup-wizard' ) );
57 exit;
58 }
59
60 /**
61 * Adds a dashboard page for our setup wizard.
62 *
63 * @since 4.0.0
64 *
65 * @return void
66 */
67 public function addDashboardPage() {
68 add_dashboard_page( '', '', aioseo()->admin->getPageRequiredCapability( 'aioseo-setup-wizard' ), 'aioseo-setup-wizard', '' );
69 }
70
71 /**
72 * Hide the dashboard page from the menu.
73 *
74 * @since 4.1.5
75 *
76 * @return void
77 */
78 public function hideDashboardPageFromMenu() {
79 remove_submenu_page( 'index.php', 'aioseo-setup-wizard' );
80 }
81
82 /**
83 * Checks to see if we should load the setup wizard.
84 *
85 * @since 4.0.0
86 *
87 * @return void
88 */
89 public function maybeLoadOnboardingWizard() {
90 // Don't load the interface if doing an ajax call.
91 if ( wp_doing_ajax() || wp_doing_cron() ) {
92 return;
93 }
94
95 // Check for wizard-specific parameter
96 // Allow plugins to disable the setup wizard
97 // Check if current user is allowed to save settings.
98 if (
99 ! isset( $_GET['page'] ) ||
100 'aioseo-setup-wizard' !== wp_unslash( $_GET['page'] ) || // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized
101 ! current_user_can( aioseo()->admin->getPageRequiredCapability( 'aioseo-setup-wizard' ) )
102 ) {
103 return;
104 }
105
106 set_current_screen();
107
108 // Remove an action in the Gutenberg plugin ( not core Gutenberg ) which throws an error.
109 remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' );
110
111 // If we are redirecting, clear the transient so it only happens once.
112 aioseo()->cache->delete( 'activation_redirect' );
113
114 $this->loadOnboardingWizard();
115 }
116
117 /**
118 * Load the Onboarding Wizard template.
119 *
120 * @since 4.0.0
121 *
122 * @return void
123 */
124 private function loadOnboardingWizard() {
125 $this->enqueueScripts();
126 $this->setupWizardHeader();
127 $this->setupWizardContent();
128 $this->setupWizardFooter();
129 exit;
130 }
131
132 /**
133 * Enqueue's scripts for the setup wizard.
134 *
135 * @since 4.0.0
136 *
137 * @return void
138 */
139 public function enqueueScripts() {
140 // We don't want any plugin adding notices to our screens. Let's clear them out here.
141 remove_all_actions( 'admin_notices' );
142 remove_all_actions( 'all_admin_notices' );
143
144 // Scripts.
145 aioseo()->helpers->enqueueScript(
146 'aioseo-vendors',
147 'js/chunk-vendors.js'
148 );
149 aioseo()->helpers->enqueueScript(
150 'aioseo-common',
151 'js/chunk-common.js'
152 );
153 aioseo()->helpers->enqueueScript(
154 'aioseo-setup-wizard-script',
155 'js/setup-wizard.js'
156 );
157
158 // Styles.
159 $rtl = is_rtl() ? '.rtl' : '';
160 aioseo()->helpers->enqueueStyle(
161 'aioseo-vendors',
162 "css/chunk-vendors$rtl.css"
163 );
164 aioseo()->helpers->enqueueStyle(
165 'aioseo-common',
166 "css/chunk-common$rtl.css"
167 );
168 // aioseo()->helpers->enqueueStyle(
169 // 'aioseo-setup-wizard-style',
170 // "css/setup-wizard$rtl.css"
171 // );
172 // aioseo()->helpers->enqueueStyle(
173 // 'aioseo-setup-wizard-vendors-style',
174 // "css/chunk-setup-wizard-vendors$rtl.css"
175 // );
176
177 wp_localize_script(
178 'aioseo-setup-wizard-script',
179 'aioseo',
180 aioseo()->helpers->getVueData( 'setup-wizard' )
181 );
182
183 wp_localize_script(
184 'aioseo-setup-wizard-script',
185 'aioseoTranslations',
186 [
187 'translations' => aioseo()->helpers->getJedLocaleData( 'all-in-one-seo-pack' )
188 ]
189 );
190
191 wp_enqueue_style( 'common' );
192 wp_enqueue_media();
193 }
194
195 /**
196 * Outputs the simplified header used for the Onboarding Wizard.
197 *
198 * @since 4.0.0
199 *
200 * @return void
201 */
202 public function setupWizardHeader() {
203 ?>
204 <!DOCTYPE html>
205 <html <?php language_attributes(); ?>>
206 <head>
207 <meta name="viewport" content="width=device-width"/>
208 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
209 <title>
210 <?php
211 // Translators: 1 - The plugin name ("All in One SEO").
212 echo sprintf( esc_html__( '%1$s &rsaquo; Onboarding Wizard', 'all-in-one-seo-pack' ), esc_html( AIOSEO_PLUGIN_SHORT_NAME ) );
213 ?>
214 </title>
215 <?php do_action( 'admin_print_scripts' ); ?>
216 <?php do_action( 'admin_print_styles' ); ?>
217 <?php do_action( 'admin_head' ); ?>
218 </head>
219 <body class="aioseo-setup-wizard">
220 <?php
221 }
222
223 /**
224 * Outputs the content of the current step.
225 *
226 * @since 4.0.0
227 *
228 * @return void
229 */
230 public function setupWizardContent() {
231 echo '<div id="aioseo-app"></div>';
232 }
233
234 /**
235 * Outputs the simplified footer used for the Onboarding Wizard.
236 *
237 * @since 4.0.0
238 *
239 * @return void
240 */
241 public function setupWizardFooter() {
242 ?>
243 <?php
244 wp_print_scripts( 'aioseo-vendors' );
245 wp_print_scripts( 'aioseo-common' );
246 wp_print_scripts( 'aioseo-setup-wizard-script' );
247 do_action( 'admin_footer', '' );
248 do_action( 'admin_print_footer_scripts' );
249 // do_action( 'customize_controls_print_footer_scripts' );
250 ?>
251 </body>
252 </html>
253 <?php
254 }
255 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Admin;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Usage tracking class.
11 *
12 * @since 4.0.0
13 */
14 abstract class Usage {
15 /**
16 * Returns the current plugin version type ("lite" or "pro").
17 *
18 * @since 4.1.3
19 *
20 * @return string The version type.
21 */
22 abstract public function getType();
23
24 /**
25 * Source of notifications content.
26 *
27 * @since 4.0.0
28 *
29 * @var string
30 */
31 private $url = 'https://aiousage.com/v1/track';
32
33 /**
34 * Whether or not usage tracking is enabled.
35 *
36 * @since 4.0.0
37 *
38 * @var bool
39 */
40 protected $enabled = false;
41
42 /**
43 * Class Constructor.
44 *
45 * @since 4.0.0
46 */
47 public function __construct() {
48 add_action( 'init', [ $this, 'init' ], 2 );
49 }
50
51 /**
52 * Runs on the init action.
53 *
54 * @since 4.0.0
55 *
56 * @return void
57 */
58 public function init() {
59 try {
60 $action = 'aioseo_send_usage_data';
61 if ( ! $this->enabled ) {
62 aioseo()->helpers->unscheduleAction( $action );
63
64 return;
65 }
66
67 // Register the action handler.
68 add_action( $action, [ $this, 'process' ] );
69
70 if ( ! as_next_scheduled_action( $action ) ) {
71 as_schedule_recurring_action( $this->generateStartDate(), WEEK_IN_SECONDS, $action, [], 'aioseo' );
72
73 // Run the task immediately using an async action.
74 as_enqueue_async_action( $action, [], 'aioseo' );
75 }
76 } catch ( \Exception $e ) {
77 // Do nothing.
78 }
79 }
80
81 /**
82 * Processes the usage tracking.
83 *
84 * @since 4.0.0
85 *
86 * @return void
87 */
88 public function process() {
89 if ( ! $this->enabled ) {
90 return;
91 }
92
93 wp_remote_post(
94 $this->getUrl(),
95 [
96 'timeout' => 5,
97 'redirection' => 5,
98 'httpversion' => '1.1',
99 'blocking' => true,
100 'headers' => [ 'Content-Type' => 'application/json; charset=utf-8' ],
101 'body' => wp_json_encode( $this->getData() ),
102 'user-agent' => 'AIOSEO/' . AIOSEO_VERSION . '; ' . get_bloginfo( 'url' ),
103 ]
104 );
105 }
106
107 /**
108 * Gets the URL for the notifications api.
109 *
110 * @since 4.0.0
111 *
112 * @return string The URL to use for the api requests.
113 */
114 private function getUrl() {
115 if ( defined( 'AIOSEO_USAGE_TRACKING_URL' ) ) {
116 return AIOSEO_USAGE_TRACKING_URL;
117 }
118
119 return $this->url;
120 }
121
122 /**
123 * Retrieves the data to send in the usage tracking.
124 *
125 * @since 4.0.0
126 *
127 * @return array An array of data to send.
128 */
129 protected function getData() {
130 $themeData = wp_get_theme();
131 $type = $this->getType();
132
133 return [
134 // Generic data (environment).
135 'url' => home_url(),
136 'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION,
137 'wp_version' => get_bloginfo( 'version' ),
138 'mysql_version' => aioseo()->db->db->db_version(),
139 'server_version' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
140 'is_ssl' => is_ssl(),
141 'is_multisite' => is_multisite(),
142 'sites_count' => function_exists( 'get_blog_count' ) ? (int) get_blog_count() : 1,
143 'active_plugins' => $this->getActivePlugins(),
144 'theme_name' => $themeData->name,
145 'theme_version' => $themeData->version,
146 'user_count' => function_exists( 'get_user_count' ) ? get_user_count() : null,
147 'locale' => get_locale(),
148 'timezone_offset' => aioseo()->helpers->getTimeZoneOffset(),
149 'email' => get_bloginfo( 'admin_email' ),
150 // AIOSEO specific data.
151 'aioseo_version' => AIOSEO_VERSION,
152 'aioseo_license_key' => null,
153 'aioseo_license_type' => null,
154 'aioseo_is_pro' => false,
155 "aioseo_${type}_installed_date" => aioseo()->internalOptions->internal->installed,
156 'aioseo_settings' => $this->getSettings()
157 ];
158 }
159
160 /**
161 * Get the settings and escape the quotes so it can be JSON encoded.
162 *
163 * @since 4.0.0
164 *
165 * @return array An array of settings data.
166 */
167 private function getSettings() {
168 $settings = aioseo()->options->all();
169 array_walk_recursive( $settings, function( &$v ) {
170 if ( is_string( $v ) && strpos( $v, '&quot' ) !== false ) {
171 $v = str_replace( '&quot', '&#x5c;&quot', $v );
172 }
173 });
174
175 $internal = aioseo()->internalOptions->all();
176 array_walk_recursive( $internal, function( &$v ) {
177 if ( is_string( $v ) && strpos( $v, '&quot' ) !== false ) {
178 $v = str_replace( '&quot', '&#x5c;&quot', $v );
179 }
180 });
181
182 return [
183 'options' => $settings,
184 'internal' => $internal
185 ];
186 }
187
188 /**
189 * Return a list of active plugins.
190 *
191 * @since 4.0.0
192 *
193 * @return array An array of active plugin data.
194 */
195 private function getActivePlugins() {
196 if ( ! function_exists( 'get_plugins' ) ) {
197 include ABSPATH . '/wp-admin/includes/plugin.php';
198 }
199 $active = get_option( 'active_plugins', [] );
200 $plugins = array_intersect_key( get_plugins(), array_flip( $active ) );
201
202 return array_map(
203 static function ( $plugin ) {
204 if ( isset( $plugin['Version'] ) ) {
205 return $plugin['Version'];
206 }
207
208 return 'Not Set';
209 },
210 $plugins
211 );
212 }
213
214 /**
215 * Generate a random start date for usage tracking.
216 *
217 * @since 4.0.0
218 *
219 * @return integer The randomized start date.
220 */
221 private function generateStartDate() {
222 $tracking = [
223 'days' => wp_rand( 0, 6 ) * DAY_IN_SECONDS,
224 'hours' => wp_rand( 0, 23 ) * HOUR_IN_SECONDS,
225 'minutes' => wp_rand( 0, 23 ) * HOUR_IN_SECONDS,
226 'seconds' => wp_rand( 0, 59 )
227 ];
228
229 return strtotime( 'next sunday' ) + array_sum( $tracking );
230 }
231 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Route class for the API.
11 *
12 * @since 4.0.0
13 */
14 class Analyze {
15 /**
16 * Analyzes the site for SEO.
17 *
18 * @since 4.0.0
19 *
20 * @param \WP_REST_Request $request The REST Request
21 * @return \WP_REST_Response The response.
22 */
23 public static function analyzeSite( $request ) {
24 $body = $request->get_json_params();
25 $analyzeUrl = ! empty( $body['url'] ) ? esc_url_raw( urldecode( $body['url'] ) ) : null;
26 $refreshResults = ! empty( $body['refresh'] ) ? (bool) $body['refresh'] : false;
27 $analyzeOrHomeUrl = ! empty( $analyzeUrl ) ? $analyzeUrl : home_url();
28 $responseCode = null === aioseo()->cache->get( 'analyze_site_code' ) ? [] : aioseo()->cache->get( 'analyze_site_code' );
29 $responseBody = null === aioseo()->cache->get( 'analyze_site_body' ) ? [] : aioseo()->cache->get( 'analyze_site_body' );
30 if (
31 empty( $responseCode ) ||
32 empty( $responseCode[ $analyzeOrHomeUrl ] ) ||
33 empty( $responseBody ) ||
34 empty( $responseBody[ $analyzeOrHomeUrl ] ) ||
35 $refreshResults
36 ) {
37 $token = aioseo()->internalOptions->internal->siteAnalysis->connectToken;
38 $license = aioseo()->options->has( 'general' ) && aioseo()->options->general->has( 'licenseKey' )
39 ? aioseo()->options->general->licenseKey
40 : '';
41 $url = defined( 'AIOSEO_ANALYZE_URL' ) ? AIOSEO_ANALYZE_URL : 'https://analyze.aioseo.com';
42 $response = wp_remote_post( $url . '/v1/analyze/', [
43 'headers' => [
44 'X-AIOSEO-Key' => $token,
45 'X-AIOSEO-License' => $license,
46 'Content-Type' => 'application/json'
47 ],
48 'body' => wp_json_encode( [
49 'url' => $analyzeOrHomeUrl
50 ] ),
51 'timeout' => 60
52 ] );
53
54 $responseCode[ $analyzeOrHomeUrl ] = wp_remote_retrieve_response_code( $response );
55 $responseBody[ $analyzeOrHomeUrl ] = json_decode( wp_remote_retrieve_body( $response ) );
56
57 aioseo()->cache->update( 'analyze_site_code', $responseCode, 10 * MINUTE_IN_SECONDS );
58 aioseo()->cache->update( 'analyze_site_body', $responseBody, 10 * MINUTE_IN_SECONDS );
59 }
60
61 if ( 200 !== $responseCode[ $analyzeOrHomeUrl ] || empty( $responseBody[ $analyzeOrHomeUrl ]->success ) || ! empty( $responseBody[ $analyzeOrHomeUrl ]->error ) ) {
62 if ( ! empty( $responseBody[ $analyzeOrHomeUrl ]->error ) && 'invalid-token' === $responseBody[ $analyzeOrHomeUrl ]->error ) {
63 aioseo()->internalOptions->internal->siteAnalysis->reset();
64 }
65
66 return new \WP_REST_Response( [
67 'success' => false,
68 'response' => $responseBody[ $analyzeOrHomeUrl ]
69 ], 400 );
70 }
71
72 if ( $analyzeUrl ) {
73 $competitors = aioseo()->internalOptions->internal->siteAnalysis->competitors;
74 $competitors = array_reverse( $competitors, true );
75
76 $competitors[ $analyzeUrl ] = wp_json_encode( $responseBody[ $analyzeOrHomeUrl ] );
77
78 $competitors = array_reverse( $competitors, true );
79
80 // Reset the competitors.
81 aioseo()->internalOptions->internal->siteAnalysis->competitors = $competitors;
82
83 return new \WP_REST_Response( $competitors, 200 );
84 }
85
86 aioseo()->internalOptions->internal->siteAnalysis->score = $responseBody[ $analyzeOrHomeUrl ]->score;
87 aioseo()->internalOptions->internal->siteAnalysis->results = wp_json_encode( $responseBody[ $analyzeOrHomeUrl ]->results );
88
89 return new \WP_REST_Response( $responseBody[ $analyzeOrHomeUrl ], 200 );
90 }
91
92 /**
93 * Deletes the analyzed site for SEO.
94 *
95 * @since 4.0.0
96 *
97 * @param \WP_REST_Request $request The REST Request
98 * @return \WP_REST_Response The response.
99 */
100 public static function deleteSite( $request ) {
101 $body = $request->get_json_params();
102 $analyzeUrl = ! empty( $body['url'] ) ? esc_url_raw( urldecode( $body['url'] ) ) : null;
103
104 $competitors = aioseo()->internalOptions->internal->siteAnalysis->competitors;
105
106 unset( $competitors[ $analyzeUrl ] );
107
108 // Reset the competitors.
109 aioseo()->internalOptions->internal->siteAnalysis->competitors = $competitors;
110
111 return new \WP_REST_Response( $competitors, 200 );
112 }
113
114 /**
115 * Analyzes the title for SEO.
116 *
117 * @since 4.1.2
118 *
119 * @param \WP_REST_Request $request The REST Request.
120 * @return \WP_REST_Response The response.
121 */
122 public static function analyzeHeadline( $request ) {
123 $body = $request->get_json_params();
124 $headline = ! empty( $body['headline'] ) ? sanitize_text_field( $body['headline'] ) : '';
125 $shouldStoreHeadline = ! empty( $body['shouldStoreHeadline'] ) ? rest_sanitize_boolean( $body['shouldStoreHeadline'] ) : false;
126
127 if ( empty( $headline ) ) {
128 return new \WP_REST_Response( [
129 'success' => false,
130 'message' => __( 'Please enter a valid headline.', 'all-in-one-seo-pack' )
131 ], 400 );
132 }
133
134 $result = aioseo()->headlineAnalyzer->getResult( $headline );
135
136 $headlines = aioseo()->internalOptions->internal->headlineAnalysis->headlines;
137 $headlines = array_reverse( $headlines, true );
138
139 $headlines[ $headline ] = wp_json_encode( $result );
140
141 $headlines = array_reverse( $headlines, true );
142
143 // Store the headlines with the latest one.
144 if ( $shouldStoreHeadline ) {
145 aioseo()->internalOptions->internal->headlineAnalysis->headlines = $headlines;
146 }
147
148 return new \WP_REST_Response( $headlines, 200 );
149 }
150
151 /**
152 * Deletes the analyzed Headline for SEO.
153 *
154 * @since 4.1.6
155 *
156 * @param \WP_REST_Request $request The REST Request.
157 * @return \WP_REST_Response The response.
158 */
159 public static function deleteHeadline( $request ) {
160 $body = $request->get_json_params();
161 $headline = sanitize_text_field( $body['headline'] );
162
163 $headlines = aioseo()->internalOptions->internal->headlineAnalysis->headlines;
164
165 unset( $headlines[ $headline ] );
166
167 // Reset the headlines.
168 aioseo()->internalOptions->internal->headlineAnalysis->headlines = $headlines;
169
170 return new \WP_REST_Response( $headlines, 200 );
171 }
172 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Route class for the API.
11 *
12 * @since 4.0.0
13 */
14 class Connect {
15 /**
16 * Get the connect URL.
17 *
18 * @since 4.0.0
19 *
20 * @param \WP_REST_Request $request The REST Request
21 * @return \WP_REST_Response The response.
22 */
23 public static function getConnectUrl( $request ) {
24 $body = $request->get_json_params();
25 $key = ! empty( $body['licenseKey'] ) ? sanitize_text_field( $body['licenseKey'] ) : null;
26 $wizard = ! empty( $body['wizard'] ) ? (bool) $body['wizard'] : false;
27 $success = true;
28 $urlData = aioseo()->admin->connect->generateConnectUrl( $key, $wizard ? admin_url( 'index.php?page=aioseo-setup-wizard#/success' ) : null );
29 $url = '';
30 $message = '';
31
32 if ( ! empty( $urlData['error'] ) ) {
33 $success = false;
34 $message = $urlData['error'];
35 }
36
37 $url = $urlData['url'];
38
39 return new \WP_REST_Response( [
40 'success' => $success,
41 'url' => $url,
42 'message' => $message,
43 'popup' => ! isset( $urlData['popup'] ) ? true : $urlData['popup']
44 ], 200 );
45 }
46
47 /**
48 * Process the connection.
49 *
50 * @since 4.0.0
51 *
52 * @param \WP_REST_Request $request The REST Request
53 * @return \WP_REST_Response The response.
54 */
55 public static function processConnect( $request ) {
56 $body = $request->get_json_params();
57 $downloadUrl = ! empty( $body['downloadUrl'] ) ? esc_url_raw( urldecode( $body['downloadUrl'] ) ) : null;
58 $token = ! empty( $body['token'] ) ? sanitize_text_field( $body['token'] ) : null;
59 $wizard = ! empty( $body['wizard'] ) ? sanitize_text_field( $body['wizard'] ) : null;
60 $success = true;
61 $message = '';
62
63 if ( $wizard ) {
64 aioseo()->internalOptions->internal->wizard = $wizard;
65 }
66
67 $response = aioseo()->admin->connect->process( $downloadUrl, $token );
68 if ( ! empty( $response['error'] ) ) {
69 $message = $response['error'];
70 } else {
71 $message = $response['success'];
72 }
73
74 return new \WP_REST_Response( [
75 'success' => $success,
76 'message' => $message
77 ], 200 );
78 }
79
80 /**
81 * Saves the connect token.
82 *
83 * @since 4.0.0
84 *
85 * @param \WP_REST_Request $request The REST Request
86 * @return \WP_REST_Response The response.
87 */
88 public static function saveConnectToken( $request ) {
89 $body = $request->get_json_params();
90 $token = ! empty( $body['token'] ) ? sanitize_text_field( $body['token'] ) : null;
91 $success = true;
92 $message = 'token-saved';
93
94 aioseo()->internalOptions->internal->siteAnalysis->connectToken = $token;
95
96 return new \WP_REST_Response( [
97 'success' => $success,
98 'message' => $message
99 ], 200 );
100 }
101 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Integrations\Semrush;
10
11 /**
12 * Route class for the API.
13 *
14 * @since 4.0.16
15 */
16 class Integrations {
17 /**
18 * Fetches the additional keyphrases.
19 *
20 * @since 4.0.16
21 *
22 * @param \WP_REST_Request $request The REST Request
23 * @return \WP_REST_Response The response.
24 */
25 public static function semrushGetKeyphrases( $request ) {
26 $body = $request->get_json_params();
27 $keyphrases = Semrush::getKeyphrases( $body['keyphrase'], $body['database'] );
28 if ( false === $keyphrases ) {
29 return new \WP_REST_Response( [
30 'success' => false,
31 'message' => 'Tokens expired and could not be refreshed.'
32 ], 400 );
33 }
34
35 return new \WP_REST_Response( [
36 'success' => true,
37 'keyphrases' => $keyphrases
38 ], 200 );
39 }
40
41 /**
42 * Authenticates with Semrush.
43 *
44 * @since 4.0.16
45 *
46 * @param \WP_REST_Request $request The REST Request
47 * @return \WP_REST_Response The response.
48 */
49 public static function semrushAuthenticate( $request ) {
50 $body = $request->get_json_params();
51
52 if ( empty( $body['code'] ) ) {
53 return new \WP_REST_Response( [
54 'success' => false,
55 'message' => 'Missing authorization code.'
56 ], 400 );
57 }
58
59 $success = Semrush::authenticate( $body['code'] );
60 if ( ! $success ) {
61 return new \WP_REST_Response( [
62 'success' => false,
63 'message' => 'Authentication failed.'
64 ], 400 );
65 }
66
67 return new \WP_REST_Response( [
68 'success' => true,
69 'semrush' => aioseo()->internalOptions->integrations->semrush->all()
70 ], 200 );
71 }
72
73 /**
74 * Refreshes the API tokens.
75 *
76 * @since 4.0.16
77 *
78 * @param \WP_REST_Request $request The REST Request
79 * @return \WP_REST_Response The response.
80 */
81 public static function semrushRefresh() {
82 $success = Semrush::refreshTokens();
83 if ( ! $success ) {
84 return new \WP_REST_Response( [
85 'success' => false,
86 'message' => 'API tokens could not be refreshed.'
87 ], 400 );
88 }
89
90 return new \WP_REST_Response( [
91 'success' => true,
92 'semrush' => aioseo()->internalOptions->integrations->semrush->all()
93 ], 200 );
94 }
95 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Migration as CommonMigration;
10 use AIOSEO\Plugin\Common\Models;
11
12 /**
13 * Route class for the API.
14 *
15 * @since 4.0.6
16 */
17 class Migration {
18 /**
19 * Resets blank title formats and retriggers the post/term meta migration.
20 *
21 * @since 4.0.6
22 *
23 * @return \WP_REST_Response The response.
24 */
25 public static function fixBlankFormats() {
26 $oldOptions = ( new CommonMigration\OldOptions() )->oldOptions;
27 if ( ! $oldOptions ) {
28 return new \WP_REST_Response( [
29 'success' => true,
30 'message' => 'Could not load v3 options.'
31 ], 400 );
32 }
33
34 $postTypes = aioseo()->helpers->getPublicPostTypes( true );
35 $taxonomies = aioseo()->helpers->getPublicTaxonomies( true );
36 foreach ( $oldOptions as $k => $v ) {
37 if ( ! preg_match( '/^aiosp_([a-zA-Z]*)_title_format$/', $k, $match ) || ! empty( $v ) ) {
38 continue;
39 }
40
41 $objectName = $match[1];
42 if ( in_array( $objectName, $postTypes, true ) && aioseo()->dynamicOptions->searchAppearance->postTypes->has( $objectName ) ) {
43 aioseo()->dynamicOptions->searchAppearance->postTypes->$objectName->title = '#post_title #separator_sa #site_title';
44 continue;
45 }
46
47 if ( in_array( $objectName, $taxonomies, true ) && aioseo()->dynamicOptions->searchAppearance->taxonomies->has( $objectName ) ) {
48 aioseo()->dynamicOptions->searchAppearance->taxonomies->$objectName->title = '#taxonomy_title #separator_sa #site_title';
49 }
50 }
51
52 aioseo()->migration->redoMetaMigration();
53
54 Models\Notification::deleteNotificationByName( 'v3-migration-title-formats-blank' );
55
56 return new \WP_REST_Response( [
57 'success' => true,
58 'message' => 'Title formats have been reset; post/term migration has been scheduled.',
59 'notifications' => Models\Notification::getNotifications()
60 ], 200 );
61 }
62 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Models;
10
11 /**
12 * Route class for the API.
13 *
14 * @since 4.0.0
15 */
16 class Notifications {
17 /**
18 * Extend the start date of a notice.
19 *
20 * @since 4.0.0
21 *
22 * @param \WP_REST_Request $request The REST Request
23 * @return \WP_REST_Response The response.
24 */
25 public static function blogVisibilityReminder() {
26 return self::reminder( 'blog-visibility' );
27 }
28
29 /**
30 * Extend the start date of a notice.
31 *
32 * @since 4.0.5
33 *
34 * @param \WP_REST_Request $request The REST Request
35 * @return \WP_REST_Response The response.
36 */
37 public static function descriptionFormatReminder() {
38 return self::reminder( 'description-format' );
39 }
40
41 /**
42 * Extend the start date of a notice.
43 *
44 * @since 4.0.0
45 *
46 * @param \WP_REST_Request $request The REST Request
47 * @return \WP_REST_Response The response.
48 */
49 public static function installMiReminder() {
50 return self::reminder( 'install-mi' );
51 }
52
53 /**
54 * Extend the start date of a notice.
55 *
56 * @since 4.0.0
57 *
58 * @param \WP_REST_Request $request The REST Request
59 * @return \WP_REST_Response The response.
60 */
61 public static function installAddonsReminder() {
62 return self::reminder( 'install-addons' );
63 }
64
65 /**
66 * Extend the start date of a notice.
67 *
68 * @since 4.0.0
69 *
70 * @param \WP_REST_Request $request The REST Request
71 * @return \WP_REST_Response The response.
72 */
73 public static function installImageSeoReminder() {
74 return self::reminder( 'install-aioseo-image-seo' );
75 }
76
77 /**
78 * Extend the start date of a notice.
79 *
80 * @since 4.0.0
81 *
82 * @param \WP_REST_Request $request The REST Request
83 * @return \WP_REST_Response The response.
84 */
85 public static function installLocalBusinessReminder() {
86 return self::reminder( 'install-aioseo-local-business' );
87 }
88
89 /**
90 * Extend the start date of a notice.
91 *
92 * @since 4.0.0
93 *
94 * @param \WP_REST_Request $request The REST Request
95 * @return \WP_REST_Response The response.
96 */
97 public static function installNewsSitemapReminder() {
98 return self::reminder( 'install-aioseo-news-sitemap' );
99 }
100
101 /**
102 * Extend the start date of a notice.
103 *
104 * @since 4.0.0
105 *
106 * @param \WP_REST_Request $request The REST Request
107 * @return \WP_REST_Response The response.
108 */
109 public static function installVideoSitemapReminder() {
110 return self::reminder( 'install-aioseo-video-sitemap' );
111 }
112
113 /**
114 * Extend the start date of a notice.
115 *
116 * @since 4.0.0
117 *
118 * @param \WP_REST_Request $request The REST Request
119 * @return \WP_REST_Response The response.
120 */
121 public static function conflictingPluginsReminder() {
122 return self::reminder( 'conflicting-plugins' );
123 }
124
125 /**
126 * Extend the start date of a notice.
127 *
128 * @since 4.0.0
129 *
130 * @param \WP_REST_Request $request The REST Request
131 * @return \WP_REST_Response The response.
132 */
133 public static function deprecatedFiltersReminder() {
134 return self::reminder( 'deprecated-filters-v2' );
135 }
136
137 /**
138 * Extend the start date of a notice.
139 *
140 * @since 4.0.0
141 *
142 * @param \WP_REST_Request $request The REST Request
143 * @return \WP_REST_Response The response.
144 */
145 public static function migrationCustomFieldReminder() {
146 return self::reminder( 'v3-migration-custom-field' );
147 }
148
149 /**
150 * Extend the start date of a notice.
151 *
152 * @since 4.0.0
153 *
154 * @param \WP_REST_Request $request The REST Request
155 * @return \WP_REST_Response The response.
156 */
157 public static function migrationSchemaNumberReminder() {
158 return self::reminder( 'v3-migration-schema-number' );
159 }
160
161 /**
162 * This allows us to not repeat code over and over.
163 *
164 * @since 4.0.0
165 *
166 * @param string $slug The slug of the reminder.
167 * @return @return \WP_REST_Response The response.
168 */
169 protected static function reminder( $slug ) {
170 aioseo()->notices->remindMeLater( $slug );
171
172 return new \WP_REST_Response( [
173 'success' => true,
174 'notifications' => Models\Notification::getNotifications()
175 ], 200 );
176 }
177
178 /**
179 * Dismiss notifications.
180 *
181 * @since 4.0.0
182 *
183 * @param \WP_REST_Request $request The REST Request
184 * @return \WP_REST_Response The response.
185 */
186 public static function dismissNotifications( $request ) {
187 $slugs = $request->get_json_params();
188
189 $notifications = aioseo()->db
190 ->start( 'aioseo_notifications' )
191 ->whereIn( 'slug', $slugs )
192 ->run()
193 ->models( 'AIOSEO\\Plugin\\Common\\Models\\Notification' );
194
195 foreach ( $notifications as $notification ) {
196 $notification->dismissed = 1;
197 $notification->save();
198 }
199
200 // Dismiss static notifications.
201 if ( in_array( 'notification-review', $slugs, true ) ) {
202 update_user_meta( get_current_user_id(), '_aioseo_notification_plugin_review_dismissed', true );
203 }
204
205 if ( in_array( 'notification-review-delay', $slugs, true ) ) {
206 update_user_meta( get_current_user_id(), '_aioseo_notification_plugin_review_dismissed', strtotime( '+1 week' ) );
207 }
208
209 return new \WP_REST_Response( [
210 'success' => true,
211 'notifications' => Models\Notification::getNotifications()
212 ], 200 );
213 }
214 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Route class for the API.
11 *
12 * @since 4.0.0
13 */
14 class Ping {
15 /**
16 * Returns a success if the API is alive.
17 *
18 * @since 4.0.0
19 *
20 * @param \WP_REST_Request $request The REST Request
21 * @return \WP_REST_Response The response.
22 */
23 public static function ping() {
24 return new \WP_REST_Response( [
25 'success' => true
26 ], 200 );
27 }
28 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Route class for the API.
11 *
12 * @since 4.0.0
13 */
14 class Plugins {
15 /**
16 * Installs plugins from vue.
17 *
18 * @since 4.0.0
19 *
20 * @param \WP_REST_Request $request The REST Request
21 * @return \WP_REST_Response The response.
22 */
23 public static function installPlugins( $request ) {
24 $error = esc_html__( 'Installation failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
25 $body = $request->get_json_params();
26
27 if ( ! is_array( $body ) ) {
28 return new \WP_REST_Response( [
29 'success' => false,
30 'message' => $error
31 ], 400 );
32 }
33
34 if ( ! aioseo()->addons->canInstall() ) {
35 return new \WP_REST_Response( [
36 'success' => false,
37 'message' => $error
38 ], 400 );
39 }
40
41 $failed = [];
42 $completed = [];
43 foreach ( $body as $plugin ) {
44 if ( empty( $plugin['plugin'] ) ) {
45 return new \WP_REST_Response( [
46 'success' => false,
47 'message' => $error
48 ], 400 );
49 }
50
51 $result = aioseo()->addons->installAddon( $plugin['plugin'] );
52 if ( ! $result ) {
53 $failed[] = $plugin['plugin'];
54 } else {
55 $completed[ $plugin['plugin'] ] = $result;
56 }
57 }
58
59 return new \WP_REST_Response( [
60 'success' => true,
61 'completed' => $completed,
62 'failed' => $failed
63 ], 200 );
64 }
65
66 /**
67 * Upgrade plugins from vue.
68 *
69 * @since 4.1.6
70 *
71 * @param \WP_REST_Request $request The REST Request
72 * @return \WP_REST_Response The response.
73 */
74 public static function upgradePlugins( $request ) {
75 $error = esc_html__( 'Plugin update failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
76 $body = $request->get_json_params();
77
78 if ( ! is_array( $body ) ) {
79 return new \WP_REST_Response( [
80 'success' => false,
81 'message' => $error
82 ], 400 );
83 }
84
85 if ( ! aioseo()->addons->canUpdate() ) {
86 return new \WP_REST_Response( [
87 'success' => false,
88 'message' => $error
89 ], 400 );
90 }
91
92 $failed = [];
93 $completed = [];
94 foreach ( $body as $plugin ) {
95 if ( empty( $plugin['plugin'] ) ) {
96 return new \WP_REST_Response( [
97 'success' => false,
98 'message' => $error
99 ], 400 );
100 }
101
102 $result = aioseo()->addons->upgradeAddon( $plugin['plugin'] );
103 if ( ! $result ) {
104 $failed[] = $plugin['plugin'];
105 } else {
106 $completed[ $plugin['plugin'] ] = aioseo()->addons->getAddon( $plugin['plugin'], true );
107 }
108 }
109
110 return new \WP_REST_Response( [
111 'success' => true,
112 'completed' => $completed,
113 'failed' => $failed
114 ], 200 );
115 }
116
117 /**
118 * Deactivates plugins from vue.
119 *
120 * @since 4.0.0
121 *
122 * @param \WP_REST_Request $request The REST Request
123 * @return \WP_REST_Response The response.
124 */
125 public static function deactivatePlugins( $request ) {
126 $error = esc_html__( 'Deactivation failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
127 $body = $request->get_json_params();
128
129 if ( ! is_array( $body ) ) {
130 return new \WP_REST_Response( [
131 'success' => false,
132 'message' => $error
133 ], 400 );
134 }
135
136 if ( ! current_user_can( 'install_plugins' ) ) {
137 return new \WP_REST_Response( [
138 'success' => false,
139 'message' => $error
140 ], 400 );
141 }
142
143 require_once ABSPATH . 'wp-admin/includes/plugin.php';
144
145 $failed = [];
146 $completed = [];
147 foreach ( $body as $plugin ) {
148 if ( empty( $plugin['plugin'] ) ) {
149 return new \WP_REST_Response( [
150 'success' => false,
151 'message' => $error
152 ], 400 );
153 }
154
155 // Activate the plugin silently.
156 $activated = deactivate_plugins( $plugin['plugin'] );
157
158 if ( is_wp_error( $activated ) ) {
159 $failed[] = $plugin['plugin'];
160 }
161
162 $completed[] = $plugin['plugin'];
163 }
164
165 return new \WP_REST_Response( [
166 'success' => true,
167 'completed' => $completed,
168 'failed' => $failed
169 ], 200 );
170 }
171 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Models;
10
11 /**
12 * Route class for the API.
13 *
14 * @since 4.0.0
15 */
16 class Sitemaps {
17 /**
18 * Delete all static sitemap files.
19 *
20 * @since 4.0.0
21 *
22 * @return \WP_REST_Response The response.
23 */
24 public static function deleteStaticFiles() {
25 require_once( ABSPATH . 'wp-admin/includes/file.php' );
26 $files = list_files( get_home_path(), 1 );
27 if ( ! count( $files ) ) {
28 return;
29 }
30
31 $isGeneralSitemapStatic = aioseo()->options->sitemap->general->advancedSettings->enable &&
32 in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) &&
33 ! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic;
34
35 $detectedFiles = [];
36 if ( ! $isGeneralSitemapStatic ) {
37 foreach ( $files as $filename ) {
38 if ( preg_match( '#.*sitemap.*#', $filename ) ) {
39 // We don't want to delete the video sitemap here at all.
40 $isVideoSitemap = preg_match( '#.*video.*#', $filename ) ? true : false;
41 if ( ! $isVideoSitemap ) {
42 $detectedFiles[] = $filename;
43 }
44 }
45 }
46 }
47
48 if ( ! count( $detectedFiles ) ) {
49 return new \WP_REST_Response( [
50 'success' => false,
51 'message' => 'No sitemap files found.'
52 ], 400 );
53 }
54
55 $wpfs = aioseo()->helpers->wpfs();
56 if ( ! is_object( $wpfs ) ) {
57 return new \WP_REST_Response( [
58 'success' => false,
59 'message' => 'No access to filesystem.'
60 ], 400 );
61 }
62
63 foreach ( $detectedFiles as $file ) {
64 @$wpfs->delete( $file, false, 'f' );
65 }
66
67 Models\Notification::deleteNotificationByName( 'sitemap-static-files' );
68
69 return new \WP_REST_Response( [
70 'success' => true,
71 'notifications' => Models\Notification::getNotifications()
72 ], 200 );
73 }
74
75 /**
76 * Deactivates conflicting plugins.
77 *
78 * @since 4.0.0
79 *
80 * @param \WP_REST_Request $request The REST Request
81 * @return \WP_REST_Response The response.
82 */
83 public static function deactivateConflictingPlugins() {
84 $error = esc_html__( 'Deactivation failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
85 if ( ! current_user_can( 'install_plugins' ) ) {
86 return new \WP_REST_Response( [
87 'success' => false,
88 'message' => $error
89 ], 400 );
90 }
91
92 $plugins = array_merge(
93 aioseo()->conflictingPlugins->getConflictingPlugins( 'seo' ),
94 aioseo()->conflictingPlugins->getConflictingPlugins( 'sitemap' )
95 );
96
97 require_once ABSPATH . 'wp-admin/includes/plugin.php';
98
99 foreach ( $plugins as $pluginPath ) {
100 if ( is_plugin_active( $pluginPath ) ) {
101 deactivate_plugins( $pluginPath );
102 }
103 }
104
105 Models\Notification::deleteNotificationByName( 'conflicting-plugins' );
106
107 return new \WP_REST_Response( [
108 'success' => true,
109 'notifications' => Models\Notification::getNotifications()
110 ], 200 );
111 }
112
113 /**
114 * Check whether the slug for the HTML sitemap is not in use.
115 *
116 * @since 4.1.3
117 *
118 * @param \WP_REST_Request $request The REST Request
119 * @return \WP_REST_Response The response.
120 */
121 public static function validateHtmlSitemapSlug( $request ) {
122 $body = $request->get_json_params();
123
124 $pageUrl = ! empty( $body['pageUrl'] ) ? sanitize_text_field( $body['pageUrl'] ) : '';
125 if ( empty( $pageUrl ) ) {
126 return new \WP_REST_Response( [
127 'success' => false,
128 'message' => 'No path was provided.'
129 ], 400 );
130 }
131
132 $pageUrl = wp_parse_url( $pageUrl );
133 if ( empty( $pageUrl['path'] ) ) {
134 return new \WP_REST_Response( [
135 'success' => false,
136 'message' => 'The given path is invalid.'
137 ], 400 );
138 }
139
140 $path = trim( $pageUrl['path'], '/' );
141 $exists = aioseo()->helpers->pathExists( $path );
142
143 return new \WP_REST_Response( [
144 'exists' => $exists
145 ], 200 );
146 }
147 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Route class for the API.
11 *
12 * @since 4.0.0
13 */
14 class Tags {
15 /**
16 * Get all Tags.
17 *
18 * @since 4.0.0
19 *
20 * @param \WP_REST_Request $request The REST Request
21 * @return \WP_REST_Response The response.
22 */
23 public static function getTags() {
24 return new \WP_REST_Response( [
25 'tags' => aioseo()->tags->all( true )
26 ], 200 );
27 }
28 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Api;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Models;
10 use AIOSEO\Plugin\Common\Tools as CommonTools;
11
12 /**
13 * Route class for the API.
14 *
15 * @since 4.0.0
16 */
17 class Tools {
18 /**
19 * Import and delete the static robots.txt.
20 *
21 * @since 4.0.0
22 *
23 * @param \WP_REST_Request $request The REST Request
24 * @return \WP_REST_Response The response.
25 */
26 public static function importRobotsTxt( $request ) {
27 $body = $request->get_json_params();
28 $network = ! empty( $body['network'] ) ? (bool) $body['network'] : false;
29
30 if ( ! aioseo()->robotsTxt->importPhysicalRobotsTxt( $network ) ) {
31 return new \WP_REST_Response( [
32 'success' => false,
33 'message' => __( 'There was an error importing the physical robots.txt file.', 'all-in-one-seo-pack' )
34 ], 400 );
35 }
36
37 aioseo()->options->tools->robots->enable = true;
38
39 if ( ! aioseo()->robotsTxt->deletePhysicalRobotsTxt() ) {
40 return new \WP_REST_Response( [
41 'success' => false,
42 'message' => __( 'There was an error deleting the physical robots.txt file.', 'all-in-one-seo-pack' )
43 ], 400 );
44 }
45
46 Models\Notification::deleteNotificationByName( 'robots-physical-file' );
47
48 return new \WP_REST_Response( [
49 'success' => true,
50 'notifications' => Models\Notification::getNotifications()
51 ], 200 );
52 }
53
54 /**
55 * Delete the static robots.txt.
56 *
57 * @since 4.0.0
58 *
59 * @param \WP_REST_Request $request The REST Request
60 * @return \WP_REST_Response The response.
61 */
62 public static function deleteRobotsTxt() {
63 if ( ! aioseo()->robotsTxt->deletePhysicalRobotsTxt() ) {
64 return new \WP_REST_Response( [
65 'success' => false,
66 'message' => __( 'There was an error deleting the physical robots.txt file.', 'all-in-one-seo-pack' )
67 ], 400 );
68 }
69
70 Models\Notification::deleteNotificationByName( 'robots-physical-file' );
71
72 return new \WP_REST_Response( [
73 'success' => true,
74 'notifications' => Models\Notification::getNotifications()
75 ], 200 );
76 }
77
78 /**
79 * Email debug info.
80 *
81 * @since 4.0.0
82 *
83 * @param \WP_REST_Request $request The REST Request
84 * @return \WP_REST_Response The response.
85 */
86 public static function emailDebugInfo( $request ) {
87 $body = $request->get_json_params();
88 $email = ! empty( $body['email'] ) ? $body['email'] : null;
89
90 if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
91 return new \WP_REST_Response( [
92 'success' => false,
93 'message' => 'invalid-email-address'
94 ], 400 );
95 }
96
97 require_once ABSPATH . 'wp-admin/includes/update.php';
98
99 // Translators: 1 - The plugin name ("All in One SEO"), 2 - The Site URL.
100 $html = sprintf( __( '%1$s Debug Info from %2$s', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME, aioseo()->helpers->getSiteDomain() ) . "\r\n------------------\r\n\r\n";
101 $info = CommonTools\SystemStatus::getSystemStatusInfo();
102 foreach ( $info as $group ) {
103 if ( empty( $group['results'] ) ) {
104 continue;
105 }
106
107 $html .= "\r\n\r\n{$group['label']}\r\n";
108 foreach ( $group['results'] as $data ) {
109 $html .= "{$data['header']}: {$data['value']}\r\n";
110 }
111 }
112
113 if ( ! wp_mail(
114 $email,
115 // Translators: 1 - The plugin name ("All in One SEO).
116 sprintf( __( '%1$s Debug Info', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME ),
117 $html
118 ) ) {
119 return new \WP_REST_Response( [
120 'success' => false,
121 'message' => __( 'Unable to send debug email, please check your email send settings and try again.', 'all-in-one-seo-pack' )
122 ], 400 );
123 }
124
125 return new \WP_REST_Response( [
126 'success' => true
127 ], 200 );
128 }
129
130 /**
131 * Create a settings backup.
132 *
133 * @since 4.0.0
134 *
135 * @param \WP_REST_Request $request The REST Request
136 * @return \WP_REST_Response The response.
137 */
138 public static function createBackup() {
139 aioseo()->backup->create();
140
141 return new \WP_REST_Response( [
142 'success' => true,
143 'backups' => array_reverse( aioseo()->backup->all() )
144 ], 200 );
145 }
146
147 /**
148 * Restore a settings backup.
149 *
150 * @since 4.0.0
151 *
152 * @param \WP_REST_Request $request The REST Request
153 * @return \WP_REST_Response The response.
154 */
155 public static function restoreBackup( $request ) {
156 $body = $request->get_json_params();
157 $backup = ! empty( $body['backup'] ) ? (int) $body['backup'] : null;
158 if ( empty( $backup ) ) {
159 return new \WP_REST_Response( [
160 'success' => false,
161 'backups' => array_reverse( aioseo()->backup->all() )
162 ], 400 );
163 }
164
165 aioseo()->backup->restore( $backup );
166
167 return new \WP_REST_Response( [
168 'success' => true,
169 'backups' => array_reverse( aioseo()->backup->all() ),
170 'options' => aioseo()->options->all(),
171 'internalOptions' => aioseo()->internalOptions->all()
172 ], 200 );
173 }
174
175 /**
176 * Delete a settings backup.
177 *
178 * @since 4.0.0
179 *
180 * @param \WP_REST_Request $request The REST Request
181 * @return \WP_REST_Response The response.
182 */
183 public static function deleteBackup( $request ) {
184 $body = $request->get_json_params();
185 $backup = ! empty( $body['backup'] ) ? (int) $body['backup'] : null;
186 if ( empty( $backup ) ) {
187 return new \WP_REST_Response( [
188 'success' => false,
189 'backups' => array_reverse( aioseo()->backup->all() )
190 ], 400 );
191 }
192
193 aioseo()->backup->delete( $backup );
194
195 return new \WP_REST_Response( [
196 'success' => true,
197 'backups' => array_reverse( aioseo()->backup->all() )
198 ], 200 );
199 }
200
201 /**
202 * Save the .htaccess file.
203 *
204 * @since 4.0.0
205 *
206 * @param \WP_REST_Request $request The REST Request
207 * @return \WP_REST_Response The response.
208 */
209 public static function saveHtaccess( $request ) {
210 $body = $request->get_json_params();
211 $htaccess = ! empty( $body['htaccess'] ) ? sanitize_textarea_field( $body['htaccess'] ) : '';
212
213 if ( empty( $htaccess ) ) {
214 return new \WP_REST_Response( [
215 'success' => false,
216 'message' => __( '.htaccess file is empty.', 'all-in-one-seo-pack' )
217 ], 400 );
218 }
219
220 $htaccess = aioseo()->helpers->decodeHtmlEntities( $htaccess );
221 if ( ! aioseo()->htaccess->saveContents( $htaccess ) ) {
222 return new \WP_REST_Response( [
223 'success' => false,
224 'message' => __( 'An error occurred while trying to write to the .htaccess file. Please try again later.', 'all-in-one-seo-pack' )
225 ], 400 );
226 }
227
228 return new \WP_REST_Response( [
229 'success' => true
230 ], 200 );
231 }
232
233 /**
234 * Clear the passed in log.
235 *
236 * @since 4.0.0
237 *
238 * @param \WP_REST_Request $request The REST Request
239 * @return \WP_REST_Response The response.
240 */
241 public static function clearLog( $request ) {
242 $body = $request->get_json_params();
243 $log = ! empty( $body['log'] ) ? $body['log'] : null;
244
245 $logSize = 0;
246 switch ( $log ) {
247 case 'badBotBlockerLog':
248 aioseo()->badBotBlocker->clearLog();
249 $logSize = aioseo()->badBotBlocker->getLogSize();
250 break;
251 }
252
253 return new \WP_REST_Response( [
254 'success' => true,
255 'logSize' => aioseo()->helpers->convertFileSize( $logSize )
256 ], 200 );
257 }
258 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Breadcrumbs;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Breadcrumb Block.
11 *
12 * @since 4.1.1
13 */
14 class Block extends \AIOSEO\Plugin\Common\Utils\Blocks {
15 /**
16 * Class constructor.
17 *
18 * @since 4.1.1
19 */
20 public function __construct() {
21 parent::__construct();
22 }
23
24 /**
25 * Registers the block.
26 *
27 * @since 4.1.1
28 *
29 * @return void
30 */
31 public function register() {
32 register_block_type(
33 'aioseo/breadcrumbs', [
34 'render_callback' => [ $this, 'render' ]
35 ]
36 );
37 }
38
39 /**
40 * Renders the block.
41 *
42 * @since 4.1.1
43 *
44 * @param array $blockAttributes The block attributes.
45 * @return string The output from the output buffering.
46 */
47 public function render( $blockAttributes ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
48 $postId = ! empty( $_GET['post_id'] ) ? wp_unslash( $_GET['post_id'] ) : false; // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized
49 if ( $this->isGBEditor() && ! empty( $postId ) ) {
50 return aioseo()->breadcrumbs->frontend->sideDisplay( false, 'post' === get_post_type( $postId ) ? 'post' : 'single', get_post( $postId ) );
51 }
52
53 return aioseo()->breadcrumbs->frontend->display( false );
54 }
55 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Breadcrumbs;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Class Frontend.
11 *
12 * @since 4.1.1
13 */
14 class Frontend {
15 /**
16 * A local 'cached' crumb array.
17 *
18 * @since 4.1.1
19 *
20 * @var array
21 */
22 public $breadcrumbs = [];
23
24 /**
25 * Gets the current page's breadcrumbs.
26 *
27 * @since 4.1.1
28 *
29 * @return array
30 */
31 public function getBreadcrumbs() {
32 if ( ! empty( $this->breadcrumbs ) ) {
33 return apply_filters( 'aioseo_breadcrumbs_trail', $this->breadcrumbs );
34 }
35
36 $type = '';
37 $reference = get_queried_object();
38 // These types need the queried object for reference.
39 if ( is_object( $reference ) ) {
40 if ( is_single() ) {
41 $type = 'single';
42 }
43
44 if ( is_singular( 'post' ) ) {
45 $type = 'post';
46 }
47
48 if ( is_page() && ! is_front_page() ) {
49 $type = 'page';
50 }
51
52 if ( is_category() || is_tag() ) {
53 $type = 'category';
54 }
55
56 if ( is_tax() ) {
57 $type = 'taxonomy';
58 }
59
60 if ( is_post_type_archive() ) {
61 $type = 'postTypeArchive';
62 }
63
64 if ( is_author() ) {
65 $type = 'author';
66 }
67
68 if ( is_home() ) {
69 $type = 'blog';
70 }
71 }
72
73 if ( is_date() ) {
74 $type = 'date';
75 $reference = [
76 'year' => get_query_var( 'year' ),
77 'month' => get_query_var( 'monthnum' ),
78 'day' => get_query_var( 'day' )
79 ];
80 }
81
82 if ( is_search() ) {
83 $type = 'search';
84 $reference = get_search_query();
85 }
86
87 if ( is_404() ) {
88 $type = 'notFound';
89 }
90
91 $paged = false;
92 if ( is_paged() || ( is_singular() && 1 < get_query_var( 'page' ) ) ) {
93 global $wp;
94 $paged = [
95 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' ),
96 'link' => home_url( $wp->request )
97 ];
98 }
99
100 return apply_filters( 'aioseo_breadcrumbs_trail', aioseo()->breadcrumbs->buildBreadcrumbs( $type, $reference, $paged ) );
101 }
102
103 /**
104 * Helper function to display breadcrumbs for a specific page.
105 *
106 * @since 4.1.1
107 *
108 * @param bool $echo Print out the breadcrumb.
109 * @param string $type The type for the breadcrumb.
110 * @param string $reference A reference to be used for rendering the breadcrumb.
111 * @return string|void A html breadcrumb.
112 */
113 public function sideDisplay( $echo = true, $type = '', $reference = '' ) {
114 // Save previously built breadcrumbs.
115 $previousCrumbs = $this->breadcrumbs;
116
117 // Build and run the sideDisplay.
118 $this->breadcrumbs = aioseo()->breadcrumbs->buildBreadcrumbs( $type, $reference );
119 $sideDisplay = $this->display( $echo );
120
121 // Restore previously built breadcrumbs.
122 $this->breadcrumbs = $previousCrumbs;
123
124 return $sideDisplay;
125 }
126
127 /**
128 * Display a generic breadcrumb preview.
129 *
130 * @since 4.1.5
131 *
132 * @param bool $echo Print out the breadcrumb.
133 * @param string $label The preview crumb label.
134 * @return string|void A html breadcrumb.
135 */
136 public function preview( $echo = true, $label = '' ) {
137 // Translators: "Crumb" refers to a part of the breadcrumb trail.
138 $label = empty( $label ) ? __( 'Sample Crumb', 'all-in-one-seo-pack' ) : $label;
139
140 return $this->sideDisplay( $echo, 'preview', $label );
141 }
142
143 /**
144 * Display the breadcrumb in the frontend.
145 *
146 * @since 4.1.1
147 *
148 * @param bool $echo Print out the breadcrumb.
149 * @return string|void A html breadcrumb.
150 */
151 public function display( $echo = true ) {
152 if ( ! aioseo()->options->breadcrumbs->enable || ! apply_filters( 'aioseo_breadcrumbs_output', true ) ) {
153 return;
154 }
155
156 $breadcrumbs = $this->getBreadcrumbs();
157 if ( empty( $breadcrumbs ) ) {
158 return;
159 }
160
161 $breadcrumbsCount = count( $breadcrumbs );
162
163 $display = '<div class="aioseo-breadcrumbs">';
164 foreach ( $breadcrumbs as $breadcrumb ) {
165 -- $breadcrumbsCount;
166
167 $breadcrumbDisplay = $this->breadcrumbToDisplay( $breadcrumb );
168
169 // Strip link from Last crumb.
170 if (
171 0 === $breadcrumbsCount &&
172 aioseo()->breadcrumbs->showCurrentItem() &&
173 ! $this->linkCurrentItem() &&
174 'default' === $breadcrumbDisplay['templateType']
175 ) {
176 $breadcrumbDisplay['template'] = $this->stripLink( $breadcrumbDisplay['template'] );
177 }
178
179 $display .= $breadcrumbDisplay['template'];
180
181 if ( 0 < $breadcrumbsCount ) {
182 $display .= $this->getSeparator();
183 }
184 }
185 $display .= '</div>';
186
187 $display = wp_kses_post( $display );
188
189 if ( $echo ) {
190 echo $display; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
191 }
192
193 return $display;
194 }
195
196 /**
197 * Turns a crumb array into a rendered html crumb.
198 *
199 * @since 4.1.1
200 *
201 * @param array $item The crumb array.
202 * @return string|void The crumb html.
203 */
204 protected function breadcrumbToDisplay( $item ) {
205 $templateItem = $this->getCrumbTemplate( $item );
206
207 if ( empty( $templateItem['template'] ) ) {
208 return;
209 }
210
211 // Do tags.
212 $templateItem['template'] = aioseo()->breadcrumbs->tags->replaceTags( $templateItem['template'], $item );
213
214 // Restore html.
215 $templateItem['template'] = aioseo()->helpers->decodeHtmlEntities( $templateItem['template'] );
216
217 // Remove html link if it comes back from the template but we passed no links to it.
218 if ( empty( $item['link'] ) ) {
219 $templateItem['template'] = $this->stripLink( $templateItem['template'] );
220 }
221
222 // Allow shortcodes to run in the final html.
223 $templateItem['template'] = do_shortcode( $templateItem['template'] );
224
225 // Final security cleaning.
226 $templateItem['template'] = wp_kses_post( $templateItem['template'] );
227
228 return $templateItem;
229 }
230
231 /**
232 * Helper function to get a crumb's template.
233 *
234 * @since 4.1.1
235 *
236 * @param array $crumb The crumb array.
237 * @return string The html template.
238 */
239 protected function getTemplate( $crumb ) {
240 return $this->getDefaultTemplate( $crumb );
241 }
242
243 /**
244 * Helper function to get a crumb's template.
245 *
246 * @since 4.1.1
247 *
248 * @param array $crumb The crumb array.
249 * @return array The template type and html.
250 */
251 protected function getCrumbTemplate( $crumb ) {
252 return [
253 'templateType' => 'default',
254 'template' => $this->getTemplate( $crumb )
255 ];
256 }
257
258 /**
259 * Default html template.
260 *
261 * @since 4.1.1
262 *
263 * @param string $type The crumb's type.
264 * @param mixed $reference The crumb's reference.
265 * @return string The default crumb template.
266 */
267 public function getDefaultTemplate( $type = '', $reference = '' ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
268 return <<<TEMPLATE
269 <span class="aioseo-breadcrumb">
270 <a href="#breadcrumb_link" title="#breadcrumb_label">#breadcrumb_label</a>
271 </span>
272 TEMPLATE;
273 }
274
275 /**
276 * Helper function to strip a html link from the crumb.
277 *
278 * @since 4.1.1
279 *
280 * @param string $html The crumb's html.
281 * @return string A crumb html without links.
282 */
283 public function stripLink( $html ) {
284 return preg_replace( '/<a\s.*?>|<\/a>/is', '', $html );
285 }
286
287 /**
288 * Get the breadcrumb configured separator.
289 *
290 * @since 4.1.1
291 *
292 * @return string The separator html.
293 */
294 public function getSeparator() {
295 $separator = apply_filters( 'aioseo_breadcrumbs_separator_symbol', aioseo()->options->breadcrumbs->separator );
296
297 return apply_filters( 'aioseo_breadcrumbs_separator', '<span class="aioseo-breadcrumb-separator">' . esc_html( $separator ) . '</span>' );
298 }
299
300 /**
301 * Function to filter the linkCurrentItem option.
302 *
303 * @since 4.1.3
304 *
305 * @return bool Link current item.
306 */
307 public function linkCurrentItem() {
308 return apply_filters( 'aioseo_breadcrumbs_link_current_item', aioseo()->options->breadcrumbs->linkCurrentItem );
309 }
310 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Breadcrumbs;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Class Shortcode.
11 *
12 * @since 4.1.1
13 */
14 class Shortcode {
15 /**
16 * Shortcode constructor.
17 *
18 * @since 4.1.1
19 */
20 public function __construct() {
21 add_shortcode( 'aioseo_breadcrumbs', [ $this, 'display' ] );
22 }
23
24 /**
25 * Shortcode callback.
26 *
27 * @since 4.1.1
28 *
29 * @return string|void The breadcrumb html.
30 */
31 public function display() {
32 return aioseo()->breadcrumbs->frontend->display( false );
33 }
34 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Breadcrumbs;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Class Widget.
11 *
12 * @since 4.1.1
13 */
14 class Widget extends \WP_Widget {
15 /**
16 * Class constructor.
17 *
18 * @since 4.1.1
19 */
20 public function __construct() {
21 // Widget defaults.
22 $this->defaults = [
23 'title' => ''
24 ];
25
26 // Widget Slug.
27 $widgetSlug = 'aioseo-breadcrumb-widget';
28
29 // Widget basics.
30 $widgetOps = [
31 'classname' => $widgetSlug,
32 'description' => esc_html__( 'Display the current page breadcrumb.', 'all-in-one-seo-pack' ),
33 ];
34
35 // Widget controls.
36 $controlOps = [
37 'id_base' => $widgetSlug,
38 ];
39
40 // Load widget.
41 parent::__construct( $widgetSlug, esc_html__( 'AIOSEO - Breadcrumbs', 'all-in-one-seo-pack' ), $widgetOps, $controlOps );
42 }
43
44 /**
45 * Widget callback.
46 *
47 * @since 4.1.1
48 *
49 * @param array $args Widget args.
50 * @param array $instance The widget instance options.
51 * @return void
52 */
53 public function widget( $args, $instance ) {
54 // Merge with defaults.
55 $instance = wp_parse_args( (array) $instance, $this->defaults );
56
57 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
58
59 // Title.
60 if ( ! empty( $instance['title'] ) ) {
61 echo $args['before_title'] . apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
62 'widget_title', $instance['title'], $instance, $this->id_base
63 ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
64 }
65
66 // Breadcrumb.
67 ! empty( $_GET['legacy-widget-preview'] ) ? aioseo()->breadcrumbs->frontend->preview() : aioseo()->breadcrumbs->frontend->display();
68
69 // Workaround for a bug in the Gutenberg widget preview.
70 echo '<span style="display: none">a</span>'; // TODO: remove this when the preview bug is fixed.
71
72 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
73 }
74
75 /**
76 * Widget option update.
77 *
78 * @since 4.1.1
79 *
80 * @param array $newInstance New instance options.
81 * @param array $oldInstance Old instance options.
82 * @return array Processed new instance options.
83 */
84 public function update( $newInstance, $oldInstance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
85 $newInstance['title'] = wp_strip_all_tags( $newInstance['title'] );
86
87 return $newInstance;
88 }
89
90 /**
91 * Widget options form.
92 *
93 * @since 4.1.1
94 *
95 * @param array $instance The widget instance options.
96 * @return void
97 */
98 public function form( $instance ) {
99 // Merge with defaults.
100 $instance = wp_parse_args( (array) $instance, $this->defaults );
101 ?>
102 <p>
103 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
104 <?php echo esc_html( __( 'Title:', 'all-in-one-seo-pack' ) ); ?>
105 </label>
106 <input
107 type="text"
108 id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
109 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
110 value="<?php echo esc_attr( $instance['title'] ); ?>"
111 class="widefat"
112 />
113 </p>
114 <?php
115 }
116 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Help;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Help {
10 /**
11 * Source of notifications content.
12 *
13 * @since 4.0.0
14 *
15 * @var string
16 */
17 private $url = 'https://cdn.aioseo.com/wp-content/docs.json';
18
19 /**
20 * Settings.
21 *
22 * @since 4.0.0
23 *
24 * @var array
25 */
26 private $settings = [
27 'docsUrl' => 'https://aioseo.com/docs/',
28 'supportTicketUrl' => 'https://aioseo.com/account/support/',
29 'upgradeUrl' => 'https://aioseo.com/pricing/',
30 ];
31
32 /**
33 * Gets the URL for the notifications api.
34 *
35 * @since 4.0.0
36 *
37 * @return string The URL to use for the api requests.
38 */
39 private function getUrl() {
40 if ( defined( 'AIOSEO_DOCS_FEED_URL' ) ) {
41 return AIOSEO_DOCS_FEED_URL;
42 }
43
44 return $this->url;
45 }
46
47 /**
48 * Get docs from the cache.
49 *
50 * @since 4.0.0
51 *
52 * @return array Docs data.
53 */
54 public function getDocs() {
55 $aioseoAdminHelpDocs = aioseo()->cache->get( 'admin_help_docs' );
56 $aioseoAdminHelpDocsCacheTime = WEEK_IN_SECONDS;
57 if ( null === $aioseoAdminHelpDocs ) {
58 $request = wp_remote_get( $this->getUrl() );
59
60 if ( is_wp_error( $request ) ) {
61 return false;
62 }
63
64 $response = $request['response'];
65
66 if ( ( $response['code'] <= 200 ) && ( $response['code'] > 299 ) ) {
67 $aioseoAdminHelpDocsCacheTime = 10 * MINUTE_IN_SECONDS;
68 }
69 $aioseoAdminHelpDocs = wp_remote_retrieve_body( $request );
70 aioseo()->cache->update( 'admin_help_docs', $aioseoAdminHelpDocs, $aioseoAdminHelpDocsCacheTime );
71 }
72
73 return $aioseoAdminHelpDocs;
74 }
75 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Contains helper methods for the import from other plugins.
11 *
12 * @since 4.0.0
13 */
14 abstract class Helpers {
15 /**
16 * Converts macros to smart tags.
17 *
18 * @since 4.1.3
19 *
20 * @param string $value The string with macros.
21 * @return string The string with macros converted.
22 */
23 abstract public function macrosToSmartTags( $value );
24
25 /**
26 * Maps a list of old settings from V3 to their counterparts in V4.
27 *
28 * @since 4.0.0
29 *
30 * @param array $mappings The old settings, mapped to their new settings.
31 * @param array $group The old settings group.
32 * @param bool $convertMacros Whether to convert the old V3 macros to V4 smart tags.
33 * @return void
34 */
35 public function mapOldToNew( $mappings, $group, $convertMacros = false ) {
36 if (
37 ! is_array( $mappings ) ||
38 ! is_array( $group ) ||
39 ! count( $mappings ) ||
40 ! count( $group )
41 ) {
42 return;
43 }
44
45 $mainOptions = aioseo()->options->noConflict();
46 $dynamicOptions = aioseo()->dynamicOptions->noConflict();
47 foreach ( $mappings as $name => $values ) {
48 if ( ! isset( $group[ $name ] ) ) {
49 continue;
50 }
51
52 $error = false;
53 $options = ! empty( $values['dynamic'] ) ? $dynamicOptions : $mainOptions;
54 $lastOption = '';
55 for ( $i = 0; $i < count( $values['newOption'] ); $i++ ) {
56 $lastOption = $values['newOption'][ $i ];
57 if ( ! $options->has( $lastOption, false ) ) {
58 $error = true;
59 break;
60 };
61 if ( count( $values['newOption'] ) - 1 !== $i ) {
62 $options = $options->$lastOption;
63 }
64 }
65
66 if ( $error ) {
67 continue;
68 }
69
70 switch ( $values['type'] ) {
71 case 'boolean':
72 if ( ! empty( $group[ $name ] ) ) {
73 $options->$lastOption = true;
74 break;
75 }
76 $options->$lastOption = false;
77 break;
78 case 'integer':
79 case 'float':
80 $value = aioseo()->helpers->sanitizeOption( $group[ $name ] );
81 if ( $value ) {
82 $options->$lastOption = $value;
83 }
84 break;
85 default:
86 $value = $group[ $name ];
87 if ( $convertMacros ) {
88 $value = $this->macrosToSmartTags( $value );
89 }
90 $options->$lastOption = aioseo()->helpers->sanitizeOption( $value );
91 break;
92 }
93 }
94 }
95 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Imports the settings and meta data from other plugins.
11 *
12 * @since 4.0.0
13 */
14 abstract class Importer {
15 /**
16 * Starts the import.
17 *
18 * @since 4.0.0
19 *
20 * @param array $options What the user wants to import.
21 * @return void
22 */
23 public function doImport( $options = [] ) {
24 if ( empty( $options ) ) {
25 $this->importSettings();
26 $this->importPostMeta();
27 $this->importTermMeta();
28
29 return;
30 }
31
32 foreach ( $options as $optionName ) {
33 switch ( $optionName ) {
34 case 'settings':
35 $this->importSettings();
36 break;
37 case 'postMeta':
38 $this->postMeta->scheduleImport();
39 break;
40 default:
41 break;
42 }
43 }
44 }
45 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
10
11 /**
12 * Migrates the General Settings.
13 *
14 * @since 4.0.0
15 */
16 class GeneralSettings {
17 /**
18 * Class constructor.
19 *
20 * @since 4.0.0
21 */
22 public function __construct() {
23 $this->options = get_option( 'rank-math-options-general' );
24 if ( empty( $this->options ) ) {
25 return;
26 }
27
28 $this->isTruSeoDisabled();
29 $this->migrateRedirectAttachments();
30 $this->migrateRssContentSettings();
31
32 $settings = [
33 'google_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'google' ] ],
34 'bing_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'bing' ] ],
35 'yandex_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'yandex' ] ],
36 'baidu_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'baidu' ] ],
37 'pinterest_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'pinterest' ] ],
38 ];
39
40 aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
41 }
42
43 /**
44 * Checks whether TruSEO should be disabled.
45 *
46 * @since 4.0.0
47 *
48 * @return void
49 */
50 private function isTruSeoDisabled() {
51 if ( ! empty( $this->options['frontend_seo_score'] ) ) {
52 aioseo()->options->advanced->truSeo = 'on' === $this->options['frontend_seo_score'];
53 }
54 }
55
56 /**
57 * Migrates the Redirect Attachments setting.
58 *
59 * @since 4.0.0
60 *
61 * @return void
62 */
63 private function migrateRedirectAttachments() {
64 if ( isset( $this->options['attachment_redirect_urls'] ) ) {
65 if ( 'on' === $this->options['attachment_redirect_urls'] ) {
66 aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'attachment_parent';
67 } else {
68 aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'disabled';
69 }
70 }
71 }
72
73 /**
74 * Migrates the RSS content settings.
75 *
76 * @since 4.0.0
77 *
78 * @return void
79 */
80 private function migrateRssContentSettings() {
81 if ( isset( $this->options['rss_before_content'] ) ) {
82 aioseo()->options->rssContent->before = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_before_content'] ) );
83 }
84
85 if ( isset( $this->options['rss_after_content'] ) ) {
86 aioseo()->options->rssContent->after = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_after_content'] ) );
87 }
88 }
89 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\ImportExport;
10
11 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
12
13 /**
14 * Contains helper methods for the import from Rank Math.
15 *
16 * @since 4.0.0
17 */
18 class Helpers extends ImportExport\Helpers {
19 /**
20 * Converts the macros from Rank Math to our own smart tags.
21 *
22 * @since 4.0.0
23 *
24 * @param string $string The string with macros.
25 * @param string $pageType The page type.
26 * @return string $string The string with smart tags.
27 */
28 public function macrosToSmartTags( $string, $pageType = null ) {
29 $macros = $this->getMacros( $pageType );
30
31 if ( preg_match( '#%BLOGDESCLINK%#', $string ) ) {
32 $blogDescriptionLink = '<a href="' .
33 aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'url' ) ) . '">' .
34 aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'name' ) ) . ' - ' .
35 aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'description' ) ) . '</a>';
36
37 $string = str_replace( '%BLOGDESCLINK%', $blogDescriptionLink, $string );
38 }
39
40 if ( preg_match_all( '#%customfield\(([^%\s]*)\)%#', $string, $matches ) && ! empty( $matches[1] ) ) {
41 foreach ( $matches[1] as $name ) {
42 $string = aioseo()->helpers->pregReplace( "#%customfield\($name\)%#", "#custom_field-$name", $string );
43 }
44 }
45
46 if ( preg_match_all( '#%customterm\(([^%\s]*)\)%#', $string, $matches ) && ! empty( $matches[1] ) ) {
47 foreach ( $matches[1] as $name ) {
48 $string = aioseo()->helpers->pregReplace( "#%customterm\($name\)%#", "#tax_name-$name", $string );
49 }
50 }
51
52 foreach ( $macros as $macro => $tag ) {
53 $string = aioseo()->helpers->pregReplace( "#$macro(?![a-zA-Z0-9_])#im", $tag, $string );
54 }
55
56 // Strip out all remaining tags.
57 $string = aioseo()->helpers->pregReplace( '/%[^\%\s]*\([^\%]*\)%/i', '', aioseo()->helpers->pregReplace( '/%[^\%\s]*%/i', '', $string ) );
58
59 return trim( $string );
60 }
61
62 /**
63 * Returns the macro mappings.
64 *
65 * @since 4.1.1
66 *
67 * @param string $pageType The page type.
68 * @return array $macros The macros.
69 */
70 protected function getMacros( $pageType = null ) {
71 $macros = [
72 '%sitename%' => '#site_title',
73 '%blog_title%' => '#site_title',
74 '%blog_description%' => '#tagline',
75 '%sitedesc%' => '#tagline',
76 '%sep%' => '#separator_sa',
77 '%post_title%' => '#post_title',
78 '%page_title%' => '#post_title',
79 '%postname%' => '#post_title',
80 '%title%' => '#post_title',
81 '%seo_title%' => '#post_title',
82 '%excerpt%' => '#post_excerpt',
83 '%wc_shortdesc%' => '#post_excerpt',
84 '%category%' => '#taxonomy_title',
85 '%term%' => '#taxonomy_title',
86 '%term_description%' => '#taxonomy_description',
87 '%currentdate%' => '#current_date',
88 '%currentday%' => '#current_day',
89 '%currentmonth%' => '#current_month',
90 '%name%' => '#author_first_name #author_last_name',
91 '%author%' => '#author_first_name #author_last_name',
92 '%date%' => '#post_date',
93 '%year%' => '#current_year',
94 '%search_query%' => '#search_term',
95 '%AUTHORLINK%' => '#author_link',
96 '%POSTLINK%' => '#post_link',
97 '%BLOGLINK%' => '#site_link',
98 /* '%seo_description%' => '',
99 '%user_description%' => '',
100 '%wc_price%' => '',
101 '%page%' => '',
102 '%FEATUREDIMAGE%' => '',
103 '%filename%' => '',*/
104 ];
105
106 switch ( $pageType ) {
107 case 'archive':
108 $macros['%title%'] = '#archive_title';
109 break;
110 case 'term':
111 $macros['%title%'] = '#taxonomy_title';
112 break;
113 default:
114 $macros['%title%'] = '#post_title';
115 break;
116 }
117
118 // Strip all other tags.
119 $macros['%[^%]*%'] = '';
120
121 return $macros;
122 }
123 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Models;
10
11 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
12
13 /**
14 * Imports the post meta from Rank Math.
15 *
16 * @since 4.0.0
17 */
18 class PostMeta {
19 /**
20 * Schedules the post meta import.
21 *
22 * @since 4.0.0
23 *
24 * @return void
25 */
26 public function scheduleImport() {
27 try {
28 if ( as_next_scheduled_action( aioseo()->importExport->rankMath->postActionName ) ) {
29 return;
30 }
31
32 if ( ! aioseo()->cache->get( 'import_post_meta_rank_math' ) ) {
33 aioseo()->cache->update( 'import_post_meta_rank_math', time(), WEEK_IN_SECONDS );
34 }
35
36 as_schedule_single_action( time(), aioseo()->importExport->rankMath->postActionName, [], 'aioseo' );
37 } catch ( \Exception $e ) {
38 // Do nothing.
39 }
40 }
41
42 /**
43 * Imports the post meta.
44 *
45 * @since 4.0.0
46 *
47 * @return void
48 */
49 public function importPostMeta() {
50 $postsPerAction = 100;
51 $publicPostTypes = implode( "', '", aioseo()->helpers->getPublicPostTypes( true ) );
52 $timeStarted = gmdate( 'Y-m-d H:i:s', aioseo()->cache->get( 'import_post_meta_rank_math' ) );
53
54 $posts = aioseo()->db
55 ->start( 'posts' . ' as p' )
56 ->select( 'p.ID, p.post_type' )
57 ->join( 'postmeta as pm', '`p`.`ID` = `pm`.`post_id`' )
58 ->leftJoin( 'aioseo_posts as ap', '`p`.`ID` = `ap`.`post_id`' )
59 ->whereRaw( "pm.meta_key LIKE 'rank_math_%'" )
60 ->whereRaw( "( p.post_type IN ( '$publicPostTypes' ) )" )
61 ->whereRaw( "( ap.post_id IS NULL OR ap.updated < '$timeStarted' )" )
62 ->orderBy( 'p.ID DESC' )
63 ->limit( $postsPerAction )
64 ->run()
65 ->result();
66
67 if ( ! $posts || ! count( $posts ) ) {
68 aioseo()->cache->delete( 'import_post_meta_rank_math' );
69
70 return;
71 }
72
73 $mappedMeta = [
74 'rank_math_title' => 'title',
75 'rank_math_description' => 'description',
76 'rank_math_canonical_url' => 'canonical_url',
77 'rank_math_focus_keyword' => 'keyphrases',
78 'rank_math_robots' => '',
79 'rank_math_advanced_robots' => '',
80 'rank_math_facebook_title' => 'og_title',
81 'rank_math_facebook_description' => 'og_description',
82 'rank_math_facebook_image' => 'og_image_custom_url',
83 'rank_math_twitter_use_facebook' => 'twitter_use_og',
84 'rank_math_twitter_title' => 'twitter_title',
85 'rank_math_twitter_description' => 'twitter_description',
86 'rank_math_twitter_image' => 'twitter_image_custom_url',
87 'rank_math_twitter_card_type' => 'twitter_card'
88 ];
89
90 foreach ( $posts as $post ) {
91 $postMeta = aioseo()->db
92 ->start( 'postmeta' . ' as pm' )
93 ->select( 'pm.meta_key, pm.meta_value' )
94 ->where( 'pm.post_id', $post->ID )
95 ->whereRaw( "`pm`.`meta_key` LIKE 'rank_math_%'" )
96 ->run()
97 ->result();
98
99 if ( ! $postMeta || ! count( $postMeta ) ) {
100 continue;
101 }
102
103 $meta = [
104 'post_id' => $post->ID,
105 ];
106
107 foreach ( $postMeta as $record ) {
108 $name = $record->meta_key;
109 $value = $record->meta_value;
110
111 if (
112 ! in_array( $post->post_type, [ 'page', 'attachment' ], true ) &&
113 preg_match( '#^rank_math_schema_([^\s]*)$#', $name, $match ) && ! empty( $match[1] )
114 ) {
115 switch ( $match[1] ) {
116 case 'Article':
117 case 'NewsArticle':
118 case 'BlogPosting':
119 $meta['schema_type'] = 'Article';
120 $meta['schema_type_options'] = wp_json_encode(
121 [ 'article' => [ 'articleType' => $match[1] ] ]
122 );
123 break;
124 default:
125 break;
126 }
127 }
128
129 if ( ! in_array( $name, array_keys( $mappedMeta ), true ) ) {
130 continue;
131 }
132
133 switch ( $name ) {
134 case 'rank_math_focus_keyword':
135 $keyphrase = [
136 'focus' => [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $value ) ],
137 'additional' => []
138 ];
139 $meta['keyphrases'] = wp_json_encode( $keyphrase );
140 break;
141 case 'rank_math_robots':
142 $value = aioseo()->helpers->maybeUnserialize( $value );
143 if ( ! empty( $value ) ) {
144 $meta['robots_default'] = false;
145 foreach ( $value as $robotsName ) {
146 $meta[ "robots_$robotsName" ] = true;
147 }
148 }
149 break;
150 case 'rank_math_advanced_robots':
151 $value = aioseo()->helpers->maybeUnserialize( $value );
152 if ( ! empty( $value['max-snippet'] ) && intval( $value['max-snippet'] ) ) {
153 $meta['robots_max_snippet'] = intval( $value['max-snippet'] );
154 }
155 if ( ! empty( $value['max-video-preview'] ) && intval( $value['max-video-preview'] ) ) {
156 $meta['robots_max_videopreview'] = intval( $value['max-video-preview'] );
157 }
158 if ( ! empty( $value['max-image-preview'] ) ) {
159 $meta['robots_max_imagepreview'] = aioseo()->helpers->sanitizeOption( lcfirst( $value['max-image-preview'] ) );
160 }
161 break;
162 case 'rank_math_facebook_image':
163 $meta['og_image_type'] = 'custom_image';
164 $meta[ $mappedMeta[ $name ] ] = esc_url( $value );
165 break;
166 case 'rank_math_twitter_image':
167 $meta['twitter_image_type'] = 'custom_image';
168 $meta[ $mappedMeta[ $name ] ] = esc_url( $value );
169 break;
170 case 'rank_math_twitter_card_type':
171 preg_match( '#large#', $value, $match );
172 $meta[ $mappedMeta[ $name ] ] = ! empty( $match ) ? 'summary_large_image' : 'summary';
173 break;
174 case 'rank_math_twitter_use_facebook':
175 $meta[ $mappedMeta[ $name ] ] = 'on' === $value;
176 break;
177 case 'rank_math_title':
178 case 'rank_math_description':
179 if ( 'page' === $post->post_type ) {
180 $value = aioseo()->helpers->pregReplace( '#%category%#', '', $value );
181 $value = aioseo()->helpers->pregReplace( '#%excerpt%#', '', $value );
182 }
183 $value = aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value );
184 default:
185 $meta[ $mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
186 break;
187 }
188 }
189
190 $aioseoPost = Models\Post::getPost( $post->ID );
191 $aioseoPost->set( $meta );
192 $aioseoPost->save();
193 }
194
195 if ( count( $posts ) === $postsPerAction ) {
196 try {
197 as_schedule_single_action( time() + 5, aioseo()->importExport->rankMath->postActionName, [], 'aioseo' );
198 } catch ( \Exception $e ) {
199 // Do nothing.
200 }
201 } else {
202 aioseo()->cache->delete( 'import_post_meta_rank_math' );
203 }
204 }
205 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\ImportExport;
10
11 class RankMath extends ImportExport\Importer {
12 /**
13 * A list of plugins to look for to import.
14 *
15 * @since 4.0.0
16 *
17 * @var array
18 */
19 public $plugins = [
20 [
21 'name' => 'Rank Math SEO',
22 'version' => '1.0',
23 'basename' => 'seo-by-rank-math/rank-math.php',
24 'slug' => 'rank-math-seo'
25 ]
26 ];
27
28 /**
29 * The post action name.
30 *
31 * @since 4.0.0
32 *
33 * @var string
34 */
35 public $postActionName = 'aioseo_import_post_meta_rank_math';
36
37 /**
38 * Class constructor.
39 *
40 * @since 4.0.0
41 *
42 * @param ImportExport $importer the ImportExport class.
43 */
44 public function __construct( $importer ) {
45 $this->helpers = new Helpers();
46 $this->postMeta = new PostMeta();
47 add_action( $this->postActionName, [ $this->postMeta, 'importPostMeta' ] );
48
49 $plugins = $this->plugins;
50 foreach ( $plugins as $key => $plugin ) {
51 $plugins[ $key ]['class'] = $this;
52 }
53 $importer->addPlugins( $plugins );
54 }
55
56
57 /**
58 * Imports the settings.
59 *
60 * @since 4.0.0
61 *
62 * @return void
63 */
64 protected function importSettings() {
65 new GeneralSettings();
66 new TitleMeta();
67 new Sitemap();
68 }
69 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
10
11 /**
12 * Migrates the sitemap settings.
13 *
14 * @since 4.0.0
15 */
16 class Sitemap {
17 /**
18 * Class constructor.
19 *
20 * @since 4.0.0
21 */
22 public function __construct() {
23 $this->options = get_option( 'rank-math-options-sitemap' );
24 if ( empty( $this->options ) ) {
25 return;
26 }
27
28 $this->migrateIncludedObjects();
29 $this->migrateIncludeImages();
30 $this->migrateExcludedPosts();
31 $this->migrateExcludedTerms();
32 $this->migrateExcludedRoles();
33
34 $settings = [
35 'items_per_page' => [ 'type' => 'string', 'newOption' => [ 'sitemap', 'general', 'linksPerIndex' ] ],
36 ];
37
38 aioseo()->options->sitemap->general->indexes = true;
39 aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
40 }
41
42 /**
43 * Migrates the included post types and taxonomies.
44 *
45 * @since 4.0.0
46 *
47 * @return void
48 */
49 private function migrateIncludedObjects() {
50 $includedPostTypes = [];
51 $includedTaxonomies = [];
52
53 $allowedPostTypes = array_values( array_diff( aioseo()->helpers->getPublicPostTypes( true ), aioseo()->helpers->getNoindexedPostTypes() ) );
54 foreach ( $allowedPostTypes as $postType ) {
55 foreach ( $this->options as $name => $value ) {
56 if ( preg_match( "#pt_${postType}_sitemap$#", $name, $match ) && 'on' === $this->options[ $name ] ) {
57 $includedPostTypes[] = $postType;
58 }
59 }
60 }
61
62 $allowedTaxonomies = array_values( array_diff( aioseo()->helpers->getPublicTaxonomies( true ), aioseo()->helpers->getNoindexedTaxonomies() ) );
63 foreach ( $allowedTaxonomies as $taxonomy ) {
64 foreach ( $this->options as $name => $value ) {
65 if ( preg_match( "#tax_${taxonomy}_sitemap$#", $name, $match ) && 'on' === $this->options[ $name ] ) {
66 $includedTaxonomies[] = $taxonomy;
67 }
68 }
69 }
70
71 aioseo()->options->sitemap->general->postTypes->included = $includedPostTypes;
72 if ( count( $allowedPostTypes ) !== count( $includedPostTypes ) ) {
73 aioseo()->options->sitemap->general->postTypes->all = false;
74 }
75
76 aioseo()->options->sitemap->general->taxonomies->included = $includedTaxonomies;
77 if ( count( $allowedTaxonomies ) !== count( $includedTaxonomies ) ) {
78 aioseo()->options->sitemap->general->taxonomies->all = false;
79 }
80 }
81
82 /**
83 * Migrates the Redirect Attachments setting.
84 *
85 * @since 4.0.0
86 *
87 * @return void
88 */
89 private function migrateIncludeImages() {
90 if ( ! empty( $this->options['include_images'] ) ) {
91 if ( 'off' === $this->options['include_images'] ) {
92 aioseo()->options->sitemap->general->advancedSettings->enable = true;
93 aioseo()->options->sitemap->general->advancedSettings->excludeImages = true;
94 }
95 }
96 }
97
98 /**
99 * Migrates the posts that are excluded from the sitemap.
100 *
101 * @since 4.0.0
102 *
103 * @return void
104 */
105 private function migrateExcludedPosts() {
106 if ( empty( $this->options['exclude_posts'] ) ) {
107 return;
108 }
109
110 $rmExcludedPosts = array_filter( explode( ',', $this->options['exclude_posts'] ) );
111 $excludedPosts = aioseo()->options->sitemap->general->advancedSettings->excludePosts;
112
113 if ( count( $rmExcludedPosts ) ) {
114 foreach ( $rmExcludedPosts as $rmExcludedPost ) {
115 $post = get_post( trim( $rmExcludedPost ) );
116 if ( ! is_object( $post ) ) {
117 continue;
118 }
119
120 $excludedPost = new \stdClass();
121 $excludedPost->value = $post->ID;
122 $excludedPost->type = $post->post_type;
123 $excludedPost->label = $post->post_title;
124 $excludedPost->link = get_permalink( $post->ID );
125
126 array_push( $excludedPosts, wp_json_encode( $excludedPost ) );
127 }
128 aioseo()->options->sitemap->general->advancedSettings->enable = true;
129 }
130 aioseo()->options->sitemap->general->advancedSettings->excludePosts = $excludedPosts;
131 }
132
133 /**
134 * Migrates the terms that are excluded from the sitemap.
135 *
136 * @since 4.0.0
137 *
138 * @return void
139 */
140 private function migrateExcludedTerms() {
141 if ( empty( $this->options['exclude_terms'] ) ) {
142 return;
143 }
144
145 $rmExcludedTerms = array_filter( explode( ',', $this->options['exclude_terms'] ) );
146 $excludedTerms = aioseo()->options->sitemap->general->advancedSettings->excludeTerms;
147
148 if ( count( $rmExcludedTerms ) ) {
149 foreach ( $rmExcludedTerms as $rmExcludedTerm ) {
150 $term = get_term( trim( $rmExcludedTerm ) );
151 if ( ! is_object( $term ) ) {
152 continue;
153 }
154
155 $excludedTerm = new \stdClass();
156 $excludedTerm->value = $term->term_id;
157 $excludedTerm->type = $term->taxonomy;
158 $excludedTerm->label = $term->name;
159 $excludedTerm->link = get_term_link( $term );
160
161 array_push( $excludedTerms, wp_json_encode( $excludedTerm ) );
162 }
163 aioseo()->options->sitemap->general->advancedSettings->enable = true;
164 }
165 aioseo()->options->sitemap->general->advancedSettings->excludeTerms = $excludedTerms;
166 }
167
168 /**
169 * Migrates the roles that are excluded from GA tracking.
170 *
171 * For some reason, Rank Math stores these in the sitemap settings.
172 *
173 * @since 4.0.0
174 *
175 * @return void
176 */
177 private function migrateExcludedRoles() {
178 if ( empty( $this->options['exclude_users'] ) ) {
179 return;
180 }
181
182 $excludedRoles = [];
183 foreach ( $this->options['exclude_users'] as $k => $v ) {
184 $excludedRoles[] = $k;
185 }
186
187 aioseo()->options->deprecated->webmasterTools->googleAnalytics->excludeUsers = $excludedRoles;
188 }
189 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Migrates the Search Appearance settings.
11 *
12 * @since 4.0.0
13 */
14 abstract class SearchAppearance {
15 /**
16 * The schema graphs we support.
17 *
18 * @since 4.0.0
19 *
20 * @var array
21 */
22 public static $supportedSchemaGraphs = [
23 'none',
24 'WebPage',
25 'Article'
26 ];
27
28 /**
29 * The WebPage graphs we support.
30 *
31 * @since 4.0.0
32 *
33 * @var array
34 */
35 public static $supportedWebPageGraphs = [
36 'AboutPage',
37 'CollectionPage',
38 'ContactPage',
39 'FAQPage',
40 'ItemPage',
41 'ProfilePage',
42 'QAPage',
43 'RealEstateListing',
44 'SearchResultsPage',
45 'WebPage'
46 ];
47
48 /**
49 * The Article graphs we support.
50 *
51 * @since 4.0.0
52 *
53 * @var array
54 */
55 public static $supportedArticleGraphs = [
56 'Article',
57 'BlogPosting',
58 'NewsArticle'
59 ];
60 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
10
11 /**
12 * Migrates the Analytics Settings.
13 *
14 * @since 4.1.4
15 */
16 class Analytics {
17 /**
18 * Class constructor.
19 *
20 * @since 4.1.4
21 */
22 public function __construct() {
23 $this->options = get_option( 'seopress_google_analytics_option_name' );
24 if ( empty( $this->options ) ) {
25 return;
26 }
27
28 $settings = [
29 'seopress_google_analytics_other_tracking' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'miscellaneousVerification' ] ],
30 ];
31
32 aioseo()->importExport->seoPress->helpers->mapOldToNew( $settings, $this->options );
33 }
34 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
10
11 /**
12 * Migrates the Breadcrumb settings.
13 *
14 * @since 4.1.4
15 */
16 class Breadcrumbs {
17 /**
18 * Class constructor.
19 *
20 * @since 4.1.4
21 */
22 public function __construct() {
23 $this->options = get_option( 'seopress_pro_option_name' );
24 if ( empty( $this->options ) ) {
25 return;
26 }
27
28 $this->migrate();
29 }
30
31 /**
32 * Migrates the Breadcrumbs settings.
33 *
34 * @since 4.1.4
35 *
36 * @return void
37 */
38 private function migrate() {
39 if ( ! empty( $this->options['seopress_breadcrumbs_i18n_search'] ) ) {
40 aioseo()->options->breadcrumbs->searchResultFormat = sprintf( '%1$s #breadcrumb_archive_post_type_name', $this->options['seopress_breadcrumbs_i18n_search'] );
41 }
42
43 if ( ! empty( $this->options['seopress_breadcrumbs_remove_blog_page'] ) ) {
44 aioseo()->options->breadcrumbs->showBlogHome = false;
45 }
46
47 $settings = [
48 'seopress_breadcrumbs_enable' => [ 'type' => 'boolean', 'newOption' => [ 'breadcrumbs', 'enable' ] ],
49 'seopress_breadcrumbs_separator' => [ 'type' => 'string', 'newOption' => [ 'breadcrumbs', 'separator' ] ],
50 'seopress_breadcrumbs_i18n_home' => [ 'type' => 'string', 'newOption' => [ 'breadcrumbs', 'homepageLabel' ] ],
51 'seopress_breadcrumbs_i18n_here' => [ 'type' => 'string', 'newOption' => [ 'breadcrumbs', 'breadcrumbPrefix' ] ],
52 'seopress_breadcrumbs_i18n_404' => [ 'type' => 'string', 'newOption' => [ 'breadcrumbs', 'errorFormat404' ] ],
53 ];
54
55 aioseo()->importExport->seoPress->helpers->mapOldToNew( $settings, $this->options );
56 }
57 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
10
11 /**
12 * Migrates the General Settings.
13 *
14 * @since 4.1.4
15 */
16 class GeneralSettings {
17 /**
18 * Class constructor.
19 *
20 * @since 4.1.4
21 */
22 public function __construct() {
23 $this->options = get_option( 'seopress_advanced_option_name' );
24 if ( empty( $this->options ) ) {
25 return;
26 }
27
28 $this->roles = aioseo()->access->getRoles();
29
30 $this->migrateBlockMetaboxRoles();
31 $this->migrateBlockContentAnalysisRoles();
32 $this->migrateAttachmentRedirects();
33
34 $settings = [
35 'seopress_advanced_advanced_google' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'google' ] ],
36 'seopress_advanced_advanced_bing' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'bing' ] ],
37 'seopress_advanced_advanced_pinterest' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'pinterest' ] ],
38 'seopress_advanced_advanced_yandex' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'yandex' ] ],
39 ];
40
41 aioseo()->importExport->seoPress->helpers->mapOldToNew( $settings, $this->options );
42 }
43
44 /**
45 * Migrates Block AIOSEO metabox setting.
46 *
47 * @since 4.1.4
48 *
49 * @return void
50 */
51 private function migrateBlockMetaboxRoles() {
52 $seoPressRoles = $this->options['seopress_advanced_security_metaboxe_role'];
53 if ( empty( $seoPressRoles ) ) {
54 return;
55 }
56
57 $roleSettings = [ 'useDefault', 'pageAnalysis', 'pageGeneralSettings', 'pageSocialSettings', 'pageSchemaSettings', 'pageAdvancedSettings' ];
58
59 foreach ( $seoPressRoles as $wpRole => $value ) {
60 $role = $this->roles[ $wpRole ];
61 if ( empty( $role ) || aioseo()->access->isAdmin( $role ) ) {
62 continue;
63 }
64
65 if ( aioseo()->options->accessControl->has( $role ) ) {
66 foreach ( $roleSettings as $setting ) {
67 aioseo()->options->accessControl->$role->$setting = false;
68 }
69 } elseif ( aioseo()->dynamicOptions->accessControl->has( $role ) ) {
70 foreach ( $roleSettings as $setting ) {
71 aioseo()->dynamicOptions->accessControl->$role->$setting = false;
72 }
73 }
74 }
75 }
76
77 /**
78 * Migrates Block Content analysis metabox setting.
79 *
80 * @since 4.1.4
81 *
82 * @return void
83 */
84 private function migrateBlockContentAnalysisRoles() {
85 $seoPressRoles = $this->options['seopress_advanced_security_metaboxe_ca_role'];
86 if ( empty( $seoPressRoles ) ) {
87 return;
88 }
89
90 $roleSettings = [ 'useDefault', 'pageAnalysis' ];
91
92 foreach ( $seoPressRoles as $wpRole => $value ) {
93 $role = $this->roles[ $wpRole ];
94 if ( empty( $role ) || aioseo()->access->isAdmin( $role ) ) {
95 continue;
96 }
97
98 if ( aioseo()->options->accessControl->has( $role ) ) {
99 foreach ( $roleSettings as $setting ) {
100 aioseo()->options->accessControl->$role->$setting = false;
101 }
102 } elseif ( aioseo()->dynamicOptions->accessControl->has( $role ) ) {
103 foreach ( $roleSettings as $setting ) {
104 aioseo()->dynamicOptions->accessControl->$role->$setting = false;
105 }
106 }
107 }
108 }
109
110 /**
111 * Migrates redirect attachment pages settings.
112 *
113 * @since 4.1.4
114 *
115 * @return void
116 */
117 private function migrateAttachmentRedirects() {
118 if ( ! empty( $this->options['seopress_advanced_advanced_attachments'] ) ) {
119 aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'attachment_parent';
120 }
121
122 if ( ! empty( $this->options['seopress_advanced_advanced_attachments_file'] ) ) {
123 aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'attachment';
124 }
125
126 if ( empty( $this->options['seopress_advanced_advanced_attachments'] ) && empty( $this->options['seopress_advanced_advanced_attachments_file'] ) ) {
127 aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'disabled';
128 }
129 }
130 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\ImportExport;
10
11 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
12
13 /**
14 * Contains helper methods for the import from SEOPress.
15 *
16 * @since 4.1.4
17 */
18 class Helpers extends ImportExport\Helpers {
19 /**
20 * Converts the macros from SEOPress to our own smart tags.
21 *
22 * @since 4.1.4
23 *
24 * @param string $string The string with macros.
25 * @param string $pageType The page type.
26 * @return string $string The string with smart tags.
27 */
28 public function macrosToSmartTags( $string, $postType = null ) {
29 $macros = $this->getMacros( $postType );
30
31 foreach ( $macros as $macro => $tag ) {
32 $string = aioseo()->helpers->pregReplace( "#$macro(?![a-zA-Z0-9_])#im", $tag, $string );
33 }
34
35 return trim( $string );
36 }
37
38 /**
39 * Returns the macro mappings.
40 *
41 * @since 4.1.4
42 *
43 * @param string $postType The post type.
44 * @param string $pageType The page type.
45 * @return array $macros The macros.
46 */
47 protected function getMacros( $postType = null, $pageType = null ) {
48 $macros = [
49 '%%sep%%' => '#separator_sa',
50 '%%sitetitle%%' => '#site_title',
51 '%%sitename%%' => '#site_title',
52 '%%tagline%%' => '#tagline',
53 '%%sitedesc%%' => '#tagline',
54 '%%title%%' => '#site_title',
55 '%%post_title%%' => '#post_title',
56 '%%post_excerpt%%' => '#post_excerpt',
57 '%%excerpt%%' => '#post_excerpt',
58 '%%post_content%%' => '#post_content',
59 '%%post_url%%' => '#permalink',
60 '%%post_date%%' => '#post_date',
61 '%%post_permalink%%' => '#permalink',
62 '%%date%%' => '#post_date',
63 '%%post_author%%' => '#author_name',
64 '%%post_category%%' => '#categories',
65 '%%_category_title%%' => '#taxonomy_title',
66 '%%_category_description%%' => '#taxonomy_description',
67 '%%tag_title%%' => '#taxonomy_title',
68 '%%tag_description%%' => '#taxonomy_description',
69 '%%term_title%%' => '#taxonomy_title',
70 '%%term_description%%' => '#taxonomy_description',
71 '%%search_keywords%%' => '#search_term',
72 '%%current_pagination%%' => '#page_number',
73 '%%page%%' => '#page_number',
74 '%%archive_title%%' => '#archive_title',
75 '%%archive_date%%' => '#archive_date',
76 '%%wc_single_price%%' => '#woocommerce_price',
77 '%%wc_sku%%' => '#woocommerce_sku',
78 '%%currentday%%' => '#current_day',
79 '%%currentmonth%%' => '#current_month',
80 '%%currentmonth_short%%' => '#current_month',
81 '%%currentyear%%' => '#current_year',
82 '%%currentdate%%' => '#current_date',
83 '%%author_first_name%%' => '#author_first_name',
84 '%%author_last_name%%' => '#author_last_name',
85 '%%author_website%%' => '#author_link',
86 '%%author_nickname%%' => '#author_first_name',
87 '%%author_bio%%' => '#author_bio',
88 '%%currentmonth_num%%' => '#current_month',
89 ];
90
91 if ( $postType ) {
92 $postType = get_post_type_object( $postType );
93 if ( ! empty( $postType ) ) {
94 $macros += [
95 '%%cpt_plural%%' => $postType->labels->name,
96 ];
97 }
98 }
99
100 switch ( $pageType ) {
101 case 'archive':
102 $macros['%%title%%'] = '#archive_title';
103 break;
104 case 'term':
105 $macros['%%title%%'] = '#taxonomy_title';
106 break;
107 default:
108 $macros['%%title%%'] = '#post_title';
109 break;
110 }
111
112 // Strip all other tags.
113 $macros['%%[^%]*%%'] = '';
114
115 return $macros;
116 }
117 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Models;
10
11 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
12
13 /**
14 * Imports the post meta from SEOPress.
15 *
16 * @since 4.1.4
17 */
18 class PostMeta {
19 /**
20 * The mapped meta
21 *
22 * @since 4.1.4
23 *
24 * @var array
25 */
26 private $mappedMeta = [
27 '_seopress_analysis_target_kw' => '',
28 '_seopress_robots_archive' => 'robots_noarchive',
29 '_seopress_robots_canonical' => 'canonical_url',
30 '_seopress_robots_follow' => 'robots_nofollow',
31 '_seopress_robots_imageindex' => 'robots_noimageindex',
32 '_seopress_robots_index' => 'robots_noindex',
33 '_seopress_robots_odp' => 'robots_noodp',
34 '_seopress_robots_snippet' => 'robots_nosnippet',
35 '_seopress_social_twitter_desc' => 'twitter_description',
36 '_seopress_social_twitter_img' => 'twitter_image_custom_url',
37 '_seopress_social_twitter_title' => 'twitter_title',
38 '_seopress_social_fb_desc' => 'og_description',
39 '_seopress_social_fb_img' => 'og_image_custom_url',
40 '_seopress_social_fb_title' => 'og_title',
41 '_seopress_titles_desc' => 'description',
42 '_seopress_titles_title' => 'title',
43 ];
44
45 /**
46 * Class constructor.
47 *
48 * @since 4.1.4
49 */
50 public function scheduleImport() {
51 if ( aioseo()->helpers->scheduleSingleAction( aioseo()->importExport->seoPress->postActionName, 0 ) ) {
52 if ( ! aioseo()->cache->get( 'import_post_meta_seopress' ) ) {
53 aioseo()->cache->update( 'import_post_meta_seopress', time(), WEEK_IN_SECONDS );
54 }
55 }
56 }
57
58 /**
59 * Imports the post meta.
60 *
61 * @since 4.1.4
62 *
63 * @return void
64 */
65 public function importPostMeta() {
66 $postsPerAction = 100;
67 $publicPostTypes = implode( "', '", aioseo()->helpers->getPublicPostTypes( true ) );
68 $timeStarted = gmdate( 'Y-m-d H:i:s', aioseo()->cache->get( 'import_post_meta_seopress' ) );
69
70 $posts = aioseo()->db
71 ->start( 'posts as p' )
72 ->select( 'p.ID, p.post_type' )
73 ->join( 'postmeta as pm', '`p`.`ID` = `pm`.`post_id`' )
74 ->leftJoin( 'aioseo_posts as ap', '`p`.`ID` = `ap`.`post_id`' )
75 ->whereRaw( "pm.meta_key LIKE '_seopress_%'" )
76 ->whereRaw( "( p.post_type IN ( '$publicPostTypes' ) )" )
77 ->whereRaw( "( ap.post_id IS NULL OR ap.updated < '$timeStarted' )" )
78 ->orderBy( 'p.ID DESC' )
79 ->limit( $postsPerAction )
80 ->run()
81 ->result();
82
83 if ( ! $posts || ! count( $posts ) ) {
84 aioseo()->cache->delete( 'import_post_meta_seopress' );
85
86 return;
87 }
88
89 foreach ( $posts as $post ) {
90 $postMeta = aioseo()->db
91 ->start( 'postmeta' . ' as pm' )
92 ->select( 'pm.meta_key, pm.meta_value' )
93 ->where( 'pm.post_id', $post->ID )
94 ->whereRaw( "`pm`.`meta_key` LIKE '_seopress_%'" )
95 ->run()
96 ->result();
97
98 if ( ! $postMeta || ! count( $postMeta ) ) {
99 continue;
100 }
101
102 $meta = array_merge( [
103 'post_id' => (int) $post->ID,
104 ], $this->getMetaData( $postMeta, $post->ID ) );
105
106 $aioseoPost = Models\Post::getPost( (int) $post->ID );
107 $aioseoPost->set( $meta );
108 $aioseoPost->save();
109 }
110
111 if ( count( $posts ) === $postsPerAction ) {
112 aioseo()->helpers->scheduleSingleAction( aioseo()->importExport->seoPress->postActionName, 5, [], true );
113 } else {
114 aioseo()->cache->delete( 'import_post_meta_seopress' );
115 }
116 }
117
118 /**
119 * Get the meta data by post meta.
120 *
121 * @since 4.1.4
122 *
123 * @param object $postMeta The post meta from database.
124 * @return array The meta data.
125 */
126 public function getMetaData( $postMeta, $postId ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
127 $meta = [];
128 foreach ( $postMeta as $record ) {
129 $name = $record->meta_key;
130 $value = $record->meta_value;
131
132 if ( ! in_array( $name, array_keys( $this->mappedMeta ), true ) ) {
133 continue;
134 }
135
136 switch ( $name ) {
137 case '_seopress_analysis_target_kw':
138 $keyphrase = [
139 'focus' => [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $value ) ],
140 'additional' => []
141 ];
142 $meta['keyphrases'] = wp_json_encode( $keyphrase );
143 break;
144 case '_seopress_robots_snippet':
145 case '_seopress_robots_archive':
146 case '_seopress_robots_imageindex':
147 case '_seopress_robots_odp':
148 case '_seopress_robots_follow':
149 case '_seopress_robots_index':
150 if ( 'yes' === $value ) {
151 $meta['robots_default'] = false;
152 $meta[ $this->mappedMeta[ $name ] ] = true;
153 }
154 break;
155 case '_seopress_social_twitter_img':
156 $meta['twitter_use_og'] = false;
157 $meta['twitter_image_type'] = 'custom_image';
158 $meta[ $this->mappedMeta[ $name ] ] = esc_url( $value );
159 break;
160 case '_seopress_social_fb_img':
161 $meta['og_image_type'] = 'custom_image';
162 $meta[ $this->mappedMeta[ $name ] ] = esc_url( $value );
163 break;
164 case '_seopress_titles_title':
165 case '_seopress_titles_desc':
166 $value = aioseo()->importExport->seoPress->helpers->macrosToSmartTags( $value );
167 default:
168 $meta[ $this->mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
169 break;
170 }
171 }
172
173 return $meta;
174 }
175 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\ImportExport\SeoPress;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
10
11 /**
12 * Migrates the robots.txt settings.
13 *
14 * @since 4.1.4
15 */
16 class RobotsTxt {
17 /**
18 * Class constructor.
19 *
20 * @since 4.1.4
21 */
22 public function __construct() {
23 $this->options = get_option( 'seopress_pro_option_name' );
24 if ( empty( $this->options ) ) {
25 return;
26 }
27
28 $this->migrateRobotsTxt();
29
30 $settings = [
31 'seopress_robots_enable' => [ 'type' => 'boolean', 'newOption' => [ 'tools', 'robots', 'enable' ] ],
32 ];
33
34 aioseo()->importExport->seoPress->helpers->mapOldToNew( $settings, $this->options );
35 }
36
37 /**
38 * Migrates the robots.txt.
39 *
40 * @since 4.1.4
41 *
42 * @return void
43 */
44 public function migrateRobotsTxt() {
45 $lines = explode( "\n", $this->options['seopress_robots_file'] );
46 $allRules = aioseo()->robotsTxt->extractRules( $lines );
47
48 aioseo()->options->tools->robots->rules = aioseo()->robotsTxt->prepareRobotsTxt( $allRules );
49 }
50 }
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.