HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
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,pcntl_unshare,
Upload Files
File: /var/www/zaklada/wp-content/plugins/wpml-translation-management/classes/jobs/utils/ElementLink.php
<?php

namespace WPML\TM\Jobs\Utils;

use stdClass;
use WPML_Post_Translation;
use WPML_TM_Post_Link_Factory;

class ElementLink {

	/** @var WPML_TM_Post_Link_Factory $postLinkFactory */
	private $postLinkFactory;

	/** @var WPML_Post_Translation $postTranslation */
	private $postTranslation;

	public function __construct( WPML_TM_Post_Link_Factory $postLinkFactory, WPML_Post_Translation $postTranslation ) {
		$this->postLinkFactory = $postLinkFactory;
		$this->postTranslation = $postTranslation;
	}

	/**
	 * @param stdClass $job
	 *
	 * @return string
	 */
	public function getOriginal( stdClass $job ) {
		return $this->get( $job, __( 'View original', 'wpml-translation-management' ) );
	}

	/**
	 * @param stdClass $job
	 *
	 * @return string
	 */
	public function getTranslation( stdClass $job ) {
		if ( $this->isExternalType( $job->element_type_prefix ) ) {
			return '';
		}

		$translatedId = $this->postTranslation->element_id_in( $job->original_doc_id, $job->language_code );

		if ( $translatedId ) {
			return $this->get( $job, __( 'View', 'wpml-translation-management' ), $translatedId );
		}

		return '';
	}

	/**
	 * @param stdClass    $job
	 * @param string      $viewText
	 * @param string|null $elementId
	 *
	 * @return mixed|string|void
	 */
	private function get( stdClass $job, $viewText, $elementId = null ) {
		$elementId   = $elementId ?: $job->original_doc_id;
		$elementType = preg_replace( '/^' . $job->element_type_prefix . '_/', '', $job->original_post_type );

		if ( $this->isExternalType( $job->element_type_prefix ) ) {
			$url          = apply_filters( 'wpml_external_item_url', '', $elementId );
			$tmPostLink = '<a href="' . $url . '">' . $viewText . '</a>';
		} else {
			$tmPostLink = $this->postLinkFactory->view_link_anchor( $elementId, $viewText, '_blank' );
		}

		$tmPostLink = apply_filters( 'wpml_document_view_item_link',
		                               $tmPostLink,
		                               $viewText,
		                               $job,
		                               $job->element_type_prefix,
		                               $elementType );

		return $tmPostLink;
	}

	/**
	 * @param string $elementTypePrefix
	 *
	 * @return bool
	 */
	private function isExternalType( $elementTypePrefix ) {
		return apply_filters( 'wpml_is_external', false, $elementTypePrefix );
	}
}