Merge branch 'live' into dev
[dylansserver.git] / index.php
index bbd2254..de27473 100644 (file)
--- a/index.php
+++ b/index.php
@@ -2,10 +2,11 @@
 
 abstract class cms {
 
-  private $config_file = '/etc/dylanstestserver.ini';
+  private $config_file = '/etc/dylansserver.ini';
   protected $db;
   protected $recaptcha_publickey;
   protected $recaptcha_privatekey;
+  protected  $scripts;
   public $title;
   public $home_link;
 
@@ -69,19 +70,11 @@ abstract class cms {
     return $return;
       }
 
-  public function display_head($title = "dylanstestserver",
+  public function display_head($title = "dylansserver",
                                   $home_link = "/") {
-    $scripts = "";
+    $scripts = $this->scripts;
     $stylesheets = "<link href='/includes/style.css' rel='stylesheet' type='text/css'>";
-    if (cms::determine_type() == "index") {
-      $scripts = "<script type='text/javascript' src='/includes/all.js'></script>"; 
-      $home_link = "http://validator.w3.org/unicorn/check?ucn_uri=dylanstestserver.com&amp;ucn_task=conformance#";
-    } else if ($this->determine_type() == 'note') {
-      $scripts = "<script type='text/javascript' src='http://www.google.com/recaptcha/api/js/recaptcha_ajax.js'></script>";
-      $scripts .= "<script type='text/javascript' src='/includes/jquery-core.js'></script>";
-      $scripts .= "<script type='text/javascript' src='/includes/jquery-all-components.js'></script>";
-      $scripts .= "<script type='text/javascript' src='/includes/ajax.js'></script>";
-    }
+    $home_link = "http://validator.w3.org/unicorn/check?ucn_uri=dylansserver.com&amp;ucn_task=conformance#";
     echo <<<END_OF_HEAD
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
@@ -93,7 +86,7 @@ abstract class cms {
   <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
 
   <title>$this->title</title>
-  <link rel="icon" href="favicon.ico" type="image/png">
+  <link rel="icon" href="/favicon.ico" type="image/png">
   $stylesheets
   $scripts
 </head>
@@ -102,7 +95,7 @@ abstract class cms {
   <div id="structure">
     <div id="banner">
       <a href="$this->home_link">
-      <img src="/images/dylanstestserver.png" alt="dylanstestserver"
+      <img src="/images/dylansserver.png" alt="dylansserver"
       border="0"></a>
     </div>
 
@@ -140,6 +133,7 @@ END_OF_CLOSE;
 class index extends cms {
 
   public function display() {
+    $this->scripts = "<script type='text/javascript' src='/includes/index.js'></script>"; 
     $this->display_head();
     $this->display_exhibits();
     echo "<ul id='portfolio' style='text-align:right'>";
@@ -167,7 +161,7 @@ class index extends cms {
         </li>
 
         <li><a href=
-        "git">git://dylanstestserver.com</a></li>
+        "git">git://dylansserver.com</a></li>
 
         <li>
           <h3>some notes:</h3>
@@ -182,21 +176,21 @@ OTHER_PROJECTS;
     // Because of the CSS necessary for the animations,
     // the contact link needs to be in #portfolio to clear
     // the floats.
-       echo "<li>";
+    echo "<li>";
     $this->display_contact();
-       echo "</li>";
+    echo "</li>";
     echo "</ul>";
     $this->display_close($show_contact = false);
   }
 
   protected function display_exhibits() {
+    echo "<div id='exhibit'>";
     $sql = "SELECT text FROM projects";
     $result = $this->db->query($sql);
     while ($entry = $result->fetch_object()) {
-      echo "<div class='exhibit'>";
       echo $entry->text;
-      echo "</div>";
     }
+    echo "</div>";
   }
 
   private function list_projects() {
@@ -282,10 +276,15 @@ class page extends cms {
       $month_posted = $date_posted[1];
       $datetime_posted = explode(' ', $date_posted[2]);
       $day_posted = $datetime_posted[0];
-      echo "<div class='note'>";
-      echo "<h2><span style='color:grey;'>$year_posted/$month_posted/$day_posted/</span><a href='$url'>$title</a></h2>";
-      echo $entry['text'];
-      echo "</div>";
+      $text = $entry['text'];
+      echo <<<END_NOTE
+      <div class='note'>
+      <h1>
+        <span class='date'>$year_posted/$month_posted/$day_posted/</span><a rel="canonical" href='$url'>$title</a>
+      </h1>
+      $text
+      </div>
+END_NOTE;
     }
     echo "</div>";
     $this->write_navigation();
@@ -294,7 +293,7 @@ class page extends cms {
 
   private function write_navigation() {
     echo "<div id='navigation'>";
-    echo "<h2>";
+    echo "<h1>";
     if($this->page > 1){
       $previous_page = $this->page - 1;
       echo "<a href='/notes/page/$previous_page'>prev</a>";
@@ -303,7 +302,7 @@ class page extends cms {
     $forward_page = $this->page + 1;
     echo " <a href='/notes/page/$forward_page'>next</a>";
     }
-    echo "</h2>";
+    echo "</h1>";
     echo "</div>";
   }
 
@@ -324,6 +323,11 @@ class note extends cms {
   public $number_of_comments;
 
   public function __construct() {
+    if (isset($_GET['comments'])) {
+      $this->scripts = "
+        <script type='text/javascript' src='http://www.google.com/recaptcha/api/js/recaptcha_ajax.js'></script>
+        <script type='text/javascript' src='/includes/comment.js'></script>";
+    }
     parent::__construct();
     if (isset($_GET['comments'])) {
       $this->comments_enabled = true;
@@ -385,15 +389,14 @@ class note extends cms {
     }
     if (isset($_POST['captcha']) || $resp->is_valid) {
       $sql = ("INSERT INTO comments (date_posted, author,
-                  email, text, note)
-                VALUES(NOW(), ?, ?, ?, ?)");
+                  text, note)
+                VALUES(NOW(), ?, ?, ?)");
       $stmt = $this->db->prepare($sql);
       // Checks are needed here (no blank text,
-      // and a default author / email need to be set
+      // and a default author needs to be set
       // for no-javascript users.
-      $stmt->bind_param('ssss',
+      $stmt->bind_param('sss',
                           htmlspecialchars($_POST['name']),
-                          htmlspecialchars($_POST['email']),
                           htmlspecialchars($_POST['text']),
                         $this->id);
       $stmt->execute();
@@ -403,7 +406,7 @@ class note extends cms {
   private function display_note() {
     echo <<<END_OF_NOTE
     <div id='note'>
-    <h2><span style='color:grey;'>$this->year_posted/$this->month_posted/$this->day_posted/</span>$this->title</h2>
+    <h1><span class='date'>$this->year_posted/$this->month_posted/$this->day_posted/</span>$this->title</h1>
     $this->text
     </div>
 END_OF_NOTE;
@@ -413,14 +416,14 @@ END_OF_NOTE;
     echo <<<END_OF_NAVIGATION
     <br>
     <div id='navigation'>
-    <h2>
+    <h1>
 END_OF_NAVIGATION;
     if (!$this->comments_enabled) {
       $this->display_comment_link();
     }
     echo <<<END_OF_NAVIGATION
     <a href="/notes/">back to notes</a>/
-    </h2>
+    </h1>
     </div>
 END_OF_NAVIGATION;
   }
@@ -441,15 +444,15 @@ END_OF_NAVIGATION;
 
   private function display_comments() {
     echo "<div id='comments'>";
-    $sql= "SELECT date_posted, author, email, text
+    $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'];
-      $email = $entry['email'];
       $text = htmlspecialchars($entry['text']);
+      $head = "<h3>$author</h3>";
       echo <<<END_OF_COMMENT
       <div class='comment'>
       $head
@@ -482,8 +485,6 @@ END_CAPTCHA_STYLE;
       <textarea rows="10" cols="70" name="text" id="comment_text"></textarea>
       <h3>name:</h3>
       <input type=text name="name" id="comment_name">
-      <h3>email:</h3>
-      <input type=text name="email" id="comment_email"><br>
   
       <nowiki>
       <div id="recaptcha_widget"> 
@@ -492,7 +493,7 @@ END_CAPTCHA_STYLE;
         <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')">Get an image CAPTCHA</a></span><a href="javascript:Recaptcha.showhelp()">help</a> )
+          <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" />
@@ -505,19 +506,31 @@ END_CAPTCHA_STYLE;
 END_OF_FORM;
     echo recaptcha_get_html($this->recaptcha_publickey); 
     if ($this->failed_captcha) {
-    echo <<<END_OF_FORM
-        <span style='font-weight:bold;font-family:sans-serif;color:red;margin-top:15px;'>reCAPTCHA said you're not human,</span>
-        <input id="submit" class="submit" type="submit" value="try again?">
+    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_FORM;
+END_OF_ERRORS;
     } else {
-      echo <<<END_OF_FORM
+      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;
-    }
   }
 }
 
@@ -565,7 +578,7 @@ class archive extends cms {
                 AND DAY(date_posted) = ?
                 ORDER BY date_posted DESC";
         $result = $this->query($sql, "ddd",
-                                  $_GET['year'], $_GET['month'],
+                                $_GET['year'], $_GET['month'],
                                 $_GET['day']);
         break;
     }
@@ -580,9 +593,9 @@ class archive extends cms {
         $datetime_posted = explode(' ', $date_posted[2]);
         $day_posted = $datetime_posted[0];
         echo "<div class='note'>";
-        echo "<h2><span style='color:grey;'>";
-               echo "$year_posted/$month_posted/$day_posted/";
-               echo "</span><a href='$url'>$title</a></h2>";
+        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>";
       }
@@ -590,7 +603,7 @@ class archive extends cms {
       $this->write_navigation();
     } else {
       echo "<br>";
-      echo "<h2 style='font-family:sans-serif;'>sorry, nothing here</h2>";
+      echo "<h1>sorry, nothing here</h2>";
       echo "<pre>Empty set (0.00 sec)</pre>";
     }
     $this->display_close();
@@ -599,9 +612,7 @@ class archive extends cms {
   private function write_navigation() {
     echo "<br>";
     echo "<div id='navigation'>";
-    echo "<h2>";
     // fill me in!
-    echo "</h2>";
     echo "</div>";
   }