HEX
Server: Apache
System: Linux websend04.greenconsulting.it 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
User: web20 (5023)
PHP: 7.2.34-38+ubuntu18.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/clients/client0/web20/web/wp-content/plugins/wpml-string-translation/classes/Shortcode.php
<?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;
	}
}