/** * Redirector * * @param array $data * @param integer $status */ function redirect($data = null) { if (!is_array($data)) { if (is_string($data)) { header('Location: ' . make_url($data), true, 301); exit; } else { if (empty($data)) { header('Location: ' . BASE_URL); exit; } } wasp_error('Incorrect redirect path'); } $msgTemp = []; if (!empty($data['message'])) { $msgTemp['message'] = $data['message']; } if (!empty($data['error'])) { $msgTemp['error'] = $data['error']; } if (array_count($msgTemp) > 0) { make_temp('redirect', serialize($msgTemp)); } unset($data['message'], $data['error'], $msgTemp); if (empty($data['controller'])) { unset($data['controller'], $data['method']); $_ = ''; if (array_count($data) > 0) { foreach ($data as $key => $val) { if (is_varible_name($key) && is_scalar($val)) { $_ .= "/{$key}/{$val}"; } } } header('Location: ' . BASE_URL . (!empty($_) ? '/index/default' . $_ : '')); exit; } $_ = BASE_URL . '/' . $data['controller']; if (isset($data['method'])) { $_ .= '/' . $data['method']; } unset($data['controller'], $data['method']); if (array_count($data) > 0) { foreach ($data as $key => $val) { if (is_varible_name($key) && is_scalar($val)) { $_ .= "/{$key}/{$val}"; } } } if (is_ajax() && !headers_sent()) { http_cache_off(); if (get_x_response_type() == 'html') { exit(javascript('window.location.href = "' . $_ . '";')); } else { if (get_x_response_type() == 'script') { exit('window.location.href = "' . $_ . '";'); } } } header('Location: ' . $_, true, 301); exit; }
public function display($content) { if (!$this->render) { if (!headers_sent() && array_count($this->_headers) > 0) { foreach ($this->_headers as $key => $val) { header($val); } } http_cache_off(); if (!Cookie::isSaved()) { cookie()->save(); } if (wasp_strlen($content) > 102400) { @ini_set('zlib.output_compression', 1); } echo $this->getDebugInfo($content); return; } $templater = new \Smarty(); $templater->enableSecurity('Wasp_Smarty_Security'); $templater->setTemplateDir($this->getThemePath() . DIR_SEP); $temp_dir = TEMP_DIR . DIR_SEP . 'smarty' . DIR_SEP . $this->getThemeName(); if (!is_dir($temp_dir)) { wasp_mkdir($temp_dir); } $templater->setCompileDir($temp_dir . DIR_SEP); if (array_count($this->_assigns) > 0) { foreach ($this->_assigns as $key => $val) { $templater->assign($key, $val); } } $templater->assign('content', $content); if (function_exists('memory_get_peak_usage')) { $templater->assign('max_mem_use', get_mem_use(true)); } else { $templater->assign('max_mem_use', '-//-'); } $out = $templater->fetch($this->_layout); if (!headers_sent() && array_count($this->_headers) > 0) { foreach ($this->_headers as $key => $val) { header($val); } } if (!Cookie::isSaved()) { cookie()->save(); } if (wasp_strlen($out) > 102400) { ini_set('zlib.output_compression', 1); } unset($templater); memory_clear(); /** * Add CSS */ if (array_count($this->_css_list) > 0) { $_ = "\n\t\t<!-- DYNAMIC CSS -->\n"; foreach ($this->_css_list as $key => $val) { if (preg_match('/^http/is', $val)) { $_ .= "\t\t<link href=\"{$val}\" rel=\"stylesheet\" type=\"text/css\" />\n"; } else { $url = $this->getThemeUrl() . '/css/' . $val; $_ .= "\t\t<link href=\"{$url}\" rel=\"stylesheet\" type=\"text/css\" />\n"; } } $out = preg_replace('#\\<\\/head\\>#is', $_ . "</head>\n", $out); unset($_, $key, $val, $url); } /** * Add JS */ if (array_count($this->_js_list) > 0) { $info = "\n\t\t<!-- :position DYNAMIC JS -->\n"; foreach ($this->_js_list as $pos => $item) { $_ = str_replace(':position', wasp_strtoupper($pos), "\n\t\t<!-- :position DYNAMIC JS -->\n"); if (array_count($item) > 0) { foreach ($item as $key => $val) { if (preg_match('/^http/is', $val)) { $_ .= "\t\t<script type=\"text/javascript\" src=\"{$val}\"></script>\n"; } else { $url = $this->getThemeUrl() . '/js/' . $val; $_ .= "\t\t<script type=\"text/javascript\" src=\"{$url}\"></script>\n"; } } $out = preg_replace("#\\<\\/{$pos}\\>#is", $_ . "</{$pos}>\n", $out); unset($_, $key, $val, $url); } } unset($pos, $item); } echo $this->getDebugInfo($out); }