HEX
Server: LiteSpeed
System: Linux srv158.niagahoster.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: u1694298 (3732)
PHP: 7.4.33
Disabled: symlink,shell_exec,exec,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Upload Files
File: /home/u1694298/www/wp-content/plugins/yop-poll/includes/Templates/class-template-engine.php
<?php
namespace YopPoll\Templates;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Template_Engine {

	public static function get_template_path( $base ) {
		$path = YOP_POLL_DIR . 'includes/Templates/' . sanitize_file_name( $base ) . '/template.php';
		if ( file_exists( $path ) ) {
			return $path;
		}
		return YOP_POLL_DIR . 'includes/Templates/classic/template.php';
	}

	public static function get_template_style_url( $base ) {
		$file = 'includes/Templates/' . sanitize_file_name( $base ) . '/style.css';
		if ( file_exists( YOP_POLL_DIR . $file ) ) {
			return YOP_POLL_URL . $file;
		}
		return YOP_POLL_URL . 'includes/Templates/classic/style.css';
	}

	/**
	 * Resolve the CSS base for a poll, falling back to 'classic' when the
	 * template directory does not exist (e.g. base = 'custom').
	 */
	public static function resolve_css_base( string $base ): string {
		$dir = YOP_POLL_DIR . 'includes/Templates/' . sanitize_file_name( $base );
		return is_dir( $dir ) ? $base : 'classic';
	}

	/**
	 * Resolve the CSS base for a specific poll, consulting the template's
	 * rendering_base when the poll's own template_base has no directory.
	 */
	public static function resolve_css_base_for_poll( string $base, int $template_id ): string {
		$dir = YOP_POLL_DIR . 'includes/Templates/' . sanitize_file_name( $base );
		if ( is_dir( $dir ) ) {
			return $base;
		}
		// Directory missing (e.g. base = 'custom'): look up the template row.
		if ( $template_id > 0 ) {
			global $wpdb;
			$table = $wpdb->prefix . YOP_POLL_TABLE_PREFIX . 'templates';
			$row   = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter -- $table built from $wpdb->prefix . YOP_POLL_TABLE_PREFIX; one-row template lookup for CSS base resolution.
				$wpdb->prepare( "SELECT rendering_base FROM {$table} WHERE id = %d", $template_id ), // phpcs:ignore WordPress.DB.PreparedSQL
				ARRAY_A
			);
			if ( $row && ! empty( $row['rendering_base'] ) ) {
				$rb  = sanitize_key( $row['rendering_base'] );
				$dir = YOP_POLL_DIR . 'includes/Templates/' . sanitize_file_name( $rb );
				if ( is_dir( $dir ) ) {
					return $rb;
				}
			}
		}
		return 'classic';
	}
}