<?php
//small functions, are use in client side.. and need to call any where...
//functions with out in class
function currentWebLanguage()
{
    global $functions;
    //Work For website Language
    $lang = '';
    if (isset($_SESSION['webUser']['webLang'])) {
        $lang = $_SESSION['webUser']['webLang'];
    } else {
        $defaultWebLanguage = $functions->WebDefaultLanguage();
        $lang = $defaultWebLanguage;
    }


    $_SESSION['webUser']['webLang'] = $lang;
    return $lang;
}


function setRememberMe($name, $value, $days)
{

    $hour = time() + (3600 * 24 * $days);
    $value = serialize($value);
    setcookie("$name", $value, $hour);
    $_COOKIE["$name"] = '';
    $_COOKIE["$name"] = $value;
}


function webUserSession()
{

    global $functions;

    //Set Session if New User.

    if (!isset($_SESSION['webUser']['login']) && !isset($_SESSION['webUser']['tempId'])) {

        $_SESSION['webUser']['login'] = '0';

        $_SESSION['webUser']['id'] = '0';

        $_SESSION['webUser']['tempId'] = uniqid() . "_" . uniqid();

        //tempId blank if user login, transfer tempId in old temp id on login,

        $_SESSION['webUser']['oldTempId'] = '';

        $_SESSION['webUser']['name'] = '';
    }

    return $_SESSION['webUser'];
}


function webUserId()
{
    $userData = webUserSession();
    return $userData['id'];
}

function webTempUserId()
{
    $userData = webUserSession();
    return $userData['tempId'];
}


function webUserOldTempId()
{
    $userData = webUserSession();
    return $userData['oldTempId'];
}


function userLoginCheck()
{
    $userData = webUserSession();
    if ($userData['id'] == '0')
        return false;
    return true;
}

function webUserType()
{
    @$userData = webUserSession();
    return @$userData['type'];
}


//work on latin content type

function specialChar_to_english_letters($text)
{
    return preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($text));
}

function sanitize_file_name($string, $anal = false)
{

    $string = specialChar_to_english_letters($string);
    $strip = array(
        "~",
        "`",
        "!",
        "@",
        "#",
        "$",
        "%",
        "^",
        "&",
        "*",
        "(",
        ")",
        "=",
        "+",
        "[",
        "{",
        "]",
        "}",
        "\\",
        "|",
        ";",
        ":",
        "\"",
        "'",
        "&#8216;",
        "&#8217;",
        "&#8220;",
        "&#8221;",
        "&#8211;",
        "&#8212;",
        "—",
        "–",
        ",",
        "<",
        ">",
        "/",
        "?"
    );

    $clean = trim(str_replace($strip, "", strip_tags($string)));

    $clean = preg_replace('/\s+/', "-", $clean);

    $clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean;
    return strtolower($clean);
}