HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
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/html/wpsysiot/wp-content/plugins/pro-elements/modules/lottie/classes/caption-helper.php
<?php

namespace ElementorPro\Modules\Lottie\Classes;

use ElementorPro\Core\Isolation\Wordpress_Adapter_Interface;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

class Caption_Helper {
	private Wordpress_Adapter_Interface $wp_adapter;
	private array $settings = [];

	public function __construct( Wordpress_Adapter_Interface $wp_adapter, array $settings ) {
		$this->wp_adapter = $wp_adapter;
		$this->settings = $settings;
	}

	public function get_caption() {
		if ( $this->has_custom_caption() ) {
			return $this->get_custom_caption();
		}

		if ( $this->has_attachment_caption() ) {
			return $this->get_attachment_caption();
		}

		if ( $this->has_title_caption() ) {
			return $this->get_title_caption();
		}

		return '';
	}

	private function get_custom_caption() {
		return $this->settings['caption'] ?? '';
	}

	private function get_attachment_caption() {
		$attachment_id = $this->settings['source_json']['id'];

		if ( ! $this->user_can_access( $attachment_id ) ) {
			return '';
		}

		return $this->wp_adapter->wp_get_attachment_caption( $attachment_id );
	}

	private function get_title_caption() {
		$post_id = $this->settings['source_json']['id'];

		if ( ! $this->user_can_access( $post_id ) ) {
			return '';
		}

		return $this->wp_adapter->get_the_title( $post_id );
	}

	private function user_can_access( $resource_id ) {
		if ( $this->wp_adapter->current_user_can( 'manage_options' ) ) {
			return true;
		}

		if ( $this->wp_adapter->current_user_can( 'edit_post', $resource_id ) ) {
			return true;
		}

		if ( $this->wp_adapter->current_user_can( 'read_post', $resource_id ) ) {
			return true;
		}

		return false;
	}

	private function has_title_caption() {
		return 'title' === $this->settings['caption_source'];
	}

	private function has_custom_caption() {
		if ( $this->is_external_url_caption() ) {
			return true;
		}

		if ( 'custom' === $this->settings['caption_source'] ) {
			return $this->is_media_file_caption();
		}

		return false;
	}

	private function has_attachment_caption() {
		return 'caption' === $this->settings['caption_source'];
	}

	private function is_media_file_caption() {
		return 'media_file' === $this->settings['source'] && 'none' !== $this->settings['caption_source'];
	}

	private function is_external_url_caption() {
		return 'external_url' === $this->settings['source'] && '' !== $this->settings['caption'];
	}
}