class archive extends model {
+ public $notes = array();
+
public function __construct() {
parent::__construct();
}
}
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'])):
$_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;
}
}
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;
}
}
$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();
public $day_posted;
public $text;
public $number_of_comments;
+ public $comments;
public function __construct() {
parent::__construct();
$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",
} else {
throw new notFound();
}
+ }
+
+ public function fetch_comments() {
$sql = "SELECT COUNT(*) FROM comments
WHERE note = $this->id";
$result = $this->db->query($sql);
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');
}
}
- 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");
- }
}
?>
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() {
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 ?, ?";
$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>";
}
}
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>";
}
}
}
<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>
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>
</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
<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>