3 require('includes/header.php');
7 add_error('You are not wise enough.', true);
12 if($_POST['form_sent'])
14 $page_data['url'] = ltrim($_POST['url'], '/');
15 $page_data['title'] = $_POST['title'];
16 $page_data['content'] = $_POST['content'];
21 if( ! ctype_digit($_GET['edit']))
23 add_error('Invalid page ID.', true);
26 $stmt = $link->prepare('SELECT url, page_title, content FROM pages WHERE id = ?');
27 $stmt->bind_param('i', $_GET['edit']);
29 $stmt->store_result();
30 if($stmt->num_rows
< 1)
32 $page_title = 'Non-existent page';
33 add_error('There is no page with that ID.', true);
35 if( ! $_POST['form_sent'])
37 $stmt->bind_result($page_data['url'], $page_data['title'], $page_data['content']);
43 $page_title = 'Editing page: <a href="/' . $page_data['url'] . '">' . htmlspecialchars($page_data['title']) . '</a>';
45 $page_data['id'] = $_GET['edit'];
49 $page_title = 'New page';
50 if( ! empty($page_data['title']))
52 $page_title .= ': ' . htmlspecialchars($page_data['title']);
60 if(empty($page_data['url']))
62 add_error('A path is required.');
67 // Undo the effects of sanitize_for_textarea:
68 $page_data['content'] = str_replace('/textarea', '/textarea', $page_data['content']);
72 $edit_page = $link->prepare('UPDATE pages SET url = ?, page_title = ?, content = ? WHERE id = ?');
73 $edit_page->bind_param('sssi', $page_data['url'], $page_data['title'], $page_data['content'], $page_data['id']);
74 $edit_page->execute();
77 $notice = 'Page successfully edited.';
81 $add_page = $link->prepare('INSERT INTO pages (url, page_title, content) VALUES (?, ?, ?)');
82 $add_page->bind_param('sss', $page_data['url'], $page_data['title'], $page_data['content']);
86 $notice = 'Page successfully created.';
89 redirect($notice, $page_data['url']);
95 if( $_POST['preview'] && ! empty($page_data['content']) && check_token() )
97 echo '<h3 id="preview">Preview</h3><div class="body standalone"> <h2>' . $page_data['title'] . '</h2>' . $page_data['content'] . '</div>';
102 <form action
="" method
="post">
103 <?php
csrf_token() ?
>
104 <div
class="noscreen">
105 <input type
="hidden" name
="form_sent" value
="1" />
109 <label
for="url">Path
</label
>
110 <input id
="url" name
="url" value
="<?php echo htmlspecialchars($page_data['url']) ?>" />
114 <label
for="title">Page title
</label
>
115 <input id
="title" name
="title" value
="<?php echo htmlspecialchars($page_data['title']) ?>" />
119 <textarea id
="content" name
="content" cols
="120" rows
="18"><?php
echo sanitize_for_textarea($page_data['content']) ?
></textarea
>
120 <p
>Use pure HTML
.</p
>
124 <input type
="submit" name
="preview" value
="Preview" class="inline" />
125 <input type
="submit" name
="post" value
="Submit" class="inline">
131 require('includes/footer.php');