rss now using model
[dylansserver.git] / cms.php
diff --git a/cms.php b/cms.php
index a3d9c3b..b5b3b20 100644 (file)
--- a/cms.php
+++ b/cms.php
@@ -89,12 +89,14 @@ 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":
+        require_once("model/rss.php");
         $rss = new rss();
-        $rss->display();
+        require_once("view/rss.php");
         break;
       case 'archive':
         $archive = new archive;
@@ -156,72 +158,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() {
@@ -300,42 +236,6 @@ class archive extends cms {
 }
 
 
-class rss extends cms {
-
-  public function display() {
-    require_once("view/rss.php");
-  }
-
-  public function display_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, '.');
-         if ($end_of_first_sentence) {
-           $end_of_second_sentence = strpos($text, '.', ($end_of_first_sentence + 1));
-               if ($end_of_second_sentence) {
-                 $description = substr($text, '0', ($end_of_second_sentence + 1));
-               } else {
-                 $description = substr($text, '0', ($end_of_first_sentence + 1));
-               }
-         }
-      echo "<item>";
-      echo "  <title>$title</title>";
-      echo "  <link>$url</link>";
-      echo "  <guid>$url</guid>";
-      echo "  <description>$description</description>";
-      echo "</item>";
-       }
-  }
-}
-
-
 class notFound extends Exception {
 
     public function __construct() {