/** * Constructor. Parses the request and fills in all the * values it can. */ protected function __construct() { $this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $config = api_config::getInstance(); $this->outputLangs = $config->lang['languages']; $this->defaultLang = $config->lang['default']; if (is_null($this->outputLangs)) { $this->outputLangs = array('en'); } if (is_null($this->defaultLang)) { $this->defaultLang = 'en'; } // Parse host, get SLD / TLDww.tv.nu/ $hostinfo = api_init::getHostConfig($this->host); if ($hostinfo) { $this->sld = $hostinfo['sld']; $this->tld = $hostinfo['tld']; } $path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; //$path = isset($_REQUEST['p']) ? $_GET['p'] : ''; if (strpos($path, '.php') !== FALSE) { $path = substr($path, 0, strpos($path, '.php')); } if (strpos($path, '?') !== FALSE) { $path = substr($path, 0, strpos($path, '?')); } // Get language from the beginning of the URL $lang = $this->getLanguageFromPath($path); if ($lang !== null) { $this->lang = $lang['lang']; $path = $lang['path']; } // Strip out path prefix from path if (isset($hostinfo['path'])) { if (strpos($path, $hostinfo['path']) === 0) { $path = substr($path, strlen($hostinfo['path'])); } if (substr($path, 0, 1) !== '/') { $path = '/' . $path; } } // HTTP verb - assume GET as default $this->verb = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET'; $this->params = new api_params(); $this->params->setGet($_GET); if ($this->verb == 'POST') { $this->params->setPost($_POST); } if ($this->lang === '') { $lang = $this->parseLanguage($path); $this->lang = $lang['lang']; $path = $lang['path']; } $this->url = API_HOST . $this->lang . API_MOUNTPATH . substr($path, 1); $this->path = api_helpers_string::removeDoubleSlashes($path); // Path $this->filename = $this->parseFilename($this->path); $matches = array(); if ($this->filename != '') { /* if you set an extension: [xml, foo, rss, html] node in your * config file, only these extensions are valid extensions. * the rest is not parsed as an extension */ preg_match("#\\.([a-z]+)\$#", $this->filename, $matches); $aExtensions = api_config::getInstance()->extensions; if (isset($matches[1]) && !empty($matches[1])) { if (isset($aExtensions) && is_array($aExtensions)) { if (in_array($matches[1], $aExtensions)) { $this->extension = $matches[1]; } } else { $this->extension = $matches[1]; } } } }