$plugin = <<403WebShell
403Webshell
Server IP : 193.224.177.188  /  Your IP : 216.73.217.123
Web Server : Apache
System : Linux cpanel.krtk.mta.hu 3.10.0-962.3.2.lve1.5.89.el7.x86_64 #1 SMP Thu Jul 9 15:55:31 UTC 2026 x86_64
User : krtkhu ( 1061)
PHP Version : 8.4.28
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home2/krtkhu/www/wp-content/plugins/hellopack-client/includes/Api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home2/krtkhu/www/wp-content/plugins/hellopack-client/includes/Api/Normalizer.php
<?php
/**
 * API response normalizer.
 *
 * @package HelloPack\Client
 */

declare( strict_types=1 );

namespace HelloPack\Client\Api;

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

/**
 * Normalizes raw API responses into a consistent format.
 */
class Normalizer {

	/**
	 * Normalize a plugin from API response.
	 *
	 * @param array<string, mixed> $plugin Raw plugin data.
	 * @return array<string, mixed>
	 */
	public function normalize_plugin( array $plugin ): array {
		$requires         = null;
		$tested           = null;
		$requires_plugins = array();

		$versions = $this->extract_compatible_versions( $plugin );
		if ( ! empty( $versions ) ) {
			$requires = $versions[ count( $versions ) - 1 ];
			$tested   = $versions[0];
		}

		if ( ! empty( $plugin['wordpress_plugin_metadata']['requires_plugins'] ) ) {
			$required = $plugin['wordpress_plugin_metadata']['requires_plugins'];
			if ( is_string( $required ) ) {
				$requires_plugins = array_map( 'trim', explode( ',', $required ) );
			} elseif ( is_array( $required ) ) {
				$requires_plugins = $required;
			}
		}

		$meta = $plugin['wordpress_plugin_metadata'] ?? array();

		$normalized = array(
			'id'               => $plugin['id'] ?? 0,
			'slug'             => $plugin['slug'] ?? '',
			'name'             => $meta['plugin_name'] ?? '',
			'author'           => $meta['author'] ?? '',
			'version'          => $meta['version'] ?? '',
			'description'      => self::clean_text( $meta['description'] ?? '' ),
			'url'              => $plugin['url'] ?? '',
			'author_url'       => $plugin['author_url'] ?? '',
			'thumbnail_url'    => $plugin['thumbnail_url'] ?? '',
			'landscape_url'    => $plugin['previews']['landscape_preview']['landscape_url'] ?? '',
			'requires'         => $requires,
			'tested'           => $tested,
			'requires_plugins' => $requires_plugins,
			'number_of_sales'  => $plugin['number_of_sales'] ?? '',
			'updated_at'       => $plugin['updated_at'] ?? '',
			'rating'           => $plugin['rating'] ?? '',
			'versions'         => is_array( $plugin['versions'] ?? null ) ? $plugin['versions'] : array(),
		);

		return $this->fill_preview_urls( $normalized, $plugin );
	}

	/**
	 * Normalize a theme from API response.
	 *
	 * @param array<string, mixed> $theme Raw theme data.
	 * @return array<string, mixed>
	 */
	public function normalize_theme( array $theme ): array {
		$slug = $this->resolve_theme_slug( $theme );
		$meta = $theme['wordpress_theme_metadata'] ?? array();

		$normalized = array(
			'id'            => $theme['id'] ?? 0,
			'slug'          => $slug,
			'name'          => $meta['theme_name'] ?? '',
			'author'        => $meta['author_name'] ?? '',
			'version'       => $meta['version'] ?? '',
			'description'   => self::clean_text( $meta['description'] ?? '' ),
			'url'           => $theme['url'] ?? '',
			'author_url'    => $theme['author_url'] ?? '',
			'thumbnail_url' => $theme['thumbnail_url'] ?? '',
			'rating'        => $theme['rating'] ?? '',
			'landscape_url' => $theme['landscape_url'] ?? '',
			'versions'      => is_array( $theme['versions'] ?? null ) ? $theme['versions'] : array(),
		);

		return $this->fill_preview_urls( $normalized, $theme );
	}

	/**
	 * Extract compatible WordPress versions from attributes.
	 *
	 * @param array<string, mixed> $item Item data.
	 * @return array<int, string>
	 */
	private function extract_compatible_versions( array $item ): array {
		$versions = array();

		foreach ( $item['attributes'] ?? array() as $attr ) {
			if ( ! empty( $attr['name'] ) && 'compatible-software' === $attr['name'] && is_array( $attr['value'] ?? null ) ) {
				foreach ( $attr['value'] as $version ) {
					$versions[] = str_replace( 'WordPress ', '', trim( $version ) );
				}
				break;
			}
		}

		return $versions;
	}

	/**
	 * Resolve theme slug from various sources.
	 *
	 * @param array<string, mixed> $theme Theme data.
	 * @return string
	 */
	private function resolve_theme_slug( array $theme ): string {
		if ( ! empty( $theme['slug'] ) ) {
			return $theme['slug'];
		}

		if ( ! empty( $theme['thumbnail_url'] ) ) {
			$slug = preg_replace( '/\.(png|jpg|jpeg|gif)$/i', '', basename( $theme['thumbnail_url'] ) );
			if ( ! empty( $slug ) ) {
				return $slug;
			}
		}

		$meta = $theme['wordpress_theme_metadata'] ?? array();

		if ( ! empty( $meta['text_domain'] ) ) {
			return $meta['text_domain'];
		}

		if ( ! empty( $meta['theme_name'] ) ) {
			return sanitize_title( $meta['theme_name'] );
		}

		return '';
	}

	/**
	 * Fill missing preview URLs from the previews array.
	 *
	 * @param array<string, mixed> $normalized Normalized data.
	 * @param array<string, mixed> $raw        Raw API data.
	 * @return array<string, mixed>
	 */
	private function fill_preview_urls( array $normalized, array $raw ): array {
		$previews = $raw['previews'] ?? array();

		if ( ! is_array( $previews ) ) {
			return $normalized;
		}

		if ( empty( $normalized['landscape_url'] ) ) {
			foreach ( $previews as $preview ) {
				if ( ! empty( $preview['landscape_url'] ) ) {
					$normalized['landscape_url'] = $preview['landscape_url'];
					break;
				}
			}
		}

		if ( empty( $normalized['thumbnail_url'] ) ) {
			foreach ( $previews as $preview ) {
				if ( ! empty( $preview['icon_url'] ) ) {
					$normalized['thumbnail_url'] = $preview['icon_url'];
					break;
				}
			}
		}

		return $normalized;
	}

	/**
	 * Remove control characters from a string.
	 *
	 * @param string $text Input text.
	 * @return string
	 */
	private static function clean_text( string $text ): string {
		return preg_replace( '/[\x00-\x1F\x7F]/', '', wp_strip_all_tags( $text ) );
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit