JFIF    $         d d  7    * Z qn )ZP 0   !1 A "#a$2Qr   D8 a Ri [f  \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H  ~ , l s / 9  ć: [=/#f ; ) x { ٛE Q )~     = 𘙲r*2~  a _V = '  ku m F  D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq  1dđ #̩ ͑ 0  ; H ] u 搂 @:~ ו K L  N s h } O I R* 8 :2 ! lD JV o (  3 = M ( z Ȱ+i *N A  r6K n S l ) ! J J Ӂ* %  ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c  P A\IL Nj! J ۱+ O\ ͔ ] ޒ S߼ J ȧ c%A N ol  ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f  h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0  'G=i 2N +0 e 2 ]] 9 VT P  O׮ 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P  < 0 x <     !1AQ "Raq 02Br #S CTb  ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV׸ YT D I 6 2 '8Y2  7'\T P.6 d &˦ @V q i  |8 -O Ε  ] ʔ U=   T L 8= ;6c |  !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U# 6w +  +s &r+n ڐ   { @ 29 gL u " T Ù  M=6  (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 !  OS  r D  5 7 % | ?x> L |  / nD 6?/8 w # [ ) L 7 +6〼T A T g   !  %5  Mm Z /c  -{1_Je "| ^$ 'O  & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@  u6  BԒ  i YN * f 0 _ GhKW u  lT <nj- 0{  M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q  $ H8o Q˼EV ~ k 0 h' L  Pp M -M"  m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @񄞅~p   #   !1QAa q  ? AL0L  x LU 4 d ; x   " 16ad0 7.\ߋ 0  = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X  &Q  З non]я u ג./ ; gZ$ M QР 2M ]h ni 0  P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _  1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3  6 #Ik+ v  {ƒ v i ( ވ  ? a e)  X xy/*@Q Ǽ Ծ ) $ IWO l c G;  !i  k{ gOŀ L ('x  T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ)  X 5 c QɎMy W ?  Q *!R > 6=7)Xj 5`J ] e  8%t ! + ' ! 1Q 5   !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $  v , ,m   㵜5u bV  =sY+ @d { N ! dn O < .- B;  _w J t 6;Q  Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш  e黅X ۢ F :)[ F G X ƹ / w _c MeD   ,ʡc c .  W D  tA $ j@ : ) - # u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P  6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L !  ~ y5 g9T̅J kbM' +s :S +B) v @ M  j e C f j E 0  Y\Qn z G 1 д~ W o{T 9?`  Rm yhsy3 !HAD ] m  c1 ~ 2 L  S u7x T ;j$ `} 4-> L#  vzŏ I L S  ֭  T { r  jGK C ; b  pU= - ` Bs K. S F w4  M q] Z dH S 0 ) tLg Tiny File Manager | Plugin_Request_Utility.php
  • File: Plugin_Request_Utility.php
  • Full Path: /home/mata8712/public_html/on-me-trouve/wp-content/plugins/plugin-check/includes/Utilities/Plugin_Request_Utility.php
  • File size: 8.31 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
/**
 * Class WordPress\Plugin_Check\Utilities
 *
 * @package plugin-check
 */

namespace WordPress\Plugin_Check\Utilities;

use Exception;
use WordPress\Plugin_Check\Checker\Abstract_Check_Runner;
use WordPress\Plugin_Check\Checker\AJAX_Runner;
use WordPress\Plugin_Check\Checker\CLI_Runner;

/**
 * Class providing utility methods to return plugin information based on the request.
 *
 * @since 1.0.0
 */
class Plugin_Request_Utility {

	/**
	 * Instance of the current runner based on the request.
	 *
	 * @since 1.0.0
	 * @var Abstract_Check_Runner|null
	 */
	protected static $runner;

	/**
	 * The universal runtime preparation cleanups if applied.
	 *
	 * @since 1.0.0
	 * @var callable|null
	 */
	protected static $cleanup;

	/**
	 * Returns the plugin basename based on the input provided.
	 *
	 * @since 1.0.0
	 *
	 * @param string $plugin_slug The plugin slug or basename.
	 * @return string The plugin basename.
	 *
	 * @throws Exception Thrown if an invalid basename or plugin slug is provided.
	 */
	public static function get_plugin_basename_from_input( $plugin_slug ) {
		require_once ABSPATH . 'wp-admin/includes/plugin.php';

		if ( empty( $plugin_slug ) ) {
			throw new Exception( 'Invalid plugin slug: Plugin slug must not be empty.' );
		}

		$plugins = get_plugins();

		// Is the provided value is a full plugin basename?
		if ( isset( $plugins[ $plugin_slug ] ) ) {
			return $plugin_slug;
		}

		if ( strpos( $plugin_slug, '/' ) ) {
			throw new Exception(
				sprintf(
					'Invalid plugin basename: Plugin with basename %s is not installed.',
					$plugin_slug
				)
			);
		}

		foreach ( array_keys( $plugins ) as $plugin_basename ) {
			if ( strpos( $plugin_basename, $plugin_slug . '/' ) === 0 ) {
				return $plugin_basename;
			}
		}

		throw new Exception(
			sprintf(
				'Invalid plugin slug: Plugin with slug %s is not installed.',
				$plugin_slug
			)
		);
	}

	/**
	 * Returns the plugin slug based on the input provided.
	 *
	 * @since 1.3.0
	 *
	 * @param string $plugin_url The plugin url.
	 * @return string The plugin slug.
	 */
	public static function get_slug_from_url( $plugin_url ) {
		$plugin_slug = '';

		if ( false !== strpos( $plugin_url, '#wporgapi:' ) ) {
			$plugin_url = substr( $plugin_url, 0, strpos( $plugin_url, '#' ) );
		}
		$plugin_slug = basename( $plugin_url );
		$plugin_slug = str_replace( '.zip', '', $plugin_slug );

		return $plugin_slug;
	}

	/**
	 * Initializes the runner classes.
	 *
	 * @since 1.0.0
	 */
	public static function initialize_runner() {
		$runners = array(
			new CLI_Runner(),
			new AJAX_Runner(),
		);

		foreach ( $runners as $runner ) {
			if ( $runner->is_plugin_check() ) {
				add_action(
					'muplugins_loaded',
					function () use ( $runner ) {
						static::$cleanup = $runner->prepare();
						static::$runner  = $runner;
					}
				);

				break;
			}
		}
	}

	/**
	 * Get the Runner class for the current request.
	 *
	 * @since 1.0.0
	 *
	 * @return Abstract_Check_Runner|null The Runner class for the request or null.
	 */
	public static function get_runner() {
		if ( null !== static::$runner ) {
			return static::$runner;
		}

		return null;
	}

	/**
	 * Runs the cleanup functions and destroys the runner.
	 *
	 * @since 1.0.0
	 */
	public static function destroy_runner() {
		// Run the cleanup functions.
		if ( null !== self::$cleanup ) {
			call_user_func( self::$cleanup );
		}

		static::$runner = null;
	}

	/**
	 * Gets the directories to ignore using the filter.
	 *
	 * @since 1.0.0
	 */
	public static function get_directories_to_ignore() {
		// By default, ignore the '.git', 'vendor', 'vendor_prefixed, 'vendor-prefixed' and 'node_modules' directories.
		$default_ignore_directories = array(
			'.git',
			'vendor',
			'node_modules',
			'vendor_prefixed',
			'vendor-prefixed',
		);

		/**
		 * Filters the directories to ignore.
		 *
		 * @since 1.0.0
		 *
		 * @param array $default_ignore_directories An array of directories to ignore.
		 */
		$directories_to_ignore = (array) apply_filters( 'wp_plugin_check_ignore_directories', $default_ignore_directories );

		return $directories_to_ignore;
	}

	/**
	 * Gets the files to ignore using the filter.
	 *
	 * @since 1.0.2
	 */
	public static function get_files_to_ignore() {
		$default_ignore_files = array();

		/**
		 * Filters the files to ignore.
		 *
		 * @since 1.0.2
		 *
		 * @param array $default_ignore_files An array of files to ignore.
		 */
		$files_to_ignore = (array) apply_filters( 'wp_plugin_check_ignore_files', $default_ignore_files );

		return $files_to_ignore;
	}

	/**
	 * Returns the plugin basename after downloading and installing the plugin.
	 *
	 * @since 1.1.0
	 *
	 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
	 *
	 * @param string $plugin_url The URL of the plugin to download.
	 * @return string The plugin basename after downloading and installing the plugin.
	 *
	 * @throws Exception Thrown if an invalid URL given or zip could be extracted properly.
	 *
	 * @SuppressWarnings(PHPMD.NPathComplexity)
	 */
	public static function download_plugin( $plugin_url ) {
		$args     = array(
			'timeout' => 60,
		);
		$response = wp_safe_remote_get( $plugin_url, $args );

		if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
			throw new Exception(
				__( 'Downloading the zip file failed.', 'plugin-check' )
			);
		}

		// Prevents URL from wporg.
		if ( false !== strpos( $plugin_url, '#wporgapi:' ) ) {
			$plugin_info_url = substr( $plugin_url, strpos( $plugin_url, '#wporgapi:' ) );
			$plugin_info_url = str_replace( '#wporgapi:', '', $plugin_info_url );
			$plugin_url      = substr( $plugin_url, 0, strpos( $plugin_url, '#' ) );
		}

		$basename = basename( $plugin_url );

		require_once ABSPATH . 'wp-admin/includes/file.php';

		WP_Filesystem();

		global $wp_filesystem;

		// Create the name of the file and the declare the directory and path.
		$plugin_check_dir = self::get_upload_dir();

		$response_zip_body = wp_remote_retrieve_body( $response );

		$file_path = $plugin_check_dir . $basename;

		if ( ! $wp_filesystem->put_contents( $plugin_check_dir . $basename, $response_zip_body ) ) {
			throw new Exception(
				__( 'Saving zip file failed.', 'plugin-check' )
			);
		}

		$temp_dir = $plugin_check_dir . strtotime( 'now' ) . '/';

		// Unzip file.
		$unzip_file = unzip_file( $file_path, $temp_dir );

		if ( true !== $unzip_file ) {
			throw new Exception( $unzip_file->get_error_message() );
		}

		// Remove zip file.
		unlink( $file_path );

		if ( ! empty( $plugin_info_url ) && filter_var( $plugin_info_url, FILTER_VALIDATE_URL ) ) {
			$response_json = wp_safe_remote_get( $plugin_info_url );

			if ( is_wp_error( $response_json ) || 200 !== wp_remote_retrieve_response_code( $response_json ) ) {
				throw new Exception(
					__( 'Fetching data failed.', 'plugin-check' )
				);
			}

			$response_body = wp_remote_retrieve_body( $response_json );

			json_decode( $response_body );

			if ( JSON_ERROR_NONE !== json_last_error() ) {
				throw new Exception(
					__( 'Invalid JSON content.', 'plugin-check' )
				);
			}

			if ( ! $wp_filesystem->put_contents( $plugin_check_dir . 'plugin-info.json', $response_body ) ) {
				throw new Exception(
					__( 'Saving JSON file failed.', 'plugin-check' )
				);
			}
		}

		$files              = scandir( $temp_dir );
		$files              = array_diff( $files, array( '.', '..' ) );
		$target_folder_name = ! empty( $files ) && 1 === count( $files ) ? reset( $files ) : '';

		return $temp_dir . $target_folder_name;
	}

	/**
	 * Get the upload directory for the plugin check.
	 *
	 * @since 1.1.0
	 *
	 * @return string The upload directory for the plugin check.
	 */
	public static function get_upload_dir() {
		$upload_dir = trailingslashit( get_temp_dir() ) . 'plugin-check/';

		if ( ! is_dir( $upload_dir ) ) {
			mkdir( $upload_dir, 0755, true );
		}

		return $upload_dir;
	}

	/**
	 * Checks if the directory is a valid plugin.
	 *
	 * @since 1.1.0
	 *
	 * @param string $directory Directory.
	 * @return bool true if the directory is valid plugin, otherwise false.
	 */
	public static function is_directory_valid_plugin( $directory ) {
		$is_valid = false;

		if ( is_dir( $directory ) ) {
			$files = glob( $directory . '/*.php' );

			foreach ( $files as $file ) {
				$plugin_data = get_plugin_data( $file );
				if ( ! empty( $plugin_data['Name'] ) ) {
					$is_valid = true;
					break;
				}
			}
		}

		return $is_valid;
	}
}