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

namespace Yoast\WP\Duplicate_Post\UI;

use WP_Post;
use Yoast\WP\Duplicate_Post\Permissions_Helper;
use Yoast\WP\Duplicate_Post\Utils;

/**
 * Duplicate Post class to manage the classic editor UI.
 */
class Classic_Editor {

	/**
	 * Holds the object to create the action link to duplicate.
	 *
	 * @var Link_Builder
	 */
	protected $link_builder;

	/**
	 * Holds the permissions helper.
	 *
	 * @var Permissions_Helper
	 */
	protected $permissions_helper;

	/**
	 * Holds the asset manager.
	 *
	 * @var Asset_Manager
	 */
	protected $asset_manager;

	/**
	 * Initializes the class.
	 *
	 * @param Link_Builder       $link_builder       The link builder.
	 * @param Permissions_Helper $permissions_helper The permissions helper.
	 * @param Asset_Manager      $asset_manager      The asset manager.
	 */
	public function __construct( Link_Builder $link_builder, Permissions_Helper $permissions_helper, Asset_Manager $asset_manager ) {
		$this->link_builder       = $link_builder;
		$this->permissions_helper = $permissions_helper;
		$this->asset_manager      = $asset_manager;
	}

	/**
	 * Adds hooks to integrate with WordPress.
	 *
	 * @return void
	 */
	public function register_hooks() {
		\add_action( 'post_submitbox_misc_actions', [ $this, 'add_check_changes_link' ], 90 );

		if ( (int) Utils::get_option( 'duplicate_post_show_link_in', 'submitbox' ) === 1 ) {
			if ( (int) Utils::get_option( 'duplicate_post_show_link', 'new_draft' ) === 1 ) {
				\add_action( 'post_submitbox_start', [ $this, 'add_new_draft_post_button' ] );
			}

			if ( (int) Utils::get_option( 'duplicate_post_show_link', 'rewrite_republish' ) === 1 ) {
				\add_action( 'post_submitbox_start', [ $this, 'add_rewrite_and_republish_post_button' ] );
			}
		}

		\add_action( 'load-post.php', [ $this, 'hook_translations' ] );
		\add_filter( 'post_updated_messages', [ $this, 'change_scheduled_notice_classic_editor' ] );

		\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_classic_editor_scripts' ] );
		if ( (int) Utils::get_option( 'duplicate_post_show_link_in', 'submitbox' ) === 1 ) {
			if ( (int) Utils::get_option( 'duplicate_post_show_link', 'new_draft' ) === 1
				|| (int) Utils::get_option( 'duplicate_post_show_link', 'rewrite_republish' ) === 1
			) {
				\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_classic_editor_styles' ] );
			}
		}

		// Remove slug editing from Classic Editor.
		\add_action( 'add_meta_boxes', [ $this, 'remove_slug_meta_box' ], 10, 2 );
		\add_filter( 'get_sample_permalink_html', [ $this, 'remove_sample_permalink_slug_editor' ], 10, 5 );
	}

	/**
	 * Hooks the functions to change the translations.
	 *
	 * @return void
	 */
	public function hook_translations() {
			\add_filter( 'gettext', [ $this, 'change_republish_strings_classic_editor' ], 10, 3 );
			\add_filter( 'gettext_with_context', [ $this, 'change_schedule_strings_classic_editor' ], 10, 4 );
	}

	/**
	 * Enqueues the necessary JavaScript code for the Classic editor.
	 *
	 * @return void
	 */
	public function enqueue_classic_editor_scripts() {
		if ( $this->permissions_helper->is_classic_editor() && isset( $_GET['post'] ) ) {
			$id   = \intval( \wp_unslash( $_GET['post'] ) );
			$post = \get_post( $id );

			if ( $post !== null && $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
				$this->asset_manager->enqueue_strings_script();
			}
		}
	}

	/**
	 * Enqueues the necessary styles for the Classic editor.
	 *
	 * @return void
	 */
	public function enqueue_classic_editor_styles() {
		if ( $this->permissions_helper->is_classic_editor()
			&& isset( $_GET['post'] ) ) {
			$id   = \intval( \wp_unslash( $_GET['post'] ) );
			$post = \get_post( $id );

			if ( $post !== null && $this->permissions_helper->should_links_be_displayed( $post ) ) {
				$this->asset_manager->enqueue_styles();
			}
		}
	}

	/**
	 * Adds a button in the post/page edit screen to create a clone
	 *
	 * @param WP_Post|null $post The post object that's being edited.
	 *
	 * @return void
	 */
	public function add_new_draft_post_button( $post = null ) {
		if ( $post === null ) {
			if ( isset( $_GET['post'] ) ) {
				$id   = \intval( \wp_unslash( $_GET['post'] ) );
				$post = \get_post( $id );
			}
		}

		if ( $post instanceof WP_Post && $this->permissions_helper->should_links_be_displayed( $post ) ) {
			?>
			<div id="duplicate-action">
				<a class="submitduplicate duplication"
					href="<?php echo \esc_url( $this->link_builder->build_new_draft_link( $post ) ); ?>"><?php \esc_html_e( 'Copy to a new draft', 'duplicate-post' ); ?>
				</a>
			</div>
			<?php
		}
	}

	/**
	 * Adds a button in the post/page edit screen to create a clone for Rewrite & Republish.
	 *
	 * @param WP_Post|null $post The post object that's being edited.
	 *
	 * @return void
	 */
	public function add_rewrite_and_republish_post_button( $post = null ) {
		if ( $post === null ) {
			if ( isset( $_GET['post'] ) ) {
				$id   = \intval( \wp_unslash( $_GET['post'] ) );
				$post = \get_post( $id );
			}
		}

		if (
			$post instanceof WP_Post
			&& $this->permissions_helper->should_rewrite_and_republish_be_allowed( $post )
			&& $this->permissions_helper->should_links_be_displayed( $post )
		) {
			?>
			<div id="rewrite-republish-action">
				<a class="submitduplicate duplication" href="<?php echo \esc_url( $this->link_builder->build_rewrite_and_republish_link( $post ) ); ?>"><?php \esc_html_e( 'Rewrite & Republish', 'duplicate-post' ); ?>
				</a>
			</div>
			<?php
		}
	}

	/**
	 * Adds a message in the post/page edit screen to create a clone for Rewrite & Republish.
	 *
	 * @param WP_Post|null $post The post object that's being edited.
	 *
	 * @return void
	 */
	public function add_check_changes_link( $post = null ) {
		if ( $post === null ) {
			if ( isset( $_GET['post'] ) ) {
				$id   = \intval( \wp_unslash( $_GET['post'] ) );
				$post = \get_post( $id );
			}
		}

		if ( $post instanceof WP_Post && $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
			?>
				<div id="check-changes-action" class="misc-pub-section">
					<?php \esc_html_e( 'Do you want to compare your changes with the original version before merging? Please save any changes first.', 'duplicate-post' ); ?>
					<br><br>
					<a class='button' href=<?php echo \esc_url( $this->link_builder->build_check_link( $post ) ); ?>>
						<?php \esc_html_e( 'Compare', 'duplicate-post' ); ?>
					</a>
				</div>
				<?php
		}
	}

	/**
	 * Changes the 'Publish' copies in the submitbox to 'Republish' if a post is intended for republishing.
	 *
	 * @param string $translation The translated text.
	 * @param string $text        The text to translate.
	 * @param string $domain      The translation domain.
	 *
	 * @return string The to-be-used copy of the text.
	 */
	public function change_republish_strings_classic_editor( $translation, $text, $domain ) {
		if ( $domain !== 'default' ) {
			return $translation;
		}

		if ( $text === 'Publish'
			&& $this->should_change_rewrite_republish_copy( \get_post() ) ) {
				return \__( 'Republish', 'duplicate-post' );
		}
		elseif ( $text === 'Publish on: %s'
			&& $this->should_change_rewrite_republish_copy( \get_post() ) ) {
			/* translators: %s: Date on which the post is to be republished. */
			return \__( 'Republish on: %s', 'duplicate-post' );
		}

		return $translation;
	}

	/**
	 * Changes the 'Schedule' copy in the submitbox to 'Schedule republish' if a post is intended for republishing.
	 *
	 * @param string $translation The translated text.
	 * @param string $text        The text to translate.
	 * @param string $context     The translation context.
	 * @param string $domain      The translation domain.
	 *
	 * @return string The to-be-used copy of the text.
	 */
	public function change_schedule_strings_classic_editor( $translation, $text, $context, $domain ) {
		if ( $domain !== 'default' || $context !== 'post action/button label' ) {
			return $translation;
		}

		if ( $text === 'Schedule'
			&& $this->should_change_rewrite_republish_copy( \get_post() ) ) {
			return \__( 'Schedule republish', 'duplicate-post' );
		}

		return $translation;
	}

	/**
	 * Changes the post-scheduled notice when a post or page intended for republishing is scheduled.
	 *
	 * @param array<string, array<int, string>> $messages Post updated messaged.
	 *
	 * @return array<string, array<int, string>> The to-be-used messages.
	 */
	public function change_scheduled_notice_classic_editor( $messages ) {
		$post = \get_post();
		if ( ! $this->should_change_rewrite_republish_copy( $post ) ) {
			return $messages;
		}

		$permalink      = \esc_url( \get_permalink( $post->ID ) );
		$title          = \esc_html( $post->post_title );
		$scheduled_date = \get_the_time( \get_option( 'date_format' ), $post );
		$scheduled_time = \get_the_time( \get_option( 'time_format' ), $post );

		if ( $post->post_type === 'post' ) {
			$messages['post'][9] = \sprintf(
				/* translators: 1: The post title with a link to the frontend page, 2: The scheduled date and time. */
				\esc_html__(
					'This rewritten post %1$s is now scheduled to replace the original post. It will be published on %2$s.',
					'duplicate-post',
				),
				'<a href="' . $permalink . '">' . $title . '</a>',
				'<strong>' . $scheduled_date . ' ' . $scheduled_time . '</strong>',
			);
			return $messages;
		}

		if ( $post->post_type === 'page' ) {
			$messages['page'][9] = \sprintf(
				/* translators: 1: The page title with a link to the frontend page, 2: The scheduled date and time. */
				\esc_html__(
					'This rewritten page %1$s is now scheduled to replace the original page. It will be published on %2$s.',
					'duplicate-post',
				),
				'<a href="' . $permalink . '">' . $title . '</a>',
				'<strong>' . $scheduled_date . ' ' . $scheduled_time . '</strong>',
			);
		}

		return $messages;
	}

	/**
	 * Determines if the Rewrite & Republish copies for the post should be used.
	 *
	 * @param WP_Post $post The current post object.
	 *
	 * @return bool True if the Rewrite & Republish copies should be used.
	 */
	public function should_change_rewrite_republish_copy( $post ) {
		global $pagenow;
		if ( ! \in_array( $pagenow, [ 'post.php', 'post-new.php' ], true ) ) {
			return false;
		}

		if ( ! $post instanceof WP_Post ) {
			return false;
		}

		return $this->permissions_helper->is_rewrite_and_republish_copy( $post );
	}

	/**
	 * Removes the slug meta box in the Classic Editor when the post is a Rewrite & Republish copy.
	 *
	 * @param string  $post_type Post type.
	 * @param WP_Post $post      Post object.
	 *
	 * @return void
	 */
	public function remove_slug_meta_box( $post_type, $post ) {
		if ( $post instanceof WP_Post && $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
			\remove_meta_box( 'slugdiv', $post_type, 'normal' );
		}
	}

	/**
	 * Removes the sample permalink slug editor in the Classic Editor when the post is a Rewrite & Republish copy.
	 *
	 * @param string  $html      Sample permalink HTML markup.
	 * @param int     $post_id   Post ID.
	 * @param string  $new_title New sample permalink title.
	 * @param string  $new_slug  New sample permalink slug.
	 * @param WP_Post $post      Post object.
	 *
	 * @return string The filtered HTML of the sample permalink slug editor.
	 */
	public function remove_sample_permalink_slug_editor( $html, $post_id, $new_title, $new_slug, $post ) {
		if ( ! $post instanceof WP_Post ) {
			return $html;
		}

		if ( $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
			return '';
		}

		return $html;
	}
}