page now using model
authorDylan Lloyd <dylan@dylansserver.com>
Fri, 23 Mar 2012 08:52:37 +0000 (04:52 -0400)
committerDylan Lloyd <dylan@dylansserver.com>
Fri, 23 Mar 2012 08:52:37 +0000 (04:52 -0400)
cms.php
view/page.php

diff --git a/cms.php b/cms.php
index a3d9c3b..428cae1 100644 (file)
--- a/cms.php
+++ b/cms.php
@@ -89,8 +89,9 @@ abstract class cms {
         require_once("view/note.php");
         break;
       case 'page':
-        $page = new page;
-        $page->display();
+        require_once("model/page.php");
+        $page = new page();
+        require_once("view/page.php");
         break;
       case "rss":
         $rss = new rss();
@@ -156,72 +157,6 @@ class project extends index {
 }
 
 
-class page extends cms {
-
-  private $page = 1;
-  private $offset = 0;
-  private $notes_per_page = 4;
-  private $number_of_pages = 1;
-
-  public function __construct() {
-    parent::__construct();
-    $this->page_offset();
-  }
-
-  private function page_offset() {
-    $sql = "SELECT COUNT(*) FROM notes";
-    $result = $this->db->query($sql);
-    $result = $result->fetch_array();
-    $this->number_of_pages = ceil($result[0] / $this->notes_per_page);
-    if (isset($_GET['page']) && is_numeric($_GET['page'])) {
-      $this->page = (int) $_GET['page'];
-    } else {
-      throw new notFound();
-    }
-    if ($this->page > $this->number_of_pages) {
-      throw new notFound();
-    }
-    if ($this->page < 1) {
-      throw new notFound();
-    }
-    $this->offset = ($this->page - 1) * $this->notes_per_page;
-  }
-
-  public function display() {
-      require_once("view/page.php");
-  }
-
-  public function display_notes() {
-    echo "<div id='notes'>";
-    $sql = "SELECT date_posted, title, url, text
-              FROM notes ORDER BY date_posted DESC
-              LIMIT ?, ?";
-    $result = $this->query($sql, "ii",
-                              $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;
-    }
-    echo "</div>";
-  }
-}
-
-
 class archive extends cms {
 
   public function __construct() {
index 2829668..8bba8ac 100644 (file)
@@ -3,7 +3,7 @@
 
 <html>
 <head>
-  <title><?php echo $this->title; ?></title>
+  <title><?php echo $page->title; ?></title>
   <link rel="icon" href="/favicon.ico" type="image/png">
   <link href='/includes/style.css' rel='stylesheet' type='text/css'>
   <script type='text/javascript' src='/includes/syntax/scripts/shCore.js'></script>
 <body onload="return typeof highlight == 'function' ? highlight() : true">
   <div id="structure">
     <div id="banner">
-      <a href="<?php echo $this->home_link ?>">
+      <a href="<?php echo $page->home_link ?>">
       <img src="/images/dylansserver.png" alt="dylansserver"
       border="0"></a>
     </div>
 
     <div id="content">
       <div id='notes'>
-        <?php $this->display_notes() ?>
+        <?php $page->display_notes() ?>
     <div id='navigation'>
     <h1>
     <?php
-    if($this->page > 1){
-      $previous_page = $this->page - 1;
+    if($page->page > 1){
+      $previous_page = $page->page - 1;
       echo "<a href='/notes/page/$previous_page'>prev</a>";
     }
-    if($this->page < $this->number_of_pages) {
-    $forward_page = $this->page + 1;
+    if($page->page < $page->number_of_pages) {
+    $forward_page = $page->page + 1;
     echo " <a href='/notes/page/$forward_page'>next</a>";
     } ?>
     </h1>