<?php

// 全局函数

// 捕获所有请求信息，包含fatal error
// register_shutdown_function('shutdownHandler');
function shutdownHandler()
{
    \Heanup\Frame\Logger::emerg('', 'access');
}

/**
 * 获取当前语言环境
 *
 * @return string
 */
function lang()
{
    static $global_lang;
    if ($global_lang !== null) {
        return $global_lang;
    }
    $global_lang = ! empty($_REQUEST['global_lang']) ? $_REQUEST['global_lang'] : $_COOKIE['global_lang'];
    if (empty($global_lang) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $global_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        $global_lang=$global_lang=='zh'?$global_lang:"en";
        setcookie("global_lang", $global_lang, time() + 3600 * 24 * 30, '/');
    }
    return $global_lang;
}

/**
 * 获取当前平台值
 *
 * @return string
 */
function getplatform()
{
    $platform = ! empty($_REQUEST['platform']) ? intval($_REQUEST['platform']) : intval($_COOKIE['user_platform']);
    $platform = $platform ?  : 1;
    if (! $_COOKIE['user_platform'])
        setcookie("user_platform", $platform, time() + 3600 * 24 * 30, '/');
    return $platform;
}

/**
 * 脚本推送
 *
 * @param string $shpath
 *            执行的脚本路径
 * @param string $parrams
 *            附加的参数
 * @return string
 */
function push($shpath, $parrams = "")
{
    return shell_exec("/bin/sh " . $shpath . " " . $parrams);
}