1 <?php
     
2 if(!file_exists('settings.php')){
     
3     echo "Hello! To setup the wiki, copy <code>example_settings.php</code> to
     
4           <code>settings.php</code> and then reload this page.";
     
5     exit;
     
6 }
     
7 
     8 require_once 'settings.php';
     
9 
    10 # Trim a trailing slash from paths (if there was one)
    
11 $GLOBALS['page_dir'] = rtrim($GLOBALS['page_dir'], '/');
    
12 $GLOBALS['archive_dir'] = rtrim($GLOBALS['archive_dir'], '/');
    
13 $GLOBALS['uploads_dir'] = rtrim($GLOBALS['uploads_dir'], '/');
    
14 
    15 
    16 # This is to style the edit page differently from a regular content view page.
    
17 # Default is empty string (no special class).
    
18 $GLOBALS['page_body_class'] = '';
    
19 
    20 function return_error($code, $msg){
    
21     http_response_code($code);
    
22     echo $msg;
    
23     exit;
    
24 }
    
25 
    26 function check_login(){
    
27     if(!isset($_COOKIE['login'])
    
28      ||!isset($GLOBALS['wiki_logins'])
    
29      ||!isset($GLOBALS['wiki_logins'][$_COOKIE['login']])){
    
30         return false;
    
31     }
    
32 
    33     $GLOBALS['user_name'] = $GLOBALS['wiki_logins'][$_COOKIE['login']];
    
34     return true;
    
35 }
    
36 
    37 function require_login(){
    
38     if(!check_login()){
    
39         return_error(401, 'Login required!');
    
40     }
    
41 }
    
42