HEX
Server: Apache/2.4.29 (Ubuntu)
System: Linux instance-1 5.4.0-1092-gcp #101~18.04.1-Ubuntu SMP Mon Oct 17 18:29:06 UTC 2022 x86_64
User: web202 (5061)
PHP: 8.1.14
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, exec, shell_exec, system, passthru, proc_open, proc_close, popen, parse_ini_file, show_source
Upload Files
File: /data0/www/clients/client33/web202/web/wp-content/plugins/ninjafirewall/lib/class-helpers.php
<?php
/*
 +=====================================================================+
 |    _   _ _        _       _____ _                        _ _        |
 |   | \ | (_)_ __  (_) __ _|  ___(_)_ __ _____      ____ _| | |       |
 |   |  \| | | '_ \ | |/ _` | |_  | | '__/ _ \ \ /\ / / _` | | |       |
 |   | |\  | | | | || | (_| |  _| | | | |  __/\ V  V / (_| | | |       |
 |   |_| \_|_|_| |_|/ |\__,_|_|   |_|_|  \___| \_/\_/ \__,_|_|_|       |
 |                |__/                                                 |
 |  (c) NinTechNet Limited ~ https://nintechnet.com/                   |
 +=====================================================================+
*/

if ( class_exists('NinjaFirewall_helpers') ) {
	return;
}

class NinjaFirewall_helpers {


	/**
	 * Retrieve and return matching files from a directory.
	 * Replacement for the PHP glob() function to make file search compatible with remote files.
	 */
	public static function nfw_glob( $directory, $regex, $pathname = false, $sortname = true ) {

		$list = [];

		foreach ( new DirectoryIterator( $directory ) as $finfo ) {
			if (! $finfo->isDot() && preg_match("`$regex`", $finfo->getFilename() ) ) {
				if ( $pathname ) {
					$list[] = $finfo->getPathname();
				} else {
					$list[] = $finfo->getFilename();
				}
			}
		}
		if ( $sortname === true ) {
			asort( $list );
		}

		return $list;
	}


	/**
	 * Retrieve and return matching files from a directory, recursively.
	 * Replacement for the PHP glob() function to make file search compatible with remote files.
	 */
	public static function nfw_glob_recursive( $directory, $regex, $pathname = false ) {

		$list = [];

		$dir_iterator = new RecursiveDirectoryIterator( $directory );
		$iterator = new RecursiveIteratorIterator( $dir_iterator );

		foreach ( $iterator as $finfo ) {
			if ( preg_match("`$regex`", $finfo->getFilename() ) ) {
				if ( $pathname ) {
					$list[] = $finfo->getPathname();
				} else {
					$list[] = $finfo->getFilename();
				}
			}
		}
		return $list;
	}

}

// ---------------------------------------------------------------------
// EOF