示例#1
0
function current_user($cols = '')
{
    global $USER, $DETDB;
    if ($cols == '') {
        return $USER;
    } else {
        $obj = new stdClass();
        $cols = take_good_array($cols, true);
        foreach ($USER as $key => $item) {
            if (in_array($key, $cols)) {
                $obj->{$key} = $item;
            }
        }
        if (count($cols) != count($obj)) {
            if ($sec = $DETDB->select('users', $cols, true, "WHERE ID='{$USER->ID}'")) {
                if ($obj === null) {
                    $obj = new stdClass();
                }
                foreach ($sec as $key => $item) {
                    if (!isset($obj->{$key})) {
                        $obj->{$key} = $item;
                    }
                }
            }
        }
        if (count($cols) == 1 && isset($obj->{$cols}[0])) {
            $obj = $obj->{$cols}[0];
        }
        return $obj;
    }
}
示例#2
0
function set_glob_content($par)
{
    global $PAGE, $DETDB;
    $par = take_good_array($par);
    $custom =& $PAGE->content;
    $custom = set_merge($custom, $par);
    if ($custom['pagi']) {
        if ($custom['current'] === null) {
            $custom['current'] = get_pagination_number();
        }
        if ($custom['offset'] === null) {
            $custom['offset'] = $custom['limit'] * ($custom['current'] - 1);
        }
    }
    if ($custom['handler']) {
        $pre = null;
        if (is_string($custom['handler'])) {
            $pre = make_action($custom['handler'], $custom);
        } elseif (is_callable($custom['handler'])) {
            $pre = call_user_func($custom['handler'], $custom);
        }
        if ($pre && (is_object($pre) || is_array($pre))) {
            $custom = set_merge($custom, $pre, true);
        }
    }
    if ($custom['pagi'] && $custom['all'] === null) {
        $custom['all'] = isset($par['table']) ? $DETDB->count($par['table']) : 1;
    }
    if ($custom['body'] == '' && isset($par['table'])) {
        if ($custom['pagi']) {
            $par['offset'] = $custom['offset'];
            $par['limit'] = $custom['limit'];
        }
        $custom['body'] = $DETDB->select($par);
    }
    if ($custom['pagi'] && $custom['all'] && $custom['limit'] && ceil($custom['all'] / $custom['limit']) < $custom['current']) {
        redirect(get_current_key(), true);
    }
}
示例#3
0
function secure_text($str, $param = null)
{
    $custom = array('str' => $str, 'clear' => false, 'html' => true, 'basic_remove' => 'script, iframe, applet', 'custom_remove' => '');
    if (is_merged($param)) {
        $custom = set_merge($custom, $param);
    }
    if ($custom['clear']) {
        $custom['str'] = strip_tags($custom['str']);
    } else {
        if (!$custom['html']) {
            $custom['str'] = htmlentities($custom['str'], ENT_HTML5, 'UTF-8');
        }
        $removes = array();
        if ($custom['custom_remove']) {
            $removes = array_merge($removes, take_good_array($custom['custom_remove'], true));
        }
        if ($custom['basic_remove']) {
            $removes = array_merge($removes, take_good_array($custom['basic_remove'], true));
        }
        $removes = array_unique($removes);
        if (count($removes)) {
            foreach ($removes as $tag) {
                $custom['str'] = preg_replace("/<{$tag}.*?\\/{$tag}>/i", '', $custom['str']);
            }
        }
    }
    return $custom['str'];
}
示例#4
0
function string_values($arr, $var = null, $par = null)
{
    $str = '';
    $mode = is_assoc_array($arr) && $par == null ? true : false;
    if ($mode) {
        $par = $var;
    }
    $custom = array('separ' => ',', 'empty' => 'NULL', 'middle' => '=', 'body' => "'", 'json' => false);
    $custom = set_merge($custom, $par);
    $arr = take_good_array($arr, true, $custom['json']);
    if (!$mode) {
        $var = take_good_array($var, false, $custom['json']);
        if (count($arr) == 1 && count($var) > 1) {
            $var = array(json_val_encode($var));
        }
    }
    $L = get_last_key($arr);
    $i = 1;
    if (!$mode && $var) {
        $B = count($arr) < count($var) ? count($arr) : count($var);
    } else {
        $B = count($arr);
    }
    foreach ($arr as $key => $item) {
        if ($i <= $B) {
            $item1 = $item2 = null;
            if ($mode) {
                $item1 = $key;
                $item2 = $item;
            } elseif (isset($var[$key])) {
                $item1 = $item;
                $item2 = $var[$key];
            }
            if (is_jsoned($item1)) {
                $item1 = json_val_encode($item1);
            }
            if (is_jsoned($item2)) {
                $item2 = json_val_encode($item2);
            }
            $str .= "{$item1}{$custom['middle']}{$custom['body']}{$item2}{$custom['body']}";
            if ($key != $L && $i < $B) {
                $str .= $custom['separ'];
            }
            $i++;
        }
    }
    return $str;
}