| Server IP : 219.234.31.115 / Your IP : 216.73.217.134 Web Server : Apache System : Linux ebs-140924 5.10.0-30-amd64 #1 SMP Debian 5.10.218-1 (2024-06-01) x86_64 User : vndaystarftp ( 67432) PHP Version : 7.3.33 Disable Function : link,symlink,passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server,pcntl_fork,pcntl_rfork MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/wwwroot/vndaystarftp/wwwroot/wp-content/plugins/wpml-string-translation/classes/ |
Upload File : |
<?php
namespace WPML\ST;
class Shortcode {
const STRING_DOMAIN = 'wpml-shortcode';
private $context;
private $name;
/**
* @var \wpdb
*/
private $wpdb;
public function __construct( \wpdb $wpdb ) {
$this->wpdb = $wpdb;
}
function init_hooks() {
add_shortcode( 'wpml-string', [ $this, 'render' ] );
}
/**
* @param array $attributes
* @param string $value
*
* @return string
*/
function render( $attributes, $value ) {
$this->parse_attributes( $attributes, $value );
$this->maybe_register_string( $value );
return do_shortcode( icl_t( $this->context, $this->name, $value ) );
}
/**
* @param string $value
*/
private function maybe_register_string( $value ) {
$string = $this->get_registered_string();
if ( ! $string || $string->value !== $value ) {
icl_register_string( $this->context, $this->name, $value );
}
}
/**
* @param array $attributes
* @param string $value
*/
private function parse_attributes( $attributes, $value ) {
$pairs = array(
'context' => self::STRING_DOMAIN,
'name' => 'wpml-shortcode-' . md5( $value ),
);
$attributes = shortcode_atts( $pairs, $attributes );
$this->context = $attributes['context'];
$this->name = $attributes['name'];
}
/**
* @return \stdClass
*/
private function get_registered_string() {
$strings = $this->get_strings_registered_in_context();
if ( $strings && array_key_exists( $this->name, $strings ) ) {
return $strings[ $this->name ];
}
return null;
}
/**
* @return \stdClass[]
*/
private function get_strings_registered_in_context() {
$cache_key = $this->context;
$cache_group = 'wpml-string-shortcode';
$cache_found = false;
$string = wp_cache_get( $cache_key, $cache_group, false, $cache_found );
if ( ! $cache_found ) {
$query = 'SELECT name, id, value, status FROM ' . $this->wpdb->prefix . 'icl_strings WHERE context=%s';
$sql = $this->wpdb->prepare( $query, $this->context );
$string = $this->wpdb->get_results( $sql, OBJECT_K );
wp_cache_set( $cache_key, $string, $cache_group );
}
return $string;
}
}