Initial commit

This commit is contained in:
Joey Kimsey
2024-08-04 21:15:59 -04:00
parent c9d1fb983f
commit 0d469501ee
695 changed files with 70184 additions and 71 deletions

View File

@ -0,0 +1,146 @@
<?php
/**
* app/plugins/comments/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Comments
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins;
use ReflectionClass;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Installer;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Classes\Plugin;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Hermes\Functions\Redirect;
use TheTempusProject\Bedrock\Functions\Session;
use TheTempusProject\Models\Comments as CommentModel;
class Comments extends Plugin {
public $pluginName = 'TP Comments';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin to add user comments for other plugins.';
public $admin_links = [
[
'text' => '<i class="fa fa-fw fa-comment"></i> Comments',
'url' => '{ROOT_URL}admin/comments',
],
];
public $main_links = [
[
'text' => 'Moderator',
'url' => '{ROOT_URL}moderator/index',
'filter' => 'mod',
]
];
public $permissionMatrix = [
'modAccess' => [
'pretty' => 'Access Moderator Areas',
'default' => false,
],
];
public $resourceMatrix = [
'group' => [
[
'name' => 'Moderator',
'permissions' => '{"adminAccess":false}',
]
],
];
public $comments;
public function __construct( $load = false ) {
if ( !empty(App::$activePerms) ) {
App::$isMod = !empty(App::$activePerms['modAccess']);
} else {
App::$isMod = false;
}
$this->filters[] = [
'name' => 'mod',
'find' => '#{MOD}(.*?){/MOD}#is',
'replace' => ( App::$isMod ? '$1' : '' ),
'enabled' => true,
];
$this->getModel();
parent::__construct( $load );
}
public function formPost( $type, $content, $redirect ) {
if ( !App::$isLoggedIn ) {
Session::flash( 'notice', 'You must be logged in to post comments.' );
return Redirect::to( $redirect . $content->ID );
}
if ( !Forms::check( 'newComment' ) ) {
Session::flash( 'error', [ 'There was a problem with your comment form.' => Check::userErrors() ] );
return Redirect::to( $redirect . $content->ID );
}
if ( !$this->comments->create( $type, $content->ID, Input::post( 'comment' ) ) ) {
Session::flash( 'error', [ 'There was a problem posting your comment.' => Check::userErrors() ] );
} else {
Session::flash( 'success', 'Comment posted' );
}
return Redirect::to( $redirect . $content->ID );
}
public function formEdit( $type, $content, $redirect ) {
if ( !App::$isLoggedIn ) {
Session::flash( 'notice', 'You must be logged in to do that.' );
return Redirect::to( $type );
}
if ( !App::$isAdmin && $content->author != App::$activeUser->ID ) {
Session::flash( 'error', 'You do not have permission to edit this comment' );
return Redirect::to( $type );
}
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'comments.admin.edit', $content );
}
if ( !Forms::check( 'editComment' ) ) {
Issues::add( 'error', [ 'There was a problem editing your comment.' => Check::userErrors() ] );
return Views::view( 'comments.admin.edit', $content );
}
if ( !$this->comments->update( $content->ID, Input::post( 'comment' ) ) ) {
Issues::add( 'error', [ 'There was a problem editing your comment.' => Check::userErrors() ] );
return Views::view( 'comments.admin.edit', $content );
}
Session::flash( 'success', 'Comment updated' );
return Redirect::to( $redirect . $content->contentID );
}
public function formDelete( $type, $content, $redirect ) {
if ( !App::$isLoggedIn ) {
Session::flash( 'notice', 'You must be logged in to do that.' );
return Redirect::to( $type );
}
if ( !App::$isAdmin && $content->author != App::$activeUser->ID ) {
Session::flash( 'error', 'You do not have permission to edit this comment' );
return Redirect::to( $type );
}
if ( !$this->comments->delete( (array) $content->ID ) ) {
Session::flash( 'error', 'There was an error with your request.' );
} else {
Session::flash( 'success', 'Comment has been deleted' );
}
return Redirect::to( $redirect . $content->contentID );
}
public function getModel() {
if ( empty($this->comments) ) {
$this->comments = new CommentModel;
}
return $this->comments;
}
}