Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
joepdooper committed Mar 8, 2024
1 parent 2357e0a commit a1b94c1
Show file tree
Hide file tree
Showing 22 changed files with 295 additions and 309 deletions.
431 changes: 231 additions & 200 deletions core/classes/Ivy/User.php

Large diffs are not rendered by default.

30 changes: 0 additions & 30 deletions core/include/auth.php

This file was deleted.

62 changes: 10 additions & 52 deletions core/include/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

// authentication
$auth = new \Delight\Auth\Auth($db,true);
require_once _PUBLIC_PATH . 'core/include/auth.php';

// hooks
$hooks = new Hooks();

// core autoload
require_once _PUBLIC_PATH . 'core/include/autoloader.php';

// settings
// set settings
(new \Ivy\Setting)->get()->setKeyBy('name')->cache()->data();

// template
Expand All @@ -35,7 +34,11 @@
// core JS
\Ivy\Template::addJS("core/js/helper.js");

// template hooks
// start router
$router = new \Bramus\Router\Router();
$router->setBasePath(_SUBFOLDER);

// template hooks and routes
include \Ivy\Template::setTemplateFile('hooks/hook.basic.php');
$hook_template_editor = \Ivy\Template::setTemplateFile('hooks/hook.editor.php');
if (file_exists($hook_template_editor)) {
Expand All @@ -47,56 +50,11 @@
}

// plugin hooks and routes
$router = new \Bramus\Router\Router();
$router->setBasePath(_SUBFOLDER);
$plugin = new \Ivy\Plugin;
$plugin->run();
include _PUBLIC_PATH . 'core/include/routes.php';
$router->run();

// minify
use MatthiasMullie\Minify;

function minify_css_files(): void
{
$minify = new Minify\CSS();

if(\Ivy\Setting::$cache['minify_css']->bool){
if(!file_exists(\Ivy\Template::setTemplateFile('css/minified.css'))){
foreach(\Ivy\Template::$css as $cssfile){
$sourcePath = \Ivy\Template::setTemplateFile($cssfile);
$minify->add($sourcePath);
}
$minify->minify(_PUBLIC_PATH . _TEMPLATE_SUB . 'css/minified.css');
}
} else {
if(file_exists(\Ivy\Template::setTemplateFile('css/minified.css'))){
unlink(\Ivy\Template::setTemplateFile('css/minified.css'));
}
}

}

$hooks->add_action('add_css_action','minify_css_files','9999');

function minify_js_files(): void
{
$minify = new Minify\JS();

if(\Ivy\Setting::$cache['minify_js']->bool){
if(!file_exists(\Ivy\Template::setTemplateFile('js/minified.js'))){
foreach(\Ivy\Template::$js as $jsfile){
$sourcePath = \Ivy\Template::setTemplateFile($jsfile);
$minify->add($sourcePath);
}
$minify->minify(_PUBLIC_PATH . _TEMPLATE_SUB . 'js/minified.js');
}
} else {
if(file_exists(\Ivy\Template::setTemplateFile('js/minified.js'))){
unlink(\Ivy\Template::setTemplateFile('js/minified.js'));
}
}

}
// standard routes
include _PUBLIC_PATH . 'core/include/routes.php';

$hooks->add_action('add_js_action','minify_js_files','9999');
// run router
$router->run();
4 changes: 0 additions & 4 deletions core/include/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@
}
catch (\Delight\Auth\InvalidSelectorTokenPairException $e) {
\Ivy\Message::add('Invalid token');
// die('Invalid token');
}
catch (\Delight\Auth\TokenExpiredException $e) {
\Ivy\Message::add('Token expired');
// die('Token expired');
}
catch (\Delight\Auth\UserAlreadyExistsException $e) {
\Ivy\Message::add('Email address already exists');
// die('Email address already exists');
}
catch (\Delight\Auth\TooManyRequestsException $e) {
\Ivy\Message::add('Too many requests');
// die('Too many requests');
}
}
4 changes: 0 additions & 4 deletions core/include/reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
}
catch (\Delight\Auth\InvalidSelectorTokenPairException $e) {
\Ivy\Message::add('Invalid token');
// die('Invalid token');
}
catch (\Delight\Auth\TokenExpiredException $e) {
\Ivy\Message::add('Token expired');
// die('Token expired');
}
catch (\Delight\Auth\ResetDisabledException $e) {
\Ivy\Message::add('Password reset is disabled');
// die('Password reset is disabled');
}
catch (\Delight\Auth\TooManyRequestsException $e) {
\Ivy\Message::add('Too many requests');
// die('Too many requests');
}
}
8 changes: 4 additions & 4 deletions core/include/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$router->before('GET|POST', '/admin/([a-z0-9_-]+)', function($id) {
global $auth;
if($auth->isLoggedIn()){
if(!canEditAsAdmin($auth) && !in_array($id,['register','login','logout','reset','profile'])){
if(!\Ivy\User::canEditAsAdmin($auth) && !in_array($id,['register','login','logout','reset','profile'])){
header('location:' . _BASE_PATH);
exit();
}
Expand All @@ -33,7 +33,7 @@
$router->before('GET|POST', '/plugin/.*', function() {
global $auth;
if($auth->isLoggedIn()){
if(!canEditAsSuperAdmin($auth)){
if(!\Ivy\User::canEditAsSuperAdmin($auth)){
header('location:' . _BASE_PATH);
exit();
}
Expand Down Expand Up @@ -97,12 +97,12 @@
exit;
}
if($auth->isLoggedIn() && in_array($id,['setting','plugin','register','reset','template','user'])){
if (!canEditAsAdmin($auth)){
if (!\Ivy\User::canEditAsAdmin($auth)){
header('location:' . _BASE_PATH . 'admin/profile');
exit;
}
}
if(canEditAsAdmin($auth) || (!canEditAsAdmin($auth) && in_array($id,['register','login','logout','reset','profile']))):
if(\Ivy\User::canEditAsAdmin($auth) || (!\Ivy\User::canEditAsAdmin($auth) && in_array($id,['register','login','logout','reset','profile']))):
\Ivy\Template::$file = \Ivy\Template::setTemplateFile('admin/' . $id . '.php');
endif;
});
Expand Down
35 changes: 35 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// Include init
require 'core/include/init.php';

global $hooks;
?>
<!DOCTYPE html>
<html lang="<?php echo substr(\Ivy\Setting::$cache['language']->value, 0, 2); ?>">
Expand All @@ -31,6 +32,23 @@

<?php $hooks->do_action('add_css_action');?>

<?php
if(\Ivy\Setting::$cache['minify_css']->bool){
if(!file_exists(\Ivy\Template::setTemplateFile('css/minified.css'))){
$minify = new MatthiasMullie\Minify\CSS();
foreach(\Ivy\Template::$css as $cssfile){
$sourcePath = \Ivy\Template::setTemplateFile($cssfile);
$minify->add($sourcePath);
}
$minify->minify(_PUBLIC_PATH . _TEMPLATE_SUB . 'css/minified.css');
}
} else {
if(file_exists(\Ivy\Template::setTemplateFile('css/minified.css'))){
unlink(\Ivy\Template::setTemplateFile('css/minified.css'));
}
}
?>

<?php if(\Ivy\Setting::$cache['minify_css']->bool): ?>
<link defer href="<?php print _BASE_PATH . \Ivy\Template::setTemplateFile('css/minified.css'); ?>" rel="stylesheet" type="text/css">
<?php else: ?>
Expand Down Expand Up @@ -76,6 +94,23 @@

<?php $hooks->do_action('add_js_action'); ?>

<?php
if(\Ivy\Setting::$cache['minify_js']->bool){
if(!file_exists(\Ivy\Template::setTemplateFile('js/minified.js'))){
$minify = new MatthiasMullie\Minify\JS();
foreach(\Ivy\Template::$js as $jsfile){
$sourcePath = \Ivy\Template::setTemplateFile($jsfile);
$minify->add($sourcePath);
}
$minify->minify(_PUBLIC_PATH . _TEMPLATE_SUB . 'js/minified.js');
}
} else {
if(file_exists(\Ivy\Template::setTemplateFile('js/minified.js'))){
unlink(\Ivy\Template::setTemplateFile('js/minified.js'));
}
}
?>

<?php if(!empty(\Ivy\Template::$esm)): ?>
<?php foreach(\Ivy\Template::$esm as $esmfile): ?>
<script type="module" src="<?php print _BASE_PATH . \Ivy\Template::setTemplateFile($esmfile); ?>"></script>
Expand Down
2 changes: 1 addition & 1 deletion plugins/Article/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){

global $router, $db;

Expand Down
2 changes: 1 addition & 1 deletion plugins/Audio/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){

global $router;
$router->post('/audio/(\w+)/(\d+)(/\w+)?(/\d+)?', function($action, $id, $template_route = null, $template_id = null) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/Documentation/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){

global $router, $db, $auth;
$router->post('/documentation/(\w+)/(\d+)(/\w+)?(/\d+)?', function($action, $id, $template_route = null, $template_id = null) use($db, $auth) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/Gig/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){

global $router, $db, $auth;
$router->post('/gig/(\w+)/(\d+)(/\w+)?(/\d+)?', function($action, $id, $template_route = null, $template_id = null) use($db, $auth) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/Image/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){
global $router, $auth, $db;

if($auth->isLoggedIn()){
Expand Down
2 changes: 1 addition & 1 deletion plugins/SortItem/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){
global $router;

$router->post('/item/sort/', function(){
Expand Down
2 changes: 1 addition & 1 deletion plugins/Tag/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){
global $router, $db;
$router->post('/tag/post', function() use($db, $auth) {
(new \Tag\Item)->post();
Expand Down
2 changes: 1 addition & 1 deletion plugins/Tag/template/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth, $tag;
?>

<?php if (canEditAsEditor($auth) && \Ivy\Template::$content->author): ?>
<?php if (\Ivy\User::canEditAsEditor($auth) && \Ivy\Template::$content->author): ?>
<div class="select-container">
<span class="select-arrow">
<?php print file_get_contents(_BASE_PATH . "media/icon/" . "feather/chevron-down.svg"); ?>
Expand Down
2 changes: 1 addition & 1 deletion plugins/Text/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){

global $router;
$router->post('/text/(\w+)/(\d+)(/\w+)?(/\d+)?', function($action, $id, $template_route = null, $template_id = null) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/Vimeo/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){
global $router;

$router->post('/vimeo/(\w+)/(\d+)(/\w+)?(/\d+)?', function($action, $id, $template_route = null, $template_id = null) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/Youtube/hooks/hook.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;

if($auth->isLoggedIn()){
if(canEditAsEditor($auth)){
if(\Ivy\User::canEditAsEditor($auth)){
global $router;

$router->post('/youtube/(\w+)/(\d+)(/\w+)?(/\d+)?', function($action, $id, $template_route = null, $template_id = null) {
Expand Down
2 changes: 1 addition & 1 deletion templates/base/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
?>

<footer class="bg-secondary position-relative">
<?php if(canEditAsAdmin($auth)): ?>
<?php if(\Ivy\User::canEditAsAdmin($auth)): ?>
<nav class="menu">
<ul>
<li>
Expand Down
2 changes: 1 addition & 1 deletion templates/base/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@

<link rel="manifest" href="<?php print _BASE_PATH; ?>manifest.json" crossorigin="use-credentials">

<title><?php print \Ivy\Setting::$cache['title']->value; ?></title>
<title><?php print \Ivy\Setting::$cache['title']->value; ?></title>
2 changes: 1 addition & 1 deletion templates/base/include/add_item_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $auth;
?>

<?php if(canEditAsEditor($auth)): ?>
<?php if(\Ivy\User::canEditAsEditor($auth)): ?>

<input id="overlay-mode" name="overlay-mode" class="overlay-mode-checkbox d-none" type="checkbox">

Expand Down
2 changes: 1 addition & 1 deletion templates/base/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?php endif; ?>
</div>

<?php if(canEditAsEditor($auth)): ?>
<?php if(\Ivy\User::canEditAsEditor($auth)): ?>
<input id="overlay-mode" name="overlay-mode" class="overlay-mode-checkbox d-none" type="checkbox">
<label class="overlay" for="overlay-mode">
<div class="popup">
Expand Down

0 comments on commit a1b94c1

Please sign in to comment.