From 80048ad1ddf0485c1ebf9817312c10302ac34403 Mon Sep 17 00:00:00 2001 From: Joey Kimsey Date: Tue, 20 Aug 2024 06:37:38 -0400 Subject: [PATCH] various bugfixes --- .gitignore | 1 - app/classes/forms.php | 534 +++++++++++++++++ app/config/constants.php | 2 + app/controllers/admin/composer.php | 2 +- app/controllers/admin/routes.php | 2 +- app/functions/forms.php | 542 ------------------ app/models/log.php | 2 +- app/models/user.php | 2 +- app/plugins/blog/models/posts.php | 2 +- app/plugins/bugreport/models/bugreport.php | 2 +- app/plugins/comments/models/comments.php | 2 +- app/plugins/messages/models/message.php | 2 +- .../notifications/models/notification.php | 2 +- app/plugins/subscribe/plugin.php | 7 + app/plugins/subscribe/views/footer/right.html | 15 + app/templates/default/default.inc.php | 9 +- app/views/foot.html | 44 -- app/views/footer/center.html | 9 + app/views/footer/container.html | 17 + app/views/footer/left.html | 7 + app/views/footer/right.html | 15 + bin/autoload.php | 6 +- bin/tempus_project.php | 97 +++- install.php | 53 +- 24 files changed, 729 insertions(+), 647 deletions(-) delete mode 100644 app/functions/forms.php create mode 100644 app/plugins/subscribe/views/footer/right.html delete mode 100644 app/views/foot.html create mode 100644 app/views/footer/center.html create mode 100644 app/views/footer/container.html create mode 100644 app/views/footer/left.html create mode 100644 app/views/footer/right.html diff --git a/.gitignore b/.gitignore index ff7b9e7..91f4cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -61,5 +61,4 @@ logs/* .vscode/ mail.log vendor/canary/logs/* -docker/.env .env diff --git a/app/classes/forms.php b/app/classes/forms.php index 11293f8..a60b7af 100644 --- a/app/classes/forms.php +++ b/app/classes/forms.php @@ -16,11 +16,19 @@ namespace TheTempusProject\Classes; use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Canary\Bin\Canary as Debug; +use TheTempusProject\Bedrock\Functions\Input; +use TheTempusProject\Models\User; +use TheTempusProject\Classes\Forms; +use TheTempusProject\Bedrock\Classes\Database; class Forms extends Check { private static $formHandlers = []; + private static $initialized = false; public static function check( $formName ) { + if ( self::$initialized !== true ) { + self::initHandlers(); + } if ( empty( self::$formHandlers[ $formName ] ) ) { Debug::error( "Form not found: $formName" ); return false; @@ -74,4 +82,530 @@ class Forms extends Check { } return true; } + + /** + * Adds these functions to the form list. + */ + public function __construct() { + if ( self::$initialized === true ) { + return; + } + self::initHandlers(); + } + + private static function initHandlers() { + self::addHandler( 'passwordResetCode', __CLASS__, 'passwordResetCode' ); + self::addHandler( 'createRoute', __CLASS__, 'createRoute' ); + self::addHandler( 'editRoute', __CLASS__, 'editRoute' ); + self::addHandler( 'register', __CLASS__, 'register' ); + self::addHandler( 'createUser', __CLASS__, 'createUser' ); + self::addHandler( 'editUser', __CLASS__, 'editUser' ); + self::addHandler( 'login', __CLASS__, 'login' ); + self::addHandler( 'changeEmail', __CLASS__, 'changeEmail' ); + self::addHandler( 'changePassword', __CLASS__, 'changePassword' ); + self::addHandler( 'passwordReset', __CLASS__, 'passwordReset' ); + self::addHandler( 'emailConfirmation', __CLASS__, 'emailConfirmation' ); + self::addHandler( 'confirmationResend', __CLASS__, 'confirmationResend' ); + self::addHandler( 'replyMessage', __CLASS__, 'replyMessage' ); + self::addHandler( 'newMessage', __CLASS__, 'newMessage' ); + self::addHandler( 'userPrefs', __CLASS__, 'userPrefs' ); + self::addHandler( 'newGroup', __CLASS__, 'newGroup' ); + self::addHandler( 'editGroup', __CLASS__, 'editGroup' ); + self::addHandler( 'install', __CLASS__, 'install' ); + self::addHandler( 'installStart', __CLASS__, 'install', [ 'start' ] ); + self::addHandler( 'installAgreement', __CLASS__, 'install', [ 'agreement' ] ); + self::addHandler( 'installCheck', __CLASS__, 'install', [ 'check' ] ); + self::addHandler( 'installConfigure', __CLASS__, 'install', [ 'configure' ] ); + self::addHandler( 'installRouting', __CLASS__, 'install', [ 'routing' ] ); + self::addHandler( 'installModels', __CLASS__, 'install', [ 'models' ] ); + self::addHandler( 'installPlugins', __CLASS__, 'install', [ 'plugins' ] ); + self::addHandler( 'installResources', __CLASS__, 'install', [ 'resources' ] ); + self::addHandler( 'installAdminUser', __CLASS__, 'install', [ 'adminUser' ] ); + self::$initialized = true; + } + + /** + * Validates the installer forms. + * + * @return {bool} + */ + public static function install( $page = '' ) { + // if ( !self::token() ) { + // return false; + // } + switch ( $page ) { + case 'configure': + if ( ! Input::exists( 'submit' ) ) { + return false; + } + if ( !Database::check( Input::post( 'dbHost' ), Input::post( 'dbName' ), Input::post( 'dbUsername' ), Input::post( 'dbPassword' ) ) ) { + self::addUserError( 'DB connection error.' ); + return false; + } + return true; + case 'adminUser': + if ( !self::checkUsername( Input::post( 'newUsername' ) ) ) { + self::addUserError( 'Invalid username.' ); + return false; + } + if ( !self::password( Input::post( 'userPassword' ) ) ) { + self::addUserError( 'Invalid password.' ); + return false; + } + if ( Input::post( 'userPassword' ) !== Input::post( 'userPassword2' ) ) { + self::addUserError( 'Passwords do not match.' ); + return false; + } + if ( Input::post( 'userEmail' ) !== Input::post( 'userEmail2' ) ) { + self::addUserError( 'Emails do not match.' ); + return false; + } + return true; + case 'check': + if ( !self::uploads() ) { + self::addUserError( 'Uploads are disabled.' ); + return false; + } + if ( !self::php() ) { + self::addUserError( 'PHP version is too old.' ); + return false; + } + if ( !self::phpExtensions() ) { + self::addUserError( 'PHP extensions are missing.' ); + return false; + } + if ( !self::sessions() ) { + self::addUserError( 'There is an error with Sessions.' ); + return false; + } + if ( !self::mail() ) { + self::addUserError( 'PHP mail is not enabled.' ); + return false; + } + if ( !self::safe() ) { + self::addUserError( 'Safe mode is enabled.' ); + return false; + } + if ( ! Input::exists( 'submit' ) ) { + return false; + } + return true; + case 'start': + case 'agreement': + case 'routing': + case 'models': + case 'plugins': + case 'resources': + if ( ! Input::exists( 'submit' ) ) { + return false; + } + return true; + default: + return false; + } + return false; + } + + /** + * Validates the password re-send form. + * + * @return {bool} + */ + public static function passwordResetCode() { + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the route creation form. + * + * @return {bool} + */ + public static function createRoute() { + if ( !Input::exists( 'redirect_type' ) ) { + return false; + } + if ( 'external' == Input::post( 'redirect_type' ) && !self::url( Input::post( 'forwarded_url' ) ) ) { + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the route edit form. + * + * @return {bool} + */ + public static function editRoute() { + if ( !Input::exists( 'redirect_type' ) ) { + return false; + } + if ( 'external' == Input::post( 'redirect_type' ) && !self::url( Input::post( 'forwarded_url' ) ) ) { + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the user creation form. + * + * @return {bool} + */ + public static function createUser() { + $user = new User; + if ( !$user->checkUsername( Input::post( 'username' ) ) ) { + self::addUserError( 'Invalid username.' ); + return false; + } + if ( !self::password( Input::post( 'password' ) ) ) { + self::addUserError( 'Invalid password.' ); + return false; + } + if ( !self::email( Input::post( 'email' ) ) ) { + self::addUserError( 'Invalid Email.' ); + return false; + } + if ( !$user->noEmailExists( Input::post( 'email' ) ) ) { + self::addUserError( 'A user with that email is already registered.' ); + return false; + } + if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { + self::addUserError( 'Passwords do not match.' ); + return false; + } + if ( Input::post( 'email' ) !== Input::post( 'email2' ) ) { + self::addUserError( 'Emails do not match.' ); + return false; + } + if ( !Input::post( 'groupSelect' ) ) { + self::addUserError( 'You must select a group for the new user.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the user edit form. + * + * @return {bool} + */ + public static function editUser() { + $user = new User; + if ( !$user->checkUsername( Input::post( 'username' ) ) ) { + self::addUserError( 'Invalid username.' ); + return false; + } + if ( Input::exists( 'password' ) ) { + if ( !self::password( Input::post( 'password' ) ) ) { + self::addUserError( 'Invalid password.' ); + return false; + } + if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { + self::addUserError( 'Passwords do not match.' ); + return false; + } + } + if ( !self::email( Input::post( 'email' ) ) ) { + self::addUserError( 'Invalid Email.' ); + return false; + } + if ( !Input::post( 'groupSelect' ) ) { + self::addUserError( 'You must select a group for the new user.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the user registration form. + * + * @return {bool} + */ + public static function register() { + $user = new User; + if ( !self::checkUsername( Input::post( 'username' ) ) ) { + self::addUserError( 'Invalid username.' ); + return false; + } + if ( !self::password( Input::post( 'password' ) ) ) { + self::addUserError( 'Invalid password.' ); + return false; + } + if ( !self::email( Input::post( 'email' ) ) ) { + self::addUserError( 'Invalid Email.' ); + return false; + } + if ( !$user->noEmailExists( Input::post( 'email' ) ) ) { + self::addUserError( 'A user with that email is already registered.' ); + return false; + } + if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { + self::addUserError( 'Passwords do not match.' ); + return false; + } + if ( Input::post( 'email' ) !== Input::post( 'email2' ) ) { + self::addUserError( 'Emails do not match.' ); + return false; + } + if ( Input::post( 'terms' ) != '1' ) { + self::addUserError( 'You must agree to the terms of service.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the user login form. + * + * @return {bool} + */ + public static function login() { + if ( !self::checkUsername( Input::post( 'username' ) ) ) { + self::addUserError( 'Invalid username.' ); + return false; + } + if ( !self::password( Input::post( 'password' ) ) ) { + self::addUserError( 'Invalid password.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the email change form. + * + * @return {bool} + */ + public static function changeEmail() { + if ( !self::email( Input::post( 'email' ) ) ) { + self::addUserError( 'Invalid Email.' ); + return false; + } + if ( Input::post( 'email' ) !== Input::post( 'email2' ) ) { + self::addUserError( 'Emails do not match.' ); + return false; + } + if ( !self::token() ) { + return false; + } + + return true; + } + + /** + * Validates the password change form. + * + * @return {bool} + */ + public static function changePassword() { + if ( !self::password( Input::post( 'password' ) ) ) { + self::addUserError( 'Invalid password.' ); + return false; + } + if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { + self::addUserError( 'Passwords do not match.' ); + return false; + } + if ( !self::token() ) { + return false; + } + + return true; + } + + /** + * Validates the password reset form. + * + * @return {bool} + */ + public static function passwordReset() { + if ( !self::password( Input::post( 'password' ) ) ) { + self::addUserError( 'Invalid password.' ); + return false; + } + if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { + self::addUserError( 'Passwords do not match.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the email confirmation re-send form. + * + * @return {bool} + */ + public static function emailConfirmation() { + if ( !Input::exists( 'confirmationCode' ) ) { + self::addUserError( 'No confirmation code provided.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the email confirmation re-send form. + * + * @return {bool} + */ + public static function confirmationResend() { + if ( !Input::exists( 'resendConfirmation' ) ) { + self::addUserError( 'Confirmation not provided.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the reply message form. + * + * @return {bool} + */ + public static function replyMessage() { + if ( !Input::exists( 'message' ) ) { + self::addUserError( 'Reply cannot be empty.' ); + return false; + } + if ( !Input::exists( 'messageID' ) ) { + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the new message form. + * + * @return {bool} + */ + public static function newMessage() { + if ( !Input::exists( 'toUser' ) ) { + self::addUserError( 'You must specify a user to send the message to.' ); + return false; + } + if ( !Input::exists( 'subject' ) ) { + self::addUserError( 'You must have a subject for your message.' ); + return false; + } + if ( !Input::exists( 'message' ) ) { + self::addUserError( 'No message entered.' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the user preferences form. + * + * @return {bool} + */ + public static function userPrefs() { + // @todo make this a real check + if ( !Input::exists( 'timeFormat' ) ) { + self::addUserError( 'You must specify timeFormat' ); + return false; + } + if ( !Input::exists( 'pageLimit' ) ) { + self::addUserError( 'You must specify pageLimit' ); + return false; + } + if ( !Input::exists( 'gender' ) ) { + self::addUserError( 'You must specify gender' ); + return false; + } + if ( !Input::exists( 'dateFormat' ) ) { + self::addUserError( 'You must specify dateFormat' ); + return false; + } + if ( !Input::exists( 'timezone' ) ) { + self::addUserError( 'You must specify timezone' ); + return false; + } + if ( !Input::exists( 'updates' ) ) { + self::addUserError( 'You must specify updates' ); + return false; + } + if ( !Input::exists( 'newsletter' ) ) { + self::addUserError( 'You must specify newsletter' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the group creation form. + * + * @return {bool} + */ + public static function newGroup() { + if ( !Input::exists( 'name' ) ) { + self::addUserError( 'You must specify a name' ); + return false; + } + if ( !self::dataTitle( Input::exists( 'name' ) ) ) { + self::addUserError( 'invalid group name' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } + + /** + * Validates the group edit form. + * + * @return {bool} + */ + public static function editGroup() { + if ( !Input::exists( 'name' ) ) { + self::addUserError( 'You must specify a name' ); + return false; + } + if ( !self::dataTitle( Input::exists( 'name' ) ) ) { + self::addUserError( 'invalid group name' ); + return false; + } + if ( !self::token() ) { + return false; + } + return true; + } } diff --git a/app/config/constants.php b/app/config/constants.php index 801882f..32e8dda 100644 --- a/app/config/constants.php +++ b/app/config/constants.php @@ -43,6 +43,8 @@ if ( ! defined( 'CONFIG_DIRECTORY' ) ) { // Cookies define( 'DEFAULT_COOKIE_PREFIX', 'TP_'); // Debug + + define( 'CANARY_DEBUG_DIRECTORY', APP_ROOT_DIRECTORY . 'logs' . DIRECTORY_SEPARATOR ); define( 'CANARY_DEBUG_LEVEL_ERROR', 'error' ); define( 'CANARY_DEBUG_LEVEL_WARN', 'warn' ); define( 'CANARY_DEBUG_LEVEL_INFO', 'info' ); diff --git a/app/controllers/admin/composer.php b/app/controllers/admin/composer.php index 49880af..0f14bb2 100644 --- a/app/controllers/admin/composer.php +++ b/app/controllers/admin/composer.php @@ -59,6 +59,6 @@ class Composer extends AdminController { $out[] = (object) $versionsInstalled[ $name ]; } - Views::view( 'admin.dependencies', $out ); + Views::view( 'admin.modules.composer.dependencies', $out ); } } diff --git a/app/controllers/admin/routes.php b/app/controllers/admin/routes.php index f72e95c..284fab6 100644 --- a/app/controllers/admin/routes.php +++ b/app/controllers/admin/routes.php @@ -11,7 +11,7 @@ */ namespace TheTempusProject\Controllers\Admin; -use TheTempusProject\TTPForms; +use TheTempusProject\Classes\Forms as TTPForms; use TheTempusProject\Houdini\Classes\Views; use TheTempusProject\Houdini\Classes\Issues; use TheTempusProject\Houdini\Classes\Navigation; diff --git a/app/functions/forms.php b/app/functions/forms.php deleted file mode 100644 index eceb619..0000000 --- a/app/functions/forms.php +++ /dev/null @@ -1,542 +0,0 @@ - - * @link https://TheTempusProject.com - * @license https://opensource.org/licenses/MIT [MIT LICENSE] - */ -namespace TheTempusProject; - -use TheTempusProject\Bedrock\Functions\Input; -use TheTempusProject\Bedrock\Functions\Check; -use TheTempusProject\Models\User; -use TheTempusProject\Classes\Forms; -use TheTempusProject\Bedrock\Classes\Database; - -class TTPForms extends Forms { - /** - * Adds these functions to the form list. - */ - public function __construct() { - self::addHandler( 'passwordResetCode', __CLASS__, 'passwordResetCode' ); - self::addHandler( 'createRoute', __CLASS__, 'createRoute' ); - self::addHandler( 'editRoute', __CLASS__, 'editRoute' ); - self::addHandler( 'register', __CLASS__, 'register' ); - self::addHandler( 'createUser', __CLASS__, 'createUser' ); - self::addHandler( 'editUser', __CLASS__, 'editUser' ); - self::addHandler( 'login', __CLASS__, 'login' ); - self::addHandler( 'changeEmail', __CLASS__, 'changeEmail' ); - self::addHandler( 'changePassword', __CLASS__, 'changePassword' ); - self::addHandler( 'passwordReset', __CLASS__, 'passwordReset' ); - self::addHandler( 'emailConfirmation', __CLASS__, 'emailConfirmation' ); - self::addHandler( 'confirmationResend', __CLASS__, 'confirmationResend' ); - self::addHandler( 'replyMessage', __CLASS__, 'replyMessage' ); - self::addHandler( 'newMessage', __CLASS__, 'newMessage' ); - self::addHandler( 'userPrefs', __CLASS__, 'userPrefs' ); - self::addHandler( 'newGroup', __CLASS__, 'newGroup' ); - self::addHandler( 'editGroup', __CLASS__, 'editGroup' ); - self::addHandler( 'install', __CLASS__, 'install' ); - self::addHandler( 'installStart', __CLASS__, 'install', [ 'start' ] ); - self::addHandler( 'installAgreement', __CLASS__, 'install', [ 'agreement' ] ); - self::addHandler( 'installCheck', __CLASS__, 'install', [ 'check' ] ); - self::addHandler( 'installConfigure', __CLASS__, 'install', [ 'configure' ] ); - self::addHandler( 'installRouting', __CLASS__, 'install', [ 'routing' ] ); - self::addHandler( 'installModels', __CLASS__, 'install', [ 'models' ] ); - self::addHandler( 'installPlugins', __CLASS__, 'install', [ 'plugins' ] ); - self::addHandler( 'installResources', __CLASS__, 'install', [ 'resources' ] ); - self::addHandler( 'installAdminUser', __CLASS__, 'install', [ 'adminUser' ] ); - } - - /** - * Validates the installer forms. - * - * @return {bool} - */ - public static function install( $page = '' ) { - // if ( !self::token() ) { - // return false; - // } - switch ( $page ) { - case 'configure': - if ( ! Input::exists( 'submit' ) ) { - return false; - } - if ( !Database::check( Input::post( 'dbHost' ), Input::post( 'dbName' ), Input::post( 'dbUsername' ), Input::post( 'dbPassword' ) ) ) { - self::addUserError( 'DB connection error.' ); - return false; - } - return true; - case 'adminUser': - if ( !self::checkUsername( Input::post( 'newUsername' ) ) ) { - self::addUserError( 'Invalid username.' ); - return false; - } - if ( !self::password( Input::post( 'userPassword' ) ) ) { - self::addUserError( 'Invalid password.' ); - return false; - } - if ( Input::post( 'userPassword' ) !== Input::post( 'userPassword2' ) ) { - self::addUserError( 'Passwords do not match.' ); - return false; - } - if ( Input::post( 'userEmail' ) !== Input::post( 'userEmail2' ) ) { - self::addUserError( 'Emails do not match.' ); - return false; - } - return true; - case 'check': - if ( !self::uploads() ) { - self::addUserError( 'Uploads are disabled.' ); - return false; - } - if ( !self::php() ) { - self::addUserError( 'PHP version is too old.' ); - return false; - } - if ( !self::phpExtensions() ) { - self::addUserError( 'PHP extensions are missing.' ); - return false; - } - if ( !self::sessions() ) { - self::addUserError( 'There is an error with Sessions.' ); - return false; - } - if ( !self::mail() ) { - self::addUserError( 'PHP mail is not enabled.' ); - return false; - } - if ( !self::safe() ) { - self::addUserError( 'Safe mode is enabled.' ); - return false; - } - if ( ! Input::exists( 'submit' ) ) { - return false; - } - return true; - case 'start': - case 'agreement': - case 'routing': - case 'models': - case 'plugins': - case 'resources': - if ( ! Input::exists( 'submit' ) ) { - return false; - } - return true; - default: - return false; - } - return false; - } - - /** - * Validates the password re-send form. - * - * @return {bool} - */ - public static function passwordResetCode() { - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the route creation form. - * - * @return {bool} - */ - public static function createRoute() { - if ( !Input::exists( 'redirect_type' ) ) { - return false; - } - if ( 'external' == Input::post( 'redirect_type' ) && !self::url( Input::post( 'forwarded_url' ) ) ) { - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the route edit form. - * - * @return {bool} - */ - public static function editRoute() { - if ( !Input::exists( 'redirect_type' ) ) { - return false; - } - if ( 'external' == Input::post( 'redirect_type' ) && !self::url( Input::post( 'forwarded_url' ) ) ) { - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the user creation form. - * - * @return {bool} - */ - public static function createUser() { - $user = new User; - if ( !$user->checkUsername( Input::post( 'username' ) ) ) { - self::addUserError( 'Invalid username.' ); - return false; - } - if ( !self::password( Input::post( 'password' ) ) ) { - self::addUserError( 'Invalid password.' ); - return false; - } - if ( !self::email( Input::post( 'email' ) ) ) { - self::addUserError( 'Invalid Email.' ); - return false; - } - if ( !$user->noEmailExists( Input::post( 'email' ) ) ) { - self::addUserError( 'A user with that email is already registered.' ); - return false; - } - if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { - self::addUserError( 'Passwords do not match.' ); - return false; - } - if ( Input::post( 'email' ) !== Input::post( 'email2' ) ) { - self::addUserError( 'Emails do not match.' ); - return false; - } - if ( !Input::post( 'groupSelect' ) ) { - self::addUserError( 'You must select a group for the new user.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the user edit form. - * - * @return {bool} - */ - public static function editUser() { - $user = new User; - if ( !$user->checkUsername( Input::post( 'username' ) ) ) { - self::addUserError( 'Invalid username.' ); - return false; - } - if ( Input::exists( 'password' ) ) { - if ( !self::password( Input::post( 'password' ) ) ) { - self::addUserError( 'Invalid password.' ); - return false; - } - if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { - self::addUserError( 'Passwords do not match.' ); - return false; - } - } - if ( !self::email( Input::post( 'email' ) ) ) { - self::addUserError( 'Invalid Email.' ); - return false; - } - if ( !Input::post( 'groupSelect' ) ) { - self::addUserError( 'You must select a group for the new user.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the user registration form. - * - * @return {bool} - */ - public static function register() { - $user = new User; - if ( !self::checkUsername( Input::post( 'username' ) ) ) { - self::addUserError( 'Invalid username.' ); - return false; - } - if ( !self::password( Input::post( 'password' ) ) ) { - self::addUserError( 'Invalid password.' ); - return false; - } - if ( !self::email( Input::post( 'email' ) ) ) { - self::addUserError( 'Invalid Email.' ); - return false; - } - if ( !$user->noEmailExists( Input::post( 'email' ) ) ) { - self::addUserError( 'A user with that email is already registered.' ); - return false; - } - if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { - self::addUserError( 'Passwords do not match.' ); - return false; - } - if ( Input::post( 'email' ) !== Input::post( 'email2' ) ) { - self::addUserError( 'Emails do not match.' ); - return false; - } - if ( Input::post( 'terms' ) != '1' ) { - self::addUserError( 'You must agree to the terms of service.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the user login form. - * - * @return {bool} - */ - public static function login() { - if ( !self::checkUsername( Input::post( 'username' ) ) ) { - self::addUserError( 'Invalid username.' ); - return false; - } - if ( !self::password( Input::post( 'password' ) ) ) { - self::addUserError( 'Invalid password.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the email change form. - * - * @return {bool} - */ - public static function changeEmail() { - if ( !self::email( Input::post( 'email' ) ) ) { - self::addUserError( 'Invalid Email.' ); - return false; - } - if ( Input::post( 'email' ) !== Input::post( 'email2' ) ) { - self::addUserError( 'Emails do not match.' ); - return false; - } - if ( !self::token() ) { - return false; - } - - return true; - } - - /** - * Validates the password change form. - * - * @return {bool} - */ - public static function changePassword() { - if ( !self::password( Input::post( 'password' ) ) ) { - self::addUserError( 'Invalid password.' ); - return false; - } - if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { - self::addUserError( 'Passwords do not match.' ); - return false; - } - if ( !self::token() ) { - return false; - } - - return true; - } - - /** - * Validates the password reset form. - * - * @return {bool} - */ - public static function passwordReset() { - if ( !self::password( Input::post( 'password' ) ) ) { - self::addUserError( 'Invalid password.' ); - return false; - } - if ( Input::post( 'password' ) !== Input::post( 'password2' ) ) { - self::addUserError( 'Passwords do not match.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the email confirmation re-send form. - * - * @return {bool} - */ - public static function emailConfirmation() { - if ( !Input::exists( 'confirmationCode' ) ) { - self::addUserError( 'No confirmation code provided.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the email confirmation re-send form. - * - * @return {bool} - */ - public static function confirmationResend() { - if ( !Input::exists( 'resendConfirmation' ) ) { - self::addUserError( 'Confirmation not provided.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the reply message form. - * - * @return {bool} - */ - public static function replyMessage() { - if ( !Input::exists( 'message' ) ) { - self::addUserError( 'Reply cannot be empty.' ); - return false; - } - if ( !Input::exists( 'messageID' ) ) { - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the new message form. - * - * @return {bool} - */ - public static function newMessage() { - if ( !Input::exists( 'toUser' ) ) { - self::addUserError( 'You must specify a user to send the message to.' ); - return false; - } - if ( !Input::exists( 'subject' ) ) { - self::addUserError( 'You must have a subject for your message.' ); - return false; - } - if ( !Input::exists( 'message' ) ) { - self::addUserError( 'No message entered.' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the user preferences form. - * - * @return {bool} - */ - public static function userPrefs() { - // @todo make this a real check - if ( !Input::exists( 'timeFormat' ) ) { - self::addUserError( 'You must specify timeFormat' ); - return false; - } - if ( !Input::exists( 'pageLimit' ) ) { - self::addUserError( 'You must specify pageLimit' ); - return false; - } - if ( !Input::exists( 'gender' ) ) { - self::addUserError( 'You must specify gender' ); - return false; - } - if ( !Input::exists( 'dateFormat' ) ) { - self::addUserError( 'You must specify dateFormat' ); - return false; - } - if ( !Input::exists( 'timezone' ) ) { - self::addUserError( 'You must specify timezone' ); - return false; - } - if ( !Input::exists( 'updates' ) ) { - self::addUserError( 'You must specify updates' ); - return false; - } - if ( !Input::exists( 'newsletter' ) ) { - self::addUserError( 'You must specify newsletter' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the group creation form. - * - * @return {bool} - */ - public static function newGroup() { - if ( !Input::exists( 'name' ) ) { - self::addUserError( 'You must specify a name' ); - return false; - } - if ( !self::dataTitle( Input::exists( 'name' ) ) ) { - self::addUserError( 'invalid group name' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } - - /** - * Validates the group edit form. - * - * @return {bool} - */ - public static function editGroup() { - if ( !Input::exists( 'name' ) ) { - self::addUserError( 'You must specify a name' ); - return false; - } - if ( !self::dataTitle( Input::exists( 'name' ) ) ) { - self::addUserError( 'invalid group name' ); - return false; - } - if ( !self::token() ) { - return false; - } - return true; - } -} - -new TTPForms; diff --git a/app/models/log.php b/app/models/log.php index 6e610f5..9131548 100644 --- a/app/models/log.php +++ b/app/models/log.php @@ -13,7 +13,7 @@ namespace TheTempusProject\Models; use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Bedrock\Classes\Config; -use TheTempusProject\Bedrock\Classes\CustomException; +use TheTempusProject\Canary\Classes\CustomException; use TheTempusProject\TheTempusProject as App; use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\Canary\Bin\Canary as Debug; diff --git a/app/models/user.php b/app/models/user.php index 0e7049e..d31fb99 100644 --- a/app/models/user.php +++ b/app/models/user.php @@ -21,7 +21,7 @@ use TheTempusProject\Bedrock\Functions\Hash; use TheTempusProject\Bedrock\Functions\Session; use TheTempusProject\Bedrock\Functions\Code; use TheTempusProject\Bedrock\Classes\Config; -use TheTempusProject\Bedrock\Classes\CustomException; +use TheTempusProject\Canary\Classes\CustomException; use TheTempusProject\Classes\Email; use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\Classes\Preferences; diff --git a/app/plugins/blog/models/posts.php b/app/plugins/blog/models/posts.php index 862ac33..3d593fe 100644 --- a/app/plugins/blog/models/posts.php +++ b/app/plugins/blog/models/posts.php @@ -17,7 +17,7 @@ use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Bedrock\Functions\Sanitize; use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\TheTempusProject as App; -use TheTempusProject\Bedrock\Classes\CustomException; +use TheTempusProject\Canary\Classes\CustomException; use TheTempusProject\Houdini\Classes\Filters; class Posts extends DatabaseModel { diff --git a/app/plugins/bugreport/models/bugreport.php b/app/plugins/bugreport/models/bugreport.php index 8f86698..5ae20ab 100644 --- a/app/plugins/bugreport/models/bugreport.php +++ b/app/plugins/bugreport/models/bugreport.php @@ -15,7 +15,7 @@ namespace TheTempusProject\Models; use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Bedrock\Classes\Config; use TheTempusProject\Canary\Bin\Canary as Debug; -use TheTempusProject\Bedrock\Classes\CustomException; +use TheTempusProject\Canary\Classes\CustomException; use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\Plugins\Bugreport as Plugin; use TheTempusProject\TheTempusProject as App; diff --git a/app/plugins/comments/models/comments.php b/app/plugins/comments/models/comments.php index 8514c63..8287d10 100644 --- a/app/plugins/comments/models/comments.php +++ b/app/plugins/comments/models/comments.php @@ -18,7 +18,7 @@ use TheTempusProject\Canary\Bin\Canary as Debug; use TheTempusProject\Houdini\Classes\Views; use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\TheTempusProject as App; -use TheTempusProject\Bedrock\Classes\CustomException; +use TheTempusProject\Canary\Classes\CustomException; use TheTempusProject\Houdini\Classes\Filters; class Comments extends DatabaseModel { diff --git a/app/plugins/messages/models/message.php b/app/plugins/messages/models/message.php index 4806477..b949437 100644 --- a/app/plugins/messages/models/message.php +++ b/app/plugins/messages/models/message.php @@ -18,7 +18,7 @@ use TheTempusProject\Canary\Bin\Canary as Debug; use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Bedrock\Functions\Sanitize; use TheTempusProject\TheTempusProject as App; -use TheTempusProject\Bedrock\Classes\CustomException; +use TheTempusProject\Canary\Classes\CustomException; class Message extends DatabaseModel { public $tableName = 'messages'; diff --git a/app/plugins/notifications/models/notification.php b/app/plugins/notifications/models/notification.php index 003a188..cb1395f 100644 --- a/app/plugins/notifications/models/notification.php +++ b/app/plugins/notifications/models/notification.php @@ -18,7 +18,7 @@ use TheTempusProject\Canary\Bin\Canary as Debug; use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\TheTempusProject as App; use TheTempusProject\Houdini\Classes\Views; -use TheTempusProject\Bedrock\Classes\CustomException; +use TheTempusProject\Canary\Classes\CustomException; class Notification extends DatabaseModel { public $tableName = 'notifications'; diff --git a/app/plugins/subscribe/plugin.php b/app/plugins/subscribe/plugin.php index 588cbdd..e95d34e 100644 --- a/app/plugins/subscribe/plugin.php +++ b/app/plugins/subscribe/plugin.php @@ -16,6 +16,8 @@ use ReflectionClass; use TheTempusProject\Classes\Installer; use TheTempusProject\Houdini\Classes\Navigation; use TheTempusProject\Classes\Plugin; +use TheTempusProject\Houdini\Classes\Components; +use TheTempusProject\Houdini\Classes\Views; use TheTempusProject\TheTempusProject as App; class Subscribe extends Plugin { @@ -31,4 +33,9 @@ class Subscribe extends Plugin { 'url' => '{ROOT_URL}admin/subscriptions', ], ]; + + public function __construct( $load = false ) { + parent::__construct( $load ); + Components::set( 'FOOTER_RIGHT', Views::simpleView( 'subscribe.footer.right') ); + } } diff --git a/app/plugins/subscribe/views/footer/right.html b/app/plugins/subscribe/views/footer/right.html new file mode 100644 index 0000000..de5c05b --- /dev/null +++ b/app/plugins/subscribe/views/footer/right.html @@ -0,0 +1,15 @@ + +
+

Subscribe

+ +
\ No newline at end of file diff --git a/app/templates/default/default.inc.php b/app/templates/default/default.inc.php index 9e60877..ef3b61f 100644 --- a/app/templates/default/default.inc.php +++ b/app/templates/default/default.inc.php @@ -31,9 +31,12 @@ class DefaultLoader extends Loader { Components::set( 'BOOTSTRAP_CDN', self::BOOTSTRAP_CDN ); $this->addCss( '' ); $this->addJs( '' ); - Components::set( 'LOGO', Config::getValue( 'main/logo' ) ); - Components::set( 'FOOT', Navigation::getMenuView( 'foot', 'FOOTER_LINKS', App::FOOTER_MENU_NAME, false ) ); - Components::set( 'COPY', Views::simpleView( 'copy') ); + Components::setIfNull( 'LOGO', Config::getValue( 'main/logo' ) ); + Components::setIfNull( 'FOOTER_LEFT', Navigation::getMenuView( 'footer.left', 'FOOTER_LINKS', App::FOOTER_MENU_NAME, false ) ); + Components::setIfNull( 'FOOTER_CENTER', Views::simpleView( 'footer.center') ); + Components::setIfNull( 'FOOTER_RIGHT', Views::simpleView( 'footer.right') ); + Components::setIfNull( 'FOOT', Views::simpleView( 'footer.container') ); + Components::setIfNull( 'COPY', Views::simpleView( 'copy') ); /** * Top-Nav */ diff --git a/app/views/foot.html b/app/views/foot.html deleted file mode 100644 index 2936f05..0000000 --- a/app/views/foot.html +++ /dev/null @@ -1,44 +0,0 @@ - \ No newline at end of file diff --git a/app/views/footer/center.html b/app/views/footer/center.html new file mode 100644 index 0000000..49675e3 --- /dev/null +++ b/app/views/footer/center.html @@ -0,0 +1,9 @@ +
+ +
\ No newline at end of file diff --git a/app/views/footer/container.html b/app/views/footer/container.html new file mode 100644 index 0000000..a1436a4 --- /dev/null +++ b/app/views/footer/container.html @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/app/views/footer/left.html b/app/views/footer/left.html new file mode 100644 index 0000000..d4e7db6 --- /dev/null +++ b/app/views/footer/left.html @@ -0,0 +1,7 @@ + +
+

Contact

+ +
\ No newline at end of file diff --git a/app/views/footer/right.html b/app/views/footer/right.html new file mode 100644 index 0000000..86a0cac --- /dev/null +++ b/app/views/footer/right.html @@ -0,0 +1,15 @@ + +
+

Information

+ +
\ No newline at end of file diff --git a/bin/autoload.php b/bin/autoload.php index 5774a9a..fe3860f 100644 --- a/bin/autoload.php +++ b/bin/autoload.php @@ -151,14 +151,14 @@ function sideLoad() { // Canary Autoloader (Debugging) if ( ! defined( 'CANARY_AUTOLOADED' ) ) { if ( defined( 'CANARY_ROOT_DIRECTORY' ) ) { - require_once CANARY_ROOT_DIRECTORY . 'bin' . DIRECTORY_SEPARATOR . 'autoload.php'; + require_once CANARY_ROOT_DIRECTORY . 'Bin' . DIRECTORY_SEPARATOR . 'autoload.php'; } } // Bedrock Autoloader (Core Functionality) if ( ! defined( 'BEDROCK_AUTOLOADED' ) ) { if ( defined( 'BEDROCK_ROOT_DIRECTORY' ) ) { - require_once BEDROCK_ROOT_DIRECTORY . 'bin' . DIRECTORY_SEPARATOR . 'autoload.php'; + require_once BEDROCK_ROOT_DIRECTORY . 'Bin' . DIRECTORY_SEPARATOR . 'autoload.php'; } } @@ -172,4 +172,4 @@ function sideLoad() { define( 'VENDOR_AUTOLOADED', false ); } -require_once 'bin/tempus_project.php'; +require_once 'tempus_project.php'; diff --git a/bin/tempus_project.php b/bin/tempus_project.php index f532416..ca76165 100644 --- a/bin/tempus_project.php +++ b/bin/tempus_project.php @@ -19,6 +19,7 @@ use TheTempusProject\Bedrock\Functions\Input; use TheTempusProject\Bedrock\Functions\Session; use TheTempusProject\Bedrock\Functions\Cookie; use TheTempusProject\Bedrock\Functions\Check; +use TheTempusProject\Bedrock\Functions\Date; use TheTempusProject\Canary\Bin\Canary as Debug; use TheTempusProject\Hermes\Functions\Redirect; @@ -241,13 +242,85 @@ class TheTempusProject extends Bedrock { 'example' => '(?)', ], ]; + public $configMatrix = [ + "main" => [ + "logo" => [ + "type" => "file", + "pretty" => "Site Logo (Used mostly in emails)", + "default" => "images/logo.png" + ], + "name" => [ + "type" => "text", + "pretty" => "Site Name", + "default" => "TTP Example" + ], + "template" => [ + "type" => "text", + "pretty" => "Default Site Template", + "default" => "default" + ], + "tokenEnabled" => [ + "type" => "radio", + "pretty" => "Enable CSRF Token for all forms.", + "default" => true + ], + "loginLimit" => [ + "type" => "text", + "pretty" => "Maximum Login Attempts per hour", + "default" => 5 + ] + ], + "database" => [ + "dbEnabled" => [ + "type" => "radio", + "pretty" => "Database Enabled", + "default" => true, + "protected" => true + ], + "dbHost" => [ + "type" => "text", + "pretty" => "Database Host (IE: http://localhost:3306)", + "default" => "127.0.0.1", + "protected" => true + ], + "dbMaxQuery" => [ + "type" => "text", + "pretty" => "Maximum results per query", + "default" => 100, + "protected" => true + ], + "dbName" => [ + "type" => "text", + "pretty" => "Database Name", + "default" => "ttp-example", + "protected" => true + ], + "dbPassword" => [ + "type" => "text", + "pretty" => "Database Password", + "default" => "", + "protected" => true + ], + "dbPrefix" => [ + "type" => "text", + "pretty" => "Database table Prefix", + "default" => "TTP_", + "protected" => true + ], + "dbUsername" => [ + "type" => "text", + "pretty" => "Database Username", + "default" => "root", + "protected" => true + ] + ] + ]; /** * The constructor takes care of everything that we will need before * finally calling appload to instantiate the appropriate controller/method. */ public function __construct() { - // Initialize the parent app parent::__construct(); Debug::info( 'Requested URL: ' . $this->getCurrentUrl() ); @@ -289,9 +362,6 @@ class TheTempusProject extends Bedrock { } } - // echo '
'.var_export( $plugins, true ).'
'; - // exit(); - Debug::gend(); } @@ -329,6 +399,13 @@ class TheTempusProject extends Bedrock { return true; } + public static function dateTimeCallback( $data ) { + if ( empty( $data[2] ) ) { + return ''; + } + return Date::formatTimestamp( $data[1], $data[2] ); + } + public function loadFilters() { // These Filter have to be loaded here because they have calculated values $this->filters[] = [ @@ -359,9 +436,17 @@ class TheTempusProject extends Bedrock { 'enabled' => true, 'example' => '{LOGGEDIN}Only visible to users who are logged-in{LOGGEDIN}', ]; - if ( !empty( $this->filters ) ) { + $this->filters[] = [ + 'name' => 'dtc', + 'find' => '#{DTC(.*?)}(.*?){/DTC}#is', + 'replace' => [ __CLASS__, 'dateTimeCallback' ], + 'enabled' => true, + 'callback' => true, + 'example' => '{DTC=date}000000000{DTC}', + ]; + if ( ! empty( $this->filters ) ) { foreach( $this->filters as $filter ) { - Filters::add( $filter['name'], $filter['find'], $filter['replace'], $filter['enabled'] ); + Filters::add( $filter['name'], $filter['find'], $filter['replace'], $filter['enabled'], ( $filter['callback'] ?? false ) ); } } } diff --git a/install.php b/install.php index 2929ae6..419afdd 100644 --- a/install.php +++ b/install.php @@ -188,6 +188,7 @@ class Install extends Controller { Views::view( 'install.check' ); } + /** * One of the most important steps for installation, is the configuration. In this step, we will define some very core settings * for the app including the app's name and database credentials. @@ -199,45 +200,19 @@ class Install extends Controller { $logo = 'Uploads/Images/System/' . Upload::last(); } TheTempusProject::$activeConfig->load( BEDROCK_CONFIG_JSON ); - $configMatrix = [ - 'main' => [ - 'logo' => [ - 'value' => $logo, - ], - 'name' => [ - 'value' => Input::postNull( 'siteName' ), - ], - 'loginLimit' => [ - 'type' => 'text', - 'pretty' => 'Maximum Login Attempts per hour', - 'default' => 5, - 'value' => 5, - ], - ], - 'database' => [ - 'dbMaxQuery' => [ - 'value'=> 100, - ], - 'dbEnabled' => [ - 'value' => true, - ], - 'dbHost' => [ - 'value' => Input::postNull( 'dbHost' ), - ], - 'dbName' => [ - 'value' => Input::postNull( 'dbName' ), - ], - 'dbPassword' => [ - 'value' => Input::postNull( 'dbPassword' ), - ], - 'dbPrefix' => [ - 'value' => Input::postNull( 'dbPrefix' ), - ], - 'dbUsername' => [ - 'value' => Input::postNull( 'dbUsername' ), - ], - ], - ]; + $baseConfig = TheTempusProject::$configMatrix; + $baseConfig['main']['logo']['value'] = $logo; + $baseConfig['main']['name']['value'] = Input::postNull( 'siteName' ); + $baseConfig['main']['template']['value'] = $baseConfig['main']['template']['default']; + $baseConfig['main']['tokenEnabled']['value'] = $baseConfig['main']['tokenEnabled']['default']; + $baseConfig['main']['loginLimit']['value'] = $baseConfig['main']['loginLimit']['default']; + $baseConfig['database']['dbEnabled']['value'] = $baseConfig['database']['dbEnabled']['default']; + $baseConfig['database']['dbHost']['value'] = Input::postNull( 'dbHost' ); + $baseConfig['database']['dbMaxQuery']['value'] = $baseConfig['database']['dbMaxQuery']['default']; + $baseConfig['database']['dbName']['value'] = Input::postNull( 'dbName' ); + $baseConfig['database']['dbPassword']['value'] = Input::postNull( 'dbPassword' ); + $baseConfig['database']['dbPrefix']['value'] = Input::postNull( 'dbPrefix' ); + $baseConfig['database']['dbUsername']['value'] = Input::postNull( 'dbUsername' ); if ( ! TheTempusProject::$activeConfig->generate( CONFIG_JSON, $configMatrix ) ) { return Issues::add( 'error', 'Config file already exists so the installer has been halted. If there was an error with installation, please delete app/config/config.json manually and try again. The installer should automatically bring you back to this step.' ); }