Files
thetempusproject/app/plugins/comments/controllers/admin/comments.php
Joey Kimsey d7e8b586d7 various updates
remove dependence on jQuery
add image delete
Admin ui fix for mobile
image updates to new style
update comments
2025-02-05 06:36:29 -05:00

84 lines
2.8 KiB
PHP

<?php
/**
* app/plugins/comments/controllers/admin/comments.php
*
* This is the comments admin controller.
*
* @package TP Comments
* @version 5.0.1
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers\Admin;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Models\Comments as CommentsModel;
class Comments extends AdminController {
protected static $comments;
public function __construct() {
parent::__construct();
self::$title = 'Admin - Comments';
self::$comments = new CommentsModel;
$view = Navigation::activePageSelect( 'nav.admin', '/admin/comments' );
Components::set( 'ADMINNAV', $view );
}
public function edit( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'comments.admin.edit', self::$comments->findById( $data ) );
}
if ( !Forms::check( 'editComment' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return Views::view( 'comments.admin.edit', self::$comments->findById( $data ) );
}
if ( self::$comments->update( $data, Input::post( 'comment' ) ) ) {
Issues::add( 'success', 'Comment updated' );
} else {
return Views::view( 'comments.admin.edit', self::$comments->findById( $data ) );
}
$this->index();
}
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( $contentID ) ) {
return Views::view( 'comments.list', $commentData );
}
Issues::add( 'error', 'Comment not found.' );
$this->index();
}
public function delete( $data = null ) {
if ( $data == null ) {
if ( !Input::exists( 'C_' ) ) {
return $this->index();
}
$data = Input::post( 'C_' );
}
if ( !self::$comments->delete( $data ) ) {
Issues::add( 'error', 'There was an error with your request.' );
} else {
Issues::add( 'success', 'Comment has been deleted' );
}
$this->index();
}
public function index() {
Views::view( 'comments.admin.list', self::$comments->recent() );
}
}