function http_channel() { static $channel, $channel_retrieved = false; if ($channel_retrieved) { return $channel; } $path = http_path(); $paths_array = explode('/', ltrim($path, '/')); $channel = count($paths_array) > 0 ? $paths_array[0] : ''; $channel_retrieved = true; return $channel; }
<li>Logged in as <?php h($current_user->name); ?> </li> <li><a class="logout" href="/logout.php">Logout</a></li> </ul> </div> <div id="main-navigation"> <ul class="wat-cf"> <?php $i = 0; foreach ($nav as $k => $v) { $class = array(); if ($i == 0) { $class[] = 'first'; } if ($i == 0 && substr($path, -5) == '.html') { $class[] = 'active'; } else { if (http_path() == $k) { $class[] = 'active'; } } printf('<li class="%s"><a href="%s">%s</a></li>', implode(' ', $class), $k, h($v, true)); $i++; } ?> </ul> </div> </div>
$file = ROOT . '/giiki/theme/' . $page_name; if (file_exists($file)) { include $file; } else { die('No such page'); } break; case isset($_REQUEST['edit']): include 'giiki/theme/edit.php'; break; case isset($_REQUEST['view']): default: if (http_is_post()) { if ($_POST['form_action'] == 'newpage') { $page_name = preg_replace('/[^a-z\\s0-9\\/_\\-\\.]/i', '', $_POST['pagename']); if (!$page_name) { http_redirect(http_request_uri()); } http_redirect('/' . $page_name . '.html?edit'); } } if (!$g->page_exists()) { http_redirect('/' . $g->get_page() . '?edit'); } $qs = str_replace(http_path() . '?', '', http_request_uri()); if (strlen($qs) == 40 && preg_match('/^[a-z0-9]+$/i', $qs)) { define('COMMIT', $qs); } include 'giiki/theme/view.php'; break; }
/** * Check if user logged in. * * If not, redirect. */ function authenticate() { if (http_path() == '/login.php') { return; } do { if ($_COOKIE['cs']) { // user id and token present, check $cookie_store = json_decode($_COOKIE['cs']); if (!$cookie_store->email) { break; } try { $dbo = new DB_User(); $user = $dbo->find_by('email', $cookie_store->email); if ($cookie_store->key != md5($cookie_store->email . $cookie_store->ts . $user->token)) { break; } $this->user = $user; $this->git->set_author($this->user); return true; } catch (Exception $e) { break; } } else { break; // no chance of being logged in } } while (0); http_redirect('/login.php?fwd=' . rawurlencode(http_request_uri())); }