VENOM-10: Moved to new Module Structure

Fixed File-Endings
Added Entity-System
This commit is contained in:
Maurice Grönwoldt 2021-01-03 16:59:11 +01:00
parent 32a78ed1b9
commit eb6770204a
101 changed files with 1272 additions and 892 deletions

View file

@ -1,18 +1,18 @@
<?php <?php
use Venom\Core\Config; use Venom\Core\Config;
use Venom\Core\DatabaseHandler; use Venom\Core\Database\Database;
$config = Config::getInstance(); $config = Config::getInstance();
$config->setVersion(1.0); $config->setVersion(1.0);
$config->setDatabase([ $config->setDatabase([
DatabaseHandler::DB_TYPE => 'mysql', //please change only if you know what you're doing! this can break a lot. Database::DB_TYPE => 'mysql', //please change only if you know what you're doing! this can break a lot.
DatabaseHandler::DB_HOST => '127.0.0.1', Database::DB_HOST => '127.0.0.1',
DatabaseHandler::DB_PORT => '3306', //default port is 3306 Database::DB_PORT => '3306', //default port is 3306
DatabaseHandler::DB_USER => 'venom', Database::DB_USER => 'venom',
DatabaseHandler::DB_PASSWORD => 'venomPassword', Database::DB_PASSWORD => 'venomPassword',
DatabaseHandler::DB_DB => 'venomCMS', Database::DB_DB => 'venomCMS',
DatabaseHandler::DB_EXTRA => '' // need to start with ';' Database::DB_EXTRA => '' // need to start with ';'
]); ]);
/** /**

0
base/lang.base.php Normal file → Executable file
View file

View file

@ -1,9 +1,4 @@
<?php <?php
//register modules -> need to have the Module Class at parent with the init function ;) //register modules -> only apply Module Path! like Meta now the ModuleLoader search for /modules/Meta/module.php!
$modules = []; $modules = [];
// register controllers that can handle templates ;) need to have a render function for this
$controllers = [
'test' => \Controllers\TestController::class,
];

18
base/router.base.php Normal file → Executable file
View file

@ -11,19 +11,5 @@ if (!isset($venom)) {
exit(1); exit(1);
} }
$router = new Router('defaultRouter', 1.0, 'api/'); $router = new Router(Router::DEFAULT_ROUTER, 1.0, 'api/');
$router->addRoutes([ $venom->addRouter($router);
'/test' => [
'cl' => Route::class,
'roles' => ['ROLE_GUEST'],
'routes' => [
'*' => [
"GET" => 'getAll'
],
'1' => [
"GET" => 'getAll'
]
]
],
]);
$venom->addRouter('defaultRouter', $router);

0
conf/.gitkeep Normal file → Executable file
View file

View file

@ -46,7 +46,7 @@ create table if not exists users
password varchar(255) not null, password varchar(255) not null,
token varchar(255) not null, token varchar(255) not null,
salt varchar(255) not null, salt varchar(255) not null,
roles text default 'ROLE_GUEST' not null, roleId text default '0' not null,
isActive tinyint(1) default 1 null isActive tinyint(1) default 1 null
) )
comment 'User File'; comment 'User File';

0
lang/example.php Normal file → Executable file
View file

0
public/.htaccess Normal file → Executable file
View file

0
public/content/.gitkeep Normal file → Executable file
View file

0
public/theme/admin/css/admin-panel.css Normal file → Executable file
View file

0
public/theme/admin/css/login.css Normal file → Executable file
View file

0
public/theme/admin/css/style.css Normal file → Executable file
View file

0
public/theme/admin/icon-sprite.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

0
public/theme/admin/images/logo.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

0
public/theme/admin/js/components.js Normal file → Executable file
View file

0
public/theme/admin/js/components.min.js vendored Normal file → Executable file
View file

0
public/theme/admin/js/scripts.js Normal file → Executable file
View file

0
public/theme/admin/js/scripts.min.js vendored Normal file → Executable file
View file

0
public/theme/default/css/test.css Normal file → Executable file
View file

0
public/theme/default/js/test.js Normal file → Executable file
View file

6
src/Venom/Admin/AdminController.php Normal file → Executable file
View file

@ -4,12 +4,12 @@
namespace Venom\Admin; namespace Venom\Admin;
use Venom\Entities\RoleEntity;
use Venom\Helper\URLHelper; use Venom\Helper\URLHelper;
use Venom\Security\Security;
use Venom\Views\Asset; use Venom\Views\Asset;
use Venom\Views\RenderController; use Venom\Views\RenderController;
use Venom\Views\VenomRenderer; use Venom\Views\VenomRenderer;
use Venom\Models\User;
use \Venom\Security\Security;
class AdminController implements RenderController class AdminController implements RenderController
@ -29,7 +29,7 @@ class AdminController implements RenderController
$this->tpl = 'async'; $this->tpl = 'async';
} }
$isLogin = Security::get()->hasRole(User::ADMIN_ROLE); $isLogin = Security::get()->hasPermission("admin", RoleEntity::TYPE_READ);
$renderer->addVar('isLoggedIn', $isLogin); $renderer->addVar('isLoggedIn', $isLogin);
if (!$isLogin) { if (!$isLogin) {
Asset::get()->addCSS('login', 'login.css'); Asset::get()->addCSS('login', 'login.css');

View file

@ -1,26 +0,0 @@
<?php
namespace Venom\Admin;
use Modules\Meta\MetaDataModule;
use Modules\PageModule;
use Modules\RoleModule;
use Modules\SeoUrlModule;
use Modules\User\UserModule;
use Modules\VenomStatusModule;
class AdminModulesLoader
{
public static function getModules(): array
{
return [
'metaData' => MetaDataModule::class,
'pages' => PageModule::class,
'role' => RoleModule::class,
'seoUrl' => SeoUrlModule::class,
'users' => UserModule::class,
'venomStatus' => VenomStatusModule::class,
];
}
}

19
src/Venom/Admin/AdminRouterInit.php Normal file → Executable file
View file

@ -6,6 +6,7 @@ namespace Venom\Admin;
use Venom\Admin\Routes\LoginRoute; use Venom\Admin\Routes\LoginRoute;
use Venom\Admin\Routes\TemplateLoader; use Venom\Admin\Routes\TemplateLoader;
use Venom\Routing\Route;
use Venom\Routing\Router; use Venom\Routing\Router;
use Venom\Venom; use Venom\Venom;
@ -19,27 +20,19 @@ class AdminRouterInit
public static function getRoutes(): array public static function getRoutes(): array
{ {
return [ return [
'/login' => [ '/login' => new Route(LoginRoute::class, [
'cl' => LoginRoute::class,
'roles' => ['ROLE_GUEST'],
'routes' => [
'*' => [ '*' => [
"POST" => 'login' "POST" => 'login'
], ],
'1' => [ '1' => [
"GET" => 'handle' "GET" => 'handle'
] ]
] ]),
], '/templateLoader' => new Route(TemplateLoader::class, [
'/templateLoader' => [
'cl' => TemplateLoader::class,
'roles' => ['ROLE_GUEST'],
'routes' => [
'*' => [ '*' => [
"GET" => 'handle' "GET" => 'handle'
] ],
] ]),
]
]; ];
} }
} }

4
src/Venom/Admin/Routes/LoginRoute.php Normal file → Executable file
View file

@ -4,11 +4,9 @@
namespace Venom\Admin\Routes; namespace Venom\Admin\Routes;
use Venom\Core\ArgumentHandler;
use Venom\Routing\Route;
use Venom\Security\Security; use Venom\Security\Security;
class LoginRoute implements Route class LoginRoute
{ {
public function login(): bool public function login(): bool

3
src/Venom/Admin/Routes/TemplateLoader.php Normal file → Executable file
View file

@ -6,9 +6,8 @@ namespace Venom\Admin\Routes;
use Venom\Core\ArgumentHandler; use Venom\Core\ArgumentHandler;
use Venom\Core\Config; use Venom\Core\Config;
use Venom\Helper\TemplateUtil; use Venom\Helper\TemplateUtil;
use Venom\Routing\Route;
class TemplateLoader implements Route class TemplateLoader
{ {
public function handle(): bool public function handle(): bool
{ {

2
src/Venom/Controller/SeoController.php Normal file → Executable file
View file

@ -6,7 +6,7 @@ namespace Venom\Controller;
use Venom\Core\ArgumentHandler; use Venom\Core\ArgumentHandler;
use Venom\Core\Config; use Venom\Core\Config;
use Venom\Core\DatabaseHandler; use Venom\Core\Database\DatabaseHandler;
use Venom\Helper\ErrorHandler; use Venom\Helper\ErrorHandler;
use Venom\Helper\URLHelper; use Venom\Helper\URLHelper;

3
src/Venom/Core/Config.php Normal file → Executable file
View file

@ -2,7 +2,8 @@
namespace Venom\Core; namespace Venom\Core;
use Venom\Models\ConfigObject; use Venom\Core\Database\DatabaseHandler;
use Venom\Entities\ConfigObject;
class Config class Config
{ {

View file

@ -0,0 +1,102 @@
<?php
namespace Venom\Core\Database;
// class that hold the Database Connection! and Executes like the DatabaseHandler
use PDO;
use PDOException;
use PDOStatement;
use Venom\Entities\DatabaseObject;
class Database
{
// constants
public const DB_TYPE = 'type';
public const DB_HOST = 'host';
public const DB_PORT = 'port';
public const DB_USER = 'user';
public const DB_PASSWORD = 'pw';
public const DB_DB = 'db';
public const DB_EXTRA = 'extra';
private ?\PDO $db = null;
public function init(array $data): void
{
//init instance with the current data... only working if the db is not init!
if ($this->db != null) {
return;
}
$dsn = '%s:host=%s;dbname=%s;port=%s';
$connectString = sprintf($dsn, $data[self::DB_TYPE], $data[self::DB_HOST], $data[self::DB_DB], $data[self::DB_PORT] . $data[self::DB_EXTRA]);
try {
$this->db = new PDO($connectString, $data[self::DB_USER], $data[self::DB_PASSWORD]);
} catch (PDOException $e) {
trigger_error($e->getMessage());
die($e->getCode());
}
}
public function getOne(string|EasyQuery $query, array $args = []): ?DatabaseObject
{
$sql = $query;
if ($query instanceof EasyQuery) {
$sql = $query->getQuery();
$args = $query->getArgs();
}
$data = $this->getAll($sql, $args);
if (count($data) > 0) {
return $data[0];
}
return null;
}
public function getAll(string|EasyQuery $query, array $args = []): array
{
$sql = $query;
if ($query instanceof EasyQuery) {
$sql = $query->getQuery();
$args = $query->getArgs();
}
$stmt = $this->db->prepare($sql);
$stmt->setFetchMode(PDO::FETCH_CLASS, DatabaseObject::class);
$stmt->execute($args);
return $stmt->fetchAll();
}
public function execute(string|EasyQuery $query, array $args = []): bool
{
$sql = $query;
if ($query instanceof EasyQuery) {
$sql = $query->getQuery();
$args = $query->getArgs();
}
$stmt = $this->db->prepare($sql);
return $stmt->execute($args);
}
public function createStatement($query): bool|PDOStatement
{
$stmt = $this->db->prepare($query);
$stmt->setFetchMode(PDO::FETCH_CLASS, DatabaseObject::class); // set to default fetch-mode :D
return $stmt;
}
public function setClass($stmt, $class)
{
$stmt->setFetchMode(PDO::FETCH_CLASS, $class);
}
public function start()
{
$this->db->beginTransaction();
}
public function commit()
{
$this->db->commit();
}
public function rollBack()
{
$this->db->rollBack();
}
}

View file

@ -0,0 +1,38 @@
<?php
namespace Venom\Core\Database;
class DatabaseHandler
{
private static ?DatabaseHandler $instance = null;
private Database $db;
private array $cache; //EntityManager Cache!
protected function __construct()
{
$this->db = new Database();
}
public static function get(): Database
{
return self::getInstance()->db;
}
public static function getInstance(): DatabaseHandler
{
if (self::$instance === null) {
self::$instance = new DatabaseHandler();
}
return self::$instance;
}
public static function getEntityManager($entityClass): EntityManager
{
$instance = self::getInstance();
// i dont make sure this class exist because the user should do this ;)
if (!isset($instance->cache[$entityClass])) {
$instance->cache[$entityClass] = new EntityManager($entityClass, self::get());
}
return $instance->cache[$entityClass];
}
}

View file

@ -0,0 +1,220 @@
<?php
namespace Venom\Core\Database;
// the QueryBuilder is stupid! dont use it for Very Complex Queries because it's should do Entity Loading Easier :)
class EasyQuery
{
const ORDER_ASC = 0;
const ORDER_DESC = 1;
const WHERE_AND = "AND";
const WHERE_AND_NOT = "AND NOT";
const WHERE_OR = "OR";
const WHERE_OR_NOT = "OR NOT";
const WHERE_NOT = "NOT";
private array $where = [];
private array $args = [];
private string $query = "";
private int $limit = -1;
private int $offset = 0;
private string $whereStmt = "";
private string $havingStmt = "";
private array $order = [];
private array $groupBy = [];
private array $having = [];
public function __construct(private string $tableName, private array $fields = [])
{
}
public static function createSelect(array $fields, string $table): string
{
return "SELECT " . implode(", ", $fields) . " FROM " . $table;
}
public function setWhere(string $statement): static
{
$this->whereStmt = $statement;
return $this;
}
public function setHaving(string $statement): static
{
$this->havingStmt = $statement;
return $this;
}
public function setLimit(int $limit): static
{
$this->limit = $limit;
return $this;
}
public function setOffset(int $offset): static
{
$this->offset = $offset;
return $this;
}
public function addField($field, $as = ""): static
{
if ($as !== "") {
$field .= " AS " . $as;
}
$this->fields[] = $field;
return $this;
}
public function addFields(array $fields): static
{
foreach ($fields as $field) {
$this->fields[] = $field;
}
return $this;
}
public function where($key, $value, $type = "AND"): static
{
$this->where[] = [$key, $type];
$this->args[":" . $key] = $value;
return $this;
}
public function having($key, $value, $type = "AND"): static
{
$this->having[] = [$key, $type];
$this->args[":" . $key] = $value;
return $this;
}
public function orderBy(string $key, int $mode = self::ORDER_ASC): static
{
$this->order[] = $mode === self::ORDER_DESC ? $key . " DESC" : $key;
return $this;
}
public function groupBy(string $key): static
{
$this->groupBy[] = $key;
return $this;
}
public function setArg($key, $value): static
{
$this->args[":" . $key] = $value;
return $this;
}
// returns a Query
public function addArgAndField($key, $value): static
{
$this->args[":" . $key] = $value;
$this->fields[] = $key;
return $this;
}
public function buildSelect(): static
{
// we build an easyQuery Builder that can very easy stuff
$query = self::createSelect($this->fields, $this->tableName);
if (count($this->where) > 0) {
$this->whereStmt = $this->parseStmt($this->where, $this->whereStmt);
}
if (count($this->having) > 0) {
$this->havingStmt = $this->parseStmt($this->having, $this->havingStmt);
}
if ($this->whereStmt !== "") {
$query .= " WHERE " . $this->whereStmt;
}
if (count($this->groupBy)) {
$query .= " GROUP BY " . implode(", ", $this->groupBy);
}
if ($this->havingStmt !== "") {
$query .= " HAVING " . $this->havingStmt;
}
if (count($this->order)) {
$query .= " ORDER BY " . implode(", ", $this->order);
}
if ($this->offset > 0) {
$query .= " OFFSET " . $this->offset;
}
if ($this->limit > 0) {
$query .= " LIMIT " . $this->limit;
}
$this->query = $query;
return $this;
}
public function buildInsertQuery(): static
{
$query = "INSERT INTO " . $this->tableName;
$joinedFields = implode(", ", $this->fields);
$values = implode(", ", array_keys($this->args));
$query .= "(" . $joinedFields . ") VALUES (" . $values . ")";
$this->query = $query;
return $this;
}
public function buildUpdateQuery(): static
{
$query = "UPDATE " . $this->tableName . " SET ";
$setFields = [];
foreach ($this->fields as $field) {
$setFields[] = $field . " = :" . $field;
}
$query .= implode(", ", $setFields);
if (count($this->where) > 0) {
$this->whereStmt = $this->parseStmt($this->where, $this->whereStmt);
}
if ($this->whereStmt !== "") {
$query .= " WHERE " . $this->whereStmt;
}
$this->query = $query;
return $this;
}
public function buildDeleteQuery(): static
{
$query = "DELETE FROM " . $this->tableName;
if (count($this->where) > 0) {
$this->whereStmt = $this->parseStmt($this->where, $this->whereStmt);
}
if ($this->whereStmt !== "") {
$query .= " WHERE " . $this->whereStmt;
}
$this->query = $query;
return $this;
}
public function getQuery(): string
{
return $this->query;
}
public function getArgs(): array
{
return $this->args;
}
public function getFields(): array
{
return $this->fields;
}
private function parseStmt($items, $default = ""): string
{
$query = $default;
foreach ($items as $item) {
if ($query !== "") {
$query .= " " . $item[1] . " ";
}
if ($item[1] === self::WHERE_NOT && $query === "") {
$query .= "NOT ";
}
$query .= $item[0] . " = :" . $item[0];
}
return $query;
}
}

View file

@ -0,0 +1,127 @@
<?php
namespace Venom\Core\Database;
// Entity has a Load and Save function!
// The Entity needs to have a primary key... most of the time this is a id!
use JsonSerializable;
use RuntimeException;
abstract class Entity implements JsonSerializable
{
public static string $tableName = "";
// make sure this exists!
public int $id = -1;
public string $primaryKey = "id";
public array $loadedFields = [];
public array $blackList = ["id"];
// Please override this Property in the Class you implement the Abstract Class! this is needed to run the right SQL calls
public ?array $fields = null;
// Override this if you want special fields :)
public function getFieldsToWrite(): array
{
if ($this->fields !== null) {
return $this->fields;
}
$localBlacklist = array_merge(["primaryKey", "tableName", "loadedFields", "blackList", "fields"], $this->blackList);
$allLoaded = in_array("*", $this->loadedFields);
$vars = get_object_vars($this);
foreach ($vars as $key => $var) {
if (in_array($key, $localBlacklist)) {
unset($vars[$key]);
}
}
if (!$allLoaded) {
foreach ($vars as $key => $var) {
if (!in_array($var, $this->loadedFields)) {
unset($vars[$key]);
}
}
}
unset($vars[$this->primaryKey]);
$this->fields = $vars;
return $this->fields;
}
public function save(): bool
{
$this->preSave();
$primaryKey = $this->primaryKey;
$fields = $this->removeEmptyFields($this->getFieldsToWrite());
$query = new EasyQuery(static::$tableName);
foreach ($fields as $key => $field) {
$query->addArgAndField($key, $field);
}
if ($this->$primaryKey === "") {
$query->buildInsertQuery();
} else {
$query->where($primaryKey, $this->$primaryKey)->buildUpdateQuery();
}
return DatabaseHandler::get()->execute($query);
}
public function load($fields = ['*'], ?EasyQuery $query = null): static
{
if ($query === null) {
$primaryKey = $this->primaryKey;
$query = new EasyQuery(static::$tableName, $fields);
$query->where($primaryKey, $this->$primaryKey)->setLimit(1)->buildSelect();
} else {
$query->setLimit(1)->buildSelect();
}
$item = DatabaseHandler::get()->getOne($query);
if ($item === null) {
return $this;
}
$lazy = $item->getData();
$this->id = $item->id;
foreach ($lazy as $key => $item) {
$this->$key = $item;
}
$this->fields = null;
$this->loadedFields = array_merge($this->loadedFields, $query->getFields());
$this->postLoad();
return $this;
}
public function __set($name, $value)
{
// Implement your own if you want to override this behaviour!
throw new RuntimeException("Write to Property: $name that is not Available in the Entity!");
}
public function delete()
{
$key = $this->primaryKey;
$query = new EasyQuery(self::$tableName);
$query->setArg($this->primaryKey, $this->$key)->buildDeleteQuery();
DatabaseHandler::get()->execute($query->getQuery(), $query->getArgs());
}
public function jsonSerialize(): array
{
return $this->getFieldsToWrite();
}
public function preSave()
{
}
public function postLoad()
{
}
private function removeEmptyFields(array $vars): array
{
foreach ($vars as $name => $item) {
if (empty($item) && $name != $this->primaryKey) {
unset($vars[$name]);
}
}
return $vars;
}
}

View file

@ -0,0 +1,127 @@
<?php
namespace Venom\Core\Database;
use Exception;
class EntityManager
{
/** @var Entity[] */
private array $entities = [];
public function __construct(private string $classType, private Database $db)
{
}
public static function create($callable): EntityManager
{
return DatabaseHandler::getEntityManager($callable);
}
public function createEntity()
{
$ent = new $this->classType;
$this->entities[] = $ent;
return $ent;
}
public function addEntity(Entity $entity)
{
$this->entities[] = $entity;
}
public function removeEntity(Entity $entity)
{
foreach ($this->entities as $key => $item) {
if ($entity === $item) {
unset($this->entities[$key]);
break;
}
}
}
public function findBy($key, $value): ?Entity
{
foreach ($this->entities as $entity) {
if ($entity->$key === $value) {
return $entity;
}
}
return null;
}
public function saveAll()
{
if (count($this->entities) === 0) {
return;
}
try {
$this->db->start();
foreach ($this->entities as $entity) {
$entity->save();
}
$this->db->commit();
} catch (Exception $ex) {
trigger_error($ex->getMessage());
$this->db->rollBack();
}
}
public function deleteEntities()
{
try {
$this->db->start();
foreach ($this->entities as $entity) {
$entity->delete();
}
$this->db->commit();
} catch (Exception $ex) {
trigger_error($ex->getMessage());
$this->db->rollBack();
}
}
public function clearAll()
{
$this->entities = [];
}
public function load(string|EasyQuery $query, $args = [], array $fields = ["*"])
{
$sql = $query;
if ($query instanceof EasyQuery) {
$query->buildSelect();
$sql = $query->getQuery();
$args = $query->getArgs();
$fields = $query->getFields();
}
$stmt = $this->db->createStatement($sql);
$this->db->setClass($stmt, $this->classType);
if ($stmt->execute($args)) {
/** @var Entity[] $all */
$all = $stmt->fetchAll();
foreach ($all as $item) {
$item->loadedFields = $fields;
$item->postLoad();
$this->addEntity($item);
}
}
}
public function execute($query): bool
{
return $this->db->execute($query);
}
public function getAll(): array
{
return $this->entities;
}
private function addEntities(array $entities)
{
foreach ($entities as $entity) {
$this->entities[] = $entity;
}
}
}

View file

@ -1,92 +0,0 @@
<?php
namespace Venom\Core;
use PDO;
use PDOException;
use Venom\Models\DatabaseObject;
/**
* Singleton DatabaseHandler... make sure we only have one connection to the database..
* @package Venom\Database
*/
class DatabaseHandler
{
// constants
public const DB_TYPE = 'type';
public const DB_HOST = 'host';
public const DB_PORT = 'port';
public const DB_USER = 'user';
public const DB_PASSWORD = 'pw';
public const DB_DB = 'db';
public const DB_EXTRA = 'extra';
private static ?self $instance = null;
private ?PDO $db = null;
public static function get(): DatabaseHandler
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function init(array $data): void
{
//init instance with the current data... only working if the db is not init!
if ($this->db != null) {
return;
}
$dsn = '%s:host=%s;dbname=%s;port=%s';
$connectString = sprintf($dsn, $data[self::DB_TYPE], $data[self::DB_HOST], $data[self::DB_DB], $data[self::DB_PORT] . $data[self::DB_EXTRA]);
try {
$this->db = new PDO($connectString, $data[self::DB_USER], $data[self::DB_PASSWORD]);
} catch (PDOException $e) {
trigger_error($e->getMessage());
die($e->getCode());
}
}
public function getOne(string $query, array $args = []): ?DatabaseObject
{
$data = $this->getAll($query, $args);
if (count($data) > 0) {
return $data[0];
}
return null;
}
public function getAll(string $query, array $args = []): array
{
$stmt = $this->db->prepare($query);
$stmt->setFetchMode(PDO::FETCH_CLASS, DatabaseObject::class);
$stmt->execute($args);
return $stmt->fetchAll();
}
public function execute(string $query, array $args = []): bool
{
$stmt = $this->db->prepare($query);
return $stmt->execute($args);
}
// Returns a Select like this: SELECT id, name, ... FROM table || do what you want
public static function createEasySelect(array $fields, string $table): string
{
return "SELECT " . implode(",", $fields) . " FROM " . $table;
}
public static function getUpdateString(array $data, string $table, string $where): array
{
$string = [];
$save = [];
foreach ($data as $key => $value) {
$k = ":" . strtolower($key);
$string[] = $key . "= " . $k;
$save[$k] = $value;
}
return ["UPDATE " . $table . " SET " . implode(",", $string) . " " . $where, $save];
}
}

5
src/Venom/Core/Language.php Normal file → Executable file
View file

@ -5,7 +5,8 @@ namespace Venom\Core;
use RuntimeException; use RuntimeException;
use Venom\Models\DatabaseObject; use Venom\Core\Database\DatabaseHandler;
use Venom\Entities\DatabaseObject;
class Language class Language
{ {
@ -20,7 +21,7 @@ class Language
public function initLang() public function initLang()
{ {
$lang = ArgumentHandler::get()->getItem("lang", $this->defaultLang->shortTag); $lang = ArgumentHandler::get()->getItem("lang", $this->defaultLang->shortTag ?? 'de');
//check if language exists //check if language exists
$data = DatabaseHandler::get()->getOne("select id from language where shortTag = :shortTag", [ $data = DatabaseHandler::get()->getOne("select id from language where shortTag = :shortTag", [
':shortTag' => $lang ':shortTag' => $lang

13
src/Venom/Core/Module.php Normal file → Executable file
View file

@ -3,18 +3,17 @@
namespace Venom\Core; namespace Venom\Core;
use Venom\Venom;
interface Module interface Module
{ {
const NAME = "name"; const NAME = "name";
const AUTHOR = "author"; const AUTHOR = "author";
const SECURE = "secure"; const SECURE = "secure";
const ROUTE = "routes"; const ROUTE = "routes";
const ADMIN_ROUTE = "adminRoutes";
const DESC = "description"; const DESC = "description";
const TEMPLATES = "templates";
public function register(Venom $venom): bool; const ADMIN_TEMPLATES = "adminTemplates";
const CONTROLLER = "controllers";
public function init(): void; const TEMPLATE_PATH = "tplPath";
const ACTIVE = "isActive";
} }

72
src/Venom/Core/ModuleLoader.php Executable file
View file

@ -0,0 +1,72 @@
<?php
namespace Venom\Core;
use RuntimeException;
use Venom\Helper\TemplateUtil;
use Venom\Routing\Route;
use Venom\Routing\Router;
use Venom\Venom;
class ModuleLoader
{
public static function getModules(): array
{
return [
'Meta',
'User',
'Data',
'Role',
'SEO',
'VenomStatus',
];
}
public static function loadModule(string $name, Venom $venom)
{
// load module search in the Module Path for a module.php file
$dir = __DIR__ . "/../../modules/" . $name . "/module.php";
if (!file_exists($dir)) {
throw new RuntimeException("Module File: \"$dir\" Not found");
}
include_once $dir;
}
public static function initModule(array $module, Venom $venom): bool
{
if (!$module[Module::ACTIVE]) {
return false;
}
// register Router, Templates and more :)
$isAdmin = Config::getInstance()->isAdmin();
if ($isAdmin) {
self::registerRoutes($module,
$venom,
$module[Module::ADMIN_ROUTE],
$venom->getRouter(Router::ADMIN_ROUTER)
);
TemplateUtil::getInstance()->addTemplates($module[Module::ADMIN_TEMPLATES], $module[Module::TEMPLATE_PATH]);
} else {
self::registerRoutes($module,
$venom,
$module[Module::ROUTE],
$venom->getRouter(Router::DEFAULT_ROUTER)
);
TemplateUtil::getInstance()->addTemplates($module[Module::TEMPLATES], $module[Module::TEMPLATE_PATH]);
}
$venom->addControllers($module[Module::CONTROLLER]);
return true;
}
public static function registerRoutes(array $module, Venom $venom, array $routes, Router $router)
{
foreach ($routes as $key => $route) {
/** @var Route $route */
$route->module = $module[Module::NAME];
$route->isSecure = $module[Module::SECURE];
$route->venom = $venom;
$router->addRoute($key, $route);
}
}
}

0
src/Venom/Core/Registry.php Normal file → Executable file
View file

3
src/Venom/Core/Setup.php Normal file → Executable file
View file

@ -39,9 +39,6 @@ class Setup
if (isset($modules)) { if (isset($modules)) {
$venom->initModules($modules); $venom->initModules($modules);
} }
if (isset($controllers)) {
$venom->initControllers($controllers);
}
} }
public static function loadRouters(Venom $venom): void public static function loadRouters(Venom $venom): void

View file

@ -1,10 +1,12 @@
<?php <?php
namespace Venom\Models; namespace Venom\Entities;
class ConfigObject use Venom\Core\Database\Entity;
class ConfigObject extends Entity
{ {
private array $data = []; private array $data = [];

View file

@ -1,10 +1,12 @@
<?php <?php
namespace Venom\Models; namespace Venom\Entities;
class DataModel use Venom\Core\Database\Entity;
class DataEntity extends Entity
{ {
public const TYPE_CONTENT = 'content'; public const TYPE_CONTENT = 'content';
public const TYPE_FORM = 'form'; public const TYPE_FORM = 'form';

View file

@ -1,17 +1,16 @@
<?php <?php
namespace Venom\Models; namespace Venom\Entities;
use Venom\Core\Database\Entity;
use JsonSerializable;
/** /**
* Database Object to use queries like this $obj->id, $obj->value * Database Object to use queries like this $obj->id, $obj->value
* also the option to print it in csv format ; as delimiter * also the option to print it in csv format ; as delimiter
* @package Venom\Database * @package Venom\Database
*/ */
class DatabaseObject implements JsonSerializable class DatabaseObject extends Entity
{ {
private array $data = []; private array $data = [];
@ -48,9 +47,4 @@ class DatabaseObject implements JsonSerializable
{ {
return $this->data; return $this->data;
} }
public function jsonSerialize(): array
{
return $this->data;
}
} }

View file

@ -0,0 +1,59 @@
<?php
namespace Venom\Entities;
use Venom\Core\Database\EasyQuery;
use Venom\Core\Database\Entity;
class RoleEntity extends Entity
{
public static string $tableName = "roles";
public string $name = "";
public string $content = "";
public bool $isActive = true;
private array $roles = [];
public const TYPE_WRITE = 1;
public const TYPE_READ = 0;
public const TYPE_NO = -1;
public function hasPermission(string $module, int $type): bool
{
if ($this->id === -1) {
return true;
}
if ($type === self::TYPE_NO) {
return true;
}
if (!isset($this->roles[$module]) && $type) {
return false;
}
$mod = $this->roles[$module];
return $mod["type"] === $type;
}
public function postLoad()
{
if (!empty($this->content)) {
$this->roles = json_decode($this->content);
}
}
public function preSave()
{
$this->content = json_encode($this->roles);
}
public function load($fields = ['*'], ?EasyQuery $query = null): static
{
if ($this->id === -1 || $this->id === 0) {
return $this;
}
return parent::load($fields, $query);
}
}

57
src/Venom/Entities/User.php Executable file
View file

@ -0,0 +1,57 @@
<?php
namespace Venom\Entities;
use Venom\Core\Database\EasyQuery;
use Venom\Core\Database\Entity;
class User extends Entity
{
public const ADMIN_ROLE = '-1';
public const GUEST_ROLE = '0';
public static string $tableName = "users";
public string $username = "GUEST";
public string $firstname = "";
public string $lastname = "";
public string $email = "";
public string $password = "";
public string $token = "";
public string $salt = "";
public int $roleId = 0;
public bool $isActive = true;
private ?RoleEntity $roleEntity = null;
private bool $loaded = false;
public function hasPermission(string $module, $type = RoleEntity::TYPE_WRITE): bool
{
if ($this->roleEntity === null) {
$this->roleEntity = new RoleEntity();
$this->roleEntity->id = $this->roleId;
$this->roleEntity->load();
}
return $this->roleEntity->hasPermission($module, $type);
}
public function postLoad()
{
$this->loaded = true;
}
public function isLoaded(): bool
{
return $this->loaded;
}
public function loadUser()
{
$eq = new EasyQuery(User::$tableName, ["*"]);
$eq->where("username", $this->username)
->where("id", $this->id, EasyQuery::WHERE_OR);
$this->load([], $eq);
return true;
}
}

0
src/Venom/Exceptions/ExceptionHandler.php Normal file → Executable file
View file

0
src/Venom/Helper/AdminHelper.php Normal file → Executable file
View file

View file

@ -4,7 +4,6 @@
namespace Venom\Helper; namespace Venom\Helper;
use http\Exception\RuntimeException;
use Venom\Core\ArgumentHandler; use Venom\Core\ArgumentHandler;
class ErrorHandler class ErrorHandler

4
src/Venom/Helper/MetaGenerator.php Normal file → Executable file
View file

@ -36,8 +36,8 @@ class MetaGenerator
public function render(): void public function render(): void
{ {
foreach($this->container as $key => $value) { foreach ($this->container as $key => $value) {
echo '<meta name="'.$key.'" content="'.$value.'">'; echo '<meta name="' . $key . '" content="' . $value . '">';
} }
} }
} }

25
src/Venom/Helper/TemplateUtil.php Normal file → Executable file
View file

@ -11,6 +11,7 @@ class TemplateUtil
private static ?TemplateUtil $instance = null; private static ?TemplateUtil $instance = null;
private string $baseTemplate; private string $baseTemplate;
private string $templateDir; private string $templateDir;
private array $templates = [];
private function __construct() private function __construct()
{ {
@ -44,15 +45,31 @@ class TemplateUtil
return $this->baseTemplate; return $this->baseTemplate;
} }
public static function includeTemplate($template, $suffix = '.php') public function addTemplates($templates, string $basePath)
{ {
foreach ($templates as $key => $template) {
$this->templates[$key] = $basePath . $template;
}
}
public static function includeTemplate($template, $suffix = '.php'): bool|string
{
$tx = self::getInstance()->getCache($template);
if ($tx === "") {
$dir = self::getInstance()->getDir(); $dir = self::getInstance()->getDir();
$template .= $suffix; $tx = $dir . $template;
if (file_exists($dir . $template)) { }
$tx .= $suffix;
if (file_exists($tx)) {
ob_start(); ob_start();
include_once $dir . $template; include_once $tx;
return ob_get_clean(); return ob_get_clean();
} }
return ''; return '';
} }
private function getCache($template)
{
return $this->templates[$template] ?? '';
}
} }

0
src/Venom/Helper/URLHelper.php Normal file → Executable file
View file

View file

@ -1,129 +0,0 @@
<?php
namespace Venom\Models;
use Venom\Core\DatabaseHandler;
class User
{
public const ADMIN_ROLE = 'ROLE_ADMIN';
public const GUEST_ROLE = 'ROLE_GUEST';
private string $username = 'GUEST';
private string $email = 'GUEST';
private string $firstname = '';
private string $lastname = '';
private string $password = '';
private string $salt = '';
private string $token = '';
private string $id = '-1';
private array $roles = [];
private bool $isLoaded = false;
public function hasRole(string $role): bool
{
return in_array($role, $this->roles, true);
}
public function loadUser(): bool
{
if (isset($_SESSION['userID']) || $this->username !== 'GUEST') {
// try to load user from id!
$user = DatabaseHandler::get()->getOne("SELECT * FROM users WHERE id = :id OR username = :name AND isActive = 1", [
':id' => $_SESSION['userID'] ?? -1,
':name' => $this->username
]);
if ($user !== null) {
$this->username = $user->username ?? '';
$this->email = $user->email ?? '';
$this->password = $user->password ?? '';
$this->token = $user->token ?? '';
$this->salt = $user->salt ?? '';
$this->id = $user->id ?? '-1';
$this->roles = explode(',', $user->roles ?? '');
$this->isLoaded = true;
return true;
}
}
return false;
}
public function getUsername(): string
{
return $this->username;
}
public function setUsername(string $username): void
{
$this->username = $username;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): void
{
$this->password = $password;
}
public function getSalt(): string
{
return $this->salt;
}
public function setSalt(string $salt): void
{
$this->salt = $salt;
}
public function getToken(): string
{
return $this->token;
}
public function setToken(string $token): void
{
$this->token = $token;
}
public function getRoles(): array
{
return $this->roles;
}
public function setRoles(array $roles): void
{
$this->roles = $roles;
}
public function addRole($value): void
{
if (!in_array($value, $this->roles, true)) {
$this->roles[] = $value;
}
}
public function isLoaded(): bool
{
return $this->isLoaded;
}
public function getId(): string
{
return $this->id;
}
}

44
src/Venom/Routing/Route.php Normal file → Executable file
View file

@ -4,7 +4,47 @@
namespace Venom\Routing; namespace Venom\Routing;
interface Route use RuntimeException;
{ use Venom\Entities\RoleEntity;
use Venom\Security\Security;
use Venom\Venom;
class Route
{
const GET = "GET";
const POST = "POST";
const PUT = "PUT";
const DELETE = "DELETE";
public string $url;
public array $routes = [];
public int $maxParameters = 0;
public string $module = "unknown";
public bool $isSecure = false;
public Venom $venom;
public function __construct(public string $controller, array $config)
{
$count = count($config);
if ($count === 0) {
throw new RuntimeException("Route: \"$controller\" no valid Routes Found!");
}
$count -= isset($config["*"]) ? 1 : 0;
$this->maxParameters = $count;
$this->routes = $config;
}
public function getDefinitions($method, mixed $subRoute): ?array
{
if ($this->isSecure && !Security::get()->hasPermission($this->module, $method === Route::GET ? RoleEntity::TYPE_READ : RoleEntity::TYPE_WRITE)) {
return null;
}
if (isset($this->routes[$subRoute]) && isset($this->routes[$subRoute][$method])) {
return [
"cl" => $this->controller,
"fnc" => $this->routes[$subRoute][$method]
];
}
return null;
}
} }

39
src/Venom/Routing/Router.php Normal file → Executable file
View file

@ -5,10 +5,7 @@ namespace Venom\Routing;
use Exception; use Exception;
use Venom\Core\Config;
use Venom\Exceptions\ExceptionHandler; use Venom\Exceptions\ExceptionHandler;
use Venom\Models\User;
use Venom\Security\Security;
class Router class Router
{ {
@ -31,7 +28,7 @@ class Router
$this->routes = array_merge($this->routes, $routes); $this->routes = array_merge($this->routes, $routes);
} }
public function addRoute(string $path, array $route): void public function addRoute(string $path, Route $route): void
{ {
$this->routes[$path] = $route; $this->routes[$path] = $route;
} }
@ -58,9 +55,9 @@ class Router
return null; return null;
} }
private function removeIfFirst($rawString, $string) private function removeIfFirst($rawString, $string): bool|string
{ {
if ($string !== '' && 0 === strpos($rawString, $string)) { if ($string !== '' && str_starts_with($rawString, $string)) {
return substr($rawString, strlen($string)); return substr($rawString, strlen($string));
} }
return $rawString; return $rawString;
@ -68,24 +65,15 @@ class Router
private function getRouteByName($url, $method, $subRoute = '*', $params = []): ?array private function getRouteByName($url, $method, $subRoute = '*', $params = []): ?array
{ {
if (isset($this->routes[$url]) if (isset($this->routes[$url])) {
&& isset($this->routes[$url]['routes']) /** @var Route $route */
&& isset($this->routes[$url]['routes'][$subRoute]) $route = $this->routes[$url];
&& isset($this->routes[$url]['routes'][$subRoute][$method]) $sub = $route->getDefinitions($method, $subRoute);
) { if ($sub === null) {
if ((Config::getInstance()->getSecurity()->useSecurity || $this->id === self::ADMIN_ROUTER)
&& isset($this->routes[$url]['roles'])
) {
$roles = $this->routes[$url]['roles'];
if (!in_array(User::GUEST_ROLE, $roles, true) && !Security::get()->hasRoles($roles)) {
return null; return null;
} }
} $sub["params"] = array_reverse($params);
return [ return $sub;
'cl' => $this->routes[$url]['cl'],
'fnc' => $this->routes[$url]['routes'][$subRoute][$method],
'params' => $params
];
} }
return null; return null;
} }
@ -128,9 +116,14 @@ class Router
} }
} }
private function removeTrailingSlash(string $rawString) private function removeTrailingSlash(string $rawString): bool|string
{ {
$len = strlen($rawString); $len = strlen($rawString);
return $rawString[$len - 1] === '/' ? substr($rawString, 0, strlen($rawString) - 1) : $rawString; return $rawString[$len - 1] === '/' ? substr($rawString, 0, strlen($rawString) - 1) : $rawString;
} }
public function getId(): string
{
return $this->id;
}
} }

12
src/Venom/Security/BaseLogin.php Normal file → Executable file
View file

@ -6,8 +6,8 @@ namespace Venom\Security;
use Venom\Core\ArgumentHandler; use Venom\Core\ArgumentHandler;
use Venom\Core\Config; use Venom\Core\Config;
use Venom\Entities\User;
use Venom\Helper\URLHelper; use Venom\Helper\URLHelper;
use Venom\Models\User;
/** /**
* Class that Login stupid via Password, Username * Class that Login stupid via Password, Username
@ -31,7 +31,7 @@ class BaseLogin implements Login
public function redirect(): void public function redirect(): void
{ {
$url = ArgumentHandler::get()->getPostItem('REDIRECT_TO', URLHelper::getInstance()->getUrl()); $url = ArgumentHandler::get()->getPostItem('REDIRECT_TO', URLHelper::getInstance()->getUrl());
if($url === 'NO') { if ($url === 'NO') {
echo json_encode(['message' => 'login'], JSON_THROW_ON_ERROR); echo json_encode(['message' => 'login'], JSON_THROW_ON_ERROR);
} else { } else {
header('Location: ' . $url); header('Location: ' . $url);
@ -42,14 +42,14 @@ class BaseLogin implements Login
public function login(): bool public function login(): bool
{ {
$sec = Config::getInstance()->getSecurity(); $sec = Config::getInstance()->getSecurity();
$this->user->setUsername(ArgumentHandler::get()->getPostItem('USERNAME')); $this->user->username = (string)ArgumentHandler::get()->getPostItem('USERNAME');
if (!$this->user->loadUser()) { if (!$this->user->loadUser()) {
return false; return false;
} }
$secret = $sec->secret ?? 'venom'; $secret = $sec->secret ?? 'venom';
$hashed = hash($sec->algo ?? 'SHA256', ArgumentHandler::get()->getPostItem('PASSWORD') . $secret . $this->user->getSalt()); $hashed = hash($sec->algo ?? 'SHA256', ArgumentHandler::get()->getPostItem('PASSWORD') . $secret . $this->user->salt);
if ($this->user->getPassword() === $hashed) { if ($this->user->password === $hashed) {
$_SESSION['userID'] = $this->user->getId(); $_SESSION['userID'] = $this->user->id;
return true; return true;
} }
return false; return false;

2
src/Venom/Security/Login.php Normal file → Executable file
View file

@ -4,7 +4,7 @@
namespace Venom\Security; namespace Venom\Security;
use Venom\Models\User; use Venom\Entities\User;
interface Login interface Login
{ {

22
src/Venom/Security/Security.php Normal file → Executable file
View file

@ -3,9 +3,10 @@
namespace Venom\Security; namespace Venom\Security;
use \RuntimeException; use RuntimeException;
use Venom\Core\Config; use Venom\Core\Config;
use Venom\Models\User; use Venom\Entities\RoleEntity;
use Venom\Entities\User;
class Security class Security
{ {
@ -15,7 +16,8 @@ class Security
public function __construct() public function __construct()
{ {
$this->user = new User(); $this->user = new User();
$this->user->loadUser(); $this->user->id = $_SESSION['userID'] ?? "-1";
$this->user->load();
} }
public static function get(): Security public static function get(): Security
@ -26,19 +28,9 @@ class Security
return self::$instance; return self::$instance;
} }
public function hasRole(string $role): bool public function hasPermission(string $module, $type = RoleEntity::TYPE_WRITE): bool
{ {
return $this->user->hasRole($role); return $this->user->hasPermission($module, $type);
}
public function hasRoles(array $roles): bool
{
foreach ($roles as $role) {
if (!$this->user->hasRole($role)) {
return false;
}
}
return true;
} }
public function login(): void public function login(): void

View file

@ -5,11 +5,11 @@ namespace Venom;
use Venom\Admin\AdminController; use Venom\Admin\AdminController;
use Venom\Admin\AdminModulesLoader;
use Venom\Admin\AdminRouterInit; use Venom\Admin\AdminRouterInit;
use Venom\Core\ArgumentHandler; use Venom\Core\ArgumentHandler;
use Venom\Core\Config; use Venom\Core\Config;
use Venom\Core\Module; use Venom\Core\Module;
use Venom\Core\ModuleLoader;
use Venom\Core\Registry; use Venom\Core\Registry;
use Venom\Exceptions\ExceptionHandler; use Venom\Exceptions\ExceptionHandler;
use Venom\Helper\ErrorHandler; use Venom\Helper\ErrorHandler;
@ -117,28 +117,32 @@ class Venom
public function initModules(array $modules): void public function initModules(array $modules): void
{ {
if (Config::getInstance()->isAdmin()) { if (Config::getInstance()->isAdmin()) {
$modules = array_merge(AdminModulesLoader::getModules(), $modules); $modules = array_merge(ModuleLoader::getModules(), $modules);
}
foreach ($modules as $key => $moduleClass) {
$module = new $moduleClass;
if ($module instanceof Module && $module->register($this)) {
$this->modules[$key] = $module;
} }
foreach ($modules as $module) {
ModuleLoader::loadModule($module, $this);
} }
} }
public function initControllers(array $controllers): void public function addControllers(array $controllers): void
{ {
$this->controllers = $controllers; $this->controllers = array_merge($this->controllers, $controllers);
} }
public function addRouter(string $name, Router $router): void public function addRouter(Router $router): void
{ {
$this->routers[$name] = $router; $this->routers[$router->getId()] = $router;
} }
public function getRouter(string $router): ?Router public function getRouter(string $router): ?Router
{ {
return $this->routers[$router]; return $this->routers[$router];
} }
public function registerModule(array $module)
{
if (ModuleLoader::initModule($module, $this)) {
$this->modules[$module[Module::NAME]] = $module;
}
}
} }

View file

@ -3,9 +3,9 @@
namespace Venom\Views; namespace Venom\Views;
use \RuntimeException; use RuntimeException;
use Venom\Core\DatabaseHandler; use Venom\Core\DatabaseHandler;
use Venom\Models\DataModel; use Venom\Entities\DataEntity;
class DataLoader class DataLoader
{ {
@ -23,7 +23,7 @@ class DataLoader
return self::$instance; return self::$instance;
} }
public static function loadById(string $id): ?DataModel public static function loadById(string $id): ?DataEntity
{ {
if ($id === '') { if ($id === '') {
throw new RuntimeException('Try to Load empty ID from Database'); throw new RuntimeException('Try to Load empty ID from Database');
@ -33,14 +33,14 @@ class DataLoader
]); ]);
if ($data !== null) { if ($data !== null) {
$model = new DataModel($data->identity, $data->datatype, $data->raw, $data->generated); $model = new DataEntity($data->identity, $data->datatype, $data->raw, $data->generated);
$model->setActive(true); $model->setActive(true);
return $model; return $model;
} }
return null; return null;
} }
public function updateData(DataModel $model): bool public function updateData(DataEntity $model): bool
{ {
if ($model->getId() === '') { if ($model->getId() === '') {
return $this->insertData($model); return $this->insertData($model);
@ -57,7 +57,7 @@ class DataLoader
); );
} }
public function insertData(DataModel $model): bool public function insertData(DataEntity $model): bool
{ {
$this->validateModel($model); $this->validateModel($model);
@ -73,7 +73,7 @@ class DataLoader
); );
} }
private function validateModel(DataModel $model): void private function validateModel(DataEntity $model): void
{ {
if ($model->getId() === '') { if ($model->getId() === '') {
$model->setId($this->generateID()); $model->setId($this->generateID());

0
src/Venom/Views/RenderController.php Normal file → Executable file
View file

0
src/modules/.gitkeep Normal file → Executable file
View file

View file

@ -0,0 +1,13 @@
<?php
namespace Modules\Data\Controller;
class DataController
{
public function get()
{
}
}

34
src/modules/Data/module.php Executable file
View file

@ -0,0 +1,34 @@
<?php
use Modules\Data\Controller\DataController;
use Venom\Core\Module;
use Venom\Routing\Route;
$venom = $venom ?? die();
$venom->registerModule([
Module::ACTIVE => true,
Module::NAME => 'DataModule',
Module::DESC => 'Data Module for Content every',
Module::AUTHOR => 'VstZ dev',
// NEED TO CHECK RIGHTS? :D IF FALSE WRITE IS ALWAYS ALLOWED ALSO READ!
Module::SECURE => true,
Module::ROUTE => [],
Module::ADMIN_ROUTE => [
'/data' => new Route(DataController::class, [
"*" => [
Route::GET => 'get'
]
])
],
Module::TEMPLATE_PATH => __DIR__ . "/tpl/",
Module::TEMPLATES => [
],
Module::ADMIN_TEMPLATES => [
],
Module::CONTROLLER => [
]
]);

2
src/modules/Meta/Controller/MetaAPIController.php Normal file → Executable file
View file

@ -16,7 +16,7 @@ class MetaAPIController
public function getById($id) public function getById($id)
{ {
AdminHelper::sendResponse(MetaController::getById($id)); AdminHelper::sendResponse(SeoUrlController::getById($id));
} }
public function update($id) public function update($id)

0
src/modules/Meta/Controller/MetaController.php Normal file → Executable file
View file

View file

@ -1,79 +0,0 @@
<?php
namespace Modules\Meta;
use Modules\Meta\Controller\MetaAPIController;
use Venom\Core\Config;
use Venom\Core\Module;
use Venom\Helper\AdminHelper;
use Venom\Routing\Route;
use Venom\Routing\Router;
use Venom\Venom;
class MetaDataModule implements Module, Route
{
public function register(Venom $venom): bool
{
if (Config::getInstance()->isAdmin()) {
$this->registerAdminRoutes($venom);
}
return true;
}
public function init(): void
{
}
private function registerAdminRoutes(Venom $venom)
{
$venom->getRouter(Router::ADMIN_ROUTER)->addRoutes([
'/metaData' => [
'cl' => MetaAPIController::class,
'roles' => ['ROLE_ADMIN'],
'routes' => [
'*' => [
"GET" => 'get',
],
'1' => [
"GET" => 'getById',
"POST" => 'update',
"PUT" => 'insert',
"DELETE" => 'delete'
]
]
]
]);
}
public function get()
{
AdminHelper::sendResponse([
'metaData' => [
['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
['id' => 2, 'name' => 'versustunez', 'icon' => 'vt-edit']
]
]);
}
public function update(): bool
{
return false;
}
public function insert(): bool
{
return false;
}
public function getById($id)
{
AdminHelper::sendResponse([
'caseName' => 'ROLE_ADMIN',
'id' => $id,
'name' => 'Admin',
'icon' => 'vt-visibility',
]);
}
}

43
src/modules/Meta/module.php Normal file → Executable file
View file

@ -1,22 +1,41 @@
<?php <?php
use Modules\Meta\Controller\MetaAPIController;
use Venom\Core\Module; use Venom\Core\Module;
use Venom\Routing\Route;
/*$module = [
$venom = $venom ?? die();
$venom->registerModule([
Module::ACTIVE => true,
Module::NAME => 'MetaModule', Module::NAME => 'MetaModule',
Module::DESC => 'Meta Data Module for SEO', Module::DESC => 'Meta Data Module for SEO',
Module::AUTHOR => 'VstZ dev', Module::AUTHOR => 'VstZ dev',
// NEED TO CHECK RIGHTS? :D IF FALSE WRITE IS ALWAYS ALLOWED ALSO READ!
Module::SECURE => true, Module::SECURE => true,
MODULE::ROUTE => [ Module::ROUTE => [],
'/' Module::ADMIN_ROUTE => [
'/metaData' => new Route(MetaAPIController::class, [
"*" => [
Route::GET => 'get'
], ],
MODULE::TEMPLATES => [ "1" => [
// Include Templates with shorter names! $render->include("meta_roles") Route::GET => 'getById',
'meta_roles' => 'PATH_TO_TEMPLATE' Route::POST => 'update',
], Route::PUT => 'insert',
MODULE::ADMIN_TEMPLATES => [ Route::DELETE => 'delete'
//
] ]
]; ])
$venom = $venom ?? die(); ],
$venom->registerModule($module);*/ Module::TEMPLATE_PATH => __DIR__ . "/tpl/",
Module::TEMPLATES => [
// Include Templates with shorter names! $render->include("meta_roles")
//'meta_roles' => 'PATH_TO_TEMPLATE_FROM_TEMPLATE_PATH'
],
Module::ADMIN_TEMPLATES => [
//
],
Module::CONTROLLER => [
]
]);

View file

@ -1,85 +0,0 @@
<?php
namespace Modules;
use Venom\Core\Config;
use Venom\Core\Module;
use Venom\Helper\AdminHelper;
use Venom\Routing\Route;
use Venom\Routing\Router;
use Venom\Venom;
class PageModule implements Module, Route
{
public function register(Venom $venom): bool
{
if (Config::getInstance()->isAdmin()) {
$this->registerAdminRoutes($venom);
}
return true;
}
public function init(): void
{
}
private function registerAdminRoutes(Venom $venom)
{
$venom->getRouter(Router::ADMIN_ROUTER)->addRoutes([
'/pages' => [
'cl' => PageModule::class,
'roles' => ['ROLE_ADMIN'],
'routes' => [
'*' => [
"GET" => 'get',
],
'1' => [
"GET" => 'getById',
"POST" => 'update',
"PUT" => 'insert',
]
]
]
]);
}
public function get()
{
AdminHelper::sendResponse([
'pages' => [
['id' => 1, 'name' => 'Flamingos going wild!', 'icon' => 'vt-edit'],
['id' => 2, 'name' => 'Turbinen sind geil.', 'icon' => 'vt-edit'],
['id' => 3, 'name' => 'Aufbau und Umbau des neuen VENOMs Plugins', 'icon' => 'vt-edit'],
['id' => 4, 'name' => 'Aber Mama hat gesagt!', 'icon' => 'vt-edit'],
['id' => 5, 'name' => 'Frische Fische nur heute!', 'icon' => 'vt-edit']
],
]);
}
public function update(): bool
{
return false;
}
public function insert(): bool
{
return false;
}
public function getById($id)
{
AdminHelper::sendResponse([
'caseName' => 'ROLE_ADMIN',
'id' => $id,
'name' => 'Admin',
'icon' => 'vt-visibility',
'users' => [
['value' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
['value' => 2, 'name' => 'versustunez', 'icon' => 'vt-edit']
]
]);
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Modules\Role\Controller;
use Venom\Helper\AdminHelper;
class RoleController
{
public function get()
{
AdminHelper::sendResponse([
'roles' => [
['id' => 1, 'name' => 'Admin', 'icon' => 'vt-visibility'],
['id' => 2, 'name' => 'Moderator', 'icon' => 'vt-edit'],
['id' => 3, 'name' => 'Gast', 'icon' => 'vt-edit'],
]
]);
}
}

34
src/modules/Role/module.php Executable file
View file

@ -0,0 +1,34 @@
<?php
use Modules\Role\Controller\RoleController;
use Venom\Core\Module;
use Venom\Routing\Route;
$venom = $venom ?? die();
$venom->registerModule([
Module::ACTIVE => true,
Module::NAME => 'RoleModule',
Module::DESC => 'Role Management',
Module::AUTHOR => 'VstZ dev',
// NEED TO CHECK RIGHTS? :D IF FALSE WRITE IS ALWAYS ALLOWED ALSO READ!
Module::SECURE => true,
Module::ROUTE => [],
Module::ADMIN_ROUTE => [
'/roles' => new Route(RoleController::class, [
"*" => [
Route::GET => 'get'
]
])
],
Module::TEMPLATE_PATH => __DIR__ . "/tpl/",
Module::TEMPLATES => [
],
Module::ADMIN_TEMPLATES => [
],
Module::CONTROLLER => [
]
]);

View file

@ -1,81 +0,0 @@
<?php
namespace Modules;
use Venom\Core\Config;
use Venom\Core\DatabaseHandler;
use Venom\Core\Module;
use Venom\Helper\AdminHelper;
use Venom\Routing\Route;
use Venom\Routing\Router;
use Venom\Venom;
class RoleModule implements Module, Route
{
public function register(Venom $venom): bool
{
if (Config::getInstance()->isAdmin()) {
$this->registerAdminRoutes($venom);
}
return true;
}
public function init(): void
{
}
private function registerAdminRoutes(Venom $venom)
{
$venom->getRouter(Router::ADMIN_ROUTER)->addRoutes([
'/roles' => [
'cl' => RoleModule::class,
'roles' => ['ROLE_ADMIN'],
'routes' => [
'*' => [
"GET" => 'get',
],
'1' => [
"GET" => 'getById',
"POST" => 'update',
"PUT" => 'insert',
]
]
]
]);
}
public function get()
{
//$req = DatabaseHandler::get()->getAll("SELECT * FROM roles");
AdminHelper::sendResponse([
'roles' => [
['id' => 1, 'name' => 'Admin', 'icon' => 'vt-visibility'],
['id' => 2, 'name' => 'Moderator', 'icon' => 'vt-edit'],
['id' => 3, 'name' => 'Gast', 'icon' => 'vt-edit'],
]
]);
}
public function update(): bool
{
return false;
}
public function insert(): bool
{
return false;
}
public function getById($id)
{
AdminHelper::sendResponse([
'caseName' => 'ROLE_ADMIN',
'id' => $id,
'name' => 'Admin',
'icon' => 'vt-visibility'
]);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Modules\SEO\Controller;
class SeoUrlController
{
public static function get(): array
{
return [];
}
public static function getById($id): array
{
return [];
}
}

40
src/modules/SEO/module.php Executable file
View file

@ -0,0 +1,40 @@
<?php
use Modules\SEO\Controller\SeoUrlController;
use Venom\Core\Module;
use Venom\Routing\Route;
$venom = $venom ?? die();
$venom->registerModule([
Module::ACTIVE => true,
Module::NAME => 'SeoModule',
Module::DESC => 'SEO Management for beautiful URLs',
Module::AUTHOR => 'VstZ dev',
// NEED TO CHECK RIGHTS? :D IF FALSE WRITE IS ALWAYS ALLOWED ALSO READ!
Module::SECURE => true,
Module::ROUTE => [],
Module::ADMIN_ROUTE => [
'/seoUrl' => new Route(SeoUrlController::class, [
"*" => [
Route::GET => 'get'
],
"1" => [
Route::GET => 'getById',
Route::POST => 'update',
Route::PUT => 'insert',
Route::DELETE => 'delete'
]
])
],
Module::TEMPLATE_PATH => __DIR__ . "/tpl/",
Module::TEMPLATES => [
],
Module::ADMIN_TEMPLATES => [
],
Module::CONTROLLER => [
]
]);

View file

@ -1,81 +0,0 @@
<?php
namespace Modules;
use Venom\Core\Config;
use Venom\Core\Module;
use Venom\Helper\AdminHelper;
use Venom\Routing\Route;
use Venom\Routing\Router;
use Venom\Venom;
class SeoUrlModule implements Module, Route
{
public function register(Venom $venom): bool
{
if (Config::getInstance()->isAdmin()) {
$this->registerAdminRoutes($venom);
}
return true;
}
public function init(): void
{
}
private function registerAdminRoutes(Venom $venom)
{
$venom->getRouter(Router::ADMIN_ROUTER)->addRoutes([
'/seoUrl' => [
'cl' => SeoUrlModule::class,
'roles' => ['ROLE_ADMIN'],
'routes' => [
'*' => [
"GET" => 'get',
],
'1' => [
"GET" => 'getById',
"POST" => 'update',
"PUT" => 'insert',
]
]
]
]);
}
public function get()
{
AdminHelper::sendResponse([
'pages' => [
['id' => 1, 'name' => 'Flamingos going wild!', 'icon' => 'vt-edit'],
['id' => 2, 'name' => 'Turbinen sind geil.', 'icon' => 'vt-edit'],
['id' => 3, 'name' => 'Aufbau und Umbau des neuen VENOMs Plugins', 'icon' => 'vt-edit'],
['id' => 4, 'name' => 'Aber Mama hat gesagt!', 'icon' => 'vt-edit'],
['id' => 5, 'name' => 'Frische Fische nur heute!', 'icon' => 'vt-edit']
]
]);
}
public function update(): bool
{
return false;
}
public function insert(): bool
{
return false;
}
public function getById($id)
{
AdminHelper::sendResponse([
'caseName' => 'ROLE_ADMIN',
'id' => $id,
'name' => 'Admin',
'icon' => 'vt-visibility',
]);
}
}

16
src/modules/User/Controller/UserAPIController.php Normal file → Executable file
View file

@ -4,16 +4,20 @@
namespace Modules\User\Controller; namespace Modules\User\Controller;
use Venom\Core\ArgumentHandler; use Venom\Core\ArgumentHandler;
use Venom\Core\DatabaseHandler; use Venom\Core\Database\EasyQuery;
use Venom\Core\Database\EntityManager;
use Venom\Entities\User;
use Venom\Helper\AdminHelper; use Venom\Helper\AdminHelper;
class UserAPIController class UserAPIController
{ {
public function get() public function get()
{ {
$entityManager = EntityManager::create(User::class);
$easyQuery = new EasyQuery(User::$tableName, ["id", "username", "firstname", "lastname", "email", "isActive"]);
$entityManager->load($easyQuery);
//['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'], //['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
$data = UserController::get(["id", "username", "firstname", "lastname", "email", "isActive"]); AdminHelper::sendResponse(["users" => $entityManager->getAll()]);
AdminHelper::sendResponse(["users" => $data]);
} }
public function getById($id) public function getById($id)
@ -48,12 +52,6 @@ class UserAPIController
public function delete($id) public function delete($id)
{ {
AdminHelper::sendStatus(DatabaseHandler::get()->execute(
"DELETE FROM users WHERE id=:id",
[
':id' => $id
]
));
} }
public function create($id) public function create($id)

2
src/modules/User/Controller/UserController.php Normal file → Executable file
View file

@ -5,7 +5,7 @@ namespace Modules\User\Controller;
use Venom\Core\DatabaseHandler; use Venom\Core\DatabaseHandler;
use Venom\Models\DatabaseObject; use Venom\Entities\DatabaseObject;
class UserController class UserController
{ {

View file

@ -1,49 +0,0 @@
<?php
namespace Modules\User;
use Modules\User\Controller\UserAPIController;
use Venom\Core\Config;
use Venom\Core\Module;
use Venom\Helper\AdminHelper;
use Venom\Routing\Route;
use Venom\Routing\Router;
use Venom\Venom;
class UserModule implements Module, Route
{
public function register(Venom $venom): bool
{
if (Config::getInstance()->isAdmin()) {
$this->registerAdminRoutes($venom);
}
return true;
}
public function init(): void
{
}
private function registerAdminRoutes(Venom $venom)
{
$venom->getRouter(Router::ADMIN_ROUTER)->addRoutes([
'/users' => [
'cl' => UserAPIController::class,
'roles' => ['ROLE_ADMIN'],
'routes' => [
'*' => [
"GET" => 'get',
],
'1' => [
"GET" => 'getById',
"POST" => 'insert',
"PUT" => 'update',
]
]
]
]);
}
}

42
src/modules/User/module.php Executable file
View file

@ -0,0 +1,42 @@
<?php
use Modules\User\Controller\UserAPIController;
use Venom\Core\Module;
use Venom\Routing\Route;
use Venom\Venom;
/** @var Venom $venom */
$venom = $venom ?? die();
$venom->registerModule([
Module::ACTIVE => true,
Module::NAME => 'UserModule',
Module::DESC => 'User Management',
Module::AUTHOR => 'VstZ dev',
// NEED TO CHECK RIGHTS? :D IF FALSE WRITE IS ALWAYS ALLOWED ALSO READ!
Module::SECURE => true,
Module::ROUTE => [],
Module::ADMIN_ROUTE => [
'/users' => new Route(UserAPIController::class, [
"*" => [
Route::GET => 'get'
],
"1" => [
Route::GET => 'getById',
Route::POST => 'insert',
Route::PUT => 'update',
Route::DELETE => 'delete'
]
]
)
],
Module::TEMPLATE_PATH => __DIR__ . "/tpl/",
Module::TEMPLATES => [
],
Module::ADMIN_TEMPLATES => [
//
],
Module::CONTROLLER => [
]
]);

View file

@ -0,0 +1,13 @@
<?php
namespace Modules\VenomStatus\Controller;
class VenomStatusController
{
public function get()
{
}
}

View file

@ -0,0 +1,34 @@
<?php
use Modules\VenomStatus\Controller\VenomStatusController;
use Venom\Core\Module;
use Venom\Routing\Route;
$venom = $venom ?? die();
$venom->registerModule([
Module::ACTIVE => true,
Module::NAME => 'VenomStatusModule',
Module::DESC => 'Show Routes and Modules!',
Module::AUTHOR => 'VstZ dev',
// NEED TO CHECK RIGHTS? :D IF FALSE WRITE IS ALWAYS ALLOWED ALSO READ!
Module::SECURE => true,
Module::ROUTE => [],
Module::ADMIN_ROUTE => [
'/venomStatus' => new Route(VenomStatusController::class, [
"*" => [
Route::GET => 'get'
]
])
],
Module::TEMPLATE_PATH => __DIR__ . "/tpl/",
Module::TEMPLATES => [
],
Module::ADMIN_TEMPLATES => [
],
Module::CONTROLLER => [
]
]);

View file

@ -1,78 +0,0 @@
<?php
namespace Modules;
use Venom\Core\Config;
use Venom\Core\Module;
use Venom\Helper\AdminHelper;
use Venom\Routing\Route;
use Venom\Routing\Router;
use Venom\Venom;
class VenomStatusModule implements Module, Route
{
public function register(Venom $venom): bool
{
if (Config::getInstance()->isAdmin()) {
$this->registerAdminRoutes($venom);
}
return true;
}
public function init(): void
{
}
private function registerAdminRoutes(Venom $venom)
{
$venom->getRouter(Router::ADMIN_ROUTER)->addRoutes([
'/venomStatus' => [
'cl' => VenomStatusModule::class,
'roles' => ['ROLE_ADMIN'],
'routes' => [
'*' => [
"GET" => 'get',
],
'1' => [
"GET" => 'getById',
"POST" => 'update',
"PUT" => 'insert',
]
]
]
]);
}
public function get()
{
AdminHelper::sendResponse([
'users' => [
['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
['id' => 2, 'name' => 'versustunez', 'icon' => 'vt-edit']
]
]);
}
public function update(): bool
{
return false;
}
public function insert(): bool
{
return false;
}
public function getById($id)
{
AdminHelper::sendResponse([
'caseName' => 'ROLE_ADMIN',
'id' => $id,
'name' => 'Admin',
'icon' => 'vt-visibility',
]);
}
}

0
tpl/.gitkeep Normal file → Executable file
View file

0
tpl/admin/admin-panel.php Normal file → Executable file
View file

0
tpl/admin/base.php Normal file → Executable file
View file

0
tpl/admin/jsTemplates/includes/btn.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/includes/input.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/includes/select.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/includes/svg.tpl Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 155 B

After

Width:  |  Height:  |  Size: 155 B

0
tpl/admin/jsTemplates/includes/switch.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/metaDataList.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/overview.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/pageEdit.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/pagesList.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/roleEdit.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/rolesList.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/seoUrlEdit.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/seoUrlList.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/userEdit.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/usersList.tpl Normal file → Executable file
View file

0
tpl/admin/jsTemplates/venomStatus.tpl Normal file → Executable file
View file

0
tpl/admin/login.php Normal file → Executable file
View file

0
tpl/default/base.php Normal file → Executable file
View file