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 | options-form-generator.php
  • File: options-form-generator.php
  • Full Path: /home/mata8712/public_html/on-me-trouve/wp-content/plugins/duplicate-post/src/admin/options-form-generator.php
  • File size: 9.44 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace Yoast\WP\Duplicate_Post\Admin;

use WP_Taxonomy;
use Yoast\WP\Duplicate_Post\Utils;

/**
 * Class Options_Form_Generator.
 */
class Options_Form_Generator {

	/**
	 * The Options_Inputs instance.
	 *
	 * @var Options_Inputs
	 */
	protected $options_inputs;

	/**
	 * Options_Form_Generator constructor.
	 *
	 * @param Options_Inputs $inputs The Options_Inputs instance.
	 */
	public function __construct( Options_Inputs $inputs ) {
		$this->options_inputs = $inputs;
	}

	/**
	 * Generates the HTML output of an input control, based on the passed options.
	 *
	 * @param array  $options       The options to base the input on.
	 * @param string $parent_option The parent option, used for grouped inputs. Optional.
	 *
	 * @return string The HTML output.
	 */
	public function generate_options_input( array $options, $parent_option = '' ) {
		$output = '';

		foreach ( $options as $option => $option_values ) {
			// Skip empty options.
			if ( empty( $option_values ) ) {
				continue;
			}

			// Check for support of the current WordPress version.
			if ( \array_key_exists( 'version', $option_values ) && \version_compare( \get_bloginfo( 'version' ), $option_values['version'] ) < 0 ) {
				continue;
			}

			if ( \array_key_exists( 'sub_options', $option_values ) ) {
				$output .= $this->generate_options_input( $option_values['sub_options'], $option );

				continue;
			}

			// If callback, call it.
			if ( \array_key_exists( 'callback', $option_values ) ) {
				$output .= $this->{$option_values['callback']}();

				continue;
			}

			if ( ! \array_key_exists( 'type', $option_values ) ) {
				continue;
			}

			$id = ( \array_key_exists( 'id', $option_values ) ? $option_values['id'] : $this->prepare_input_id( $option ) );

			if ( $parent_option !== '' ) {
				$id     = \sprintf( '%s-%s', $this->prepare_input_id( $parent_option ), $id );
				$option = \sprintf( '%s[%s]', $parent_option, $option );
			}

			switch ( $option_values['type'] ) {
				case 'checkbox':
					$output .= $this->options_inputs->checkbox(
						$option,
						$option_values['value'],
						$id,
						$this->is_checked( $option, $option_values, $parent_option ),
					);

					$output .= \sprintf( '<label for="%s">%s</label>', $id, \esc_html( $option_values['label'] ) );
					break;
				case 'text':
					$output .= $this->options_inputs->text( $option, $option_values['value'], $id );
					break;
				case 'number':
					$output .= $this->options_inputs->number( $option, $option_values['value'], $id );

					break;
			}

			if ( \array_key_exists( 'description', $option_values ) ) {
				$output .= ' ' . $this->extract_description( $option_values['description'], $id );
			}

			$output .= '<br />';
		}

		return $output;
	}

	/**
	 * Sorts taxonomy objects based on being public, followed by being private
	 * and when the visibility is equal, on the taxonomy public name (case-sensitive).
	 *
	 * @param WP_Taxonomy $taxonomy1 First taxonomy object.
	 * @param WP_Taxonomy $taxonomy2 Second taxonomy object.
	 *
	 * @return int An integer less than, equal to, or greater than zero indicating respectively
	 *             the first taxonomy should be sorted before, at the same level or after the second taxonomy.
	 */
	public function sort_taxonomy_objects( $taxonomy1, $taxonomy2 ) {
		if ( $taxonomy1->public === true && $taxonomy2->public === false ) {
			return -1;
		}
		elseif ( $taxonomy1->public === false && $taxonomy2->public === true ) {
			return 1;
		}

		// Same visibility, sort by name.
		return \strnatcmp( $taxonomy1->labels->name, $taxonomy2->labels->name );
	}

	/**
	 * Extracts and formats the description associated with the input field.
	 *
	 * @param string|array<string> $description The description string. Can be an array of strings.
	 * @param string               $id          The ID of the input field.
	 *
	 * @return string The description HTML for the input.
	 */
	public function extract_description( $description, $id ) {
		if ( ! \is_array( $description ) ) {
			return \sprintf( '<span id="%s-description">(%s)</span>', $id, \esc_html( $description ) );
		}

		return \sprintf( '<p id="%s-description">%s</p>', $id, \implode( '<br />', \array_map( '\esc_html', $description ) ) );
	}

	/**
	 * Generates a list of checkboxes for registered taxonomies.
	 *
	 * @return string The generated taxonomies list.
	 */
	public function generate_taxonomy_exclusion_list() {
		$taxonomies = \get_taxonomies( [], 'objects' );

		\usort( $taxonomies, [ $this, 'sort_taxonomy_objects' ] );

		$taxonomies_blacklist = \get_option( 'duplicate_post_taxonomies_blacklist' );

		if ( ! \is_array( $taxonomies_blacklist ) ) {
			$taxonomies_blacklist = [];
		}

		$output = '';

		foreach ( $taxonomies as $taxonomy ) {
			if ( $taxonomy->name === 'post_format' ) {
				continue;
			}

			$is_public = ( $taxonomy->public ) ? 'public' : 'private';
			$name      = \esc_attr( $taxonomy->name );

			$output .= \sprintf( '<div class="taxonomy_%s">', $is_public );
			$output .= $this->generate_options_input(
				[
					'duplicate_post_taxonomies_blacklist[]' => [
						'type'    => 'checkbox',
						'id'      => 'duplicate-post-' . $this->prepare_input_id( $name ),
						'value'   => $name,
						'checked' => \in_array( $taxonomy->name, $taxonomies_blacklist, true ),
						'label'   => $taxonomy->labels->name . ' [' . $taxonomy->name . ']',
					],
				],
			);
			$output .= '</div>';
		}

		return $output;
	}

	/**
	 * Generates a list of checkboxes for registered roles.
	 *
	 * @return string The generated roles list.
	 */
	public function generate_roles_permission_list() {
		$post_types        = \get_post_types( [ 'show_ui' => true ], 'objects' );
		$edit_capabilities = [ 'edit_posts' => true ];

		foreach ( $post_types as $post_type ) {
			$edit_capabilities[ $post_type->cap->edit_posts ] = true;
		}

		$output = '';

		foreach ( Utils::get_roles() as $name => $display_name ) {
			$role = \get_role( $name );

			if ( \count( \array_intersect_key( $role->capabilities, $edit_capabilities ) ) > 0 ) {
				$output .= $this->generate_options_input(
					[
						'duplicate_post_roles[]' => [
							'type'    => 'checkbox',
							'id'      => 'duplicate-post-' . $this->prepare_input_id( $name ),
							'value'   => $name,
							'checked' => $role->has_cap( 'copy_posts' ),
							'label'   => \translate_user_role( $display_name ),
						],
					],
				);
			}
		}

		return $output;
	}

	/**
	 * Generates a list of checkboxes for registered post types.
	 *
	 * @return string The generated post types list.
	 */
	public function generate_post_types_list() {
		$post_types        = \get_post_types( [ 'show_ui' => true ], 'objects' );
		$hidden_post_types = $this->get_hidden_post_types();
		$output            = '';

		foreach ( $post_types as $post_type_object ) {
			if ( \in_array( $post_type_object->name, $hidden_post_types, true ) ) {
				continue;
			}

			$name = \esc_attr( $post_type_object->name );

			$output .= $this->generate_options_input(
				[
					'duplicate_post_types_enabled[]' => [
						'type'    => 'checkbox',
						'id'      => 'duplicate-post-' . $this->prepare_input_id( $name ),
						'value'   => $name,
						'checked' => $this->is_post_type_enabled( $post_type_object->name ),
						'label'   => $post_type_object->labels->name,
					],
				],
			);
		}

		return $output;
	}

	/**
	 * Determines whether the passed option should result in a checked checkbox or not.
	 *
	 * @param string $option        The option to search for.
	 * @param array  $option_values The option's values.
	 * @param string $parent_option The parent option. Optional.
	 *
	 * @return bool Whether or not the checkbox should be checked.
	 */
	public function is_checked( $option, $option_values, $parent_option = '' ) {
		if ( \array_key_exists( 'checked', $option_values ) ) {
			return $option_values['checked'];
		}

		// Check for serialized options.
		$saved_option = ! empty( $parent_option ) ? \get_option( $parent_option ) : \get_option( $option );

		if ( ! \is_array( $saved_option ) ) {
			return (int) $saved_option === 1;
		}

		// Clean up the sub-option's name.
		$cleaned_option = \trim( \str_replace( $parent_option, '', $option ), '[]' );

		return \array_key_exists( $cleaned_option, $saved_option ) && (int) $saved_option[ $cleaned_option ] === 1;
	}

	/**
	 * Prepares the passed ID so it's properly formatted.
	 *
	 * @param string $id The ID to prepare.
	 *
	 * @return string The prepared input ID.
	 */
	public function prepare_input_id( $id ) {
		return \str_replace( '_', '-', $id );
	}

	/**
	 * Checks whether or not a post type is enabled.
	 *
	 * @codeCoverageIgnore As this is a simple wrapper for a function that is also being used elsewhere, we can skip testing for now.
	 *
	 * @param string $post_type The post type.
	 *
	 * @return bool Whether or not the post type is enabled.
	 */
	public function is_post_type_enabled( $post_type ) {
		$duplicate_post_types_enabled = \get_option( 'duplicate_post_types_enabled', [ 'post', 'page' ] );
		if ( ! \is_array( $duplicate_post_types_enabled ) ) {
			$duplicate_post_types_enabled = [ $duplicate_post_types_enabled ];
		}
		return \in_array( $post_type, $duplicate_post_types_enabled, true );
	}

	/**
	 * Generates a list of post types that should be hidden from the options page.
	 *
	 * @return array The array of names of the post types to hide.
	 */
	public function get_hidden_post_types() {
		$hidden_post_types = [
			'attachment',
			'wp_block',
		];

		if ( Utils::is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
			$hidden_post_types[] = 'product';
		}

		return $hidden_post_types;
	}
}