- Joined
- Jan 27, 2012
- Messages
- 382
- Reaction score
- 343
Hi.
I decided to create a new Habbo CMS. Reason? Idk, just for the lazy times.
Why the name "Masterpiece"? Cuz its my personal masterpiece ;9
Screenshots:
Snippets:
IndexController.php
My own routing system: (index/@int:id for example)
RouteHandler.php
Route.php
Index.tpl.php:
More screens and snippets are coming while the developement.
Cya,
iExit
I decided to create a new Habbo CMS. Reason? Idk, just for the lazy times.
Why the name "Masterpiece"? Cuz its my personal masterpiece ;9
Screenshots:
You must be registered to see links
You must be registered to see links
Snippets:
IndexController.php
PHP:
<?php
namespace App\Controllers;
use \System\Controller\Controller;
use \System\Route\Route;
use \System\Template\Template;
use \System\Template\View;
use \System\Language\LanguageFile;
use \System\Common;
use \System\Route\IRoutable;
use \System\Controller\IRunable;
use \System\Events\IEventlistener;
class IndexController extends Controller implements IRoutable, IRunable, IEventlistener {
private $template;
public function getRoutes() {
return [
new Route('/index', $this),
new Route('/index/login', $this)
];
}
public function onRun() {
$this->checkRank(-1);
$this->template = new Template('index/Index.tpl.php', new LanguageFile('Index'));
}
public function onFirstRun() { }
public function onCall($route, $params) {
switch($route) {
case '/index':
return $this->IndexAction();
break;
case'/index/login':
return $this->LoginAction();
break;
}
}
public function IndexAction() {
return View::display($this->template);
}
public function LoginAction() {
if(isset($_POST['username'], $_POST['password'])) {
if(!Common::_empty($_POST['username'], $_POST['password'])) {
$user = Common::getUserFactory()->getByUsername($_POST['username']);
if($user != null) {
if($user->getRow()->password == Common::PW_HASH($_POST['password'])) {
$_SESSION['username'] = $user->getRow()->username;
$_SESSION['password'] = $user->getRow()->password;
return $this->link('me');
} else {
$this->template->set('error', 'wrong_password');
}
} else {
$this->template->set('error', 'user_not_exist');
}
} else {
$this->template->set('error', 'username_password_empty');
}
}
return $this->IndexAction();
}
}
My own routing system: (index/@int:id for example)
RouteHandler.php
PHP:
<?php
namespace System\Route;
use \System\Console;
class RouteHandler {
private $routes = [];
private $route = '/';
private $handler;
const ACCESSABLE = 0;
const INVALIDREQUEST = 1;
const NOTFOUND = 2;
public function add(Route $route) {
if (!$this->routeExists($route)) {
$this->routes[] = $route;
}
}
private function routeExists($searchingRoute) {
foreach ($this->routes as $route) {
if ($route->getRoute() == $searchingRoute->getRoute()) {
return true;
}
}
return false;
}
public function setRoute($route) {
$this->route = rtrim($route, '/');
}
public function checkRoutes() {
$foundRoute = null;
foreach ($this->routes as $route) {
if ($route->getRoute() == $this->route) {
$this->handler = $route;
return;
}
$explodedRoute = explode('/', $route->getRoute());
$currentRoute = explode('/', $this->route);
$match = 0;
if (count($explodedRoute) == count($currentRoute)) {
for ($i = 0; $i < count($currentRoute); $i++) {
if ($explodedRoute[$i] != '') {
if (substr($explodedRoute[$i], 0, 1) == '@') {
$explodedArea = explode(':', $explodedRoute[$i]);
$type = str_replace('@', '', $explodedArea[0]);
switch (strtolower($type)) {
case 'int':
if (ctype_digit($currentRoute[$i])) {
$route->addParam($explodedArea[1], $currentRoute[$i]);
$route->addInteger(1);
$match++;
}
break;
case 'string':
if (!ctype_digit($currentRoute[$i])) {
$route->addParam($explodedArea[1], $currentRoute[$i]);
$route->addString(1);
$match++;
}
break;
}
} else {
if ($currentRoute[$i] == $explodedRoute[$i]) {
$match++;
}
}
Console::log('App->RouteHandler', $match.' zu '.(count($explodedRoute) - 1). ' bei ' .$route->getRoute());
}
}
if ($match == (count($explodedRoute) - 1)) {
$foundRoute = 1;
$this->handler = $route;
}
}
}
if ($foundRoute == null) {
return RouteHandler::NOTFOUND;
}
if (!$this->handler->isAllowedToPost() && (count($_POST) > 0)) {
return RouteHandler::INVALIDREQUEST;
}
return RouteHandler::ACCESSABLE;
}
public function getHandler() {
return $this->handler;
}
}
Route.php
PHP:
<?php
namespace System\Route;
class Route {
private $post = false;
private $route;
private /*Controller*/ $class;
private $params = [];
private $routeIntegers = 0;
private $routeStrings = 0;
public function __construct($route, $class, $post = false) {
$this->route = $route;
$this->class = $class;
$this->post = $post;
}
public function getIntegers() {
return $this->routeIntegers;
}
public function addInteger($i) {
$this->routeIntegers += $i;
}
public function addParam($name, $value) {
$this->params[$name] = $value;
}
public function isAllowedToPost() {
return $this->post;
}
public function getClass() {
return $this->class;
}
public function getParams() {
return $this->params;
}
public function addString($i) {
$this->routeStrings += $i;
}
public function getStrings() {
return $this->routeStrings;
}
public function getRoute() {
return $this->route;
}
}
Index.tpl.php:
PHP:
<!DOCTYPE html>
<html>
<head>
<title><?php echo $this->getLang()->get('title', ['%hotelname%' => HOTELNAME]); ?></title>
<link href="<?php echo PATH; ?>public/css/Main.css" rel="stylesheet">
<link href="<?php echo PATH; ?>public/css/960_12_col.css" rel="stylesheet">
<link href="<?php echo PATH; ?>public/css/index/Index.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="<?php echo PATH; ?>public/js/index/index.js"></script>
</head>
<body>
<div id="hotel"></div>
<div id="new"></div>
<?php if($this->get('error') != null) { ?>
<div id="error">
<?php echo $this->getLang()->get('error')->get($this->get('error')); ?>
</div>
<?php } ?>
<header style="position: relative; z-index: 999999999999999">
<div class="container_12" style="margin:0 auto;position: relative; z-index: 999999">
<div class="grid_3">
<div id="logo"></div>
</div>
<div class="grid_9" style="padding-top: 20px">
<div class="grid_9 alpha">
<span class="title">Login</span>
</div>
<form method="POST" action="<?php echo PATH; ?>index/login">
<div class="grid_3 alpha">
<input class="input" name="username" type="text" placeholder="<?php echo $this->getLang()->get('content')->get('login')->get('username'); ?>">
</div>
<div class="grid_3">
<input class="input" name="password" type="password" placeholder="<?php echo $this->getLang()->get('content')->get('login')->get('password'); ?>">
</div>
<div class="grid_3 omega">
<input class="submit" type="submit" value="<?php echo $this->getLang()->get('content')->get('login')->get('button'); ?>">
</div>
</form>
</div>
<div class="grid_12">
<div id="header_arrow"></div>
</div>
</div>
</header>
<div class="container_12" style="margin:0 auto;position: relative; z-index: 9999;">
<div id="loginGrid" class="grid_12" style="position: absolute; top: 120px">
<div id="maintitle"><?php echo $this->getLang()->get('content')->get('title'); ?></div>
<div id="subtitle"><?php echo $this->getLang()->get('content')->get('subtitle', [
'%registeredAccounts%' => '<span style="font-weight: bold; font-family: Roboto">'.System\Common::getUserFactory()->getRegisteredUsersCount().'</span>'
]); ?></div>
<div style="margin-top: 150px; position: relative">
<div id="registerButton"><?php echo $this->getLang()->get('content')->get('registerButton'); ?></div>
</div>
</div>
</div>
<footer>
<div class="container_12" style="margin:0 auto;position: relative; z-index: 9999;">
<div class="grid_12" style="line-height: 125%">
<a href="#">Register</a> <a href="#">Register</a><br />
11
</div>
</div>
</footer>
</body>
</html>
More screens and snippets are coming while the developement.
Cya,
iExit