X-Git-Url: https://disinclined.org/git/?a=blobdiff_plain;f=model%2Fnote.php;h=f0c54cbec01e9fbe7d17dcf04184e35107c0168b;hb=a3778d8897496a7b491b6e51b80f3b8d8598d232;hp=01338be29f03aec67d2537f68b94452abe5d2985;hpb=4db3a80e869ec8b8c3e0c3f8401c8df12ff5c553;p=dylansserver.git diff --git a/model/note.php b/model/note.php index 01338be..f0c54cb 100644 --- a/model/note.php +++ b/model/note.php @@ -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 "$anchor_text"; + } + + 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'] = htmlspecialchars($entry['author']); + $this->comment[$i]['text'] = htmlspecialchars($entry['text']); + $i++; + } + require_once('view/comment.php'); + } + + 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 "$anchor_text"; - } - - public function display_comments() { - echo "
"; - $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 = "

" . htmlspecialchars($author) . "

"; - echo "
"; - echo $head; - echo $text; - echo "
"; - } - echo "
"; - } - - public function display_comment_form() { - $publickey = $this->recaptcha_publickey; - require_once("view/comment-form.php"); - } } ?>