+ <div id='navigation'>
+ <h1>
+END_OF_NAVIGATION;
+ if (!$this->comments_enabled) {
+ $this->display_comment_link();
+ }
+ echo <<<END_OF_NAVIGATION
+ <a href="/notes/">back to notes</a>/
+ </h1>
+ </div>
+END_OF_NAVIGATION;
+ }
+
+ private function display_comment_link() {
+ if ($this->number_of_comments > 0) {
+ $anchor_text = "comments($this->number_of_comments)/";
+ } else {
+ $anchor_text = "comment?";
+ }
+ if (substr($this->url, (strlen($this->url)-1), strlen($this->url)) == '/') {
+ $url = $this->url . 'comments/';
+ } else {
+ $url = $this->url . '/comments/';
+ }
+ echo "<a id='comment_link' href='$url'>$anchor_text</a>";
+ }
+
+ private function display_comments() {
+ echo "<div id='comments'>";
+ $sql= "SELECT date_posted, author, text
+ FROM comments WHERE note = ?
+ ORDER BY date_posted DESC";
+ $result = $this->query($sql, 'd', $this->id);
+ foreach ($result as $row => $entry) {
+ $date_posted = $entry['date_posted'];
+ $author = $entry['author'];
+ $text = htmlspecialchars($entry['text']);
+ $head = "<h3>$author</h3>";
+ echo <<<END_OF_COMMENT
+ <div class='comment'>
+ $head
+ $text
+ </div>
+END_OF_COMMENT;
+ }
+ echo "</div>";
+ }
+
+ private function display_comment_form() {
+ $publickey = $this->recaptcha_publickey;
+ echo <<<END_CAPTCHA_STYLE
+<script type="text/javascript">
+Recaptcha.create("$publickey",
+ "recaptcha_div",
+ {
+ theme : 'custom',
+ custom_theme_widget: 'recaptcha_widget',
+ callback: Recaptcha.focus_response_field
+ });
+</script>
+END_CAPTCHA_STYLE;
+ require_once('includes/recaptchalib.php');
+ $url = $this->url . "verify";
+ echo "<form id='comment_form' method='post' action='$url'>";
+ echo <<<END_OF_FORM
+ <div id="comment">
+ <h3>comment:</h3>
+ <textarea rows="10" cols="70" name="text" id="comment_text"></textarea>
+ <h3>name:</h3>
+ <input type=text name="name" id="comment_name">
+
+ <nowiki>
+ <div id="recaptcha_widget">
+ <h3 class="recaptcha_only_if_image"><b>what's this say</b>?</h3>
+ <h3 class="recaptcha_only_if_audio"><b>enter the numbers you hear</b>:</h3>
+ <span style="font-size:80%;">
+ ( <a href="javascript:Recaptcha.reload()">another</a> /
+ <span class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">audio</a></span> /
+ <span class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')">image</a></span><a href="javascript:Recaptcha.showhelp()">help</a> )
+ </span>
+ <br><br>
+ <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />
+ <br><br>
+ <div style="float:right;position:relative;width:100px;">
+ <div id="recaptcha_image"></div>
+ </div>
+ <br><br><br><br>
+ </div>
+END_OF_FORM;
+ echo recaptcha_get_html($this->recaptcha_publickey);
+ if ($this->failed_captcha) {
+ echo <<<END_OF_ERRORS
+ <div id="not_human">
+ reCAPTCHA said you're not human, <br>
+ try again?
+ </div>
+ <input id="submit" class="submit" type="submit" value="post comment">
+ </form>
+ </div>
+END_OF_ERRORS;
+ } else {
+ echo <<<END_OF_ERRORS
+ <div id="not_human">
+ reCAPTCHA said you're not human, <br>
+ try again?
+ </div>
+ <div id="blank_comment">
+ but you didn't write anything! <br>
+ </div>
+END_OF_ERRORS;
+ }
+ echo <<<END_OF_FORM
+ <input id="submit" class="submit" type="submit" value="post comment">
+ </form>
+ </div>
+END_OF_FORM;
+ }
+}
+
+
+class archive extends cms {
+
+ public function __construct() {
+ parent::__construct();
+ }
+
+ private function check_exists() {
+ $sql = "SELECT COUNT(*) FROM notes
+ WHERE url = ?";
+ $results = $this->query($sql, "s", $_GET['note']);
+ if ($results[0]["COUNT(*)"] != 1) {
+ $this->not_found();
+ }
+ }
+
+ public function display() {
+ $this->display_head();
+ switch (true) {
+ case (isset($_GET['year']) && !isset($_GET['month'])
+ && !isset($_GET['day'])):
+ $sql = "SELECT title, url, date_posted, text
+ FROM notes WHERE YEAR(date_posted) = ?
+ ORDER BY date_posted DESC";
+ $result = $this->query($sql, "d",
+ $_GET['year']);
+ break;
+ case (isset($_GET['year']) && isset($_GET['month'])
+ && !isset($_GET['day'])):
+ $sql = "SELECT title, url, date_posted, text
+ FROM notes WHERE YEAR(date_posted) = ?
+ AND MONTH(date_posted) = ?
+ ORDER BY date_posted DESC";
+ $result = $this->query($sql, "dd",
+ $_GET['year'], $_GET['month']);
+ break;
+ case (isset($_GET['year']) && isset($_GET['month'])
+ && isset($_GET['day'])):
+ $sql = "SELECT title, url, date_posted, text
+ FROM notes WHERE YEAR(date_posted) = ?
+ AND MONTH(date_posted) = ?
+ AND DAY(date_posted) = ?
+ ORDER BY date_posted DESC";
+ $result = $this->query($sql, "ddd",
+ $_GET['year'], $_GET['month'],
+ $_GET['day']);
+ break;
+ }
+ if (count($result) >= 1) {
+ echo "<div id='notes'>";
+ foreach ($result as $row => $entry) {
+ $title = $entry['title'];
+ $url = '/note/' . $entry['url'];
+ $date_posted = explode("-", $entry['date_posted']);
+ $year_posted = $date_posted[0];
+ $month_posted = $date_posted[1];
+ $datetime_posted = explode(' ', $date_posted[2]);
+ $day_posted = $datetime_posted[0];
+ echo "<div class='note'>";
+ echo "<h1><span class='date'>";
+ echo "$year_posted/$month_posted/$day_posted/";
+ echo "</span><a href='$url'>$title</a></h1>";
+ echo $entry['text'];
+ echo "</div>";
+ }
+ echo "</div>";
+ $this->write_navigation();
+ } else {
+ echo "<br>";
+ echo "<h1>sorry, nothing here</h2>";
+ echo "<pre>Empty set (0.00 sec)</pre>";
+ }
+ $this->display_close();
+ }
+
+ private function write_navigation() {
+ echo "<br>";
+ echo "<div id='navigation'>";
+ // fill me in!
+ echo "</div>";
+ }
+
+}
+
+
+class notFound extends Exception {
+
+ public function __construct() {
+ header('HTTP/1.0 404 Not Found');
+ ob_end_clean();
+ include('404.php');
+ exit();
+ }
+
+}
+
+
+class captcha extends cms {
+
+ public function display() {
+ $challenge = $_GET['challenge'];
+ $response = $_GET['response'];
+ $remoteip = $_SERVER['REMOTE_ADDR'];
+ $curl = curl_init('http://api-verify.recaptcha.net/verify?');
+ curl_setopt ($curl, CURLOPT_POST, 4);
+ curl_setopt ($curl, CURLOPT_POSTFIELDS, "privatekey=$this->recaptcha_privatekey&remoteip=$remoteip&challenge=$challenge&response=$response");
+ $result = curl_exec ($curl);
+ curl_close ($curl);
+ }
+
+}
+
+
+## now actually do something:
+switch (cms::determine_type()) {
+ case 'index':
+ $index = new index();
+ $index->display();
+ break;
+ case 'project':
+ $project = new project();
+ $project->display();
+ break;
+ case 'note':
+ $note = new note;
+ $note->display();
+ break;
+ case 'page':
+ $page = new page;
+ $page->display();
+ break;
+ case 'archive':
+ $archive = new archive;
+ $archive->display();
+ break;
+ case "captcha":
+ $captcha = new captcha;
+ $captcha->display();
+ break;
+}