HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
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,
Upload Files
File: /var/www/delta/wp-content/plugins/w3-total-cache/Generic_Faq.php
<?php
/**
 * File: Generic_Faq.php
 *
 * @package W3TC
 */

namespace W3TC;

/**
 * Class: Generic_Faq
 */
class Generic_Faq {
	/**
	 * Return FAQ section URLs.
	 *
	 * @return array
	 */
	public static function sections(): array {
		return array(
			'General'            => 'https://api.w3-edge.com/v1/faq/general',
			'Usage'              => 'https://api.w3-edge.com/v1/faq/usage',
			'Compatibility'      => 'https://api.w3-edge.com/v1/faq/compatibility',
			'Minification'       => 'https://api.w3-edge.com/v1/faq/minification',
			'CDN'                => 'https://api.w3-edge.com/v1/faq/cdn',
			'Browser Cache'      => 'https://api.w3-edge.com/v1/faq/browser-cache',
			'Errors / Debugging' => 'https://api.w3-edge.com/v1/faq/errors-debugging',
			'Requirements'       => 'https://api.w3-edge.com/v1/faq/requirements',
			'Developers'         => 'https://api.w3-edge.com/v1/faq/developers',
			'Extensions'         => 'https://api.w3-edge.com/v1/faq/extensions',
			'Installation'       => 'https://api.w3-edge.com/v1/faq/installation',
		);
	}

	/**
	 * Returns list of questions for section.
	 *
	 * @static
	 *
	 * @see self::sections()
	 *
	 * @param string $section Section.
	 * @return array|null
	 */
	public static function parse( string $section ): ?array {
		$sections = self::sections();

		if ( ! isset( $sections[ $section ] ) ) {
			return null;
		}

		$url      = $sections[ $section ];
		$response = wp_remote_get( $url );

		if ( is_wp_error( $response ) ) {
			return null;
		}

		$questions = array();
		$regexes   = array(
			'~<h1[^>]*>(.*?)</h1>.*?<a[^>]*href="(#[^"]+)"~mi',
			'~<li>.*?<a[^>]*href="/BoldGrid/w3-total-cache/wiki/FAQ([^"]+)"[^>]*>(.*?)</a>.*?</li>~mi',
		);

		foreach ( $regexes as $i => $regex ) {
			preg_match_all( $regex, $response['body'], $m );

			if ( is_array( $m ) && count( $m ) > 1 ) {
				$c = count( $m[1] );

				for ( $n = 0; $n < $c; $n++ ) {
					if ( 0 === $i ) {
						// Index 0 has the question first then the URL fragment.
						$questions[] = array(
							'q' => $m[1][ $n ],
							'a' => $url . $m[2][ $n ],
						);
					} else {
						// Index 1 has the URL fragment first then the name.  Just use the original URL.
						$questions[] = array(
							'q' => $m[2][ $n ],
							'a' => $url,
						);
					}
				}
			}
		}

		return $questions;
	}
}