first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
class WPML_LS_Actions extends WPML_LS_Public_API {
public function init_hooks() {
if ( $this->sitepress->get_setting( 'setup_complete' ) ) {
add_action( 'wpml_language_switcher', array( $this, 'callback' ), 10, 2 );
/**
* Backward compatibility
*
* @deprecated see 'wpml_language_switcher'
*/
add_action( 'icl_language_selector', array( $this, 'callback' ) );
add_action( 'wpml_add_language_selector', array( $this, 'callback' ) );
add_action( 'wpml_footer_language_selector', array( $this, 'callback' ) );
}
}
/**
* @param array $args
* @param string|null $twig_template
*/
public function callback( $args, $twig_template = null ) {
if ( '' === $args ) {
$args = array();
}
$args = $this->parse_legacy_actions( $args );
$args = $this->convert_shortcode_args_aliases( $args );
echo $this->render( $args, $twig_template );
}
/**
* @param array $args
*
* @return array
*/
private function parse_legacy_actions( $args ) {
$current_filter = current_filter();
if ( in_array( $current_filter, array( 'icl_language_selector', 'wpml_add_language_selector' ) ) ) {
$args['type'] = 'custom';
} elseif ( 'wpml_footer_language_selector' === $current_filter ) {
$args['type'] = 'footer';
}
return $args;
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* Class WPML_LS_Public_API
*/
class WPML_LS_Public_API {
/** @var WPML_LS_Settings $settings */
private $settings;
/** @var WPML_LS_Render $render */
private $render;
/** @var SitePress $sitepress */
protected $sitepress;
/** @var WPML_LS_Slot_Factory */
private $slot_factory;
/**
* WPML_LS_Public_API constructor.
*
* @param WPML_LS_Settings $settings
* @param WPML_LS_Render $render
* @param SitePress $sitepress
* @param WPML_LS_Slot_Factory $slot_factory
*/
public function __construct(
WPML_LS_Settings $settings,
WPML_LS_Render $render,
SitePress $sitepress,
WPML_LS_Slot_Factory $slot_factory = null
) {
$this->settings = $settings;
$this->render = $render;
$this->sitepress = $sitepress;
$this->slot_factory = $slot_factory;
}
/**
* @param array $args
* @param string|null $twig_template
*
* @return string
*/
protected function render( $args, $twig_template = null ) {
$defaults_slot_args = $this->get_default_slot_args( $args );
$slot_args = array_merge( $defaults_slot_args, $args );
$slot = $this->get_slot_factory()->get_slot( $slot_args );
$slot->set( 'show', 1 );
$slot->set( 'template_string', $twig_template );
if ( $slot->is_post_translations() ) {
$output = $this->render->post_translations_label( $slot );
} else {
$output = $this->render->render( $slot );
}
return $output;
}
/**
* @param array $args
*
* @return array
*/
private function get_default_slot_args( $args ) {
$type = 'custom';
if ( isset( $args['type'] ) ) {
$type = $args['type'];
}
switch ( $type ) {
case 'footer':
$default_slot = $this->settings->get_slot( 'statics', 'footer' );
break;
case 'post_translations':
$default_slot = $this->settings->get_slot( 'statics', 'post_translations' );
break;
case 'widget':
$default_slot = $this->get_slot_factory()->get_default_slot( 'sidebars' );
break;
case 'custom':
default:
$default_slot = $this->settings->get_slot( 'statics', 'shortcode_actions' );
break;
}
return $default_slot->get_model();
}
/**
* @param array $args
*
* @return array
*/
protected function convert_shortcode_args_aliases( $args ) {
$aliases_map = self::get_argument_aliases();
foreach ( $aliases_map as $alias => $key ) {
if ( array_key_exists( $alias, $args ) ) {
$args[ $key ] = $args[ $alias ];
unset( $args[ $alias ] );
}
}
return $args;
}
/**
* @return array
*/
public static function get_argument_aliases() {
return array(
'flags' => 'display_flags',
'link_current' => 'display_link_for_current_lang',
'native' => 'display_names_in_native_lang',
'translated' => 'display_names_in_current_lang',
);
}
/**
* @return WPML_LS_Slot_Factory
*/
private function get_slot_factory() {
if ( ! $this->slot_factory ) {
$this->slot_factory = new WPML_LS_Slot_Factory();
}
return $this->slot_factory;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Class WPML_LS_Shortcodes
*/
class WPML_LS_Shortcodes extends WPML_LS_Public_API {
public function init_hooks() {
if ( $this->sitepress->get_setting( 'setup_complete' ) ) {
add_shortcode( 'wpml_language_switcher', array( $this, 'callback' ) );
// Backward compatibility
add_shortcode( 'wpml_language_selector_widget', array( $this, 'callback' ) );
add_shortcode( 'wpml_language_selector_footer', array( $this, 'callback' ) );
}
}
/**
* @param array|string $args
* @param string|null $content
* @param string $tag
*
* @return string
*/
public function callback( $args, $content = null, $tag = '' ) {
$args = (array) $args;
$args = $this->parse_legacy_shortcodes( $args, $tag );
$args = $this->convert_shortcode_args_aliases( $args );
return $this->render( $args, $content );
}
/**
* @param array $args
* @param string $tag
*
* @return mixed
*/
private function parse_legacy_shortcodes( $args, $tag ) {
if ( 'wpml_language_selector_widget' === $tag ) {
$args['type'] = 'custom';
} elseif ( 'wpml_language_selector_footer' === $tag ) {
$args['type'] = 'footer';
}
return $args;
}
}