public function _remap($model) { global $admin, $ci, $page; $this->benchmark->mark('page_setup_start'); if (!defined('BLOG')) { define('BLOG', ''); } define('BASE_URL', $this->config->base_url()); $this->poster = md5(BASE_URL); $this->model = $model; $ci = $this; // $ci =& get_instance(); doesn't cut it so ... $errors = ''; do { $errors .= ob_get_clean(); } while (ob_get_level()); ob_start(); session_cache_limiter(''); // turn off automatic sending of cache headers if ($this->model == '#cache#') { $file = func_get_arg(1); $type = array_pop($file); $this->load->driver('resources'); return $this->resources->deliverer->view(implode('/', $file), $type); } $admin = array_merge(array('name' => '', 'email' => '', 'password' => '', 'folder' => ''), (array) $admin); define('ADMIN', !empty($admin['folder']) ? trim($admin['folder'], '/') . '/' : 'admin/'); $uri = $this->uri->uri_string(); $bp_admin = strpos($uri . '/', ADMIN) === 0 ? isset($admin['function']) ? $admin['function'] : true : false; if (!$bp_admin && $this->poster != $this->model) { $uri = str_replace('_', '-', $uri); } $paths = array(); foreach (explode('/', $uri) as $value) { if (($extension = strpos($value, '.')) !== false) { $value = substr($value, 0, $extension); } // remove file extensions if (!empty($value)) { $paths[] = $value; } // remove empty "folders" } $paths = array_diff($paths, array('index')); // remove any reference to 'index' $type = pathinfo($uri, PATHINFO_EXTENSION); if (!empty($type) && in_array($type, array('xml', 'txt', 'less'))) { $desired_url = $this->config->base_url(implode('/', $paths) . '.' . $type); } else { $desired_url = $this->config->site_url($paths) . strstr($_SERVER['REQUEST_URI'], '?'); } $actual_url = (is_https() ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; if ($desired_url != $actual_url) { header('Location: ' . $desired_url, true, 301); exit; } $this->load->driver('session'); $this->load->library('sitemap'); if ($html = $this->sitemap->cached()) { $this->benchmark->mark('page_setup_end'); $this->benchmark->mark('page_display_start'); } else { require_once BASE . 'Page.php'; $page = new Page(); $this->benchmark->mark('page_setup_end'); $this->benchmark->mark('page_content_start'); if ($this->model == $this->poster) { $this->delay_flashdata(); $this->log_analytics('users'); $image = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); header('Expires: Fri, 01 Jan 1990 00:00:00 GMT'); header('Cache-Control: max-age=0, must-revalidate'); header('Content-Length: ' . strlen($image)); header('Content-Type: image/gif'); header('Pragma: no-cache'); exit($image); } elseif ($template = $this->input->post($this->poster)) { $this->delay_flashdata(); $data = array(); $file = BASE_URI . 'blog/content/post.tpl'; if (is_file($file)) { $this->load->driver('blog', array('role' => '#post#')); $this->blog->resources(BASE_URL . 'blog/content/'); $this->load->library('auth'); $vars = array('template' => $template, 'user' => $this->auth->user(), 'uri' => array('id' => $this->sitemap->uri('id'), 'type' => $this->sitemap->uri('type'), 'views' => $this->sitemap->uri('views'))); $this->blog->smarty($file, $vars); $data = $this->compile($page->post); } $data = json_encode($this->filter_links($data)); header('Content-Type: application/json'); header('Content-Length: ' . strlen($data)); exit($data); } elseif ($this->model == '#sitemap#') { $params = func_get_arg(1); $method = array_shift($params); // Either 'robots' or 'xml' $html = $this->sitemap->{$method}(array_shift($params)); } else { if ($bp_admin) { $this->load->driver('blog', array('role' => '#admin#')); if (is_callable($bp_admin)) { $html = $bp_admin(); } elseif ($route = $page->routes(array(ADMIN, ADMIN . '[blog:view]/[published|unpublished|posts|pages' . (is_admin(1) ? '|authors|categories|tags|templates|backup|restore' : null) . ':folder]?', ADMIN . '[sitemap' . (is_admin(1) ? '|setup|errors|plugins|folders|databases' : null) . ':view]', ADMIN . '[users:view]/[logout' . (is_admin(1) ? '|register|edit|list' : null) . ':action]?', ADMIN . '[themes:view]/[download|preview:action]?/[:theme]?/[bootstrap\\.less:less]?', ADMIN . '[analytics:view]/[users|pages|referrers:method]?'))) { if (!isset($route['params']['view'])) { $page->eject(ADMIN . 'blog'); } $view = $route['params']['view']; $this->load->driver('admin', array('file' => $view)); $html = $this->admin->{$view}->view($route['params']); } else { $page->eject(BASE_URL . ADMIN . 'users'); } } elseif ($folder = $page->folder(BASE_URI . 'folders/')) { $this->load->driver('blog', array('role' => '#folder#')); $html = $page->outreach($folder . 'index.php', array('folder' => array('name' => trim(str_replace(BASE_URI . 'folders', '', $folder), '/'), 'url' => str_replace(BASE_URI, BASE_URL, $folder), 'uri' => $folder))); } else { $this->load->driver('blog', array('role' => '#blog#')); if ($file = $this->blog->file($page->get('uri'))) { $html = $this->blog->pages->post($file); } elseif ($route = $page->routes(array(BLOG, BLOG . '/[atom|rss:method].xml', BLOG . '/[archives:method]/[i:year]?/[i:month]?/[i:day]?', BLOG . '/[authors|tags:method]/[:uri]?', BLOG . '/[**:method]' => 'category'))) { $method = isset($route['params']['method']) ? $route['params']['method'] : ($this->input->get('search') ? 'search' : 'index'); if ($route['target'] == 'category') { $method = 'category'; $route['params'] = array_shift($route['params']); if (!is_dir($this->blog->post . $route['params'])) { show_404($page->url()); } } $html = $this->blog->pages->{$method}($route['params']); } else { show_404($page->url()); } } } $this->benchmark->mark('page_content_end'); $this->benchmark->mark('page_display_start'); if ($page->get('type') == 'html') { $html = $this->layout($html); do { $errors .= ob_get_clean(); } while (ob_get_level()); $html = $this->filter_links($page->display($html . $errors)); } if ($this->output->get_content_type() == 'text/html') { $this->output->set_content_type($page->get('type')); } if (trim($errors) == '') { $this->sitemap->update($html); } } $this->log_analytics('hits'); if ($this->session->enable_profiler && $this->output->get_content_type() == 'text/html' && $bp_admin === false) { $this->output->enable_profiler(true); } elseif (trim($errors) == '') { $this->sitemap->may_change(); } do { $errors .= ob_get_clean(); } while (ob_get_level()); // for compression's sake $this->load->view('view', array('html' => $html)); $this->benchmark->mark('page_display_end'); }