0f23b809a0fe5c7f9e3e57d77e2732d19e869946
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_close(){
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>
114 class index extends cms {
115 public function display() {
116 $this->display_head();
117 $this->display_exhibits();
118 echo "<ul id=\"portfolio\" style=\"text-align:right\">";
119 $this->list_projects();
120 echo <<<OTHER_PROJECTS
122 <h3>things i've done for others:</h3>
126 "http://activehamptons.com">activehamptons.com</a></li>
129 "http://transfishing.com">transfishing.com</a></li>
132 <h3>something i've worked on:</h3>
136 "http://tempositions.com">tempositions.com</a></li>
139 <h3>my repositories:</h3>
143 "git">git://dylanstestserver.com</a></li>
150 "/notes/">here</a></li>
156 $this->display_close();
159 protected function display_exhibits() {
160 echo "<div id=\"exhibit\">";
161 $sql = "SELECT text FROM projects";
162 $result = $this->db->query($sql);
163 while ($entry = $result->fetch_object()) {
169 private function list_projects() {
170 echo "<div id=\"exhibit\">";
173 <h3>my projects:</h3>
176 $sql = "SELECT title FROM projects";
177 $result = $this->db->query($sql);
178 while ($entry = $result->fetch_object()) {
179 echo "<li><a class=\"tab\" href=\"$entry->title\">$entry->title</a></li>";
184 class project extends index {
185 protected function display_exhibits() {
186 echo "<div id=\"exhibit\">";
187 $sql = "SELECT text FROM projects
189 $result = $this->query($sql, "s", $_GET['project']);
190 if ($result = $result[0]['text']) {
191 $text = str_replace("class=\"exhibit\"", "class=\"exhibit\" style=\"display:block;\"", $result);
195 throw new notFound();
200 class page extends cms {
203 private $notes_per_page = 4;
204 private $number_of_pages = 1;
206 public function __construct() {
207 parent::__construct();
208 $this->page_offset();
211 private function page_offset() {
212 $sql = "SELECT COUNT(*) FROM notes";
213 $result = $this->db->query($sql);
214 $result = $result->fetch_array();
215 $this->number_of_pages = ceil($result[0] / $this->notes_per_page);
216 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
217 $this->page = (int) $_GET['page'];
219 throw new notFound();
221 if ($this->page > $this->number_of_pages) {
222 throw new notFound();
224 if ($this->page < 1) {
225 throw new notFound();
227 $this->offset = ($this->page - 1) * $this->notes_per_page;
230 public function display() {
231 $this->display_head();
232 echo "<div id=\"notes\">";
233 $sql = "SELECT date_posted, title, url, text
234 FROM notes ORDER BY date_posted DESC
236 $result = $this->query($sql, "ii",
238 $this->notes_per_page);
239 foreach ($result as $row => $entry) {
240 $title = $entry['title'];
241 $url = '/note/' . $entry['url'];
242 $date_posted = explode("-", $entry['date_posted']);
243 $year_posted = $date_posted[0];
244 $month_posted = $date_posted[1];
245 $datetime_posted = explode(' ', $date_posted[2]);
246 $day_posted = $datetime_posted[0];
247 echo "<div class=\"note\">";
248 echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span><a href=\"$url\">$title</a></h2>";
253 $this->write_navigation();
254 $this->display_close();
257 private function write_navigation() {
258 echo "<div id=\"navigation\">";
261 $previous_page = $this->page - 1;
262 echo "<a href=\"/notes/page/$previous_page\">prev</a>";
264 if($this->page < $this->number_of_pages) {
265 $forward_page = $this->page + 1;
266 echo " <a href=\"/notes/page/$forward_page\">next</a>";
274 class note extends cms {
276 public function __construct() {
277 parent::__construct();
278 $this->check_exists();
281 private function check_exists() {
282 $sql = "SELECT COUNT(*) FROM notes
284 $results = $this->query($sql, "s", $_GET['note']);
285 if ($results[0]["COUNT(*)"] != 1) {
286 throw new notFound();
290 public function display() {
291 $this->display_head();
292 $sql = "SELECT title, date_posted, text
293 FROM notes WHERE url = ?";
294 $result = $this->query($sql, "s",
297 $title = $entry["title"];
298 $date_posted = explode("-", $entry["date_posted"]);
299 $year_posted = $date_posted[0];
300 $month_posted = $date_posted[1];
301 $datetime_posted = explode(' ', $date_posted[2]);
302 $day_posted = $datetime_posted[0];
303 echo "<div id=\"note\">";
304 echo "<h2><span style=\"color:grey;\">$year_posted/$month_posted/$day_posted/</span>$title</h2>";
306 $this->write_navigation();
307 $this->display_close();
310 private function write_navigation() {
312 echo "<div id=\"navigation\">";
314 echo "<a href=\"/notes/\">notes</a>/";
320 class notFound extends Exception {
321 public function __construct() {
322 header("HTTP/1.0 404 Not Found");
329 ## now actually do something:
330 switch (cms::determine_type()) {
332 $index = new index();
336 $project = new project();