$52 GRAYBYTE WORDPRESS FILE MANAGER $34

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/home/bqrcodec/contact.fpt.auto/wp-content/plugins/code-snippets-pro/php/

HOME
Current File : /home/bqrcodec/contact.fpt.auto/wp-content/plugins/code-snippets-pro/php//class-active-snippets.php
<?php

namespace Code_Snippets;

use MatthiasMullie\Minify;

/**
 * Class for loading active snippets of various types.
 *
 * @package Code_Snippets
 */
class Active_Snippets {

	/**
	 * List of content snippets.
	 *
	 * @var array
	 */
	private $content_snippets = [];

	/**
	 * Class constructor.
	 */
	public function __construct() {
		add_action( 'init', array( $this, 'init' ) );
	}

	/**
	 * Initialise class functions.
	 */
	public function init() {
		$db = code_snippets()->db;
		$this->content_snippets = $db->fetch_active_snippets( [ 'head-content', 'footer-content' ] );

		add_action( 'wp_head', [ $this, 'load_head_content' ] );
		add_action( 'wp_footer', [ $this, 'load_footer_content' ] );

		if ( code_snippets()->licensing->was_licensed() ) {
			// respond to a request to print out the active CSS snippets.
			if ( isset( $_GET['code-snippets-css'] ) ) {
				$this->print_code( 'css' );
				exit;
			}

			// respond to a request to print the active JavaScript snippets.
			if ( isset( $_GET['code-snippets-js-snippets'] ) && ! is_admin() ) {
				$this->print_code( 'js' );
				exit;
			}

			add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_js' ), 15 );
			add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_css' ), 15 );
			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_css' ), 15 );
		}
	}

	/**
	 * Increment the asset revision for a specified scope
	 *
	 * @param string $scope   Name of snippet scope.
	 * @param bool   $network Whether to increase for the whole network or the current site.
	 */
	public function increment_rev( $scope, $network ) {
		if ( $network && ! is_multisite() ) {
			return;
		}

		$revisions = Settings\get_self_option( $network, 'code_snippets_assets_rev', array() );

		if ( 'all' === $scope ) {
			foreach ( $revisions as $i => $v ) {
				$revisions[ $i ]++;
			}
		} else {
			if ( ! isset( $revisions[ $scope ] ) ) {
				$revisions[ $scope ] = 0;
			}

			$revisions[ $scope ]++;
		}

		Settings\update_self_option( $network, 'code_snippets_assets_rev', $revisions );
	}

	/**
	 * Retrieve the current asset revision number
	 *
	 * @param string $scope Name of snippet scope.
	 *
	 * @return int Current asset revision number.
	 */
	public function get_rev( $scope ) {
		$rev = 0;

		$revisions = get_option( 'code_snippets_assets_rev' );
		if ( isset( $revisions[ $scope ] ) ) {
			$rev += intval( $revisions[ $scope ] );
		}

		if ( is_multisite() ) {
			$revisions = get_site_option( 'code_snippets_assets_rev' );
			if ( isset( $revisions[ $scope ] ) ) {
				$rev += intval( $revisions[ $scope ] );
			}
		}

		return $rev;
	}

	/**
	 * Retrieve the URL to a generated scope asset.
	 *
	 * @param string $scope      Name of the scope to retrieve the asset for.
	 * @param bool   $latest_rev Whether to ensure that the URL is to the latest revision of the asset.
	 *
	 * @return string URL to asset.
	 */
	public function get_asset_url( $scope, $latest_rev = false ) {
		$base = 'admin-css' === $scope ? self_admin_url( '/' ) : home_url( '/' );

		if ( '-css' === substr( $scope, -4 ) ) {
			$url = add_query_arg( 'code-snippets-css', 1, $base );

		} elseif ( '-js' === substr( $scope, -3 ) ) {
			$key = 'site-head-js' === $scope ? 'head' : 'footer';
			$url = add_query_arg( 'code-snippets-js-snippets', $key, $base );

		} else {
			return '';
		}

		if ( $latest_rev ) {
			$rev = $this->get_rev( $scope );
			$url = $rev ? add_query_arg( 'ver', $rev, $url ) : $url;
		}

		return $url;
	}

	/**
	 * Enqueue the active style snippets for the current page
	 */
	public function enqueue_css() {
		$scope = is_admin() ? 'admin' : 'site';
		$rev = $this->get_rev( "$scope-css" );

		if ( ! $rev ) {
			return;
		}

		$url = $this->get_asset_url( "$scope-css" );
		wp_enqueue_style( "code-snippets-{$scope}-styles", $url, array(), $rev );
	}

	/**
	 * Enqueue the active javascript snippets for the current page
	 */
	public function enqueue_js() {
		$head_rev = $this->get_rev( 'site-head-js' );
		$footer_rev = $this->get_rev( 'site-footer-js' );

		if ( $head_rev ) {
			wp_enqueue_script(
				'code-snippets-site-head',
				$this->get_asset_url( 'site-head-js' ),
				array(),
				$head_rev,
				false
			);
		}

		if ( $footer_rev ) {
			wp_enqueue_script(
				'code-snippets-site-footer',
				$this->get_asset_url( 'site-footer-js' ),
				array(),
				$footer_rev,
				true
			);
		}
	}

	/**
	 * Set the necessary headers to mark this page as an asset
	 *
	 * @param string $mime_type File MIME type used to set Content-Type header.
	 */
	private static function do_asset_headers( $mime_type ) {
		$expiry = 365 * 24 * 60 * 60; // year in seconds.
		header( 'Content-Type: ' . $mime_type, true, 200 );
		header( sprintf( 'Expires: %s GMT', gmdate( 'D, d M Y H:i:s', time() + $expiry ) ) );
	}

	/**
	 * Fetch and print the active snippets for a given type and the current scope.
	 *
	 * @param string $type Must be either 'css' or 'js'.
	 */
	private function print_code( $type ) {
		if ( 'js' !== $type && 'css' !== $type ) {
			return;
		}

		if ( 'css' === $type ) {
			$this->do_asset_headers( 'text/css' );
			$current_scope = is_admin() ? 'admin-css' : 'site-css';
		} else {
			$this->do_asset_headers( 'text/javascript' );
			$current_scope = isset( $_GET['code-snippets-js-snippets'] ) && 'footer' === $_GET['code-snippets-js-snippets'] ? 'footer' : 'head';
			$current_scope = "site-$current_scope-js";
		}

		$active_snippets = code_snippets()->db->fetch_active_snippets( $current_scope, 'code' );

		// Concatenate all fetched code together into a single string.
		$code = '';
		foreach ( $active_snippets as $snippets ) {
			// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
			$code .= implode( "\n\n", array_column( $snippets, 'code' ) );
		}

		// Minify the prepared code if the setting has been set.
		$setting = Settings\get_setting( 'general', 'minify_output' );
		if ( is_array( $setting ) && in_array( $type, $setting, true ) ) {
			$minifier = 'css' === $type ? new Minify\CSS( $code ) : new Minify\JS( $code );
			$code = $minifier->minify();
		}

		// Output the code and exit.
		echo $code;
		exit;
	}

	/**
	 * Print snippet code fetched from the database from a certain scope.
	 *
	 * @param array  $snippets_list List of data fetched.
	 * @param string $scope         Name of scope to print.
	 */
	private function print_content_snippets( $snippets_list, $scope ) {
		foreach ( $snippets_list as $snippets ) {
			foreach ( $snippets as $snippet ) {
				if ( $scope === $snippet['scope'] ) {
					// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
					echo "\n", $snippet['code'], "\n";
				}
			}
		}
	}

	/**
	 * Print head content snippets.
	 */
	public function load_head_content() {
		$this->print_content_snippets( $this->content_snippets, 'head-content' );
	}

	/**
	 * Print footer content snippets.
	 */
	public function load_footer_content() {
		$this->print_content_snippets( $this->content_snippets, 'footer-content' );
	}
}

Current_dir [ WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
admin-menus
--
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
export
--
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
front-end
--
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
settings
--
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
views
--
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-active-snippets.php
6.827 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-admin.php
9.028 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-command.php
15.078 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-contextual-help.php
6.101 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-db.php
7.98 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-licensing.php
2.886 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-list-table.php
37.864 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-plugin.php
8.257 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-rest-api.php
1.416 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-snippet.php
16.934 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-upgrade.php
6.263 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
class-validator.php
6.809 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
editor.php
3.053 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
load.php
1.299 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
snippet-ops.php
16.085 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
strings.php
2.165 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755
uninstall.php
1.921 KB
30 Jan 2024 5.36 PM
bqrcodec / bqrcodec
0755

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF