Initial commit
This commit is contained in:
105
app/plugins/blog/controllers/admin/blog.php
Normal file
105
app/plugins/blog/controllers/admin/blog.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?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\Plugins\Blog as BlogPlugin;
|
||||
|
||||
class Blog extends AdminController {
|
||||
public static $posts;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$blog = new BlogPlugin;
|
||||
self::$posts = $blog->posts;
|
||||
self::$title = 'Admin - Blog';
|
||||
$view = Navigation::activePageSelect( 'nav.admin', '/admin/blog' );
|
||||
Components::set( 'ADMINNAV', $view );
|
||||
}
|
||||
|
||||
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( '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( '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' ) ) );
|
||||
}
|
||||
}
|
158
app/plugins/blog/controllers/blog.php
Normal file
158
app/plugins/blog/controllers/blog.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?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\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;
|
||||
|
||||
class Blog extends Controller {
|
||||
protected static $blog;
|
||||
protected static $comments;
|
||||
protected static $posts;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
Template::setTemplate( 'blog' );
|
||||
$blog = new BlogPlugin;
|
||||
self::$posts = $blog->posts;
|
||||
}
|
||||
|
||||
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( self::$comments ) ) {
|
||||
self::$comments = new CommentsModel;
|
||||
}
|
||||
$plugin = new Comments;
|
||||
if ( empty( $sub ) || empty( $data ) ) {
|
||||
Session::flash( 'error', 'Whoops, try again.' );
|
||||
Redirect::to( 'blog' );
|
||||
}
|
||||
switch ( $sub ) {
|
||||
case 'post':
|
||||
$content = self::$posts->findById( (int) $data );
|
||||
if ( empty( $content ) ) {
|
||||
Session::flash( 'error', 'Unknown Post.' );
|
||||
Redirect::to( 'blog' );
|
||||
}
|
||||
return $plugin->formPost( self::$posts->tableName, $content, 'blog/post/' );
|
||||
return self::$comments->formPost( 'blog', $content, 'blog/post/' );
|
||||
case 'edit':
|
||||
$content = self::$comments->findById( $data );
|
||||
if ( empty( $content ) ) {
|
||||
Session::flash( 'error', 'Unknown Comment.' );
|
||||
Redirect::to( 'blog' );
|
||||
}
|
||||
return $plugin->formEdit( self::$posts->tableName, $content, 'blog/post/' );
|
||||
return self::$comments->formEdit( 'blog', $content, 'blog/post/' );
|
||||
case 'delete':
|
||||
$content = self::$comments->findById( $data );
|
||||
if ( empty( $content ) ) {
|
||||
Session::flash( 'error', 'Unknown Comment.' );
|
||||
Redirect::to( 'blog' );
|
||||
}
|
||||
return $plugin->formDelete( self::$posts->tableName, $content, 'blog/post/' );
|
||||
return self::$comments->formDelete( 'blog', $content, 'blog/post/' );
|
||||
}
|
||||
}
|
||||
|
||||
public function post( $id = null ) {
|
||||
if ( empty( $id ) ) {
|
||||
return $this->index();
|
||||
}
|
||||
$post = self::$posts->findById( $id );
|
||||
if ( empty( $post ) ) {
|
||||
return $this->index();
|
||||
}
|
||||
if ( empty( self::$comments ) ) {
|
||||
self::$comments = new CommentsModel;
|
||||
}
|
||||
Debug::log( 'Controller initiated: ' . __METHOD__ . '.' );
|
||||
self::$title = 'Blog Post';
|
||||
// I removed this once because i didn't realize.
|
||||
// this triggers the comment post controller method when the comment form is submitted on the post viewing page
|
||||
if ( Input::exists( 'contentId' ) ) {
|
||||
$this->comments( 'post', Input::post( 'contentId' ) );
|
||||
}
|
||||
Components::set( 'CONTENT_ID', $id );
|
||||
Components::set( 'COMMENT_TYPE', 'blog' );
|
||||
if ( App::$isLoggedIn ) {
|
||||
Components::set( 'NEWCOMMENT', Views::simpleView( 'comments.create' ) );
|
||||
} else {
|
||||
Components::set( 'NEWCOMMENT', '' );
|
||||
}
|
||||
$post = self::$posts->findById( $id );
|
||||
Components::set( 'count', self::$comments->count( self::$posts->tableName, $post->ID ) );
|
||||
Components::set( 'COMMENTS', Views::simpleView( 'comments.list', self::$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 ) );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user