/** * @override */ function PreRender($args = array()) { if (count($args) > 0) { $controller =& $args[0]; // just to render close button with the right id if (!is_null($this->CloseButton)) { $temp = array($this->CloseButton => $this->CloseButtonAction); $this->Buttons = array_merge($this->Buttons, $temp); } $rem = system_is_ajax_call() ? ".remove()" : ''; $close_action = "\$('#{$this->id}').dialog('close'){$rem};"; foreach ($this->Buttons as $label => $action) { if (!starts_with($action, '[jscode]') && !starts_with($action, 'function')) { $action = "function(){ {$action} }"; } $this->Buttons[$label] = str_replace("{close_action}", $close_action, $action); } $this->Options['buttons'] = $this->Buttons; $tmp = $this->_script; $this->_script = array(); $this->script("try{ \$('#{$this->id}').dialog(" . system_to_json($this->Options) . "); }catch(ex){ wdf.debug(ex); }"); $this->script("\$('#{$this->id}').parent().find('.ui-dialog-buttonpane .ui-button').click(function(){ \$(this).parent().find('.ui-button').button('disable'); });"); $this->_script = array_merge($this->_script, $tmp); foreach ($this->_script as $s) { $controller->addDocReady($s); } } return parent::PreRender($args); }
/** * @override */ function WdfRender() { $tempvars = system_render_object_tree($this->get_vars()); foreach ($GLOBALS as $key => &$val) { ${$key} = $val; } $buf = array(); foreach ($tempvars as $key => &$val) { if (isset(${$key})) { $buf[$key] = ${$key}; } ${$key} = $val; } if ($this instanceof HtmlPage && stripos($this->file, "htmlpage.tpl.php") !== false) { $__template_file = __autoload__template($this, $this->SubTemplate ? $this->SubTemplate : ""); if ($__template_file === false) { WdfException::Raise("SubTemplate for class '" . get_class($this) . "' not found: " . $this->file, $this->SubTemplate); } if (stripos($__template_file, "htmlpage.tpl.php") === false) { ob_start(); require $__template_file; $sub_template_content = ob_get_contents(); ob_end_clean(); } $this->file = __DIR__ . "/htmlpage.tpl.php"; } $__template_file = __autoload__template($this, $this->file); if ($__template_file === false) { WdfException::Raise("Template for class '" . get_class($this) . "' not found: " . $this->file); } ob_start(); require $__template_file; $contents = ob_get_contents(); ob_end_clean(); foreach ($tempvars as $key => &$val) { unset(${$key}); } foreach ($buf as $key => &$val) { ${$key} = $val; } if (system_is_ajax_call() && count($this->_script) > 0) { $contents .= "<script> " . implode("\n", $this->_script) . "</script>"; } return $contents; }
/** * @override */ function WdfRender() { $attr = array(); foreach ($this->_attributes as $name => $value) { if ($name[0] != "_") { $attr[] = "{$name}=\"" . str_replace("\"", """, $value) . "\""; } } foreach ($this->_data_attributes as $name => $value) { $attr[] = "data-{$name}='" . str_replace("'", "\\'", $value) . "'"; } $content = system_render_object_tree($this->_content); if (isset($GLOBALS['html_skip_if_empty'][$this->Tag])) { if (trim(implode(" ", $content)) == "") { return ""; } } $css = array(); foreach ($this->_css as $key => $val) { $css[] = "{$key}:{$val};"; } $attr = count($attr) > 0 ? " " . implode(" ", $attr) : ""; $css = count($css) > 0 ? " style=\"" . implode(" ", $css) . "\"" : ""; $content = count($content) > 0 ? implode("", $content) : ""; if ($this->Tag) { if ($content || $this->CloseTagNeeded()) { $res = "<{$this->Tag}{$attr}{$css}>{$content}</{$this->Tag}>"; } else { $res = "<{$this->Tag}{$attr}{$css}/>"; } } else { $res = "{$content}"; } if (system_is_ajax_call() && count($this->_script) > 0) { $res .= "<script> " . implode("\n", $this->_script) . "</script>"; } return $res; }
function __construct($allow_regenerate_id = true) { global $CONFIG; if (session_name() != $CONFIG['session']['session_name'] || session_id() == "") { $name = $CONFIG['session']['session_name']; session_name($name); if (system_is_ajax_call() && !isset($_COOKIE[$name])) { die; } if (isset($_REQUEST[$name])) { $regen_needed = false; /** * @todo The following code is superfluous if variables_order=EGPCS and session.use_only_cookies = Off */ // in case that there is a session id passed in the cookie and in the post, prefer the one in post: if (isset($_POST[$name]) && $_REQUEST[$name] != $_POST[$name]) { $_REQUEST[$name] = $_COOKIE[$name] = $_POST[$name]; $regen_needed = true; } // in case that there is a session id passed in the cookie and in the get, prefer the one in get, // but do not set the COOKIE to make multi-session handling possible if (isset($_GET[$name]) && $_REQUEST[$name] != $_GET[$name]) { $_REQUEST[$name] = $_GET[$name]; $regen_needed = true; } $sid = preg_replace("/[^0-9a-zA-Z]/", "", $_REQUEST[$name]); if ($sid != "") { session_id($sid); $try = 0; while (@session_start() === false && $try++ < 10) { usleep(200); } if ($try >= 10) { trigger_error("session_start failed 10 times!", E_USER_ERROR); } // generate a new session id if the passed one is not valid if ($regen_needed && $allow_regenerate_id) { $this->RegenerateId(true); } } else { session_id($this->GenerateSessionId()); $try = 0; while (@session_start() === false && $try++ < 10) { usleep(200); } if ($try >= 10) { trigger_error("start_start failed 10 times!", E_USER_ERROR); } } } else { try { $try = 0; while (@session_start() === false && $try++ < 10) { usleep(200); } if ($try >= 10) { trigger_error("start_start failed 10 times!", E_USER_ERROR); } } catch (Exception $ex) { } } } }
/** * @internal PreRender HOOK handler */ function AddLoaderCode($args) { $loader = array(); foreach (self::$_apis as $api => $definition) { list($version, $options) = $definition; if (isset($options['callback'])) { $options['callback'] = "function(){ " . implode("\n", $options['callback']) . " }"; } else { $options['callback'] = "function(){}"; } if ($this->_culture) { $options['language'] = $this->_culture->ResolveToLanguage()->Code; } if ($this->frozen) { $loader[] = "window.googleLoadCallback = " . $options['callback']; $options['callback'] = 'function(){ window.googleLoadCallback(); }'; $loader[] = "if( window.googleLoaded ) { window.googleLoadCallback(); } else { window.googleLoaded = true; google.charts.load('42'," . system_to_json($options) . "); }"; } else { $loader[] = "google.load('{$api}','{$version}'," . system_to_json($options) . ");"; } } $controller = $args[0]; if (system_is_ajax_call()) { $controller->script($loader); } elseif ($controller instanceof HtmlPage) { $controller->addDocReady($loader, false); } // <- see the 'false'? we add these codes inline, not into the ready handler as this crashes }
/** * 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); } }