adding site.php
6 files changed, 37 insertions(+), 32 deletions(-)

M includes/app.php
M home.php => includes/home.php
M page.php => includes/page.php
M includes/site_header.php
M index.php
A => site.php
M includes/app.php +6 -2
@@ 131,9 131,13 @@ function get_link($user_id, $slug)
     return "<a href=\"page.php?id=$user_id&slug=$slug\">$slug</a>";
 }
 
-function get_link2($username, $slug)
+function get_link2($username, $slug = null)
 {
-    return "<a href=\"page.php?u=$username&slug=$slug\">$slug</a>";
+    if (isset($slug)) {
+        return "<a href=\"site.php?u=$username&p=$slug\">$slug</a>";
+    } else {
+        return "<a href=\"site.php?u=$username\">$username</a>";
+    }
 }
 
 function home_link($user_id, $name)

          
M home.php => includes/home.php +3 -10
@@ 1,11 1,4 @@ 
-<?php
-require 'includes/app.php';
-
-$site_user = $app->getUser()->getFromUsername(get_user()) or page_not_found();
-$content = content_to_html2($site_user['home'], $site_user);
-?>
-
-<?php include 'includes/site_header.php'; ?>
+<?php include 'site_header.php'; ?>
 
 <main>
 <?php if ($content): ?>

          
@@ 16,10 9,10 @@ require 'includes/app.php';
 <?php endif; ?>
 </main>
 
-<?php if (is_site_admin($site_user)): ?>
+<?php if ($is_admin): ?>
     <nav class="page-admin">
         <a href="home_update.php">Edit</a>
     </nav>
 <?php endif; ?>
 
-<?php include 'includes/site_footer.php'; ?>
  No newline at end of file
+<?php include 'site_footer.php'; ?>
  No newline at end of file

          
M page.php => includes/page.php +9 -18
@@ 1,25 1,16 @@ 
-<?php
-require 'includes/app.php';
-
-$slug = get_slug();
-$site_user = $app->getUser()->getFromUsername(get_user()) or page_not_found();
-$page = $GLOBALS['app']->getPage()->get($site_user['id'], $slug);
-$related = $GLOBALS['app']->getPage()->related($site_user['id'], $slug);
-?>
-
-<?php include 'includes/site_header.php'; ?>
+<?php include 'site_header.php'; ?>
 
 <main>
     <?php if ($page): ?>
-        <?= content_to_html2($page['content'], $site_user) ?>
+        <?= $content ?>
     <?php else: ?>
         <h1>Not found</h1>
-        <?php if (is_site_admin($site_user)): ?>
-            <p>Create page for <?= $slug ?>?</p>
+        <?php if ($is_admin): ?>
+            <p>Create page for <?=$p?>?</p>
             <form action="page_create.php" method="post" enctype="multipart/form-data">
                 <?php include 'includes/csrf.php' ?>
 
-                <input id="title" type="hidden" name="name" autocomplete="off" value="<?= $slug ?>"
+                <input id="title" type="hidden" name="name" autocomplete="off" value="<?=$p?>"
                        class="form-control"/>
 
                 <input type="submit" value="Create"/>

          
@@ 39,11 30,11 @@ require 'includes/app.php';
     </section>
 <?php endif; ?>
 
-<?php if ($page && is_site_admin($site_user)): ?>
+<?php if ($page && $is_admin): ?>
     <nav class="page-admin">
-        <?= edit_link($slug) ?>
-        <?= delete_link($slug) ?>
+        <?= edit_link($p) ?>
+        <?= delete_link($p) ?>
     </nav>
 <?php endif; ?>
 
-<?php include 'includes/site_footer.php'; ?>
+<?php include 'site_footer.php'; ?>

          
M includes/site_header.php +1 -1
@@ 14,7 14,7 @@ 
 
 <header>
     <nav>
-        <?=home_link(0, $site_user['name'])?>
+        <?=get_link2($site_user['name'])?>
         <a href="pages_index.php?id=<?=$site_user['id']?>">Pages</a>
         <a href="changelog.php?id=<?=$site_user['id']?>">Changelog</a>
     </nav>

          
M index.php +1 -1
@@ 2,7 2,7 @@ 
 require 'includes/app.php';
 
 if (is_member($user)) {
-    redirect("home.php?u=$user[name]");
+    redirect("site.php?u=$user[name]");
 }
 ?>
 

          
A => site.php +17 -0
@@ 0,0 1,17 @@ 
+<?php
+require 'includes/app.php';
+
+$u = get_user();
+$p = filter_input(INPUT_GET, 'p', FILTER_SANITIZE_SPECIAL_CHARS);
+$site_user = $app->getUser()->getFromUsername($u) or page_not_found();
+$is_admin = is_site_admin($site_user);
+
+if ($p) {
+    $page = $app->getPage()->get($site_user['id'], $p);
+    $related = $app->getPage()->related($site_user['id'], $p);
+    $content = content_to_html2($page['content'], $site_user);
+    include 'includes/page.php';
+} else {
+    $content = content_to_html2($site_user['home'], $site_user);
+    include 'includes/home.php';
+}
  No newline at end of file