HEX
HEX
Server: Apache
System: Linux localhost.localdomain 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1001)
PHP: 8.1.32
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/ahmsolaiman.com/wp-content/plugins/types/application/models/helper/url.php
<?php

/**
 * Helper class for building external links to documentation and elsewhere.
 *
 * Note that URLs first need to be loaded before you can use self::get_url().
 *
 * @since 2.0
 */
final class Types_Helper_Url {

	const UTM_SOURCE = 'plugin';
	const UTM_CAMPAIGN = 'types';

	private static $utm_medium;
	private static $utm_term;
	private static $utm_content;

	private static $urls = array();

	const WP_TYPES_DOMAIN = 'toolset.com';


	// All values for utm_medium should be eventually defined here
	const UTM_MEDIUM_HELP = 'help';
	const UTM_MEDIUM_POSTEDIT = 'postedit';
	const UTM_MEDIUM_SHORTCODES = 'shortcodes-gui';


	/**
	 * @param bool|string $medium
	 */
	public static function set_medium( $medium = false ) {
		if( $medium ) {
			self::$utm_medium = $medium;
			return;
		}

		global $pagenow;
		if( ! empty( $pagenow ) ) {
			self::$utm_medium = $pagenow;
			return;
		}

		self::$utm_medium = false;
	}

	private static function get_medium() {
		if( self::$utm_medium === null ) {
			self::set_medium();
		}

		return self::$utm_medium;
	}

	public static function add_urls( $urls ) {
		if( is_array( $urls ) ) {
			self::$urls = array_merge( self::$urls, $urls );
		}
	}


	private static function apply_analytics_arguments_to_url( $url ) {
		if( ! self::get_medium() ) {
			return $url;
		}

		$args = array(
			'utm_source' => self::UTM_SOURCE,
			'utm_campaign' => self::UTM_CAMPAIGN,
			'utm_medium' => self::$utm_medium,
			'utm_term' => self::$utm_term
		);

		// This can === true, in which case we'll skip it, see self::get_url().
		if( is_string( self::$utm_content ) ) {
			$args['utm_content'] = self::$utm_content;
		}

		return add_query_arg(
			$args,
			$url
		);

	}

	/**
	 * Determines whether an URL points to the toolset.com domain.
	 *
	 * @param string $url
	 * @return bool
	 * @since 2.1
	 */
	private static function is_link_to_wptypes( $url ) {
		$url_parts = parse_url( $url );
		return ( toolset_getarr( $url_parts, 'host') == self::WP_TYPES_DOMAIN );
	}


	/**
	 * Retrieve the URL with additional arguments.
	 *
	 * @param string $key URL key as defined in self::add_urls().
	 * @param bool|string $utm_content This is a bit more complex than we wanted:
	 *     - false will skip *all* analytics arguments (default).
	 *     - true will continue with adding the analytics arguments but omit the utm_content one
	 *     - If a string is provided, it will be added as utm_content.
	 * @param bool|string $utm_term utm_term argument or false if $key should be used instead.
	 * @param bool|string $utm_medium utm_medium (to be set globally) or false to use a previously set value.
	 * @param bool $add_site_url If this is true and the URL points to toolset.com, an additional argument with current
	 *    site's URL will be added.
	 *
	 * @return mixed|string The URL or an empty string if the key was invalid.
	 * @since 2.0
	 */
	public static function get_url( $key, $utm_content = false, $utm_term = false, $utm_medium = false, $add_site_url = true ) {
		if( !isset( self::$urls[ $key ] ) ) {
			return '';
		}

		$url = self::$urls[ $key ];

		// return url if no arguments
		if( ! $utm_content ) {
			return $url;
		}

		// add utm content
		self::$utm_content = $utm_content;

		// use key for term, if no term isset
		if( ! $utm_term ) {
			$utm_term = $key;
		}

		self::$utm_term = $utm_term;

		// apply medium only if medium isset
		if( $utm_medium ) {
			self::set_medium( $utm_medium );
		}

		// apply arguments
		$url = self::apply_analytics_arguments_to_url( $url );

		return $url;

	}


	private static $documentation_urls_loaded = false;


	/**
	 * Load URLs to documentation links so they can be obtained via get_url().
	 *
	 * @since 2.1
	 */
	public static function load_documentation_urls() {
		if( ! self::$documentation_urls_loaded ) {
			$documentation_urls = include( TYPES_DATA . '/documentation-urls.php' );
			Types_Helper_Url::add_urls( $documentation_urls );
			self::$documentation_urls_loaded = true;
		}
	}
}