PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.6
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 18.6, at src/actions/importing/aioseo/aioseo-general-settings-importing-action.php

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