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();
21 public static function determine_type() {
22 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
24 } else if (isset($_GET['year'])) {
26 } else if (isset($_GET['note'])) {
28 } else if ($_SERVER['REQUEST_URI'] == '/') {
30 } else if (isset($_GET['project'])) {
35 protected function not_found() {
36 header("HTTP/1.0 404 Not Found");
41 public function query() {
42 $args = func_get_args();
43 $statement = $this->db
->prepare($args[0]);
44 $args = array_slice($args, 1);
45 call_user_func_array(array($statement, 'bind_param'), &$args);
46 $statement->execute();
48 $statement->store_result();
50 $data = $statement->result_metadata();
52 $fields[0] = &$statement;
53 while($field = $data->fetch_field()) {
54 $fields[] = &$row[$field->name
];
56 call_user_func_array("mysqli_stmt_bind_result", $fields);
58 while ($statement->fetch()) {
59 foreach ($row as $key1=>$value1) $return[$i][$key1] = $value1;
62 $statement->free_result();
66 public function display_head($title = "dylanstestserver",
69 $stylesheets = "<link href=\"/includes/style.css\" rel=\"stylesheet\" type=\"text/css\">";
70 if (cms
::determine_type() == "index") {
71 $scripts = "<script type=\"text/javascript\" src=\"/includes/all.js\">";
72 $home_link = "http://validator.w3.org/unicorn/check?ucn_uri=dylanstestserver.com&ucn_task=conformance#";
75 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
76 "http://www.w3.org/TR/html4/loose.dtd">
80 <meta name="generator" content=
81 "HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
82 <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
85 <link rel="icon" href="favicon.ico" type="image/png">
95 <img src="/images/dylanstestserver.png" alt="dylanstestserver"
103 public function display_close(){
105 <div id="contact_me"><h1><a href=
106 "mailto:dylan@psu.edu">dylan</a></h1><a href=
107 "mailto:dylan@psu.edu">@psu.edu</a>
120 class index extends cms {
121 public function display() {
122 $this->display_head();
123 $this->display_exhibits();
124 echo "<ul id=\"portfolio\" style=\"text-align:right\">";
125 $this->list_projects();
126 echo <<<OTHER_PROJECTS
128 <h3>things i've done for others:</h3>
132 "http://activehamptons.com">activehamptons.com</a></li>
135 "http://transfishing.com">transfishing.com</a></li>
138 <h3>something i've worked on:</h3>
142 "http://tempositions.com">tempositions.com</a></li>
145 <h3>my repositories:</h3>
149 "git">git://dylanstestserver.com</a></li>
156 "/notes/">here</a></li>
162 $this->display_close();
165 protected function display_exhibits() {
166 echo "<div id=\"exhibit\">";
167 $sql = "SELECT text FROM projects";
168 $result = $this->db->query($sql);
169 while ($entry = $result->fetch_object()) {
175 private function list_projects() {
176 echo "<div id=\"exhibit\">";
179 <h3>my projects:</h3>
182 $sql = "SELECT title FROM projects";
183 $result = $this->db->query($sql);
184 while ($entry = $result->fetch_object()) {
185 echo "<li><a class=\"tab\" href=\"$entry->title\">$entry->title</a></li>";
190 class project extends index {
191 protected function display_exhibits() {
192 echo "<div id=\"exhibit\">";
193 $sql = "SELECT text FROM projects
195 $result = $this->query($sql, "s", $_GET['project']);
196 if ($result = $result[0]['text']) {
197 $text = str_replace("class=\"exhibit\"", "class=\"exhibit\" style=\"display:block;\"", $result);
206 class page extends cms {
209 private $notes_per_page = 4;
210 private $number_of_pages = 1;
212 public function __construct() {
213 parent::__construct();
214 $this->page_offset();
217 private function page_offset() {
218 $sql = "SELECT COUNT(*) FROM notes";
219 $result = $this->db->query($sql);
220 $result = $result->fetch_array();
221 $this->number_of_pages = ceil($result[0] / $this->notes_per_page);
222 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
223 $this->page = (int) $_GET['page'];
227 if ($this->page > $this->number_of_pages) {
230 if ($this->page < 1) {
233 $this->offset = ($this->page - 1) * $this->notes_per_page;
236 public function display() {
237 $this->display_head();
238 echo "<div id=\"notes\">";
239 $sql = "SELECT date_posted, title, url, text
240 FROM notes ORDER BY date_posted DESC
242 $result = $this->query($sql, "ii",
244 $this->notes_per_page);
245 foreach ($result as $row => $entry) {
246 $title = $entry['title'];
247 $url = '/note/' . $entry['url'];
248 $date_posted = explode("-", $entry['date_posted']);
249 $year_posted = $date_posted[0];
250 $month_posted = $date_posted[1];
251 $datetime_posted = explode(' ', $date_posted[2]);
252 $day_posted = $datetime_posted[0];
253 echo "<div class=\"note\">";
254 echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span><a href=\"$url\">$title</a></h2>";
259 $this->write_navigation();
260 $this->display_close();
263 private function write_navigation() {
264 echo "<div id=\"navigation\">";
267 $previous_page = $this->page - 1;
268 echo "<a href=\"/notes/page/$previous_page\">prev</a>";
270 if($this->page < $this->number_of_pages) {
271 $forward_page = $this->page + 1;
272 echo " <a href=\"/notes/page/$forward_page\">next</a>";
280 class note extends cms {
282 public function __construct() {
283 parent::__construct();
284 $this->check_exists();
287 private function check_exists() {
288 $sql = "SELECT COUNT(*) FROM notes
290 $results = $this->query($sql, "s", $_GET['note']);
291 if ($results[0]["COUNT(*)"] != 1) {
296 public function display() {
297 $this->display_head();
298 $sql = "SELECT title, date_posted, text
299 FROM notes WHERE url = ?";
300 $result = $this->query($sql, "s",
303 $title = $entry["title"];
304 $date_posted = explode("-", $entry["date_posted"]);
305 $year_posted = $date_posted[0];
306 $month_posted = $date_posted[1];
307 $datetime_posted = explode(' ', $date_posted[2]);
308 $day_posted = $datetime_posted[0];
309 echo "<div id=\"note\">";
310 echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span>$title</h2>";
312 $this->write_navigation();
313 $this->display_close();
316 private function write_navigation() {
318 echo "<div id=\"navigation\">";
320 echo "<a href=\"/notes/\">notes</a>/";
326 class archive extends cms {
328 public function __construct() {
329 parent::__construct();
332 private function check_exists() {
333 $sql = "SELECT COUNT(*) FROM notes
335 $results = $this->query($sql, "s", $_GET['note']);
336 if ($results[0]["COUNT(*)"] != 1) {
341 public function display() {
342 // this really needs its own pagination...
343 // there should be a class for that.
344 $this->display_head();
346 case (isset($_GET['year']) && !isset($_GET['month'])
347 && !isset($_GET['day'])):
348 $sql = "SELECT title, url, date_posted, text
349 FROM notes WHERE YEAR(date_posted) = ?";
350 $result = $this->query($sql, "d",
353 case (isset($_GET['year']) && isset($_GET['month'])
354 && !isset($_GET['day'])):
355 $sql = "SELECT title, url, date_posted, text
356 FROM notes WHERE YEAR(date_posted) = ?
357 AND MONTH(date_posted) = ?";
358 $result = $this->query($sql, "dd",
359 $_GET['year'], $_GET['month']);
361 case (isset($_GET['year']) && isset($_GET['month'])
362 && isset($_GET['day'])):
363 $sql = "SELECT title, url, date_posted, text
364 FROM notes WHERE YEAR(date_posted) = ?
365 AND MONTH(date_posted) = ?
366 AND DAY(date_posted) = ?";
367 $result = $this->query($sql, "ddd",
368 $_GET['year'], $_GET['month'],
372 if (count($result) >= 1) {
373 foreach ($result as $row => $entry) {
374 $title = $entry['title'];
375 $url = '/note/' . $entry['url'];
376 $date_posted = explode("-", $entry['date_posted']);
377 $year_posted = $date_posted[0];
378 $month_posted = $date_posted[1];
379 $datetime_posted = explode(' ', $date_posted[2]);
380 $day_posted = $datetime_posted[0];
381 echo "<div class=\"note\">";
382 echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span><a href=\"$url\">$title</a></h2>";
387 $this->write_navigation();
390 echo "<h2 style=\"font-family:sans-serif;\">sorry, can't find that</h2>";
391 echo "<pre>Empty set (0.00 sec)</pre>";
393 $this->display_close();
396 private function write_navigation() {
398 echo "<div id=\"navigation\">";
406 ## now actually do something:
407 switch (cms::determine_type()) {
409 $index = new index();
413 $project = new project();
425 $archive = new archive;