1 <?php
     
2 require_once 'core.php';
     
3 
     4 $logged_in = check_login();
     
5 $show_edit_menu = $logged_in;
     
6 
     7 # Get requested page, or load default
     
8 $page_name = $GLOBALS['default_page_name'];
     
9 if(isset($_REQUEST['page']) && strlen($_REQUEST['page']) > 0){
    
10     $page_name = $_REQUEST['page'];
    
11 }
    
12 ?>
    
13 <!DOCTYPE html>
    
14 <html lang="<?=$GLOBALS['lang']?>">
    
15 <head>
    
16     <title>Wiki</title>
    
17     <meta charset="utf-8">
    
18     <meta name="viewport" content="width=device-width, initial-scale=1">
    
19     <link rel="icon" type="image/png" sizes="32x32" href="icon32x32.png">
    
20     <style>
    
21     body {
    
22         margin: auto;
    
23         padding: 20px;
    
24         max-width: 700px;
    
25         font-size: 1.2em;
    
26         background: #FFE;
    
27     }
    
28     #edit_menu {
    
29         display: flex;
    
30         align-items: center;
    
31     }
    
32     #edit_menu>div { padding: 5px; }
    
33     #edit_menu div.name { color: #666; }
    
34     </style>
    
35 </head>
    
36 <body>
    
37 
    38 <header id="edit_menu">
    
39     <div><a href="index.php">Home</a></div>
    
40 
    41     <div style="flex: 2;"></div>
    
42 
    43     <?php if(isset($show_edit_menu) && $show_edit_menu): ?>
    
44         <img src="icon32x32.png" alt="">
    
45         <div>
    
46             <div class="name"><?=$GLOBALS['user_name']?></div>
    
47             <a href="edit.php?page=<?=$GLOBALS['page_name']?>">Edit this Page</a>
    
48         </div>
    
49     <?php endif; ?>
    
50 
    51 </header>
    
52 
    53 <?php
    
54 if(!$GLOBALS['anonymous_viewing'] && !$logged_in){
    
55     echo '<h1>Login Required</h1>';
    
56     exit;
    
57 }
    
58 
    59 $fname = "${GLOBALS['page_dir']}/${page_name}.html";
    
60 if(file_exists($fname)){
    
61     include $fname;
    
62 }
    
63 else{
    
64     if($show_edit_menu){
    
65         echo "<h1>Create '$page_name'?</h1>
    
66             <p><a href=\"edit.php?page=$page_name\">Click here</a>
    
67              to create this page.</p>";
    
68     }
    
69     else{
    
70         echo "<h1>Not found</h1><p>Page '$page_name' not found.</p>";
    
71     }
    
72 }
    
73 ?>
    
74 
    75     <script>
    
76     // Find a main heading tag and set the page title.
    
77     var tt = document.querySelector('h1');
    
78     if(tt){ document.title = tt.textContent; }
    
79     </script>
    
80 </body>
    
81 </html>