image = $image; } /** * Builds the mapping that ties AOISEO option keys with Yoast ones and their data transformation method. * * @return void */ protected function build_mapping() { $this->aioseo_options_to_yoast_map = [ '/separator' => [ 'yoast_name' => 'separator', 'transform_method' => 'transform_separator', ], '/siteTitle' => [ 'yoast_name' => 'title-home-wpseo', 'transform_method' => 'simple_import', ], '/metaDescription' => [ 'yoast_name' => 'metadesc-home-wpseo', 'transform_method' => 'simple_import', ], '/schema/siteRepresents' => [ 'yoast_name' => 'company_or_person', 'transform_method' => 'transform_site_represents', ], '/schema/person' => [ 'yoast_name' => 'company_or_person_user_id', 'transform_method' => 'simple_import', ], '/schema/organizationName' => [ 'yoast_name' => 'company_name', 'transform_method' => 'simple_import', ], '/schema/organizationLogo' => [ 'yoast_name' => 'company_logo', 'transform_method' => 'import_company_logo', ], '/schema/personLogo' => [ 'yoast_name' => 'person_logo', 'transform_method' => 'import_person_logo', ], ]; } /** * Imports the organization logo while also accounting for the id of the log to be saved in the separate Yoast option. * * @param string $logo_url The company logo url coming from AIOSEO settings. * * @return string The transformed company logo url. */ public function import_company_logo( $logo_url ) { $logo_id = $this->image->get_attachment_by_url( $logo_url ); $this->options->set( 'company_logo_id', $logo_id ); $this->options->set( 'company_logo_meta', false ); $logo_meta = $this->image->get_attachment_meta_from_settings( 'company_logo' ); $this->options->set( 'company_logo_meta', $logo_meta ); return $this->url_import( $logo_url ); } /** * Imports the person logo while also accounting for the id of the log to be saved in the separate Yoast option. * * @param string $logo_url The person logo url coming from AIOSEO settings. * * @return string The transformed person logo url. */ public function import_person_logo( $logo_url ) { $logo_id = $this->image->get_attachment_by_url( $logo_url ); $this->options->set( 'person_logo_id', $logo_id ); $this->options->set( 'person_logo_meta', false ); $logo_meta = $this->image->get_attachment_meta_from_settings( 'person_logo' ); $this->options->set( 'person_logo_meta', $logo_meta ); return $this->url_import( $logo_url ); } /** * Transforms the site represents setting. * * @param string $site_represents The site represents setting. * * @return string The transformed site represents setting. */ public function transform_site_represents( $site_represents ) { switch ( $site_represents ) { case 'person': return 'person'; case 'organization': default: return 'company'; } } /** * Transforms the separator setting. * * @param string $separator The separator setting. * * @return string The transformed separator. */ public function transform_separator( $separator ) { switch ( $separator ) { case '-': return 'sc-dash'; case '–': return 'sc-ndash'; case '—': return 'sc-mdash'; case '»': return 'sc-raquo'; case '«': return 'sc-laquo'; case '>': return 'sc-gt'; case '•': return 'sc-bull'; case '|': return 'sc-pipe'; default: return 'sc-dash'; } } }