rss layout now fully separated m/v/c
authorDylan Lloyd <dylan@dylansserver.com>
Sat, 24 Mar 2012 19:17:42 +0000 (15:17 -0400)
committerDylan Lloyd <dylan@dylansserver.com>
Sat, 24 Mar 2012 19:17:42 +0000 (15:17 -0400)
model/rss.php
view/rss.php

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 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>