function PostProcess(&$output, $simpledebug = false) { global $webapp; Profiler::StartTimer("TemplateManager::PostProcess()"); $matchregex = "/\\[\\[(\\w[^\\[\\]{}:|]*)(?:[:|](.*?))?\\]\\]/"; if (!is_array($output)) { // FIXME - we should probably still postprocess if we're returning XML if (preg_match_all($matchregex, $output, $matches, PREG_SET_ORDER)) { $search = $replace = array(); foreach ($matches as $m) { $search[] = $m[0]; $replace[] = !empty($this->varreplace[$m[1]]) ? htmlspecialchars($this->varreplace[$m[1]]) : (!empty($m[2]) ? $m[2] : ""); } $pos = array_search("[[debug]]", $search); if ($pos !== false) { // if there are errors, check for access and force debug $show_debug = $webapp->debug; /* if (Logger::hasErrors()) { $user = User::singleton(); if ($user->HasRole("DEBUG") || $user->HasRole("ADMIN") || $user->HasRole("QA")) { $show_debug = true; } } */ if ($show_debug) { //$replace[$pos] = $this->GetTemplate("debug.tpl"); $replace[$pos] = $simpledebug ? Logger::Display(E_ALL) : ComponentManager::fetch("elation.debug"); } else { $replace[$pos] = ""; } } if (($pos = array_search("[[dependencies]]", $search)) !== false) { $replace[$pos] = DependencyManager::display(); // Sometimes dependencies also use postprocessing variables, so parse those and add them to the list too // FIXME - could be cleaner, this is copy-pasta of the first parsing pass above if (preg_match_all($matchregex, $replace[$pos], $submatches, PREG_SET_ORDER)) { foreach ($submatches as $sm) { $search[] = $sm[0]; $replace[] = !empty($this->varreplace[$sm[1]]) ? htmlspecialchars($this->varreplace[$sm[1]]) : (!empty($sm[2]) ? $sm[2] : ""); } } } $output = str_replace($search, $replace, $output); } } Profiler::StopTimer("TemplateManager::PostProcess()"); return $output; }