diff --git a/config.base.php b/config.base.php index 28e5c98..9a07a54 100644 --- a/config.base.php +++ b/config.base.php @@ -17,16 +17,23 @@ $config->setDatabase([ // used for external batch-mailing and error reporting. // please generate login data at: api.vstz.dev +// api will check this data before processing $config->setAPIAuth([ + 'useAPI' => true, 'url' => 'https://api.vstz.dev/v1/', 'user' => 'vstz', 'pw' => '6(f&B~ZxH3DfC#qJ', 'logsError' => true ]); +/** + * BATCH Mailing is something that will send only mails after a specific time like 1 min. + * it is used to prevent spamming. + * batch mailing only works via API!... if API not used BatchMailing will disabled... or you have a cron that works like a batch... + */ $config->setMail([ 'useBatch' => true, //if true it will not send mails. - 'writeToDB' => true, //is needed for batch and is always true if batch is used + 'writeToDB' => true, //is needed for batch and is always true if batch is use //this stuff is only important if not using batch mailing! 'host' => 'localhost', 'port' => '587', @@ -43,9 +50,11 @@ $config->setRender([ 'baseFile' => 'base', //this will called after all templates are rendered... 'useCache' => false, //is only on big systems good 'cacheName' => 'defaultCache', //this is for bigger systems, ignore it + 'uploadDir' => 'content/' ]); $config->setMaintainMode(false); $config->setDevMode(true); +$config->setBaseUrl(''); // can changed to something like that: https://example.com !not enter a / after the url! this will break all $config->close(); \ No newline at end of file diff --git a/module.base.php b/module.base.php index aacea87..7480485 100644 --- a/module.base.php +++ b/module.base.php @@ -5,5 +5,7 @@ $modules = []; // register controllers that can handle templates ;) need to have a render function for this $controllers = [ - 'test' => \Modules\TestController::class + 'test' => \Modules\TestController::class, + //api-controller + 'apiMailer' => \Modules\API\APIMailer::class, ]; \ No newline at end of file diff --git a/public/admin/index.php b/public/admin/index.php new file mode 100644 index 0000000..a6e5691 --- /dev/null +++ b/public/admin/index.php @@ -0,0 +1,30 @@ +setIsAdmin(true); + +require_once '../../config.inc.php'; +require_once '../../module.inc.php'; + +if ($config->isDevMode()) { + error_reporting(E_ALL); + ini_set('error_reporting', E_ALL); +} +$venom = new Venom(); +$venom->initModules($modules); +$venom->initControllers($controllers); +$venom->run(); \ No newline at end of file diff --git a/public/content/.gitkeep b/public/content/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/public/theme/default/css/test.css b/public/theme/default/css/test.css new file mode 100644 index 0000000..047290a --- /dev/null +++ b/public/theme/default/css/test.css @@ -0,0 +1,25 @@ +* { + box-sizing: border-box; +} + +html, body { + margin: 0; + font-size: 16px; + color: #fff; + background-color: #333; + font-family: sans-serif; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + width: 100vw; +} + +header { + font-size: 5vw; + cursor: pointer; +} + +header:hover { + color: #ff0323; +} \ No newline at end of file diff --git a/public/theme/default/js/test.js b/public/theme/default/js/test.js new file mode 100644 index 0000000..e69de29 diff --git a/src/Venom/ArgumentHandler.php b/src/Venom/ArgumentHandler.php new file mode 100644 index 0000000..aaf88ee --- /dev/null +++ b/src/Venom/ArgumentHandler.php @@ -0,0 +1,37 @@ + $item) { + $this->arguments[htmlspecialchars($key)] = htmlspecialchars($item); + } + foreach ($_POST as $key => $item) { + $this->arguments[htmlspecialchars($key)] = htmlspecialchars($item); + } + } + + public static function get(): ArgumentHandler + { + if (self::$instance == null) { + self::$instance = new ArgumentHandler(); + } + return self::$instance; + } + + public function getItem(string $key, $default = null) + { + if (isset($this->arguments[$key])) { + return $this->arguments[$key]; + } + return $default; + } +} \ No newline at end of file diff --git a/src/Venom/Config.php b/src/Venom/Config.php index e664ba3..5582f4d 100644 --- a/src/Venom/Config.php +++ b/src/Venom/Config.php @@ -14,6 +14,8 @@ class Config private array $renderer = []; private bool $maintenance = false; private bool $devMode = false; + private bool $isAdmin = false; + private string $baseUrl = ''; private function __construct() { @@ -38,29 +40,17 @@ class Config public function setAPIAuth(array $array): void { - if ($this->isWriteable) { - $this->api = $array; - } else { - trigger_error('try to write closed config!'); - } + $this->set('api', $array); } public function setRender(array $array): void { - if ($this->isWriteable) { - $this->renderer = $array; - } else { - trigger_error('try to write closed config!'); - } + $this->set('renderer', $array); } public function setMaintainMode(bool $mode): void { - if ($this->isWriteable) { - $this->maintenance = $mode; - } else { - trigger_error('try to write closed config!'); - } + $this->set('maintenance', $mode); } public function getVersion(): float @@ -70,12 +60,7 @@ class Config public function setVersion(float $param): void { - if ($this->isWriteable) { - $this->version = $param; - } else { - trigger_error('try to write closed config!'); - } - + $this->set('version', $param); } public function getApi(): array @@ -90,11 +75,7 @@ class Config public function setMail(array $array): void { - if ($this->isWriteable) { - $this->mail = $array; - } else { - trigger_error('try to write closed config!'); - } + $this->set('mail', $array); } public function getRenderer(): array @@ -114,11 +95,35 @@ class Config public function setDevMode(bool $mode): void { - if ($this->isWriteable) { - $this->devMode = $mode; - } else { - trigger_error('try to write closed config!'); - } + $this->set('devMode', $mode); + } + + /** + * @return bool + */ + public function isAdmin(): bool + { + return $this->isAdmin; + } + + /** + * @param bool $isAdmin + */ + public function setIsAdmin(bool $isAdmin): void + { + $this->set('isAdmin', $isAdmin); + } + + public function setBaseUrl(string $url) { + $this->set('baseUrl', $url); + } + + /** + * @return bool + */ + public function isClosed(): bool + { + return !$this->isWriteable; } /** @@ -128,4 +133,17 @@ class Config { $this->isWriteable = false; } + + public function set(string $variable, $value) { + if (!$this->isWriteable) { + trigger_error('try to write closed config!'); + return; + } + $this->$variable = $value; + } + + public function getBaseUrl() + { + return $this->baseUrl; + } } \ No newline at end of file diff --git a/src/Venom/Venom.php b/src/Venom/Venom.php index 6cd02b5..b368ce2 100644 --- a/src/Venom/Venom.php +++ b/src/Venom/Venom.php @@ -4,6 +4,7 @@ namespace Venom; +use Venom\Views\Asset; use Venom\Views\RenderController; use Venom\Views\VenomRenderer; @@ -16,6 +17,7 @@ class Venom public function __construct() { $this->renderer = new VenomRenderer($this); + Asset::get()->setRenderer($this->renderer); } public function run(): void diff --git a/src/Venom/Views/Asset.php b/src/Venom/Views/Asset.php new file mode 100644 index 0000000..ee5c0fa --- /dev/null +++ b/src/Venom/Views/Asset.php @@ -0,0 +1,89 @@ +jsFiles[$name] = [ + 'file' => $filepath, + 'pos' => $pos + ]; + } + + public function addCSS(string $name, string $filepath, $pos = 99999) + { + $this->cssFiles[$name] = [ + 'file' => $filepath, + 'pos' => $pos + ]; + } + + public function getImagePath(string $filepath, bool $useAbsolute = false) + { + $preDir = '/content'; + if ($useAbsolute) { + $preDir = Config::getInstance()->getBaseUrl() . $preDir; + } + } + + public function setRenderer(VenomRenderer $renderer) + { + $this->renderer = $renderer; + } + + //this will output all js files! sorted by position + public function renderJS() + { + usort($this->jsFiles, function ($a, $b) { + return $a['pos'] <=> $b['pos']; + }); + $theme = $this->getPath('/theme/' . Config::getInstance()->getRenderer()['theme'] . '/js/'); + foreach ($this->jsFiles as $key => $file) { + echo ''; + } + } + + public function renderCSS() + { + usort($this->cssFiles, function ($a, $b) { + return $a['pos'] <=> $b['pos']; + }); + $theme = $this->getPath('/theme/' . Config::getInstance()->getRenderer()['theme'] . '/css/'); + foreach ($this->cssFiles as $key => $file) { + echo ''; + } + } + + private function getPath($base) + { + $preDir = $base; + $baseUrl = Config::getInstance()->getBaseUrl(); + if ($baseUrl != '') { + $preDir = Config::getInstance()->getBaseUrl() . $preDir; + } + return $preDir; + } +} \ No newline at end of file diff --git a/src/Venom/Views/VenomRenderer.php b/src/Venom/Views/VenomRenderer.php index 6b08b60..771c963 100644 --- a/src/Venom/Views/VenomRenderer.php +++ b/src/Venom/Views/VenomRenderer.php @@ -4,6 +4,7 @@ namespace Venom\Views; +use Venom\ArgumentHandler; use Venom\Config; use Venom\Venom; @@ -24,10 +25,16 @@ class VenomRenderer public function render(): void { + $isAsync = false; if ($this->controller) { ob_start(); $this->controller->render($this); $this->templateData = ob_get_clean(); + $isAsync = $this->controller->getTemplate() === 'async'; + } + if ($isAsync || ArgumentHandler::get()->getItem('async', 'false') === 'true') { + echo $this->templateData; + exit; } $this->loadBasicTemplate(); } diff --git a/src/modules/API/APIMailer.php b/src/modules/API/APIMailer.php new file mode 100644 index 0000000..c98ee77 --- /dev/null +++ b/src/modules/API/APIMailer.php @@ -0,0 +1,33 @@ +useAPI = Config::getInstance()->getApi()['useAPI'] === true; + return true; + } + + public function render(VenomRenderer $renderer): bool + { + //check for batch rendering... this is very important! + echo 'batch...'; + return $this->useAPI; + } + + //return async to say the backend that this should exit after rendering + public function getTemplate(): string + { + return 'async'; + } +} \ No newline at end of file diff --git a/src/modules/TestController.php b/src/modules/TestController.php index 839a4a2..b526fc8 100644 --- a/src/modules/TestController.php +++ b/src/modules/TestController.php @@ -4,6 +4,7 @@ namespace Modules; +use Venom\Views\Asset; use Venom\Views\RenderController; use Venom\Views\VenomRenderer; @@ -17,6 +18,8 @@ class TestController implements RenderController public function render(VenomRenderer $renderer): bool { + Asset::get()->addJS('test', 'test.js'); + Asset::get()->addCSS('test', 'test.css'); return true; } diff --git a/tpl/default/base.php b/tpl/default/base.php index 6aa9612..3354cf6 100644 --- a/tpl/default/base.php +++ b/tpl/default/base.php @@ -1,3 +1,9 @@ + @@ -6,11 +12,17 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> VenomBase + renderCSS(); + ?>
VenomCMS
templateData ?> +renderJS(); +?> \ No newline at end of file