412e4539 by Jeff Balicki

dod

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent ee775142
Showing 1000 changed files with 4994 additions and 0 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

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 100 million downloads since 2007.
6 * Author: All in One SEO Team
7 * Author URI: https://aioseo.com/
8 * Version: 4.3.3
9 * Text Domain: all-in-one-seo-pack
10 * Domain Path: /languages
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.6', '<' ) ) {
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, '7.0', '<' ) ) {
88 add_action( 'admin_notices', 'aioseo_php_notice_deprecated' );
89 }
90
91 // Define the class and the function.
92 // The AIOSEOAbstract class is required here because it can't be autoloaded.
93 require_once dirname( __FILE__ ) . '/app/AIOSEOAbstract.php';
94 require_once dirname( __FILE__ ) . '/app/AIOSEO.php';
95
96 aioseo();
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 // Exit if accessed directly.
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Abstract class holding the class properties of our main AIOSEO class.
9 *
10 * @since 4.2.7
11 */
12 abstract class AIOSEOAbstract {
13 /**
14 * Core class instance.
15 *
16 * @since 4.2.7
17 *
18 * @var \AIOSEO\Plugin\Common\Core\Core
19 */
20 public $core = null;
21
22 /**
23 * Helpers class instance.
24 *
25 * @since 4.2.7
26 *
27 * @var Object
28 */
29 public $helpers = null;
30
31 /**
32 * InternalNetworkOptions class instance.
33 *
34 * @since 4.2.7
35 *
36 * @var \AIOSEO\Plugin\Common\Options\InternalNetworkOptions|\AIOSEO\Plugin\Pro\Options\InternalNetworkOptions
37 */
38 public $internalNetworkOptions = null;
39
40 /**
41 * InternalOptions class instance.
42 *
43 * @since 4.2.7
44 *
45 * @var \AIOSEO\Plugin\Lite\Options\InternalOptions|\AIOSEO\Plugin\Pro\Options\InternalOptions
46 */
47 public $internalOptions = null;
48
49 /**
50 * PreUpdates class instance.
51 *
52 * @since 4.2.7
53 *
54 * @var \AIOSEO\Plugin\Common\Main\PreUpdates|\AIOSEO\Plugin\Pro\Main\PreUpdates
55 */
56 public $preUpdates = null;
57
58 /**
59 * Db class instance.
60 * This prop is set for backwards compatibility.
61 *
62 * @since 4.2.7
63 *
64 * @var \AIOSEO\Plugin\Common\Core\Db
65 */
66 public $db = null;
67
68 /**
69 * Transients class instance.
70 * This prop is set for backwards compatibility.
71 *
72 * @since 4.2.7
73 *
74 * @var \AIOSEO\Plugin\Common\Core\Cache
75 */
76 public $transients = null;
77
78 /**
79 * OptionsCache class instance.
80 * This prop is set for backwards compatibility.
81 *
82 * @since 4.2.7
83 *
84 * @var \AIOSEO\Plugin\Common\Options\Cache
85 */
86 public $optionsCache = null;
87
88 /**
89 * PostSettings class instance.
90 *
91 * @since 4.2.7
92 *
93 * @var \AIOSEO\Plugin\Lite\Admin\PostSettings|\AIOSEO\Plugin\Pro\Admin\PostSettings
94 */
95 public $postSettings = null;
96
97 /**
98 * Standalone class instance.
99 *
100 * @since 4.2.7
101 *
102 * @var AIOSEO\Plugin\Common\Standalone
103 */
104 public $standalone = null;
105
106 /**
107 * Search Statistics class instance.
108 *
109 * @since 4.3.0
110 *
111 * @var \AIOSEO\Plugin\Common\SearchStatistics\SearchStatistics|\AIOSEO\Plugin\Pro\SearchStatistics\SearchStatistics
112 */
113 public $searchStatistics = null;
114
115 /**
116 * ThirdParty class instance.
117 *
118 * @since 4.2.7
119 *
120 * @var \AIOSEO\Plugin\Common\ThirdParty\ThirdParty
121 */
122 public $thirdParty = null;
123
124 /**
125 * Tags class instance.
126 *
127 * @since 4.2.7
128 *
129 * @var \AIOSEO\Plugin\Common\Utils\Addons|\AIOSEO\Plugin\Pro\Utils\Addons
130 */
131 public $tags = null;
132
133 /**
134 * Addons class instance.
135 *
136 * @since 4.2.7
137 *
138 * @var \AIOSEO\Plugin\Common\Utils\Blocks
139 */
140 public $blocks = null;
141
142 /**
143 * BadBotBlocker class instance.
144 *
145 * @since 4.2.7
146 *
147 * @var \AIOSEO\Plugin\Common\Tools\BadBotBlocker
148 */
149 public $badBotBlocker = null;
150
151 /**
152 * Breadcrumbs class instance.
153 *
154 * @since 4.2.7
155 *
156 * @var \AIOSEO\Plugin\Common\Breadcrumbs\Breadcrumbs|\AIOSEO\Plugin\Pro\Breadcrumbs\Breadcrumbs
157 */
158 public $breadcrumbs = null;
159
160 /**
161 * DynamicBackup class instance.
162 *
163 * @since 4.2.7
164 *
165 * @var \AIOSEO\Plugin\Common\Options\DynamicBackup|\AIOSEO\Plugin\Pro\Options\DynamicBackup
166 */
167 public $dynamicBackup = null;
168
169 /**
170 * NetworkOptions class instance.
171 *
172 * @since 4.2.7
173 *
174 * @var \AIOSEO\Plugin\Common\Options\NetworkOptions|\AIOSEO\Plugin\Pro\Options\NetworkOptions
175 */
176 public $networkOptions = null;
177
178 /**
179 * Backup class instance.
180 *
181 * @since 4.2.7
182 *
183 * @var \AIOSEO\Plugin\Common\Utils\Backup
184 */
185 public $backup = null;
186
187 /**
188 * Access class instance.
189 *
190 * @since 4.2.7
191 *
192 * @var \AIOSEO\Plugin\Common\Utils\Access|\AIOSEO\Plugin\Pro\Utils\Access
193 */
194 public $access = null;
195
196 /**
197 * NetworkLicense class instance.
198 *
199 * @since 4.2.7
200 *
201 * @var null|\AIOSEO\Plugin\Pro\Admin\NetworkLicense
202 */
203 public $networkLicense = null;
204
205 /**
206 * License class instance.
207 *
208 * @since 4.2.7
209 *
210 * @var null|\AIOSEO\Plugin\Pro\Admin\License
211 */
212 public $license = null;
213
214 /**
215 * Updates class isntance.
216 *
217 * @since 4.2.7
218 *
219 * @var \AIOSEO\Plugin\Common\Main\Updates|\AIOSEO\Plugin\Pro\Main\Updates
220 */
221 public $updates = null;
222
223 /**
224 * Meta class instance.
225 *
226 * @since 4.2.7
227 *
228 * @var \AIOSEO\Plugin\Common\Meta\Meta|\AIOSEO\Plugin\Pro\Meta\Meta
229 */
230 public $meta = null;
231
232 /**
233 * Social class instance.
234 *
235 * @since 4.2.7
236 *
237 * @var \AIOSEO\Plugin\Common\Social\Social|\AIOSEO\Plugin\Pro\Social\Social
238 */
239 public $social = null;
240
241 /**
242 * RobotsTxt class instance.
243 *
244 * @since 4.2.7
245 *
246 * @var \AIOSEO\Plugin\Common\Tools\RobotsTxt
247 */
248 public $robotsTxt = null;
249
250 /**
251 * Htaccess class instance.
252 *
253 * @since 4.2.7
254 *
255 * @var \AIOSEO\Plugin\Common\Tools\Htaccess
256 */
257 public $htaccess = null;
258
259 /**
260 * Term class instance.
261 *
262 * @since 4.2.7
263 *
264 * @var null|\AIOSEO\Plugin\Pro\Admin\Term
265 */
266 public $term = null;
267
268 /**
269 * Notices class instance.
270 *
271 * @since 4.2.7
272 *
273 * @var \AIOSEO\Plugin\Lite\Admin\Notices\Notices|\AIOSEO\Plugin\Pro\Admin\Notices\Notices
274 */
275 public $notices = null;
276
277 /**
278 * WpNotices class instance.
279 *
280 * @since 4.2.7
281 *
282 * @var \AIOSEO\Plugin\Common\Admin\Notices\WpNotices
283 */
284 public $wpNotices = null;
285
286 /**
287 * Admin class instance.
288 *
289 * @since 4.2.7
290 *
291 * @var \AIOSEO\Plugin\Lite\Admin\Admin|\AIOSEO\Plugin\Pro\Admin\Admin
292 */
293 public $admin = null;
294
295 /**
296 * NetworkAdmin class instance.
297 *
298 * @since 4.2.7
299 *
300 * @var \AIOSEO\Plugin\Common\Admin\NetworkAdmin|\AIOSEO\Plugin\Pro\Admin\NetworkAdmin
301 */
302 public $networkAdmin = null;
303
304 /**
305 * Activate class instance.
306 *
307 * @since 4.2.7
308 *
309 * @var \AIOSEO\Plugin\Common\Main|Activate|\AIOSEO\Plugin\Pro\Main\Activate
310 */
311 public $activate = null;
312
313 /**
314 * ConflictingPlugins class instance.
315 *
316 * @since 4.2.7
317 *
318 * @var \AIOSEO\Plugin\Common\Admin\ConflictingPlugins|\AIOSEO\Plugin\Pro\Admin\ConflictingPlugins
319 */
320 public $conflictingPlugins = null;
321
322 /**
323 * Migration class instance.
324 *
325 * @since 4.2.7
326 *
327 * @var \AIOSEO\Plugin\Common\Migration\Migration|\AIOSEO\Plugin\Pro\Migration\Migration
328 */
329 public $migration = null;
330
331 /**
332 * ImportExport class instance.
333 *
334 * @since 4.2.7
335 *
336 * @var \AIOSEO\Plugin\Common\ImportExport\ImportExport
337 */
338 public $importExport = null;
339
340 /**
341 * Sitemap class instance.
342 *
343 * @since 4.2.7
344 *
345 * @var \AIOSEO\Plugin\Common\Sitemap\Sitemap|\AIOSEO\Plugin\Pro\Sitemap\Sitemap
346 */
347 public $sitemap = null;
348
349 /**
350 * HtmlSitemap class instance.
351 *
352 * @since 4.2.7
353 *
354 * @var \AIOSEO\Plugin\Common\Sitemap\Html\Sitemap
355 */
356 public $htmlSitemap = null;
357
358 /**
359 * CategoryBase class instance.
360 *
361 * @since 4.2.7
362 *
363 * @var null|\AIOSEO\Plugin\Pro\Main\CategoryBase
364 */
365 public $categoryBase = null;
366
367 /**
368 * SlugMonitor class instance.
369 *
370 * @since 4.2.7
371 *
372 * @var \AIOSEO\Plugin\Common\Admin\SlugMonitor
373 */
374 public $slugMonitor = null;
375
376 /**
377 * Schema class instance.
378 *
379 * @since 4.2.7
380 *
381 * @var \AIOSEO\Plugin\Common\Schema\Schema|\AIOSEO\Plugin\Pro\Schema\Schema
382 */
383 public $schema = null;
384
385 /**
386 * Rss class instance.
387 *
388 * @since 4.2.7
389 *
390 * @var \AIOSEO\Plugin\Common\Rss
391 */
392 public $rss = null;
393
394 /**
395 * Main class instance.
396 *
397 * @since 4.2.7
398 *
399 * @var \AIOSEO\Plugin\Common\Main\Main|\AIOSEO\Plugin\Pro\Main\Main
400 */
401 public $main = null;
402
403 /**
404 * Head class instance.
405 *
406 * @since 4.2.7
407 *
408 * @var \AIOSEO\Plugin\Common\Main\Head|\AIOSEO\Plugin\Pro\Main\Head
409 */
410 public $head = null;
411
412 /**
413 * Dashboard class instance.
414 *
415 * @since 4.2.7
416 *
417 * @var \AIOSEO\Plugin\Common\Admin\Dashboard|\AIOSEO\Plugin\Pro\Admin\Dashboard
418 */
419 public $dashboard = null;
420
421 /**
422 * API class instance.
423 *
424 * @since 4.2.7
425 *
426 * @var \AIOSEO\Plugin\Lite\Api\Api|\AIOSEO\Plugin\Pro\Api\Api
427 */
428 public $api = null;
429
430 /**
431 * Help class instance.
432 *
433 * @since 4.2.7
434 *
435 * @var \AIOSEO\Plugin\Common\Help\Help
436 */
437 public $help = null;
438
439 /**
440 * Settings class instance.
441 *
442 * @since 4.2.7
443 *
444 * @var \AIOSEO\Plugin\Common\Utils\VueSettings
445 */
446 public $settings = null;
447
448 /**
449 * Cache class instance.
450 *
451 * @since 4.2.7
452 *
453 * @var \AIOSEO\Plugin\Common\Core\Cache
454 */
455 public $cache = null;
456
457 /**
458 * CachePrune class instance.
459 *
460 * @since 4.2.7
461 *
462 * @var \AIOSEO\Plugin\Common\Core\CachePrune
463 */
464 public $cachePrune = null;
465
466 /**
467 * Addons class instance.
468 *
469 * @since 4.2.7
470 *
471 * @var \AIOSEO\Plugin\Common\Utils\Addons|\AIOSEO\Plugin\Pro\Utils\Addons
472 */
473 public $addons = null;
474
475 /**
476 * Addons class instance.
477 *
478 * @since 4.3.0
479 *
480 * @var \AIOSEO\Plugin\Common\Utils\Features|\AIOSEO\Plugin\Pro\Utils\Features
481 */
482 public $features = null;
483
484 /**
485 * Options class instance.
486 *
487 * @since 4.2.7
488 *
489 * @var \AIOSEO\Plugin\Lite\Options\Options|\AIOSEO\Plugin\Pro\Options\Options
490 */
491 public $options = null;
492
493 /**
494 * DynamicOptions class instance.
495 *
496 * @since 4.2.7
497 *
498 * @var \AIOSEO\Plugin\Common\Options\DynamicOptions|\AIOSEO\Plugin\Pro\Options\DynamicOptions
499 */
500 public $dynamicOptions = null;
501
502 /**
503 * Usage class instance.
504 *
505 * @since 4.2.7
506 *
507 * @var \AIOSEO\Plugin\Lite\Admin\Usage|\Admin\Plugin\Pro\Admin\Usage
508 */
509 public $usage = null;
510
511 /**
512 * SiteHealth class instance.
513 *
514 * @since 4.2.7
515 *
516 * @var \AIOSEO\Plugin\Common\Admin\SiteHealth|\AIOSEO\Plugin\Pro\Admin\SiteHealth
517 */
518 public $siteHealth = null;
519
520 /**
521 * AutoUpdates class instance.
522 *
523 * @since 4.2.7
524 *
525 * @var null|\AIOSEO\Plugin\Admin\AutoUpdates
526 */
527 public $autoUpdates = null;
528
529 /**
530 * Templates class instance.
531 *
532 * @since 4.2.7
533 *
534 * @var \AIOSEO\Plugin\Common\Utils\Templates|\AIOSEO\Plugin\Pro\Utils\Templates
535 */
536 public $templates = null;
537
538 /**
539 * Filters class instance.
540 *
541 * @since 4.2.7
542 *
543 * @var \AIOSEO\Plugin\Lite\Main\Filters|\AIOSEO\Plugin\Pro\Main\Filters
544 */
545 public $filters = null;
546
547 /**
548 * ActionScheduler class instance.
549 *
550 * @since 4.2.7
551 *
552 * @var \AIOSEO\Plugin\Common\Utils\ActionScheduler
553 */
554 public $actionScheduler = null;
555
556 /**
557 * AI class instance.
558 *
559 * @since 4.3.3
560 *
561 * @var null|\AIOSEO\Plugin\Pro\Ai\Ai
562 */
563 public $ai = null;
564 }
...\ 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, 'addDashboardWidgets' ] );
22 }
23
24 /**
25 * Registers our dashboard widgets.
26 *
27 * @since 4.2.0
28 *
29 * @return void
30 */
31 public function addDashboardWidgets() {
32 // Add the SEO Setup widget.
33 if (
34 $this->canShowWidget( 'seoSetup' ) &&
35 apply_filters( 'aioseo_show_seo_setup', true ) &&
36 ( aioseo()->access->isAdmin() || aioseo()->access->hasCapability( 'aioseo_setup_wizard' ) ) &&
37 ! aioseo()->standalone->setupWizard->isCompleted()
38 ) {
39 wp_add_dashboard_widget(
40 'aioseo-seo-setup',
41 // Translators: 1 - The plugin short name ("AIOSEO").
42 sprintf( esc_html__( '%s Setup', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME ),
43 [
44 $this,
45 'outputSeoSetup',
46 ],
47 null,
48 null,
49 'normal',
50 'high'
51 );
52 }
53
54 // Add the Overview widget.
55 if (
56 $this->canShowWidget( 'seoOverview' ) &&
57 apply_filters( 'aioseo_show_seo_overview', true ) &&
58 ( aioseo()->access->isAdmin() || aioseo()->access->hasCapability( 'aioseo_page_analysis' ) )
59 ) {
60 wp_add_dashboard_widget(
61 'aioseo-overview',
62 // Translators: 1 - The plugin short name ("AIOSEO").
63 sprintf( esc_html__( '%s Overview', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME ),
64 [
65 $this,
66 'outputSeoOverview',
67 ]
68 );
69 }
70
71 // Add the News widget.
72 if (
73 $this->canShowWidget( 'seoNews' ) &&
74 apply_filters( 'aioseo_show_seo_news', true ) &&
75 aioseo()->access->isAdmin()
76 ) {
77 wp_add_dashboard_widget(
78 'aioseo-rss-feed',
79 esc_html__( 'SEO News', 'all-in-one-seo-pack' ),
80 [
81 $this,
82 'displayRssDashboardWidget',
83 ]
84 );
85 }
86 }
87
88 /**
89 * Whether or not to show the widget.
90 *
91 * @since 4.0.0
92 * @version 4.2.8
93 *
94 * @param string $widget The widget to check if can show.
95 * @return boolean True if yes, false otherwise.
96 */
97 protected function canShowWidget( $widget ) { // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
98 return true;
99 }
100
101 /**
102 * Output the SEO Setup widget.
103 *
104 * @since 4.2.0
105 *
106 * @return void
107 */
108 public function outputSeoSetup() {
109 $this->output( 'aioseo-seo-setup-app' );
110 }
111
112 /**
113 * Output the SEO Overview widget.
114 *
115 * @since 4.2.0
116 *
117 * @return void
118 */
119 public function outputSeoOverview() {
120 $this->output( 'aioseo-overview-app' );
121 }
122
123 /**
124 * Output the widget wrapper for the Vue App.
125 *
126 * @since 4.2.0
127 *
128 * @param string $appId The App ID to print out.
129 * @return void
130 */
131 private function output( $appId ) {
132 // Enqueue the scripts for the widget.
133 $this->enqueue();
134
135 // Opening tag.
136 echo '<div id="' . esc_attr( $appId ) . '">';
137
138 // Loader element.
139 require AIOSEO_DIR . '/app/Common/Views/parts/loader.php';
140
141 // Closing tag.
142 echo '</div>';
143 }
144
145 /**
146 * Enqueue the scripts and styles.
147 *
148 * @since 4.2.0
149 *
150 * @return void
151 */
152 private function enqueue() {
153 aioseo()->core->assets->load( 'src/vue/standalone/dashboard-widgets/main.js', [], aioseo()->helpers->getVueData( 'dashboard' ) );
154 }
155
156 /**
157 * Display RSS Dashboard Widget
158 *
159 * @since 4.0.0
160 *
161 * @return void
162 */
163 public function displayRssDashboardWidget() {
164 // Check if the user has chosen not to display this widget through screen options.
165 $currentScreen = get_current_screen();
166 $hiddenWidgets = get_user_meta( get_current_user_id(), 'metaboxhidden_' . $currentScreen->id );
167 if ( $hiddenWidgets && count( $hiddenWidgets ) > 0 && is_array( $hiddenWidgets[0] ) && in_array( 'aioseo-rss-feed', $hiddenWidgets[0], true ) ) {
168 return;
169 }
170
171 include_once ABSPATH . WPINC . '/feed.php';
172
173 $rssItems = aioseo()->core->networkCache->get( 'rss_feed' );
174 if ( null === $rssItems ) {
175 $rss = fetch_feed( 'https://aioseo.com/feed/' );
176 if ( is_wp_error( $rss ) ) {
177 esc_html_e( 'Temporarily unable to load feed.', 'all-in-one-seo-pack' );
178
179 return;
180 }
181 $rssItems = $rss->get_items( 0, 4 ); // Show four items.
182 $cached = [];
183 foreach ( $rssItems as $item ) {
184 $cached[] = [
185 'url' => $item->get_permalink(),
186 'title' => aioseo()->helpers->decodeHtmlEntities( $item->get_title() ),
187 'date' => $item->get_date( get_option( 'date_format' ) ),
188 'content' => substr( wp_strip_all_tags( $item->get_content() ), 0, 128 ) . '...',
189 ];
190 }
191 $rssItems = $cached;
192
193 aioseo()->core->networkCache->update( 'rss_feed', $cached, 12 * HOUR_IN_SECONDS );
194 }
195 ?>
196 <ul>
197 <?php
198 if ( false === $rssItems ) {
199 echo '<li>' . esc_html( __( 'No articles were found.', 'all-in-one-seo-pack' ) ) . '</li>';
200
201 return;
202 }
203
204 foreach ( $rssItems as $item ) {
205 ?>
206 <li>
207 <a target="_blank" href="<?php echo esc_url( $item['url'] ); ?>" rel="noopener noreferrer">
208 <?php echo esc_html( $item['title'] ); ?>
209 </a>
210 <span><?php echo esc_html( $item['date'] ); ?></span>
211 <div>
212 <?php echo esc_html( wp_strip_all_tags( $item['content'] ) ) . '...'; ?>
213 </div>
214 </li>
215 <?php
216 }
217
218 ?>
219 </ul>
220 <?php
221 }
222 }
...\ 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 * Abstract class that Pro and Lite both extend.
11 *
12 * @since 4.2.5
13 */
14 class NetworkAdmin extends Admin {
15 /**
16 * Construct method.
17 *
18 * @since 4.2.5
19 */
20 public function __construct() {
21 include_once ABSPATH . 'wp-admin/includes/plugin.php';
22 if (
23 is_network_admin() &&
24 ! is_plugin_active_for_network( plugin_basename( AIOSEO_FILE ) )
25 ) {
26 return;
27 }
28
29 if ( wp_doing_ajax() || wp_doing_cron() ) {
30 return;
31 }
32
33 add_action( 'sanitize_comment_cookies', [ $this, 'init' ], 21 );
34 }
35
36 /**
37 * Initialize the admin.
38 *
39 * @since 4.2.5
40 *
41 * @return void
42 */
43 public function init() {
44 add_action( 'network_admin_menu', [ $this, 'addNetworkMenu' ] );
45
46 $this->setPages();
47 }
48
49 /**
50 * Add the network menu inside of WordPress.
51 *
52 * @since 4.2.5
53 *
54 * @return void
55 */
56 public function addNetworkMenu() {
57 $this->addMainMenu( 'aioseo' );
58
59 foreach ( $this->pages as $slug => $page ) {
60 if (
61 'aioseo-settings' !== $slug &&
62 'aioseo-tools' !== $slug &&
63 'aioseo-about' !== $slug &&
64 'aioseo-feature-manager' !== $slug
65 ) {
66 continue;
67 }
68
69 $hook = add_submenu_page(
70 $this->pageSlug,
71 ! empty( $page['page_title'] ) ? $page['page_title'] : $page['menu_title'],
72 $page['menu_title'],
73 $this->getPageRequiredCapability( $slug ),
74 $slug,
75 [ $this, 'page' ]
76 );
77 add_action( "load-{$hook}", [ $this, 'hooks' ] );
78 }
79
80 // Remove the "dashboard" submenu page that is not needed in the network admin.
81 remove_submenu_page( $this->pageSlug, $this->pageSlug );
82 }
83 }
...\ 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 %4$s. %5$sRead more for additional information.%6$s', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
86 '<strong>',
87 '</strong>',
88 'AIOSEO',
89 date( 'Y' ),
90 '<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
91 '</a>'
92 ),
93 [
94 'a' => [
95 'href' => [],
96 'target' => [],
97 'rel' => [],
98 ],
99 'strong' => [],
100 ]
101 );
102 ?>
103 </p>
104 </div>
105
106 <?php
107 // In case this is on plugin activation.
108 if ( isset( $_GET['activate'] ) ) {
109 unset( $_GET['activate'] );
110 }
111 }
112
113 /**
114 * Print the script for dismissing the notice.
115 *
116 * @since 4.1.2
117 *
118 * @return void
119 */
120 public function printScript() {
121 // Create a nonce.
122 $nonce = wp_create_nonce( 'aioseo-dismiss-deprecated-wordpress' );
123 ?>
124 <script>
125 window.addEventListener('load', function () {
126 var dismissBtn
127
128 // Add an event listener to the dismiss button.
129 dismissBtn = document.querySelector('.aioseo-deprecated-wordpress-notice .notice-dismiss')
130 dismissBtn.addEventListener('click', function (event) {
131 var httpRequest = new XMLHttpRequest(),
132 postData = ''
133
134 // Build the data to send in our request.
135 postData += '&action=aioseo-dismiss-deprecated-wordpress-notice'
136 postData += '&nonce=<?php echo esc_html( $nonce ); ?>'
137
138 httpRequest.open('POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>')
139 httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
140 httpRequest.send(postData)
141 })
142 });
143 </script>
144 <?php
145 }
146
147 /**
148 * Dismiss the deprecated WordPress notice.
149 *
150 * @since 4.1.2
151 *
152 * @return WP_Response The successful response.
153 */
154 public function dismissNotice() {
155 // Early exit if we're not on a aioseo-dismiss-deprecated-wordpress-notice action.
156 if ( ! isset( $_POST['action'] ) || 'aioseo-dismiss-deprecated-wordpress-notice' !== $_POST['action'] ) {
157 return;
158 }
159
160 check_ajax_referer( 'aioseo-dismiss-deprecated-wordpress', 'nonce' );
161
162 update_option( '_aioseo_deprecated_wordpress_dismissed', true );
163
164 return wp_send_json_success();
165 }
166 }
...\ 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()->core->cache->get( 'v3_migration_in_progress_posts' );
24 $transientTerms = aioseo()->core->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 * WpNotices class.
11 *
12 * @since 4.2.3
13 */
14 class WpNotices {
15 /**
16 * Notices array
17 *
18 * @since 4.2.3
19 *
20 * @var array
21 */
22 private $notices;
23
24 /**
25 * The cache key.
26 *
27 * @since 4.2.3
28 *
29 * @var string
30 */
31 private $cacheKey = 'wp_notices';
32
33 /**
34 * Class Constructor.
35 *
36 * @since 4.2.3
37 */
38 public function __construct() {
39 add_action( 'rest_api_init', [ $this, 'registerApiField' ] );
40 add_action( 'enqueue_block_editor_assets', [ $this, 'enqueueScripts' ] );
41 add_action( 'admin_notices', [ $this, 'adminNotices' ] );
42 }
43
44 /**
45 * Enqueue notices scripts.
46 *
47 * @since 4.2.3
48 *
49 * @return void
50 */
51 public function enqueueScripts() {
52 aioseo()->core->assets->load( 'src/vue/standalone/wp-notices/main.js' );
53 }
54
55 /**
56 * Registers an API field with notices.
57 *
58 * @since 4.2.3
59 *
60 * @return void
61 */
62 public function registerApiField() {
63 foreach ( aioseo()->helpers->getPublicPostTypes( true ) as $postType ) {
64 register_rest_field( $postType, 'aioseo_notices', [
65 'get_callback' => [ $this, 'apiGetNotices' ]
66 ] );
67 }
68 }
69
70 /**
71 * API field callback.
72 *
73 * @since 4.2.3
74 *
75 * @return array Notices array
76 */
77 public function apiGetNotices() {
78 $notices = $this->getNoticesInContext();
79
80 // Notices show only one time.
81 $this->removeNotices( $notices );
82
83 return $notices;
84 }
85
86 /**
87 * Get all notices.
88 *
89 * @since 4.2.3
90 *
91 * @return array Notices array
92 */
93 public function getNotices() {
94 if ( empty( $this->notices ) ) {
95 $this->notices = aioseo()->core->cache->get( $this->cacheKey );
96 }
97
98 return ! empty( $this->notices ) ? $this->notices : [];
99 }
100
101 /**
102 * Get all notices in the current context.
103 *
104 * @since 4.2.6
105 *
106 * @return array Notices array
107 */
108 public function getNoticesInContext() {
109 $contextNotices = $this->getNotices();
110 foreach ( $contextNotices as $key => $notice ) {
111 if ( empty( $notice['allowedContexts'] ) ) {
112 continue;
113 }
114
115 $allowed = false;
116 foreach ( $notice['allowedContexts'] as $allowedContext ) {
117 if ( $this->isAllowedContext( $allowedContext ) ) {
118 $allowed = true;
119 break;
120 }
121 }
122
123 if ( ! $allowed ) {
124 unset( $contextNotices[ $key ] );
125 }
126 }
127
128 return $contextNotices;
129 }
130
131 /**
132 * Test if we are in the current context.
133 *
134 * @since 4.2.6
135 *
136 * @param string $context The context to test. (posts)
137 * @return bool Is the required context.
138 */
139 private function isAllowedContext( $context ) {
140 switch ( $context ) {
141 case 'posts':
142 return aioseo()->helpers->isScreenPostList() ||
143 aioseo()->helpers->isScreenPostEdit() ||
144 aioseo()->helpers->isAjaxCronRestRequest();
145 }
146
147 return false;
148 }
149
150 /**
151 * Finds a notice by message.
152 *
153 * @since 4.2.3
154 *
155 * @param string $message The message string.
156 * @param string $type The message type.
157 * @return void|array The found notice.
158 */
159 public function getNotice( $message, $type = '' ) {
160 $notices = $this->getNotices();
161 foreach ( $notices as $notice ) {
162 if ( $notice['options']['id'] === $this->getNoticeId( $message, $type ) ) {
163 return $notice;
164 }
165 }
166 }
167
168 /**
169 * Generates a notice id.
170 *
171 * @since 4.2.3
172 *
173 * @param string $message The message string.
174 * @param string $type The message type.
175 * @return string The notice id.
176 */
177 public function getNoticeId( $message, $type = '' ) {
178 return md5( $message . $type );
179 }
180
181 /**
182 * Clear notices.
183 *
184 * @since 4.2.3
185 *
186 * @return void
187 */
188 public function clearNotices() {
189 $this->notices = [];
190 $this->updateCache();
191 }
192
193 /**
194 * Remove certain notices.
195 *
196 * @since 4.2.6
197 *
198 * @param array $notices A list of notices to remove.
199 * @return void
200 */
201 public function removeNotices( $notices ) {
202 foreach ( array_keys( $notices ) as $noticeKey ) {
203 unset( $this->notices[ $noticeKey ] );
204 }
205 $this->updateCache();
206 }
207
208 /**
209 * Adds a notice.
210 *
211 * @since 4.2.3
212 *
213 * @param string $message The message.
214 * @param string $status The message status [success, info, warning, error]
215 * @param array $options Options for the message. https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createnotice
216 * @param array $allowedContexts The contexts where this notice will show.
217 * @return void
218 */
219 public function addNotice( $message, $status = 'warning', $options = [], $allowedContexts = [] ) {
220 $type = ! empty( $options['type'] ) ? $options['type'] : '';
221 $foundNotice = $this->getNotice( $message, $type );
222 if ( empty( $message ) || ! empty( $foundNotice ) ) {
223 return;
224 }
225
226 $notice = [
227 'message' => $message,
228 'status' => $status,
229 'options' => wp_parse_args( $options, [
230 'id' => $this->getNoticeId( $message, $type ),
231 'isDismissible' => true
232 ] ),
233 'allowedContexts' => $allowedContexts
234 ];
235
236 $this->notices[] = $notice;
237 $this->updateCache();
238 }
239
240 /**
241 * Show notices on classic editor.
242 *
243 * @since 4.2.3
244 *
245 * @return void
246 */
247 public function adminNotices() {
248 // Double check we're actually in the admin before outputting anything.
249 if ( ! is_admin() ) {
250 return;
251 }
252
253 $notices = $this->getNoticesInContext();
254 foreach ( $notices as $notice ) {
255 // Hide snackbar notices on classic editor.
256 if ( ! empty( $notice['options']['type'] ) && 'snackbar' === $notice['options']['type'] ) {
257 continue;
258 }
259
260 $status = ! empty( $notice['status'] ) ? $notice['status'] : 'warning';
261 $class = ! empty( $notice['options']['class'] ) ? $notice['options']['class'] : '';
262 ?>
263 <div
264 class="notice notice-<?php echo esc_attr( $status ) ?> <?php echo esc_attr( $class ) ?>">
265 <?php echo '<p>' . $notice['message'] . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
266 <?php
267 if ( ! empty( $notice['options']['actions'] ) ) {
268 foreach ( $notice['options']['actions'] as $action ) {
269 echo '<p>';
270 if ( ! empty( $action['url'] ) ) {
271 $class = ! empty( $action['class'] ) ? $action['class'] : '';
272 $target = ! empty( $action['target'] ) ? $action['target'] : '';
273 echo '<a
274 href="' . esc_attr( $action['url'] ) . '"
275 class="' . esc_attr( $class ) . '"
276 target="' . esc_attr( $target ) . '"
277 >';
278 }
279 echo $action['label']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
280 if ( ! empty( $action['url'] ) ) {
281 echo '</a>';
282 }
283 echo '</p>';
284 }
285 ?>
286 <?php } ?>
287 </div>
288 <?php
289 }
290
291 // Notices show only one time.
292 $this->removeNotices( $notices );
293 }
294
295 /**
296 * Helper to update the cache with the current notices array.
297 *
298 * @since 4.2.6
299 *
300 * @return void
301 */
302 private function updateCache() {
303 aioseo()->core->cache->update( $this->cacheKey, $this->notices );
304 }
305 }
...\ 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 * Handles all admin code for the SEO Analysis menu.
11 *
12 * @since 4.2.6
13 */
14 class SeoAnalysis {
15 /**
16 * Class constructor.
17 *
18 * @since 4.2.6
19 */
20 public function __construct() {
21 add_action( 'save_post', [ $this, 'bustStaticHomepageResults' ], 10, 1 );
22 }
23
24 /**
25 * Busts the SEO Analysis for the static homepage when it is updated.
26 *
27 * @since 4.2.6
28 *
29 * @param int $postId The post ID.
30 * @return void
31 */
32 public function bustStaticHomepageResults( $postId ) {
33 if ( ! aioseo()->helpers->isStaticHomePage( $postId ) ) {
34 return;
35 }
36
37 aioseo()->internalOptions->internal->siteAnalysis->score = 0;
38 aioseo()->internalOptions->internal->siteAnalysis->results = null;
39
40 aioseo()->core->cache->delete( 'analyze_site_code' );
41 aioseo()->core->cache->delete( 'analyze_site_body' );
42 }
43 }
...\ 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 * Monitors changes to post slugs.
11 *
12 * @since 4.2.3
13 */
14 class SlugMonitor {
15 /**
16 * Holds posts that have been updated.
17 *
18 * @since 4.2.3
19 *
20 * @var array
21 */
22 private $updatedPosts = [];
23
24 /**
25 * Class constructor.
26 *
27 * @since 4.2.3
28 */
29 public function __construct() {
30 // We can't monitor changes without permalinks enabled.
31 if ( ! get_option( 'permalink_structure' ) ) {
32 return;
33 }
34
35 add_action( 'pre_post_update', [ $this, 'prePostUpdate' ] );
36
37 // WP 5.6+.
38 if ( function_exists( 'wp_after_insert_post' ) ) {
39 add_action( 'wp_after_insert_post', [ $this, 'afterInsertPost' ], 11, 4 );
40 } else {
41 add_action( 'post_updated', [ $this, 'postUpdated' ], 11, 3 );
42 }
43 }
44
45 /**
46 * Remember the previous post permalink.
47 *
48 * @since 4.2.3
49 *
50 * @param integer $postId The post ID.
51 * @return void
52 */
53 public function prePostUpdate( $postId ) {
54 $this->updatedPosts[ $postId ] = get_permalink( $postId );
55 }
56
57 /**
58 * Called when a post has been completely inserted ( with categories and meta ).
59 *
60 * @since 4.2.3
61 *
62 * @param integer $postId The post ID.
63 * @param \WP_Post $post The post object.
64 * @param bool $update Whether this is an existing post being updated.
65 * @param null|\WP_Post $postBefore The post object before changes were made.
66 * @return void
67 */
68 public function afterInsertPost( $postId, $post, $update, $postBefore ) {
69 if ( ! $update ) {
70 return;
71 }
72
73 $this->postUpdated( $postId, $post, $postBefore );
74 }
75
76 /**
77 * Called when a post has been updated - check if the slug has changed.
78 *
79 * @since 4.2.3
80 *
81 * @param integer $postId The post ID.
82 * @param \WP_Post $post The post object.
83 * @param \WP_Post $postBefore The post object before changes were made.
84 * @return void
85 */
86 public function postUpdated( $postId, $post, $postBefore ) {
87 if ( ! isset( $this->updatedPosts[ $postId ] ) ) {
88 return;
89 }
90
91 $before = aioseo()->helpers->getPermalinkPath( $this->updatedPosts[ $postId ] );
92 $after = aioseo()->helpers->getPermalinkPath( get_permalink( $postId ) );
93 if ( ! aioseo()->helpers->hasPermalinkChanged( $before, $after ) ) {
94 return;
95 }
96
97 // Can we monitor this slug?
98 if ( ! $this->canMonitorPost( $post, $postBefore ) ) {
99 return;
100 }
101
102 // Ask aioseo-redirects if automatic redirects is monitoring it.
103 if ( $this->automaticRedirect( $post->post_type, $before, $after ) ) {
104 return;
105 }
106
107 // Filter to allow users to disable the slug monitor messages.
108 if ( apply_filters( 'aioseo_redirects_disable_slug_monitor', false ) ) {
109 return;
110 }
111
112 $redirectUrl = $this->manualRedirectUrl( [
113 'url' => $before,
114 'target' => $after,
115 'type' => 301
116 ] );
117
118 $message = __( 'The permalink for this post just changed! This could result in 404 errors for your site visitors.', 'all-in-one-seo-pack' );
119
120 // Default notice redirecting to the Redirects screen.
121 $action = [
122 'url' => $redirectUrl,
123 'label' => __( 'Add Redirect to improve SEO', 'all-in-one-seo-pack' ),
124 'target' => '_blank',
125 'class' => 'aioseo-redirects-slug-changed'
126 ];
127
128 // If redirects is active we'll show add-redirect in a modal.
129 if ( aioseo()->addons->getLoadedAddon( 'redirects' ) ) {
130 // We need to remove the target here so the action keeps the url used by the add-redirect modal.
131 unset( $action['target'] );
132 }
133
134 aioseo()->wpNotices->addNotice( $message, 'warning', [ 'actions' => [ $action ] ], [ 'posts' ] );
135 }
136
137 /**
138 * Checks if this is a post we can monitor.
139 *
140 * @since 4.2.3
141 *
142 * @param \WP_Post $post The post object.
143 * @param \WP_Post $postBefore The post object before changes were made.
144 * @return boolean True if we can monitor this post.
145 */
146 private function canMonitorPost( $post, $postBefore ) {
147 // Check that this is for the expected post.
148 if ( ! isset( $post->ID ) || ! isset( $this->updatedPosts[ $post->ID ] ) ) {
149 return false;
150 }
151
152 // Don't do anything if we're not published.
153 if ( 'publish' !== $post->post_status || 'publish' !== $postBefore->post_status ) {
154 return false;
155 }
156
157 // Don't do anything is the post type is not public.
158 if ( ! is_post_type_viewable( $post->post_type ) ) {
159 return false;
160 }
161
162 return true;
163 }
164
165 /**
166 * Tries to add a automatic redirect.
167 *
168 * @since 4.2.3
169 *
170 * @param string $postType The post type.
171 * @param string $before The url before.
172 * @param string $after The url after.
173 * @return bool True if an automatic redirect was added.
174 */
175 private function automaticRedirect( $postType, $before, $after ) {
176 if ( ! aioseo()->addons->getLoadedAddon( 'redirects' ) ) {
177 return false;
178 }
179
180 return aioseoRedirects()->monitor->automaticRedirect( $postType, $before, $after );
181 }
182
183 /**
184 * Generates a URL for adding manual redirects.
185 *
186 * @since 4.2.3
187 *
188 * @param array $urls An array of [url, target, type, slash, case, regex].
189 * @return string The redirect link.
190 */
191 public function manualRedirectUrl( $urls ) {
192 if ( ! aioseo()->addons->getLoadedAddon( 'redirects' ) ) {
193 return admin_url( 'admin.php?page=aioseo-redirects' );
194 }
195
196 return aioseoRedirects()->helpers->manualRedirectUrl( $urls );
197 }
198 }
...\ 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()->actionScheduler->unschedule( $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' => 10,
97 'headers' => array_merge( [
98 'Content-Type' => 'application/json; charset=utf-8'
99 ], aioseo()->helpers->getApiHeaders() ),
100 'user-agent' => aioseo()->helpers->getApiUserAgent(),
101 'body' => wp_json_encode( $this->getData() )
102 ]
103 );
104 }
105
106 /**
107 * Gets the URL for the notifications api.
108 *
109 * @since 4.0.0
110 *
111 * @return string The URL to use for the api requests.
112 */
113 private function getUrl() {
114 if ( defined( 'AIOSEO_USAGE_TRACKING_URL' ) ) {
115 return AIOSEO_USAGE_TRACKING_URL;
116 }
117
118 return $this->url;
119 }
120
121 /**
122 * Retrieves the data to send in the usage tracking.
123 *
124 * @since 4.0.0
125 *
126 * @return array An array of data to send.
127 */
128 protected function getData() {
129 $themeData = wp_get_theme();
130 $type = $this->getType();
131
132 return [
133 // Generic data (environment).
134 'url' => home_url(),
135 'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION,
136 'wp_version' => get_bloginfo( 'version' ),
137 'mysql_version' => aioseo()->core->db->db->db_version(),
138 'server_version' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
139 'is_ssl' => is_ssl(),
140 'is_multisite' => is_multisite(),
141 'sites_count' => function_exists( 'get_blog_count' ) ? (int) get_blog_count() : 1,
142 'active_plugins' => $this->getActivePlugins(),
143 'theme_name' => $themeData->name,
144 'theme_version' => $themeData->version,
145 'user_count' => function_exists( 'get_user_count' ) ? get_user_count() : null,
146 'locale' => get_locale(),
147 'timezone_offset' => aioseo()->helpers->getTimeZoneOffset(),
148 'email' => get_bloginfo( 'admin_email' ),
149 // AIOSEO specific data.
150 'aioseo_version' => AIOSEO_VERSION,
151 'aioseo_license_key' => null,
152 'aioseo_license_type' => null,
153 'aioseo_is_pro' => false,
154 "aioseo_${type}_installed_date" => aioseo()->internalOptions->internal->installed,
155 'aioseo_settings' => $this->getSettings()
156 ];
157 }
158
159 /**
160 * Get the settings and escape the quotes so it can be JSON encoded.
161 *
162 * @since 4.0.0
163 *
164 * @return array An array of settings data.
165 */
166 private function getSettings() {
167 $settings = aioseo()->options->all();
168 array_walk_recursive( $settings, function( &$v ) {
169 if ( is_string( $v ) && strpos( $v, '&quot' ) !== false ) {
170 $v = str_replace( '&quot', '&#x5c;&quot', $v );
171 }
172 });
173
174 $settings = $this->filterPrivateSettings( $settings );
175
176 $internal = aioseo()->internalOptions->all();
177 array_walk_recursive( $internal, function( &$v ) {
178 if ( is_string( $v ) && strpos( $v, '&quot' ) !== false ) {
179 $v = str_replace( '&quot', '&#x5c;&quot', $v );
180 }
181 });
182
183 return [
184 'options' => $settings,
185 'internal' => $internal
186 ];
187 }
188
189 /**
190 * Return a list of active plugins.
191 *
192 * @since 4.0.0
193 *
194 * @return array An array of active plugin data.
195 */
196 private function getActivePlugins() {
197 if ( ! function_exists( 'get_plugins' ) ) {
198 include ABSPATH . '/wp-admin/includes/plugin.php';
199 }
200 $active = get_option( 'active_plugins', [] );
201 $plugins = array_intersect_key( get_plugins(), array_flip( $active ) );
202
203 return array_map(
204 static function ( $plugin ) {
205 if ( isset( $plugin['Version'] ) ) {
206 return $plugin['Version'];
207 }
208
209 return 'Not Set';
210 },
211 $plugins
212 );
213 }
214
215 /**
216 * Generate a random start date for usage tracking.
217 *
218 * @since 4.0.0
219 *
220 * @return integer The randomized start date.
221 */
222 private function generateStartDate() {
223 $tracking = [
224 'days' => wp_rand( 0, 6 ) * DAY_IN_SECONDS,
225 'hours' => wp_rand( 0, 23 ) * HOUR_IN_SECONDS,
226 'minutes' => wp_rand( 0, 23 ) * HOUR_IN_SECONDS,
227 'seconds' => wp_rand( 0, 59 )
228 ];
229
230 return strtotime( 'next sunday' ) + array_sum( $tracking );
231 }
232
233 /**
234 * Anonimizes or obfuscates the value of certain settings.
235 *
236 * @since 4.3.2
237 *
238 * @param array $settings The settings.
239 * @return array The altered settings.
240 */
241 private function filterPrivateSettings( $settings ) {
242 if ( ! empty( $settings['advanced']['openAiKey'] ) ) {
243 $settings['advanced']['openAiKey'] = true;
244 }
245
246 if ( ! empty( $settings['localBusiness']['maps']['apiKey'] ) ) {
247 $settings['localBusiness']['maps']['apiKey'] = true;
248 }
249
250 return $settings;
251 }
252 }
...\ 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()->core->cache->get( 'analyze_site_code' ) ? [] : aioseo()->core->cache->get( 'analyze_site_code' );
29 $responseBody = null === aioseo()->core->cache->get( 'analyze_site_body' ) ? [] : aioseo()->core->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 $url = defined( 'AIOSEO_ANALYZE_URL' ) ? AIOSEO_ANALYZE_URL : 'https://analyze.aioseo.com';
39 $response = aioseo()->helpers->wpRemotePost( $url . '/v1/analyze/', [
40 'timeout' => 60,
41 'headers' => [
42 'X-AIOSEO-Key' => $token,
43 'Content-Type' => 'application/json'
44 ],
45 'body' => wp_json_encode( [
46 'url' => $analyzeOrHomeUrl
47 ] ),
48 ] );
49
50 $responseCode[ $analyzeOrHomeUrl ] = wp_remote_retrieve_response_code( $response );
51 $responseBody[ $analyzeOrHomeUrl ] = json_decode( wp_remote_retrieve_body( $response ) );
52
53 aioseo()->core->cache->update( 'analyze_site_code', $responseCode, 10 * MINUTE_IN_SECONDS );
54 aioseo()->core->cache->update( 'analyze_site_body', $responseBody, 10 * MINUTE_IN_SECONDS );
55 }
56
57 if ( 200 !== $responseCode[ $analyzeOrHomeUrl ] || empty( $responseBody[ $analyzeOrHomeUrl ]->success ) || ! empty( $responseBody[ $analyzeOrHomeUrl ]->error ) ) {
58 if ( ! empty( $responseBody[ $analyzeOrHomeUrl ]->error ) && 'invalid-token' === $responseBody[ $analyzeOrHomeUrl ]->error ) {
59 aioseo()->internalOptions->internal->siteAnalysis->reset();
60 }
61
62 return new \WP_REST_Response( [
63 'success' => false,
64 'response' => $responseBody[ $analyzeOrHomeUrl ]
65 ], 400 );
66 }
67
68 if ( $analyzeUrl ) {
69 $competitors = aioseo()->internalOptions->internal->siteAnalysis->competitors;
70 $competitors = array_reverse( $competitors, true );
71
72 $competitors[ $analyzeUrl ] = wp_json_encode( $responseBody[ $analyzeOrHomeUrl ] );
73
74 $competitors = array_reverse( $competitors, true );
75
76 // Reset the competitors.
77 aioseo()->internalOptions->internal->siteAnalysis->competitors = $competitors;
78
79 return new \WP_REST_Response( $competitors, 200 );
80 }
81
82 $results = $responseBody[ $analyzeOrHomeUrl ]->results;
83
84 // Image alt attributes get stripped by sanitize_text_field, so we need to adjust the way they are stored to keep them intact.
85 if ( ! empty( $results->basic->noImgAltAtts->value ) ) {
86 $results->basic->noImgAltAtts->value = array_map( 'htmlentities', $results->basic->noImgAltAtts->value );
87 }
88
89 aioseo()->internalOptions->internal->siteAnalysis->results = wp_json_encode( $results );
90 aioseo()->internalOptions->internal->siteAnalysis->score = $responseBody[ $analyzeOrHomeUrl ]->score;
91
92 return new \WP_REST_Response( $responseBody[ $analyzeOrHomeUrl ], 200 );
93 }
94
95 /**
96 * Deletes the analyzed site for SEO.
97 *
98 * @since 4.0.0
99 *
100 * @param \WP_REST_Request $request The REST Request
101 * @return \WP_REST_Response The response.
102 */
103 public static function deleteSite( $request ) {
104 $body = $request->get_json_params();
105 $analyzeUrl = ! empty( $body['url'] ) ? esc_url_raw( urldecode( $body['url'] ) ) : null;
106
107 $competitors = aioseo()->internalOptions->internal->siteAnalysis->competitors;
108
109 unset( $competitors[ $analyzeUrl ] );
110
111 // Reset the competitors.
112 aioseo()->internalOptions->internal->siteAnalysis->competitors = $competitors;
113
114 return new \WP_REST_Response( $competitors, 200 );
115 }
116
117 /**
118 * Analyzes the title for SEO.
119 *
120 * @since 4.1.2
121 *
122 * @param \WP_REST_Request $request The REST Request.
123 * @return \WP_REST_Response The response.
124 */
125 public static function analyzeHeadline( $request ) {
126 $body = $request->get_json_params();
127 $headline = ! empty( $body['headline'] ) ? sanitize_text_field( $body['headline'] ) : '';
128 $shouldStoreHeadline = ! empty( $body['shouldStoreHeadline'] ) ? rest_sanitize_boolean( $body['shouldStoreHeadline'] ) : false;
129
130 if ( empty( $headline ) ) {
131 return new \WP_REST_Response( [
132 'success' => false,
133 'message' => __( 'Please enter a valid headline.', 'all-in-one-seo-pack' )
134 ], 400 );
135 }
136
137 $result = aioseo()->standalone->headlineAnalyzer->getResult( $headline );
138
139 $headlines = aioseo()->internalOptions->internal->headlineAnalysis->headlines;
140 $headlines = array_reverse( $headlines, true );
141
142 $headlines[ $headline ] = wp_json_encode( $result );
143
144 $headlines = array_reverse( $headlines, true );
145
146 // Store the headlines with the latest one.
147 if ( $shouldStoreHeadline ) {
148 aioseo()->internalOptions->internal->headlineAnalysis->headlines = $headlines;
149 }
150
151 return new \WP_REST_Response( $headlines, 200 );
152 }
153
154 /**
155 * Deletes the analyzed Headline for SEO.
156 *
157 * @since 4.1.6
158 *
159 * @param \WP_REST_Request $request The REST Request.
160 * @return \WP_REST_Response The response.
161 */
162 public static function deleteHeadline( $request ) {
163 $body = $request->get_json_params();
164 $headline = sanitize_text_field( $body['headline'] );
165
166 $headlines = aioseo()->internalOptions->internal->headlineAnalysis->headlines;
167
168 unset( $headlines[ $headline ] );
169
170 // Reset the headlines.
171 aioseo()->internalOptions->internal->headlineAnalysis->headlines = $headlines;
172
173 return new \WP_REST_Response( $headlines, 200 );
174 }
175 }
...\ 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 /**
10 * Route class for the API.
11 *
12 * @since 4.2.5
13 */
14 class Network {
15 /**
16 * Save network robots rules.
17 *
18 * @since 4.2.5
19 *
20 * @param \WP_REST_Request $request The REST Request
21 * @return \WP_REST_Response The response.
22 */
23 public static function saveNetworkRobots( $request ) {
24 $isNetwork = 'network' === $request->get_param( 'siteId' );
25 $siteId = $isNetwork ? aioseo()->helpers->getNetworkId() : (int) $request->get_param( 'siteId' );
26 $body = $request->get_json_params();
27 $rules = ! empty( $body['rules'] ) ? array_map( 'sanitize_text_field', $body['rules'] ) : [];
28 $enabled = isset( $body['enabled'] ) ? boolval( $body['enabled'] ) : null;
29
30 aioseo()->helpers->switchToBlog( $siteId );
31
32 $options = $isNetwork ? aioseo()->networkOptions : aioseo()->options;
33 $enabled = null === $enabled ? $options->tools->robots->enable : $enabled;
34
35 $options->sanitizeAndSave( [
36 'tools' => [
37 'robots' => [
38 'enable' => $enabled,
39 'rules' => $rules
40 ]
41 ]
42 ] );
43
44 return new \WP_REST_Response( [
45 'success' => true
46 ], 200 );
47 }
48 }
...\ 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.2.1
57 *
58 * @param \WP_REST_Request $request The REST Request
59 * @return \WP_REST_Response The response.
60 */
61 public static function installOmReminder() {
62 return self::reminder( 'install-om' );
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 installAddonsReminder() {
74 return self::reminder( 'install-addons' );
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 installImageSeoReminder() {
86 return self::reminder( 'install-aioseo-image-seo' );
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 installLocalBusinessReminder() {
98 return self::reminder( 'install-aioseo-local-business' );
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 installNewsSitemapReminder() {
110 return self::reminder( 'install-aioseo-news-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 installVideoSitemapReminder() {
122 return self::reminder( 'install-aioseo-video-sitemap' );
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 conflictingPluginsReminder() {
134 return self::reminder( 'conflicting-plugins' );
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()->core->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', '3' );
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 $plugins = ! empty( $body['plugins'] ) ? $body['plugins'] : [];
27 $network = ! empty( $body['network'] ) ? $body['network'] : false;
28
29 if ( ! is_array( $plugins ) ) {
30 return new \WP_REST_Response( [
31 'success' => false,
32 'message' => $error
33 ], 400 );
34 }
35
36 if ( ! aioseo()->addons->canInstall() ) {
37 return new \WP_REST_Response( [
38 'success' => false,
39 'message' => $error
40 ], 400 );
41 }
42
43 $failed = [];
44 $completed = [];
45 foreach ( $plugins as $plugin ) {
46 if ( empty( $plugin['plugin'] ) ) {
47 return new \WP_REST_Response( [
48 'success' => false,
49 'message' => $error
50 ], 400 );
51 }
52
53 $result = aioseo()->addons->installAddon( $plugin['plugin'], $network );
54 if ( ! $result ) {
55 $failed[] = $plugin['plugin'];
56 } else {
57 $completed[ $plugin['plugin'] ] = $result;
58 }
59 }
60
61 return new \WP_REST_Response( [
62 'success' => true,
63 'completed' => $completed,
64 'failed' => $failed
65 ], 200 );
66 }
67
68 /**
69 * Upgrade plugins from vue.
70 *
71 * @since 4.1.6
72 *
73 * @param \WP_REST_Request $request The REST Request
74 * @return \WP_REST_Response The response.
75 */
76 public static function upgradePlugins( $request ) {
77 $error = esc_html__( 'Plugin update failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
78 $body = $request->get_json_params();
79 $plugins = ! empty( $body['plugins'] ) ? $body['plugins'] : [];
80 $network = ! empty( $body['network'] ) ? $body['network'] : false;
81
82 if ( ! is_array( $plugins ) ) {
83 return new \WP_REST_Response( [
84 'success' => false,
85 'message' => $error
86 ], 400 );
87 }
88
89 if ( ! aioseo()->addons->canUpdate() ) {
90 return new \WP_REST_Response( [
91 'success' => false,
92 'message' => $error
93 ], 400 );
94 }
95
96 $failed = [];
97 $completed = [];
98 foreach ( $plugins as $plugin ) {
99 if ( empty( $plugin['plugin'] ) ) {
100 return new \WP_REST_Response( [
101 'success' => false,
102 'message' => $error
103 ], 400 );
104 }
105
106 $result = aioseo()->addons->upgradeAddon( $plugin['plugin'], $network );
107 if ( ! $result ) {
108 $failed[] = $plugin['plugin'];
109 } else {
110 $completed[ $plugin['plugin'] ] = aioseo()->addons->getAddon( $plugin['plugin'], true );
111 }
112 }
113
114 return new \WP_REST_Response( [
115 'success' => true,
116 'completed' => $completed,
117 'failed' => $failed
118 ], 200 );
119 }
120
121 /**
122 * Deactivates plugins from vue.
123 *
124 * @since 4.0.0
125 *
126 * @param \WP_REST_Request $request The REST Request
127 * @return \WP_REST_Response The response.
128 */
129 public static function deactivatePlugins( $request ) {
130 $error = esc_html__( 'Deactivation failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
131 $body = $request->get_json_params();
132 $plugins = ! empty( $body['plugins'] ) ? $body['plugins'] : [];
133 $network = ! empty( $body['network'] ) ? $body['network'] : false;
134
135 if ( ! is_array( $plugins ) ) {
136 return new \WP_REST_Response( [
137 'success' => false,
138 'message' => $error
139 ], 400 );
140 }
141
142 if ( ! current_user_can( 'install_plugins' ) ) {
143 return new \WP_REST_Response( [
144 'success' => false,
145 'message' => $error
146 ], 400 );
147 }
148
149 require_once ABSPATH . 'wp-admin/includes/plugin.php';
150
151 $failed = [];
152 $completed = [];
153 foreach ( $plugins as $plugin ) {
154 if ( empty( $plugin['plugin'] ) ) {
155 return new \WP_REST_Response( [
156 'success' => false,
157 'message' => $error
158 ], 400 );
159 }
160
161 // Activate the plugin silently.
162 $activated = deactivate_plugins( $plugin['plugin'], false, $network );
163
164 if ( is_wp_error( $activated ) ) {
165 $failed[] = $plugin['plugin'];
166 }
167
168 $completed[] = $plugin['plugin'];
169 }
170
171 return new \WP_REST_Response( [
172 'success' => true,
173 'completed' => $completed,
174 'failed' => $failed
175 ], 200 );
176 }
177 }
...\ 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 $fs = aioseo()->core->fs;
56 if ( ! $fs->isWpfsValid() ) {
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 $fs->fs->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 $parsedPageUrl = wp_parse_url( $pageUrl );
133 if ( empty( $parsedPageUrl['path'] ) ) {
134 return new \WP_REST_Response( [
135 'success' => false,
136 'message' => 'The given path is invalid.'
137 ], 400 );
138 }
139
140 $isUrl = aioseo()->helpers->isUrl( $pageUrl );
141 $isInternalUrl = aioseo()->helpers->isInternalUrl( $pageUrl );
142 if ( $isUrl && ! $isInternalUrl ) {
143 return new \WP_REST_Response( [
144 'success' => false,
145 'message' => 'The given URL is not a valid internal URL.'
146 ], 400 );
147 }
148
149 $pathExists = self::pathExists( $parsedPageUrl['path'], $isUrl );
150
151 return new \WP_REST_Response( [
152 'exists' => $pathExists
153 ], 200 );
154 }
155
156 /**
157 * Checks whether the given path is unique or not.
158 *
159 * @since 4.1.4
160 * @version 4.2.6
161 *
162 * @param string $path The path.
163 * @param bool $path Whether the given path is a URL.
164 * @return boolean Whether the path exists.
165 */
166 private static function pathExists( $path, $isUrl ) {
167 $path = trim( $path, '/' );
168 $url = $isUrl ? $path : trailingslashit( home_url() ) . $path;
169
170 // Let's do another check here, just to be sure that the domain matches.
171 if ( ! aioseo()->helpers->isInternalUrl( $url ) ) {
172 return false;
173 }
174
175 $response = wp_safe_remote_head( $url );
176 $status = wp_remote_retrieve_response_code( $response );
177 if ( ! $status ) {
178 // If there is no status code, we might be in a local environment with CURL misconfigured.
179 // In that case we can still check if a post exists for the path by quering the DB.
180 $post = aioseo()->helpers->getPostbyPath(
181 $path,
182 OBJECT,
183 aioseo()->helpers->getPublicPostTypes( true )
184 );
185
186 return is_object( $post );
187 }
188
189 return 200 === $status;
190 }
191 }
...\ 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( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
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 $saveHtaccess = (object) aioseo()->htaccess->saveContents( $htaccess );
222 if ( ! $saveHtaccess->success ) {
223 return new \WP_REST_Response( [
224 'success' => false,
225 'message' => $saveHtaccess->message ? $saveHtaccess->message : __( 'An error occurred while trying to write to the .htaccess file. Please try again later.', 'all-in-one-seo-pack' ),
226 'reason' => $saveHtaccess->reason
227 ], 400 );
228 }
229
230 return new \WP_REST_Response( [
231 'success' => true
232 ], 200 );
233 }
234
235 /**
236 * Clear the passed in log.
237 *
238 * @since 4.0.0
239 *
240 * @param \WP_REST_Request $request The REST Request
241 * @return \WP_REST_Response The response.
242 */
243 public static function clearLog( $request ) {
244 $body = $request->get_json_params();
245 $log = ! empty( $body['log'] ) ? $body['log'] : null;
246
247 $logSize = 0;
248 switch ( $log ) {
249 case 'badBotBlockerLog':
250 aioseo()->badBotBlocker->clearLog();
251 $logSize = aioseo()->badBotBlocker->getLogSize();
252 break;
253 }
254
255 return new \WP_REST_Response( [
256 'success' => true,
257 'logSize' => aioseo()->helpers->convertFileSize( $logSize )
258 ], 200 );
259 }
260 }
...\ 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 * Handles user related API routes.
11 *
12 * @since 4.2.8
13 */
14 class User {
15 /**
16 * Get the user image.
17 *
18 * @since 4.2.8
19 *
20 * @param \WP_REST_Request $request The REST Request
21 * @return \WP_REST_Response The response.
22 */
23 public static function getUserImage( $request ) {
24 $args = $request->get_params();
25
26 if ( empty( $args['userId'] ) ) {
27 return new \WP_REST_Response( [
28 'success' => false,
29 'message' => 'No user ID was provided.'
30 ], 400 );
31 }
32
33 $url = get_avatar_url( $args['userId'] );
34
35 return new \WP_REST_Response( [
36 'success' => true,
37 'url' => is_array( $url ) ? $url[0] : $url,
38 ], 200 );
39 }
40 }
...\ 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 {
15 /**
16 * Class constructor.
17 *
18 * @since 4.1.1
19 */
20 public function __construct() {
21 $this->register();
22 }
23
24 /**
25 * Registers the block.
26 *
27 * @since 4.1.1
28 *
29 * @return void
30 */
31 public function register() {
32 aioseo()->blocks->registerBlock(
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 ( aioseo()->blocks->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 = htmlspecialchars( sanitize_text_field( 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 // We can only run after this action because we need all post types loaded.
157 if ( ! did_action( 'init' ) ) {
158 return;
159 }
160
161 $breadcrumbs = $this->getBreadcrumbs();
162 if ( empty( $breadcrumbs ) ) {
163 return;
164 }
165
166 $breadcrumbsCount = count( $breadcrumbs );
167
168 $display = '<div class="aioseo-breadcrumbs">';
169 foreach ( $breadcrumbs as $breadcrumb ) {
170 --$breadcrumbsCount;
171
172 $breadcrumbDisplay = $this->breadcrumbToDisplay( $breadcrumb );
173
174 // Strip link from Last crumb.
175 if (
176 0 === $breadcrumbsCount &&
177 aioseo()->breadcrumbs->showCurrentItem() &&
178 ! $this->linkCurrentItem() &&
179 'default' === $breadcrumbDisplay['templateType']
180 ) {
181 $breadcrumbDisplay['template'] = $this->stripLink( $breadcrumbDisplay['template'] );
182 }
183
184 $display .= $breadcrumbDisplay['template'];
185
186 if ( 0 < $breadcrumbsCount ) {
187 $display .= $this->getSeparator();
188 }
189 }
190 $display .= '</div>';
191
192 $display = wp_kses_post( $display );
193
194 if ( $echo ) {
195 echo $display; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
196 }
197
198 return $display;
199 }
200
201 /**
202 * Turns a crumb array into a rendered html crumb.
203 *
204 * @since 4.1.1
205 *
206 * @param array $item The crumb array.
207 * @return string|void The crumb html.
208 */
209 protected function breadcrumbToDisplay( $item ) {
210 $templateItem = $this->getCrumbTemplate( $item );
211 if ( empty( $templateItem['template'] ) ) {
212 return;
213 }
214
215 // Do tags.
216 $templateItem['template'] = aioseo()->breadcrumbs->tags->replaceTags( $templateItem['template'], $item );
217
218 // Restore html.
219 $templateItem['template'] = aioseo()->helpers->decodeHtmlEntities( $templateItem['template'] );
220
221 // Remove html link if it comes back from the template but we passed no links to it.
222 if ( empty( $item['link'] ) ) {
223 $templateItem['template'] = $this->stripLink( $templateItem['template'] );
224 }
225
226 // Allow shortcodes to run in the final html.
227 $templateItem['template'] = do_shortcode( $templateItem['template'] );
228
229 // Final security cleaning.
230 $templateItem['template'] = wp_kses_post( $templateItem['template'] );
231
232 return $templateItem;
233 }
234
235 /**
236 * Helper function to get a crumb's template.
237 *
238 * @since 4.1.1
239 *
240 * @param array $crumb The crumb array.
241 * @return string The html template.
242 */
243 protected function getTemplate( $crumb ) {
244 return $this->getDefaultTemplate( $crumb );
245 }
246
247 /**
248 * Helper function to get a crumb's template.
249 *
250 * @since 4.1.1
251 *
252 * @param array $crumb The crumb array.
253 * @return array The template type and html.
254 */
255 protected function getCrumbTemplate( $crumb ) {
256 return [
257 'templateType' => 'default',
258 'template' => $this->getTemplate( $crumb )
259 ];
260 }
261
262 /**
263 * Default html template.
264 *
265 * @since 4.1.1
266 *
267 * @param string $type The crumb's type.
268 * @param mixed $reference The crumb's reference.
269 * @return string The default crumb template.
270 */
271 public function getDefaultTemplate( $type = '', $reference = '' ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
272 return <<<TEMPLATE
273 <span class="aioseo-breadcrumb">
274 <a href="#breadcrumb_link" title="#breadcrumb_label">#breadcrumb_label</a>
275 </span>
276 TEMPLATE;
277 }
278
279 /**
280 * Helper function to strip a html link from the crumb.
281 *
282 * @since 4.1.1
283 *
284 * @param string $html The crumb's html.
285 * @return string A crumb html without links.
286 */
287 public function stripLink( $html ) {
288 return preg_replace( '/<a\s.*?>|<\/a>/is', '', $html );
289 }
290
291 /**
292 * Get the breadcrumb configured separator.
293 *
294 * @since 4.1.1
295 *
296 * @return string The separator html.
297 */
298 public function getSeparator() {
299 $separator = apply_filters( 'aioseo_breadcrumbs_separator_symbol', aioseo()->options->breadcrumbs->separator );
300
301 return apply_filters( 'aioseo_breadcrumbs_separator', '<span class="aioseo-breadcrumb-separator">' . esc_html( $separator ) . '</span>' );
302 }
303
304 /**
305 * Function to filter the linkCurrentItem option.
306 *
307 * @since 4.1.3
308 *
309 * @return bool Link current item.
310 */
311 public function linkCurrentItem() {
312 return apply_filters( 'aioseo_breadcrumbs_link_current_item', aioseo()->options->breadcrumbs->linkCurrentItem );
313 }
314 }
...\ 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 * The default attributes.
17 *
18 * @since 4.2.7
19 *
20 * @var array
21 */
22 private $defaults = [];
23
24 /**
25 * Class constructor.
26 *
27 * @since 4.1.1
28 */
29 public function __construct() {
30 // Widget defaults.
31 $this->defaults = [
32 'title' => ''
33 ];
34
35 // Widget Slug.
36 $widgetSlug = 'aioseo-breadcrumb-widget';
37
38 // Widget basics.
39 $widgetOps = [
40 'classname' => $widgetSlug,
41 'description' => esc_html__( 'Display the current page breadcrumb.', 'all-in-one-seo-pack' ),
42 ];
43
44 // Widget controls.
45 $controlOps = [
46 'id_base' => $widgetSlug,
47 ];
48
49 // Load widget.
50 parent::__construct( $widgetSlug, esc_html__( 'AIOSEO - Breadcrumbs', 'all-in-one-seo-pack' ), $widgetOps, $controlOps );
51 }
52
53 /**
54 * Widget callback.
55 *
56 * @since 4.1.1
57 *
58 * @param array $args Widget args.
59 * @param array $instance The widget instance options.
60 * @return void
61 */
62 public function widget( $args, $instance ) {
63 // Merge with defaults.
64 $instance = wp_parse_args( (array) $instance, $this->defaults );
65
66 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
67
68 // Title.
69 if ( ! empty( $instance['title'] ) ) {
70 echo $args['before_title'] . apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
71 'widget_title', $instance['title'], $instance, $this->id_base
72 ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
73 }
74
75 // Breadcrumb.
76 ! empty( $_GET['legacy-widget-preview'] ) ? aioseo()->breadcrumbs->frontend->preview() : aioseo()->breadcrumbs->frontend->display();
77
78 // Workaround for a bug in the Gutenberg widget preview.
79 echo '<span style="display: none">a</span>'; // TODO: remove this when the preview bug is fixed.
80
81 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
82 }
83
84 /**
85 * Widget option update.
86 *
87 * @since 4.1.1
88 *
89 * @param array $newInstance New instance options.
90 * @param array $oldInstance Old instance options.
91 * @return array Processed new instance options.
92 */
93 public function update( $newInstance, $oldInstance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
94 $newInstance['title'] = wp_strip_all_tags( $newInstance['title'] );
95
96 return $newInstance;
97 }
98
99 /**
100 * Widget options form.
101 *
102 * @since 4.1.1
103 *
104 * @param array $instance The widget instance options.
105 * @return void
106 */
107 public function form( $instance ) {
108 // Merge with defaults.
109 $instance = wp_parse_args( (array) $instance, $this->defaults );
110 ?>
111 <p>
112 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
113 <?php echo esc_html( __( 'Title:', 'all-in-one-seo-pack' ) ); ?>
114 </label>
115 <input
116 type="text"
117 id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
118 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
119 value="<?php echo esc_attr( $instance['title'] ); ?>"
120 class="widefat"
121 />
122 </p>
123 <?php
124 }
125 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 namespace AIOSEO\Plugin\Common\Core;
3
4 // Exit if accessed directly.
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use AIOSEO\Plugin\Common\Options;
10 use AIOSEO\Plugin\Common\Utils;
11
12 /**
13 * Loads core classes.
14 *
15 * @since 4.1.9
16 */
17 class Core {
18 /**
19 * AIOSEO Tables.
20 *
21 * @since 4.2.5
22 *
23 * @var array
24 */
25 private $aioseoTables = [
26 'aioseo_cache',
27 'aioseo_links',
28 'aioseo_links_suggestions',
29 'aioseo_notifications',
30 'aioseo_posts',
31 'aioseo_redirects',
32 'aioseo_redirects_404',
33 'aioseo_redirects_404_logs',
34 'aioseo_redirects_hits',
35 'aioseo_redirects_logs',
36 'aioseo_terms',
37 'aioseo_search_statistics_objects'
38 ];
39
40 /**
41 * Filesystem class instance.
42 *
43 * @since 4.2.7
44 *
45 * @var Utils\Filesystem
46 */
47 public $fs = null;
48
49 /**
50 * Filesystem class instance.
51 *
52 * @since 4.2.7
53 *
54 * @var Utils\Filesystem
55 */
56 public $assets = null;
57
58 /**
59 * Assets class instance.
60 *
61 * @since 4.2.7
62 *
63 * @var Utils\Database
64 */
65 public $db = null;
66
67 /**
68 * Cache class instance.
69 *
70 * @since 4.2.7
71 *
72 * @var Utils\Cache
73 */
74 public $cache = null;
75
76 /**
77 * NetworkCache class instance.
78 *
79 * @since 4.2.7
80 *
81 * @var Utils\NetworkCache
82 */
83 public $networkCache = null;
84
85 /**
86 * CachePrune class instance.
87 *
88 * @since 4.2.7
89 *
90 * @var Utils\CachePrune
91 */
92 public $cachePrune = null;
93
94 /**
95 * Cache class instance.
96 *
97 * @since 4.2.7
98 *
99 * @var Options\Cache
100 */
101 public $optionsCache = null;
102
103 /**
104 * Class constructor.
105 *
106 * @since 4.1.9
107 */
108 public function __construct() {
109 $this->fs = new Utils\Filesystem( $this );
110 $this->assets = new Utils\Assets( $this );
111 $this->db = new Utils\Database();
112 $this->cache = new Utils\Cache();
113 $this->networkCache = new Utils\NetworkCache();
114 $this->cachePrune = new Utils\CachePrune();
115 $this->optionsCache = new Options\Cache();
116 }
117
118 /**
119 * Removes all our tables and options.
120 *
121 * @since 4.2.3
122 *
123 * @param bool $force Whether we should ignore the uninstall option or not. We ignore it when we reset all data via the Debug Panel.
124 * @return void
125 */
126 public function uninstallDb( $force = false ) {
127 // Confirm that user has decided to remove all data, otherwise stop.
128 if ( ! $force && ! aioseo()->options->advanced->uninstall ) {
129 return;
130 }
131
132 // Delete all our custom tables.
133 global $wpdb;
134 foreach ( $this->getDbTables() as $tableName ) {
135 $wpdb->query( 'DROP TABLE IF EXISTS ' . $tableName ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
136 }
137
138 // Delete all AIOSEO Locations and Location Categories.
139 $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'aioseo-location'" );
140 $wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'aioseo-location-category'" );
141
142 // Delete all the plugin settings.
143 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'aioseo\_%'" );
144
145 // Remove any transients we've left behind.
146 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_aioseo\_%'" );
147 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'aioseo\_%'" );
148
149 // Delete all entries from the action scheduler table.
150 $wpdb->query( "DELETE FROM {$wpdb->prefix}actionscheduler_actions WHERE hook LIKE 'aioseo\_%'" );
151 $wpdb->query( "DELETE FROM {$wpdb->prefix}actionscheduler_groups WHERE slug = 'aioseo'" );
152 }
153
154 /**
155 * Get all the DB tables with prefix.
156 *
157 * @since 4.2.5
158 *
159 * @return array An array of tables.
160 */
161 public function getDbTables() {
162 global $wpdb;
163
164 $tables = [];
165 foreach ( $this->aioseoTables as $tableName ) {
166 $tables[] = $wpdb->prefix . $tableName;
167 }
168
169 return $tables;
170 }
171 }
...\ 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 the documentation 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 network cache.
49 *
50 * @since 4.0.0
51 *
52 * @return array Docs data.
53 */
54 public function getDocs() {
55 $aioseoAdminHelpDocs = aioseo()->core->networkCache->get( 'admin_help_docs' );
56 $aioseoAdminHelpDocsCacheTime = WEEK_IN_SECONDS;
57 if ( null === $aioseoAdminHelpDocs ) {
58 $request = aioseo()->helpers->wpRemoteGet( $this->getUrl() );
59
60 if ( is_wp_error( $request ) ) {
61 return [];
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()->core->networkCache->update( 'admin_help_docs', $aioseoAdminHelpDocs, $aioseoAdminHelpDocsCacheTime );
71 }
72
73 return $aioseoAdminHelpDocs ? json_decode( $aioseoAdminHelpDocs, true ) : [];
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
62 if ( count( $values['newOption'] ) - 1 !== $i ) {
63 $options = $options->$lastOption;
64 }
65 }
66
67 if ( $error ) {
68 continue;
69 }
70
71 switch ( $values['type'] ) {
72 case 'boolean':
73 if ( ! empty( $group[ $name ] ) ) {
74 $options->$lastOption = true;
75 break;
76 }
77 $options->$lastOption = false;
78 break;
79 case 'integer':
80 case 'float':
81 $value = aioseo()->helpers->sanitizeOption( $group[ $name ] );
82 if ( $value ) {
83 $options->$lastOption = $value;
84 }
85 break;
86 default:
87 $value = $group[ $name ];
88 if ( $convertMacros ) {
89 $value = $this->macrosToSmartTags( $value );
90 }
91 $options->$lastOption = aioseo()->helpers->sanitizeOption( $value );
92 break;
93 }
94 }
95 }
96 }
...\ 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 * Imports the settings.
17 *
18 * @since 4.2.7
19 *
20 * @return void
21 */
22 protected function importSettings() {}
23
24 /**
25 * Imports the post meta.
26 *
27 * @since 4.2.7
28 *
29 * @return void
30 */
31 protected function importPostMeta() {}
32
33 /**
34 * Imports the term meta.
35 *
36 * @since 4.2.7
37 *
38 * @return void
39 */
40 protected function importTermMeta() {}
41
42 /**
43 * PostMeta class instance.
44 *
45 * @since 4.2.7
46 *
47 * @var Object
48 */
49 protected $postMeta = null;
50
51 /**
52 * TermMeta class instance.
53 *
54 * @since 4.2.7
55 *
56 * @var Object
57 */
58 protected $termMeta = null;
59
60 /**
61 * Helpers class instance.
62 *
63 * @since 4.2.7
64 *
65 * @var Object
66 */
67 public $helpers = null;
68
69 /**
70 * Starts the import.
71 *
72 * @since 4.0.0
73 *
74 * @param array $options What the user wants to import.
75 * @return void
76 */
77 public function doImport( $options = [] ) {
78 if ( empty( $options ) ) {
79 $this->importSettings();
80 $this->importPostMeta();
81 $this->importTermMeta();
82
83 return;
84 }
85
86 foreach ( $options as $optionName ) {
87 switch ( $optionName ) {
88 case 'settings':
89 $this->importSettings();
90 break;
91 case 'postMeta':
92 $this->postMeta->scheduleImport();
93 break;
94 default:
95 break;
96 }
97 }
98 }
99 }
...\ 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 * List of options.
19 *
20 * @since 4.2.7
21 *
22 * @var array
23 */
24 private $options = [];
25
26 /**
27 * Class constructor.
28 *
29 * @since 4.0.0
30 */
31 public function __construct() {
32 $this->options = get_option( 'rank-math-options-general' );
33 if ( empty( $this->options ) ) {
34 return;
35 }
36
37 $this->isTruSeoDisabled();
38 $this->migrateRedirectAttachments();
39 $this->migrateStripCategoryBase();
40 $this->migrateRssContentSettings();
41
42 $settings = [
43 'google_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'google' ] ],
44 'bing_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'bing' ] ],
45 'yandex_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'yandex' ] ],
46 'baidu_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'baidu' ] ],
47 'pinterest_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'pinterest' ] ],
48 ];
49
50 aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
51 }
52
53 /**
54 * Checks whether TruSEO should be disabled.
55 *
56 * @since 4.0.0
57 *
58 * @return void
59 */
60 private function isTruSeoDisabled() {
61 if ( ! empty( $this->options['frontend_seo_score'] ) ) {
62 aioseo()->options->advanced->truSeo = 'on' === $this->options['frontend_seo_score'];
63 }
64 }
65
66 /**
67 * Migrates the Redirect Attachments setting.
68 *
69 * @since 4.0.0
70 *
71 * @return void
72 */
73 private function migrateRedirectAttachments() {
74 if ( isset( $this->options['attachment_redirect_urls'] ) ) {
75 if ( 'on' === $this->options['attachment_redirect_urls'] ) {
76 aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'attachment_parent';
77 } else {
78 aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'disabled';
79 }
80 }
81 }
82
83 /**
84 * Migrates the Strip Category Base setting.
85 *
86 * @since 4.2.0
87 *
88 * @return void
89 */
90 private function migrateStripCategoryBase() {
91 if ( isset( $this->options['strip_category_base'] ) ) {
92 aioseo()->options->searchAppearance->advanced->removeCatBase = 'on' === $this->options['strip_category_base'] ? true : false;
93 }
94 }
95
96 /**
97 * Migrates the RSS content settings.
98 *
99 * @since 4.0.0
100 *
101 * @return void
102 */
103 private function migrateRssContentSettings() {
104 if ( isset( $this->options['rss_before_content'] ) ) {
105 aioseo()->options->rssContent->before = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_before_content'] ) );
106 }
107
108 if ( isset( $this->options['rss_after_content'] ) ) {
109 aioseo()->options->rssContent->after = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_after_content'] ) );
110 }
111 }
112 }
...\ 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()->core->cache->get( 'import_post_meta_rank_math' ) ) {
33 aioseo()->core->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()->core->cache->get( 'import_post_meta_rank_math' ) );
53
54 $posts = aioseo()->core->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 ->groupBy( 'p.ID' )
64 ->limit( $postsPerAction )
65 ->run()
66 ->result();
67
68 if ( ! $posts || ! count( $posts ) ) {
69 aioseo()->core->cache->delete( 'import_post_meta_rank_math' );
70
71 return;
72 }
73
74 $mappedMeta = [
75 'rank_math_title' => 'title',
76 'rank_math_description' => 'description',
77 'rank_math_canonical_url' => 'canonical_url',
78 'rank_math_focus_keyword' => 'keyphrases',
79 'rank_math_robots' => '',
80 'rank_math_advanced_robots' => '',
81 'rank_math_facebook_title' => 'og_title',
82 'rank_math_facebook_description' => 'og_description',
83 'rank_math_facebook_image' => 'og_image_custom_url',
84 'rank_math_twitter_use_facebook' => 'twitter_use_og',
85 'rank_math_twitter_title' => 'twitter_title',
86 'rank_math_twitter_description' => 'twitter_description',
87 'rank_math_twitter_image' => 'twitter_image_custom_url',
88 'rank_math_twitter_card_type' => 'twitter_card'
89 ];
90
91 foreach ( $posts as $post ) {
92 $postMeta = aioseo()->core->db
93 ->start( 'postmeta' . ' as pm' )
94 ->select( 'pm.meta_key, pm.meta_value' )
95 ->where( 'pm.post_id', $post->ID )
96 ->whereRaw( "`pm`.`meta_key` LIKE 'rank_math_%'" )
97 ->run()
98 ->result();
99
100 $meta = [
101 'post_id' => $post->ID,
102 ];
103
104 if ( ! $postMeta || ! count( $postMeta ) ) {
105 $aioseoPost = Models\Post::getPost( (int) $post->ID );
106 $aioseoPost->set( $meta );
107 $aioseoPost->save();
108
109 aioseo()->migration->meta->migrateAdditionalPostMeta( $post->ID );
110 continue;
111 }
112
113 foreach ( $postMeta as $record ) {
114 $name = $record->meta_key;
115 $value = $record->meta_value;
116
117 if (
118 ! in_array( $post->post_type, [ 'page', 'attachment' ], true ) &&
119 preg_match( '#^rank_math_schema_([^\s]*)$#', $name, $match ) && ! empty( $match[1] )
120 ) {
121 switch ( $match[1] ) {
122 case 'Article':
123 case 'NewsArticle':
124 case 'BlogPosting':
125 $meta['schema_type'] = 'Article';
126 $meta['schema_type_options'] = wp_json_encode(
127 [ 'article' => [ 'articleType' => $match[1] ] ]
128 );
129 break;
130 default:
131 break;
132 }
133 }
134
135 if ( ! in_array( $name, array_keys( $mappedMeta ), true ) ) {
136 continue;
137 }
138
139 switch ( $name ) {
140 case 'rank_math_focus_keyword':
141 $keyphrases = array_map( 'trim', explode( ',', $value ) );
142 $keyphraseArray = [
143 'focus' => [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $keyphrases[0] ) ],
144 'additional' => []
145 ];
146 unset( $keyphrases[0] );
147 foreach ( $keyphrases as $keyphrase ) {
148 $keyphraseArray['additional'][] = [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $keyphrase ) ];
149 }
150
151 $meta['keyphrases'] = wp_json_encode( $keyphraseArray );
152 break;
153 case 'rank_math_robots':
154 $value = aioseo()->helpers->maybeUnserialize( $value );
155 if ( ! empty( $value ) ) {
156 $meta['robots_default'] = false;
157 foreach ( $value as $robotsName ) {
158 $meta[ "robots_$robotsName" ] = true;
159 }
160 }
161 break;
162 case 'rank_math_advanced_robots':
163 $value = aioseo()->helpers->maybeUnserialize( $value );
164 if ( ! empty( $value['max-snippet'] ) && intval( $value['max-snippet'] ) ) {
165 $meta['robots_max_snippet'] = intval( $value['max-snippet'] );
166 }
167 if ( ! empty( $value['max-video-preview'] ) && intval( $value['max-video-preview'] ) ) {
168 $meta['robots_max_videopreview'] = intval( $value['max-video-preview'] );
169 }
170 if ( ! empty( $value['max-image-preview'] ) ) {
171 $meta['robots_max_imagepreview'] = aioseo()->helpers->sanitizeOption( lcfirst( $value['max-image-preview'] ) );
172 }
173 break;
174 case 'rank_math_facebook_image':
175 $meta['og_image_type'] = 'custom_image';
176 $meta[ $mappedMeta[ $name ] ] = esc_url( $value );
177 break;
178 case 'rank_math_twitter_image':
179 $meta['twitter_image_type'] = 'custom_image';
180 $meta[ $mappedMeta[ $name ] ] = esc_url( $value );
181 break;
182 case 'rank_math_twitter_card_type':
183 preg_match( '#large#', $value, $match );
184 $meta[ $mappedMeta[ $name ] ] = ! empty( $match ) ? 'summary_large_image' : 'summary';
185 break;
186 case 'rank_math_twitter_use_facebook':
187 $meta[ $mappedMeta[ $name ] ] = 'on' === $value;
188 break;
189 case 'rank_math_title':
190 case 'rank_math_description':
191 if ( 'page' === $post->post_type ) {
192 $value = aioseo()->helpers->pregReplace( '#%category%#', '', $value );
193 $value = aioseo()->helpers->pregReplace( '#%excerpt%#', '', $value );
194 }
195 $value = aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value );
196 default:
197 $meta[ $mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
198 break;
199 }
200 }
201
202 $aioseoPost = Models\Post::getPost( $post->ID );
203 $aioseoPost->set( $meta );
204 $aioseoPost->save();
205
206 aioseo()->migration->meta->migrateAdditionalPostMeta( $post->ID );
207 }
208
209 if ( count( $posts ) === $postsPerAction ) {
210 try {
211 as_schedule_single_action( time() + 5, aioseo()->importExport->rankMath->postActionName, [], 'aioseo' );
212 } catch ( \Exception $e ) {
213 // Do nothing.
214 }
215 } else {
216 aioseo()->core->cache->delete( 'import_post_meta_rank_math' );
217 }
218 }
219 }
...\ 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.
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.