<commit_before><?php
/**
 * Adtechmedia_Request
 *
 * @category File
 * @package  Adtechmedia_Plugin
 * @author   yamagleb
 */

/**
 * Class Adtechmedia_ServerOptions
 */
class Adtechmedia_ServerOptions {

	/**
	 * Set server options
	 */
	static public function set_options() {
		if ( self::is_apache() ) {
			self::set_apache_config();
		} elseif ( self::is_nginx() ) {
			self::set_nginx_config();
		}
	}

	/**
	 * Delete server options
	 */
	static public function delete_options() {
		if ( self::is_apache() ) {
			self::delete_apache_config();
		} elseif ( self::is_nginx() ) {
			self::delete_nginx_config();
		}
	}

	/**
	 * Returns true if server is Apache
	 *
	 * @return boolean
	 */
	static public function is_apache() {
		// assume apache when unknown, since most common
		if ( empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
			return true;
		}

		return isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false;
	}

	/**
	 * Returns true if server is nginx
	 *
	 * @return boolean
	 */
	static public function is_nginx() {
		return isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false;
	}

	/**
	 * Set config for Apache
	 */
	static public function set_apache_config() {
		$path     = explode( 'wp-content', dirname( __FILE__ ) )[0] . '/.htaccess';
		$handle   = @fopen( $path, "r" );
		$content  = '';
		$inserted = false;
		if ( $handle ) {
			while ( ( $buffer = fgets( $handle, 4096 ) ) !== false ) {

				if ( ! $inserted && stristr( $buffer, 'RewriteRule' ) ) {
					$content .= 'RewriteRule ^sw\.min\.js$ /wp-content/plugins/adtechmedia/js/sw.min.js [L]' . PHP_EOL;
					$inserted = true;
				}
				$content .= $buffer;
			}
			@fclose( $handle );
		}
		file_put_contents( $path, $content );
	}

	/**
	 * Delete config for Apache
	 */
	static public function delete_apache_config() {
		$path     = explode( 'wp-content', dirname( __FILE__ ) )[0] . '/.htaccess';
		$handle   = @fopen( $path, "r" );
		$content  = '';
		if ( $handle ) {
			while ( ( $buffer = fgets( $handle, 4096 ) ) !== false ) {

				if ( !stristr( $buffer, 'RewriteRule ^sw\.min\.js$ /wp-content/plugins/adtechmedia/js/sw.min.js [L]' ) ) {<commit_msg>fix set apache config<commit_after><?php
/**
 * Adtechmedia_Request
 *
 * @category File
 * @package  Adtechmedia_Plugin
 * @author   yamagleb
 */

/**
 * Class Adtechmedia_ServerOptions
 */
class Adtechmedia_ServerOptions {

	/**
	 * Set server options
	 */
	static public function set_options() {
		if ( self::is_apache() ) {
			self::set_apache_config();
		} elseif ( self::is_nginx() ) {
			self::set_nginx_config();
		}
	}

	/**
	 * Delete server options
	 */
	static public function delete_options() {
		if ( self::is_apache() ) {
			self::delete_apache_config();
		} elseif ( self::is_nginx() ) {
			self::delete_nginx_config();
		}
	}

	/**
	 * Returns true if server is Apache
	 *
	 * @return boolean
	 */
	static public function is_apache() {
		// assume apache when unknown, since most common
		if ( empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
			return true;
		}

		return isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false;
	}

	/**
	 * Returns true if server is nginx
	 *
	 * @return boolean
	 */
	static public function is_nginx() {
		return isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false;
	}

	/**
	 * Set config for Apache
	 */
	static public function set_apache_config() {
		$path     = explode( 'wp-content', dirname( __FILE__ ) )[0] . '/.htaccess';
		$handle   = @fopen( $path, "r" );
		$content  = '';
		$inserted = false;
		if ( $handle ) {
			while ( ( $buffer = fgets( $handle, 4096 ) ) !== false ) {

				if ( ! $inserted && stristr( $buffer, 'RewriteRule' ) ) {
					$content .= 'RewriteRule ^sw\.min\.js$ /wp-content/plugins/adtechmedia/js/sw.min.js [L]' . PHP_EOL;
					$inserted = true;
				}
				$content .= $buffer;
			}
			fclose( $handle );

			file_put_contents( $path, $content );
		}
	}

	/**
	 * Delete config for Apache
	 */
	static public function delete_apache_config() {
		$path     = explode( 'wp-content', dirname( __FILE__ ) )[0] . '/.htaccess';
		$handle   = @fopen( $path, "r" );
		$content  = '';
		if ( $handle ) {
			while ( ( $buffer = fgets( $handle, 4096 ) ) !== false ) {

				if ( !stristr( $buffer, 'RewriteRule ^sw\.min\.js$ /wp-content/plugins/adtechmedia/js/sw.min.js [L]' ) ) {
{'fraction_non_alphanumeric': 0.17575757575757575, 'fraction_numerical': 0.004489337822671156, 'mean_word_length': 3.1335807050092765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5196108', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1558, 'n_words': 349}