/** * 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; }
/** * @implements <SessionBase::Store> */ function Store(&$obj, $id = "") { global $CONFIG; if ($id == "") { if (!isset($obj->_storage_id)) { WdfException::Raise("Trying to store an object without storage_id!"); } $id = $obj->_storage_id; } else { $obj->_storage_id = $id; } $serializer = new Serializer(); $content = $serializer->Serialize($obj); $vals = "id=?0 , request_id=?1 , storage_id=?2 , last_access=NOW(), content=?3"; $updates = "last_access=NOW(), content=?4, request_id=?5"; $this->ds->ExecuteSql("REPLACE INTO " . $CONFIG['session']['table'] . "\n\t\t\tSET {$vals}", array(session_id(), request_id(), $id, $content)); $GLOBALS['object_storage'][strtolower($id)] = $obj; }
/** * @override */ function WdfRenderAsRoot() { execute_hooks(HOOK_PRE_RENDER, array($this)); $init_data = $this->wdf_settings; $init_data['request_id'] = request_id(); $init_data['site_root'] = cfg_get('system', 'url_root'); if (cfg_getd('system', 'attach_session_to_ajax', false)) { $init_data['session_id'] = session_id(); $init_data['session_name'] = session_name(); } if (isDevOrBeta()) { $init_data['log_to_console'] = true; } if ($GLOBALS['CONFIG']['system']['ajax_debug_argument']) { $init_data['log_to_server'] = $GLOBALS['CONFIG']['system']['ajax_debug_argument']; } $this->set("wdf_init", "wdf.init(" . json_encode($init_data) . ");"); $this->set("docready", $this->docready); $this->set("plaindocready", $this->plaindocready); return parent::WdfRenderAsRoot(); }
function peace($flag = '') { $proposition_id = $this->proposition_id; $valid_flags = array('details', 'details_submit'); $flag = $this->flagcheck($valid_flags, $flag); switch ($flag) { // details case 'details': $this->smarty->display('propositions_peace.tpl'); break; // details_submit // details_submit case 'details_submit': $target =& request_id('kingdom', 'target_kingdom_id'); $kingdom =& $this->data->kingdom($_SESSION['kingdom_id']); if (!isset($kingdom['allies'][$target['kingdom_id']]) && !isset($kingdom['enemies'][$target['kingdom_id']])) { error(__FILE__, __LINE__, 'INVALID_ID', 'Already at peace with specified kingdom.'); } $statement = trim(substr(trim($_REQUEST['statement']), 0, 512)); $proposition = array('round_id' => $_SESSION['round_id'], 'kingdom_id' => $_SESSION['kingdom_id'], 'player_id' => $_SESSION['player_id'], 'title' => 'Peace with ' . $target['name'], 'statement' => $statement, 'type' => PROPOSITION_PEACE, 'target_id' => $target['kingdom_id'], 'expires' => microfloat() + $_SESSION['round_speed'] * 86400); $db_result = $this->sql->execute('propositions', $proposition); $proposition_id = mysql_insert_id(); $_SESSION['status'][] = 'Proposition added.'; redirect('propositions.php?fn=propositions_info&proposition_id=' . $proposition_id); break; // for // for case 'for': $proposition =& $this->data->proposition($proposition_id); $kingdom =& $this->data->kingdom($proposition['kingdom_id']); $target =& $this->data->kingdom($proposition['target_id']); if (empty($proposition['storage']) && !isset($kingdom['allies'][$target['kingdom_id']])) { $proposition = array('round_id' => $_SESSION['round_id'], 'kingdom_id' => $proposition['target_id'], 'player_id' => $_SESSION['player_id'], 'title' => 'Peace with ' . $kingdom['name'], 'statement' => $proposition['statement'], 'type' => PROPOSITION_PEACE, 'storage' => $proposition['kingdom_id'], 'target_id' => $proposition['kingdom_id'], 'expires' => microfloat() + $_SESSION['round_speed'] * 86400); $db_result = $this->sql->execute('propositions', $proposition); } else { if (isset($kingdom['enemies'][$proposition['target_id']])) { unset($kingdom['enemies'][$proposition['target_id']]); } if (isset($kingdom['allies'][$proposition['target_id']])) { unset($kingdom['allies'][$proposition['target_id']]); } if (isset($target['enemies'][$proposition['kingdom_id']])) { unset($target['enemies'][$proposition['kingdom_id']]); } if (isset($target['allies'][$proposition['kingdom_id']])) { unset($target['allies'][$proposition['kingdom_id']]); } $news = array('kingdom_id' => $proposition['kingdom_id'], 'kingdom_name' => $kingdom['name'], 'player_id' => $proposition['player_id'], 'player_name' => $player['name'], 'target_id' => $target['kingdom_id'], 'target_name' => $target['name'], 'statement' => $proposition['statement'], 'posted' => microfloat()); add_news_entry(NEWS_PEACE, $news); } $this->data->save(); break; // against // against case 'against': // diplomatic_message( break; // neutral // neutral case 'neutral': break; default: error(__FILE__, __LINE__, 'INVALID_FLAG', 'Invalid internal flag for proposition'); break; } }