コード例 #1
0
ファイル: system.php プロジェクト: rtoi/WebFramework
/**
 * Terminats the current run and presents a result to the browser.
 * 
 * @param mixed $result The result that shall be passed to the browser
 * @param bool $die If true uses <die>() for output, else uses <echo>()
 * @return void
 */
function system_exit($result = null, $die = true)
{
    if (!isset($result) || !$result) {
        $result = current_controller(false);
    }
    if (system_is_ajax_call()) {
        if ($result instanceof AjaxResponse) {
            $response = $result->Render();
        } elseif ($result instanceof Renderable) {
            $response = AjaxResponse::Renderable($result)->Render();
        } else {
            WdfException::Raise("Unknown AJAX return value");
        }
    } elseif ($result instanceof AjaxResponse) {
        // is system_is_ajax_call() failed to detect AJAX but response in fact IS for AJAX
        die("__SESSION_TIMEOUT__");
    } else {
        $_SESSION['request_id'] = request_id();
        if ($result instanceof Renderable) {
            $response = $result->WdfRenderAsRoot();
            if ($result->_translate && system_is_module_loaded("translation")) {
                $response = __translate($response);
            }
        } elseif (system_is_module_loaded("translation")) {
            $response = __translate($result);
        }
    }
    model_store();
    session_update();
    execute_hooks(HOOK_PRE_FINISH, array($response));
    if ($die) {
        die($response);
    }
    echo $response;
}
コード例 #2
0
ファイル: translation.php プロジェクト: rtoi/WebFramework
/**
 * Returns a localized string from the current user's language. 
 * 
 * Replaces all placeholders in string from arreplace i.e. TXT_TEST => "this is a {tt}" with arreplace = aray("{tt}" => "test") => returns "this is a test"
 * Buffers all strings on first access of this function.
 * @param string $constant Text constant. i.e. TXT_...
 * @param array $arreplace Replacement array
 * @param bool $unbuffered Reload from session instead of from cache buffer of current script
 * @param string $encoding E.g. cp1252. Default "null" => UTF-8 will be returned
 * @return string Translated string
 */
function getStringOrig($constant, $arreplace = null, $unbuffered = false, $encoding = null)
{
    // common 'ensure includes'-block. repeated multiple times in this file for performance reasons
    if (!isset($GLOBALS['current_language'])) {
        detect_language();
    }
    if (!isset($GLOBALS['translation']['included_language']) || $GLOBALS['translation']['included_language'] != $GLOBALS['current_language']) {
        translation_do_includes();
    }
    if ($arreplace instanceof Model) {
        $arreplace = $arreplace->AsArray();
    }
    if (!$unbuffered) {
        $key = "lang_{$GLOBALS['translation']['included_language']}_{$constant}" . md5($constant . serialize($arreplace) . $GLOBALS['current_language'] . $encoding);
        $res = cache_get($key);
        if ($res !== false) {
            return $res;
        }
    }
    $GLOBALS['translation']['skip_buffering_once'] = false;
    if (isset($GLOBALS['translation']['strings'][$constant])) {
        $res = $GLOBALS['translation']['strings'][$constant];
        $res = ReplaceVariables($res, $arreplace);
    } else {
        // may be one of the system default strings
        $def = cfg_get('translation', 'default_strings', $constant);
        if ($def) {
            $res = ReplaceVariables($def, $arreplace);
            $GLOBALS['translation']['skip_buffering_once'] = true;
            $GLOBALS['__unknown_constants']["k" . $constant] = $constant;
        } else {
            // $constant is not really a constant, but just a string, so we just need to replace the vars in there
            $res = ReplaceVariables($constant, $arreplace);
            if ($res == $constant) {
                // if still the same, constant is unknown
                $res = htmlspecialchars($constant) . "?";
                $GLOBALS['translation']['skip_buffering_once'] = true;
                $GLOBALS['__unknown_constants']["k" . $constant] = $constant;
            }
        }
    }
    if (!is_null($encoding)) {
        $res = iconv("UTF-8", $encoding . "//IGNORE", $res);
    }
    if (!$GLOBALS['translation']['skip_buffering_once'] && preg_match_all($GLOBALS['__translate_regpattern'], $res, $m)) {
        $res = __translate($res);
    }
    if (isset($key) && !$GLOBALS['translation']['skip_buffering_once']) {
        cache_set($key, $res);
    }
    return $res;
}
コード例 #3
0
 /**
  * @internal Renders the response for output.
  */
 function Render()
 {
     if ($this->_data) {
         if (isset($this->_data->script)) {
             $this->_data->script = "<script>" . implode("\n", $this->_data->script) . "</script>";
         }
         $res = system_to_json($this->_data);
     } elseif ($this->_text) {
         $res = json_encode($this->_text);
     } else {
         return '""';
     }
     // return an empty string JSON encoded to not kill the app JS side
     return !$this->_translated && system_is_module_loaded("translation") ? __translate($res) : $res;
 }