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 | Checklist.php
  • File: Checklist.php
  • Full Path: /home/mata8712/public_html/on-me-trouve/wp-content/plugins/wpforms-lite/src/SetupChecklist/Checklist.php
  • File size: 7.14 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace WPForms\SetupChecklist;

use WPForms\Pro\Admin\PluginList;
use WPForms\SetupWizard\Service\PluginCatalog;
use WPForms\SetupWizard\Service\PluginDetector;

/**
 * Setup Checklist model.
 *
 * Composes the declarative {@see Config} with live {@see CompletionDetector}
 * results into the shape the menu and the page consume: sections enriched with
 * per-item completion, per-section completion, and an overall progress summary.
 * Detection results are memoized for the request so a single page load that asks
 * for both the sections and the progress runs each check only once.
 *
 * @since 2.0.0
 */
class Checklist {

	/**
	 * Data-model source.
	 *
	 * @since 2.0.0
	 *
	 * @var Config
	 */
	private $config;

	/**
	 * Completion detector.
	 *
	 * @since 2.0.0
	 *
	 * @var CompletionDetector
	 */
	private $detector;

	/**
	 * Plugin detector (installed/active status for form plugins).
	 *
	 * @since 2.0.0
	 *
	 * @var PluginDetector
	 */
	private $plugin_detector;

	/**
	 * Plugin catalog (display names for detected form plugins).
	 *
	 * @since 2.0.0
	 *
	 * @var PluginCatalog
	 */
	private $plugin_catalog;

	/**
	 * Memoized enriched sections for the current request.
	 *
	 * @since 2.0.0
	 *
	 * @var array|null
	 */
	private $sections;

	/**
	 * Constructor.
	 *
	 * @since 2.0.0
	 *
	 * @param Config             $config          Data-model source.
	 * @param CompletionDetector $detector        Completion detector.
	 * @param PluginDetector     $plugin_detector Plugin detector.
	 * @param PluginCatalog      $plugin_catalog  Plugin catalog.
	 */
	public function __construct( Config $config, CompletionDetector $detector, PluginDetector $plugin_detector, PluginCatalog $plugin_catalog ) {

		$this->config          = $config;
		$this->detector        = $detector;
		$this->plugin_detector = $plugin_detector;
		$this->plugin_catalog  = $plugin_catalog;
	}

	/**
	 * Sections enriched with completion state.
	 *
	 * @since 2.0.0
	 *
	 * @return array<string, array>
	 */
	public function get_sections(): array {

		if ( $this->sections !== null ) {
			return $this->sections;
		}

		$sections = $this->config->get_sections();

		foreach ( $sections as $section_id => $section ) {
			$completed = 0;
			$items     = $section['items'] ?? [];

			foreach ( $items as $item_id => $item ) {
				$item = $this->resolve_item( $item );

				if ( $item === null ) {
					unset( $items[ $item_id ] );

					continue;
				}

				$items[ $item_id ] = $item;

				$is_complete = $this->detector->is_complete( $item['id'] );

				$items[ $item_id ]['complete'] = $is_complete;

				if ( $is_complete ) {
					++$completed;
				}
			}

			$total = count( $items );

			$complete_on_any = ! empty( $section['complete_on_any'] );

			$sections[ $section_id ]['items']           = $items;
			$sections[ $section_id ]['completed_items'] = $completed;
			$sections[ $section_id ]['total_items']     = $total;
			$sections[ $section_id ]['complete']        = $this->is_section_complete( $completed, $total, $complete_on_any );
		}

		$this->sections = $sections;

		return $this->sections;
	}

	/**
	 * Determine whether a section is complete.
	 *
	 * A section needs at least one item. It is complete when any item is done
	 * for `complete_on_any` sections, or when every item is done otherwise.
	 *
	 * @since 2.0.0
	 *
	 * @param int  $completed       Number of completed items in the section.
	 * @param int  $total           Total number of items in the section.
	 * @param bool $complete_on_any Whether a single completed item marks the section complete.
	 *
	 * @return bool
	 */
	private function is_section_complete( int $completed, int $total, bool $complete_on_any ): bool {

		if ( $total === 0 ) {
			return false;
		}

		return $complete_on_any ? $completed > 0 : $completed === $total;
	}

	/**
	 * Resolve an item before counting: a non-applicable conditional item returns null.
	 *
	 * @since 2.0.0
	 *
	 * @param array $item Conditional item from the config.
	 *
	 * @return array|null The finalised item, or null when it does not apply.
	 */
	private function resolve_item( array $item ): ?array {

		if ( $item['id'] === 'lite_connect' ) {
			return $this->resolve_lite_connect_item( $item );
		}

		if ( $item['id'] !== 'import_forms' ) {
			return $item;
		}

		$detected = array_filter(
			$this->plugin_detector->forms_plugins(),
			static function ( $status ) {

				return ! empty( $status['installed'] );
			}
		);

		if ( empty( $detected ) ) {
			return $this->detector->is_complete( 'import_forms' ) ? $item : null;
		}

		if ( count( $detected ) === 1 ) {
			$item['title'] = sprintf(
				/* translators: %s - the detected form plugin name. */
				__( 'Import From %s', 'wpforms-lite' ),
				$this->plugin_catalog->name( (string) array_keys( $detected )[0] )
			);
		} else {
			$item['title'] = __( 'Import From Other Form Plugins', 'wpforms-lite' );
		}

		return $item;
	}

	/**
	 * Resolve the Lite Connect sub-step.
	 *
	 * @since 2.0.0
	 *
	 * @param array $item Conditional item from the config.
	 *
	 * @return array|null The finalised item, or null when it does not apply.
	 */
	private function resolve_lite_connect_item( array $item ): ?array {

		if ( ! wpforms()->is_pro() ) {
			return $item;
		}

		if ( ! $this->detector->had_lite_connect_enabled() || ! $this->has_valid_license() ) {
			return null;
		}

		$item['title']        = __( 'Restore Entry Backups', 'wpforms-lite' );
		$item['description']  = __( 'Since you enabled Lite Connect in the free version of WPForms, you have entries backed up and ready to be restored.', 'wpforms-lite' );
		$item['cta']['label'] = __( 'Restore Entry Backups', 'wpforms-lite' );
		$item['cta']['url']   = add_query_arg(
			[
				'wpforms_lite_connect_action' => 'import',
				'_wpnonce'                    => wp_create_nonce( 'wpforms_lite_connect_action' ),
			],
			Page::get_url()
		);

		$item['cta']['spinner'] = true;

		if ( $this->detector->is_lite_connect_restore_in_progress() ) {
			$item['cta']['label']    = __( 'Import in Progress', 'wpforms-lite' );
			$item['cta']['disabled'] = true;

			unset( $item['cta']['action'] );
		}

		return $item;
	}

	/**
	 * Whether the site has a valid Pro license.
	 *
	 * @since 2.0.0
	 *
	 * @return bool
	 */
	private function has_valid_license(): bool {

		return ( new PluginList() )->is_valid_license();
	}

	/**
	 * Overall progress summary.
	 *
	 * @since 2.0.0
	 *
	 * @return array{percent:int, completed_sections:int, total_sections:int, completed_items:int, total_items:int}
	 */
	public function get_progress(): array {

		$sections = $this->get_sections();

		$total_sections     = count( $sections );
		$completed_sections = 0;
		$total_items        = 0;
		$completed_items    = 0;

		foreach ( $sections as $section ) {
			$completed_sections += ! empty( $section['complete'] ) ? 1 : 0;
			$total_items        += $section['total_items'] ?? 0;
			$completed_items    += $section['completed_items'] ?? 0;
		}

		$percent = $total_sections > 0 ? (int) round( $completed_sections / $total_sections * 100 ) : 0;

		return [
			'percent'            => $percent,
			'completed_sections' => $completed_sections,
			'total_sections'     => $total_sections,
			'completed_items'    => $completed_items,
			'total_items'        => $total_items,
		];
	}
}