<?php

/*
 * *************************************************
 * Copyright (C) 2020 Earworks.                    *
 * Codeigniter Project Template Modification       *
 * Please contact our email for more information : *
 * contact@earworks.co.id                          *
 * *************************************************
 */

defined('BASEPATH') OR exit('No direct script access allowed');
if (!function_exists('get_query_string')) {

    function url_query($custom_query = []) {
        $get = null;
        if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
            $get = '?' . $_SERVER['QUERY_STRING'];
        }
        if ($custom_query) {
            foreach ($custom_query as $key => $val) {
                $new_query = urlencode($key) . '=' . urlencode($val);
                $get = ($get != null) ? $get . '&' . $new_query : '?' . $new_query;
            }
        }
        return $get;
    }

}

function base_url($uri = '', $protocol = NULL) {
    $result = get_instance()->config->base_url($uri, $protocol);
    if (strpos($uri, '..') !== false) {
        $parts = explode('/', $result);
        $backwardIndex = array_search('..', $parts);
        unset($parts[$backwardIndex]);
        unset($parts[$backwardIndex - 1]);
        $result = implode('/', $parts);
    }
    return $result;
}
function ws_url($url = null){
    $trim_url = ltrim($url, '/');
    $host = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : RTS_HOST; 
    $str = "ws://{$host}:".RTS_PORT."/blank/public/{$trim_url}";
    return $str;
}