HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: //proc/self/cwd/wp-content/plugins/wpml-string-translation/classes/utilities/wpml-st-scan-dir.php
<?php

class WPML_ST_Scan_Dir {
	const PLACEHOLDERS_ROOT = '<root>';

	/**
	 * @param string $folder
	 * @param array $extensions
	 * @param bool $single_file
	 * @param array $ignore_folders
	 *
	 * @return array
	 */
	public function scan( $folder, array $extensions = array(), $single_file = false, $ignore_folders = array() ) {

		$files = array();
		$scanned_files = array();

		if ( is_dir( $folder ) ) {
			$scanned_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $folder ) );
		} elseif ( $single_file ) {
			$scanned_files = array( new SplFileInfo( $folder ) );
		}

		foreach ( $scanned_files as $file ) {
			$ignore_file = false;

			if ( in_array( $file->getExtension(), $extensions, true ) ) {

				foreach( $ignore_folders as $ignore_folder ) {
					if ( false !== strpos( $file->getPathname(), str_replace( self::PLACEHOLDERS_ROOT, $folder, $ignore_folder ) ) ) {
						$ignore_file = true;
					}
				}

				if ( $ignore_file ) {
					continue;
				}

				$files[] = $file->getPathname();
			}
		}

		return $files;
	}
}