Инструменты пользователя

Инструменты сайта


Боковая панель

Связь

class_dfunction

class DFunction

class DFunction - класс для проверки пользовательских данных.

# nano classes/DFunction.php
<?php
 
/**
 * 
 * @author darkfire
 * 
 * include_once($_SERVER['DOCUMENT_ROOT']."/classes/DFunction.php");
 */
class DFunction {
 
    static function detectlanguage() {
        /* Example for use
         * $language = DFunction::detectlanguage();
         * echo "You have chosen $language as your language in your web browser.";
         */
 
        $langcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $langcode = explode(",", $langcode['0']);
        return $langcode['0'];
    }
 
    static function clearInData($data, $type = 'i') {
        // User datas is clearing.
        switch ($type) {
            case 'i': return (int) $data;
                break;
            case 's': return trim(strip_tags($data));
                break;
            default: return FALSE;
                break;
        }
    }
 
}
 
function go_url($url) {
    /* Example for use
     * go_url($_SERVER['REQUEST_URI']);
     */
    if (!headers_sent()) {    //If headers not sent then do php redirect
        header('Location: ' . $url);
        exit;
    } else {
//If headers are sent do JS redirect... if javascript disabled, do html redirect.
        echo '<script type="text/javascript"> window.location.href="' . $url . '"; </script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
        echo '</noscript>';
        exit;
    }
}
 
function FBytes($size, $param = 'KB') {
    /*
     * Convert Bytes to KB to MB to GB to TB
     * echo FBytes(filesize($filename),'MB');
     */
    switch ($param) {
        case 'TB': $size /= 1024;
        case 'GB': $size /= 1024;
        case 'MB': $size /= 1024;
        case 'KB': $size /= 1024;
    }
    return round($size, 2) . " $param";
}
 
function nicebool($value) {
    if ($value === false || $value == 0 || empty($value))
        return "<font color=\"red\">Off (${value})</font>";
    return "<font color=\"green\">On (${value})</font>";
}
 
function nicebool2($value) {
    if ($value >= 10 and $value < 100)
        return "<font color=\"orange\">(${value})</font>";
    if ($value >= 100)
        return "<font color=\"red\">(${value})</font>";
    return $value;
}
 
?>



class_dfunction.txt · Последние изменения: 2015/04/08 07:47 (внешнее изменение)