GIF89a=( õ' 7IAXKgNgYvYx\%wh…hŽth%ˆs%—x¨}9®Œ©€&©‰%¶†(¹–.¹5·œD¹&Çš)ÇŸ5ǘ;Í£*È¡&Õ²)ׯ7×µ<Ñ»4ï°3ø‘HÖ§KͯT÷¨Yÿšqÿ»qÿÔFØ !ù ' !ÿ NETSCAPE2.0 , =( þÀ“pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§gª«ªE¯°¨¬ª±²Œ¹º¹E¾­”´ÂB¶¯ §Åȸ»ÑD¾¿Á•ÄÅ®° ÝH¾ÒLÀÆDÙ«D¶BÝïðÀ¾DÑÑÔTÌÍíH òGö¨A RÎڐ |¥ ٭&ºìE8œ¹kGÔAÞpx­a¶­ã R2XB®åE8I€Õ6Xî:vT)äžþÀq¦è³¥ì仕F~%xñ  4#ZÔ‰O|-4Bs‘X:= QÉ œš lºÒyXJŠGȦ|s hÏíK–3l7·B|¥$'7Jީܪ‰‡àá”Dæn=Pƒ ¤Òëí‰`䌨ljóá¯Éüv>á–Á¼5 ½.69ûϸd«­ºÀûnlv©‹ªîf{¬ÜãPbŸ  l5‘ޝpß ´ ˜3aÅùäI«O’ý·‘áÞ‡˜¾Æ‚ÙÏiÇÿ‹Àƒ #öó)pâš Þ½ ‘Ý{ó)vmÞü%D~ 6f s}ŃƒDØW Eþ`‡þ À…L8xá†ç˜{)x`X/> Ì}mø‚–RØ‘*|`D=‚Ø_ ^ð5 !_…'aä“OÚ—7âcð`D”Cx`ÝÂ¥ä‹éY¹—F¼¤¥Š?¡Õ™ n@`} lď’ÄÉ@4>ñd œ à‘vÒxNÃ×™@žd=ˆgsžG±æ ´²æud &p8Qñ)ˆ«lXD©øÜéAžHìySun jª×k*D¤LH] †¦§C™Jä–´Xb~ʪwStŽ6K,°£qÁœ:9ت:¨þªl¨@¡`‚ûÚ ».Û¬¯t‹ÆSÉ[:°=Š‹„‘Nåû”Ìî{¿ÂA ‡Rà›ÀÙ6úë°Ÿð0Ä_ ½;ÃϱîÉì^ÇÛÇ#Ëë¼ôº!±Ä˜íUîÅÇ;0L1óÁµö«p% AÀºU̬ݵ¼á%霼€‡¯Á~`ÏG¯»À× ­²± =4ªnpð3¾¤³¯­ü¾¦îuÙuµÙ®|%2ÊIÿür¦#0·ÔJ``8È@S@5ê¢ ö×Þ^`8EÜ]ý.뜃Âç 7 ú ȉÞj œ½Dç zý¸iþœÑÙûÄë!ˆÞÀl§Ïw‹*DçI€nEX¯¬¼ &A¬Go¼QföõFç°¯;é¦÷îŽêJ°îúôF5¡ÌQ|îúöXªæ»TÁÏyñêï]ê² o óÎC=öõ›ÒÓPB@ D×½œä(>èCÂxŽ`±«Ÿ–JЀ»Û á¤±p+eE0`ëŽ`A Ú/NE€Ø†À9‚@¤à H½7”à‡%B‰`Àl*ƒó‘–‡8 2ñ%¸ —€:Ù1Á‰E¸àux%nP1ð!‘ðC)¾P81lÑɸF#ˆ€{´âé°ÈB„0>±û °b¡Š´±O‚3È–Ù()yRpbµ¨E.Z‘D8ÊH@% òŒx+%Ù˜Æcü »¸˜fõ¬b·d`Fê™8èXH"ÉÈ-±|1Ô6iI, 2““¬$+](A*jÐ QTÂo‰.ÛU슬Œã„Ž`¯SN¡–¶Äåyše¯ª’­¬‚´b¦Éož œ)åyâ@Ì®3 ÎtT̉°&Ø+žLÀf"Ø-|žçÔ>‡Ðv¦Ðžì\‚ Q1)Ž@Žh#aP72”ˆ™¨$‚ !ù " , =( …7IAXG]KgNgYvYxR"k\%w]'}hŽth%ˆg+ˆs%—r.—m3šx3˜x¨}9®€&©€+¨‡7§‰%¶†(¹–.¹œD¹&ǘ;Í•&ײ)×»4ïÌ6ò§KÍ þ@‘pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§g «¬ E ±± ¨­¶°ººE Á´”·®C¬²§Ç¶Œ»ÓDÃÕƷ¯Ê±H½ºM×ÁGÚ¬D¶BËÁ½î½DÓôTÏÛßîG»ôõC×CÌ l&âž:'òtU³6ɹ#·Ø)€'Ü.6±&ëÍÈ» K(8p0N?!æ2"ÛˆNIJX>R¼ÐO‚M '¡¨2¸*Ÿþ>#n↠å@‚<[:¡Iïf’ ¤TÚ˘CdbÜÙ“[«ŽEú5MBo¤×@€`@„€Êt W-3 ¶Ÿ¡BíêäjIÝ…Eò9[T…$íêﯧ„…•s»Óȳ¹€ÅÚdc®UUρ#±Ùïldj?´í¼²`\ŽÁðÞu|3'ÖŒ]ë6 ¶S#²‡˜FKLÈ *N E´‘áäŠ$˜›eÄYD„ºq«.è촁ƒs \-ÔjA 9²õ÷å- üúM[Âx(ís÷ì®x€|í¡Ù’p¦‚ ŽkÛTÇDpE@WÜ ²Ç]kŠ1¨ þ€·Yb ÓÁ‰l°*n0 ç™—žzBdОu¾7ĉBl€â‰-ºx~|UåU‰  h*Hœ|e"#"?vpÄiŠe6^ˆ„+qâŠm8 #VÇá ‘å–ÄV„œ|Аè•m"сœn|@›U¶ÆÎž—Špb¥G¨ED”€±Úê2FÌIç? >Éxå Œ± ¡¤„%‘žjŸ‘ꄯ<Ìaà9ijÐ2˜D¦È&›†Z`‚å]wþ¼Â:ç6àB¤7eFJ|õÒ§Õ,¨äàFÇ®cS·Ê¶+B°,‘Þ˜ºNûãØ>PADÌHD¹æž«ÄÀnÌ¥}­#Ë’ë QÀÉSÌÂÇ2ÌXÀ{æk²lQÁ2«ÊðÀ¯w|2Í h‹ÄÂG€,m¾¶ë3ÐÙ6-´ÅE¬L°ÆIij*K½ÀÇqï`DwVÍQXœÚÔpeœ±¬Ñ q˜§Tœ½µƒ°Œìu Â<¶aØ*At¯lmEØ ü ôÛN[P1ÔÛ¦­±$ÜÆ@`ùåDpy¶yXvCAyåB`ŽD¶ 0QwG#¯ æš[^Äþ $ÀÓÝǦ{„L™[±úKÄgÌ;ï£S~¹ìGX.ôgoT.»åˆ°ùŸûù¡?1zö¦Ÿž:ÅgÁ|ìL¹ „®£œŠ‚à0œ]PÁ^p F<"•ç?!,ñ‡N4—…PÄ Á„ö¨Û:Tè@hÀ‹%táÿ:ø-žI<`þ‹p I….)^ 40D#p@ƒj4–؀:²‰1Øâr˜¼F2oW¼#Z†;$Q q” ‘ ÂK¦ñNl#29 !’F@¥Bh·ᏀL!—XFóLH‘Kh¤.«hE&JòG¨¥<™WN!€ÑÙÚˆY„@†>Œž19J" 2,/ &.GXB%ÌRÈ9B6¹W]’î×ÔW¥’IÎ$ ñ‹ÓŒE8YÆ ¼³™ñA5“à®Q.aŸB€&Ø©³ JÁ—! ¦t)K%tœ-¦JF bòNMxLôþ)ÐR¸Ð™‘ èÝ6‘O!THÌ„HÛ ‰ !ù ) , =( …AXKgNgYvYxR"k\%wh…hŽh%ˆg+ˆs%—r.—x3˜x¨}9®€&©€+¨Œ,©‡7§‰%¶†(¹–.¹5·&Çš)ǘ;Í•&×£*Ȳ)ׯ7×»4ï°3øÌ6ò‘HÖ§KÍ»Hó¯T÷¨Yÿ»qÿÇhÿ þÀ”pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§g ª« E$±²¨ª­ · °²½$E$ÂÕ««D· Í ¿¦Ç¶¸ÌŒ¾³CÃÅÆ E ééH½MÛÂGâªD­ çBêêϾD²ÒaÀà€Š1r­ðÓ¤ ÔožzU!L˜C'¾yW½UGtäÇïÙllê0×àÂuGþ)AÀs[þ·xì ÁxO%ƒûX2ó—  P£n›R/¡ÑšHše+êDm?# —‘Ç£6¡8íJ¡ŸâDiäªM¥Ö„ôj“¬¹£5oQ7°- <‡ *´lãÓŒ2r/a!l)dÈ A™ÈE¢ôÔ͆…ð ;Ö˜c ¡%ß‚’Ùˆâ¸b½—pe~C"BíëÚHïeF2§æŠ8qb t_`urŠeü wÅu3êæPv§h•"ß`íÍxçLĹÜÖ3á  ~Öº“®›¸ÏMDfJÙ °„ÛµáWõ%§œ‚à©–‚X ÓØ)@®Ñ›Eþ´wëuÅSxb8y\mÖzœ¥§ZbºE—ÂLªÌw!y(>¡™wú=Ç|ÅÝs¢d €CÁW)HÜcC$€L Ä7„r.á\{)@ð` @ äXÈ$PD” `šaG:§æˆOˆ72EÐamn]ù"ŒcÊxÑŒ° &dR8`g«iÙŸLR!¦P …d’ä¡“¦ðÎTƒ¦ià|À _ ¥ Qi#¦Šg›Æ ›noMµ ›V ã£)p ç£ÎW…š=Âeªk§†j„ ´®1ß²sÉxéW«jšl|0¯B0Û, \jÛ´›6±¬¶C ÛíWþï|ëÙ‹¸ñzĸV {ì;Ýñn¼òVˆm³I¼³.Ðã¤PN¥ ²µ¼„µCã+¹ÍByî£Ñ¾HŸ›ëê 7ìYÆFTk¨SaoaY$Dµœìï¿Ã29RÈkt Çïfñ ÇÒ:ÀÐSp¹3ÇI¨â¥DZÄ ü9Ïýögñ½­uÔ*3)O‘˜Ö[_hv ,àî×Et Ÿé¶BH€ Õ[ü±64M@ÔSÌM7dÐl5-ÄÙU܍´©zߌ3Ô€3ž„ „ ¶ÛPô½5×g› êÚ˜kN„Ý…0Îj4€Ìë°“#{þÕ3S2çKÜ'ợlø¼Ú2K{° {Û¶?žm𸧠ËI¼nEò='êüóºè^üæÃ_Û=°óž‚ì#Oý¿Í'¡½áo..ÏYìnüñCœO±Áa¿¢Kô½o,üÄËbö²çºíï{ËC Ú— "”Ï{ËK ÍÒw„õ±Oz dÕ¨à:$ ƒô—«v»] A#ð «€¿šéz)Rx׿ˆ¥‚d``èw-îyÏf×K!ð€þ­Ð|ìPľ„=Ì`ý(f” 'Pa ¥ÐBJa%Ðâf§„%Š¡}FàáÝ×6>ÉäŠG"éŽè=ø!oа^FP¼Ø©Q„ÀCÙÁ`(Ž\ÄÝ® ©Â$<n@dÄ E#ììUÒI! ‚#lù‹`k¦ÐÇ'Rró’ZýNBÈMF Í[¤+‹ðɈ-áwj¨¥þ8¾rá ,VÂh„"|½œ=×G_¦Ñ™EØ 0i*%̲˜Æda0mV‚k¾)›;„&6 p>ÓjK “¦Ç# âDÂ:ûc?:R Ó¬fÞéI-Ì“•Ã<ä=™Ï7˜3œ¨˜c2ŒW ,ˆ”8(T™P‰F¡Jhç"‚ ; 403WebShell
403Webshell
Server IP : 172.67.177.218  /  Your IP : 216.73.216.195
Web Server : LiteSpeed
System : Linux premium229.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User : akhalid ( 749)
PHP Version : 8.3.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/akhalid/dangroup.sa/wp-content/plugins/google-site-kit/includes/Core/Util/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/akhalid/dangroup.sa/wp-content/plugins/google-site-kit/includes/Core/Util/Entity_Factory.php
<?php
/**
 * Class Google\Site_Kit\Core\Util\Entity_Factory
 *
 * @package   Google\Site_Kit
 * @copyright 2021 Google LLC
 * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link      https://sitekit.withgoogle.com
 */

namespace Google\Site_Kit\Core\Util;

use Google\Site_Kit\Plugin;
use WP_Query;
use WP_Post;
use WP_Term;
use WP_User;
use WP_Post_Type;
use WP_Screen;

/**
 * Class providing access to entities.
 *
 * This class entirely relies on WordPress core behavior and is technically decoupled from Site Kit. For example,
 * entities returned by this factory rely on the regular WordPress home URL and ignore Site Kit-specific details, such
 * as an alternative "reference site URL".
 *
 * Instead of relying on this class directly, use {@see Context::get_reference_entity()} or
 * {@see Context::get_reference_entity_from_url()}.
 *
 * @since 1.15.0
 * @access private
 * @ignore
 */
final class Entity_Factory {

	/**
	 * Gets the entity for the current WordPress context, if available.
	 *
	 * @since 1.15.0
	 *
	 * @return Entity|null The entity for the current context, or null if none could be determined.
	 */
	public static function from_context() {
		global $wp_the_query;

		// If currently in WP admin, run admin-specific checks.
		if ( is_admin() ) {
			$screen = get_current_screen();
			if ( ! $screen instanceof WP_Screen || 'post' !== $screen->base ) {
				return null;
			}

			$post = get_post();
			if ( $post instanceof WP_Post && self::is_post_public( $post ) ) {
				return self::create_entity_for_post( $post, 1 );
			}
			return null;
		}

		// Otherwise, run frontend-specific `WP_Query` logic.
		if ( $wp_the_query instanceof WP_Query ) {
			$entity = self::from_wp_query( $wp_the_query );

			$request_uri = Plugin::instance()->context()->input()->filter( INPUT_SERVER, 'REQUEST_URI' );
			return self::maybe_convert_to_amp_entity( $request_uri, $entity );
		}

		return null;
	}

	/**
	 * Gets the entity for the given URL, if available.
	 *
	 * Calling this method is expensive, so it should only be used in certain admin contexts where this is acceptable.
	 *
	 * @since 1.15.0
	 *
	 * @param string $url URL to determine the entity from.
	 * @return Entity|null The entity for the URL, or null if none could be determined.
	 */
	public static function from_url( $url ) {
		$query = WP_Query_Factory::from_url( $url );
		if ( ! $query ) {
			return null;
		}

		$query->get_posts();

		$entity = self::from_wp_query( $query );

		return self::maybe_convert_to_amp_entity( $url, $entity );
	}

	/**
	 * Gets the entity for the given `WP_Query` object, if available.
	 *
	 * @since 1.15.0
	 *
	 * @param WP_Query $query WordPress query object. Must already have run the actual database query.
	 * @return Entity|null The entity for the query, or null if none could be determined.
	 */
	public static function from_wp_query( WP_Query $query ) {
		// A singular post (possibly the static front page).
		if ( $query->is_singular() ) {
			$post = $query->get_queried_object();
			if ( $post instanceof WP_Post && self::is_post_public( $post ) ) {
				return self::create_entity_for_post( $post, self::get_query_pagenum( $query, 'page' ) );
			}
			return null;
		}

		$page = self::get_query_pagenum( $query );

		// The blog.
		if ( $query->is_home() ) {
			// The blog is either the front page...
			if ( $query->is_front_page() ) {
				return self::create_entity_for_front_blog( $page );
			}
			// ...or it is a separate post assigned as 'page_for_posts'.
			return self::create_entity_for_posts_blog( $page );
		}

		// A taxonomy term archive.
		if ( $query->is_category() || $query->is_tag() || $query->is_tax() ) {
			$term = $query->get_queried_object();
			if ( $term instanceof WP_Term ) {
				return self::create_entity_for_term( $term, $page );
			}
		}

		// An author archive.
		if ( $query->is_author() ) {
			$user = $query->get_queried_object();
			if ( $user instanceof WP_User ) {
				return self::create_entity_for_author( $user, $page );
			}
		}

		// A post type archive.
		if ( $query->is_post_type_archive() ) {
			$post_type = $query->get( 'post_type' );
			if ( is_array( $post_type ) ) {
				$post_type = reset( $post_type );
			}
			$post_type_object = get_post_type_object( $post_type );
			if ( $post_type_object instanceof WP_Post_Type ) {
				return self::create_entity_for_post_type( $post_type_object, $page );
			}
		}

		// A date-based archive.
		if ( $query->is_date() ) {
			$queried_post = self::get_first_query_post( $query );
			if ( ! $queried_post ) {
				return null;
			}
			if ( $query->is_year() ) {
				return self::create_entity_for_date( $queried_post, 'year', $page );
			}
			if ( $query->is_month() ) {
				return self::create_entity_for_date( $queried_post, 'month', $page );
			}
			if ( $query->is_day() ) {
				return self::create_entity_for_date( $queried_post, 'day', $page );
			}

			// Time archives are not covered for now. While they can theoretically be used in WordPress, they
			// aren't fully supported, and WordPress does not link to them anywhere.
			return null;
		}

		return null;
	}

	/**
	 * Creates the entity for a given post object.
	 *
	 * @since 1.15.0
	 * @since 1.68.0 Method access modifier changed to public.
	 *
	 * @param WP_Post $post A WordPress post object.
	 * @param int     $page Page number.
	 * @return Entity The entity for the post.
	 */
	public static function create_entity_for_post( WP_Post $post, $page ) {
		$url = self::paginate_post_url( get_permalink( $post ), $post, $page );

		return new Entity(
			urldecode( $url ),
			array(
				'type'  => 'post',
				'title' => $post->post_title,
				'id'    => $post->ID,
			)
		);
	}

	/**
	 * Creates the entity for the posts page blog archive.
	 *
	 * This method should only be used when the blog is handled via a separate page, i.e. when 'show_on_front' is set
	 * to 'page' and the 'page_for_posts' option is set. In this case the blog is technically a post itself, therefore
	 * its entity also includes an ID.
	 *
	 * @since 1.15.0
	 *
	 * @param int $page Page number.
	 * @return Entity|null The entity for the posts blog archive, or null if not set.
	 */
	private static function create_entity_for_posts_blog( $page ) {
		$post_id = (int) get_option( 'page_for_posts' );
		if ( ! $post_id ) {
			return null;
		}

		$post = get_post( $post_id );
		if ( ! $post ) {
			return null;
		}

		return new Entity(
			self::paginate_entity_url( get_permalink( $post ), $page ),
			array(
				'type'  => 'blog',
				'title' => $post->post_title,
				'id'    => $post->ID,
			)
		);
	}

	/**
	 * Creates the entity for the front page blog archive.
	 *
	 * This method should only be used when the front page is set to display the
	 * blog archive, i.e. is not technically a post itself.
	 *
	 * @since 1.15.0
	 *
	 * @param int $page Page number.
	 * @return Entity The entity for the front blog archive.
	 */
	private static function create_entity_for_front_blog( $page ) {
		// The translation string intentionally omits the 'google-site-kit' text domain since it should use
		// WordPress core translations.
		return new Entity(
			self::paginate_entity_url( user_trailingslashit( home_url() ), $page ),
			array(
				'type'  => 'blog',
				'title' => __( 'Home', 'default' ),
			)
		);
	}

	/**
	 * Creates the entity for a given term object, i.e. for a taxonomy term archive.
	 *
	 * @since 1.15.0
	 *
	 * @param WP_Term $term A WordPress term object.
	 * @param int     $page Page number.
	 * @return Entity The entity for the term.
	 */
	private static function create_entity_for_term( WP_Term $term, $page ) {
		// See WordPress's `get_the_archive_title()` function for this behavior. The strings here intentionally omit
		// the 'google-site-kit' text domain since they should use WordPress core translations.
		switch ( $term->taxonomy ) {
			case 'category':
				$title  = $term->name;
				$prefix = _x( 'Category:', 'category archive title prefix', 'default' );
				break;
			case 'post_tag':
				$title  = $term->name;
				$prefix = _x( 'Tag:', 'tag archive title prefix', 'default' );
				break;
			case 'post_format':
				$prefix = '';
				switch ( $term->slug ) {
					case 'post-format-aside':
						$title = _x( 'Asides', 'post format archive title', 'default' );
						break;
					case 'post-format-gallery':
						$title = _x( 'Galleries', 'post format archive title', 'default' );
						break;
					case 'post-format-image':
						$title = _x( 'Images', 'post format archive title', 'default' );
						break;
					case 'post-format-video':
						$title = _x( 'Videos', 'post format archive title', 'default' );
						break;
					case 'post-format-quote':
						$title = _x( 'Quotes', 'post format archive title', 'default' );
						break;
					case 'post-format-link':
						$title = _x( 'Links', 'post format archive title', 'default' );
						break;
					case 'post-format-status':
						$title = _x( 'Statuses', 'post format archive title', 'default' );
						break;
					case 'post-format-audio':
						$title = _x( 'Audio', 'post format archive title', 'default' );
						break;
					case 'post-format-chat':
						$title = _x( 'Chats', 'post format archive title', 'default' );
						break;
				}
				break;
			default:
				$tax    = get_taxonomy( $term->taxonomy );
				$title  = $term->name;
				$prefix = sprintf(
					/* translators: %s: Taxonomy singular name. */
					_x( '%s:', 'taxonomy term archive title prefix', 'default' ),
					$tax->labels->singular_name
				);
		}

		return new Entity(
			self::paginate_entity_url( get_term_link( $term ), $page ),
			array(
				'type'  => 'term',
				'title' => self::prefix_title( $title, $prefix ),
				'id'    => $term->term_id,
			)
		);
	}

	/**
	 * Creates the entity for a given user object, i.e. for an author archive.
	 *
	 * @since 1.15.0
	 *
	 * @param WP_User $user A WordPress user object.
	 * @param int     $page Page number.
	 * @return Entity The entity for the user.
	 */
	private static function create_entity_for_author( WP_User $user, $page ) {
		// See WordPress's `get_the_archive_title()` function for this behavior. The string here intentionally omits
		// the 'google-site-kit' text domain since it should use WordPress core translations.
		$title  = $user->display_name;
		$prefix = _x( 'Author:', 'author archive title prefix', 'default' );

		return new Entity(
			self::paginate_entity_url( get_author_posts_url( $user->ID, $user->user_nicename ), $page ),
			array(
				'type'  => 'user',
				'title' => self::prefix_title( $title, $prefix ),
				'id'    => $user->ID,
			)
		);
	}

	/**
	 * Creates the entity for a given post type object.
	 *
	 * @since 1.15.0
	 *
	 * @param WP_Post_Type $post_type A WordPress post type object.
	 * @param int          $page Page number.
	 * @return Entity The entity for the post type.
	 */
	private static function create_entity_for_post_type( WP_Post_Type $post_type, $page ) {
		// See WordPress's `get_the_archive_title()` function for this behavior. The string here intentionally omits
		// the 'google-site-kit' text domain since it should use WordPress core translations.
		$title  = $post_type->labels->name;
		$prefix = _x( 'Archives:', 'post type archive title prefix', 'default' );

		return new Entity(
			self::paginate_entity_url( get_post_type_archive_link( $post_type->name ), $page ),
			array(
				'type'  => 'post_type',
				'title' => self::prefix_title( $title, $prefix ),
			)
		);
	}

	/**
	 * Creates the entity for a date-based archive.
	 *
	 * The post specified has to any post from the query, in order to extract the relevant date information.
	 *
	 * @since 1.15.0
	 *
	 * @param WP_Post $queried_post A WordPress post object from the query.
	 * @param string  $type         Type of the date-based archive. Either 'year', 'month', or 'day'.
	 * @param int     $page         Page number.
	 * @return Entity|null The entity for the date archive, or null if unable to parse date.
	 */
	private static function create_entity_for_date( WP_Post $queried_post, $type, $page ) {
		// See WordPress's `get_the_archive_title()` function for this behavior. The strings here intentionally omit
		// the 'google-site-kit' text domain since they should use WordPress core translations.
		switch ( $type ) {
			case 'year':
				$prefix          = _x( 'Year:', 'date archive title prefix', 'default' );
				$format          = _x( 'Y', 'yearly archives date format', 'default' );
				$url_func        = 'get_year_link';
				$url_func_format = 'Y';
				break;
			case 'month':
				$prefix          = _x( 'Month:', 'date archive title prefix', 'default' );
				$format          = _x( 'F Y', 'monthly archives date format', 'default' );
				$url_func        = 'get_month_link';
				$url_func_format = 'Y/m';
				break;
			default:
				$type            = 'day';
				$prefix          = _x( 'Day:', 'date archive title prefix', 'default' );
				$format          = _x( 'F j, Y', 'daily archives date format', 'default' );
				$url_func        = 'get_day_link';
				$url_func_format = 'Y/m/j';
		}

		$title = get_post_time( $format, false, $queried_post, true );

		$url_func_args = get_post_time( $url_func_format, false, $queried_post );
		if ( ! $url_func_args ) {
			return null; // Unable to parse date, likely there is none set.
		}
		$url_func_args = array_map( 'absint', explode( '/', $url_func_args ) );

		return new Entity(
			self::paginate_entity_url( call_user_func_array( $url_func, $url_func_args ), $page ),
			array(
				'type'  => $type,
				'title' => self::prefix_title( $title, $prefix ),
			)
		);
	}

	/**
	 * Checks whether a given post is public, i.e. has a public URL.
	 *
	 * @since 1.15.0
	 *
	 * @param WP_Post $post A WordPress post object.
	 * @return bool True if the post is public, false otherwise.
	 */
	private static function is_post_public( WP_Post $post ) {
		// If post status isn't 'publish', the post is not public.
		if ( 'publish' !== get_post_status( $post ) ) {
			return false;
		}

		// If the post type overall is not publicly viewable, the post is not public.
		if ( ! is_post_type_viewable( $post->post_type ) ) {
			return false;
		}

		// Otherwise, the post is public.
		return true;
	}

	/**
	 * Gets the first post from a WordPress query.
	 *
	 * @since 1.15.0
	 *
	 * @param WP_Query $query WordPress query object. Must already have run the actual database query.
	 * @return WP_Post|null WordPress post object, or null if none found.
	 */
	private static function get_first_query_post( WP_Query $query ) {
		if ( ! $query->posts ) {
			return null;
		}

		$post = reset( $query->posts );
		if ( $post instanceof WP_Post ) {
			return $post;
		}

		if ( is_numeric( $post ) ) {
			return get_post( $post );
		}

		return null;
	}

	/**
	 * Combines an entity title and prefix.
	 *
	 * This is based on the WordPress core function `get_the_archive_title()`.
	 *
	 * @since 1.15.0
	 *
	 * @param string $title  The title.
	 * @param string $prefix The prefix to add, should end in a colon.
	 * @return string Resulting entity title.
	 */
	private static function prefix_title( $title, $prefix ) {
		if ( empty( $prefix ) ) {
			return $title;
		}

		// See WordPress's `get_the_archive_title()` function for this behavior. The string here intentionally omits
		// the 'google-site-kit' text domain since it should use WordPress core translations.
		return sprintf(
			/* translators: 1: Title prefix. 2: Title. */
			_x( '%1$s %2$s', 'archive title', 'default' ),
			$prefix,
			$title
		);
	}

	/**
	 * Converts given entity to AMP entity if the given URL is an AMP URL.
	 *
	 * @since 1.42.0
	 *
	 * @param string $url URL to determine the entity from.
	 * @param Entity $entity The initial entity.
	 * @return Entity The initial or new entity for the given URL.
	 */
	private static function maybe_convert_to_amp_entity( $url, $entity ) {
		if ( is_null( $entity ) || ! defined( 'AMP__VERSION' ) ) {
			return $entity;
		}

		$url_parts   = URL::parse( $url );
		$current_url = $entity->get_url();

		if ( ! empty( $url_parts['query'] ) ) {
			$url_query_params = array();

			wp_parse_str( $url_parts['query'], $url_query_params );

			// check if the $url has amp query param.
			if ( array_key_exists( 'amp', $url_query_params ) ) {
				$new_url = add_query_arg( 'amp', '1', $current_url );
				return self::convert_to_amp_entity( $new_url, $entity );
			}
		}

		if ( ! empty( $url_parts['path'] ) ) {
			// We need to correctly add trailing slash if the original url had trailing slash.
			// That's the reason why we need to check for both version.
			if ( '/amp' === substr( $url_parts['path'], -4 ) ) { // -strlen('/amp') is -4
				$new_url = untrailingslashit( $current_url ) . '/amp';
				return self::convert_to_amp_entity( $new_url, $entity );
			}

			if ( '/amp/' === substr( $url_parts['path'], -5 ) ) { // -strlen('/amp/') is -5
				$new_url = untrailingslashit( $current_url ) . '/amp/';
				return self::convert_to_amp_entity( $new_url, $entity );
			}
		}

		return $entity;
	}

	/**
	 * Converts given entity to AMP entity by changing the entity URL and adding correct mode.
	 *
	 * @since 1.42.0
	 *
	 * @param string $new_url URL of the new entity.
	 * @param Entity $entity The initial entity.
	 * @return Entity The new entity.
	 */
	private static function convert_to_amp_entity( $new_url, $entity ) {
		$new_entity = new Entity(
			$new_url,
			array(
				'id'    => $entity->get_id(),
				'type'  => $entity->get_type(),
				'title' => $entity->get_title(),
				'mode'  => 'amp_secondary',
			)
		);

		return $new_entity;
	}

	/**
	 * Gets the page number for a query, via the specified query var. Defaults to 1.
	 *
	 * @since 1.68.0
	 *
	 * @param WP_Query $query A WordPress query object.
	 * @param string   $query_var Optional. Query var to look for, expects 'paged' or 'page'. Default 'paged'.
	 * @return int The page number.
	 */
	private static function get_query_pagenum( $query, $query_var = 'paged' ) {
		return $query->get( $query_var ) ? (int) $query->get( $query_var ) : 1;
	}

	/**
	 * Paginates an entity URL.
	 *
	 * Logic extracted from `paginate_links` in WordPress core.
	 * https://github.com/WordPress/WordPress/blob/7f5d7f1b56087c3eb718da4bd81deb06e077bbbb/wp-includes/general-template.php#L4203
	 *
	 * @since 1.68.0
	 *
	 * @param string $url The URL to paginate.
	 * @param int    $pagenum The page number to add to the URL.
	 * @return string The paginated URL.
	 */
	private static function paginate_entity_url( $url, $pagenum ) {
		global $wp_rewrite;

		if ( 1 === $pagenum ) {
			return $url;
		}

		// Setting up default values based on the given URL.
		$url_parts = explode( '?', $url );

		// Append the format placeholder to the base URL.
		$base = trailingslashit( $url_parts[0] ) . '%_%';

		// URL base depends on permalink settings.
		$format  = $wp_rewrite->using_index_permalinks() && ! strpos( $base, 'index.php' ) ? 'index.php/' : '';
		$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';

		// Array of query args to add.
		$add_args = array();

		// Merge additional query vars found in the original URL into 'add_args' array.
		if ( isset( $url_parts[1] ) ) {
			// Find the format argument.
			$format_parts = explode( '?', str_replace( '%_%', $format, $base ) );
			$format_query = isset( $format_parts[1] ) ? $format_parts[1] : '';
			wp_parse_str( $format_query, $format_args );

			// Find the query args of the requested URL.
			$url_query_args = array();
			wp_parse_str( $url_parts[1], $url_query_args );

			// Remove the format argument from the array of query arguments, to avoid overwriting custom format.
			foreach ( $format_args as $format_arg => $format_arg_value ) {
				unset( $url_query_args[ $format_arg ] );
			}

			$add_args = array_merge( $add_args, urlencode_deep( $url_query_args ) );
		}

		$link = str_replace( '%_%', $format, $base );
		$link = str_replace( '%#%', $pagenum, $link );
		if ( $add_args ) {
			$link = add_query_arg( $add_args, $link );
		}

		return $link;
	}

	/**
	 * Paginates a post URL.
	 *
	 * Logic extracted from `_wp_link_page` in WordPress core.
	 * https://github.com/WordPress/WordPress/blob/7f5d7f1b56087c3eb718da4bd81deb06e077bbbb/wp-includes/post-template.php#L1031
	 *
	 * @since 1.68.0
	 *
	 * @param string  $url The URL to paginate.
	 * @param WP_Post $post The WordPress post object.
	 * @param int     $pagenum The page number to add to the URL.
	 * @return string The paginated URL.
	 */
	private static function paginate_post_url( $url, $post, $pagenum ) {
		global $wp_rewrite;

		if ( 1 === $pagenum ) {
			return $url;
		}

		if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) {
			$url = add_query_arg( 'page', $pagenum, $url );
		} elseif ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === (int) $post->ID ) {
			$url = trailingslashit( $url ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $pagenum, 'single_paged' );
		} else {
			$url = trailingslashit( $url ) . user_trailingslashit( $pagenum, 'single_paged' );
		}

		return $url;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit