�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`� 0x0x
PHP 8.1.34
Preview: RuleProvider.php Size: 18.52 KB
/home2/astrociv/www/avadhutholidays.in/wp-content/plugins/imunify-security/inc/App/Defender/RuleProvider.php
<?php
/**
 * Copyright (с) Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2025 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * https://www.cloudlinux.com/legal/
 */

namespace CloudLinux\Imunify\App\Defender;

use CloudLinux\Imunify\App\DataStore;
use CloudLinux\Imunify\App\Debug;
use CloudLinux\Imunify\App\Defender\Model\Rule;
use CloudLinux\Imunify\App\Defender\Model\RuleCollection;
use CloudLinux\Imunify\App\Defender\Model\Target;
use CloudLinux\Imunify\App\Defender\Model\TargetInfo;
use CloudLinux\Imunify\Composer\Semver\Semver;

/**
 * Rule provider class.
 *
 * Handles loading and providing rules for the Defender system.
 *
 * @since 2.1.0
 */
class RuleProvider extends CachedFileProvider {

	/**
	 * Rules file name.
	 */
	const RULES_FILE_NAME = 'rules.php';

	/**
	 * Transient name for caching rules.
	 */
	const RULES_TRANSIENT = 'imunify_security_rules';

	/**
	 * Debug instance.
	 *
	 * @var Debug
	 * @phpstan-ignore-next-line
	 */
	private $debug;

	/**
	 * List of plugins (local cache).
	 *
	 * @var array|null
	 */
	private $plugins;

	/**
	 * Cached rules (local cache for the duration of the request).
	 *
	 * @var RuleCollection|null
	 */
	private $rules = null;

	/**
	 * Ruleset version.
	 *
	 * @var string
	 */
	private $rulesetVersion = '';

	/**
	 * Constructor.
	 *
	 * @param Debug     $debug Debug instance.
	 * @param DataStore $dataStore Data store instance.
	 */
	public function __construct( $debug, $dataStore ) {
		$this->debug     = $debug;
		$this->dataStore = $dataStore;

		// Force reload rules when any plugin is activated or deactivated.
		add_action( 'activated_plugin', array( $this, 'onPluginActivation' ), 10, 2 );
		add_action( 'deactivated_plugin', array( $this, 'onPluginDeactivation' ), 10, 2 );

		// Force reload rules when theme is switched.
		add_action( 'switch_theme', array( $this, 'onThemeSwitch' ), 10, 3 );

		// Force reload rules when WordPress, plugins, or themes are updated.
		add_action( 'upgrader_process_complete', array( $this, 'onUpgraderProcessComplete' ), 10, 2 );
	}

	/**
	 * Get the filename for this provider.
	 *
	 * @since 3.0.0
	 *
	 * @return string The filename.
	 */
	protected function getFileName() {
		return self::RULES_FILE_NAME;
	}

	/**
	 * Force reload rules when any plugin is activated.
	 *
	 * @param string $plugin The plugin slug.
	 * @param bool   $network_wide Whether the plugin was activated network-wide.
	 * @return void
	 */
	public function onPluginActivation( $plugin, $network_wide ) {
		$this->forceRulesReload();
	}

	/**
	 * Force reload rules when any plugin is deactivated.
	 *
	 * @param string $plugin The plugin slug.
	 * @param bool   $network_deactivating_wide Whether the plugin was deactivated network-wide.
	 *
	 * @return void
	 */
	public function onPluginDeactivation( $plugin, $network_deactivating_wide ) {
		$this->forceRulesReload();
	}

	/**
	 * Force reload rules when theme is switched.
	 *
	 * @param string    $new_name The new theme name.
	 * @param \WP_Theme $new_theme The new theme object.
	 * @param \WP_Theme $old_theme The old theme object.
	 *
	 * @return void
	 */
	public function onThemeSwitch( $new_name, $new_theme, $old_theme ) {
		$this->forceRulesReload();
	}

	/**
	 * Drop the cached rules when WordPress, a plugin, or a theme is updated or installed.
	 *
	 * Other entity types and actions are ignored.
	 *
	 * @param \WP_Upgrader $upgrader   Upgrader instance.
	 * @param array        $hook_extra Extra arguments passed to hooked filters.
	 *
	 * @return void
	 */
	public function onUpgraderProcessComplete( $upgrader, $hook_extra ) {
		if ( ! isset( $hook_extra['type'] ) || ! in_array( $hook_extra['type'], array( 'core', 'plugin', 'theme' ), true ) ) {
			return;
		}

		// An install can overwrite an active plugin or theme just as an update does.
		if ( ! isset( $hook_extra['action'] ) || ! in_array( $hook_extra['action'], array( 'update', 'install' ), true ) ) {
			return;
		}

		// This runs in the process that still holds the old plugin, so a rebuild
		// here would key the new files' rules on the old version.
		$this->clearRulesCache();
	}

	/**
	 * Drop the cached rules without rebuilding them.
	 *
	 * @since 4.1.3
	 *
	 * @return void
	 */
	public function clearRulesCache() {
		$this->plugins = null;
		$this->rules   = null;

		if ( ! $this->dataStore->isDataFileAvailable( self::RULES_FILE_NAME ) ) {
			return;
		}

		$fileStats = stat( $this->getRulesFilePath() );
		if ( is_array( $fileStats ) ) {
			delete_transient( $this->buildTransientName( $fileStats ) );
		}
	}

	/**
	 * Load rules from transient cache or rules file.
	 *
	 * @param bool $ignoreCache Whether to ignore cache and force reload from file.
	 *
	 * @return RuleCollection Collection of rules or empty collection if no rules are available.
	 */
	public function loadRules( $ignoreCache = false ) {

		// Return cached rules if already loaded during this request.
		if ( null !== $this->rules && ! $ignoreCache ) {
			return $this->rules;
		}

		if ( $this->dataStore->isDataFileAvailable( self::RULES_FILE_NAME ) ) {

			// Use atomic stat call to avoid race conditions between mtime and size checks.
			$rulesFilePath = $this->getRulesFilePath();
			$fileStats     = stat( $rulesFilePath );

			if ( is_array( $fileStats ) ) {
				// Create unique transient name using both modification time and file size.
				$transientName = $this->buildTransientName( $fileStats );

				// Try to load from transient first (unless cache should be ignored).
				if ( ! $ignoreCache ) {
					$cachedData = get_transient( $transientName );

					if ( is_array( $cachedData ) && isset( $cachedData['rules'] ) ) {
						// Return cached rules if available.
						$this->rulesetVersion = isset( $cachedData['version'] ) ? $cachedData['version'] : '';
						$result               = RuleCollection::fromArray( $cachedData['rules'] );
						$this->rules          = $result;
						return $result;
					}
				}

				// If no cached rules or cache should be ignored, load from file and cache them.
				// WordPress transients provide built-in stampede protection.
				$rulesData = $this->loadRulesFromFile();
				$rules     = isset( $rulesData['rules'] ) ? $rulesData['rules'] : array();
				$result    = $this->getRelevantRules( $rules );

				// Cache the rules and version for 6 hours if we have valid rules.
				$cacheData = array(
					'version' => $this->rulesetVersion,
					'rules'   => $result->toArray(),
				);
				set_transient( $transientName, $cacheData, self::TRANSIENT_LIFETIME );
				$this->rules = $result;
				return $result;
			}
		}

		$result      = RuleCollection::withNoRules();
		$this->rules = $result;
		return $result;
	}

	/**
	 * Load rules from the rules file.
	 *
	 * @return array Array with 'version' and 'rules' keys, or empty array if file doesn't exist or is invalid.
	 */
	public function loadRulesFromFile() {
		$data = $this->loadDataFromFile();

		if ( ! $data || ! is_array( $data ) ) {
			$this->rulesetVersion = '';
			return array(
				'version' => '',
				'rules'   => array(),
			);
		}

		// Extract version and rules from the new structure.
		$this->rulesetVersion = isset( $data['version'] ) ? $data['version'] : '';
		$rules                = isset( $data['rules'] ) && is_array( $data['rules'] ) ? $data['rules'] : array();

		return array(
			'version' => $this->rulesetVersion,
			'rules'   => $rules,
		);
	}

	/**
	 * Get the rules file path.
	 *
	 * @return string The rules file path.
	 */
	public function getRulesFilePath() {
		return $this->getFilePath();
	}

	/**
	 * Build transient name from file statistics.
	 *
	 * @param array $fileStats File statistics from stat() call.
	 *
	 * @return string Transient name.
	 */
	public function buildTransientName( $fileStats ) {
		// The cached value is filtered by plugin version, so the key has to carry it.
		return self::RULES_TRANSIENT . '_' . $this->getPluginVersion() . '_' . $fileStats['mtime'] . '_' . $fileStats['size'];
	}

	/**
	 * Get the plugin version used to key the rules cache.
	 *
	 * @since 4.1.3
	 *
	 * @return string Plugin version.
	 */
	protected function getPluginVersion() {
		return defined( 'IMUNIFY_SECURITY_VERSION' ) ? IMUNIFY_SECURITY_VERSION : 'dev';
	}

	/**
	 * Force reload rules from file and update cache.
	 *
	 * @return RuleCollection Collection of rules.
	 */
	public function forceRulesReload() {
		$this->plugins = null;
		$this->rules   = null;
		return $this->loadRules( true );
	}

	/**
	 * Force reload data from file.
	 *
	 * Implementation of abstract method from CachedFileProvider.
	 *
	 * @since 3.0.0
	 *
	 * @return RuleCollection Collection of rules.
	 */
	public function forceReload() {
		return $this->forceRulesReload();
	}

	/**
	 * Check if the rule has all required fields.
	 *
	 * @param Rule $rule Rule object.
	 *
	 * @return bool True if the rule is valid, false otherwise.
	 */
	public function isRuleValid( $rule ) {
		// Check required fields: target, versions.
		if ( empty( $rule->getTarget() ) || empty( $rule->getVersions() ) ) {
			return false;
		}

		// Check if target is valid.
		if ( ! Target::isValid( $rule->getTarget() ) ) {
			return false;
		}

		// Check slug requirement (not required for core target).
		if ( Target::requiresSlug( $rule->getTarget() ) && empty( $rule->getSlug() ) ) {
			return false;
		}

		// Check that rule has either action or ajax_action.
		if ( ! $rule->getAction() && ! $rule->getAjaxAction() ) {
			return false;
		}

		return true;
	}

	/**
	 * Get target information if the rule's target is present on the site.
	 *
	 * @param Rule $rule Rule object.
	 *
	 * @return TargetInfo|null Target information if target is present and meets version requirements, null otherwise.
	 */
	public function getTargetInfo( $rule ) {
		if ( empty( $rule->getVersions() ) ) {
			return null;
		}

		// Load plugins if not already loaded.
		if ( null === $this->plugins ) {
			$this->plugins = $this->loadPlugins();
		}

		if ( Target::PLUGIN === $rule->getTarget() && ! empty( $rule->getSlug() ) ) {
			// Check if plugin exists and is active.
			$pluginData = $this->getPluginData( $rule->getSlug() );
			if ( ! $pluginData ) {
				return null;
			}

			// Check if plugin is active.
			$pluginFile = $this->getPluginFile( $rule->getSlug() );
			if ( ! $pluginFile || ! is_plugin_active( $pluginFile ) ) {
				return null;
			}

			// Check if plugin version meets requirements.
			$pluginVersion = isset( $pluginData['Version'] ) ? $pluginData['Version'] : null;
			if ( ! $pluginVersion ) {
				return null;
			}

			// Check if the plugin version satisfies the constraint.
			if ( $this->versionSatisfiesConstraint( $pluginVersion, $rule->getVersions() ) ) {
				return new TargetInfo( $rule->getTarget(), $rule->getSlug(), $pluginVersion );
			}
		}

		if ( Target::THEME === $rule->getTarget() && ! empty( $rule->getSlug() ) ) {
			// Check if the rule target the current theme.
			$theme = wp_get_theme();
			if ( $theme->get_template() !== $rule->getSlug() ) {
				return null;
			}

			// Check if theme version meets requirements.
			$themeVersion = $theme->get( 'Version' );
			if ( $this->versionSatisfiesConstraint( $themeVersion, $rule->getVersions() ) ) {
				return new TargetInfo( $rule->getTarget(), $rule->getSlug(), $themeVersion );
			}
		}

		if ( Target::CORE === $rule->getTarget() ) {
			// Check if WordPress core version meets requirements.
			global $wp_version;
			if ( $this->versionSatisfiesConstraint( $wp_version, $rule->getVersions() ) ) {
				return new TargetInfo( $rule->getTarget(), '', $wp_version );
			}
		}

		return null;
	}

	/**
	 * Load plugins.
	 *
	 * @return array
	 */
	private function loadPlugins() {
		// Only active plugins can match a rule target, so read just those instead
		// of scanning and header-parsing every installed plugin with get_plugins().
		if ( ! function_exists( 'get_plugin_data' ) ) {
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
		}

		// Per-site active plugins are the option values; network-activated
		// (multisite) plugins are the keys of the active_sitewide_plugins site
		// option. Must-use plugins are intentionally excluded: get_plugins() never
		// returned them and is_plugin_active() rejects them, so including them
		// would change which rules match.
		$active   = (array) get_option( 'active_plugins', array() );
		$sitewide = array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) );

		$plugins = array();
		foreach ( array_unique( array_merge( $active, $sitewide ) ) as $pluginFile ) {
			if ( ! is_string( $pluginFile ) || '' === $pluginFile ) {
				continue;
			}
			$path = WP_PLUGIN_DIR . '/' . $pluginFile;
			if ( is_readable( $path ) ) {
				// $markup = false, $translate = false skips the header markup/i18n
				// pass; only the raw Version string is needed.
				$plugins[ $pluginFile ] = get_plugin_data( $path, false, false );
			}
		}

		return $plugins;
	}

	/**
	 * Get plugin data by slug.
	 *
	 * @param string $pluginSlug Plugin slug.
	 *
	 * @return array|null Plugin data or null if not found.
	 */
	private function getPluginData( $pluginSlug ) {
		$pluginFile = $this->getPluginFile( $pluginSlug );

		return null === $pluginFile ? null : $this->plugins[ $pluginFile ];
	}

	/**
	 * Get plugin file path for is_plugin_active.
	 *
	 * @param string $pluginSlug Plugin slug.
	 *
	 * @return string|null Plugin file path or null if not found.
	 */
	private function getPluginFile( $pluginSlug ) {
		foreach ( $this->plugins as $pluginFile => $pluginData ) {
			if ( 0 === strcasecmp( $this->getPluginSlugFromFile( $pluginFile ), $pluginSlug ) ) {
				return $pluginFile;
			}
		}

		return null;
	}

	/**
	 * Derive the plugin slug from a plugin file path.
	 *
	 * WordPress plugin files are either "slug/main-file.php" for directory-based
	 * plugins or "main-file.php" for single-file plugins. For directory-based
	 * plugins the slug is the directory segment before the first slash. For
	 * single-file plugins the slug is the file name without the ".php" extension.
	 *
	 * Matching on the exact segment (instead of a loose substring test) avoids
	 * matching an unintended plugin, e.g. slug "woo" matching "woocommerce" or a
	 * slug that is a substring of another plugin's folder.
	 *
	 * @param string $pluginFile Plugin file path relative to the plugins directory.
	 *
	 * @return string Plugin slug.
	 */
	private function getPluginSlugFromFile( $pluginFile ) {
		$slashPos = strpos( $pluginFile, '/' );
		if ( false !== $slashPos ) {
			return substr( $pluginFile, 0, $slashPos );
		}

		return preg_replace( '/\.php$/i', '', $pluginFile );
	}

	/**
	 * Sanitize a version string before parsing.
	 *
	 * Handles common real-world quirks found in WordPress plugin/theme headers:
	 * - URL-encoded characters (%0d, %c4%97, etc.)
	 * - Control characters and non-ASCII bytes
	 * - Build metadata (+v3api)
	 * - Spaces in version strings (1.0.0 Alpha)
	 * - Commas used as separators (1,6,8)
	 * - Consecutive dots (3..1.27)
	 * - Underscores as separators (4.2.4_2)
	 * - Hyphen + bare number suffix (1.0.5-1 → 1.0.5.1)
	 * - Hyphen + arbitrary text suffix (1.16.5-issue-598 → 1.16.5)
	 * - Text-only segments (.unstable, .Test)
	 * - Letters mixed into numeric segments (1dev2, 3bk, 1.6c)
	 * - 6+ numeric segments (truncated to 5)
	 *
	 * @param string $version Raw version string.
	 *
	 * @return string Sanitized version string.
	 */
	private static function sanitizeVersion( $version ) {
		// Decode percent-encoded characters. E.g. "2.0.10.8%0d" → "2.0.10.8\r".
		$version = rawurldecode( $version );

		// Strip control characters and non-ASCII bytes. E.g. "2.0.10.8\r" → "2.0.10.8".
		$version = preg_replace( '/[^\x20-\x7E]/', '', $version );
		$version = trim( $version );

		// Strip semver build metadata. E.g. "3.0.13+v3api" → "3.0.13".
		$version = preg_replace( '/\+.*$/', '', $version );

		// Strip everything from the first space onward. E.g. "1.0.0 Alpha" → "1.0.0".
		$version = preg_replace( '/\s.*$/', '', $version );

		// Replace commas with dots. E.g. "1,6,8" → "1.6.8".
		$version = str_replace( ',', '.', $version );

		// Collapse consecutive dots. E.g. "3..1.27" → "3.1.27".
		$version = preg_replace( '/\.{2,}/', '.', $version );

		// Replace underscores with dots. E.g. "4.2.4_2" → "4.2.4.2".
		$version = str_replace( '_', '.', $version );

		// Handle hyphenated suffixes on numeric base versions.
		if ( preg_match( '/^(v?\d+(?:\.\d+)*)-(.+)$/', $version, $m ) ) {
			$base   = $m[1];
			$suffix = $m[2];

			// Keep known stability suffixes for the library. E.g. "1.0.0-beta1", "3.1.0-dev1".
			if ( ! preg_match( '/^(stable|beta|b|rc|alpha|a|patch|pl|p|dev)(\d|[.-]|$)/i', $suffix ) ) {
				if ( preg_match( '/^(\d+)/', $suffix, $numMatch ) ) {
					// Leading digit becomes a dot-segment. E.g. "1.0.5-1" → "1.0.5.1", "9.3.1-2nd" → "9.3.1.2".
					$version = $base . '.' . $numMatch[1];
				} else {
					// Arbitrary text suffix stripped. E.g. "1.16.5-issue-598" → "1.16.5".
					$version = $base;
				}
			}
		}

		// Strip trailing text-only segments. E.g. "1.0.20.2.unstable" → "1.0.20.2".
		$version = preg_replace( '/(\.[a-zA-Z]\w*)+$/', '', $version );

		// Strip letters mixed into numeric segments. E.g. "1.0.8.1dev2" → "1.0.8.1", "1.6c" → "1.6".
		$version = preg_replace( '/(?<=\d)[a-zA-Z]+\w*(?=\.|$)/', '', $version );

		// Truncate 6+ numeric segments to 5. E.g. "2.1.4.6.2.1" → "2.1.4.6.2".
		$version = preg_replace( '/^(v?\d+(?:\.\d+){4})\.\d+/', '$1', $version );

		// Clean up any trailing dots left by prior rules.
		$version = rtrim( $version, '.' );

		return $version;
	}

	/**
	 * Check if version satisfies constraint.
	 *
	 * @param string $currentVersion Current version of the plugin or theme.
	 * @param string $constraint     Version constraint (e.g., ">=1.0.0 <2.0.0").
	 *
	 * @return bool
	 */
	private function versionSatisfiesConstraint( $currentVersion, $constraint ) {
		try {
			$currentVersion = self::sanitizeVersion( $currentVersion );

			return Semver::satisfies( $currentVersion, $constraint );
		} catch ( \UnexpectedValueException $e ) {
			return false;
		}
	}

	/**
	 * Filter and return only relevant rules.
	 *
	 * Rule is relevant if it is valid and its target is present on the site.
	 *
	 * @param array $rules Array of rules.
	 *
	 * @return RuleCollection Collection of relevant rules.
	 */
	private function getRelevantRules( $rules ) {
		// Validate and filter rules.
		$result = new RuleCollection();
		if ( ! empty( $rules ) ) {
			foreach ( $rules as $id => $ruleData ) {
				$rule = Rule::fromArray( $id, $ruleData );
				if ( $this->isRuleValid( $rule ) && $this->getTargetInfo( $rule ) ) {
					$result->addRule( $rule );
				}
			}
		}
		return $result;
	}

	/**
	 * Get the ruleset version.
	 *
	 * @return string Ruleset version.
	 */
	public function getRulesetVersion() {
		return $this->rulesetVersion;
	}
}

Directory Contents

Dirs: 2 × Files: 16
Name Size Perms Modified Actions
Handler DIR
- drwxr-xr-x 2026-11-03 01:06:32
Edit Download
Model DIR
- drwxr-xr-x 2026-11-03 01:06:32
Edit Download
1.97 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
3.44 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
22.33 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
22.10 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
4.28 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
945 B lrw-r--r-- 2026-11-03 01:06:32
Edit Download
6.88 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
17.87 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
3.08 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
62.62 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
4.92 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
18.52 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
4.44 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
14.27 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
9.23 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
28.98 KB lrw-r--r-- 2026-11-03 01:06:32
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI