histogram: Make histograms crash less
[ninja.git] / application / helpers / base_url.php
blob95c242b8b0d00c4722c4c7724e1b06fc10c68592
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 /**
4 * Helper to get the proper complete URL to the server
5 */
6 class base_url_Core {
8 /**
9 * This relies on the setting op5reports.site_address or a webserver
10 * CLI will fail to resolve an URI without having the mentioned config key
12 * @return string similar to https://192.168.1.211/ninja/index.php/
14 public static function get() {
15 $check_port = 80;
16 $protocol = 'http';
17 if(isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) {
18 $protocol .= 's';
19 $check_port = 443;
21 $host = Kohana::config('op5reports.site_address', false, false);
22 if(!$host && isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
23 $host = $_SERVER['HTTP_HOST'];
25 // trim port from $host since we append it just below
26 $host_parts = explode(":", $host);
27 $host = $host_parts[0];
28 $port = '';
29 if(isset($_SERVER['SERVER_PORT']) && $check_port != $_SERVER['SERVER_PORT']) {
30 $port = ':'.$_SERVER['SERVER_PORT'];
32 $site_domain = Kohana::config('config.site_domain', true);
33 $uri = $protocol.'://'.$host.$port.$site_domain.'index.php/';
34 return $uri;