X-Git-Url: https://disinclined.org/git/?a=blobdiff_plain;ds=sidebyside;f=index.php;h=bf2249bfd14920d5550c47184bd62ba7bcd57499;hb=60e2ac52bbf649d4b04f91bc731672a94c4373a8;hp=7feaa03f350727c58baeed4edf7c45538ab7bf32;hpb=9da61e74c9ee47a13e7e5d13ab951429d51e8629;p=dylansserver.git diff --git a/index.php b/index.php index 7feaa03..bf2249b 100644 --- a/index.php +++ b/index.php @@ -2,20 +2,21 @@ abstract class cms { - private $config_file = '/etc/dylanstestserver.ini'; + private $config_file = '/etc/dylansserver.ini'; protected $db; protected $recaptcha_publickey; protected $recaptcha_privatekey; + protected $scripts; public $title; public $home_link; public function __construct() { $config = parse_ini_file($this->config_file, true); $this->db = new mysqli( - $config[database]['domain'], - $config[database]['user'], - $config[database]['password'], - $config[database]['database']); + $config['database']['domain'], + $config['database']['user'], + $config['database']['password'], + $config['database']['database']); if (mysqli_connect_errno()) { echo "Problem connecting to database: "; echo mysqli_connect_error(); @@ -39,7 +40,9 @@ abstract class cms { return 'index'; } else if (isset($_GET['project'])) { return 'project'; - } else if (isset($_GET['challenge'])) { + } else if (isset($_GET['rss'])) { + return 'rss'; + } else if (isset($_GET['challenge'])) { return 'captcha'; } } @@ -69,19 +72,11 @@ abstract class cms { return $return; } - public function display_head($title = "dylanstestserver", + public function display_head($title = "dylansserver", $home_link = "/") { - $scripts = ""; + $scripts = $this->scripts; $stylesheets = ""; - if (cms::determine_type() == "index") { - $scripts = ""; - $home_link = "http://validator.w3.org/unicorn/check?ucn_uri=dylanstestserver.com&ucn_task=conformance#"; - } else if ($this->determine_type() == 'note') { - $scripts = ""; - $scripts .= ""; - $scripts .= ""; - $scripts .= ""; - } + $home_link = "http://validator.w3.org/unicorn/check?ucn_uri=dylansserver.com&ucn_task=conformance#"; echo << @@ -93,16 +88,16 @@ abstract class cms { $this->title - + $stylesheets $scripts - + - @@ -140,9 +135,10 @@ END_OF_CLOSE; class index extends cms { public function display() { + $this->scripts = ""; $this->display_head(); $this->display_exhibits(); - echo ""; + echo ""; $this->list_projects(); echo << @@ -167,14 +163,21 @@ class index extends cms { git://dylanstestserver.com + "/git/">git://dylansserver.com some notes: here + "/notes/">here [rss] + + + my resume: + + + [pdf] @@ -190,13 +193,13 @@ OTHER_PROJECTS; } protected function display_exhibits() { - $sql = "SELECT text FROM projects"; + echo ""; + $sql = "SELECT text FROM projects ORDER BY rank"; $result = $this->db->query($sql); while ($entry = $result->fetch_object()) { - echo ""; echo $entry->text; - echo ""; } + echo ""; } private function list_projects() { @@ -205,7 +208,7 @@ OTHER_PROJECTS; my projects: HEREDOC; - $sql = "SELECT title FROM projects"; + $sql = "SELECT title FROM projects ORDER BY rank"; $result = $this->db->query($sql); while ($entry = $result->fetch_object()) { echo "$entry->title"; @@ -244,6 +247,24 @@ class page extends cms { public function __construct() { parent::__construct(); $this->page_offset(); + $this->scripts = " + + + + + + "; } private function page_offset() { @@ -282,10 +303,15 @@ class page extends cms { $month_posted = $date_posted[1]; $datetime_posted = explode(' ', $date_posted[2]); $day_posted = $datetime_posted[0]; - echo ""; - echo "$year_posted/$month_posted/$day_posted/$title"; - echo $entry['text']; - echo ""; + $text = $entry['text']; + echo << + + $year_posted/$month_posted/$day_posted/$title + + $text + +END_NOTE; } echo ""; $this->write_navigation(); @@ -294,7 +320,7 @@ class page extends cms { private function write_navigation() { echo ""; - echo ""; + echo ""; if($this->page > 1){ $previous_page = $this->page - 1; echo "prev"; @@ -303,7 +329,7 @@ class page extends cms { $forward_page = $this->page + 1; echo " next"; } - echo ""; + echo ""; echo ""; } @@ -324,6 +350,30 @@ class note extends cms { public $number_of_comments; public function __construct() { + $this->scripts = " + + + + + + "; + + if (isset($_GET['comments'])) { + $this->scripts .= " + + "; + } parent::__construct(); if (isset($_GET['comments'])) { $this->comments_enabled = true; @@ -385,16 +435,15 @@ class note extends cms { } if (isset($_POST['captcha']) || $resp->is_valid) { $sql = ("INSERT INTO comments (date_posted, author, - email, text, note) - VALUES(NOW(), ?, ?, ?, ?)"); + text, note) + VALUES(NOW(), ?, ?, ?)"); $stmt = $this->db->prepare($sql); // Checks are needed here (no blank text, - // and a default author / email need to be set + // and a default author needs to be set // for no-javascript users. - $stmt->bind_param('ssss', - htmlspecialchars($_POST['name']), - htmlspecialchars($_POST['email']), - htmlspecialchars($_POST['text']), + $stmt->bind_param('sss', + $_POST['name'], + $_POST['text'], $this->id); $stmt->execute(); } @@ -403,7 +452,7 @@ class note extends cms { private function display_note() { echo << - $this->year_posted/$this->month_posted/$this->day_posted/$this->title + $this->year_posted/$this->month_posted/$this->day_posted/$this->title $this->text END_OF_NOTE; @@ -411,16 +460,16 @@ END_OF_NOTE; private function write_navigation() { echo << + - + END_OF_NAVIGATION; if (!$this->comments_enabled) { $this->display_comment_link(); } echo <<back to notes/ - + back to notes/ + END_OF_NAVIGATION; } @@ -441,20 +490,15 @@ END_OF_NAVIGATION; private function display_comments() { echo ""; - $sql= "SELECT date_posted, author, email, text + $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']; - $email = $entry['email']; $text = htmlspecialchars($entry['text']); - if ($email == '') { - $head = "$author"; - } else { - $head = "$author"; - } + $head = "" . htmlspecialchars($author) . ""; echo << $head @@ -487,42 +531,52 @@ END_CAPTCHA_STYLE; name: - email: - - what's this say? - enter the numbers you hear: - - ( another / - audio / - Get an image CAPTCHAhelp ) - - + + what's this say? + + + + - - - - + enter the numbers you hear: + + another? / + audio? / + image?help? + END_OF_FORM; echo recaptcha_get_html($this->recaptcha_publickey); if ($this->failed_captcha) { - echo <<reCAPTCHA said you're not human, - + echo << + reCAPTCHA said you're not human, + try again? + + -END_OF_FORM; +END_OF_ERRORS; } else { - echo << + reCAPTCHA said you're not human, + try again? + + + but you didn't write anything! + +END_OF_ERRORS; + } + echo << END_OF_FORM; - } } } @@ -585,9 +639,9 @@ class archive extends cms { $datetime_posted = explode(' ', $date_posted[2]); $day_posted = $datetime_posted[0]; echo ""; - echo ""; + echo ""; echo "$year_posted/$month_posted/$day_posted/"; - echo "$title"; + echo "$title"; echo $entry['text']; echo ""; } @@ -595,7 +649,7 @@ class archive extends cms { $this->write_navigation(); } else { echo ""; - echo "sorry, nothing here"; + echo "sorry, nothing here"; echo "Empty set (0.00 sec)"; } $this->display_close(); @@ -604,15 +658,57 @@ class archive extends cms { private function write_navigation() { echo ""; echo ""; - echo ""; // fill me in! - echo ""; echo ""; } } +class rss extends cms { + public function display() { + $result = $this->db->query("SELECT date_posted, title, text, url + FROM notes ORDER BY date_posted DESC + LIMIT 5"); + echo << + + dylansserver.com/notes/rss + http://dylansserver.com/notes + dylansserver.com/notes/rss + +END_OF_ENTRY; + 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 << + $title + $url + $url + $description + +END_OF_ENTRY; + } + echo ""; + echo ""; + + } +} + + class notFound extends Exception { public function __construct() { @@ -659,10 +755,14 @@ switch (cms::determine_type()) { $page = new page; $page->display(); break; + case "rss": + $rss = new rss(); + $rss->display(); + break; case 'archive': $archive = new archive; - $archive->display(); - break; + $archive->display(); + break; case "captcha": $captcha = new captcha; $captcha->display();
Empty set (0.00 sec)
$author
"; - } else { - $head = "$author
"; - } + $head = "" . htmlspecialchars($author) . "
"; echo <<name:
-email:
-what's this say?
-enter the numbers you hear:
- - ( another / - audio / - Get an image CAPTCHAhelp ) - -+
+
what's this say?
++ +
+
-
+
enter the numbers you hear:
+ + another? / + audio? / + image?help? ++ try again? +