29e4076463cc821d8fdda546f037b2436c5c6adb
4 private $config_file = '/etc/dylanstestserver.ini';
7 public function __construct() {
8 $config = parse_ini_file($this->config_file
);
9 $this->db
= new mysqli(
14 if (mysqli_connect_errno()) {
15 echo "Problem connecting to database: ";
16 echo mysqli_connect_error();
22 public static function determine_type() {
23 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
25 } else if (isset($_GET['note'])) {
27 } else if ($_SERVER['REQUEST_URI'] == '/') {
29 } else if (isset($_GET['project'])) {
34 public function query() {
35 $args = func_get_args();
36 $statement = $this->db
->prepare($args[0]);
37 $args = array_slice($args, 1);
38 call_user_func_array(array($statement, 'bind_param'), &$args);
39 $statement->execute();
41 $statement->store_result();
43 $data = $statement->result_metadata();
45 $fields[0] = &$statement;
46 while($field = $data->fetch_field()) {
47 $fields[] = &$row[$field->name
];
49 call_user_func_array("mysqli_stmt_bind_result", $fields);
51 while ($statement->fetch()) {
52 foreach ($row as $key1=>$value1) $return[$i][$key1] = $value1;
55 $statement->free_result();
59 public function display_head($title = "dylanstestserver",
62 $stylesheets = "<link href=\"/includes/style.css\" rel=\"stylesheet\" type=\"text/css\">";
63 if (cms
::determine_type() == "index") {
64 $scripts = "<script type=\"text/javascript\" src=\"/includes/all.js\">";
65 $home_link = "http://validator.w3.org/unicorn/check?ucn_uri=dylanstestserver.com&ucn_task=conformance#";
68 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
69 "http://www.w3.org/TR/html4/loose.dtd">
73 <meta name="generator" content=
74 "HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
75 <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
78 <link rel="icon" href="favicon.ico" type="image/png">
88 <img src="/images/dylanstestserver.png" alt="dylanstestserver"
96 public function display_contact() {
97 echo <<<END_OF_CONTACT
98 <div id="contact_me"><h1><a href=
99 "mailto:dylan@psu.edu">dylan</a></h1><a href=
100 "mailto:dylan@psu.edu">@psu.edu</a>
105 public function display_close($show_contact = true) {
107 $this->display_contact();
122 class index extends cms {
123 public function display() {
124 $this->display_head();
125 $this->display_exhibits();
126 echo "<ul id=\"portfolio\" style=\"text-align:right\">";
127 $this->list_projects();
128 echo <<<OTHER_PROJECTS
130 <h3>things i've done for others:</h3>
134 "http://activehamptons.com">activehamptons.com</a></li>
137 "http://transfishing.com">transfishing.com</a></li>
140 <h3>something i've worked on:</h3>
144 "http://tempositions.com">tempositions.com</a></li>
147 <h3>my repositories:</h3>
151 "git">git://dylanstestserver.com</a></li>
158 "/notes/">here</a></li>
163 // Because of the CSS necessary for the animations,
164 // the contact link needs to be in #portfolio to clear
166 $this->display_contact();
168 $this->display_close($show_contact = false);
171 protected function display_exhibits() {
172 echo "<div id=\"exhibit\">";
173 $sql = "SELECT text FROM projects";
174 $result = $this->db->query($sql);
175 while ($entry = $result->fetch_object()) {
181 private function list_projects() {
182 echo "<div id=\"exhibit\">";
185 <h3>my projects:</h3>
188 $sql = "SELECT title FROM projects";
189 $result = $this->db->query($sql);
190 while ($entry = $result->fetch_object()) {
191 echo "<li><a class=\"tab\" href=\"$entry->title\">$entry->title</a></li>";
196 class project extends index {
197 protected function display_exhibits() {
198 echo "<div id=\"exhibit\">";
199 $sql = "SELECT text FROM projects
201 $result = $this->query($sql, "s", $_GET['project']);
202 if ($result = $result[0]['text']) {
203 $text = str_replace("class=\"exhibit\"", "class=\"exhibit\" style=\"display:block;\"", $result);
207 throw new notFound();
212 class page extends cms {
215 private $notes_per_page = 4;
216 private $number_of_pages = 1;
218 public function __construct() {
219 parent::__construct();
220 $this->page_offset();
223 private function page_offset() {
224 $sql = "SELECT COUNT(*) FROM notes";
225 $result = $this->db->query($sql);
226 $result = $result->fetch_array();
227 $this->number_of_pages = ceil($result[0] / $this->notes_per_page);
228 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
229 $this->page = (int) $_GET['page'];
231 throw new notFound();
233 if ($this->page > $this->number_of_pages) {
234 throw new notFound();
236 if ($this->page < 1) {
237 throw new notFound();
239 $this->offset = ($this->page - 1) * $this->notes_per_page;
242 public function display() {
243 $this->display_head();
244 echo "<div id=\"notes\">";
245 $sql = "SELECT date_posted, title, url, text
246 FROM notes ORDER BY date_posted DESC
248 $result = $this->query($sql, "ii",
250 $this->notes_per_page);
251 foreach ($result as $row => $entry) {
252 $title = $entry['title'];
253 $url = '/note/' . $entry['url'];
254 $date_posted = explode("-", $entry['date_posted']);
255 $year_posted = $date_posted[0];
256 $month_posted = $date_posted[1];
257 $datetime_posted = explode(' ', $date_posted[2]);
258 $day_posted = $datetime_posted[0];
259 echo "<div class=\"note\">";
260 echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span><a href=\"$url\">$title</a></h2>";
265 $this->write_navigation();
266 $this->display_close();
269 private function write_navigation() {
270 echo "<div id=\"navigation\">";
273 $previous_page = $this->page - 1;
274 echo "<a href=\"/notes/page/$previous_page\">prev</a>";
276 if($this->page < $this->number_of_pages) {
277 $forward_page = $this->page + 1;
278 echo " <a href=\"/notes/page/$forward_page\">next</a>";
286 class note extends cms {
288 public function __construct() {
289 parent::__construct();
290 $this->check_exists();
293 private function check_exists() {
294 $sql = "SELECT COUNT(*) FROM notes
296 $results = $this->query($sql, "s", $_GET['note']);
297 if ($results[0]["COUNT(*)"] != 1) {
298 throw new notFound();
302 public function display() {
303 $this->display_head();
304 $sql = "SELECT title, date_posted, text
305 FROM notes WHERE url = ?";
306 $result = $this->query($sql, "s",
309 $title = $entry["title"];
310 $date_posted = explode("-", $entry["date_posted"]);
311 $year_posted = $date_posted[0];
312 $month_posted = $date_posted[1];
313 $datetime_posted = explode(' ', $date_posted[2]);
314 $day_posted = $datetime_posted[0];
315 echo "<div id=\"note\">";
316 echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span>$title</h2>";
318 $this->write_navigation();
319 $this->display_close();
322 private function write_navigation() {
324 echo "<div id=\"navigation\">";
326 echo "<a href=\"/notes/\">notes</a>/";
332 class notFound extends Exception {
333 public function __construct() {
334 header("HTTP/1.0 404 Not Found");
341 ## now actually do something:
342 switch (cms::determine_type()) {
344 $index = new index();
348 $project = new project();