/** * Creates a template with layout only. * * Sometimes you just want to separate parts of your layout without giving them some special logic. * You may just store them as *.tpl.php files and create a template from them like this: * <code php> * // assuming template file is 'templates/my.tpl.php' * $tpl = Template::Make('my'); * $tpl->set('myvar','I am just layout'); * <code> * @param string $template_basename Name of the template * @return Template The created template */ static function Make($template_basename) { if (file_exists($template_basename)) { $tpl_file = $template_basename; } else { foreach (array_reverse(cfg_get('system', 'tpl_ext')) as $tpl_ext) { $tpl_file = __search_file_for_class($template_basename, $tpl_ext); if ($tpl_file) { break; } } } if (!$tpl_file) { WdfException::Raise("Template not found: {$template_basename}"); } $res = new Template($tpl_file); return $res; }
/** * @attribute[RequestParam('username','string',false)] * @attribute[RequestParam('password','string',false)] */ function Login($username, $password) { // if credentials are given, try to log in if ($username && $password) { // see config.php for credentials if ($username == cfg_get('admin', 'username') && $password == cfg_get('admin', 'password')) { $_SESSION['logged_in'] = true; // check only the fact that somebody logged in redirect('Admin'); } $this->content(uiMessage::Error("Unknown username/passsword")); } // putting it together as control here. other ways would be to create a new class // derived from Control or a Template (anonymous or with an own class) $form = $this->content(new Form()); $form->content("Username:"******"<br/>Password:"******"Login"); }
/** * @attribute[RequestParam('submitter','bool',false)] * @attribute[RequestParam('skip_minify','bool',false)] * @attribute[RequestParam('random_nc','bool',false)] */ function Start($submitter, $skip_minify, $random_nc) { global $CONFIG; if (!$submitter) { $this->_contentdiv->content("<h1>Select what to minify</h1>"); $form = $this->_contentdiv->content(new Form()); $form->AddHidden('submitter', '1'); $form->AddCheckbox('skip_minify', 'Skip minify (only collect and combine)<br/>'); $form->AddCheckbox('random_nc', 'Generate random name (instead of app version)<br/>'); $form->AddSubmit('Go'); return; } $this->_contentdiv->content("<h1>Minify DONE</h1>"); $parts = array_diff($CONFIG['class_path']['order'], array('system', 'model', 'content')); $paths = array(); foreach ($parts as $part) { $paths = array_merge($paths, $CONFIG['class_path'][$part]); } sort($paths); $root_paths = array(); foreach ($paths as $i => $cp) { $root = true; for ($j = 0; $j < $i && $root; $j++) { if (starts_with($cp, $paths[$j])) { $root = false; } } if ($root) { $root_paths[] = $cp; } } if ($skip_minify) { $GLOBALS['nominify'] = '1'; } $target_path = cfg_get('minify', 'target_path'); system_ensure_path_ending($target_path, true); $target = $target_path . cfg_get('minify', 'base_name'); minify_all($root_paths, $target, $random_nc ? md5(time()) : getAppVersion('nc')); }
/** * 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; }
/** * @internal Collects files for minifying */ function minify_collect_files($paths, $kind) { global $dependency_info, $res_file_storage, $ext_resources; $dependency_info = array(); $res_file_storage = array(); $ext_resources = array(); foreach ($paths as $path) { if (!ends_with($path, "/")) { $path .= "/"; } foreach (system_glob_rec($path, '*.class.php') as $f) { minify_collect_from_file($kind, $f); } $done_templates = array(); foreach (array_reverse(cfg_get('system', 'tpl_ext')) as $tpl_ext) { $files = system_glob_rec($path, "*.{$tpl_ext}"); foreach ($files as $f) { $skip = false; foreach ($done_templates as $d) { if (isset($res_file_storage[basename($f, ".{$d}")])) { $skip = true; break; } } if ($skip) { continue; } minify_collect_from_file($kind, $f); } $done_templates[] = $tpl_ext; } } $res = array(); $classes = array_keys($res_file_storage); foreach ($classes as $class) { $res = array_merge($res, minify_resolve_dependencies($class, $dependency_info, $res_file_storage)); } unset($dependency_info); unset($res_file_storage); return array_unique($res); }
if ($is_ajax) { echo json_encode($errors); die; } else { include "form.php"; exit; } } $db = new sql_db(DB_HOST, DB_USER, DB_PASS, DB_NAME); $created = time(); $db->query("INSERT INTO members_changes SET\n\t\t\t\t m_created = " . $created . ",\n\t\t\t\t m_type = 'add',\n\t\t\t\t m_state = 'awaiting',\n\t\t\t\t m_nick = '" . $db->check($_POST["nick"]) . "',\n\t\t\t\t m_name = '" . $db->check($_POST["name"] . " " . $_POST["surname"]) . "',\n\t\t\t\t m_mail = '" . $db->check($_POST["email"]) . "',\n\t\t\t\t m_address = '" . $db->check($_POST["address"] . ", " . $_POST["zip"] . " " . $_POST["city"] . ", " . $_POST["country"]) . "',\n\t\t\t\t m_year = '" . $db->check($_POST["birth"]) . "',\n\t\t\t\t m_jabber = '',\n\t\t\t\t m_how = '" . $db->check($_POST["how"]) . "',\n\t\t\t\t m_note = '" . $db->check($_POST["note"]) . "',\n\t\t\t\t m_distribution = '" . $db->check($_POST["distribution"]) . "',\n\t\t\t\t m_location = '" . $db->check($_POST["location"]) . "',\n\t\t\t\t m_currency = '" . $db->check($_POST["currency"]) . "',\n\t\t\t\t m_reason = '',\n\t\t\t\t m_addr = '" . $db->check($_SERVER["REMOTE_ADDR"]) . "',\n\t\t\t\t m_addr_reverse = '" . $db->check(gethostbyaddr($_SERVER["REMOTE_ADDR"])) . "',\n\t\t\t\t m_last_mail_id = 1\n\t\t\t\t "); $request_id = $db->insert_id(); // Mail admins $admins = explode(",", cfg_get("mailer_requests_sendto")); $subject = cfg_get("mailer_requests_admin_sub"); $text = cfg_get("mailer_requests_admin_text"); $subject = str_replace("%request_id%", $request_id, $subject); $subject = str_replace("%type%", "add", $subject); $subject = str_replace("%state%", "awaiting", $subject); $subject = str_replace("%member_id%", "-", $subject); $subject = str_replace("%member%", "-", $subject); $subject = str_replace("%name%", $_POST["name"] . " " . $_POST["surname"], $subject); $text = str_replace("%created%", strftime("%Y-%m-%d %H:%M", $created), $text); $text = str_replace("%changed_at%", "-", $text); $text = str_replace("%request_id%", $request_id, $text); $text = str_replace("%type%", "add", $text); $text = str_replace("%state%", "awaiting", $text); $text = str_replace("%member_id%", "-", $text); $text = str_replace("%member%", "-", $text); $text = str_replace("%admin_id%", "-", $text); $text = str_replace("%admin%", "-", $text);
/** * Executes the current request. * * This is the second of two essential functions. * It runs the actual execution. If fact it is the only place where you will * find an `echo` in the ScavixWDF code. * @return void */ function system_execute() { session_sanitize(); execute_hooks(HOOK_POST_INITSESSION); // respond to PING requests that are sended to keep the session alive if (Args::request('ping', false)) { session_keep_alive(); execute_hooks(HOOK_PING_RECIEVED); die("PONG"); } // respond to DEBUG requests if ($GLOBALS['CONFIG']['system']['ajax_debug_argument']) { $data = Args::request($GLOBALS['CONFIG']['system']['ajax_debug_argument'], false); if ($data) { logging_add_category("JS"); $data = json_decode($data, true); if (is_array($data) && count($data) > 0) { log_write(Args::request('sev', ''), array_shift($data), $data); } else { log_write(Args::request('sev', ''), $data); } die('"OK"'); } } Args::strip_tags(); global $current_controller, $current_event; list($current_controller, $current_event) = system_parse_request_path(); $current_controller = system_instanciate_controller($current_controller); if (!(system_method_exists($current_controller, $current_event) || system_method_exists($current_controller, '__method_exists') && $current_controller->__method_exists($current_event))) { $current_event = cfg_get('system', 'default_event'); } if (!isset($GLOBALS['wdf_route'])) { $GLOBALS['wdf_route'] = array($current_controller, $current_event); } if (system_method_exists($current_controller, $current_event) || system_method_exists($current_controller, '__method_exists') && $current_controller->__method_exists($current_event)) { $content = system_invoke_request($current_controller, $current_event, HOOK_PRE_EXECUTE); } else { $content = ''; } execute_hooks(HOOK_POST_EXECUTE); @set_time_limit(ini_get('max_execution_time')); system_exit($content, false); }
/** * @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(); }