From: Dylan Lloyd Date: Wed, 27 Jun 2012 06:37:54 +0000 (-0400) Subject: Merge branch 'dev' of dl:dylansserver into dev X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=08d7e1f799b17025cc1066b1e9b09e1b44c66a67;hp=28796396207c68c3962544b0a32742d324bf0c67;p=dylansserver.git Merge branch 'dev' of dl:dylansserver into dev --- diff --git a/model/archive.php b/model/archive.php index 0f805d4..d0947c4 100644 --- a/model/archive.php +++ b/model/archive.php @@ -2,6 +2,8 @@ class archive extends model { + public $notes = array(); + public function __construct() { parent::__construct(); } @@ -16,10 +18,11 @@ class archive extends model { } 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'])): @@ -50,28 +53,14 @@ class archive extends model { $_GET['day']); break; } - if (count($result) >= 1) { - echo "
"; - 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 "
"; - echo "

"; - echo "$year_posted/$month_posted/$day_posted/"; - echo "$title

"; - echo $entry['text']; - echo "
"; - } - echo "
"; - } else { - echo "
"; - echo "

sorry, nothing here

"; - echo "
Empty set (0.00 sec)
"; + 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; } } diff --git a/model/index.php b/model/index.php index dc8f6b3..f649ecc 100644 --- a/model/index.php +++ b/model/index.php @@ -2,25 +2,32 @@ 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 "
"; + 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 "
"; } - 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 "
  • $entry->title
  • "; + $this->projects[] = $entry->title; } } diff --git a/model/model.php b/model/model.php index f9bb164..9088831 100644 --- a/model/model.php +++ b/model/model.php @@ -31,7 +31,7 @@ class model { $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(); diff --git a/model/note.php b/model/note.php index 01338be..8e863f1 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'] = $entry['author']; + $this->comment[$i]['text'] = htmlspecialchars($entry['text']); + $this->comment[$i]['head'] = "

    " . htmlspecialchars($author) . "

    "; + $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'); @@ -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"); - } } ?> diff --git a/model/page.php b/model/page.php index fe7d0a6..b4c5577 100644 --- a/model/page.php +++ b/model/page.php @@ -6,10 +6,12 @@ class page extends model { 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() { @@ -35,8 +37,7 @@ class page extends model { require_once("view/page.php"); } - public function display_notes() { - echo "
    "; + protected function fetch_notes() { $sql = "SELECT date_posted, title, url, text FROM notes ORDER BY date_posted DESC LIMIT ?, ?"; @@ -44,24 +45,14 @@ class page extends model { $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 << -

    - $year_posted/$month_posted/$day_posted/$title -

    - $text -
    -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 ""; } } diff --git a/model/rss.php b/model/rss.php index b7c5164..a169ead 100644 --- a/model/rss.php +++ b/model/rss.php @@ -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 ""; - echo " $title"; - echo " $url"; - echo " $url"; - echo " $description"; - echo ""; } } } diff --git a/view/archive.php b/view/archive.php index 2829668..073c65f 100644 --- a/view/archive.php +++ b/view/archive.php @@ -36,20 +36,26 @@
    - display_notes() ?> - + notes) >= 1) { + foreach ($this->notes as $note) { + echo "
    "; + echo "

    "; + echo $note['year_posted'] . "/"; + echo $note['month_posted'] . "/"; + echo $note['day_posted'] . "/"; + echo ""; + echo $note['title'] . "

    "; + echo $note['text']; + echo "
    "; + } + } else { + echo "
    "; + echo "

    sorry, nothing here

    "; + echo "
    Empty set (0.00 sec)
    "; + } + ?> +

    dylan

    @psu.edu diff --git a/view/index.php b/view/index.php index fb2ed19..2f9b0c9 100644 --- a/view/index.php +++ b/view/index.php @@ -34,12 +34,22 @@ border="0">
    - display_exhibits() ?> +
    + exhibits as $exhibit) { + echo $exhibit; + } + ?> +
    • my projects:

    • - list_projects() ?> + projects as $project => $title) { + echo "
    • $title
    • "; + } + ?>
    • things i've done for others:

    • diff --git a/view/page.php b/view/page.php index 2829668..72d5edd 100644 --- a/view/page.php +++ b/view/page.php @@ -35,8 +35,25 @@
    -
    - display_notes() ?> +
    +
    + notes as $note) { + echo "
    "; + echo "

    "; + echo ""; + echo $note['year_posted'] . "/"; + echo $note['month_posted'] . "/"; + echo $note['day_posted'] . "/"; + echo ""; + echo ""; + echo $note['title']; + echo ""; + echo "

    "; + echo $note['text']; + } + ?> +