From 5c7a320c2ad1c792724a9defeaf33a71830c73e2 Mon Sep 17 00:00:00 2001 From: Joey Kimsey Date: Wed, 21 Aug 2024 06:14:54 -0400 Subject: [PATCH] bugfixes for pagination and installation --- app/classes/installer.php | 4 ++-- app/controllers/admin/admin.php | 2 +- app/controllers/admin/errors.php | 2 +- app/controllers/admin/groups.php | 2 +- app/controllers/admin/logins.php | 2 +- app/controllers/admin/logs.php | 6 ++--- app/controllers/admin/plugins.php | 2 +- app/controllers/admin/routes.php | 2 +- app/controllers/admin/users.php | 2 +- app/models/group.php | 2 +- app/plugins/blog/models/posts.php | 23 ++++++++++--------- app/plugins/blog/plugin.php | 12 ++++++++++ app/plugins/comments/plugin.php | 2 +- .../feedback/controllers/admin/feedback.php | 2 +- app/plugins/messages/models/message.php | 12 +++++----- .../notifications/models/notification.php | 4 ++-- app/plugins/notifications/views/list.html | 3 +-- .../admin/modules/composer/dependencies.html | 1 - app/views/admin/modules/models/list.html | 1 - app/views/admin/modules/plugins/list.html | 1 - bin/tempus_project.php | 2 +- composer.json | 1 - install.php | 3 +-- 23 files changed, 50 insertions(+), 43 deletions(-) diff --git a/app/classes/installer.php b/app/classes/installer.php index 4db019b..02ea1bf 100644 --- a/app/classes/installer.php +++ b/app/classes/installer.php @@ -439,7 +439,7 @@ class Installer { // exclude any flags we don't have a matric map for if ( empty( $module_data->class_object->$matrix ) ) { - Debug::warn( "$flag_type does not have a proper matrix map and cannot be uninstalled." ); + Debug::warn( "$flag_type does not have a proper matrix map and cannot be installed." ); $module_data->$flag_type = INSTALL_STATUS_NOT_FOUND; } } @@ -500,7 +500,7 @@ class Installer { // exclude any flags we don't have a matric map for if ( empty( $module_data->class_object->$matrix ) ) { - Debug::warn( "$flag_type does not have a proper matrix map and cannot be installed." ); + Debug::warn( "$flag_type does not have a proper matrix map and cannot be uninstalled." ); $module_data->$flag_type = INSTALL_STATUS_NOT_FOUND; } } diff --git a/app/controllers/admin/admin.php b/app/controllers/admin/admin.php index 17d1850..3fa11f4 100644 --- a/app/controllers/admin/admin.php +++ b/app/controllers/admin/admin.php @@ -39,7 +39,7 @@ class Admin extends AdminController { } public function index() { - return Views::view( 'admin.logs.admin_list', self::$log->list( 'admin' ) ); + return Views::view( 'admin.logs.admin_list', self::$log->listPaginated( 'admin' ) ); } public function view( $id = null ) { diff --git a/app/controllers/admin/errors.php b/app/controllers/admin/errors.php index da8cf23..d0bf4b3 100644 --- a/app/controllers/admin/errors.php +++ b/app/controllers/admin/errors.php @@ -39,7 +39,7 @@ class Errors extends AdminController { } public function index() { - return Views::view( 'admin.logs.error_list', self::$log->list( 'error' ) ); + return Views::view( 'admin.logs.error_list', self::$log->listPaginated( 'error' ) ); } public function view( $id = null ) { diff --git a/app/controllers/admin/groups.php b/app/controllers/admin/groups.php index 66c5ea5..44e8ccc 100644 --- a/app/controllers/admin/groups.php +++ b/app/controllers/admin/groups.php @@ -95,7 +95,7 @@ class Groups extends AdminController { } public function index( $data = null ) { - Views::view( 'admin.groups.list', self::$group->list() ); + Views::view( 'admin.groups.list', self::$group->listPaginated() ); } public function listmembers( $data = null ) { diff --git a/app/controllers/admin/logins.php b/app/controllers/admin/logins.php index 174639e..02356f6 100644 --- a/app/controllers/admin/logins.php +++ b/app/controllers/admin/logins.php @@ -39,7 +39,7 @@ class Logins extends AdminController { } public function index() { - return Views::view( 'admin.logs.login_list', self::$log->list( 'login' ) ); + return Views::view( 'admin.logs.login_list', self::$log->listPaginated( 'login' ) ); } public function view( $id = null ) { diff --git a/app/controllers/admin/logs.php b/app/controllers/admin/logs.php index 1729f1e..6c72abb 100644 --- a/app/controllers/admin/logs.php +++ b/app/controllers/admin/logs.php @@ -26,8 +26,8 @@ class Logs extends AdminController { } public function index( $data = null ) { - Views::view( 'admin.logs.error_list', self::$log->list( 'error' ) ); - Views::view( 'admin.logs.admin_list', self::$log->list( 'admin' ) ); - Views::view( 'admin.logs.login_list', self::$log->list( 'login' ) ); + Views::view( 'admin.logs.error_list', self::$log->listPaginated( 'error' ) ); + Views::view( 'admin.logs.admin_list', self::$log->listPaginated( 'admin' ) ); + Views::view( 'admin.logs.login_list', self::$log->listPaginated( 'login' ) ); } } diff --git a/app/controllers/admin/plugins.php b/app/controllers/admin/plugins.php index d5206c8..18e5836 100644 --- a/app/controllers/admin/plugins.php +++ b/app/controllers/admin/plugins.php @@ -56,7 +56,7 @@ class Plugins extends AdminController { if ( !Input::exists( 'installHash' ) ) { return Views::view( 'admin.modules.plugins.enable' ); } - if ( !Plugin::enable( $name ) ) { + if ( ! Plugin::enable( $name ) ) { Session::flash( 'error', 'There was an error enabling the plugin.' ); } else { Session::flash( 'success', 'Plugin has been enabled.' ); diff --git a/app/controllers/admin/routes.php b/app/controllers/admin/routes.php index 284fab6..e21307b 100644 --- a/app/controllers/admin/routes.php +++ b/app/controllers/admin/routes.php @@ -88,7 +88,7 @@ class Routes extends AdminController { } public function index() { - return Views::view( 'admin.routes.list', self::$routes->list() ); + return Views::view( 'admin.routes.list', self::$routes->listPaginated() ); } public function view( $id = null ) { diff --git a/app/controllers/admin/users.php b/app/controllers/admin/users.php index 6f39a96..c2e4055 100644 --- a/app/controllers/admin/users.php +++ b/app/controllers/admin/users.php @@ -140,7 +140,7 @@ class Users extends AdminController { } public function index() { - Views::view( 'admin.users.list', self::$user->userList() ); + Views::view( 'admin.users.list', self::$user->listPaginated() ); } public function view( $id = null ) { diff --git a/app/models/group.php b/app/models/group.php index bbc512b..4a375f6 100644 --- a/app/models/group.php +++ b/app/models/group.php @@ -257,7 +257,7 @@ class Group extends DatabaseModel { if ( $group === false ) { return false; } - $members = self::$db->get( 'users', [ 'userGroup', '=', $id ] ); + $members = self::$db->getPaginated( 'users', [ 'userGroup', '=', $id ] ); if ( !$members->count() ) { Debug::info( "list members: Could not find anyone in group: $id" ); return false; diff --git a/app/plugins/blog/models/posts.php b/app/plugins/blog/models/posts.php index 3d593fe..5f8873d 100644 --- a/app/plugins/blog/models/posts.php +++ b/app/plugins/blog/models/posts.php @@ -19,9 +19,12 @@ use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\TheTempusProject as App; use TheTempusProject\Canary\Classes\CustomException; use TheTempusProject\Houdini\Classes\Filters; +use TheTempusProject\Plugins\Comments as CommentPlugin; +use TheTempusProject\Models\Comments; class Posts extends DatabaseModel { public $tableName = 'posts'; + public static $comments = false; public $databaseMatrix = [ [ 'author', 'int', '11' ], @@ -32,19 +35,14 @@ class Posts extends DatabaseModel { [ 'content', 'text', '' ], ]; - public $resourceMatrix = [ - [ - 'title' => 'Welcome', - 'content' => '

This is just a simple message to say thank you for installing The Tempus Project. If you have any questions you can find everything through our website here.

', - 'author' => 1, - 'created' => '{time}', - 'edited' => '{time}', - 'draft' => 0, - ], - ]; - public function __construct() { parent::__construct(); + if ( class_exists( 'TheTempusProject\Plugins\Comments' ) ) { + $comments = new CommentPlugin; + if ( $comments->checkEnabled() ) { + self::$comments = new Comments; + } + } } public function newPost( $title, $post, $draft ) { @@ -161,6 +159,9 @@ class Posts extends DatabaseModel { if ( isset( $params['stripHtml'] ) && $params['stripHtml'] === true ) { $instance->contentSummary = strip_tags( $instance->content ); } + if ( self::$comments !== false ) { + $instance->commentCount = self::$comments->count( 'blog', $instance->ID ); + } $instance->content = Filters::applyOne( 'mentions.0', $instance->content, true ); $instance->content = Filters::applyOne( 'hashtags.0', $instance->content, true ); $out[] = $instance; diff --git a/app/plugins/blog/plugin.php b/app/plugins/blog/plugin.php index 033da68..d784824 100644 --- a/app/plugins/blog/plugin.php +++ b/app/plugins/blog/plugin.php @@ -38,6 +38,18 @@ class Blog extends Plugin { 'url' => '{ROOT_URL}blog/index', ], ]; + public $resourceMatrix = [ + 'posts' => [ + [ + 'title' => 'Welcome', + 'content' => '

This is just a simple message to say thank you for installing The Tempus Project. If you have any questions you can find everything through our website here.

', + 'author' => 1, + 'created' => '{time}', + 'edited' => '{time}', + 'draft' => 0, + ], + ], + ]; public $posts; public function __construct( $load = false ) { diff --git a/app/plugins/comments/plugin.php b/app/plugins/comments/plugin.php index ee794eb..a7cb138 100644 --- a/app/plugins/comments/plugin.php +++ b/app/plugins/comments/plugin.php @@ -54,7 +54,7 @@ class Comments extends Plugin { ], ]; public $resourceMatrix = [ - 'group' => [ + 'groups' => [ [ 'name' => 'Moderator', 'permissions' => '{"adminAccess":false}', diff --git a/app/plugins/feedback/controllers/admin/feedback.php b/app/plugins/feedback/controllers/admin/feedback.php index 89318f2..582f537 100644 --- a/app/plugins/feedback/controllers/admin/feedback.php +++ b/app/plugins/feedback/controllers/admin/feedback.php @@ -53,6 +53,6 @@ class Feedback extends AdminController { } public function index( $data = null ) { - Views::view( 'feedback.admin.list', self::$feedback->list() ); + Views::view( 'feedback.admin.list', self::$feedback->listPaginated() ); } } diff --git a/app/plugins/messages/models/message.php b/app/plugins/messages/models/message.php index b949437..501a731 100644 --- a/app/plugins/messages/models/message.php +++ b/app/plugins/messages/models/message.php @@ -61,7 +61,7 @@ class Message extends DatabaseModel { Debug::info( 'Invalid user ID' ); return false; } - $messageData = self::$db->get( $this->tableName, [ 'ID', '=', $parent ] ); + $messageData = self::$db->getPaginated( $this->tableName, [ 'ID', '=', $parent ] ); if ( $messageData->count() == 0 ) { Debug::info( 'Message not found.' ); return false; @@ -71,7 +71,7 @@ class Message extends DatabaseModel { if ( $type !== null ) { $params = array_merge( $params, [ 'AND', $type, '=', $user ] ); } - $messageData = self::$db->get( $this->tableName, $params, 'ID', 'DESC', [ 0, 1 ] ); + $messageData = self::$db->getPaginated( $this->tableName, $params, 'ID', 'DESC', [ 0, 1 ] ); if ( $messageData->count() != 0 ) { if ( $messageData->first()->recieverDeleted == 0 ) { $message = $messageData->first(); @@ -93,7 +93,7 @@ class Message extends DatabaseModel { Debug::info( 'Invalid ID' ); return false; } - $messageData = self::$db->get( $this->tableName, [ 'ID', '=', $id ] ); + $messageData = self::$db->getPaginated( $this->tableName, [ 'ID', '=', $id ] ); if ( $messageData->count() == 0 ) { Debug::info( 'Message not found.' ); return false; @@ -122,7 +122,7 @@ class Message extends DatabaseModel { } else { $find = $message->ID; } - $messageData = self::$db->get( $this->tableName, [ 'ID', '=', $find, 'OR', 'Parent', '=', $find ], 'ID', 'ASC' )->results(); + $messageData = self::$db->getPaginated( $this->tableName, [ 'ID', '=', $find, 'OR', 'Parent', '=', $find ], 'ID', 'ASC' )->results(); Components::set( 'PID', $find ); if ( $markRead == true ) { @@ -138,7 +138,7 @@ class Message extends DatabaseModel { $limit = 10; } $limit = [ 0, $limit ]; - $messageData = self::$db->get( + $messageData = self::$db->getPaginated( $this->tableName, [ 'parent', '=', 0, @@ -175,7 +175,7 @@ class Message extends DatabaseModel { $limit = 10; } $limit = [ 0, $limit ]; - $messageData = self::$db->get( + $messageData = self::$db->getPaginated( $this->tableName, [ 'parent', '=', 0, diff --git a/app/plugins/notifications/models/notification.php b/app/plugins/notifications/models/notification.php index cb1395f..3537644 100644 --- a/app/plugins/notifications/models/notification.php +++ b/app/plugins/notifications/models/notification.php @@ -74,9 +74,9 @@ class Notification extends DatabaseModel { 'expiresAt', '<', time(), ]; if ( empty( $limit ) ) { - $notifications = self::$db->get( $this->tableName, $whereClause ); + $notifications = self::$db->getPaginated( $this->tableName, $whereClause ); } else { - $notifications = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] ); + $notifications = self::$db->getPaginated( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] ); } if ( !$notifications->count() ) { Debug::info( 'No Notifications found.' ); diff --git a/app/plugins/notifications/views/list.html b/app/plugins/notifications/views/list.html index 52e9287..cd65288 100644 --- a/app/plugins/notifications/views/list.html +++ b/app/plugins/notifications/views/list.html @@ -27,5 +27,4 @@ - -{PAGINATION} \ No newline at end of file + \ No newline at end of file diff --git a/app/views/admin/modules/composer/dependencies.html b/app/views/admin/modules/composer/dependencies.html index 2294e97..6623a03 100644 --- a/app/views/admin/modules/composer/dependencies.html +++ b/app/views/admin/modules/composer/dependencies.html @@ -1,5 +1,4 @@

Installed Dependencies

-{PAGINATION} diff --git a/app/views/admin/modules/models/list.html b/app/views/admin/modules/models/list.html index e49808f..e4056e2 100644 --- a/app/views/admin/modules/models/list.html +++ b/app/views/admin/modules/models/list.html @@ -1,5 +1,4 @@

Installed Models

-{PAGINATION}
diff --git a/app/views/admin/modules/plugins/list.html b/app/views/admin/modules/plugins/list.html index 4228844..05d4454 100644 --- a/app/views/admin/modules/plugins/list.html +++ b/app/views/admin/modules/plugins/list.html @@ -1,5 +1,4 @@

Installed Plugins

-{PAGINATION}
diff --git a/bin/tempus_project.php b/bin/tempus_project.php index ca76165..922496e 100644 --- a/bin/tempus_project.php +++ b/bin/tempus_project.php @@ -242,7 +242,7 @@ class TheTempusProject extends Bedrock { 'example' => '(?)', ], ]; - public $configMatrix = [ + public static $configMatrix = [ "main" => [ "logo" => [ "type" => "file", diff --git a/composer.json b/composer.json index 423742a..0671572 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,6 @@ { "files": [ - "app/functions/forms.php", "app/functions/common.php" ], "classmap": diff --git a/install.php b/install.php index 419afdd..4c6ed98 100644 --- a/install.php +++ b/install.php @@ -213,7 +213,7 @@ class Install extends Controller { $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 ) ) { + if ( ! TheTempusProject::$activeConfig->generate( CONFIG_JSON, $baseConfig ) ) { 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.' ); } Session::flash( 'success', 'Config saved successfully.' ); @@ -341,7 +341,6 @@ class Install extends Controller { } else { $installResult = $this->installer->installModel( (object) $module, [ 'installResources' => true ], false ); } - if ( !$installResult ) { $error = true; }