PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.7
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / actions / importing / aioseo / aioseo-general-settings-importing-action.php

aioseo-general-settings-importing-action.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.7, at src/actions/importing/aioseo/aioseo-general-settings-importing-action.php

214 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
4 namespace Yoast\WP\SEO\Actions\Importing\Aioseo;
5
6 use Yoast\WP\SEO\Helpers\Image_Helper;
7 use Yoast\WP\SEO\Helpers\Import_Cursor_Helper;
8 use Yoast\WP\SEO\Helpers\Options_Helper;
9 use Yoast\WP\SEO\Helpers\Sanitization_Helper;
10 use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Replacevar_Service;
11 use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Provider_Service;
12 use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Transformer_Service;
13
14 /**
15 * Importing action for AIOSEO general settings.
16 */
17 class Aioseo_General_Settings_Importing_Action extends Abstract_Aioseo_Settings_Importing_Action {
18
19 /**
20 * The plugin of the action.
21 */
22 public const PLUGIN = 'aioseo';
23
24 /**
25 * The type of the action.
26 */
27 public const TYPE = 'general_settings';
28
29 /**
30 * The option_name of the AIOSEO option that contains the settings.
31 */
32 public const SOURCE_OPTION_NAME = 'aioseo_options';
33
34 /**
35 * The map of aioseo_options to yoast settings.
36 *
37 * @var array
38 */
39 protected $aioseo_options_to_yoast_map = [];
40
41 /**
42 * The tab of the aioseo settings we're working with.
43 *
44 * @var string
45 */
46 protected $settings_tab = 'global';
47
48 /**
49 * The image helper.
50 *
51 * @var Image_Helper
52 */
53 protected $image;
54
55 /**
56 * Aioseo_General_Settings_Importing_Action constructor.
57 *
58 * @param Import_Cursor_Helper $import_cursor The import cursor helper.
59 * @param Options_Helper $options The options helper.
60 * @param Sanitization_Helper $sanitization The sanitization helper.
61 * @param Image_Helper $image The image helper.
62 * @param Aioseo_Replacevar_Service $replacevar_handler The replacevar handler.
63 * @param Aioseo_Robots_Provider_Service $robots_provider The robots provider service.
64 * @param Aioseo_Robots_Transformer_Service $robots_transformer The robots transfomer service.
65 */
66 public function __construct(
67 Import_Cursor_Helper $import_cursor,
68 Options_Helper $options,
69 Sanitization_Helper $sanitization,
70 Image_Helper $image,
71 Aioseo_Replacevar_Service $replacevar_handler,
72 Aioseo_Robots_Provider_Service $robots_provider,
73 Aioseo_Robots_Transformer_Service $robots_transformer
74 ) {
75 parent::__construct( $import_cursor, $options, $sanitization, $replacevar_handler, $robots_provider, $robots_transformer );
76
77 $this->image = $image;
78 }
79
80 /**
81 * Builds the mapping that ties AOISEO option keys with Yoast ones and their data transformation method.
82 *
83 * @return void
84 */
85 protected function build_mapping() {
86 $this->aioseo_options_to_yoast_map = [
87 '/separator' => [
88 'yoast_name' => 'separator',
89 'transform_method' => 'transform_separator',
90 ],
91 '/siteTitle' => [
92 'yoast_name' => 'title-home-wpseo',
93 'transform_method' => 'simple_import',
94 ],
95 '/metaDescription' => [
96 'yoast_name' => 'metadesc-home-wpseo',
97 'transform_method' => 'simple_import',
98 ],
99 '/schema/siteRepresents' => [
100 'yoast_name' => 'company_or_person',
101 'transform_method' => 'transform_site_represents',
102 ],
103 '/schema/person' => [
104 'yoast_name' => 'company_or_person_user_id',
105 'transform_method' => 'simple_import',
106 ],
107 '/schema/organizationName' => [
108 'yoast_name' => 'company_name',
109 'transform_method' => 'simple_import',
110 ],
111 '/schema/organizationLogo' => [
112 'yoast_name' => 'company_logo',
113 'transform_method' => 'import_company_logo',
114 ],
115 '/schema/personLogo' => [
116 'yoast_name' => 'person_logo',
117 'transform_method' => 'import_person_logo',
118 ],
119 ];
120 }
121
122 /**
123 * Imports the organization logo while also accounting for the id of the log to be saved in the separate Yoast option.
124 *
125 * @param string $logo_url The company logo url coming from AIOSEO settings.
126 *
127 * @return string The transformed company logo url.
128 */
129 public function import_company_logo( $logo_url ) {
130 $logo_id = $this->image->get_attachment_by_url( $logo_url );
131 $this->options->set( 'company_logo_id', $logo_id );
132
133 $this->options->set( 'company_logo_meta', false );
134 $logo_meta = $this->image->get_attachment_meta_from_settings( 'company_logo' );
135 $this->options->set( 'company_logo_meta', $logo_meta );
136
137 return $this->url_import( $logo_url );
138 }
139
140 /**
141 * Imports the person logo while also accounting for the id of the log to be saved in the separate Yoast option.
142 *
143 * @param string $logo_url The person logo url coming from AIOSEO settings.
144 *
145 * @return string The transformed person logo url.
146 */
147 public function import_person_logo( $logo_url ) {
148 $logo_id = $this->image->get_attachment_by_url( $logo_url );
149 $this->options->set( 'person_logo_id', $logo_id );
150
151 $this->options->set( 'person_logo_meta', false );
152 $logo_meta = $this->image->get_attachment_meta_from_settings( 'person_logo' );
153 $this->options->set( 'person_logo_meta', $logo_meta );
154
155 return $this->url_import( $logo_url );
156 }
157
158 /**
159 * Transforms the site represents setting.
160 *
161 * @param string $site_represents The site represents setting.
162 *
163 * @return string The transformed site represents setting.
164 */
165 public function transform_site_represents( $site_represents ) {
166 switch ( $site_represents ) {
167 case 'person':
168 return 'person';
169
170 case 'organization':
171 default:
172 return 'company';
173 }
174 }
175
176 /**
177 * Transforms the separator setting.
178 *
179 * @param string $separator The separator setting.
180 *
181 * @return string The transformed separator.
182 */
183 public function transform_separator( $separator ) {
184 switch ( $separator ) {
185 case '&#45;':
186 return 'sc-dash';
187
188 case '&ndash;':
189 return 'sc-ndash';
190
191 case '&mdash;':
192 return 'sc-mdash';
193
194 case '&raquo;':
195 return 'sc-raquo';
196
197 case '&laquo;':
198 return 'sc-laquo';
199
200 case '&gt;':
201 return 'sc-gt';
202
203 case '&bull;':
204 return 'sc-bull';
205
206 case '&#124;':
207 return 'sc-pipe';
208
209 default:
210 return 'sc-dash';
211 }
212 }
213 }
214