Merge branch 'dev' of dl:dylansserver into dev
authorDylan Lloyd <dylan@miniscule>
Wed, 27 Jun 2012 06:37:54 +0000 (02:37 -0400)
committerDylan Lloyd <dylan@miniscule>
Wed, 27 Jun 2012 06:37:54 +0000 (02:37 -0400)
model/archive.php
model/index.php
model/model.php
model/note.php
model/page.php
model/rss.php
view/archive.php
view/index.php
view/page.php
view/rss.php

index 0f805d4..d0947c4 100644 (file)
@@ -2,6 +2,8 @@
 
 class archive extends model {
 
+  public $notes = array();
+
   public function __construct() {
     parent::__construct();
   }
@@ -16,10 +18,11 @@ class archive extends model {
   }
 
   public function display() {
+      $this->fetch_notes();
       require_once("view/archive.php");
   }
 
-  public function display_notes() {
+  public function fetch_notes() {
     switch (true) {
       case (isset($_GET['year']) && !isset($_GET['month'])
                 && !isset($_GET['day'])):
@@ -50,28 +53,14 @@ class archive extends model {
                                 $_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>";
-    } else {
-      echo "<br>";
-      echo "<h1>sorry, nothing here</h2>";
-      echo "<pre>Empty set (0.00 sec)</pre>";
+    foreach ($result as $row => $entry) {
+      $entry['url'] = '/note/' . $entry['url'];
+      $date_posted = explode("-", $entry['date_posted']);
+      $entry['year_posted'] = $date_posted[0];
+      $entry['month_posted'] = $date_posted[1];
+      $entry['datetime_posted'] = explode(' ', $date_posted[2]);
+      $entry['day_posted'] = $entry['date_posted'][0];
+      $this->notes[$row] = $entry;
     }
   }
 
index dc8f6b3..f649ecc 100644 (file)
@@ -2,25 +2,32 @@
 
 class index extends model {
 
+  public $exhibits = array();
+  public $projects = array();
+
+  public function __construct() {
+      parent::__construct();
+      $this->fetch_exhibits();
+      $this->fetch_projects();
+  }
+
   public function display() {
       require_once("view/index.php");
   }
 
-  public function display_exhibits() {
-    echo "<div id='exhibit'>";
+  private function fetch_exhibits() {
     $sql = "SELECT text FROM projects ORDER BY rank";
     $result = $this->db->query($sql);
     while ($entry = $result->fetch_object()) {
-      echo $entry->text;
+      $this->exhibits[] = $entry->text;
     }
-    echo "</div>";
   }
 
-  public function list_projects() {
+  private function fetch_projects() {
     $sql = "SELECT title FROM projects ORDER BY rank";
     $result = $this->db->query($sql);
     while ($entry = $result->fetch_object()) {
-      echo "<li><a class='tab' href='$entry->title'>$entry->title</a></li>";
+        $this->projects[] = $entry->title;
     }
   }
 
index f9bb164..9088831 100644 (file)
@@ -31,7 +31,7 @@ class model {
     $args = func_get_args();
     $statement = $this->db->prepare($args[0]);
     $args = array_slice($args, 1);
-    call_user_func_array(array($statement, 'bind_param'), &$args);
+    call_user_func_array(array($statement, 'bind_param'), $args);
     $statement->execute();
     $return = array();
     $statement->store_result();
index 01338be..8e863f1 100644 (file)
@@ -12,6 +12,7 @@ class note extends model {
   public $day_posted;
   public $text;
   public $number_of_comments;
+  public $comments;
 
   public function __construct() {
     parent::__construct();
@@ -23,6 +24,11 @@ class note extends model {
       $url = substr($url, 0, (strlen($url)-6));
     }
     $this->url = $url;
+    $this->fetch_note();
+    $this->fetch_comments();
+  }
+
+  public function fetch_note() {
     $sql = "SELECT title, date_posted, text, id
               FROM notes WHERE url = ?";
     $result = $this->query($sql, "s",
@@ -40,6 +46,9 @@ class note extends model {
     } else {
       throw new notFound();
     }
+  }
+
+  public function fetch_comments() {
     $sql = "SELECT COUNT(*) FROM comments
               WHERE note = $this->id";
     $result = $this->db->query($sql);
@@ -54,6 +63,40 @@ class note extends model {
       require_once("view/note.php");
   }
 
+  public 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>";
+  }
+
+  public function display_comments() {
+    $sql= "SELECT date_posted, author, text
+             FROM comments WHERE note = ?
+             ORDER BY date_posted DESC";
+    $result = $this->query($sql, 'd', $this->id);
+    $i = 0;
+    foreach ($result as $row => $entry) {
+      $this->comment[$i]['date_posted'] = $entry['date_posted'];
+      $this->comment[$i]['author']  = $entry['author'];
+      $this->comment[$i]['text'] = htmlspecialchars($entry['text']);
+      $this->comment[$i]['head'] = "<h3>" . htmlspecialchars($author) . "</h3>";
+      $i++;
+    }
+  }
+
+  public function display_comment_form() {
+    $publickey = $this->recaptcha_publickey;
+    require_once("view/comment-form.php");
+  }
+
   public function verify() {
     if (!isset($_POST['captcha'])) {
       require_once('includes/recaptchalib.php');
@@ -82,43 +125,6 @@ class note extends model {
     }
   }
 
-  public 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>";
-  }
-
-  public 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>" . htmlspecialchars($author) . "</h3>";
-      echo "<div class='comment'>";
-      echo $head;
-      echo $text;
-      echo "</div>";
-      }
-    echo "</div>";
-  }
-
-  public function display_comment_form() {
-    $publickey = $this->recaptcha_publickey;
-    require_once("view/comment-form.php");
-  }
 }
 
 ?>
index fe7d0a6..b4c5577 100644 (file)
@@ -6,10 +6,12 @@ class page extends model {
   public $offset = 0;
   public $notes_per_page = 4;
   public $number_of_pages = 1;
+  public $notes = array();
 
   public function __construct() {
     parent::__construct();
     $this->page_offset();
+    $this->fetch_notes();
   }
 
   private function page_offset() {
@@ -35,8 +37,7 @@ class page extends model {
       require_once("view/page.php");
   }
 
-  public function display_notes() {
-    echo "<div id='notes'>";
+  protected function fetch_notes() {
     $sql = "SELECT date_posted, title, url, text
               FROM notes ORDER BY date_posted DESC
               LIMIT ?, ?";
@@ -44,24 +45,14 @@ class page extends model {
                               $this->offset,
                               $this->notes_per_page);
     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];
-      $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;
+      $entry['url'] = '/note/' . $entry['url'];
+      $date_posted = explode("-", $entry['date_posted']);
+      $entry['year_posted'] = $date_posted[0];
+      $entry['month_posted'] = $date_posted[1];
+      $entry['datetime_posted'] = explode(' ', $date_posted[2]);
+      $entry['day_posted'] = $entry['date_posted'][0];
+      $this->notes[$row] = $entry;
     }
-    echo "</div>";
   }
 }
 
index b7c5164..a169ead 100644 (file)
@@ -2,35 +2,32 @@
 
 class rss extends model {
 
+  public $items = array();
+
   public function display() {
+    $this->fetch_items();
     require_once("view/rss.php");
   }
 
-  public function display_items() {
+  public function fetch_items() {
     $result = $this->db->query("SELECT date_posted, title, text, url
                                          FROM notes ORDER BY date_posted DESC
                                          LIMIT 5");
        while ($entry = $result->fetch_object()) {
-         $title = $entry->title;
-         $date_posted = $entry->date_posted;
-         $url = "http://dylansserver.com/note/" . $entry->url;
-         $text = $entry->text;
-         $text = strip_tags($text);
-         $end_of_first_sentence = strpos($text, '.');
+         $entry->url = "http://dylansserver.com/note/" . $entry->url;
+         $entry->text = strip_tags($entry->text);
+         $end_of_first_sentence = strpos($entry->text, '.');
          if ($end_of_first_sentence) {
-           $end_of_second_sentence = strpos($text, '.', ($end_of_first_sentence + 1));
+           $end_of_second_sentence = strpos($entry->text, '.', ($end_of_first_sentence + 1));
                if ($end_of_second_sentence) {
-                 $description = substr($text, '0', ($end_of_second_sentence + 1));
+                 $entry->description = substr($entry->text, '0', ($end_of_second_sentence + 1));
                } else {
-                 $description = substr($text, '0', ($end_of_first_sentence + 1));
+                 $entry->description = substr($entry->text, '0', ($end_of_first_sentence + 1));
                }
+        foreach ($entry as $key => $val) {
+          $this->items[][$key] = $entry->$key;
+        }
          }
-      echo "<item>";
-      echo "  <title>$title</title>";
-      echo "  <link>$url</link>";
-      echo "  <guid>$url</guid>";
-      echo "  <description>$description</description>";
-      echo "</item>";
        }
   }
 }
index 2829668..073c65f 100644 (file)
 
     <div id="content">
       <div id='notes'>
-        <?php $this->display_notes() ?>
-    <div id='navigation'>
-    <h1>
-    <?php
-    if($this->page > 1){
-      $previous_page = $this->page - 1;
-      echo "<a href='/notes/page/$previous_page'>prev</a>";
-    }
-    if($this->page < $this->number_of_pages) {
-    $forward_page = $this->page + 1;
-    echo " <a href='/notes/page/$forward_page'>next</a>";
-    } ?>
-    </h1>
-    </div>
+        <?php
+          if (count($this->notes) >= 1) {
+            foreach ($this->notes as $note) {
+              echo "<div class='note'>";
+              echo "<h1><span class='date'>";
+              echo $note['year_posted'] . "/";
+              echo $note['month_posted'] . "/";
+              echo $note['day_posted'] . "/";
+              echo "</span><a href='" . $note['url'] . "'>";
+              echo $note['title'] . "</a></h1>";
+              echo $note['text'];
+              echo "</div>";
+            }
+          } else {
+            echo "<br>";
+            echo "<h1>sorry, nothing here</h2>";
+            echo "<pre>Empty set (0.00 sec)</pre>";
+          }
+        ?>
+      </div>
       <div id="contact_me"><h1><a href=
       "mailto:dylan@psu.edu">dylan</a></h1><a href=
       "mailto:dylan@psu.edu">@psu.edu</a>
index fb2ed19..2f9b0c9 100644 (file)
       border="0"></a>
     </div>
     <div id="content">
-      <?php $this->display_exhibits() ?>
+      <div id='exhibit'>
+        <?php
+          foreach ($this->exhibits as $exhibit) {
+            echo $exhibit;
+          }
+        ?>
+      </div>
       <ul id="portfolio">
         <li>
            <h3>my projects:</h3>
         </li>
-        <?php $this->list_projects() ?>
+        <?php
+          foreach ($this->projects as $project => $title) {
+              echo "<li><a class='tab' href='$title'>$title</a></li>";
+          }
+        ?>
         <li>
           <h3>things i've done for others:</h3>
         </li>
index 2829668..72d5edd 100644 (file)
     </div>
 
     <div id="content">
-      <div id='notes'>
-        <?php $this->display_notes() ?>
+      <div id="notes">
+        <div id="notes">
+        <?php
+          foreach ($this->notes as $note) {
+            echo "<div class='note'>";
+            echo "<h1>";
+            echo "<span class='date'>";
+            echo $note['year_posted'] . "/";
+            echo $note['month_posted'] . "/";
+            echo $note['day_posted'] . "/";
+            echo "</span>";
+            echo "<a href='" . $note['url'] . "'>";
+            echo $note['title'];
+            echo "</a>";
+            echo "</h1>";
+            echo $note['text'];
+          }
+        ?>
+      </div>
     <div id='navigation'>
     <h1>
     <?php
index 2f55ca3..7d0c60c 100644 (file)
@@ -4,6 +4,15 @@
     <link>http://dylansserver.com/notes</link>
     <description>dylansserver.com/notes/rss</description>
     <atom:link href="http://dylansserver.com/notes/rss" rel="self" type="application/rss+xml" />
-    <?php $this->display_items() ?>
+    <?php
+      foreach ($this->items as $item) {
+        echo "<item>";
+        echo "  <title>" . $item['title'] . "</title>";
+        echo "  <link>" . $item['url'] . "</link>";
+        echo "  <guid>" . $item['url'] . "</guid>";
+        echo "  <description>" . $item['description'] . "</description>";
+        echo "</item>";
+      }
+    ?>
   </channel>
 </rss>