b5b3b201b33635311c3b857b9552275e4ccfa8f6
3 require_once("model/model.php");
7 private $config_file = '/etc/dylansserver.ini';
9 protected $recaptcha_publickey;
10 protected $recaptcha_privatekey;
14 public function __construct() {
15 $this->model
= new model();
16 $config = parse_ini_file($this->config_file
, true);
17 $this->db
= new mysqli(
18 $config['database']['domain'],
19 $config['database']['user'],
20 $config['database']['password'],
21 $config['database']['database']);
22 if (mysqli_connect_errno()) {
23 echo "Problem connecting to database: ";
24 echo mysqli_connect_error();
27 $this->recaptcha_publickey
= $config['recaptcha']['publickey'];
28 $this->recaptcha_privatekey
= $config['recaptcha']['privatekey'];
29 $this->title
= $config['site']['default_title'];
30 $this->home_link
= $config['site']['home_link'];
33 public function query() {
34 $args = func_get_args();
35 $statement = $this->db
->prepare($args[0]);
36 $args = array_slice($args, 1);
37 call_user_func_array(array($statement, 'bind_param'), &$args);
38 $statement->execute();
40 $statement->store_result();
42 $data = $statement->result_metadata();
44 $fields[0] = &$statement;
45 while($field = $data->fetch_field()) {
46 $fields[] = &$row[$field->name
];
48 call_user_func_array("mysqli_stmt_bind_result", $fields);
50 while ($statement->fetch()) {
51 foreach ($row as $key=>$value) $return[$i][$key] = $value;
54 $statement->free_result();
58 public static function determine_type() {
59 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
61 } else if (isset($_GET['year'])) {
63 } else if (isset($_GET['note'])) {
65 } else if ($_SERVER['REQUEST_URI'] == '/') {
67 } else if (isset($_GET['project'])) {
69 } else if (isset($_GET['rss'])) {
71 } else if (isset($_GET['challenge'])) {
76 public function init() {
77 switch (cms
::determine_type()) {
83 $project = new project();
87 require_once("model/note.php");
89 require_once("view/note.php");
92 require_once("model/page.php");
94 require_once("view/page.php");
97 require_once("model/rss.php");
99 require_once("view/rss.php");
102 $archive = new archive
;
106 $captcha = new captcha
;
115 class index
extends cms
{
117 public function display() {
118 require_once("view/index.php");
121 protected function display_exhibits() {
122 echo "<div id='exhibit'>";
123 $sql = "SELECT text FROM projects ORDER BY rank";
124 $result = $this->db
->query($sql);
125 while ($entry = $result->fetch_object()) {
131 private function list_projects() {
132 $sql = "SELECT title FROM projects ORDER BY rank";
133 $result = $this->db
->query($sql);
134 while ($entry = $result->fetch_object()) {
135 echo "<li><a class='tab' href='$entry->title'>$entry->title</a></li>";
142 class project
extends index
{
144 protected function display_exhibits() {
145 echo "<div id='exhibit'>";
146 $sql = "SELECT text FROM projects
148 $result = $this->query($sql, "s", $_GET['project']);
149 if ($result = $result[0]['text']) {
150 $text = str_replace("class='exhibit'", "class='exhibit' style='display:block;'", $result);
154 throw new notFound();
161 class archive
extends cms
{
163 public function __construct() {
164 parent
::__construct();
167 private function check_exists() {
168 $sql = "SELECT COUNT(*) FROM notes
170 $results = $this->query($sql, "s", $_GET['note']);
171 if ($results[0]["COUNT(*)"] != 1) {
176 public function display() {
177 require_once("view/archive.php");
180 public function display_notes() {
182 case (isset($_GET['year']) && !isset($_GET['month'])
183 && !isset($_GET['day'])):
184 $sql = "SELECT title, url, date_posted, text
185 FROM notes WHERE YEAR(date_posted) = ?
186 ORDER BY date_posted DESC";
187 $result = $this->query($sql, "d",
190 case (isset($_GET['year']) && isset($_GET['month'])
191 && !isset($_GET['day'])):
192 $sql = "SELECT title, url, date_posted, text
193 FROM notes WHERE YEAR(date_posted) = ?
194 AND MONTH(date_posted) = ?
195 ORDER BY date_posted DESC";
196 $result = $this->query($sql, "dd",
197 $_GET['year'], $_GET['month']);
199 case (isset($_GET['year']) && isset($_GET['month'])
200 && isset($_GET['day'])):
201 $sql = "SELECT title, url, date_posted, text
202 FROM notes WHERE YEAR(date_posted) = ?
203 AND MONTH(date_posted) = ?
204 AND DAY(date_posted) = ?
205 ORDER BY date_posted DESC";
206 $result = $this->query($sql, "ddd",
207 $_GET['year'], $_GET['month'],
211 if (count($result) >= 1) {
212 echo "<div id='notes'>";
213 foreach ($result as $row => $entry) {
214 $title = $entry['title'];
215 $url = '/note/' . $entry['url'];
216 $date_posted = explode("-", $entry['date_posted']);
217 $year_posted = $date_posted[0];
218 $month_posted = $date_posted[1];
219 $datetime_posted = explode(' ', $date_posted[2]);
220 $day_posted = $datetime_posted[0];
221 echo "<div class='note'>";
222 echo "<h1><span class='date'>";
223 echo "$year_posted/$month_posted/$day_posted/";
224 echo "</span><a href='$url'>$title</a></h1>";
231 echo "<h1>sorry, nothing here</h2>";
232 echo "<pre>Empty set (0.00 sec)</pre>";
239 class notFound
extends Exception
{
241 public function __construct() {
242 header('HTTP/1.0 404 Not Found');
251 class captcha
extends cms
{
253 public function display() {
254 $challenge = $_GET['challenge'];
255 $response = $_GET['response'];
256 $remoteip = $_SERVER['REMOTE_ADDR'];
257 $curl = curl_init('http://api-verify.recaptcha.net/verify?');
258 curl_setopt ($curl, CURLOPT_POST
, 4);
259 curl_setopt ($curl, CURLOPT_POSTFIELDS
, "privatekey=$this->recaptcha_privatekey&remoteip=$remoteip&challenge=$challenge&response=$response");
260 $result = curl_exec ($curl);