-
Nano - PHP7, MVC, PDO
http://i.imgur.com/4kbfweb.png
Nano is a lightweight, clean & fast Content Management System (CMS) which follows the MVC architecure and is based on a modern, stable and extensible base.
Features:
- Secure - Prepared statements, validated data & sanitized output, CSRF protection (A secure token is generated and restricted, can only be used for the form which it was generated for & only valid for one use), Bot/brute-force protection (A user can only attempt to login once every so interval otherwise a short suspension will be given which isn't really recognizable to legitimate users but will have a big impact on bots, also uses Google reCaptcha for registration and such), secure password hashing, protection for session-based attacks, click-jacking protection, plus other useful basic measures.
- Native language system - No requests to external services, all major site content can be modified on a per language level.
- Session manager - A very simple and clean wrapper to interact with session data.
- Extensions - Easily add extensions to the CMS and utilize functionality on either a global scale or per request.
- Themes - Multiple theme support, all functionality will be available regardless of theme in-use as this logic is separated and maintained.
- Advanced logging - Extremely useful logging, error/warning/notice stack traces will be logged to a local file and the user will be displayed a friendly message.
- Events - Trigger & fire user defined callback events, useful for things like proxy/ban checking.
Completed:
- Base functionality - Routing, user system, language system, error/success flash messages + more.
- Articles - Toggle categories, likes, responses.
- Mail integration - Can be used to send account activation/forgot password e-mails to users.
- Logging system - Can be used to log errors/warnings of the CMS or even log misc information such as attack attempts or visits to certain pages containing useful information of the request such as user agent, IP, time, etc.
- Various pages - A number of pages have been implemented such as me, account settings, articles, staff and client.
Snippets:
Some functions
Code:
/**
* [authenticate is a function to validate user credentials]
* @param string $username [The username to attempt]
* @param string $password [The password to attempt]
* @return bool [Whether or not the combination was correct]
*/
public function authenticate(string $username, string $password): bool {
if($this->usernameTaken($username)){
$hash = $this->engine->fetch("SELECT password FROM users WHERE username = ?", array($username))->password;
if($this->secure->basicVerify($password, $hash)){
return true;
}else{
$this->session->increment('security', 'attempts');
$this->session->set('time', time(), 'security');
return false;
}
}else{
return false;
}
}
/**
* [usernameTaken is a function to check if a username is in-use]
* @param string $username [The username to check]
* @return bool [Whether or not the username is in-use]
*/
public function usernameTaken(string $username): bool {
$checkUsername = $this->engine->fetch("SELECT null FROM users WHERE username = ?", array($username));
if($checkUsername){
return true;
}else{
return false;
}
/**
* [getStaff is a function to get the list of staff members]
* @return array [All staff ranks and their respective members]
*/
public function getStaff(){
$ranks = \Flight::engine()->fetchAll(
"SELECT
r.id, r.name
FROM
ranks r
CROSS JOIN
site_permissions p
WHERE
p.permission = ?
AND
r.id >= p.min_rank
ORDER BY
r.id
DESC",
array('display_staff')
);
$rank = [];
foreach($ranks as $r){
$staff = \Flight::engine()->fetchAll("SELECT id, username, motto, look, online FROM users WHERE rank = ?", array($r->id));
$rank[$r->name] = $staff;
}
return $rank;
}
Index Controller
Code:
namespace Acme\Controllers;
use Library\Extensions\{IndexUserMessage, Ext};
class IndexController extends Controller {
public function __construct(){
parent::__construct();
self::$event->register('checkBan');
self::$event->fire();
}
public static function show(){
if(!self::$user->active()){
return \Flight::view()->display('index.tpl', [
'error' => self::$session->getFlash('error'),
'success' => self::$session->getFlash('success'),
'form_token_login' => self::$secure->macGenerate('/'),
'locale' => self::$locale->get('index')
]);
}else{
\Flight::redirect('me');
exit();
}
}
}
Images:
Libraries currently in use: Mailgun, Twig, Flight, and Monolog.
Credits:
Geo - Developer
Brought & Sex - Moral support
Cammex - Cammex theme (Default theme I used to develop alongside Nano)
-
Re: Nano - PHP7, MVC, PDO
Your Project looks very nice, I hope you'll pull through it!
Yours Sincerely,
Sonay:love:
-
Re: Nano - PHP7, MVC, PDO
I liked the design, 7/10. Only one concepts aren't good in my personal vision.
A little tip: Try doing smaller functions, big functions are against PSR-*.
See about PSR-0, PSR-2, PSR-4 and PSR-5 here: PHP-FIG â PHP Framework Interop Group
PSR's are the PHP Standards.
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
ovflowd
I liked the design, 7/10. Only one concepts aren't good in my personal vision.
A little tip: Try doing smaller functions, big functions are against PSR-*.
See about PSR-0, PSR-2, PSR-4 and PSR-5 here:
PHP-FIG â PHP Framework Interop Group
PSR's are the PHP Standards.
Functions or methods in this case?
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
3M1L
Functions or methods in this case?
Yes methods, if are in a class. Functions if not.
-
Re: Nano - PHP7, MVC, PDO
The code is very clean, although I'm not fond of the design but again, some aspects are nice!
Overall, seems good so I shall be following your development.
-
Re: Nano - PHP7, MVC, PDO
Thanks for the feedback! Just to note this development is still on-going even though there hasn't been much updates recently, I have my hands full at the moment with some other things but it will continue as soon as things are out of the way.
Yeah the design isn't too great, I used an already released theme and adapted it as I'm not really that good/interested in design although anyone who would like to develop a theme for the CMS would be welcome to do so.
Quote:
Originally Posted by
ovflowd
I liked the design, 7/10. Only one concepts aren't good in my personal vision.
A little tip: Try doing smaller functions, big functions are against PSR-*.
See about PSR-0, PSR-2, PSR-4 and PSR-5 here:
PHP-FIG â PHP Framework Interop Group
PSR's are the PHP Standards.
What do you mean by smaller functions, was there a specific function in the snippets provided which you could pick out?
Most of the code is quite minimal in this overall, I have also followed the majority of PSR standards which I believed were appropriate and appealed to me.
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
Geo
Thanks for the feedback! Just to note this development is still on-going even though there hasn't been much updates recently, I have my hands full at the moment with some other things but it will continue as soon as things are out of the way.
Yeah the design isn't too great, I used an already released theme and adapted it as I'm not really that good/interested in design although anyone who would like to develop a theme for the CMS would be welcome to do so.
What do you mean by smaller functions, was there a specific function in the snippets provided which you could pick out?
Most of the code is quite minimal in this overall, I have also followed the majority of PSR standards which I believed were appropriate and appealed to me.
Code re-usability. I'm only giving a tip. Don't love so much your code. A good developer hate his own code. It's ironically good, because you see your code in a other way/angle. Improving code it's a endless to-do of a good developer.
Good luck.
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
ovflowd
Code re-usability. I'm only giving a tip. Don't love so much your code. A good developer hate his own code. It's ironically good, because you see your code in a other way/angle. Improving code it's a endless to-do of a good developer.
Good luck.
How can you judge code re-usability with little information regarding those aspects of the inner workings behind the CMS? Yes, I'm always going back and forth improving certain parts of the CMS but a lot of the current functionality is pretty re-usable; a few examples below.
E.g. the same getArticle() function is used to display 3 articles for the (/me) page, contents of an article page (/article/welcome-to-habbo), articles navigation list and also within the housekeeping to list the articles (/admin/articles).
usernameTaken() is used on the registration and login, to check if the username already exists before processing the response based on the result appropriately, either registering the new user/error or signing the user in/error.
Administration/ArticleController:
https://i.imgur.com/yRme7lq.png
Admin articles view:
https://i.imgur.com/5pTICpB.gif
Articles view template:
Code:
{% if articles %}
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Preview</th>
<th>Slug</th>
<th>Published</th>
<th>Author</th>
<th>Category</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for article in articles %}
<tr>
<td>{{ article.id }}</td>
<td>{{ article.title }}</td>
<td>{{ article.preview }}</td>
<td>{{ article.slug }}</td>
<td>{{ article.published }}</td>
<td>{{ article.author }}</td>
<td>{{ article.category }}</td>
<td>
<div class="btn-group-vertical">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Manage <span class="caret"></span>
</button>
<ul class="dropdown-menu" style="position:relative">
{% if article.live == true %}
<li><a href="/admin/articles/withdraw/{{ article.id }}">Withdraw</a></li>
{% else %}
<li><a href="/admin/articles/publish/{{ article.id }}">Publish</a></li>
{% endif %}
<li><a href="/admin/articles/edit/{{ article.id }}">Edit</a></li>
<li><a href="/admin/articles/delete/{{ article.id }}">Remove</a></li>
</ul>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
No articles have been published yet, <a href="/admin/articles/compose">compose</a> one?
{% endif %}
-
Re: Nano - PHP7, MVC, PDO
This looks smooth and fresh @Geo and who cares what ovflowd says. He says so many shit on every project about 'bad code'.
-
Re: Nano - PHP7, MVC, PDO
Which template engine you use? Looks interesting. This remember me Jinja (Python Template Engine)
-
Re: Nano - PHP7, MVC, PDO
Absolutely flawless coding style, quite nice project mate
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
ovflowd
Which template engine you use? Looks interesting. This remember me Jinja (Python Template Engine)
Twig.
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
ovflowd
Which template engine you use? Looks interesting. This remember me Jinja (Python Template Engine)
I'm using Twig as mentioned above and in my original post, it probably reminds you of Jinja because they are both template engines following the Django/like syntax.
-
Re: Nano - PHP7, MVC, PDO
Do you mind posting your event manager class? :)
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
3M1L
Do you mind posting your event manager class? :)
PHP Code:
<?php
declare(strict_types=1);
namespace Library\Components\Storage;
class Event {
protected $callbacks = [];
public function __construct(){}
/**
* [register is a function to register callback events]
* [MENTION=2000183830]para[/MENTION]m string $callback [The callback to register]
*/
public function register(string $callback){
$this->callbacks[] = $callback;
}
/**
* [fire is a function to fire a single or all callback events]
* [MENTION=2000183830]para[/MENTION]m string $call [The callback to fire] [Optional]
* [MENTION=850422]return[/MENTION] mixed [The respective fired callback event]
*/
public function fire(callable $call = null){
if(!$call){
foreach($this->callbacks as $callback){
call_user_func([$this, $callback]);
}
}else{
call_user_func([$this, $call]);
}
}
}
?>
Also some updates on the housekeeping, I worked a little more on the article management:
https://i.imgur.com/9SctRaL.png
-
Re: Nano - PHP7, MVC, PDO
Im interested in how the progress of this cms is going on.
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
Geo
Good updates, but i don't recommend to use "hosted" images in cms, leave author decide url of image... (Of corse if hosted in own cms will make a faster site, but also heavier)
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
rafa95123
Good updates, but i don't recommend to use "hosted" images in cms, leave author decide url of image... (Of corse if hosted in own cms will make a faster site, but also heavier)
Also, it would be good just if you could prevew what image you are picking. Choosing by name sucks.
Would prefer the size of the news in the home page being just like old school habbo. Already has a lot of images ready to be used in that square format.
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
rafa95123
Good updates, but i don't recommend to use "hosted" images in cms, leave author decide url of image... (Of corse if hosted in own cms will make a faster site, but also heavier)
Do you mean article content images or the actual image of each article? Article images are stored in the CMS folder, but you are able to link any image URL for the content images e.g. the elphpant image above.
Quote:
Originally Posted by
Japaojp
Also, it would be good just if you could prevew what image you are picking. Choosing by name sucks.
Would prefer the size of the news in the home page being just like old school habbo. Already has a lot of images ready to be used in that square format.
You can preview the image, you select a name from the dropdown list and then select the blue "preview" text seen next to the "Image" label; this opens up a modal showing you details of the image such as it's name and the actual image preview.
-
Re: Nano - PHP7, MVC, PDO
The preview is to complicated like @Japaojp was saying. The link and modal is nice but not user friendly.
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
Geo
Do you mean article content images or the actual image of each article? Article images are stored in the CMS folder, but you are able to link any image URL for the content images e.g. the elphpant image above.
The actual image of each article, cause if stay with CMS will make her heavier. I prefer leave author decides with a external link...
-
Re: Nano - PHP7, MVC, PDO
I noticed an inconsistency, it seems that you use array() in your first example and in your others you use []; I Think you should fix that inconsistency issue. Since it's 7 you should stick with [];
-
Re: Nano - PHP7, MVC, PDO
Quote:
Originally Posted by
rafa95123
The actual image of each article, cause if stay with CMS will make her heavier. I prefer leave author decides with a external link...
Yes that may make the author feel like they have more accessibility but it would also affect performance and security, it may also affect the appearance of the site as they may link an URL of an image which for example has different sizes to the standard articles images or even a dead/blocked image link.
Quote:
Originally Posted by
CodeDragon
I noticed an inconsistency, it seems that you use array() in your first example and in your others you use []; I Think you should fix that inconsistency issue. Since it's 7 you should stick with [];
I use a mixture of both syntax styles, mainly the short syntax for shorter logic such as returning data alongside a view whilst I mainly use the standard syntax style for larger arrays, sometimes even both syntax styles are used for things like hash tables.
Doesn't make much of a difference which is used on the current version as both are compatible, just more of a personal preference really.