Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC]

Status
Not open for further replies.
Experienced Elementalist
Joined
Jul 31, 2012
Messages
268
Reaction score
100
4pntcCj - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums

[PHP 5.6+] [PDO] [OOP] [TPL] [MVC]

Hey,
it's been quite a long time ago since I last contributed with something so I thought why not make a proper housekeeping and release it?
My aim is to make this an easy-to-use solution.



I'm not using any PHP framework because I love to create my own components whenever I feel the need. (Yes.. I know, laravel is godlike)
Some components CAN be a year or two old, although I'm not using old components when it involves security.

BlackWolf follows the MVC architecure, the templating is provided by my own Template engine called 'ImTPL' (such name wow).

Why the name BlackWolf?
Idk, sounds cool that's all.



So let's get into details shall we?:
BlackWolf HK is currently only compatible with Plus Emulator but I'll make sure to also make it compatible with Arcturus and maybe Comet too.



Features
BlackWolf's features are always growing, the list below shows all the features that are
Completed, In progress & Planned.


  • [*]Login
    [*]Logout
    [*]Dashboard
    • {Widget} Users count
    • {Widget} Catalogue items
    • {Widget} Furniture
    • {Widget} Banned users
    • {Widget} Server status
    • {Widget} Users online list
      • {Widget} Rooms loaded
      • {Widget} Users online

    [*]Users
    • View all Users
    • Manage Users

    [*]System permissions
    • View all Permissions
    • Manage Permissions

    [*]System pages
    • Create pages
    • Edit pages


    [*]Housekeeping
    • Configuration
    • System Logs
    • Accounts
      • Manage checkin tokens



    [*]News
    • Manage News
    • Create an Article

    [*]Bans
    • Add Ban
    • Manage Bans


    [*]Logs
    • Trade Logs
    • Command Logs
    • ?


    [*]Tickets


    [*]Word Filter
    • Filtering List
    • Filter a Word

    [*]Ranks
    • View all Ranks
    • Manage Ranks

    [*]System
    • Server Information
    • About


FAQ
Q: When will BlackWolf be released?
A: Whenever I feel it's ready to be released.

Q: How can I request a feature?
A: Post your feature and I'll probably add it to my to-do list.


Development Team
  • 3M1L


Screenshots (7)

Full album on Imgur:

Screenshots:
QKeM3Fd - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums


kzj8iw - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums


zZy6ZFt - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums


oHuGtmj - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums


JNMKpB5 - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums


Y1tHeGx - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums


kbMDqii - BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/MVC] - RaGEZONE Forums


Full album on Imgur:

Snippets
Dashboard controller:
Dashboard model:

Currently the repository (Github) is private but I'll make it public for the BETA stages.

Constructive feedback is always welcome.
 

Attachments

You must be registered for see attachments list
Last edited:
Junior Spellweaver
Joined
Jan 1, 2016
Messages
157
Reaction score
23
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+] [PDO] [OOP] [TPL] [Angular]

Good as always bby, looking forward to see the end of this :love:
 
Newbie Spellweaver
Joined
Jul 13, 2015
Messages
71
Reaction score
31
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+] [PDO] [OOP] [TPL] [Angular]

I don't liked the code. Because:

No escaping queries
No OOP
No n
amespaces
Documentation?? please only document what is necessary



And the code don't have a coding style. It's really a mess

You should try using the PHP standards (PSR).
See about PSR here:
 
Experienced Elementalist
Joined
Jul 31, 2012
Messages
268
Reaction score
100
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+] [PDO] [OOP] [TPL] [Angular]

Well, first of all, I don't need to escape queries, I simply let my querybuilder handle it with prepared statements.
I do use OOP, I just didn't post any class snippets,
here's some:

#1
PHP:
<?php

namespace core;

use auth\Authenticate as Auth;
use users\UserFactory;

class Users
{
    public function __construct()
    {

    }

    public function update($id, $cols)
    {
        if(!$this->findUser($id)) // just to be sure that the user exists.. meh :w
            return false;

        return table("users")
                ->update($cols)
                ->where("id", $id)
                ->run();
    }

    public function findUser($id, $cols = "id, username")
    {
        return $this->getUserById($id, $cols);
    }

    public function getUserById($id, $cols = "*")
    {
        $userData = (new UserFactory)->getUserById($id, $cols);

        if(!$userData)
            return false;

        return (object)$userData;
    }

    public function getRanks()
    {
        return table("permissions_groups")
                ->select("id, name, description")
                ->orderBy("id", "DESC")
                ->fetchAll();
    }
}
#2
PHP:
<?php

namespace core;

use auth\Authenticate as Auth;
use Exception;

class Permissions
{
    private $strictErrors = true; // explains itself
    private $strict       = true; // true : both userRank AND specialRank must match the same permission, false : recommended

    private $userRank = 1, $specialRank = 0;

    private $basePermissions   = [];

    private $baseSpecialGroups = [];
    private $baseGroups        = [];

    private $groups            = [];

    public function __construct()
    {

    }

    public function dump()
    {
        echo "<pre>";
        print_r(get_object_vars($this));
        echo "</pre>";
    }

    public function has($rule, $currentRank = 0)
    {
        $rule = trim($rule);

        if(empty($rule))
            return false;

        try
        {
            if($currentRank == 0 && Auth::loggedIn())
                $currentRank = Auth::user()->rank;

            if($this->hasChar("*", $rule)) // wildcard *
                return $this->validateWildcard($rule, $this->groups, $currentRank);

            if($this->strictErrors && !$this->validate($rule, $this->groups))
                throw new Exception("$rule is not defined in groups permissions!");

            foreach($this->groups as $permission => $data)
            {
                if($rule != $permission) // skip if the rule doesnt match the permission name
                    continue;

                if($this->hasAbility($data, $currentRank))
                    return true;
            }
        }
        catch(Exception $e)
        {
            redirectToError($e);
        }

        return false;
    }



    private function validateWildcard($key, $expected = [], $currentRank = 0)
    {
        if(!is_array($expected))
            return false;

        $key = explode("*", $key, 2)[0];

        foreach($expected as $rule => $ranks)
        {
            if(!$this->startsWith($rule, $key)) // skip if the rule doesn't start with our prefix
                continue;

            if(!$this->hasAbility($ranks, $currentRank))
                return false;
        }

        return true;
    }

    private function validate($key, $expected = [], $keysOnly = true)
    {
        if(is_array($expected))
            if($keysOnly)
                return in_array($key, array_keys($expected));
            else
                return in_array($key, $expected);

        return $key == $expected;
    }

    private function hasAbility($data, $currentRank = 0)
    {
        $ranks        = array_values($data["ranks"]);
        $specialRanks = array_values($data["special_ranks"]);

        $rank = $currentRank == 0 ? $this->userRank : $currentRank;

        if($this->strict)
            return in_array($rank, $ranks) && in_array($this->specialRank, $specialRanks);
        else
            return in_array($rank, $ranks) || in_array($this->specialRank, $specialRanks);
    }

    private function hasChar($char, $value, $explode = false)
    {
        $match = strpos($value, $char) !== false;

        if($match)
            return $explode ? explode($char, $value) : $match;
    }

    private function startsWith($search, $prefix)
    {
        return strncmp($search, $prefix, strlen($prefix)) == 0;
    }

    ..

Namepaces are being used for autoloading and I haven't done any documentation yet but I'm gonna do that soon,
thanks for your feedback though!
 

pel

Skilled Illusionist
Joined
Jan 27, 2012
Messages
382
Reaction score
343
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+] [PDO] [OOP] [TPL] [Angular]

What about a github / bitbucket repository?
 
Experienced Elementalist
Joined
Jul 31, 2012
Messages
268
Reaction score
100
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+] [PDO] [OOP] [TPL] [Angular]

As I already mentioned it at the end of the intro post,
'Currently the repository (Github) is private but I'll make it public for the BETA stages.'
 
  • Like
Reactions: pel
Joined
Aug 10, 2011
Messages
7,399
Reaction score
3,305
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

Just curious why you did this:

Code:
public function update($id, $cols)
    {
        if(!$this->findUser($id)) // just to be sure that the user exists.. meh :w
            return false;

        return table("users")
                ->update($cols)
                ->where("id", $id)
                ->run();
    }

I think that check is redundant because nothing will be updated if the user does not exist right? So maybe return true if affected rows == 1 ?

Code:
if(!hasAbility("hk.users.edit.password")) // this noob has no permission :( nice try tho.

Function name is hasAbility() but it checks for permissions. Wouldn't hasPermission() be a better name?

Just curious. Looks cool and looking forward to see you finish this. (Trade values with marketplace data ;)? )
 
Experienced Elementalist
Joined
Jul 31, 2012
Messages
268
Reaction score
100
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

You actually got a point on the users update, didn't think of it that way x)

The function name hasPermission() does exist, but it also redirects the user to the "Access denied" page and all I need is a boolean returned, so I thought what else can I name a function which doesn't really redirect but has something todo with permissions & found hasAbility.
But I might rename\recode them though.

Trade values with marketplace data sounds cool, I'll probably code that after I finished up the current feature list and made BlackWolf compatible with Arcturus too,

thanks for your feedback Wesley!
 
Last edited:
git bisect -m
Loyal Member
Joined
Sep 2, 2011
Messages
2,171
Reaction score
916
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

3M1L the design looks beauty.

But i need agree with lai0n in some parts.
Okay, you're using Query Builder, it's your own one? Or using a library?
The code looks a mess.

You didn't understood the concept of namespacing and bootstraping. The "action" from the snippet, wouldn't be called by AJAX?

You can actually redirect all "backend stuff" from actions to index.php or as an example 'actions.php' that will choose the action by the query string or requested uri? (A little idea)

Please start you code with documentations. Documentation it's something very important.

Depending on which "design pattern" you're using, you actually doesn't need put code that makes decision acting in your getters and setters. This would be a job of a Factory or a Controller.

Code:
    public function getUserById($id, $cols = "*")
    {
        $userData = (new UserFactory)->getUserById($id, $cols);

        if(!$userData)
            return false;

        return (object)$userData;
    }

This is weird. You're simple removing the typing of your variable. PHP will not identify anymore that this is an User. Actually, you can use some libraries or simple line codes that can specify for PHP which class this object it's derived.

Anyways, that's good if you want to make some control of what data you're obtaining.

The GetUserById maybe return a empty object.

Code:
if(!$userData)
   return false;

Why actually you're doing this?

The function "error()" it's a global function? You're not using any Helper system? Why actually created a class for Hashes but not for Error Handling?

Anyways, keep the good job in the design. I will recommend you also PSR, but they are recommendations, not rules.
 
Experienced Elementalist
Joined
Jul 31, 2012
Messages
268
Reaction score
100
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

samuus thanks!

I'm using my own Query Builder (already mentioned it at the beginning of this thread).
Exactly which parts does look like a mess? And how would you prefer doing it?

I'm not using any AJAX to submit forms (should I start doing it?).

Redirecting all "backend stuff" to index.php would just be a mess that's why I keep them in seperate files e.g 'actions/users/update.php, /actions/users/add.php', or have I missunderstood you?

I will begin with documentations, It's indeed important I agree, but in most cases I name methods in a "self-explanatory" way.

The UserFactory component is quite old (yes, also mentioned it at the beginning of this thread that some components can be old) but I should probably rewrite them according to the PSR.

I assume you're meaning that I should return an User object ^?

The reason I return a boolean instead of an empty object is because I feel more comfortable with it, or is there a rule for this too?

The function error() is a global function for Flash Messages, but I'm too lazy to write
Code:
helpers\FlashMessages::error()
everytime so I wrapped it inside a function error() and using that instead,

thanks for your feedback btw :)
 
git bisect -m
Loyal Member
Joined
Sep 2, 2011
Messages
2,171
Reaction score
916
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

3M1L

I'm using my own Query Builder (already mentioned it at the beginning of this thread).

I would recommend you this.:

Exactly which parts does look like a mess? And how would you prefer doing it?

The whole snippets looks like a mess (not organized) but maybe this be a RaGEZONE thing.


I'm not using any AJAX to submit forms (should I start doing it?).

If you're using Angular, no need of it. Angular actually does the communication. I personally don't like anymore Angular. xD

Redirecting all "backend stuff" to index.php would just be a mess that's why I keep them in seperate files e.g 'actions/users/update.php, /actions/users/add.php', or have I missunderstood you?


You can create a router.php and a RewriteRule, maybe route.php?action=$1 to /actions/ActionName

The Route will call an ActionHandler that will validate some pre-stuff, and after that call a ActionFactory that will handle the correct Action. No need of turn each action script an independent file. That's a security issue.

I also recommend you block the access of the browser directly to the actions.

You can make an Interface called ActionInterface, after that a AbstractAction Class that it's an Abstract Class that pre-implement the Interface. After that you will have each Action like AddUserAction.php, that are classes. From a specific namespace.

The ActionFactory check the existence of the Action from the Namespace, etc.etc.

That's a more proper way of do Action Routing.

Give a look here.: (i don't like this page, but anyways... it's a start.)

Anyways, using PDO it's nice.


I will begin with documentations, It's indeed important I agree, but in most cases I name methods in a "self-explanatory" way.


A good developer first do the Software Design, and after that, does the implementation. Documentation it's more important in some points that the code itself. The whole software design/concept will decide if the code will be good or not.

Doing some State Machine and Usability Diagrams will help you a lot.

For something more basics, start the code from the Interfaces & Models, that are the minor artifacts in a software. Don't start by the Controllers. Try think how your system will be before coding it. Take control of it.


The UserFactory component is quite old (yes, also mentioned it at the beginning of this thread that some components can be old) but I should probably rewrite them according to the PSR.

Remember, PSR it's not mandatory.

I assume you're meaning that I should return an User object ^?

You agree with me that all returned messages from the backend will be jSON, right? jSON handles everything as objects. You actually if think in a RESTful way, you can think that everything in your system aren't simple responses from the Database. But Actors and Artifacts from your system. User isn't simple the user table. It's an entity called User.

Simple changes give a more business way of your system.


The reason I return a boolean instead of an empty object is because I feel more comfortable with it, or is there a rule for this too?

You can avoid the false. PDO actually will return a false if doesn't exists a row with the following queries/filters. By default will return false, except count() methods that returns 0 by default, and false on error.

The function error() is a global function for Flash Messages, but I'm too lazy to write
Code:
helpers\FlashMessages::error()
everytime so I wrapped it inside a function error() and using that instead,


Don't be lazy with your own code. That's a primordial rule.

Anyways, good luck for you.!!! Best wishes.
 
Experienced Elementalist
Joined
Jul 31, 2012
Messages
268
Reaction score
100
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

samuus

I might as well start using the MVC pattern, seems like it's the cleanest way from this point of view :)
 
Experienced Elementalist
Joined
Jul 31, 2012
Messages
268
Reaction score
100
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

I've decided to use MVC & I'll recode the current source to follow the MVC pattern.
Otherwise it's gonna get REALLY messy without MVC if I continue this way so.. :):
 
Last edited by a moderator:
"(still lacks brains)"
Loyal Member
Joined
Sep 2, 2011
Messages
2,371
Reaction score
1,361
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

I've decided to use MVC & I'll recode the current source to follow the MVC pattern.
Otherwise it's gonna get REALLY messy without MVC if I continue this way so.. :):

Just use a framework...



 
git bisect -m
Loyal Member
Joined
Sep 2, 2011
Messages
2,171
Reaction score
916
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

Just use a framework...




For something small like this Housekeeping i wouldn't recommend this.

Use Laravel Lumen:

Uses the same API of Laravel but is really tiny.

It's like a ZeptoJS for jQuery, but in this case it's a PHP Framework xD

Observation.: I personally don't like CakePHP
 
"(still lacks brains)"
Loyal Member
Joined
Sep 2, 2011
Messages
2,371
Reaction score
1,361
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

For something small like this Housekeeping i wouldn't recommend this.

Use Laravel Lumen:

Uses the same API of Laravel but is really tiny.

It's like a ZeptoJS for jQuery, but in this case it's a PHP Framework xD

Observation.: I personally don't like CakePHP

Sure, use Lumen if you want less flexibility. Lumen is designed for high performance applications or API's. Usage of a full framework for a Housekeeping is perfect, don't use a micro-framework unless you are 100% sure you want to deal with the potential issues in the long run.
 
◝(⁰▿⁰)◜Smile◝ (⁰▿⁰)◜
Developer
Joined
May 29, 2007
Messages
2,167
Reaction score
899
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

For something small like this Housekeeping i wouldn't recommend this.

Use Laravel Lumen:
Uses the same API of Laravel but is really tiny.

It's true it might be a small framework but you'll actually need all of the features of Laravel.

Lummen doesn't even have Blade (the templating engine) in it's package. Lummen is good for APIs. I get your Point of view because it's Angular and it uses API calls. I personally think it's better to go with the whole package.



Also Eloquent is disabled by default in Lummen. It's not hard to enable it but it's worth mentioning.
 
git bisect -m
Loyal Member
Joined
Sep 2, 2011
Messages
2,171
Reaction score
916
Re: BlackWolf - Housekeeping (standalone) - [PHP 5.6+/PDO/OOP/TPL/Angular]

It's true it might be a small framework but you'll actually need all of the features of Laravel.

Lummen doesn't even have Blade (the templating engine) in it's package. Lummen is good for APIs. I get your Point of view because it's Angular and it uses API calls. I personally think it's better to go with the whole package.



Also Eloquent is disabled by default in Lummen. It's not hard to enable it but it's worth mentioning.

Thanks for understand my point, that was exactly this. Since Angular will do all the front-end things i don't think that a robust framework it's necessary, since in certain point, the views will be only jSON.

Angular will threat, handle and parse the template. At least is how Habbo actually does.

But if need MVC in the Houskeeping (i don't know why will need this, if the views are simply jSON, i don't get why NoBrain criticized me...) so it's better using Laravel.

For High Performance Applications, i personally like PhalconPHP..

But we don't will enter in discussion here of which Framework is better for the author, he can decide this of it's own way. Many frameworks have the basics, the same basics, in different ways.

Also i don't like using a super framework, i know that Laravel does modularization and has packages and a core package, you can even manage it with Composer, but anyways, it's a housekeeping... Not a complete CMS...

He need basically Angular Features, MVC, QueryBuilder and nothing more...

If he want to do the basics. Anyways, who will handle all those front-end things it's the Angular by itself.

I actually coded HabboWEB without the usage of any Framework, code wasn't 100% correct, but wasn't a mess at all.

Anyways, 3M1L good luck for your Housekeeping, i hope you conclude it, since this year we had many Housekeepings and no one finished.
 
Status
Not open for further replies.
Back
Top