• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners

Status
Not open for further replies.

pel

Skilled Illusionist
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
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
 

pel

Skilled Illusionist
Joined
Jan 27, 2012
Messages
382
Reaction score
343
Approved, good luck.

I dont need luck, just skilled enough :w00t:
New updates:
Redesigned me-page:
Rz1m7PV - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums

Finished first settings page:
9HNGq0c - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums

Started news (comments + voting will follow):
Jy7w6W6 - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums

Finished staffpage:
RkEAZAL - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Last edited:

pel

Skilled Illusionist
Joined
Jan 27, 2012
Messages
382
Reaction score
343
Made the Error-Page ;)
5WI9lXU - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Junior Spellweaver
Joined
Dec 24, 2011
Messages
125
Reaction score
39
Well code looks nice, but why do you use define for your config do you know that defines are slow down your codes?? better use variables dude
 
  • Like
Reactions: pel

pel

Skilled Illusionist
Joined
Jan 27, 2012
Messages
382
Reaction score
343
Well code looks nice, but why do you use define for your config do you know that defines are slow down your codes?? better use variables dude

Srsly? defined slow codes down? Holy poop.. uff.. mayber I'll fix it. Thank you anyways
 
Initiate Mage
Joined
Feb 13, 2014
Messages
1
Reaction score
1
Hey,
it looks good bro. Like your other projects.
But the index is poop, sorry. :(
I wish you a lot of fun for the programming of the cms.

P.s.: sorry for my english, im coming from germany

greetz,
sunrise
 
  • Like
Reactions: pel

pel

Skilled Illusionist
Joined
Jan 27, 2012
Messages
382
Reaction score
343
Finished Settings-Page:
(not my mail)
wCMlFqH - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums

skHpTkC - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums


Started Homepage-Shop:
Sv6wcqz - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums

B5CeYW8 - Masterpiece ~ Habbo CMS ~ OOP ~ MVC ~ Language System ~ Event listeners - RaGEZONE Forums


Working with JavaScript (jQuery.post() and JSON). No page refresh (ajax :love:)
Will update github later ;)
 

Attachments

You must be registered for see attachments list
Newbie Spellweaver
Joined
Apr 29, 2015
Messages
91
Reaction score
6
i can translate it to dutch and english if you can give me the language file.
just pm me if you need help with it :)
 
Status
Not open for further replies.
Back
Top