/**
  * @internal Create new string handler
  * @attribute[RequestParam('term','string')]
  * @attribute[RequestParam('text','string','')]
  */
 function CreateString($term, $text)
 {
     global $CONFIG;
     $data = array(array('term' => $term));
     $data = json_encode($data);
     $res = $this->request(array('action' => 'add_terms', 'data' => $data));
     if (!$res) {
         return AjaxResponse::Error("Could not create term: " . $this->Lasterror, true);
     }
     if ($text) {
         $text = urldecode($text);
         $data = array(array('term' => array('term' => $term), 'definition' => array('forms' => array($text), 'fuzzy' => 0)));
         $data = json_encode($data);
         $res = $this->request(array('action' => 'update_language', 'language' => $CONFIG['localization']['default_language'], 'data' => $data));
         if (!$res) {
             return AjaxResponse::Error("Could not set initial term content: " . $this->Lasterror, true);
         }
         cache_del('lang_' . $term);
     }
     return $this->DeleteString($term);
 }
Example #2
0
/**
 * Terminats the current run.
 * 
 * Will be called from exception and error handlers. You may, call this directly, but we
 * recommend to throw an exception instead. See the WdfException class and it's Raise() method
 * for more about this.
 * Note: This function will call `die()`!
 * @param string $reason The reason as human readable and hopefully understandable text
 * @param string $additional_message More details to be logged
 * @return void
 */
function system_die($reason, $additional_message = '')
{
    if ($reason instanceof Exception) {
        $stacktrace = $reason instanceof WdfException ? $reason->getTraceEx() : $reason->getTrace();
        $reason = logging_render_var($reason);
    }
    if (!isset($stacktrace)) {
        $stacktrace = debug_backtrace();
    }
    if (isset($GLOBALS['system']['hooks'][HOOK_SYSTEM_DIE]) && count($GLOBALS['system']['hooks'][HOOK_SYSTEM_DIE]) > 0) {
        execute_hooks(HOOK_SYSTEM_DIE, array($reason, $stacktrace));
    }
    if (system_is_ajax_call()) {
        $res = AjaxResponse::Error($reason . "\n" . $additional_message, true);
        die($res->Render());
        //		$code = "alert(unescape(".json_encode($reason."\n".$additional_message)."));";
        //		$res = new stdClass();
        //		$res->html = "<script>$code</script>";
        //		die(system_to_json($res));
    } else {
        $stacktrace = system_stacktrace_to_string($stacktrace);
        $res = "<html><head><title>Fatal system error</title></head>";
        $res .= "<body>";
        $res .= "<h1>Fatal system error occured</h1>";
        if (isDev()) {
            $res .= "<pre>{$reason}</pre><pre>{$additional_message}</pre><pre>" . $stacktrace . "</pre>";
        } else {
            $res .= "Fatal System Error occured.<br/>Please try again.<br/>Contact our technical support if this problem occurs again.<br/><br/>Apologies for any inconveniences this may have caused you.";
        }
        $res .= "</body></html>";
        die($res);
    }
}