diff --git a/app/config/constants.php b/app/config/constants.php index 1e171e9..3f076cd 100644 --- a/app/config/constants.php +++ b/app/config/constants.php @@ -38,6 +38,8 @@ if ( ! defined( 'CONFIG_DIRECTORY' ) ) { # Tempus Debugger define( 'CANARY_SECURE_HASH', 'd73ed7591a30f0ca7d686a0e780f0d05' ); # Tempus Project Core +define( 'APP_NAME', 'Joey Kimsey'); +define( 'TP_DEFAULT_LOGO', 'images/logo.png'); // Check define( 'MINIMUM_PHP_VERSION', 8.1); // Cookies diff --git a/app/controllers/admin/home.php b/app/controllers/admin/home.php index c4a7704..6572929 100644 --- a/app/controllers/admin/home.php +++ b/app/controllers/admin/home.php @@ -32,12 +32,12 @@ class Home extends AdminController { } public function index() { + Components::set( 'commentDash', '' ); if ( class_exists( 'TheTempusProject\Plugins\Comments' ) ) { $plugin = new CommentPlugin; if ( ! $plugin->checkEnabled() ) { Debug::info( 'Comments Plugin is disabled in the control panel.' ); - Components::set( 'commentDash', '' ); } else { $comments = new Comments; $commentList = Views::simpleView( 'comments.admin.dashboard', $comments->recent( 'all', 5 ) ); diff --git a/app/css/main-dark.css b/app/css/main-dark.css index ce195ba..3e18540 100644 --- a/app/css/main-dark.css +++ b/app/css/main-dark.css @@ -21,6 +21,9 @@ .context-second-bg { background-color: #1e1e1e; } +.context-third-bg { + background-color: #3a3a3a; +} .bg-default { background-color: #2c2c2c; } @@ -142,9 +145,7 @@ body { } .form-control:focus { color: #e0e0e0; - /* border-color: #85bd3e; */ - border-color: #1b947f; + border-color: #1e90ff; background-color: #1f1f1f; - /* box-shadow: 0 0 0 .25rem #1b947f; */ - box-shadow: 0 0 0 .25rem #85bd3e; + box-shadow: 0 0 0 .25rem rgba(30, 144, 255, .5); } \ No newline at end of file diff --git a/app/js/main.js b/app/js/main.js index 30be9de..633277f 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -95,22 +95,45 @@ $(document).ready(function() { }); document.addEventListener('DOMContentLoaded', function () { + const ttpDarkmode = document.getElementById('dark-mode-pref'); const toggleButton = document.getElementById('dark-mode-toggle'); const enableButton = document.getElementById('dark-mode-toggle-button'); const darkModeStylesheet = document.getElementById('dark-mode-stylesheet'); + let currentState = ''; - // Check if dark mode is saved in localStorage - if (localStorage.getItem('darkMode') === 'enabled') { + // Check if dark mode is set by ttp + if ( ttpDarkmode ) { + if ( 'true' == ttpDarkmode.value ) { + currentState = 'enabled'; + } + if ( 'false' == ttpDarkmode.value ) { + currentState = 'disabled'; + } + } + + // Check if dark mode is set in localStorage + if ( '' == currentState ) { + if ( localStorage.getItem('darkMode') === 'enabled' ) { + currentState = 'enabled'; + } + } + + // Update current button states + if ( 'enabled' == currentState ) { darkModeStylesheet.disabled = false; - toggleButton.checked = true; - + + if ( toggleButton ) { + toggleButton.checked = true; + } + if ( enableButton ) { enableButton.innerText = 'Disable Now'; } } + // Style striped table elements document.querySelectorAll('.table-striped').forEach((table) => { - if (localStorage.getItem('darkMode') === 'enabled') { + if ( 'enabled' == currentState ) { table.classList.add('table-dark'); } else { table.classList.add('table-light') @@ -119,7 +142,7 @@ document.addEventListener('DOMContentLoaded', function () { if ( enableButton ) { enableButton.addEventListener('click', function () { - if (darkModeStylesheet.disabled) { + if ( darkModeStylesheet.disabled ) { darkModeStylesheet.disabled = false; localStorage.setItem('darkMode', 'enabled'); enableButton.innerText = 'Disable Now'; @@ -131,9 +154,10 @@ document.addEventListener('DOMContentLoaded', function () { }); } - toggleButton.addEventListener('click', function () { - if (darkModeStylesheet.disabled) { - toggleDarkModePref( true ); + if ( toggleButton ) { + toggleButton.addEventListener('click', function () { + if (darkModeStylesheet.disabled) { + toggleDarkModePref( true ); darkModeStylesheet.disabled = false; localStorage.setItem('darkMode', 'enabled'); } else { @@ -141,7 +165,7 @@ document.addEventListener('DOMContentLoaded', function () { darkModeStylesheet.disabled = true; localStorage.setItem('darkMode', 'disabled'); } - + document.querySelectorAll('.table-striped').forEach((table) => { if (localStorage.getItem('darkMode') === 'enabled') { table.classList.add('table-dark'); @@ -149,9 +173,10 @@ document.addEventListener('DOMContentLoaded', function () { } else { table.classList.add('table-light'); table.classList.remove('table-dark'); - } + } + }); }); - }); + } function toggleDarkModePref( value ) { var fields = {}; diff --git a/app/models/group.php b/app/models/group.php index bbc512b..759dae7 100644 --- a/app/models/group.php +++ b/app/models/group.php @@ -31,7 +31,7 @@ class Group extends DatabaseModel { 'defaultGroup' => [ 'type' => 'customSelect', 'pretty' => 'The Default Group for new registrations.', - 'default' => 5, + 'default' => 4, ], ]; public $databaseMatrix = [ diff --git a/app/plugins/blog/controllers/admin/blog.php b/app/plugins/blog/controllers/admin/blog.php index adfc451..36b9097 100644 --- a/app/plugins/blog/controllers/admin/blog.php +++ b/app/plugins/blog/controllers/admin/blog.php @@ -46,7 +46,7 @@ class Blog extends AdminController { return $this->index(); } - $result = self::$posts->newPost( Input::post( 'title' ), Input::post( 'blogPost' ), Input::post( 'submit' ) ); + $result = self::$posts->newPost( Input::post( 'title' ), Input::post( 'blogPost' ), Input::post( 'slug' ), Input::post( 'submit' ) ); if ( $result ) { Issues::add( 'success', 'Your post has been created.' ); return $this->index(); @@ -67,7 +67,7 @@ class Blog extends AdminController { Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] ); return $this->index(); } - if ( self::$posts->updatePost( $data, Input::post( 'title' ), Input::post( 'blogPost' ), Input::post( 'submit' ) ) === true ) { + if ( self::$posts->updatePost( $data, Input::post( 'title' ), Input::post( 'blogPost' ), Input::post( 'slug' ), Input::post( 'submit' ) ) === true ) { Issues::add( 'success', 'Post Updated.' ); return $this->index(); } diff --git a/app/plugins/blog/controllers/blog.php b/app/plugins/blog/controllers/blog.php index b14100b..80cc7c8 100644 --- a/app/plugins/blog/controllers/blog.php +++ b/app/plugins/blog/controllers/blog.php @@ -62,12 +62,17 @@ class Blog extends Controller { return $this->index(); } - $plugin = new Comments; - if ( ! $plugin->checkEnabled() ) { - Issues::add( 'error', 'Comments are disabled.' ); + if ( class_exists( 'TheTempusProject\Plugins\Comments' ) ) { + $plugin = new Comments; + if ( ! $plugin->checkEnabled() ) { + Issues::add( 'error', 'Comments are disabled.' ); + return $this->index(); + } + $comments = new CommentsModel; + } else { + Debug::info( 'error', 'Comments plugin missing.' ); return $this->index(); } - $comments = new CommentsModel; switch ( $sub ) { case 'post': @@ -100,7 +105,10 @@ class Blog extends Controller { } $post = self::$posts->findById( $id ); if ( empty( $post ) ) { - return $this->index(); + $post = self::$posts->findBySlug( $id ); + if ( empty( $post ) ) { + return $this->index(); + } } Debug::log( 'Controller initiated: ' . __METHOD__ . '.' ); self::$title = 'Blog Post'; @@ -111,25 +119,24 @@ class Blog extends Controller { Components::set( 'CONTENT_ID', $id ); Components::set( 'COMMENT_TYPE', self::$posts->tableName ); + Components::set( 'NEWCOMMENT', '' ); + Components::set( 'count', '0' ); + Components::set( 'COMMENTS', '' ); - $plugin = new Comments; - if ( ! $plugin->checkEnabled() ) { - Components::set( 'NEWCOMMENT', '' ); - Components::set( 'count', '0' ); - Components::set( 'COMMENTS', '' ); - } else { - $comments = new CommentsModel; - if ( App::$isLoggedIn ) { - Components::set( 'NEWCOMMENT', Views::simpleView( 'comments.create' ) ); - } else { - Components::set( 'NEWCOMMENT', '' ); + if ( class_exists( 'TheTempusProject\Plugins\Comments' ) ) { + $plugin = new Comments; + if ( $plugin->checkEnabled() ) { + $comments = new CommentsModel; + if ( App::$isLoggedIn ) { + Components::set( 'NEWCOMMENT', Views::simpleView( 'comments.create' ) ); + } else { + Components::set( 'NEWCOMMENT', '' ); + } + Components::set( 'count', $comments->count( self::$posts->tableName, $post->ID ) ); + Components::set( 'COMMENTS', Views::simpleView( 'comments.list', $comments->display( 10, self::$posts->tableName, $post->ID ) ) ); } - Components::set( 'count', $comments->count( self::$posts->tableName, $post->ID ) ); - Components::set( 'COMMENTS', Views::simpleView( 'comments.list', $comments->display( 10, self::$posts->tableName, $post->ID ) ) ); } - $post = self::$posts->findById( $id ); - self::$title .= ' - ' . $post->title; self::$pageDescription = strip_tags( $post->contentSummaryNoLink ); Views::view( 'blog.post', $post ); diff --git a/app/plugins/blog/models/posts.php b/app/plugins/blog/models/posts.php index 7a4e158..212ac2b 100644 --- a/app/plugins/blog/models/posts.php +++ b/app/plugins/blog/models/posts.php @@ -32,6 +32,7 @@ class Posts extends DatabaseModel { [ 'edited', 'int', '10' ], [ 'draft', 'int', '1' ], [ 'title', 'varchar', '86' ], + [ 'slug', 'varchar', '64' ], [ 'content', 'text', '' ], ]; @@ -45,7 +46,7 @@ class Posts extends DatabaseModel { } } - public function newPost( $title, $post, $draft ) { + public function newPost( $title, $post, $slug, $draft ) { if ( !Check::dataTitle( $title ) ) { Debug::info( 'modelBlog: illegal title.' ); @@ -59,6 +60,7 @@ class Posts extends DatabaseModel { $fields = [ 'author' => App::$activeUser->ID, 'draft' => $draft, + 'slug' => $slug, 'created' => time(), 'edited' => time(), 'content' => Sanitize::rich( $post ), @@ -73,7 +75,7 @@ class Posts extends DatabaseModel { return true; } - public function updatePost( $id, $title, $content, $draft ) { + public function updatePost( $id, $title, $content, $slug, $draft ) { if ( empty( self::$log ) ) { self::$log = new Log; } @@ -94,6 +96,7 @@ class Posts extends DatabaseModel { } $fields = [ 'draft' => $draft, + 'slug' => $slug, 'edited' => time(), 'content' => Sanitize::rich( $content ), 'title' => $title, @@ -132,22 +135,29 @@ class Posts extends DatabaseModel { $draft = ''; $authorName = self::$user->getUsername( $instance->author ); + // Summarize + if ( ! empty( $instance->slug ) ) { + $identifier = $instance->slug; + } else { + $identifier = $instance->ID; + } + $cleanPost = Sanitize::contentShort( $instance->content ); + // By Word $wordsArray = explode( ' ', $cleanPost ); - $postLine = explode( "\n", $cleanPost ); - $spaceSummary = implode( ' ', array_splice( $wordsArray, 0, 100 ) ); - $lineSummary = implode( "\n", array_splice( $postLine, 0, 5 ) ); - if ( strlen( $spaceSummary ) < strlen( $lineSummary ) ) { - $contentSummaryNoLink = $spaceSummary; - $contentSummary = $spaceSummary; - if ( count( $wordsArray, 1 ) >= 100 ) { - $contentSummaryNoLink = $contentSummary; - $contentSummary .= '... Read More'; - } + $wordSummary = implode( ' ', array_splice( $wordsArray, 0, 100 ) ); + // By Line + $linesArray = explode( "\n", $cleanPost ); + $lineSummary = implode( "\n", array_splice( $linesArray, 0, 5 ) ); + + if ( strlen( $wordSummary ) < strlen( $lineSummary ) ) { + $contentSummaryNoLink = $wordSummary; + $contentSummary = $wordSummary . '... Read More'; } else { $contentSummaryNoLink = $lineSummary; - $contentSummary = $lineSummary . '... Read More'; + $contentSummary = $lineSummary . '... Read More'; } + $instance->contentSummaryNoLink = $contentSummaryNoLink; $instance->contentSummary = $contentSummary; @@ -164,6 +174,7 @@ class Posts extends DatabaseModel { } $instance->content = Filters::applyOne( 'mentions.0', $instance->content, true ); $instance->content = Filters::applyOne( 'hashtags.0', $instance->content, true ); + $out[] = $instance; if ( !empty( $end ) ) { $out = $out[0]; @@ -291,6 +302,22 @@ class Posts extends DatabaseModel { return $this->filter( $postData->results() ); } + public function findBySlug( $slug, $includeDraft = false ) { + $whereClause = []; + if ( $includeDraft !== true ) { + $whereClause = ['draft', '=', '0', 'AND']; + } + + $whereClause = array_merge( $whereClause, ['slug', '=', $slug] ); + + $postData = self::$db->get( $this->tableName, $whereClause ); + if ( !$postData->count() ) { + Debug::info( 'No Blog posts found.' ); + return false; + } + return $this->filter( $postData->first() ); + } + public function byMonth( $month, $year = 0, $includeDraft = false ) { if ( 0 === $year ) { $year = date( 'Y' ); diff --git a/app/plugins/blog/views/admin/create.html b/app/plugins/blog/views/admin/create.html index 7ae25f5..00d9d00 100644 --- a/app/plugins/blog/views/admin/create.html +++ b/app/plugins/blog/views/admin/create.html @@ -12,6 +12,14 @@ + +