wip from ATB

This commit is contained in:
Joey Kimsey
2025-01-04 17:21:14 -05:00
parent 87e4f90bab
commit 32a9711ade
60 changed files with 556 additions and 342 deletions

View File

@ -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();
}

View File

@ -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 );

View File

@ -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,
@ -131,39 +134,47 @@ class Posts extends DatabaseModel {
}
$draft = '';
$authorName = self::$user->getUsername( $instance->author );
$cleanPost = Sanitize::contentShort( $instance->content );
$postSpace = explode( ' ', $cleanPost );
$postLine = explode( "\n", $cleanPost );
// summary by words: 100
$spaceSummary = implode( ' ', array_splice( $postSpace, 0, 100 ) );
// summary by lines: 5
$lineSummary = implode( "\n", array_splice( $postLine, 0, 5 ) );
if ( strlen( $spaceSummary ) < strlen( $lineSummary ) ) {
$contentSummary = $spaceSummary;
if ( count( $postSpace, 1 ) <= 100 ) {
$contentSummaryNoLink = $contentSummary;
$contentSummary .= '... <a href="{ROOT_URL}blog/post/' . $instance->ID . '">Read More</a>';
}
// Summarize
if ( ! empty( $instance->slug ) ) {
$identifier = $instance->slug;
} else {
$identifier = $instance->ID;
}
$cleanPost = Sanitize::contentShort( $instance->content );
// By Word
$wordsArray = explode( ' ', $cleanPost );
$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 . '... <a href="{ROOT_URL}blog/post/' . $identifier . '" class="text-decoration-none">Read More</a>';
} else {
// @todo: need to refine this after testing
$contentSummaryNoLink = $lineSummary;
$contentSummary = $lineSummary . '... <a href="{ROOT_URL}blog/post/' . $instance->ID . '">Read More</a>';
$contentSummary = $lineSummary . '... <a href="{ROOT_URL}blog/post/' . $identifier . '" class="text-decoration-none">Read More</a>';
}
$instance->contentSummaryNoLink = $contentSummaryNoLink;
$instance->contentSummary = $contentSummary;
if ( isset( $params['stripHtml'] ) && $params['stripHtml'] === true ) {
$instance->contentSummary = strip_tags( $instance->content );
}
if ( $instance->draft != '0' ) {
$draft = ' <b>Draft</b>';
}
$instance->isDraft = $draft;
$instance->authorName = $authorName;
$instance->contentSummaryNoLink = $contentSummaryNoLink;
$instance->contentSummary = $contentSummary;
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;
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' );

View File

@ -12,6 +12,14 @@
</div>
</div>
<!-- Slug -->
<div class="mb-3 row">
<label for="slug" class="col-lg-3 col-form-label text-end">URL Slug (for pretty linking):</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="slug" id="slug" required>
</div>
</div>
<!-- form buttons -->
<div class="mb-3 row">
<div class="offset-3 col-lg-6">

View File

@ -12,6 +12,14 @@
</div>
</div>
<!-- Slug -->
<div class="mb-3 row">
<label for="slug" class="col-lg-3 col-form-label text-end">URL Slug (for pretty linking):</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="slug" id="slug" value="{slug}" required>
</div>
</div>
<!-- form buttons -->
<div class="mb-3 row">
<div class="offset-3 col-lg-6">

View File

@ -1,7 +1,7 @@
{LOOP}
<article class="blog-post">
<h2 class="blog-post-title mb-1">{title}</h2>
<p class="blog-post-meta">{DTC date}{created}{/DTC} by <a href="{ROOT_URL}home/profile/{author}">{authorName}</a></p>
<p class="blog-post-meta">{DTC date}{created}{/DTC} by <a href="{ROOT_URL}home/profile/{author}" class="text-decoration-none">{authorName}</a></p>
<div class="well">
{contentSummary}
</div>

View File

@ -3,7 +3,7 @@
<div class="blog-post">
<h2 class="blog-post-title">{title}</h2>
<hr>
<p class="blog-post-meta">{DTC date}{created}{/DTC} by <a href="{ROOT_URL}home/profile/{author}">{authorName}</a></p>
<p class="blog-post-meta">{DTC date}{created}{/DTC} by <a href="{ROOT_URL}home/profile/{author}" class="text-decoration-none">{authorName}</a></p>
{content}
{ADMIN}
<hr>

View File

@ -5,7 +5,7 @@
<div class="card-body">
<ol class="list-unstyled">
{LOOP}
<li><a href="{ROOT_URL}blog/post/{ID}">{title}</a></li>
<li><a href="{ROOT_URL}blog/post/{ID}" class="text-decoration-none">{title}</a></li>
{/LOOP}
{ALT}
<li>No Posts to show</li>
@ -13,6 +13,6 @@
</ol>
</div>
<div class="card-footer">
<a href="{ROOT_URL}blog">View All</a>
<a href="{ROOT_URL}blog" class="text-decoration-none">View All</a>
</div>
</div>

View File

@ -2,7 +2,7 @@
<h4 class="fst-italic">Archives</h4>
<ul class="list-unstyled mb-0">
{LOOP}
<li>({count}) <a href="{ROOT_URL}blog/month/{month}/{year}">{monthText} {year}</a></li>
<li>({count}) <a href="{ROOT_URL}blog/month/{month}/{year}" class="text-decoration-none">{monthText} {year}</a></li>
{/LOOP}
{ALT}
<li>None To Show</li>

View File

@ -1,5 +1,6 @@
<div class="col-8 mx-auto p-4 rounded shadow-sm mb-5 context-main-bg mt-4 container">
<h2 class="text-center mb-4">Bug Report</h2>
<hr>
<p>Thank you for visiting our bug reporting page. We value our users' input highly and in an effort to better serve your needs, please fill out the form below to help us address this issue.</p>
<p>We read each and every bug report submitted, and by submitting this form you allow us to send you a follow-up email.</p>
<form action="" method="post">

View File

@ -49,13 +49,13 @@ class Comments extends AdminController {
$this->index();
}
public function viewComments( $contentIID = null ) {
if ( empty( $contentIID ) ) {
public function viewComments( $contentID = null ) {
if ( empty( $contentID ) ) {
Issues::add( 'error', 'Content ID not found.' );
return $this->index();
}
$contentData = self::$comments->findById( $data );
if ( empty( $contentIID ) ) {
if ( empty( $contentID ) ) {
return Views::view( 'comments.list', $commentData );
}
Issues::add( 'error', 'Comment not found.' );

View File

@ -28,7 +28,7 @@
</li>
{/LOOP}
{ALT}
<li class="list-group-item">
<li class="list-group-item context-second-bg context-main mb-2">
<div class="text-center">
<p class="mb-0">Be the first to comment.</p>
</div>

View File

@ -115,7 +115,7 @@ class Notification extends DatabaseModel {
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'notificationDelete' );
Debug::error( "Bookmarks: $id not updated" );
Debug::error( "Notifications: $id not updated" );
return false;
}
return true;

View File

@ -3,13 +3,13 @@
<a
href="#"
class="d-flex align-items-center text-white text-decoration-none dropdown-toggle"
id="notiificationsDropdown"
id="notificationsDropdown"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">
<i class="fa fa-fw fa-bell"></i><span class="ms-2">{NBADGE}</span>
</a>
<ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end text-small shadow" aria-labelledby="notiificationsDropdown">
<ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end text-small shadow" aria-labelledby="notificationsDropdown">
{LOOP}
<!-- Notification Item -->
<li>

View File

@ -1,11 +1,11 @@
<div class="col-md-5 offset-md-1 mb-3">
<h5>Subscribe to our newsletter</h5>
<div class="d-flex flex-column flex-sm-row w-100 gap-2">
<form action="{ROOT_URL}subscribe/home" method="post" class="form-horizontal"></form>
<label for="newsletter1" class="visually-hidden">Email address</label>
<input name="email" id="email" type="email" class="form-control" placeholder="Email address" autocomplete="email">
<div class="col-md-5 offset-md-1 mb-3 text-center">
<h5 class="">Subscribe</h5>
<div class="d-flex flex-column flex-sm-row gap-2 justify-content-center mx-auto">
<form action="{ROOT_URL}subscribe/home" method="post" class="form-horizontal">
<label for="email" class="visually-hidden">Email address</label>
<input name="email" id="email" type="email" class="form-control my-2" placeholder="Email address" autocomplete="email">
<input type="hidden" name="token" value="{TOKEN}">
<button class="btn btn-primary" name="submit" value="submit" type="submit">Subscribe</button>
<button class="btn btn-primary my-2 w-100" name="submit" value="submit" type="submit">Subscribe</button>
</form>
</div>
</div>