aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/console
ModeNameSize
-rw-r--r--application.php2877logstatsplain
d---------command262logstatsplain
#n36'>36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
<?php
/**
*
* @package phpBB3
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

namespace phpbb\template;

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

class asset
{
	protected $components = array();

	/** @var \phpbb\path_helper **/
	protected $path_helper;

	/**
	* Constructor
	*
	* @param string $url URL
	*/
	public function __construct($url, \phpbb\path_helper $path_helper)
	{
		$this->path_helper = $path_helper;

		$this->set_url($url);
	}

	/**
	* Set URL
	*
	* @param string $url URL
	*/
	public function set_url($url)
	{
		if (version_compare(PHP_VERSION, '5.4.7') < 0 && substr($url, 0, 2) === '//')
		{
			// Workaround for PHP 5.4.6 and older bug #62844 - add fake scheme and then remove it
			$this->components = parse_url('http:' . $url);
			$this->components['scheme'] = '';
			return;
		}
		$this->components = parse_url($url);
	}

	/**
	* Convert URL components into string
	*
	* @param array $components URL components
	* @return string URL
	*/
	protected function join_url($components)
	{
		$path = '';
		if (isset($components['scheme']))
		{
			$path = $components['scheme'] === '' ? '//' : $components['scheme'] . '://';
		}

		if (isset($components['user']) || isset($components['pass']))
		{
			if ($path === '' && !isset($components['port']))
			{
				$path = '//';
			}
			$path .= $components['user'];
			if (isset($components['pass']))
			{
				$path .= ':' . $components['pass'];
			}
			$path .= '@';
		}

		if (isset($components['host']))
		{
			if ($path === '' && !isset($components['port']))
			{
				$path = '//';
			}
			$path .= $components['host'];
			if (isset($components['port']))
			{
				$path .= ':' . $components['port'];
			}
		}

		if (isset($components['path']))
		{
			$path .= $components['path'];
		}

		if (isset($components['query']))
		{
			$path .= '?' . $components['query'];
		}

		if (isset($components['fragment']))
		{
			$path .= '#' . $components['fragment'];
		}

		return $path;
	}

	/**
	* Get URL
	*
	* @return string URL
	*/
	public function get_url()
	{
		return $this->path_helper->update_web_root_path($this->join_url($this->components));
	}

	/**
	* Checks if URL is local and relative
	*
	* @return boolean True if URL is local and relative
	*/
	public function is_relative()
	{
		if (empty($this->components) || !isset($this->components['path']))
		{
			// Invalid URL
			return false;
		}
		return !isset($this->components['scheme']) && !isset($this->components['host']) && substr($this->components['path'], 0, 1) !== '/';
	}

	/**
	* Get path component of current URL
	*
	* @return string Path
	*/
	public function get_path()
	{
		return isset($this->components['path']) ? $this->components['path'] : '';
	}

	/**
	* Set path component
	*
	* @param string $path Path component
	* @param boolean $urlencode If true, parts of path should be encoded with rawurlencode()
	*/
	public function set_path($path, $urlencode = false)
	{
		if ($urlencode)
		{
			$paths = explode('/', $path);
			foreach ($paths as &$dir)
			{
				$dir = rawurlencode($dir);