hfkfhkfhgjkuhgfkjfghkj

This commit is contained in:
Local Dev
2025-02-03 12:03:51 -05:00
commit fd36f0f4bf
302 changed files with 22625 additions and 0 deletions

View File

@ -0,0 +1,102 @@
<?php
/**
* app/plugins/blog/controllers/admin/blog.php
*
* This is the Blog admin controller.
*
* @package TP Blog
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers\Admin;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Models\Posts;
class Blog extends AdminController {
public static $posts;
public function __construct() {
parent::__construct();
self::$posts = new Posts;
self::$title = 'Admin - Blog';
}
public function index( $data = null ) {
Views::view( 'blog.admin.list', self::$posts->listPosts( ['includeDrafts' => true] ) );
}
public function create( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'blog.admin.create' );
}
if ( !Forms::check( 'newBlogPost' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return $this->index();
}
$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();
} else {
Issues::add( 'error', [ 'There was an unknown error submitting your data.' => Check::userErrors() ] );
return $this->index();
}
}
public function edit( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'blog.admin.edit', self::$posts->findById( $data ) );
}
if ( Input::post( 'submit' ) == 'preview' ) {
return Views::view( 'blog.admin.preview', self::$posts->preview( Input::post( 'title' ), Input::post( 'blogPost' ) ) );
}
if ( !Forms::check( 'editBlogPost' ) ) {
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( 'slug' ), Input::post( 'submit' ) ) === true ) {
Issues::add( 'success', 'Post Updated.' );
return $this->index();
}
Issues::add( 'error', 'There was an error with your request.' );
$this->index();
}
public function view( $data = null ) {
$blogData = self::$posts->findById( $data );
if ( $blogData !== false ) {
return Views::view( 'blog.admin.view', $blogData );
}
Issues::add( 'error', 'Post not found.' );
$this->index();
}
public function delete( $data = null ) {
if ( $data == null ) {
if ( Input::exists( 'B_' ) ) {
$data = Input::post( 'B_' );
}
}
if ( !self::$posts->delete( (array) $data ) ) {
Issues::add( 'error', 'There was an error with your request.' );
} else {
Issues::add( 'success', 'Post has been deleted' );
}
$this->index();
}
public function preview( $data = null ) {
Views::view( 'blog.admin.preview', self::$posts->preview( Input::post( 'title' ), Input::post( 'blogPost' ) ) );
}
}

View File

@ -0,0 +1,186 @@
<?php
/**
* app/plugins/blog/controllers/blog.php
*
* This is the blog controller.
*
* @package TP Blog
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Template;
use TheTempusProject\Classes\Controller;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Hermes\Functions\Redirect;
use TheTempusProject\Bedrock\Functions\Session;
use TheTempusProject\Plugins\Blog as BlogPlugin;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Plugins\Comments;
use TheTempusProject\Models\Comments as CommentsModel;
use TheTempusProject\Models\Posts as PostsModel;
class Blog extends Controller {
protected static $blog;
protected static $posts;
public function __construct() {
parent::__construct();
Template::setTemplate( 'blog' );
self::$posts = new PostsModel;
}
public function index() {
self::$title = '{SITENAME} Blog';
self::$pageDescription = 'The {SITENAME} blog is where you can find various posts containing information ranging from current projects and general information to editorial and opinion based content.';
Views::view( 'blog.list', self::$posts->listPosts() );
}
public function rss() {
Debug::log( 'Controller initiated: ' . __METHOD__ . '.' );
self::$title = '{SITENAME} RSS Feed';
self::$pageDescription = '{SITENAME} blog RSS feed.';
Template::setTemplate( 'rss' );
header( 'Content-Type: text/xml' );
return Views::view( 'blog.rss', self::$posts->listPosts( ['stripHtml' => true] ) );
}
public function comments( $sub = null, $data = null ) {
Debug::log( 'Controller initiated: ' . __METHOD__ . '.' );
if ( empty( $sub ) || empty( $data ) ) {
Issues::add( 'error', 'There was an issue with your request. Please check the url and try again.' );
return $this->index();
}
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();
}
switch ( $sub ) {
case 'post':
$content = self::$posts->findById( (int) $data );
if ( empty( $content ) ) {
Issues::add( 'error', 'Unknown Content.' );
return $this->index();
}
return $plugin->formPost( self::$posts->tableName, $content, 'blog/post/' );
case 'edit':
$content = $comments->findById( $data );
if ( empty( $content ) ) {
Issues::add( 'error', 'Unknown Comment.' );
return $this->index();
}
return $plugin->formEdit( self::$posts->tableName, $content, 'blog/post/' );
case 'delete':
$content = $comments->findById( $data );
if ( empty( $content ) ) {
Issues::add( 'error', 'Unknown Comment.' );
return $this->index();
}
return $plugin->formDelete( self::$posts->tableName, $content, 'blog/post/' );
}
}
public function post( $id = null ) {
if ( empty( $id ) ) {
return $this->index();
}
$post = self::$posts->findById( $id );
if ( empty( $post ) ) {
$post = self::$posts->findBySlug( $id );
if ( empty( $post ) ) {
return $this->index();
}
}
Debug::log( 'Controller initiated: ' . __METHOD__ . '.' );
self::$title = 'Blog Post';
if ( Input::exists( 'contentId' ) ) {
$this->comments( 'post', Input::post( 'contentId' ) );
}
Components::set( 'CONTENT_ID', $id );
Components::set( 'COMMENT_TYPE', self::$posts->tableName );
Components::set( 'NEWCOMMENT', '' );
Components::set( 'count', '0' );
Components::set( 'COMMENTS', '' );
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 ) ) );
}
}
self::$title .= ' - ' . $post->title;
self::$pageDescription = strip_tags( $post->contentSummaryNoLink );
Views::view( 'blog.post', $post );
}
public function author( $data = null ) {
if ( empty( $data ) ) {
return $this->index();
}
Debug::log( 'Controller initiated: ' . __METHOD__ . '.' );
self::$title = 'Posts by author - {SITENAME}';
self::$pageDescription = '{SITENAME} blog posts easily and conveniently sorted by author.';
Views::view( 'blog.list', self::$posts->byAuthor( $data ) );
}
public function month( $month = null, $year = 0 ) {
if ( empty( $month ) ) {
return $this->index();
}
Debug::log( 'Controller initiated: ' . __METHOD__ . '.' );
self::$title = 'Posts By Month - {SITENAME}';
self::$pageDescription = '{SITENAME} blog posts easily and conveniently sorted by month.';
Views::view( 'blog.list', self::$posts->byMonth( $month, $year ) );
}
public function year( $year = null ) {
if ( empty( $year ) ) {
return $this->index();
}
Debug::log( 'Controller initiated: ' . __METHOD__ . '.' );
self::$title = 'Posts by Year - {SITENAME}';
self::$pageDescription = '{SITENAME} blog posts easily and conveniently sorted by years.';
Views::view( 'blog.list', self::$posts->byYear( $year ) );
}
public function search() {
$results = [];
if ( Input::exists( 'submit' ) ) {
$dbResults = self::$posts->search( Input::post('searchTerm') );
if ( ! empty( $dbResults ) ) {
$results = $dbResults;
}
}
Components::set( 'searchResults', Views::simpleView( 'blog.list', $results ) );
Views::view( 'blog.searchResults' );
}
}