Skip to content

Commit fb5ca83

Browse files
committed
Add rudimentary packet viewer
1 parent e30ba5a commit fb5ca83

File tree

12 files changed

+539
-32
lines changed

12 files changed

+539
-32
lines changed

controllers/Packet/View.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace BNETDocs\Controllers\Packet;
4+
5+
use \BNETDocs\Libraries\Common;
6+
use \BNETDocs\Libraries\Controller;
7+
use \BNETDocs\Libraries\Exceptions\PacketNotFoundException;
8+
use \BNETDocs\Libraries\Exceptions\UnspecifiedViewException;
9+
use \BNETDocs\Libraries\Packet;
10+
use \BNETDocs\Libraries\Router;
11+
use \BNETDocs\Libraries\UserSession;
12+
use \BNETDocs\Models\Packet\View as PacketViewModel;
13+
use \BNETDocs\Views\Packet\ViewHtml as PacketViewHtmlView;
14+
use \BNETDocs\Views\Packet\ViewPlain as PacketViewPlainView;
15+
use \DateTime;
16+
use \DateTimeZone;
17+
18+
class View extends Controller {
19+
20+
protected $packet_id;
21+
22+
public function __construct($packet_id) {
23+
parent::__construct();
24+
$this->packet_id = $packet_id;
25+
}
26+
27+
public function run(Router &$router) {
28+
switch ($router->getRequestPathExtension()) {
29+
case "htm": case "html": case "":
30+
$view = new PacketViewHtmlView();
31+
break;
32+
case "txt":
33+
$view = new PacketViewPlainView();
34+
break;
35+
default:
36+
throw new UnspecifiedViewException();
37+
}
38+
$model = new PacketViewModel();
39+
$model->packet_id = $this->packet_id;
40+
try {
41+
$model->packet = new Packet($this->packet_id);
42+
} catch (PacketNotFoundException $e) {
43+
$model->packet = null;
44+
}
45+
$model->user_session = UserSession::load($router);
46+
ob_start();
47+
$view->render($model);
48+
$router->setResponseCode(($model->packet ? 200 : 404));
49+
$router->setResponseTTL(0);
50+
$router->setResponseHeader("Content-Type", $view->getMimeType());
51+
$router->setResponseContent(ob_get_contents());
52+
ob_end_clean();
53+
}
54+
55+
}

controllers/Status.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public function run(Router &$router) {
3737
}
3838

3939
protected function getStatus(StatusModel &$model) {
40-
$model->remote_address = getenv("REMOTE_ADDR");
41-
$model->remote_geoinfo = geoip_record_by_name($model->remote_address);
42-
$model->timestamp = new DateTime("now", new DateTimeZone("UTC"));
43-
$model->version_info = Common::$version;
40+
$model->remote_address = getenv("REMOTE_ADDR");
41+
$model->remote_geoinfo = geoip_record_by_name($model->remote_address);
42+
$model->timestamp = new DateTime("now", new DateTimeZone("UTC"));
43+
$model->version_info = Common::$version;
4444
return true;
4545
}
4646

libraries/Document.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use \BNETDocs\Libraries\Exceptions\DocumentNotFoundException;
1010
use \BNETDocs\Libraries\Exceptions\QueryException;
1111
use \BNETDocs\Libraries\Markdown;
12+
use \BNETDocs\Libraries\User;
1213
use \DateTime;
1314
use \DateTimeZone;
1415
use \InvalidArgumentException;
@@ -18,8 +19,8 @@
1819

1920
class Document {
2021

21-
const OPTION_MARKDOWN = 1;
22-
const OPTION_PUBLISHED = 2;
22+
const OPTION_MARKDOWN = 0x00000001;
23+
const OPTION_PUBLISHED = 0x00000002;
2324

2425
protected $content;
2526
protected $created_datetime;
@@ -217,7 +218,7 @@ public function refresh() {
217218
$cache_key = "bnetdocs-document-" . $this->id;
218219
$cache_val = Common::$cache->get($cache_key);
219220
if ($cache_val !== false) {
220-
$cache_val = unserialize($cache_val);
221+
$cache_val = unserialize($cache_val);
221222
$this->content = $cache_val->content;
222223
$this->created_datetime = $cache_val->created_datetime;
223224
$this->edited_count = $cache_val->edited_count;

libraries/NewsPost.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
class NewsPost {
2222

23-
const OPTION_MARKDOWN = 1;
24-
const OPTION_PUBLISHED = 2;
23+
const OPTION_MARKDOWN = 0x00000001;
24+
const OPTION_PUBLISHED = 0x00000002;
2525

2626
protected $category_id;
2727
protected $content;

0 commit comments

Comments
 (0)