Exemple #1
0
	/**
	 * Get the referrer page.
	 *
	 * If there's no referrer or it's external, Kunena will return default page.
	 * Also referrers back to tasks are removed.
	 *
	 * @param string $default  Default page to return into.
	 * @param string $anchor   Anchor (location in the page).
	 *
	 * @return string
	 */
	public static function getReferrer($default = null, $anchor = null)
	{
		$app = JFactory::getApplication();

		$referrer = $app->input->server->getString('HTTP_REFERER');

		if ($referrer)
		{
			$uri = new JUri($referrer);

			// Make sure we do not return into a task -- or if task is SEF encoded, make sure it fails.
			$uri->delVar('task');
			$uri->delVar(JSession::getFormToken());

			// Check that referrer was from the same domain and came from the Joomla frontend or backend.
			$base = $uri->toString(array('scheme', 'host', 'port', 'path'));
			$host = $uri->toString(array('scheme', 'host', 'port'));

			// Referrer should always have host set and it should come from the same base address.
			if (empty($host) || stripos($base, JUri::base()) !== 0)
			{
				$uri = null;
			}
		}

		if (!isset($uri))
		{
			if ($default == null)
			{
				$default = $app->isSite() ? 'index.php?option=com_kunena' : 'administrator/index.php?option=com_kunena';
			}

			$default = self::_($default);
			$uri = new JUri($default);
		}

		if ($anchor)
		{
			$uri->setFragment($anchor);
		}

		return $uri->toString(array('path', 'query', 'fragment'));
	}
 /**
  * Test the setFragment method.
  *
  * @return  void
  *
  * @since   11.1
  * @covers  JUri::setFragment
  */
 public function testSetFragment()
 {
     $this->object->setFragment('someFragment');
     $this->assertThat($this->object->getFragment(), $this->equalTo('someFragment'));
 }