Skip to content

Commit

Permalink
Add Discord page
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Jul 26, 2019
1 parent 6fa2d5f commit 7879e68
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/controllers/Discord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace BNETDocs\Controllers;

use \BNETDocs\Models\Discord as DiscordModel;

use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Controller;
use \CarlBennett\MVC\Libraries\Router;
use \CarlBennett\MVC\Libraries\View;

use \DateTime;
use \DateTimeZone;

class Discord extends Controller {

public function &run( Router &$router, View &$view, array &$args ) {

$model = new DiscordModel();

$model->discord_url = 'https://discord.gg/';
$model->discord_url .= Common::$config->bnetdocs->discord->invite_code;
$model->discord_server_id = Common::$config->bnetdocs->discord->server_id;

$view->render( $model );

$model->_responseCode = 200;
$model->_responseHeaders[ 'Content-Type' ] = $view->getMimeType();
$model->_responseTTL = 0;

return $model;

}

}
3 changes: 3 additions & 0 deletions src/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ function main() {
$router->addRoute( // URL: /credits
"#^/credits/?$#", "Credits", "CreditsHtml"
);
$router->addRoute( // URL: /discord
"#^/discord/?$#", "Discord", "DiscordHtml"
);
$router->addRoute( // URL: /document/:id.txt
"#^/document/(\d+)\.txt#", "Document\\View", "Document\\ViewPlain"
);
Expand Down
11 changes: 11 additions & 0 deletions src/models/Discord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace BNETDocs\Models;

use \CarlBennett\MVC\Libraries\Model;

class Discord extends Model {

public $discord_url;

}
31 changes: 31 additions & 0 deletions src/templates/Discord.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace BNETDocs\Templates;

use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Pair;

$title = 'Discord';
$description = 'Join our Discord and have a chat with us!';

$this->opengraph->attach( new Pair( 'url', '/discord' ));
$this->opengraph->attach( new Pair( 'type', 'article' ));

$this->additional_css[] = "/a/forms.css";
require( './header.inc.phtml' );
?>
<article>
<header>Discord</header>
<section>
<h2>Who's Online</h2><br/>
<iframe style="display:block;margin:auto;" src="https://discordapp.com/widget?id=<?=filter_var( $this->getContext()->discord_server_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS )?>&theme=dark" width="80%" height="400" allowtransparency="true" frameborder="0"></iframe>
<h2>What is Discord?</h2><br/>
<p><a href="https://discordapp.com/">Discord</a> is a free voice, video, and text chat app made for gamers.</p>
<p>The Discord app can be accessed on PCs, browsers, and mobile phones. Users can direct message other users and congregate by joining servers.</p>
<p>From small to large communities, millions of users are using Discord to chat securely in real-time. BNETDocs is no exception.</p>
<h2>How to Join</h2>
<p style="text-align:center;"><a class="button" href="<?php echo Common::relativeUrlToAbsolute( $this->getContext()->discord_url ); ?>">Click this invite link</a></p>
<p><strong><a href="<?php echo Common::relativeUrlToAbsolute( $this->getContext()->discord_url ); ?>">Join our Discord</a></strong> and chat with other gamers like you! Our community is open to the public and we welcome new users.</p>
</section>
</article>
<?php require( './footer.inc.phtml' ); ?>
25 changes: 25 additions & 0 deletions src/views/DiscordHtml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace BNETDocs\Views;

use \BNETDocs\Models\Discord as DiscordModel;

use \CarlBennett\MVC\Libraries\Exceptions\IncorrectModelException;
use \CarlBennett\MVC\Libraries\Model;
use \CarlBennett\MVC\Libraries\Template;
use \CarlBennett\MVC\Libraries\View;

class DiscordHtml extends View {

public function getMimeType() {
return 'text/html;charset=utf-8';
}

public function render( Model &$model ) {
if ( !$model instanceof DiscordModel ) {
throw new IncorrectModelException();
}
( new Template( $model, 'Discord' ))->render();
}

}

0 comments on commit 7879e68

Please sign in to comment.